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) 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.MeasureTheory.Measure.ProbabilityMeasure import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Layercake import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction #align_import measure_theory.measure.portmanteau from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Characterizations of weak convergence of finite measures and probability measures This file will provide portmanteau characterizations of the weak convergence of finite measures and of probability measures, i.e., the standard characterizations of convergence in distribution. ## Main definitions The topologies of weak convergence on the types of finite measures and probability measures are already defined in their corresponding files; no substantial new definitions are introduced here. ## Main results The main result will be the portmanteau theorem providing various characterizations of the weak convergence of measures (probability measures or finite measures). Given measures μs and μ on a topological space Ω, the conditions that will be proven equivalent (under quite general hypotheses) are: (T) The measures μs tend to the measure μ weakly. (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). The separate implications are: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` is the implication (T) → (C). * `MeasureTheory.limsup_measure_closed_le_iff_liminf_measure_open_ge` is the equivalence (C) ↔ (O). * `MeasureTheory.tendsto_measure_of_null_frontier` is the implication (O) → (B). * `MeasureTheory.limsup_measure_closed_le_of_forall_tendsto_measure` is the implication (B) → (C). * `MeasureTheory.tendsto_of_forall_isOpen_le_liminf` gives the implication (O) → (T) for any sequence of Borel probability measures. ## Implementation notes Many of the characterizations of weak convergence hold for finite measures and are proven in that generality and then specialized to probability measures. Some implications hold with slightly more general assumptions than in the usual statement of portmanteau theorem. The full portmanteau theorem, however, is most convenient for probability measures on pseudo-emetrizable spaces with their Borel sigma algebras. Some specific considerations on the assumptions in the different implications: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` assumes `PseudoEMetricSpace`. The only reason is to have bounded continuous pointwise approximations to the indicator function of a closed set. Clearly for example metrizability or pseudo-emetrizability would be sufficient assumptions. The typeclass assumptions should be later adjusted in a way that takes into account use cases, but the proof will presumably remain essentially the same. * Where formulations are currently only provided for probability measures, one can obtain the finite measure formulations using the characterization of convergence of finite measures by their total masses and their probability-normalized versions, i.e., by `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, convergence in distribution, convergence in law, finite measure, probability measure -/ noncomputable section open MeasureTheory Set Filter BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section LimsupClosedLEAndLELiminfOpen /-! ### Portmanteau: limsup condition for closed sets iff liminf condition for open sets In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, the following two conditions are equivalent: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). Either of these will later be shown to be equivalent to the weak convergence of the sequence of measures. -/ variable {Ω : Type*} [MeasurableSpace Ω] /-- **Portmanteau theorem** -/ theorem le_measure_compl_liminf_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i => μs i E) ≤ μ E) : μ Eᶜ ≤ L.liminf fun i => μs i Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [liminf_bot, le_top] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] have obs : (L.liminf fun i : ι => 1 - μs i E) = L.liminf ((fun x => 1 - x) ∘ fun i : ι => μs i E) := rfl rw [obs] have := antitone_const_tsub.map_limsup_of_continuousAt (F := L) (fun i => μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simp_rw [← this] exact antitone_const_tsub h #align measure_theory.le_measure_compl_liminf_of_limsup_measure_le MeasureTheory.le_measure_compl_liminf_of_limsup_measure_le theorem le_measure_liminf_of_limsup_measure_compl_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i => μs i Eᶜ) ≤ μ Eᶜ) : μ E ≤ L.liminf fun i => μs i E := compl_compl E ▸ le_measure_compl_liminf_of_limsup_measure_le (MeasurableSet.compl E_mble) h #align measure_theory.le_measure_liminf_of_limsup_measure_compl_le MeasureTheory.le_measure_liminf_of_limsup_measure_compl_le theorem limsup_measure_compl_le_of_le_liminf_measure {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ E ≤ L.liminf fun i => μs i E) : (L.limsup fun i => μs i Eᶜ) ≤ μ Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] have obs : (L.limsup fun i : ι => 1 - μs i E) = L.limsup ((fun x => 1 - x) ∘ fun i : ι => μs i E) := rfl rw [obs] have := antitone_const_tsub.map_liminf_of_continuousAt (F := L) (fun i => μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simp_rw [← this] exact antitone_const_tsub h #align measure_theory.limsup_measure_compl_le_of_le_liminf_measure MeasureTheory.limsup_measure_compl_le_of_le_liminf_measure theorem limsup_measure_le_of_le_liminf_measure_compl {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ Eᶜ ≤ L.liminf fun i => μs i Eᶜ) : (L.limsup fun i => μs i E) ≤ μ E := compl_compl E ▸ limsup_measure_compl_le_of_le_liminf_measure (MeasurableSet.compl E_mble) h #align measure_theory.limsup_measure_le_of_le_liminf_measure_compl MeasureTheory.limsup_measure_le_of_le_liminf_measure_compl variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One pair of implications of the portmanteau theorem: For a sequence of Borel probability measures, the following two are equivalent: (C) The limsup of the measures of any closed set is at most the measure of the closed set under a candidate limit measure. (O) The liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure. -/ theorem limsup_measure_closed_le_iff_liminf_measure_open_ge {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] : (∀ F, IsClosed F → (L.limsup fun i => μs i F) ≤ μ F) ↔ ∀ G, IsOpen G → μ G ≤ L.liminf fun i => μs i G := by constructor · intro h G G_open exact le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h Gᶜ (isClosed_compl_iff.mpr G_open)) · intro h F F_closed exact limsup_measure_le_of_le_liminf_measure_compl F_closed.measurableSet (h Fᶜ (isOpen_compl_iff.mpr F_closed)) #align measure_theory.limsup_measure_closed_le_iff_liminf_measure_open_ge MeasureTheory.limsup_measure_closed_le_iff_liminf_measure_open_ge end LimsupClosedLEAndLELiminfOpen -- section section TendstoOfNullFrontier /-! ### Portmanteau: limit of measures of Borel sets whose boundary carries no mass in the limit In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, either of the following equivalent conditions: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). implies that (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ variable {Ω : Type*} [MeasurableSpace Ω] theorem tendsto_measure_of_le_liminf_measure_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} {E₀ E E₁ : Set Ω} (E₀_subset : E₀ ⊆ E) (subset_E₁ : E ⊆ E₁) (nulldiff : μ (E₁ \ E₀) = 0) (h_E₀ : μ E₀ ≤ L.liminf fun i => μs i E₀) (h_E₁ : (L.limsup fun i => μs i E₁) ≤ μ E₁) : L.Tendsto (fun i => μs i E) (𝓝 (μ E)) := by apply tendsto_of_le_liminf_of_limsup_le · have E₀_ae_eq_E : E₀ =ᵐ[μ] E := EventuallyLE.antisymm E₀_subset.eventuallyLE (subset_E₁.eventuallyLE.trans (ae_le_set.mpr nulldiff)) calc μ E = μ E₀ := measure_congr E₀_ae_eq_E.symm _ ≤ L.liminf fun i => μs i E₀ := h_E₀ _ ≤ L.liminf fun i => μs i E := liminf_le_liminf (eventually_of_forall fun _ => measure_mono E₀_subset) · have E_ae_eq_E₁ : E =ᵐ[μ] E₁ := EventuallyLE.antisymm subset_E₁.eventuallyLE ((ae_le_set.mpr nulldiff).trans E₀_subset.eventuallyLE) calc (L.limsup fun i => μs i E) ≤ L.limsup fun i => μs i E₁ := limsup_le_limsup (eventually_of_forall fun _ => measure_mono subset_E₁) _ ≤ μ E₁ := h_E₁ _ = μ E := measure_congr E_ae_eq_E₁.symm · infer_param · infer_param #align measure_theory.tendsto_measure_of_le_liminf_measure_of_limsup_measure_le MeasureTheory.tendsto_measure_of_le_liminf_measure_of_limsup_measure_le variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One implication of the portmanteau theorem: For a sequence of Borel probability measures, if the liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure, then for any set whose boundary carries no probability mass under the candidate limit measure, then its measures under the sequence converge to its measure under the candidate limit measure. -/ theorem tendsto_measure_of_null_frontier {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] (h_opens : ∀ G, IsOpen G → μ G ≤ L.liminf fun i => μs i G) {E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : L.Tendsto (fun i => μs i E) (𝓝 (μ E)) := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i => μs i F) ≤ μ F := limsup_measure_closed_le_iff_liminf_measure_open_ge.mpr h_opens tendsto_measure_of_le_liminf_measure_of_limsup_measure_le interior_subset subset_closure E_nullbdry (h_opens _ isOpen_interior) (h_closeds _ isClosed_closure) #align measure_theory.tendsto_measure_of_null_frontier MeasureTheory.tendsto_measure_of_null_frontier end TendstoOfNullFrontier --section section ConvergenceImpliesLimsupClosedLE /-! ### Portmanteau implication: weak convergence implies a limsup condition for closed sets In this section we prove, under the assumption that the underlying topological space `Ω` is pseudo-emetrizable, that (T) The measures μs tend to the measure μ weakly implies (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). Combining with a earlier proven implications, we get that (T) implies also both (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G); (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ /-- One implication of the portmanteau theorem: Weak convergence of finite measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit measure. -/ theorem FiniteMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [OpensMeasurableSpace Ω] {μ : FiniteMeasure Ω} {μs : ι → FiniteMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i => (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] apply ENNReal.le_of_forall_pos_le_add intro ε ε_pos _ let fs := F_closed.apprSeq have key₁ : Tendsto (fun n ↦ ∫⁻ ω, (fs n ω : ℝ≥0∞) ∂μ) atTop (𝓝 ((μ : Measure Ω) F)) := HasOuterApproxClosed.tendsto_lintegral_apprSeq F_closed (μ : Measure Ω) have room₁ : (μ : Measure Ω) F < (μ : Measure Ω) F + ε / 2 := by apply ENNReal.lt_add_right (measure_lt_top (μ : Measure Ω) F).ne (ENNReal.div_pos_iff.mpr ⟨(ENNReal.coe_pos.mpr ε_pos).ne.symm, ENNReal.two_ne_top⟩).ne.symm rcases eventually_atTop.mp (eventually_lt_of_tendsto_lt room₁ key₁) with ⟨M, hM⟩ have key₂ := FiniteMeasure.tendsto_iff_forall_lintegral_tendsto.mp μs_lim (fs M) have room₂ : (lintegral (μ : Measure Ω) fun a => fs M a) < (lintegral (μ : Measure Ω) fun a => fs M a) + ε / 2 := by apply ENNReal.lt_add_right (ne_of_lt ?_) (ENNReal.div_pos_iff.mpr ⟨(ENNReal.coe_pos.mpr ε_pos).ne.symm, ENNReal.two_ne_top⟩).ne.symm apply BoundedContinuousFunction.lintegral_lt_top_of_nnreal have ev_near := Eventually.mono (eventually_lt_of_tendsto_lt room₂ key₂) fun n => le_of_lt have ev_near' := Eventually.mono ev_near (fun n ↦ le_trans (HasOuterApproxClosed.measure_le_lintegral F_closed (μs n) M)) apply (Filter.limsup_le_limsup ev_near').trans rw [limsup_const] apply le_trans (add_le_add (hM M rfl.le).le (le_refl (ε / 2 : ℝ≥0∞))) simp only [add_assoc, ENNReal.add_halves, le_refl] #align measure_theory.finite_measure.limsup_measure_closed_le_of_tendsto MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit probability measure. -/ theorem ProbabilityMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i => (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by apply FiniteMeasure.limsup_measure_closed_le_of_tendsto ((ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds L).mp μs_lim) F_closed #align measure_theory.probability_measure.limsup_measure_closed_le_of_tendsto MeasureTheory.ProbabilityMeasure.limsup_measure_closed_le_of_tendsto /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the liminf of the measures of any open set is at least the measure of the open set under the limit probability measure. -/ theorem ProbabilityMeasure.le_liminf_measure_open_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {G : Set Ω} (G_open : IsOpen G) : (μ : Measure Ω) G ≤ L.liminf fun i => (μs i : Measure Ω) G := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := fun _ F_closed => ProbabilityMeasure.limsup_measure_closed_le_of_tendsto μs_lim F_closed le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h_closeds _ (isClosed_compl_iff.mpr G_open)) #align measure_theory.probability_measure.le_liminf_measure_open_of_tendsto MeasureTheory.ProbabilityMeasure.le_liminf_measure_open_of_tendsto theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : (μ : Measure Ω) (frontier E) = 0) : Tendsto (fun i => (μs i : Measure Ω) E) L (𝓝 ((μ : Measure Ω) E)) := haveI h_opens : ∀ G, IsOpen G → (μ : Measure Ω) G ≤ L.liminf fun i => (μs i : Measure Ω) G := fun _ G_open => ProbabilityMeasure.le_liminf_measure_open_of_tendsto μs_lim G_open tendsto_measure_of_null_frontier h_opens E_nullbdry #align measure_theory.probability_measure.tendsto_measure_of_null_frontier_of_tendsto' MeasureTheory.ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that if the boundary of a Borel set carries no probability mass under the limit measure, then the limit of the measures of the set equals the measure of the set under the limit probability measure. A version with coercions to ordinary `ℝ≥0∞`-valued measures is `MeasureTheory.ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto'`. -/ theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : Tendsto (fun i => μs i E) L (𝓝 (μ E)) := by have E_nullbdry' : (μ : Measure Ω) (frontier E) = 0 := by rw [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure, E_nullbdry, ENNReal.coe_zero] have key := ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' μs_lim E_nullbdry' exact (ENNReal.tendsto_toNNReal (measure_ne_top (↑μ) E)).comp key #align measure_theory.probability_measure.tendsto_measure_of_null_frontier_of_tendsto MeasureTheory.ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto end ConvergenceImpliesLimsupClosedLE --section section LimitBorelImpliesLimsupClosedLE /-! ### Portmanteau implication: limit condition for Borel sets implies limsup for closed sets In this section we prove, under the assumption that the underlying topological space `Ω` is pseudo-emetrizable, that (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B) implies (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). Combining with a earlier proven implications, we get that (B) implies also (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). -/ open ENNReal variable {Ω : Type*} [PseudoEMetricSpace Ω] [MeasurableSpace Ω] [OpensMeasurableSpace Ω]
Mathlib/MeasureTheory/Measure/Portmanteau.lean
399
410
theorem exists_null_frontier_thickening (μ : Measure Ω) [SigmaFinite μ] (s : Set Ω) {a b : ℝ} (hab : a < b) : ∃ r ∈ Ioo a b, μ (frontier (Metric.thickening r s)) = 0 := by
have mbles : ∀ r : ℝ, MeasurableSet (frontier (Metric.thickening r s)) := fun r => isClosed_frontier.measurableSet have disjs := Metric.frontier_thickening_disjoint s have key := Measure.countable_meas_pos_of_disjoint_iUnion (μ := μ) mbles disjs have aux := measure_diff_null (s := Ioo a b) (Set.Countable.measure_zero key volume) have len_pos : 0 < ENNReal.ofReal (b - a) := by simp only [hab, ENNReal.ofReal_pos, sub_pos] rw [← Real.volume_Ioo, ← aux] at len_pos rcases nonempty_of_measure_ne_zero len_pos.ne.symm with ⟨r, ⟨r_in_Ioo, hr⟩⟩ refine ⟨r, r_in_Ioo, ?_⟩ simpa only [mem_setOf_eq, not_lt, le_zero_iff] using hr
/- 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.MetricSpace.HausdorffDistance #align_import topology.metric_space.hausdorff_distance from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Thickenings in pseudo-metric spaces ## Main definitions * `Metric.thickening δ s`, the open thickening by radius `δ` of a set `s` in a pseudo emetric space. * `Metric.cthickening δ s`, the closed thickening by radius `δ` of a set `s` in a pseudo emetric space. ## Main results * `Disjoint.exists_thickenings`: two disjoint sets admit disjoint thickenings * `Disjoint.exists_cthickenings`: two disjoint sets admit disjoint closed thickenings * `IsCompact.exists_cthickening_subset_open`: if `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. * `Metric.hasBasis_nhdsSet_cthickening`: the `cthickening`s of a compact set `K` form a basis of the neighbourhoods of `K` * `Metric.closure_eq_iInter_cthickening'`: the closure of a set equals the intersection of its closed thickenings of positive radii accumulating at zero. The same holds for open thickenings. * `IsCompact.cthickening_eq_biUnion_closedBall`: if `s` is compact, `cthickening δ s` is the union of `closedBall`s of radius `δ` around `x : E`. -/ noncomputable section open NNReal ENNReal Topology Set Filter Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace Metric section Thickening variable [PseudoEMetricSpace α] {δ : ℝ} {s : Set α} {x : α} open EMetric /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at distance less than `δ` from some point of `E`. -/ def thickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E < ENNReal.ofReal δ } #align metric.thickening Metric.thickening theorem mem_thickening_iff_infEdist_lt : x ∈ thickening δ s ↔ infEdist x s < ENNReal.ofReal δ := Iff.rfl #align metric.mem_thickening_iff_inf_edist_lt Metric.mem_thickening_iff_infEdist_lt /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the (open) `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_thickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.thickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [thickening, mem_setOf_eq, not_lt] exact (ENNReal.ofReal_le_ofReal hδ.le).trans ε_lt.le /-- The (open) thickening equals the preimage of an open interval under `EMetric.infEdist`. -/ theorem thickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : thickening δ E = (infEdist · E) ⁻¹' Iio (ENNReal.ofReal δ) := rfl #align metric.thickening_eq_preimage_inf_edist Metric.thickening_eq_preimage_infEdist /-- The (open) thickening is an open set. -/ theorem isOpen_thickening {δ : ℝ} {E : Set α} : IsOpen (thickening δ E) := Continuous.isOpen_preimage continuous_infEdist _ isOpen_Iio #align metric.is_open_thickening Metric.isOpen_thickening /-- The (open) thickening of the empty set is empty. -/ @[simp] theorem thickening_empty (δ : ℝ) : thickening δ (∅ : Set α) = ∅ := by simp only [thickening, setOf_false, infEdist_empty, not_top_lt] #align metric.thickening_empty Metric.thickening_empty theorem thickening_of_nonpos (hδ : δ ≤ 0) (s : Set α) : thickening δ s = ∅ := eq_empty_of_forall_not_mem fun _ => ((ENNReal.ofReal_of_nonpos hδ).trans_le bot_le).not_lt #align metric.thickening_of_nonpos Metric.thickening_of_nonpos /-- The (open) thickening `Metric.thickening δ E` of a fixed subset `E` is an increasing function of the thickening radius `δ`. -/ theorem thickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickening δ₁ E ⊆ thickening δ₂ E := preimage_mono (Iio_subset_Iio (ENNReal.ofReal_le_ofReal hle)) #align metric.thickening_mono Metric.thickening_mono /-- The (open) thickening `Metric.thickening δ E` with a fixed thickening radius `δ` is an increasing function of the subset `E`. -/ theorem thickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) : thickening δ E₁ ⊆ thickening δ E₂ := fun _ hx => lt_of_le_of_lt (infEdist_anti h) hx #align metric.thickening_subset_of_subset Metric.thickening_subset_of_subset theorem mem_thickening_iff_exists_edist_lt {δ : ℝ} (E : Set α) (x : α) : x ∈ thickening δ E ↔ ∃ z ∈ E, edist x z < ENNReal.ofReal δ := infEdist_lt_iff #align metric.mem_thickening_iff_exists_edist_lt Metric.mem_thickening_iff_exists_edist_lt /-- The frontier of the (open) thickening of a set is contained in an `EMetric.infEdist` level set. -/ theorem frontier_thickening_subset (E : Set α) {δ : ℝ} : frontier (thickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } := frontier_lt_subset_eq continuous_infEdist continuous_const #align metric.frontier_thickening_subset Metric.frontier_thickening_subset theorem frontier_thickening_disjoint (A : Set α) : Pairwise (Disjoint on fun r : ℝ => frontier (thickening r A)) := by refine (pairwise_disjoint_on _).2 fun r₁ r₂ hr => ?_ rcases le_total r₁ 0 with h₁ | h₁ · simp [thickening_of_nonpos h₁] refine ((disjoint_singleton.2 fun h => hr.ne ?_).preimage _).mono (frontier_thickening_subset _) (frontier_thickening_subset _) apply_fun ENNReal.toReal at h rwa [ENNReal.toReal_ofReal h₁, ENNReal.toReal_ofReal (h₁.trans hr.le)] at h #align metric.frontier_thickening_disjoint Metric.frontier_thickening_disjoint /-- Any set is contained in the complement of the δ-thickening of the complement of its δ-thickening. -/ lemma subset_compl_thickening_compl_thickening_self (δ : ℝ) (E : Set α) : E ⊆ (thickening δ (thickening δ E)ᶜ)ᶜ := by intro x x_in_E simp only [thickening, mem_compl_iff, mem_setOf_eq, not_lt] apply EMetric.le_infEdist.mpr fun y hy ↦ ?_ simp only [mem_compl_iff, mem_setOf_eq, not_lt] at hy simpa only [edist_comm] using le_trans hy <| EMetric.infEdist_le_edist_of_mem x_in_E /-- The δ-thickening of the complement of the δ-thickening of a set is contained in the complement of the set. -/ lemma thickening_compl_thickening_self_subset_compl (δ : ℝ) (E : Set α) : thickening δ (thickening δ E)ᶜ ⊆ Eᶜ := by apply compl_subset_compl.mp simpa only [compl_compl] using subset_compl_thickening_compl_thickening_self δ E variable {X : Type u} [PseudoMetricSpace X] -- Porting note (#10756): new lemma theorem mem_thickening_iff_infDist_lt {E : Set X} {x : X} (h : E.Nonempty) : x ∈ thickening δ E ↔ infDist x E < δ := lt_ofReal_iff_toReal_lt (infEdist_ne_top h) /-- A point in a metric space belongs to the (open) `δ`-thickening of a subset `E` if and only if it is at distance less than `δ` from some point of `E`. -/ theorem mem_thickening_iff {E : Set X} {x : X} : x ∈ thickening δ E ↔ ∃ z ∈ E, dist x z < δ := by have key_iff : ∀ z : X, edist x z < ENNReal.ofReal δ ↔ dist x z < δ := fun z ↦ by rw [dist_edist, lt_ofReal_iff_toReal_lt (edist_ne_top _ _)] simp_rw [mem_thickening_iff_exists_edist_lt, key_iff] #align metric.mem_thickening_iff Metric.mem_thickening_iff @[simp] theorem thickening_singleton (δ : ℝ) (x : X) : thickening δ ({x} : Set X) = ball x δ := by ext simp [mem_thickening_iff] #align metric.thickening_singleton Metric.thickening_singleton theorem ball_subset_thickening {x : X} {E : Set X} (hx : x ∈ E) (δ : ℝ) : ball x δ ⊆ thickening δ E := Subset.trans (by simp [Subset.rfl]) (thickening_subset_of_subset δ <| singleton_subset_iff.mpr hx) #align metric.ball_subset_thickening Metric.ball_subset_thickening /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a metric space equals the union of balls of radius `δ` centered at points of `E`. -/ theorem thickening_eq_biUnion_ball {δ : ℝ} {E : Set X} : thickening δ E = ⋃ x ∈ E, ball x δ := by ext x simp only [mem_iUnion₂, exists_prop] exact mem_thickening_iff #align metric.thickening_eq_bUnion_ball Metric.thickening_eq_biUnion_ball protected theorem _root_.Bornology.IsBounded.thickening {δ : ℝ} {E : Set X} (h : IsBounded E) : IsBounded (thickening δ E) := by rcases E.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · simp · refine (isBounded_iff_subset_closedBall x).2 ⟨δ + diam E, fun y hy ↦ ?_⟩ calc dist y x ≤ infDist y E + diam E := dist_le_infDist_add_diam (x := y) h hx _ ≤ δ + diam E := add_le_add_right ((mem_thickening_iff_infDist_lt ⟨x, hx⟩).1 hy).le _ #align metric.bounded.thickening Bornology.IsBounded.thickening end Thickening section Cthickening variable [PseudoEMetricSpace α] {δ ε : ℝ} {s t : Set α} {x : α} open EMetric /-- The closed `δ`-thickening `Metric.cthickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at infimum distance at most `δ` from `E`. -/ def cthickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E ≤ ENNReal.ofReal δ } #align metric.cthickening Metric.cthickening @[simp] theorem mem_cthickening_iff : x ∈ cthickening δ s ↔ infEdist x s ≤ ENNReal.ofReal δ := Iff.rfl #align metric.mem_cthickening_iff Metric.mem_cthickening_iff /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the closed `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_cthickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.cthickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [cthickening, mem_setOf_eq, not_le] exact ((ofReal_lt_ofReal_iff ε_pos).mpr hδ).trans ε_lt theorem mem_cthickening_of_edist_le (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : edist x y ≤ ENNReal.ofReal δ) : x ∈ cthickening δ E := (infEdist_le_edist_of_mem h).trans h' #align metric.mem_cthickening_of_edist_le Metric.mem_cthickening_of_edist_le theorem mem_cthickening_of_dist_le {α : Type*} [PseudoMetricSpace α] (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : dist x y ≤ δ) : x ∈ cthickening δ E := by apply mem_cthickening_of_edist_le x y δ E h rw [edist_dist] exact ENNReal.ofReal_le_ofReal h' #align metric.mem_cthickening_of_dist_le Metric.mem_cthickening_of_dist_le theorem cthickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : cthickening δ E = (fun x => infEdist x E) ⁻¹' Iic (ENNReal.ofReal δ) := rfl #align metric.cthickening_eq_preimage_inf_edist Metric.cthickening_eq_preimage_infEdist /-- The closed thickening is a closed set. -/ theorem isClosed_cthickening {δ : ℝ} {E : Set α} : IsClosed (cthickening δ E) := IsClosed.preimage continuous_infEdist isClosed_Iic #align metric.is_closed_cthickening Metric.isClosed_cthickening /-- The closed thickening of the empty set is empty. -/ @[simp]
Mathlib/Topology/MetricSpace/Thickening.lean
238
239
theorem cthickening_empty (δ : ℝ) : cthickening δ (∅ : Set α) = ∅ := by
simp only [cthickening, ENNReal.ofReal_ne_top, setOf_false, infEdist_empty, top_le_iff]
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Analysis.Convex.Function #align_import analysis.convex.quasiconvex from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Quasiconvex and quasiconcave functions This file defines quasiconvexity, quasiconcavity and quasilinearity of functions, which are generalizations of unimodality and monotonicity. Convexity implies quasiconvexity, concavity implies quasiconcavity, and monotonicity implies quasilinearity. ## Main declarations * `QuasiconvexOn 𝕜 s f`: Quasiconvexity of the function `f` on the set `s` with scalars `𝕜`. This means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex. * `QuasiconcaveOn 𝕜 s f`: Quasiconcavity of the function `f` on the set `s` with scalars `𝕜`. This means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex. * `QuasilinearOn 𝕜 s f`: Quasilinearity of the function `f` on the set `s` with scalars `𝕜`. This means that `f` is both quasiconvex and quasiconcave. ## References * https://en.wikipedia.org/wiki/Quasiconvex_function -/ open Function OrderDual Set variable {𝕜 E F β : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid_E variable [AddCommMonoid E] [AddCommMonoid F] section LE_β variable (𝕜) [LE β] [SMul 𝕜 E] (s : Set E) (f : E → β) /-- A function is quasiconvex if all its sublevels are convex. This means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex. -/ def QuasiconvexOn : Prop := ∀ r, Convex 𝕜 ({ x ∈ s | f x ≤ r }) #align quasiconvex_on QuasiconvexOn /-- A function is quasiconcave if all its superlevels are convex. This means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex. -/ def QuasiconcaveOn : Prop := ∀ r, Convex 𝕜 ({ x ∈ s | r ≤ f x }) #align quasiconcave_on QuasiconcaveOn /-- A function is quasilinear if it is both quasiconvex and quasiconcave. This means that, for all `r`, the sets `{x ∈ s | f x ≤ r}` and `{x ∈ s | r ≤ f x}` are `𝕜`-convex. -/ def QuasilinearOn : Prop := QuasiconvexOn 𝕜 s f ∧ QuasiconcaveOn 𝕜 s f #align quasilinear_on QuasilinearOn variable {𝕜 s f} theorem QuasiconvexOn.dual : QuasiconvexOn 𝕜 s f → QuasiconcaveOn 𝕜 s (toDual ∘ f) := id #align quasiconvex_on.dual QuasiconvexOn.dual theorem QuasiconcaveOn.dual : QuasiconcaveOn 𝕜 s f → QuasiconvexOn 𝕜 s (toDual ∘ f) := id #align quasiconcave_on.dual QuasiconcaveOn.dual theorem QuasilinearOn.dual : QuasilinearOn 𝕜 s f → QuasilinearOn 𝕜 s (toDual ∘ f) := And.symm #align quasilinear_on.dual QuasilinearOn.dual theorem Convex.quasiconvexOn_of_convex_le (hs : Convex 𝕜 s) (h : ∀ r, Convex 𝕜 { x | f x ≤ r }) : QuasiconvexOn 𝕜 s f := fun r => hs.inter (h r) #align convex.quasiconvex_on_of_convex_le Convex.quasiconvexOn_of_convex_le theorem Convex.quasiconcaveOn_of_convex_ge (hs : Convex 𝕜 s) (h : ∀ r, Convex 𝕜 { x | r ≤ f x }) : QuasiconcaveOn 𝕜 s f := @Convex.quasiconvexOn_of_convex_le 𝕜 E βᵒᵈ _ _ _ _ _ _ hs h #align convex.quasiconcave_on_of_convex_ge Convex.quasiconcaveOn_of_convex_ge theorem QuasiconvexOn.convex [IsDirected β (· ≤ ·)] (hf : QuasiconvexOn 𝕜 s f) : Convex 𝕜 s := fun x hx y hy _ _ ha hb hab => let ⟨_, hxz, hyz⟩ := exists_ge_ge (f x) (f y) (hf _ ⟨hx, hxz⟩ ⟨hy, hyz⟩ ha hb hab).1 #align quasiconvex_on.convex QuasiconvexOn.convex theorem QuasiconcaveOn.convex [IsDirected β (· ≥ ·)] (hf : QuasiconcaveOn 𝕜 s f) : Convex 𝕜 s := hf.dual.convex #align quasiconcave_on.convex QuasiconcaveOn.convex end LE_β section Semilattice_β variable [SMul 𝕜 E] {s : Set E} {f g : E → β} theorem QuasiconvexOn.sup [SemilatticeSup β] (hf : QuasiconvexOn 𝕜 s f) (hg : QuasiconvexOn 𝕜 s g) : QuasiconvexOn 𝕜 s (f ⊔ g) := by intro r simp_rw [Pi.sup_def, sup_le_iff, Set.sep_and] exact (hf r).inter (hg r) #align quasiconvex_on.sup QuasiconvexOn.sup theorem QuasiconcaveOn.inf [SemilatticeInf β] (hf : QuasiconcaveOn 𝕜 s f) (hg : QuasiconcaveOn 𝕜 s g) : QuasiconcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg #align quasiconcave_on.inf QuasiconcaveOn.inf end Semilattice_β section LinearOrder_β variable [LinearOrder β] [SMul 𝕜 E] {s : Set E} {f g : E → β} theorem quasiconvexOn_iff_le_max : QuasiconvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ max (f x) (f y) := ⟨fun hf => ⟨hf.convex, fun _ hx _ hy _ _ ha hb hab => (hf _ ⟨hx, le_max_left _ _⟩ ⟨hy, le_max_right _ _⟩ ha hb hab).2⟩, fun hf _ _ hx _ hy _ _ ha hb hab => ⟨hf.1 hx.1 hy.1 ha hb hab, (hf.2 hx.1 hy.1 ha hb hab).trans <| max_le hx.2 hy.2⟩⟩ #align quasiconvex_on_iff_le_max quasiconvexOn_iff_le_max theorem quasiconcaveOn_iff_min_le : QuasiconcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → min (f x) (f y) ≤ f (a • x + b • y) := @quasiconvexOn_iff_le_max 𝕜 E βᵒᵈ _ _ _ _ _ _ #align quasiconcave_on_iff_min_le quasiconcaveOn_iff_min_le theorem quasilinearOn_iff_mem_uIcc : QuasilinearOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ∈ uIcc (f x) (f y) := by rw [QuasilinearOn, quasiconvexOn_iff_le_max, quasiconcaveOn_iff_min_le, and_and_and_comm, and_self_iff] apply and_congr_right' simp_rw [← forall_and, ← Icc_min_max, mem_Icc, and_comm] #align quasilinear_on_iff_mem_uIcc quasilinearOn_iff_mem_uIcc
Mathlib/Analysis/Convex/Quasiconvex.lean
146
150
theorem QuasiconvexOn.convex_lt (hf : QuasiconvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := by
refine fun x hx y hy a b ha hb hab => ?_ have h := hf _ ⟨hx.1, le_max_left _ _⟩ ⟨hy.1, le_max_right _ _⟩ ha hb hab exact ⟨h.1, h.2.trans_lt <| max_lt hx.2 hy.2⟩
/- Copyright (c) 2020 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.Tactic.Linarith import Mathlib.CategoryTheory.Skeletal import Mathlib.Data.Fintype.Sort import Mathlib.Order.Category.NonemptyFinLinOrd import Mathlib.CategoryTheory.Functor.ReflectsIso #align_import algebraic_topology.simplex_category from "leanprover-community/mathlib"@"e8ac6315bcfcbaf2d19a046719c3b553206dac75" /-! # The simplex category We construct a skeletal model of the simplex category, with objects `ℕ` and the morphism `n ⟶ m` being the monotone maps from `Fin (n+1)` to `Fin (m+1)`. We show that this category is equivalent to `NonemptyFinLinOrd`. ## Remarks The definitions `SimplexCategory` and `SimplexCategory.Hom` are marked as irreducible. We provide the following functions to work with these objects: 1. `SimplexCategory.mk` creates an object of `SimplexCategory` out of a natural number. Use the notation `[n]` in the `Simplicial` locale. 2. `SimplexCategory.len` gives the "length" of an object of `SimplexCategory`, as a natural. 3. `SimplexCategory.Hom.mk` makes a morphism out of a monotone map between `Fin`'s. 4. `SimplexCategory.Hom.toOrderHom` gives the underlying monotone map associated to a term of `SimplexCategory.Hom`. -/ universe v open CategoryTheory CategoryTheory.Limits /-- The simplex category: * objects are natural numbers `n : ℕ` * morphisms from `n` to `m` are monotone functions `Fin (n+1) → Fin (m+1)` -/ def SimplexCategory := ℕ #align simplex_category SimplexCategory namespace SimplexCategory section -- Porting note: the definition of `SimplexCategory` is made irreducible below /-- Interpret a natural number as an object of the simplex category. -/ def mk (n : ℕ) : SimplexCategory := n #align simplex_category.mk SimplexCategory.mk /-- the `n`-dimensional simplex can be denoted `[n]` -/ scoped[Simplicial] notation "[" n "]" => SimplexCategory.mk n -- TODO: Make `len` irreducible. /-- The length of an object of `SimplexCategory`. -/ def len (n : SimplexCategory) : ℕ := n #align simplex_category.len SimplexCategory.len @[ext] theorem ext (a b : SimplexCategory) : a.len = b.len → a = b := id #align simplex_category.ext SimplexCategory.ext attribute [irreducible] SimplexCategory open Simplicial @[simp] theorem len_mk (n : ℕ) : [n].len = n := rfl #align simplex_category.len_mk SimplexCategory.len_mk @[simp] theorem mk_len (n : SimplexCategory) : ([n.len] : SimplexCategory) = n := rfl #align simplex_category.mk_len SimplexCategory.mk_len /-- A recursor for `SimplexCategory`. Use it as `induction Δ using SimplexCategory.rec`. -/ protected def rec {F : SimplexCategory → Sort*} (h : ∀ n : ℕ, F [n]) : ∀ X, F X := fun n => h n.len #align simplex_category.rec SimplexCategory.rec -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- Morphisms in the `SimplexCategory`. -/ protected def Hom (a b : SimplexCategory) := Fin (a.len + 1) →o Fin (b.len + 1) #align simplex_category.hom SimplexCategory.Hom namespace Hom /-- Make a morphism in `SimplexCategory` from a monotone map of `Fin`'s. -/ def mk {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) : SimplexCategory.Hom a b := f #align simplex_category.hom.mk SimplexCategory.Hom.mk /-- Recover the monotone map from a morphism in the simplex category. -/ def toOrderHom {a b : SimplexCategory} (f : SimplexCategory.Hom a b) : Fin (a.len + 1) →o Fin (b.len + 1) := f #align simplex_category.hom.to_order_hom SimplexCategory.Hom.toOrderHom theorem ext' {a b : SimplexCategory} (f g : SimplexCategory.Hom a b) : f.toOrderHom = g.toOrderHom → f = g := id #align simplex_category.hom.ext SimplexCategory.Hom.ext' attribute [irreducible] SimplexCategory.Hom @[simp] theorem mk_toOrderHom {a b : SimplexCategory} (f : SimplexCategory.Hom a b) : mk f.toOrderHom = f := rfl #align simplex_category.hom.mk_to_order_hom SimplexCategory.Hom.mk_toOrderHom @[simp] theorem toOrderHom_mk {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) : (mk f).toOrderHom = f := rfl #align simplex_category.hom.to_order_hom_mk SimplexCategory.Hom.toOrderHom_mk theorem mk_toOrderHom_apply {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) (i : Fin (a.len + 1)) : (mk f).toOrderHom i = f i := rfl #align simplex_category.hom.mk_to_order_hom_apply SimplexCategory.Hom.mk_toOrderHom_apply /-- Identity morphisms of `SimplexCategory`. -/ @[simp] def id (a : SimplexCategory) : SimplexCategory.Hom a a := mk OrderHom.id #align simplex_category.hom.id SimplexCategory.Hom.id /-- Composition of morphisms of `SimplexCategory`. -/ @[simp] def comp {a b c : SimplexCategory} (f : SimplexCategory.Hom b c) (g : SimplexCategory.Hom a b) : SimplexCategory.Hom a c := mk <| f.toOrderHom.comp g.toOrderHom #align simplex_category.hom.comp SimplexCategory.Hom.comp end Hom instance smallCategory : SmallCategory.{0} SimplexCategory where Hom n m := SimplexCategory.Hom n m id m := SimplexCategory.Hom.id _ comp f g := SimplexCategory.Hom.comp g f #align simplex_category.small_category SimplexCategory.smallCategory @[simp] lemma id_toOrderHom (a : SimplexCategory) : Hom.toOrderHom (𝟙 a) = OrderHom.id := rfl @[simp] lemma comp_toOrderHom {a b c: SimplexCategory} (f : a ⟶ b) (g : b ⟶ c) : (f ≫ g).toOrderHom = g.toOrderHom.comp f.toOrderHom := rfl -- Porting note: added because `Hom.ext'` is not triggered automatically @[ext] theorem Hom.ext {a b : SimplexCategory} (f g : a ⟶ b) : f.toOrderHom = g.toOrderHom → f = g := Hom.ext' _ _ /-- The constant morphism from [0]. -/ def const (x y : SimplexCategory) (i : Fin (y.len + 1)) : x ⟶ y := Hom.mk <| ⟨fun _ => i, by tauto⟩ #align simplex_category.const SimplexCategory.const @[simp] lemma const_eq_id : const [0] [0] 0 = 𝟙 _ := by aesop @[simp] lemma const_apply (x y : SimplexCategory) (i : Fin (y.len + 1)) (a : Fin (x.len + 1)) : (const x y i).toOrderHom a = i := rfl @[simp] theorem const_comp (x : SimplexCategory) {y z : SimplexCategory} (f : y ⟶ z) (i : Fin (y.len + 1)) : const x y i ≫ f = const x z (f.toOrderHom i) := rfl #align simplex_category.const_comp SimplexCategory.const_comp /-- Make a morphism `[n] ⟶ [m]` from a monotone map between fin's. This is useful for constructing morphisms between `[n]` directly without identifying `n` with `[n].len`. -/ @[simp] def mkHom {n m : ℕ} (f : Fin (n + 1) →o Fin (m + 1)) : ([n] : SimplexCategory) ⟶ [m] := SimplexCategory.Hom.mk f #align simplex_category.mk_hom SimplexCategory.mkHom theorem hom_zero_zero (f : ([0] : SimplexCategory) ⟶ [0]) : f = 𝟙 _ := by ext : 3 apply @Subsingleton.elim (Fin 1) #align simplex_category.hom_zero_zero SimplexCategory.hom_zero_zero end open Simplicial section Generators /-! ## Generating maps for the simplex category TODO: prove that the simplex category is equivalent to one given by the following generators and relations. -/ /-- The `i`-th face map from `[n]` to `[n+1]` -/ def δ {n} (i : Fin (n + 2)) : ([n] : SimplexCategory) ⟶ [n + 1] := mkHom (Fin.succAboveOrderEmb i).toOrderHom #align simplex_category.δ SimplexCategory.δ /-- The `i`-th degeneracy map from `[n+1]` to `[n]` -/ def σ {n} (i : Fin (n + 1)) : ([n + 1] : SimplexCategory) ⟶ [n] := mkHom { toFun := Fin.predAbove i monotone' := Fin.predAbove_right_monotone i } #align simplex_category.σ SimplexCategory.σ /-- The generic case of the first simplicial identity -/ theorem δ_comp_δ {n} {i j : Fin (n + 2)} (H : i ≤ j) : δ i ≫ δ j.succ = δ j ≫ δ (Fin.castSucc i) := by ext k dsimp [δ, Fin.succAbove] rcases i with ⟨i, _⟩ rcases j with ⟨j, _⟩ rcases k with ⟨k, _⟩ split_ifs <;> · simp at * <;> omega #align simplex_category.δ_comp_δ SimplexCategory.δ_comp_δ theorem δ_comp_δ' {n} {i : Fin (n + 2)} {j : Fin (n + 3)} (H : Fin.castSucc i < j) : δ i ≫ δ j = δ (j.pred fun (hj : j = 0) => by simp [hj, Fin.not_lt_zero] at H) ≫ δ (Fin.castSucc i) := by rw [← δ_comp_δ] · rw [Fin.succ_pred] · simpa only [Fin.le_iff_val_le_val, ← Nat.lt_succ_iff, Nat.succ_eq_add_one, ← Fin.val_succ, j.succ_pred, Fin.lt_iff_val_lt_val] using H #align simplex_category.δ_comp_δ' SimplexCategory.δ_comp_δ' theorem δ_comp_δ'' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : i ≤ Fin.castSucc j) : δ (i.castLT (Nat.lt_of_le_of_lt (Fin.le_iff_val_le_val.mp H) j.is_lt)) ≫ δ j.succ = δ j ≫ δ i := by rw [δ_comp_δ] · rfl · exact H #align simplex_category.δ_comp_δ'' SimplexCategory.δ_comp_δ'' /-- The special case of the first simplicial identity -/ @[reassoc] theorem δ_comp_δ_self {n} {i : Fin (n + 2)} : δ i ≫ δ (Fin.castSucc i) = δ i ≫ δ i.succ := (δ_comp_δ (le_refl i)).symm #align simplex_category.δ_comp_δ_self SimplexCategory.δ_comp_δ_self @[reassoc] theorem δ_comp_δ_self' {n} {i : Fin (n + 2)} {j : Fin (n + 3)} (H : j = Fin.castSucc i) : δ i ≫ δ j = δ i ≫ δ i.succ := by subst H rw [δ_comp_δ_self] #align simplex_category.δ_comp_δ_self' SimplexCategory.δ_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) : δ (Fin.castSucc i) ≫ σ j.succ = σ j ≫ δ i := by ext k : 3 dsimp [σ, δ] rcases le_or_lt i k with (hik | hik) · rw [Fin.succAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hik), Fin.succ_predAbove_succ, Fin.succAbove_of_le_castSucc] rcases le_or_lt k (j.castSucc) with (hjk | hjk) · rwa [Fin.predAbove_of_le_castSucc _ _ hjk, Fin.castSucc_castPred] · rw [Fin.le_castSucc_iff, Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.succ_pred] exact H.trans_lt hjk · rw [Fin.succAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hik)] have hjk := H.trans_lt' hik rw [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr (hjk.trans (Fin.castSucc_lt_succ _)).le), Fin.predAbove_of_le_castSucc _ _ hjk.le, Fin.castPred_castSucc, Fin.succAbove_of_castSucc_lt, Fin.castSucc_castPred] rwa [Fin.castSucc_castPred] #align simplex_category.δ_comp_σ_of_le SimplexCategory.δ_comp_σ_of_le /-- The first part of the third simplicial identity -/ @[reassoc] theorem δ_comp_σ_self {n} {i : Fin (n + 1)} : δ (Fin.castSucc i) ≫ σ i = 𝟙 ([n] : SimplexCategory) := by rcases i with ⟨i, hi⟩ ext ⟨j, hj⟩ simp? at hj says simp only [len_mk] at hj dsimp [σ, δ, Fin.predAbove, Fin.succAbove] simp only [Fin.lt_iff_val_lt_val, Fin.dite_val, Fin.ite_val, Fin.coe_pred, ge_iff_le, Fin.coe_castLT, dite_eq_ite] split_ifs any_goals simp all_goals omega #align simplex_category.δ_comp_σ_self SimplexCategory.δ_comp_σ_self @[reassoc] theorem δ_comp_σ_self' {n} {j : Fin (n + 2)} {i : Fin (n + 1)} (H : j = Fin.castSucc i) : δ j ≫ σ i = 𝟙 ([n] : SimplexCategory) := by subst H rw [δ_comp_σ_self] #align simplex_category.δ_comp_σ_self' SimplexCategory.δ_comp_σ_self' /-- The second part of the third simplicial identity -/ @[reassoc] theorem δ_comp_σ_succ {n} {i : Fin (n + 1)} : δ i.succ ≫ σ i = 𝟙 ([n] : SimplexCategory) := by ext j rcases i with ⟨i, _⟩ rcases j with ⟨j, _⟩ dsimp [δ, σ, Fin.succAbove, Fin.predAbove] split_ifs <;> simp <;> simp at * <;> omega #align simplex_category.δ_comp_σ_succ SimplexCategory.δ_comp_σ_succ @[reassoc] theorem δ_comp_σ_succ' {n} (j : Fin (n + 2)) (i : Fin (n + 1)) (H : j = i.succ) : δ j ≫ σ i = 𝟙 ([n] : SimplexCategory) := by subst H rw [δ_comp_σ_succ] #align simplex_category.δ_comp_σ_succ' SimplexCategory.δ_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) : δ i.succ ≫ σ (Fin.castSucc j) = σ j ≫ δ i := by ext k : 3 dsimp [δ, σ] rcases le_or_lt k i with (hik | hik) · rw [Fin.succAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_succ_iff.mpr hik)] rcases le_or_lt k (j.castSucc) with (hjk | hjk) · rw [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hjk), Fin.castPred_castSucc, Fin.predAbove_of_le_castSucc _ _ hjk, Fin.succAbove_of_castSucc_lt, Fin.castSucc_castPred] rw [Fin.castSucc_castPred] exact hjk.trans_lt H · rw [Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hjk), Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.succAbove_of_castSucc_lt, Fin.castSucc_pred_eq_pred_castSucc] rwa [Fin.castSucc_lt_iff_succ_le, Fin.succ_pred] · rw [Fin.succAbove_of_le_castSucc _ _ (Fin.succ_le_castSucc_iff.mpr hik)] have hjk := H.trans hik rw [Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_succ_iff.mpr hjk.le), Fin.pred_succ, Fin.succAbove_of_le_castSucc, Fin.succ_pred] rwa [Fin.le_castSucc_pred_iff] #align simplex_category.δ_comp_σ_of_gt SimplexCategory.δ_comp_σ_of_gt @[reassoc] theorem δ_comp_σ_of_gt' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : j.succ < i) : δ i ≫ σ j = σ (j.castLT ((add_lt_add_iff_right 1).mp (lt_of_lt_of_le H i.is_le))) ≫ δ (i.pred fun (hi : i = 0) => by simp only [Fin.not_lt_zero, hi] at H) := by rw [← δ_comp_σ_of_gt] · simp · rw [Fin.castSucc_castLT, ← Fin.succ_lt_succ_iff, Fin.succ_pred] exact H #align simplex_category.δ_comp_σ_of_gt' SimplexCategory.δ_comp_σ_of_gt' /-- The fifth simplicial identity -/ @[reassoc] theorem σ_comp_σ {n} {i j : Fin (n + 1)} (H : i ≤ j) : σ (Fin.castSucc i) ≫ σ j = σ j.succ ≫ σ i := by ext k : 3 dsimp [σ] cases' k using Fin.lastCases with k · simp only [len_mk, Fin.predAbove_right_last] · cases' k using Fin.cases with k · rw [Fin.castSucc_zero, Fin.predAbove_of_le_castSucc _ 0 (Fin.zero_le _), Fin.predAbove_of_le_castSucc _ _ (Fin.zero_le _), Fin.castPred_zero, Fin.predAbove_of_le_castSucc _ 0 (Fin.zero_le _), Fin.predAbove_of_le_castSucc _ _ (Fin.zero_le _)] · rcases le_or_lt i k with (h | h) · simp_rw [Fin.predAbove_of_castSucc_lt i.castSucc _ (Fin.castSucc_lt_castSucc_iff.mpr (Fin.castSucc_lt_succ_iff.mpr h)), ← Fin.succ_castSucc, Fin.pred_succ, Fin.succ_predAbove_succ] rw [Fin.predAbove_of_castSucc_lt i _ (Fin.castSucc_lt_succ_iff.mpr _), Fin.pred_succ] rcases le_or_lt k j with (hkj | hkj) · rwa [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hkj), Fin.castPred_castSucc] · rw [Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hkj), Fin.le_pred_iff, Fin.succ_le_castSucc_iff] exact H.trans_lt hkj · simp_rw [Fin.predAbove_of_le_castSucc i.castSucc _ (Fin.castSucc_le_castSucc_iff.mpr (Fin.succ_le_castSucc_iff.mpr h)), Fin.castPred_castSucc, ← Fin.succ_castSucc, Fin.succ_predAbove_succ] rw [Fin.predAbove_of_le_castSucc _ k.castSucc (Fin.castSucc_le_castSucc_iff.mpr (h.le.trans H)), Fin.castPred_castSucc, Fin.predAbove_of_le_castSucc _ k.succ (Fin.succ_le_castSucc_iff.mpr (H.trans_lt' h)), Fin.predAbove_of_le_castSucc _ k.succ (Fin.succ_le_castSucc_iff.mpr h)] #align simplex_category.σ_comp_σ SimplexCategory.σ_comp_σ /-- If `f : [m] ⟶ [n+1]` is a morphism and `j` is not in the range of `f`, then `factor_δ f j` is a morphism `[m] ⟶ [n]` such that `factor_δ f j ≫ δ j = f` (as witnessed by `factor_δ_spec`). -/ def factor_δ {m n : ℕ} (f : ([m] : SimplexCategory) ⟶ [n+1]) (j : Fin (n+2)) : ([m] : SimplexCategory) ⟶ [n] := f ≫ σ (Fin.predAbove 0 j) open Fin in lemma factor_δ_spec {m n : ℕ} (f : ([m] : SimplexCategory) ⟶ [n+1]) (j : Fin (n+2)) (hj : ∀ (k : Fin (m+1)), f.toOrderHom k ≠ j) : factor_δ f j ≫ δ j = f := by ext k : 3 specialize hj k dsimp [factor_δ, δ, σ] cases' j using cases with j · rw [predAbove_of_le_castSucc _ _ (zero_le _), castPred_zero, predAbove_of_castSucc_lt 0 _ (castSucc_zero ▸ pos_of_ne_zero hj), zero_succAbove, succ_pred] · rw [predAbove_of_castSucc_lt 0 _ (castSucc_zero ▸ succ_pos _), pred_succ] rcases hj.lt_or_lt with (hj | hj) · rw [predAbove_of_le_castSucc j _] swap · exact (le_castSucc_iff.mpr hj) · rw [succAbove_of_castSucc_lt] swap · rwa [castSucc_lt_succ_iff, castPred_le_iff, le_castSucc_iff] rw [castSucc_castPred] · rw [predAbove_of_castSucc_lt] swap · exact (castSucc_lt_succ _).trans hj rw [succAbove_of_le_castSucc] swap · rwa [succ_le_castSucc_iff, lt_pred_iff] rw [succ_pred] end Generators section Skeleton /-- The functor that exhibits `SimplexCategory` as skeleton of `NonemptyFinLinOrd` -/ @[simps obj map] def skeletalFunctor : SimplexCategory ⥤ NonemptyFinLinOrd where obj a := NonemptyFinLinOrd.of (Fin (a.len + 1)) map f := f.toOrderHom #align simplex_category.skeletal_functor SimplexCategory.skeletalFunctor theorem skeletalFunctor.coe_map {Δ₁ Δ₂ : SimplexCategory} (f : Δ₁ ⟶ Δ₂) : ↑(skeletalFunctor.map f) = f.toOrderHom := rfl #align simplex_category.skeletal_functor.coe_map SimplexCategory.skeletalFunctor.coe_map theorem skeletal : Skeletal SimplexCategory := fun X Y ⟨I⟩ => by suffices Fintype.card (Fin (X.len + 1)) = Fintype.card (Fin (Y.len + 1)) by ext simpa apply Fintype.card_congr exact ((skeletalFunctor ⋙ forget NonemptyFinLinOrd).mapIso I).toEquiv #align simplex_category.skeletal SimplexCategory.skeletal namespace SkeletalFunctor instance : skeletalFunctor.Full where map_surjective f := ⟨SimplexCategory.Hom.mk f, rfl⟩ instance : skeletalFunctor.Faithful where map_injective {_ _ f g} h := by ext1 exact h instance : skeletalFunctor.EssSurj where mem_essImage X := ⟨mk (Fintype.card X - 1 : ℕ), ⟨by have aux : Fintype.card X = Fintype.card X - 1 + 1 := (Nat.succ_pred_eq_of_pos <| Fintype.card_pos_iff.mpr ⟨⊥⟩).symm let f := monoEquivOfFin X aux have hf := (Finset.univ.orderEmbOfFin aux).strictMono refine { hom := ⟨f, hf.monotone⟩ inv := ⟨f.symm, ?_⟩ hom_inv_id := by ext1; apply f.symm_apply_apply inv_hom_id := by ext1; apply f.apply_symm_apply } intro i j h show f.symm i ≤ f.symm j rw [← hf.le_iff_le] show f (f.symm i) ≤ f (f.symm j) simpa only [OrderIso.apply_symm_apply]⟩⟩ noncomputable instance isEquivalence : skeletalFunctor.IsEquivalence where #align simplex_category.skeletal_functor.is_equivalence SimplexCategory.SkeletalFunctor.isEquivalence end SkeletalFunctor /-- The equivalence that exhibits `SimplexCategory` as skeleton of `NonemptyFinLinOrd` -/ noncomputable def skeletalEquivalence : SimplexCategory ≌ NonemptyFinLinOrd := Functor.asEquivalence skeletalFunctor #align simplex_category.skeletal_equivalence SimplexCategory.skeletalEquivalence end Skeleton /-- `SimplexCategory` is a skeleton of `NonemptyFinLinOrd`. -/ lemma isSkeletonOf : IsSkeletonOf NonemptyFinLinOrd SimplexCategory skeletalFunctor where skel := skeletal eqv := SkeletalFunctor.isEquivalence #align simplex_category.is_skeleton_of SimplexCategory.isSkeletonOf /-- The truncated simplex category. -/ def Truncated (n : ℕ) := FullSubcategory fun a : SimplexCategory => a.len ≤ n #align simplex_category.truncated SimplexCategory.Truncated instance (n : ℕ) : SmallCategory.{0} (Truncated n) := FullSubcategory.category _ namespace Truncated instance {n} : Inhabited (Truncated n) := ⟨⟨[0], by simp⟩⟩ /-- The fully faithful inclusion of the truncated simplex category into the usual simplex category. -/ def inclusion {n : ℕ} : SimplexCategory.Truncated n ⥤ SimplexCategory := fullSubcategoryInclusion _ #align simplex_category.truncated.inclusion SimplexCategory.Truncated.inclusion instance (n : ℕ) : (inclusion : Truncated n ⥤ _).Full := FullSubcategory.full _ instance (n : ℕ) : (inclusion : Truncated n ⥤ _).Faithful := FullSubcategory.faithful _ end Truncated section Concrete instance : ConcreteCategory.{0} SimplexCategory where forget := { obj := fun i => Fin (i.len + 1) map := fun f => f.toOrderHom } forget_faithful := ⟨fun h => by ext : 2; exact h⟩ end Concrete section EpiMono /-- A morphism in `SimplexCategory` is a monomorphism precisely when it is an injective function -/ theorem mono_iff_injective {n m : SimplexCategory} {f : n ⟶ m} : Mono f ↔ Function.Injective f.toOrderHom := by rw [← Functor.mono_map_iff_mono skeletalEquivalence.functor] dsimp only [skeletalEquivalence, Functor.asEquivalence_functor] simp only [skeletalFunctor_obj, skeletalFunctor_map, NonemptyFinLinOrd.mono_iff_injective, NonemptyFinLinOrd.coe_of] #align simplex_category.mono_iff_injective SimplexCategory.mono_iff_injective /-- A morphism in `SimplexCategory` is an epimorphism if and only if it is a surjective function -/
Mathlib/AlgebraicTopology/SimplexCategory.lean
563
568
theorem epi_iff_surjective {n m : SimplexCategory} {f : n ⟶ m} : Epi f ↔ Function.Surjective f.toOrderHom := by
rw [← Functor.epi_map_iff_epi skeletalEquivalence.functor] dsimp only [skeletalEquivalence, Functor.asEquivalence_functor] simp only [skeletalFunctor_obj, skeletalFunctor_map, NonemptyFinLinOrd.epi_iff_surjective, NonemptyFinLinOrd.coe_of]
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Topology.Basic import Mathlib.Order.UpperLower.Basic import Mathlib.Order.OmegaCompletePartialOrder #align_import topology.omega_complete_partial_order from "leanprover-community/mathlib"@"2705404e701abc6b3127da906f40bae062a169c9" /-! # Scott Topological Spaces A type of topological spaces whose notion of continuity is equivalent to continuity in ωCPOs. ## Reference * https://ncatlab.org/nlab/show/Scott+topology -/ open Set OmegaCompletePartialOrder open scoped Classical universe u -- "Scott", "ωSup" set_option linter.uppercaseLean3 false namespace Scott /-- `x` is an `ω`-Sup of a chain `c` if it is the least upper bound of the range of `c`. -/ def IsωSup {α : Type u} [Preorder α] (c : Chain α) (x : α) : Prop := (∀ i, c i ≤ x) ∧ ∀ y, (∀ i, c i ≤ y) → x ≤ y #align Scott.is_ωSup Scott.IsωSup theorem isωSup_iff_isLUB {α : Type u} [Preorder α] {c : Chain α} {x : α} : IsωSup c x ↔ IsLUB (range c) x := by simp [IsωSup, IsLUB, IsLeast, upperBounds, lowerBounds] #align Scott.is_ωSup_iff_is_lub Scott.isωSup_iff_isLUB variable (α : Type u) [OmegaCompletePartialOrder α] /-- The characteristic function of open sets is monotone and preserves the limits of chains. -/ def IsOpen (s : Set α) : Prop := Continuous' fun x ↦ x ∈ s #align Scott.is_open Scott.IsOpen theorem isOpen_univ : IsOpen α univ := ⟨fun _ _ _ _ ↦ mem_univ _, @CompleteLattice.top_continuous α Prop _ _⟩ #align Scott.is_open_univ Scott.isOpen_univ theorem IsOpen.inter (s t : Set α) : IsOpen α s → IsOpen α t → IsOpen α (s ∩ t) := CompleteLattice.inf_continuous' #align Scott.is_open.inter Scott.IsOpen.inter theorem isOpen_sUnion (s : Set (Set α)) (hs : ∀ t ∈ s, IsOpen α t) : IsOpen α (⋃₀ s) := by simp only [IsOpen] at hs ⊢ convert CompleteLattice.sSup_continuous' (setOf ⁻¹' s) hs simp only [sSup_apply, setOf_bijective.surjective.exists, exists_prop, mem_preimage, SetCoe.exists, iSup_Prop_eq, mem_setOf_eq, mem_sUnion] #align Scott.is_open_sUnion Scott.isOpen_sUnion theorem IsOpen.isUpperSet {s : Set α} (hs : IsOpen α s) : IsUpperSet s := hs.fst end Scott /-- A Scott topological space is defined on preorders such that their open sets, seen as a function `α → Prop`, preserves the joins of ω-chains -/ abbrev Scott (α : Type u) := α #align Scott Scott instance Scott.topologicalSpace (α : Type u) [OmegaCompletePartialOrder α] : TopologicalSpace (Scott α) where IsOpen := Scott.IsOpen α isOpen_univ := Scott.isOpen_univ α isOpen_inter := Scott.IsOpen.inter α isOpen_sUnion := Scott.isOpen_sUnion α #align Scott.topological_space Scott.topologicalSpace section notBelow variable {α : Type*} [OmegaCompletePartialOrder α] (y : Scott α) /-- `notBelow` is an open set in `Scott α` used to prove the monotonicity of continuous functions -/ def notBelow := { x | ¬x ≤ y } #align not_below notBelow theorem notBelow_isOpen : IsOpen (notBelow y) := by have h : Monotone (notBelow y) := fun x z hle ↦ mt hle.trans refine ⟨h, fun c ↦ eq_of_forall_ge_iff fun z ↦ ?_⟩ simp only [ωSup_le_iff, notBelow, mem_setOf_eq, le_Prop_eq, OrderHom.coe_mk, Chain.map_coe, Function.comp_apply, exists_imp, not_forall] #align not_below_is_open notBelow_isOpen end notBelow open Scott hiding IsOpen open OmegaCompletePartialOrder
Mathlib/Topology/OmegaCompletePartialOrder.lean
110
113
theorem isωSup_ωSup {α} [OmegaCompletePartialOrder α] (c : Chain α) : IsωSup c (ωSup c) := by
constructor · apply le_ωSup · apply ωSup_le
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Johan Commelin, Bhavik Mehta -/ import Mathlib.CategoryTheory.Equivalence #align_import category_theory.adjunction.basic from "leanprover-community/mathlib"@"d101e93197bb5f6ea89bd7ba386b7f7dff1f3903" /-! # Adjunctions between functors `F ⊣ G` represents the data of an adjunction between two functors `F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint. We provide various useful constructors: * `mkOfHomEquiv` * `mkOfUnitCounit` * `leftAdjointOfEquiv` / `rightAdjointOfEquiv` construct a left/right adjoint of a given functor given the action on objects and the relevant equivalence of morphism spaces. * `adjunctionOfEquivLeft` / `adjunctionOfEquivRight` witness that these constructions give adjunctions. There are also typeclasses `IsLeftAdjoint` / `IsRightAdjoint`, which asserts the existence of a adjoint functor. Given `[F.IsLeftAdjoint]`, a chosen right adjoint can be obtained as `F.rightAdjoint`. `Adjunction.comp` composes adjunctions. `toEquivalence` upgrades an adjunction to an equivalence, given witnesses that the unit and counit are pointwise isomorphisms. Conversely `Equivalence.toAdjunction` recovers the underlying adjunction from an equivalence. -/ namespace CategoryTheory open Category -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ u₁ u₂ u₃ -- Porting Note: `elab_without_expected_type` cannot be a local attribute -- attribute [local elab_without_expected_type] whiskerLeft whiskerRight variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] /-- `F ⊣ G` represents the data of an adjunction between two functors `F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint. To construct an `adjunction` between two functors, it's often easier to instead use the constructors `mkOfHomEquiv` or `mkOfUnitCounit`. To construct a left adjoint, there are also constructors `leftAdjointOfEquiv` and `adjunctionOfEquivLeft` (as well as their duals) which can be simpler in practice. Uniqueness of adjoints is shown in `CategoryTheory.Adjunction.Opposites`. See <https://stacks.math.columbia.edu/tag/0037>. -/ structure Adjunction (F : C ⥤ D) (G : D ⥤ C) where /-- The equivalence between `Hom (F X) Y` and `Hom X (G Y)` coming from an adjunction -/ homEquiv : ∀ X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y) /-- The unit of an adjunction -/ unit : 𝟭 C ⟶ F.comp G /-- The counit of an adjunction -/ counit : G.comp F ⟶ 𝟭 D -- Porting note: It's strange that this `Prop` is being flagged by the `docBlame` linter /-- Naturality of the unit of an adjunction -/ homEquiv_unit : ∀ {X Y f}, (homEquiv X Y) f = (unit : _ ⟶ _).app X ≫ G.map f := by aesop_cat -- Porting note: It's strange that this `Prop` is being flagged by the `docBlame` linter /-- Naturality of the counit of an adjunction -/ homEquiv_counit : ∀ {X Y g}, (homEquiv X Y).symm g = F.map g ≫ counit.app Y := by aesop_cat #align category_theory.adjunction CategoryTheory.Adjunction #align category_theory.adjunction.hom_equiv CategoryTheory.Adjunction.homEquiv #align category_theory.adjunction.hom_equiv_unit CategoryTheory.Adjunction.homEquiv_unit #align category_theory.adjunction.hom_equiv_unit' CategoryTheory.Adjunction.homEquiv_unit #align category_theory.adjunction.hom_equiv_counit CategoryTheory.Adjunction.homEquiv_counit #align category_theory.adjunction.hom_equiv_counit' CategoryTheory.Adjunction.homEquiv_counit /-- The notation `F ⊣ G` stands for `Adjunction F G` representing that `F` is left adjoint to `G` -/ infixl:15 " ⊣ " => Adjunction namespace Functor /-- A class asserting the existence of a right adjoint. -/ class IsLeftAdjoint (left : C ⥤ D) : Prop where exists_rightAdjoint : ∃ (right : D ⥤ C), Nonempty (left ⊣ right) #align category_theory.is_left_adjoint CategoryTheory.Functor.IsLeftAdjoint /-- A class asserting the existence of a left adjoint. -/ class IsRightAdjoint (right : D ⥤ C) : Prop where exists_leftAdjoint : ∃ (left : C ⥤ D), Nonempty (left ⊣ right) #align category_theory.is_right_adjoint CategoryTheory.Functor.IsRightAdjoint /-- A chosen left adjoint to a functor that is a right adjoint. -/ noncomputable def leftAdjoint (R : D ⥤ C) [IsRightAdjoint R] : C ⥤ D := (IsRightAdjoint.exists_leftAdjoint (right := R)).choose #align category_theory.left_adjoint CategoryTheory.Functor.leftAdjoint /-- A chosen right adjoint to a functor that is a left adjoint. -/ noncomputable def rightAdjoint (L : C ⥤ D) [IsLeftAdjoint L] : D ⥤ C := (IsLeftAdjoint.exists_rightAdjoint (left := L)).choose #align category_theory.right_adjoint CategoryTheory.Functor.rightAdjoint end Functor /-- The adjunction associated to a functor known to be a left adjoint. -/ noncomputable def Adjunction.ofIsLeftAdjoint (left : C ⥤ D) [left.IsLeftAdjoint] : left ⊣ left.rightAdjoint := Functor.IsLeftAdjoint.exists_rightAdjoint.choose_spec.some #align category_theory.adjunction.of_left_adjoint CategoryTheory.Adjunction.ofIsLeftAdjoint /-- The adjunction associated to a functor known to be a right adjoint. -/ noncomputable def Adjunction.ofIsRightAdjoint (right : C ⥤ D) [right.IsRightAdjoint] : right.leftAdjoint ⊣ right := Functor.IsRightAdjoint.exists_leftAdjoint.choose_spec.some #align category_theory.adjunction.of_right_adjoint CategoryTheory.Adjunction.ofIsRightAdjoint namespace Adjunction -- Porting note: Workaround not needed in Lean 4 -- restate_axiom homEquiv_unit' -- restate_axiom homEquiv_counit' attribute [simp] homEquiv_unit homEquiv_counit section variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) lemma isLeftAdjoint : F.IsLeftAdjoint := ⟨_, ⟨adj⟩⟩ lemma isRightAdjoint : G.IsRightAdjoint := ⟨_, ⟨adj⟩⟩ instance (R : D ⥤ C) [R.IsRightAdjoint] : R.leftAdjoint.IsLeftAdjoint := (ofIsRightAdjoint R).isLeftAdjoint instance (L : C ⥤ D) [L.IsLeftAdjoint] : L.rightAdjoint.IsRightAdjoint := (ofIsLeftAdjoint L).isRightAdjoint variable {X' X : C} {Y Y' : D} theorem homEquiv_id (X : C) : adj.homEquiv X _ (𝟙 _) = adj.unit.app X := by simp #align category_theory.adjunction.hom_equiv_id CategoryTheory.Adjunction.homEquiv_id theorem homEquiv_symm_id (X : D) : (adj.homEquiv _ X).symm (𝟙 _) = adj.counit.app X := by simp #align category_theory.adjunction.hom_equiv_symm_id CategoryTheory.Adjunction.homEquiv_symm_id /- Porting note: `nolint simpNF` as the linter was complaining that this was provable using `simp` but it is in fact not. Also the `docBlame` linter expects a docstring even though this is `Prop` valued -/ @[simp, nolint simpNF] theorem homEquiv_naturality_left_symm (f : X' ⟶ X) (g : X ⟶ G.obj Y) : (adj.homEquiv X' Y).symm (f ≫ g) = F.map f ≫ (adj.homEquiv X Y).symm g := by rw [homEquiv_counit, F.map_comp, assoc, adj.homEquiv_counit.symm] #align category_theory.adjunction.hom_equiv_naturality_left_symm CategoryTheory.Adjunction.homEquiv_naturality_left_symm -- Porting note: Same as above @[simp, nolint simpNF] theorem homEquiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) : (adj.homEquiv X' Y) (F.map f ≫ g) = f ≫ (adj.homEquiv X Y) g := by rw [← Equiv.eq_symm_apply] simp only [Equiv.symm_apply_apply,eq_self_iff_true,homEquiv_naturality_left_symm] #align category_theory.adjunction.hom_equiv_naturality_left CategoryTheory.Adjunction.homEquiv_naturality_left -- Porting note: Same as above @[simp, nolint simpNF] theorem homEquiv_naturality_right (f : F.obj X ⟶ Y) (g : Y ⟶ Y') : (adj.homEquiv X Y') (f ≫ g) = (adj.homEquiv X Y) f ≫ G.map g := by rw [homEquiv_unit, G.map_comp, ← assoc, ← homEquiv_unit] #align category_theory.adjunction.hom_equiv_naturality_right CategoryTheory.Adjunction.homEquiv_naturality_right -- Porting note: Same as above @[simp, nolint simpNF] theorem homEquiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (adj.homEquiv X Y').symm (f ≫ G.map g) = (adj.homEquiv X Y).symm f ≫ g := by rw [Equiv.symm_apply_eq] simp only [homEquiv_naturality_right,eq_self_iff_true,Equiv.apply_symm_apply] #align category_theory.adjunction.hom_equiv_naturality_right_symm CategoryTheory.Adjunction.homEquiv_naturality_right_symm @[reassoc] theorem homEquiv_naturality_left_square (f : X' ⟶ X) (g : F.obj X ⟶ Y') (h : F.obj X' ⟶ Y) (k : Y ⟶ Y') (w : F.map f ≫ g = h ≫ k) : f ≫ (adj.homEquiv X Y') g = (adj.homEquiv X' Y) h ≫ G.map k := by rw [← homEquiv_naturality_left, ← homEquiv_naturality_right, w] @[reassoc] theorem homEquiv_naturality_right_square (f : X' ⟶ X) (g : X ⟶ G.obj Y') (h : X' ⟶ G.obj Y) (k : Y ⟶ Y') (w : f ≫ g = h ≫ G.map k) : F.map f ≫ (adj.homEquiv X Y').symm g = (adj.homEquiv X' Y).symm h ≫ k := by rw [← homEquiv_naturality_left_symm, ← homEquiv_naturality_right_symm, w] theorem homEquiv_naturality_left_square_iff (f : X' ⟶ X) (g : F.obj X ⟶ Y') (h : F.obj X' ⟶ Y) (k : Y ⟶ Y') : (f ≫ (adj.homEquiv X Y') g = (adj.homEquiv X' Y) h ≫ G.map k) ↔ (F.map f ≫ g = h ≫ k) := ⟨fun w ↦ by simpa only [Equiv.symm_apply_apply] using homEquiv_naturality_right_square adj _ _ _ _ w, homEquiv_naturality_left_square adj f g h k⟩ theorem homEquiv_naturality_right_square_iff (f : X' ⟶ X) (g : X ⟶ G.obj Y') (h : X' ⟶ G.obj Y) (k : Y ⟶ Y') : (F.map f ≫ (adj.homEquiv X Y').symm g = (adj.homEquiv X' Y).symm h ≫ k) ↔ (f ≫ g = h ≫ G.map k) := ⟨fun w ↦ by simpa only [Equiv.apply_symm_apply] using homEquiv_naturality_left_square adj _ _ _ _ w, homEquiv_naturality_right_square adj f g h k⟩ @[simp] theorem left_triangle : whiskerRight adj.unit F ≫ whiskerLeft F adj.counit = 𝟙 _ := by ext; dsimp erw [← adj.homEquiv_counit, Equiv.symm_apply_eq, adj.homEquiv_unit] simp #align category_theory.adjunction.left_triangle CategoryTheory.Adjunction.left_triangle @[simp]
Mathlib/CategoryTheory/Adjunction/Basic.lean
221
224
theorem right_triangle : whiskerLeft G adj.unit ≫ whiskerRight adj.counit G = 𝟙 _ := by
ext; dsimp erw [← adj.homEquiv_unit, ← Equiv.eq_symm_apply, adj.homEquiv_counit] simp
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Lu-Ming Zhang -/ import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Combinatorics.SimpleGraph.Connectivity import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.LinearAlgebra.Matrix.Symmetric #align_import combinatorics.simple_graph.adj_matrix from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Adjacency Matrices This module defines the adjacency matrix of a graph, and provides theorems connecting graph properties to computational properties of the matrix. ## Main definitions * `Matrix.IsAdjMatrix`: `A : Matrix V V α` is qualified as an "adjacency matrix" if (1) every entry of `A` is `0` or `1`, (2) `A` is symmetric, (3) every diagonal entry of `A` is `0`. * `Matrix.IsAdjMatrix.to_graph`: for `A : Matrix V V α` and `h : A.IsAdjMatrix`, `h.to_graph` is the simple graph induced by `A`. * `Matrix.compl`: for `A : Matrix V V α`, `A.compl` is supposed to be the adjacency matrix of the complement graph of the graph induced by `A`. * `SimpleGraph.adjMatrix`: the adjacency matrix of a `SimpleGraph`. * `SimpleGraph.adjMatrix_pow_apply_eq_card_walk`: each entry of the `n`th power of a graph's adjacency matrix counts the number of length-`n` walks between the corresponding pair of vertices. -/ open Matrix open Finset Matrix SimpleGraph variable {V α β : Type*} namespace Matrix /-- `A : Matrix V V α` is qualified as an "adjacency matrix" if (1) every entry of `A` is `0` or `1`, (2) `A` is symmetric, (3) every diagonal entry of `A` is `0`. -/ structure IsAdjMatrix [Zero α] [One α] (A : Matrix V V α) : Prop where zero_or_one : ∀ i j, A i j = 0 ∨ A i j = 1 := by aesop symm : A.IsSymm := by aesop apply_diag : ∀ i, A i i = 0 := by aesop #align matrix.is_adj_matrix Matrix.IsAdjMatrix namespace IsAdjMatrix variable {A : Matrix V V α} @[simp] theorem apply_diag_ne [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i : V) : ¬A i i = 1 := by simp [h.apply_diag i] #align matrix.is_adj_matrix.apply_diag_ne Matrix.IsAdjMatrix.apply_diag_ne @[simp] theorem apply_ne_one_iff [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i j : V) : ¬A i j = 1 ↔ A i j = 0 := by obtain h | h := h.zero_or_one i j <;> simp [h] #align matrix.is_adj_matrix.apply_ne_one_iff Matrix.IsAdjMatrix.apply_ne_one_iff @[simp] theorem apply_ne_zero_iff [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i j : V) : ¬A i j = 0 ↔ A i j = 1 := by rw [← apply_ne_one_iff h, Classical.not_not] #align matrix.is_adj_matrix.apply_ne_zero_iff Matrix.IsAdjMatrix.apply_ne_zero_iff /-- For `A : Matrix V V α` and `h : IsAdjMatrix A`, `h.toGraph` is the simple graph whose adjacency matrix is `A`. -/ @[simps] def toGraph [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) : SimpleGraph V where Adj i j := A i j = 1 symm i j hij := by simp only; rwa [h.symm.apply i j] loopless i := by simp [h] #align matrix.is_adj_matrix.to_graph Matrix.IsAdjMatrix.toGraph instance [MulZeroOneClass α] [Nontrivial α] [DecidableEq α] (h : IsAdjMatrix A) : DecidableRel h.toGraph.Adj := by simp only [toGraph] infer_instance end IsAdjMatrix /-- For `A : Matrix V V α`, `A.compl` is supposed to be the adjacency matrix of the complement graph of the graph induced by `A.adjMatrix`. -/ def compl [Zero α] [One α] [DecidableEq α] [DecidableEq V] (A : Matrix V V α) : Matrix V V α := fun i j => ite (i = j) 0 (ite (A i j = 0) 1 0) #align matrix.compl Matrix.compl section Compl variable [DecidableEq α] [DecidableEq V] (A : Matrix V V α) @[simp] theorem compl_apply_diag [Zero α] [One α] (i : V) : A.compl i i = 0 := by simp [compl] #align matrix.compl_apply_diag Matrix.compl_apply_diag @[simp] theorem compl_apply [Zero α] [One α] (i j : V) : A.compl i j = 0 ∨ A.compl i j = 1 := by unfold compl split_ifs <;> simp #align matrix.compl_apply Matrix.compl_apply @[simp] theorem isSymm_compl [Zero α] [One α] (h : A.IsSymm) : A.compl.IsSymm := by ext simp [compl, h.apply, eq_comm] #align matrix.is_symm_compl Matrix.isSymm_compl @[simp] theorem isAdjMatrix_compl [Zero α] [One α] (h : A.IsSymm) : IsAdjMatrix A.compl := { symm := by simp [h] } #align matrix.is_adj_matrix_compl Matrix.isAdjMatrix_compl namespace IsAdjMatrix variable {A} @[simp] theorem compl [Zero α] [One α] (h : IsAdjMatrix A) : IsAdjMatrix A.compl := isAdjMatrix_compl A h.symm #align matrix.is_adj_matrix.compl Matrix.IsAdjMatrix.compl theorem toGraph_compl_eq [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) : h.compl.toGraph = h.toGraphᶜ := by ext v w cases' h.zero_or_one v w with h h <;> by_cases hvw : v = w <;> simp [Matrix.compl, h, hvw] #align matrix.is_adj_matrix.to_graph_compl_eq Matrix.IsAdjMatrix.toGraph_compl_eq end IsAdjMatrix end Compl end Matrix open Matrix namespace SimpleGraph variable (G : SimpleGraph V) [DecidableRel G.Adj] variable (α) /-- `adjMatrix G α` is the matrix `A` such that `A i j = (1 : α)` if `i` and `j` are adjacent in the simple graph `G`, and otherwise `A i j = 0`. -/ def adjMatrix [Zero α] [One α] : Matrix V V α := of fun i j => if G.Adj i j then (1 : α) else 0 #align simple_graph.adj_matrix SimpleGraph.adjMatrix variable {α} -- TODO: set as an equation lemma for `adjMatrix`, see mathlib4#3024 @[simp] theorem adjMatrix_apply (v w : V) [Zero α] [One α] : G.adjMatrix α v w = if G.Adj v w then 1 else 0 := rfl #align simple_graph.adj_matrix_apply SimpleGraph.adjMatrix_apply @[simp] theorem transpose_adjMatrix [Zero α] [One α] : (G.adjMatrix α)ᵀ = G.adjMatrix α := by ext simp [adj_comm] #align simple_graph.transpose_adj_matrix SimpleGraph.transpose_adjMatrix @[simp] theorem isSymm_adjMatrix [Zero α] [One α] : (G.adjMatrix α).IsSymm := transpose_adjMatrix G #align simple_graph.is_symm_adj_matrix SimpleGraph.isSymm_adjMatrix variable (α) /-- The adjacency matrix of `G` is an adjacency matrix. -/ @[simp] theorem isAdjMatrix_adjMatrix [Zero α] [One α] : (G.adjMatrix α).IsAdjMatrix := { zero_or_one := fun i j => by by_cases h : G.Adj i j <;> simp [h] } #align simple_graph.is_adj_matrix_adj_matrix SimpleGraph.isAdjMatrix_adjMatrix /-- The graph induced by the adjacency matrix of `G` is `G` itself. -/ theorem toGraph_adjMatrix_eq [MulZeroOneClass α] [Nontrivial α] : (G.isAdjMatrix_adjMatrix α).toGraph = G := by ext simp only [IsAdjMatrix.toGraph_adj, adjMatrix_apply, ite_eq_left_iff, zero_ne_one] apply Classical.not_not #align simple_graph.to_graph_adj_matrix_eq SimpleGraph.toGraph_adjMatrix_eq variable {α} [Fintype V] @[simp] theorem adjMatrix_dotProduct [NonAssocSemiring α] (v : V) (vec : V → α) : dotProduct (G.adjMatrix α v) vec = ∑ u ∈ G.neighborFinset v, vec u := by simp [neighborFinset_eq_filter, dotProduct, sum_filter] #align simple_graph.adj_matrix_dot_product SimpleGraph.adjMatrix_dotProduct @[simp] theorem dotProduct_adjMatrix [NonAssocSemiring α] (v : V) (vec : V → α) : dotProduct vec (G.adjMatrix α v) = ∑ u ∈ G.neighborFinset v, vec u := by simp [neighborFinset_eq_filter, dotProduct, sum_filter, Finset.sum_apply] #align simple_graph.dot_product_adj_matrix SimpleGraph.dotProduct_adjMatrix @[simp] theorem adjMatrix_mulVec_apply [NonAssocSemiring α] (v : V) (vec : V → α) : (G.adjMatrix α *ᵥ vec) v = ∑ u ∈ G.neighborFinset v, vec u := by rw [mulVec, adjMatrix_dotProduct] #align simple_graph.adj_matrix_mul_vec_apply SimpleGraph.adjMatrix_mulVec_apply @[simp] theorem adjMatrix_vecMul_apply [NonAssocSemiring α] (v : V) (vec : V → α) : (vec ᵥ* G.adjMatrix α) v = ∑ u ∈ G.neighborFinset v, vec u := by simp only [← dotProduct_adjMatrix, vecMul] refine congr rfl ?_; ext x rw [← transpose_apply (adjMatrix α G) x v, transpose_adjMatrix] #align simple_graph.adj_matrix_vec_mul_apply SimpleGraph.adjMatrix_vecMul_apply @[simp] theorem adjMatrix_mul_apply [NonAssocSemiring α] (M : Matrix V V α) (v w : V) : (G.adjMatrix α * M) v w = ∑ u ∈ G.neighborFinset v, M u w := by simp [mul_apply, neighborFinset_eq_filter, sum_filter] #align simple_graph.adj_matrix_mul_apply SimpleGraph.adjMatrix_mul_apply @[simp] theorem mul_adjMatrix_apply [NonAssocSemiring α] (M : Matrix V V α) (v w : V) : (M * G.adjMatrix α) v w = ∑ u ∈ G.neighborFinset w, M v u := by simp [mul_apply, neighborFinset_eq_filter, sum_filter, adj_comm] #align simple_graph.mul_adj_matrix_apply SimpleGraph.mul_adjMatrix_apply variable (α) @[simp] theorem trace_adjMatrix [AddCommMonoid α] [One α] : Matrix.trace (G.adjMatrix α) = 0 := by simp [Matrix.trace] #align simple_graph.trace_adj_matrix SimpleGraph.trace_adjMatrix variable {α}
Mathlib/Combinatorics/SimpleGraph/AdjMatrix.lean
244
245
theorem adjMatrix_mul_self_apply_self [NonAssocSemiring α] (i : V) : (G.adjMatrix α * G.adjMatrix α) i i = degree G i := by
simp [filter_true_of_mem]
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Jujian Zhang -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.RingTheory.Localization.Basic #align_import algebra.module.localized_module from "leanprover-community/mathlib"@"831c494092374cfe9f50591ed0ac81a25efc5b86" /-! # Localized Module Given a commutative semiring `R`, a multiplicative subset `S ⊆ R` and an `R`-module `M`, we can localize `M` by `S`. This gives us a `Localization S`-module. ## Main definitions * `LocalizedModule.r` : the equivalence relation defining this localization, namely `(m, s) ≈ (m', s')` if and only if there is some `u : S` such that `u • s' • m = u • s • m'`. * `LocalizedModule M S` : the localized module by `S`. * `LocalizedModule.mk` : the canonical map sending `(m, s) : M × S ↦ m/s : LocalizedModule M S` * `LocalizedModule.liftOn` : any well defined function `f : M × S → α` respecting `r` descents to a function `LocalizedModule M S → α` * `LocalizedModule.liftOn₂` : any well defined function `f : M × S → M × S → α` respecting `r` descents to a function `LocalizedModule M S → LocalizedModule M S` * `LocalizedModule.mk_add_mk` : in the localized module `mk m s + mk m' s' = mk (s' • m + s • m') (s * s')` * `LocalizedModule.mk_smul_mk` : in the localized module, for any `r : R`, `s t : S`, `m : M`, we have `mk r s • mk m t = mk (r • m) (s * t)` where `mk r s : Localization S` is localized ring by `S`. * `LocalizedModule.isModule` : `LocalizedModule M S` is a `Localization S`-module. ## Future work * Redefine `Localization` for monoids and rings to coincide with `LocalizedModule`. -/ namespace LocalizedModule universe u v variable {R : Type u} [CommSemiring R] (S : Submonoid R) variable (M : Type v) [AddCommMonoid M] [Module R M] variable (T : Type*) [CommSemiring T] [Algebra R T] [IsLocalization S T] /-- The equivalence relation on `M × S` where `(m1, s1) ≈ (m2, s2)` if and only if for some (u : S), u * (s2 • m1 - s1 • m2) = 0-/ /- Porting note: We use small letter `r` since `R` is used for a ring. -/ def r (a b : M × S) : Prop := ∃ u : S, u • b.2 • a.1 = u • a.2 • b.1 #align localized_module.r LocalizedModule.r theorem r.isEquiv : IsEquiv _ (r S M) := { refl := fun ⟨m, s⟩ => ⟨1, by rw [one_smul]⟩ trans := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m3, s3⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => by use u1 * u2 * s2 -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s3) • ·) hu1.symm have hu2' := congr_arg ((u1 * s1) • ·) hu2.symm simp only [← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu2', hu1'] symm := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => ⟨u, hu.symm⟩ } #align localized_module.r.is_equiv LocalizedModule.r.isEquiv instance r.setoid : Setoid (M × S) where r := r S M iseqv := ⟨(r.isEquiv S M).refl, (r.isEquiv S M).symm _ _, (r.isEquiv S M).trans _ _ _⟩ #align localized_module.r.setoid LocalizedModule.r.setoid -- TODO: change `Localization` to use `r'` instead of `r` so that the two types are also defeq, -- `Localization S = LocalizedModule S R`. example {R} [CommSemiring R] (S : Submonoid R) : ⇑(Localization.r' S) = LocalizedModule.r S R := rfl /-- If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then we can localize `M` by `S`. -/ -- Porting note(#5171): @[nolint has_nonempty_instance] def _root_.LocalizedModule : Type max u v := Quotient (r.setoid S M) #align localized_module LocalizedModule section variable {M S} /-- The canonical map sending `(m, s) ↦ m/s`-/ def mk (m : M) (s : S) : LocalizedModule S M := Quotient.mk' ⟨m, s⟩ #align localized_module.mk LocalizedModule.mk theorem mk_eq {m m' : M} {s s' : S} : mk m s = mk m' s' ↔ ∃ u : S, u • s' • m = u • s • m' := Quotient.eq' #align localized_module.mk_eq LocalizedModule.mk_eq @[elab_as_elim] theorem induction_on {β : LocalizedModule S M → Prop} (h : ∀ (m : M) (s : S), β (mk m s)) : ∀ x : LocalizedModule S M, β x := by rintro ⟨⟨m, s⟩⟩ exact h m s #align localized_module.induction_on LocalizedModule.induction_on @[elab_as_elim] theorem induction_on₂ {β : LocalizedModule S M → LocalizedModule S M → Prop} (h : ∀ (m m' : M) (s s' : S), β (mk m s) (mk m' s')) : ∀ x y, β x y := by rintro ⟨⟨m, s⟩⟩ ⟨⟨m', s'⟩⟩ exact h m m' s s' #align localized_module.induction_on₂ LocalizedModule.induction_on₂ /-- If `f : M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → α`. -/ def liftOn {α : Type*} (x : LocalizedModule S M) (f : M × S → α) (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') : α := Quotient.liftOn x f wd #align localized_module.lift_on LocalizedModule.liftOn theorem liftOn_mk {α : Type*} {f : M × S → α} (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') (m : M) (s : S) : liftOn (mk m s) f wd = f ⟨m, s⟩ := by convert Quotient.liftOn_mk f wd ⟨m, s⟩ #align localized_module.lift_on_mk LocalizedModule.liftOn_mk /-- If `f : M × S → M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → LocalizedModule M S → α`. -/ def liftOn₂ {α : Type*} (x y : LocalizedModule S M) (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') : α := Quotient.liftOn₂ x y f wd #align localized_module.lift_on₂ LocalizedModule.liftOn₂ theorem liftOn₂_mk {α : Type*} (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') (m m' : M) (s s' : S) : liftOn₂ (mk m s) (mk m' s') f wd = f ⟨m, s⟩ ⟨m', s'⟩ := by convert Quotient.liftOn₂_mk f wd _ _ #align localized_module.lift_on₂_mk LocalizedModule.liftOn₂_mk instance : Zero (LocalizedModule S M) := ⟨mk 0 1⟩ /-- If `S` contains `0` then the localization at `S` is trivial. -/ theorem subsingleton (h : 0 ∈ S) : Subsingleton (LocalizedModule S M) := by refine ⟨fun a b ↦ ?_⟩ induction a,b using LocalizedModule.induction_on₂ exact mk_eq.mpr ⟨⟨0, h⟩, by simp only [Submonoid.mk_smul, zero_smul]⟩ @[simp] theorem zero_mk (s : S) : mk (0 : M) s = 0 := mk_eq.mpr ⟨1, by rw [one_smul, smul_zero, smul_zero, one_smul]⟩ #align localized_module.zero_mk LocalizedModule.zero_mk instance : Add (LocalizedModule S M) where add p1 p2 := liftOn₂ p1 p2 (fun x y => mk (y.2 • x.1 + x.2 • y.1) (x.2 * y.2)) <| fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m1', s1'⟩ ⟨m2', s2'⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => mk_eq.mpr ⟨u1 * u2, by -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s2 * s2') • ·) hu1 have hu2' := congr_arg ((u1 * s1 * s1') • ·) hu2 simp only [smul_add, ← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu1', hu2']⟩ theorem mk_add_mk {m1 m2 : M} {s1 s2 : S} : mk m1 s1 + mk m2 s2 = mk (s2 • m1 + s1 • m2) (s1 * s2) := mk_eq.mpr <| ⟨1, rfl⟩ #align localized_module.mk_add_mk LocalizedModule.mk_add_mk /-- Porting note: Some auxiliary lemmas are declared with `private` in the original mathlib3 file. We take that policy here as well, and remove the `#align` lines accordingly. -/ private theorem add_assoc' (x y z : LocalizedModule S M) : x + y + z = x + (y + z) := by induction' x using LocalizedModule.induction_on with mx sx induction' y using LocalizedModule.induction_on with my sy induction' z using LocalizedModule.induction_on with mz sz simp only [mk_add_mk, smul_add] refine mk_eq.mpr ⟨1, ?_⟩ rw [one_smul, one_smul] congr 1 · rw [mul_assoc] · rw [eq_comm, mul_comm, add_assoc, mul_smul, mul_smul, ← mul_smul sx sz, mul_comm, mul_smul] private theorem add_comm' (x y : LocalizedModule S M) : x + y = y + x := LocalizedModule.induction_on₂ (fun m m' s s' => by rw [mk_add_mk, mk_add_mk, add_comm, mul_comm]) x y private theorem zero_add' (x : LocalizedModule S M) : 0 + x = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, zero_add, mk_eq]; exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x private theorem add_zero' (x : LocalizedModule S M) : x + 0 = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, add_zero, mk_eq]; exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x instance hasNatSMul : SMul ℕ (LocalizedModule S M) where smul n := nsmulRec n #align localized_module.has_nat_smul LocalizedModule.hasNatSMul private theorem nsmul_zero' (x : LocalizedModule S M) : (0 : ℕ) • x = 0 := LocalizedModule.induction_on (fun _ _ => rfl) x private theorem nsmul_succ' (n : ℕ) (x : LocalizedModule S M) : n.succ • x = n • x + x := LocalizedModule.induction_on (fun _ _ => rfl) x instance : AddCommMonoid (LocalizedModule S M) where add := (· + ·) add_assoc := add_assoc' zero := 0 zero_add := zero_add' add_zero := add_zero' nsmul := (· • ·) nsmul_zero := nsmul_zero' nsmul_succ := nsmul_succ' add_comm := add_comm' instance {M : Type*} [AddCommGroup M] [Module R M] : Neg (LocalizedModule S M) where neg p := liftOn p (fun x => LocalizedModule.mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩ instance {M : Type*} [AddCommGroup M] [Module R M] : AddCommGroup (LocalizedModule S M) := { show AddCommMonoid (LocalizedModule S M) by infer_instance with add_left_neg := by rintro ⟨m, s⟩ change (liftOn (mk m s) (fun x => mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩) + mk m s = 0 rw [liftOn_mk, mk_add_mk] simp -- TODO: fix the diamond zsmul := zsmulRec } theorem mk_neg {M : Type*} [AddCommGroup M] [Module R M] {m : M} {s : S} : mk (-m) s = -mk m s := rfl #align localized_module.mk_neg LocalizedModule.mk_neg instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Monoid (LocalizedModule S A) := { mul := fun m₁ m₂ => liftOn₂ m₁ m₂ (fun x₁ x₂ => LocalizedModule.mk (x₁.1 * x₂.1) (x₁.2 * x₂.2)) (by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨b₁, t₁⟩ ⟨b₂, t₂⟩ ⟨u₁, e₁⟩ ⟨u₂, e₂⟩ rw [mk_eq] use u₁ * u₂ dsimp only at e₁ e₂ ⊢ rw [eq_comm] trans (u₁ • t₁ • a₁) • u₂ • t₂ • a₂ on_goal 1 => rw [e₁, e₂] on_goal 2 => rw [eq_comm] all_goals rw [smul_smul, mul_mul_mul_comm, ← smul_eq_mul, ← smul_eq_mul A, smul_smul_smul_comm, mul_smul, mul_smul]) one := mk 1 (1 : S) one_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [one_mul, one_smul]⟩ mul_one := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_one, one_smul]⟩ mul_assoc := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_smul, ← mul_assoc, mul_right_comm] } instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Semiring (LocalizedModule S A) := { show (AddCommMonoid (LocalizedModule S A)) by infer_instance, show (Monoid (LocalizedModule S A)) by infer_instance with left_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, mul_add, mul_smul_comm, smul_smul, ← mul_assoc, mul_right_comm] right_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, add_mul, smul_smul, ← mul_assoc, smul_mul_assoc, mul_right_comm] zero_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [zero_mul, smul_zero]⟩ mul_zero := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_zero, smul_zero]⟩ } instance {A : Type*} [CommSemiring A] [Algebra R A] {S : Submonoid R} : CommSemiring (LocalizedModule S A) := { show Semiring (LocalizedModule S A) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } instance {A : Type*} [Ring A] [Algebra R A] {S : Submonoid R} : Ring (LocalizedModule S A) := { inferInstanceAs (AddCommGroup (LocalizedModule S A)), inferInstanceAs (Semiring (LocalizedModule S A)) with } instance {A : Type*} [CommRing A] [Algebra R A] {S : Submonoid R} : CommRing (LocalizedModule S A) := { show (Ring (LocalizedModule S A)) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } theorem mk_mul_mk {A : Type*} [Semiring A] [Algebra R A] {a₁ a₂ : A} {s₁ s₂ : S} : mk a₁ s₁ * mk a₂ s₂ = mk (a₁ * a₂) (s₁ * s₂) := rfl #align localized_module.mk_mul_mk LocalizedModule.mk_mul_mk noncomputable instance : SMul T (LocalizedModule S M) where smul x p := let a := IsLocalization.sec S x liftOn p (fun p ↦ mk (a.1 • p.1) (a.2 * p.2)) (by rintro p p' ⟨s, h⟩ refine mk_eq.mpr ⟨s, ?_⟩ calc _ = a.2 • a.1 • s • p'.2 • p.1 := by simp_rw [Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul]; ring_nf _ = a.2 • a.1 • s • p.2 • p'.1 := by rw [h] _ = s • (a.2 * p.2) • a.1 • p'.1 := by simp_rw [Submonoid.smul_def, ← mul_smul, Submonoid.coe_mul]; ring_nf ) theorem smul_def (x : T) (m : M) (s : S) : x • mk m s = mk ((IsLocalization.sec S x).1 • m) ((IsLocalization.sec S x).2 * s) := rfl theorem mk'_smul_mk (r : R) (m : M) (s s' : S) : IsLocalization.mk' T r s • mk m s' = mk (r • m) (s * s') := by rw [smul_def, mk_eq] obtain ⟨c, hc⟩ := IsLocalization.eq.mp <| IsLocalization.mk'_sec T (IsLocalization.mk' T r s) use c simp_rw [← mul_smul, Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul, ← mul_assoc, mul_comm _ (s':R), mul_assoc, hc] theorem mk_smul_mk (r : R) (m : M) (s t : S) : Localization.mk r s • mk m t = mk (r • m) (s * t) := by rw [Localization.mk_eq_mk'] exact mk'_smul_mk .. #align localized_module.mk_smul_mk LocalizedModule.mk_smul_mk variable {T} private theorem one_smul_aux (p : LocalizedModule S M) : (1 : T) • p = p := by induction' p using LocalizedModule.induction_on with m s rw [show (1:T) = IsLocalization.mk' T (1:R) (1:S) by rw [IsLocalization.mk'_one, map_one]] rw [mk'_smul_mk, one_smul, one_mul] private theorem mul_smul_aux (x y : T) (p : LocalizedModule S M) : (x * y) • p = x • y • p := by induction' p using LocalizedModule.induction_on with m s rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y] simp_rw [← IsLocalization.mk'_mul, mk'_smul_mk, ← mul_smul, mul_assoc] private theorem smul_add_aux (x : T) (p q : LocalizedModule S M) : x • (p + q) = x • p + x • q := by induction' p using LocalizedModule.induction_on with m s induction' q using LocalizedModule.induction_on with n t rw [smul_def, smul_def, mk_add_mk, mk_add_mk] rw [show x • _ = IsLocalization.mk' T _ _ • _ by rw [IsLocalization.mk'_sec (M := S) T]] rw [← IsLocalization.mk'_cancel _ _ (IsLocalization.sec S x).2, mk'_smul_mk] congr 1 · simp only [Submonoid.smul_def, smul_add, ← mul_smul, Submonoid.coe_mul]; ring_nf · rw [mul_mul_mul_comm] -- ring does not work here private theorem smul_zero_aux (x : T) : x • (0 : LocalizedModule S M) = 0 := by erw [smul_def, smul_zero, zero_mk] private theorem add_smul_aux (x y : T) (p : LocalizedModule S M) : (x + y) • p = x • p + y • p := by induction' p using LocalizedModule.induction_on with m s rw [smul_def T x, smul_def T y, mk_add_mk, show (x + y) • _ = IsLocalization.mk' T _ _ • _ by rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y, ← IsLocalization.mk'_add, IsLocalization.mk'_cancel _ _ s], mk'_smul_mk, ← smul_assoc, ← smul_assoc, ← add_smul] congr 1 · simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_eq_mul]; ring_nf · rw [mul_mul_mul_comm, mul_assoc] -- ring does not work here private theorem zero_smul_aux (p : LocalizedModule S M) : (0 : T) • p = 0 := by induction' p using LocalizedModule.induction_on with m s rw [show (0:T) = IsLocalization.mk' T (0:R) (1:S) by rw [IsLocalization.mk'_zero], mk'_smul_mk, zero_smul, zero_mk] noncomputable instance isModule : Module T (LocalizedModule S M) where smul := (· • ·) one_smul := one_smul_aux mul_smul := mul_smul_aux smul_add := smul_add_aux smul_zero := smul_zero_aux add_smul := add_smul_aux zero_smul := zero_smul_aux @[simp] theorem mk_cancel_common_left (s' s : S) (m : M) : mk (s' • m) (s' * s) = mk m s := mk_eq.mpr ⟨1, by simp only [mul_smul, one_smul] rw [smul_comm]⟩ #align localized_module.mk_cancel_common_left LocalizedModule.mk_cancel_common_left @[simp] theorem mk_cancel (s : S) (m : M) : mk (s • m) s = mk m 1 := mk_eq.mpr ⟨1, by simp⟩ #align localized_module.mk_cancel LocalizedModule.mk_cancel @[simp] theorem mk_cancel_common_right (s s' : S) (m : M) : mk (s' • m) (s * s') = mk m s := mk_eq.mpr ⟨1, by simp [mul_smul]⟩ #align localized_module.mk_cancel_common_right LocalizedModule.mk_cancel_common_right noncomputable instance isModule' : Module R (LocalizedModule S M) := { Module.compHom (LocalizedModule S M) <| algebraMap R (Localization S) with } #align localized_module.is_module' LocalizedModule.isModule' theorem smul'_mk (r : R) (s : S) (m : M) : r • mk m s = mk (r • m) s := by erw [mk_smul_mk r m 1 s, one_mul] #align localized_module.smul'_mk LocalizedModule.smul'_mk theorem smul'_mul {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : x • p₁ * p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [mk_mul_mk, smul_def, smul_def, mk_mul_mk, mul_assoc, smul_mul_assoc] theorem mul_smul' {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : p₁ * x • p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [smul_def, mk_mul_mk, mk_mul_mk, smul_def, mul_left_comm, mul_smul_comm] variable (T) noncomputable instance {A : Type*} [Semiring A] [Algebra R A] : Algebra T (LocalizedModule S A) := Algebra.ofModule smul'_mul mul_smul' theorem algebraMap_mk' {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (IsLocalization.mk' T a s) = mk (algebraMap R A a) s := by rw [Algebra.algebraMap_eq_smul_one] change _ • mk _ _ = _ rw [mk'_smul_mk, Algebra.algebraMap_eq_smul_one, mul_one] theorem algebraMap_mk {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (Localization.mk a s) = mk (algebraMap R A a) s := by rw [Localization.mk_eq_mk'] exact algebraMap_mk' .. #align localized_module.algebra_map_mk LocalizedModule.algebraMap_mk instance : IsScalarTower R T (LocalizedModule S M) where smul_assoc r x p := by induction' p using LocalizedModule.induction_on with m s rw [← IsLocalization.mk'_sec (M := S) T x, IsLocalization.smul_mk', mk'_smul_mk, mk'_smul_mk, smul'_mk, mul_smul] noncomputable instance algebra' {A : Type*} [Semiring A] [Algebra R A] : Algebra R (LocalizedModule S A) := { (algebraMap (Localization S) (LocalizedModule S A)).comp (algebraMap R <| Localization S), show Module R (LocalizedModule S A) by infer_instance with commutes' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, mk_mul_mk, mul_comm, Algebra.commutes] smul_def' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, smul'_mk, Algebra.smul_def, one_mul] } #align localized_module.algebra' LocalizedModule.algebra' section variable (S M) /-- The function `m ↦ m / 1` as an `R`-linear map. -/ @[simps] def mkLinearMap : M →ₗ[R] LocalizedModule S M where toFun m := mk m 1 map_add' x y := by simp [mk_add_mk] map_smul' r x := (smul'_mk _ _ _).symm #align localized_module.mk_linear_map LocalizedModule.mkLinearMap end /-- For any `s : S`, there is an `R`-linear map given by `a/b ↦ a/(b*s)`. -/ @[simps] def divBy (s : S) : LocalizedModule S M →ₗ[R] LocalizedModule S M where toFun p := p.liftOn (fun p => mk p.1 (p.2 * s)) fun ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩ => mk_eq.mpr ⟨c, by rw [mul_smul, mul_smul, smul_comm _ s, smul_comm _ s, eq1, smul_comm _ s, smul_comm _ s]⟩ map_add' x y := by refine x.induction_on₂ ?_ y intro m₁ m₂ t₁ t₂ simp_rw [mk_add_mk, LocalizedModule.liftOn_mk, mk_add_mk, mul_smul, mul_comm _ s, mul_assoc, smul_comm _ s, ← smul_add, mul_left_comm s t₁ t₂, mk_cancel_common_left s] map_smul' r x := by refine x.induction_on (fun _ _ ↦ ?_) dsimp only change liftOn (mk _ _) _ _ = r • (liftOn (mk _ _) _ _) simp_rw [liftOn_mk, mul_assoc, ← smul_def] congr! #align localized_module.div_by LocalizedModule.divBy theorem divBy_mul_by (s : S) (p : LocalizedModule S M) : divBy s (algebraMap R (Module.End R (LocalizedModule S M)) s p) = p := p.induction_on fun m t => by rw [Module.algebraMap_end_apply, divBy_apply] erw [smul_def] rw [LocalizedModule.liftOn_mk, mul_assoc, ← smul_def] erw [smul'_mk] rw [← Submonoid.smul_def, mk_cancel_common_right _ s] #align localized_module.div_by_mul_by LocalizedModule.divBy_mul_by theorem mul_by_divBy (s : S) (p : LocalizedModule S M) : algebraMap R (Module.End R (LocalizedModule S M)) s (divBy s p) = p := p.induction_on fun m t => by rw [divBy_apply, Module.algebraMap_end_apply, LocalizedModule.liftOn_mk, smul'_mk, ← Submonoid.smul_def, mk_cancel_common_right _ s] #align localized_module.mul_by_div_by LocalizedModule.mul_by_divBy end end LocalizedModule section IsLocalizedModule universe u v variable {R : Type*} [CommSemiring R] (S : Submonoid R) variable {M M' M'' : Type*} [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable {A : Type*} [CommSemiring A] [Algebra R A] [Module A M'] [IsLocalization S A] variable [Module R M] [Module R M'] [Module R M''] [IsScalarTower R A M'] variable (f : M →ₗ[R] M') (g : M →ₗ[R] M'') /-- The characteristic predicate for localized module. `IsLocalizedModule S f` describes that `f : M ⟶ M'` is the localization map identifying `M'` as `LocalizedModule S M`. -/ @[mk_iff] class IsLocalizedModule : Prop where map_units : ∀ x : S, IsUnit (algebraMap R (Module.End R M') x) surj' : ∀ y : M', ∃ x : M × S, x.2 • y = f x.1 exists_of_eq : ∀ {x₁ x₂}, f x₁ = f x₂ → ∃ c : S, c • x₁ = c • x₂ #align is_localized_module IsLocalizedModule attribute [nolint docBlame] IsLocalizedModule.map_units IsLocalizedModule.surj' IsLocalizedModule.exists_of_eq -- Porting note: Manually added to make `S` and `f` explicit. lemma IsLocalizedModule.surj [IsLocalizedModule S f] (y : M') : ∃ x : M × S, x.2 • y = f x.1 := surj' y -- Porting note: Manually added to make `S` and `f` explicit. lemma IsLocalizedModule.eq_iff_exists [IsLocalizedModule S f] {x₁ x₂} : f x₁ = f x₂ ↔ ∃ c : S, c • x₁ = c • x₂ := Iff.intro exists_of_eq fun ⟨c, h⟩ ↦ by apply_fun f at h simp_rw [f.map_smul_of_tower, Submonoid.smul_def, ← Module.algebraMap_end_apply R R] at h exact ((Module.End_isUnit_iff _).mp <| map_units f c).1 h theorem IsLocalizedModule.of_linearEquiv (e : M' ≃ₗ[R] M'') [hf : IsLocalizedModule S f] : IsLocalizedModule S (e ∘ₗ f : M →ₗ[R] M'') where map_units s := by rw [show algebraMap R (Module.End R M'') s = e ∘ₗ (algebraMap R (Module.End R M') s) ∘ₗ e.symm by ext; simp, Module.End_isUnit_iff, LinearMap.coe_comp, LinearMap.coe_comp, LinearEquiv.coe_coe, LinearEquiv.coe_coe, EquivLike.comp_bijective, EquivLike.bijective_comp] exact (Module.End_isUnit_iff _).mp <| hf.map_units s surj' x := by obtain ⟨p, h⟩ := hf.surj' (e.symm x) exact ⟨p, by rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, ← e.congr_arg h, Submonoid.smul_def, Submonoid.smul_def, LinearEquiv.map_smul, LinearEquiv.apply_symm_apply]⟩ exists_of_eq h := by simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] at h exact hf.exists_of_eq h variable (M) in lemma isLocalizedModule_id (R') [CommSemiring R'] [Algebra R R'] [IsLocalization S R'] [Module R' M] [IsScalarTower R R' M] : IsLocalizedModule S (.id : M →ₗ[R] M) where map_units s := by rw [← (Algebra.lsmul R (A := R') R M).commutes]; exact (IsLocalization.map_units R' s).map _ surj' m := ⟨(m, 1), one_smul _ _⟩ exists_of_eq h := ⟨1, congr_arg _ h⟩ variable {S} in theorem isLocalizedModule_iff_isLocalization {A Aₛ} [CommSemiring A] [Algebra R A] [CommSemiring Aₛ] [Algebra A Aₛ] [Algebra R Aₛ] [IsScalarTower R A Aₛ] : IsLocalizedModule S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap ↔ IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ := by rw [isLocalizedModule_iff, isLocalization_iff] refine and_congr ?_ (and_congr (forall_congr' fun _ ↦ ?_) (forall₂_congr fun _ _ ↦ ?_)) · simp_rw [← (Algebra.lmul R Aₛ).commutes, Algebra.lmul_isUnit_iff, Subtype.forall, Algebra.algebraMapSubmonoid, ← SetLike.mem_coe, Submonoid.coe_map, Set.forall_mem_image, ← IsScalarTower.algebraMap_apply] · simp_rw [Prod.exists, Subtype.exists, Algebra.algebraMapSubmonoid] simp [← IsScalarTower.algebraMap_apply, Submonoid.mk_smul, Algebra.smul_def, mul_comm] · congr!; simp_rw [Subtype.exists, Algebra.algebraMapSubmonoid]; simp [Algebra.smul_def] instance {A Aₛ} [CommSemiring A] [Algebra R A][CommSemiring Aₛ] [Algebra A Aₛ] [Algebra R Aₛ] [IsScalarTower R A Aₛ] [h : IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ] : IsLocalizedModule S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap := isLocalizedModule_iff_isLocalization.mpr h lemma isLocalizedModule_iff_isLocalization' (R') [CommSemiring R'] [Algebra R R'] : IsLocalizedModule S (Algebra.ofId R R').toLinearMap ↔ IsLocalization S R' := by convert isLocalizedModule_iff_isLocalization (S := S) (A := R) (Aₛ := R') exact (Submonoid.map_id S).symm namespace LocalizedModule /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift' (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) : LocalizedModule S M → M'' := fun m => m.liftOn (fun p => (h p.2).unit⁻¹.val <| g p.1) fun ⟨m, s⟩ ⟨m', s'⟩ ⟨c, eq1⟩ => by -- Porting note: We remove `generalize_proofs h1 h2`. This does nothing here. dsimp only simp only [Submonoid.smul_def] at eq1 rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← map_smul, eq_comm, Module.End_algebraMap_isUnit_inv_apply_eq_iff] have : c • s • g m' = c • s' • g m := by simp only [Submonoid.smul_def, ← g.map_smul, eq1] have : Function.Injective (h c).unit.inv := by rw [Function.injective_iff_hasLeftInverse] refine ⟨(h c).unit, ?_⟩ intro x change ((h c).unit.1 * (h c).unit.inv) x = x simp only [Units.inv_eq_val_inv, IsUnit.mul_val_inv, LinearMap.one_apply] apply_fun (h c).unit.inv erw [Units.inv_eq_val_inv, Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← (h c).unit⁻¹.val.map_smul] symm rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← g.map_smul, ← g.map_smul, ← g.map_smul, ← g.map_smul, eq1] #align localized_module.lift' LocalizedModule.lift' theorem lift'_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (m : M) (s : S) : LocalizedModule.lift' S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl #align localized_module.lift'_mk LocalizedModule.lift'_mk theorem lift'_add (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (x y) : LocalizedModule.lift' S g h (x + y) = LocalizedModule.lift' S g h x + LocalizedModule.lift' S g h y := LocalizedModule.induction_on₂ (by intro a a' b b' erw [LocalizedModule.lift'_mk, LocalizedModule.lift'_mk, LocalizedModule.lift'_mk] -- Porting note: We remove `generalize_proofs h1 h2 h3`. This only generalize `h1`. erw [map_add, Module.End_algebraMap_isUnit_inv_apply_eq_iff, smul_add, ← map_smul, ← map_smul, ← map_smul] congr 1 <;> symm · erw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, mul_smul, ← map_smul] rfl · dsimp erw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, mul_comm, mul_smul, ← map_smul] rfl) x y #align localized_module.lift'_add LocalizedModule.lift'_add theorem lift'_smul (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (r : R) (m) : r • LocalizedModule.lift' S g h m = LocalizedModule.lift' S g h (r • m) := m.induction_on fun a b => by rw [LocalizedModule.lift'_mk, LocalizedModule.smul'_mk, LocalizedModule.lift'_mk] -- Porting note: We remove `generalize_proofs h1 h2`. This does nothing here. rw [← map_smul, ← g.map_smul] #align localized_module.lift'_smul LocalizedModule.lift'_smul /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : LocalizedModule S M →ₗ[R] M'' where toFun := LocalizedModule.lift' S g h map_add' := LocalizedModule.lift'_add S g h map_smul' r x := by rw [LocalizedModule.lift'_smul, RingHom.id_apply] #align localized_module.lift LocalizedModule.lift /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then `lift g m s = s⁻¹ • g m`. -/ theorem lift_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) (m : M) (s : S) : LocalizedModule.lift S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl #align localized_module.lift_mk LocalizedModule.lift_mk /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `lift g ∘ mkLinearMap = g`. -/
Mathlib/Algebra/Module/LocalizedModule.lean
713
716
theorem lift_comp (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : (lift S g h).comp (mkLinearMap S M) = g := by
ext x; dsimp; rw [LocalizedModule.lift_mk] erw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, one_smul]
/- 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]
Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean
118
118
theorem sphere_zero_right (n k : ℕ) : sphere (n + 1) 0 k = ∅ := by
simp [sphere]
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.RingTheory.IntegralClosure import Mathlib.RingTheory.Polynomial.IntegralNormalization #align_import ring_theory.algebraic from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Algebraic elements and algebraic extensions An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial. An R-algebra is algebraic over R if and only if all its elements are algebraic over R. The main result in this file proves transitivity of algebraicity: a tower of algebraic field extensions is algebraic. -/ universe u v w open scoped Classical open Polynomial section variable (R : Type u) {A : Type v} [CommRing R] [Ring A] [Algebra R A] /-- An element of an R-algebra is algebraic over R if it is a root of a nonzero polynomial with coefficients in R. -/ def IsAlgebraic (x : A) : Prop := ∃ p : R[X], p ≠ 0 ∧ aeval x p = 0 #align is_algebraic IsAlgebraic /-- An element of an R-algebra is transcendental over R if it is not algebraic over R. -/ def Transcendental (x : A) : Prop := ¬IsAlgebraic R x #align transcendental Transcendental theorem is_transcendental_of_subsingleton [Subsingleton R] (x : A) : Transcendental R x := fun ⟨p, h, _⟩ => h <| Subsingleton.elim p 0 #align is_transcendental_of_subsingleton is_transcendental_of_subsingleton variable {R} /-- A subalgebra is algebraic if all its elements are algebraic. -/ nonrec def Subalgebra.IsAlgebraic (S : Subalgebra R A) : Prop := ∀ x ∈ S, IsAlgebraic R x #align subalgebra.is_algebraic Subalgebra.IsAlgebraic variable (R A) /-- An algebra is algebraic if all its elements are algebraic. -/ protected class Algebra.IsAlgebraic : Prop := isAlgebraic : ∀ x : A, IsAlgebraic R x #align algebra.is_algebraic Algebra.IsAlgebraic variable {R A} lemma Algebra.isAlgebraic_def : Algebra.IsAlgebraic R A ↔ ∀ x : A, IsAlgebraic R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ /-- A subalgebra is algebraic if and only if it is algebraic as an algebra. -/ theorem Subalgebra.isAlgebraic_iff (S : Subalgebra R A) : S.IsAlgebraic ↔ @Algebra.IsAlgebraic R S _ _ S.algebra := by delta Subalgebra.IsAlgebraic rw [Subtype.forall', Algebra.isAlgebraic_def] refine forall_congr' fun x => exists_congr fun p => and_congr Iff.rfl ?_ have h : Function.Injective S.val := Subtype.val_injective conv_rhs => rw [← h.eq_iff, AlgHom.map_zero] rw [← aeval_algHom_apply, S.val_apply] #align subalgebra.is_algebraic_iff Subalgebra.isAlgebraic_iff /-- An algebra is algebraic if and only if it is algebraic as a subalgebra. -/ theorem Algebra.isAlgebraic_iff : Algebra.IsAlgebraic R A ↔ (⊤ : Subalgebra R A).IsAlgebraic := by delta Subalgebra.IsAlgebraic simp only [Algebra.isAlgebraic_def, Algebra.mem_top, forall_prop_of_true, iff_self_iff] #align algebra.is_algebraic_iff Algebra.isAlgebraic_iff theorem isAlgebraic_iff_not_injective {x : A} : IsAlgebraic R x ↔ ¬Function.Injective (Polynomial.aeval x : R[X] →ₐ[R] A) := by simp only [IsAlgebraic, injective_iff_map_eq_zero, not_forall, and_comm, exists_prop] #align is_algebraic_iff_not_injective isAlgebraic_iff_not_injective end section zero_ne_one variable {R : Type u} {S : Type*} {A : Type v} [CommRing R] variable [CommRing S] [Ring A] [Algebra R A] [Algebra R S] [Algebra S A] variable [IsScalarTower R S A] /-- An integral element of an algebra is algebraic. -/ theorem IsIntegral.isAlgebraic [Nontrivial R] {x : A} : IsIntegral R x → IsAlgebraic R x := fun ⟨p, hp, hpx⟩ => ⟨p, hp.ne_zero, hpx⟩ #align is_integral.is_algebraic IsIntegral.isAlgebraic instance Algebra.IsIntegral.isAlgebraic [Nontrivial R] [Algebra.IsIntegral R A] : Algebra.IsAlgebraic R A := ⟨fun a ↦ (Algebra.IsIntegral.isIntegral a).isAlgebraic⟩ theorem isAlgebraic_zero [Nontrivial R] : IsAlgebraic R (0 : A) := ⟨_, X_ne_zero, aeval_X 0⟩ #align is_algebraic_zero isAlgebraic_zero /-- An element of `R` is algebraic, when viewed as an element of the `R`-algebra `A`. -/ theorem isAlgebraic_algebraMap [Nontrivial R] (x : R) : IsAlgebraic R (algebraMap R A x) := ⟨_, X_sub_C_ne_zero x, by rw [_root_.map_sub, aeval_X, aeval_C, sub_self]⟩ #align is_algebraic_algebra_map isAlgebraic_algebraMap theorem isAlgebraic_one [Nontrivial R] : IsAlgebraic R (1 : A) := by rw [← _root_.map_one (algebraMap R A)] exact isAlgebraic_algebraMap 1 #align is_algebraic_one isAlgebraic_one theorem isAlgebraic_nat [Nontrivial R] (n : ℕ) : IsAlgebraic R (n : A) := by rw [← map_natCast (_ : R →+* A) n] exact isAlgebraic_algebraMap (Nat.cast n) #align is_algebraic_nat isAlgebraic_nat theorem isAlgebraic_int [Nontrivial R] (n : ℤ) : IsAlgebraic R (n : A) := by rw [← _root_.map_intCast (algebraMap R A)] exact isAlgebraic_algebraMap (Int.cast n) #align is_algebraic_int isAlgebraic_int theorem isAlgebraic_rat (R : Type u) {A : Type v} [DivisionRing A] [Field R] [Algebra R A] (n : ℚ) : IsAlgebraic R (n : A) := by rw [← map_ratCast (algebraMap R A)] exact isAlgebraic_algebraMap (Rat.cast n) #align is_algebraic_rat isAlgebraic_rat theorem isAlgebraic_of_mem_rootSet {R : Type u} {A : Type v} [Field R] [Field A] [Algebra R A] {p : R[X]} {x : A} (hx : x ∈ p.rootSet A) : IsAlgebraic R x := ⟨p, ne_zero_of_mem_rootSet hx, aeval_eq_zero_of_mem_rootSet hx⟩ #align is_algebraic_of_mem_root_set isAlgebraic_of_mem_rootSet open IsScalarTower protected theorem IsAlgebraic.algebraMap {a : S} : IsAlgebraic R a → IsAlgebraic R (algebraMap S A a) := fun ⟨f, hf₁, hf₂⟩ => ⟨f, hf₁, by rw [aeval_algebraMap_apply, hf₂, map_zero]⟩ #align is_algebraic_algebra_map_of_is_algebraic IsAlgebraic.algebraMap section variable {B} [Ring B] [Algebra R B] /-- This is slightly more general than `IsAlgebraic.algebraMap` in that it allows noncommutative intermediate rings `A`. -/ protected theorem IsAlgebraic.algHom (f : A →ₐ[R] B) {a : A} (h : IsAlgebraic R a) : IsAlgebraic R (f a) := let ⟨p, hp, ha⟩ := h ⟨p, hp, by rw [aeval_algHom, f.comp_apply, ha, map_zero]⟩ #align is_algebraic_alg_hom_of_is_algebraic IsAlgebraic.algHom theorem isAlgebraic_algHom_iff (f : A →ₐ[R] B) (hf : Function.Injective f) {a : A} : IsAlgebraic R (f a) ↔ IsAlgebraic R a := ⟨fun ⟨p, hp0, hp⟩ ↦ ⟨p, hp0, hf <| by rwa [map_zero, ← f.comp_apply, ← aeval_algHom]⟩, IsAlgebraic.algHom f⟩ theorem Algebra.IsAlgebraic.of_injective (f : A →ₐ[R] B) (hf : Function.Injective f) [Algebra.IsAlgebraic R B] : Algebra.IsAlgebraic R A := ⟨fun _ ↦ (isAlgebraic_algHom_iff f hf).mp (Algebra.IsAlgebraic.isAlgebraic _)⟩ /-- Transfer `Algebra.IsAlgebraic` across an `AlgEquiv`. -/ theorem AlgEquiv.isAlgebraic (e : A ≃ₐ[R] B) [Algebra.IsAlgebraic R A] : Algebra.IsAlgebraic R B := Algebra.IsAlgebraic.of_injective e.symm.toAlgHom e.symm.injective #align alg_equiv.is_algebraic AlgEquiv.isAlgebraic theorem AlgEquiv.isAlgebraic_iff (e : A ≃ₐ[R] B) : Algebra.IsAlgebraic R A ↔ Algebra.IsAlgebraic R B := ⟨fun _ ↦ e.isAlgebraic, fun _ ↦ e.symm.isAlgebraic⟩ #align alg_equiv.is_algebraic_iff AlgEquiv.isAlgebraic_iff end theorem isAlgebraic_algebraMap_iff {a : S} (h : Function.Injective (algebraMap S A)) : IsAlgebraic R (algebraMap S A a) ↔ IsAlgebraic R a := isAlgebraic_algHom_iff (IsScalarTower.toAlgHom R S A) h #align is_algebraic_algebra_map_iff isAlgebraic_algebraMap_iff theorem IsAlgebraic.of_pow {r : A} {n : ℕ} (hn : 0 < n) (ht : IsAlgebraic R (r ^ n)) : IsAlgebraic R r := by obtain ⟨p, p_nonzero, hp⟩ := ht refine ⟨Polynomial.expand _ n p, ?_, ?_⟩ · rwa [Polynomial.expand_ne_zero hn] · rwa [Polynomial.expand_aeval n p r] #align is_algebraic_of_pow IsAlgebraic.of_pow theorem Transcendental.pow {r : A} (ht : Transcendental R r) {n : ℕ} (hn : 0 < n) : Transcendental R (r ^ n) := fun ht' ↦ ht <| ht'.of_pow hn #align transcendental.pow Transcendental.pow lemma IsAlgebraic.invOf {x : S} [Invertible x] (h : IsAlgebraic R x) : IsAlgebraic R (⅟ x) := by obtain ⟨p, hp, hp'⟩ := h refine ⟨p.reverse, by simpa using hp, ?_⟩ rwa [Polynomial.aeval_def, Polynomial.eval₂_reverse_eq_zero_iff, ← Polynomial.aeval_def] lemma IsAlgebraic.invOf_iff {x : S} [Invertible x] : IsAlgebraic R (⅟ x) ↔ IsAlgebraic R x := ⟨IsAlgebraic.invOf, IsAlgebraic.invOf⟩ lemma IsAlgebraic.inv_iff {K} [Field K] [Algebra R K] {x : K} : IsAlgebraic R (x⁻¹) ↔ IsAlgebraic R x := by by_cases hx : x = 0 · simp [hx] letI := invertibleOfNonzero hx exact IsAlgebraic.invOf_iff (R := R) (x := x) alias ⟨_, IsAlgebraic.inv⟩ := IsAlgebraic.inv_iff end zero_ne_one section Field variable {K : Type u} {A : Type v} [Field K] [Ring A] [Algebra K A] /-- An element of an algebra over a field is algebraic if and only if it is integral. -/ theorem isAlgebraic_iff_isIntegral {x : A} : IsAlgebraic K x ↔ IsIntegral K x := by refine ⟨?_, IsIntegral.isAlgebraic⟩ rintro ⟨p, hp, hpx⟩ refine ⟨_, monic_mul_leadingCoeff_inv hp, ?_⟩ rw [← aeval_def, AlgHom.map_mul, hpx, zero_mul] #align is_algebraic_iff_is_integral isAlgebraic_iff_isIntegral protected theorem Algebra.isAlgebraic_iff_isIntegral : Algebra.IsAlgebraic K A ↔ Algebra.IsIntegral K A := by rw [Algebra.isAlgebraic_def, Algebra.isIntegral_def, forall_congr' fun _ ↦ isAlgebraic_iff_isIntegral] #align algebra.is_algebraic_iff_is_integral Algebra.isAlgebraic_iff_isIntegral alias ⟨IsAlgebraic.isIntegral, _⟩ := isAlgebraic_iff_isIntegral /-- This used to be an `alias` of `Algebra.isAlgebraic_iff_isIntegral` but that would make `Algebra.IsAlgebraic K A` an explicit parameter instead of instance implicit. -/ protected instance Algebra.IsAlgebraic.isIntegral [Algebra.IsAlgebraic K A] : Algebra.IsIntegral K A := Algebra.isAlgebraic_iff_isIntegral.mp ‹_› end Field section variable {K L R S A : Type*} section Ring section CommRing variable [CommRing R] [CommRing S] [Ring A] variable [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A] /-- If x is algebraic over R, then x is algebraic over S when S is an extension of R, and the map from `R` to `S` is injective. -/ theorem IsAlgebraic.tower_top_of_injective (hinj : Function.Injective (algebraMap R S)) {x : A} (A_alg : IsAlgebraic R x) : IsAlgebraic S x := let ⟨p, hp₁, hp₂⟩ := A_alg ⟨p.map (algebraMap _ _), by rwa [Ne, ← degree_eq_bot, degree_map_eq_of_injective hinj, degree_eq_bot], by simpa⟩ #align is_algebraic_of_larger_base_of_injective IsAlgebraic.tower_top_of_injective /-- If A is an algebraic algebra over R, then A is algebraic over S when S is an extension of R, and the map from `R` to `S` is injective. -/ theorem Algebra.IsAlgebraic.tower_top_of_injective (hinj : Function.Injective (algebraMap R S)) [Algebra.IsAlgebraic R A] : Algebra.IsAlgebraic S A := ⟨fun _ ↦ _root_.IsAlgebraic.tower_top_of_injective hinj (Algebra.IsAlgebraic.isAlgebraic _)⟩ #align algebra.is_algebraic_of_larger_base_of_injective Algebra.IsAlgebraic.tower_top_of_injective end CommRing section Field variable [Field K] [Field L] [Ring A] variable [Algebra K L] [Algebra L A] [Algebra K A] [IsScalarTower K L A] variable (L) /-- If x is algebraic over K, then x is algebraic over L when L is an extension of K -/ theorem IsAlgebraic.tower_top {x : A} (A_alg : IsAlgebraic K x) : IsAlgebraic L x := A_alg.tower_top_of_injective (algebraMap K L).injective #align is_algebraic_of_larger_base IsAlgebraic.tower_top /-- If A is an algebraic algebra over K, then A is algebraic over L when L is an extension of K -/ theorem Algebra.IsAlgebraic.tower_top [Algebra.IsAlgebraic K A] : Algebra.IsAlgebraic L A := Algebra.IsAlgebraic.tower_top_of_injective (algebraMap K L).injective #align algebra.is_algebraic_of_larger_base Algebra.IsAlgebraic.tower_top variable (K) theorem IsAlgebraic.of_finite (e : A) [FiniteDimensional K A] : IsAlgebraic K e := (IsIntegral.of_finite K e).isAlgebraic variable (A) /-- A field extension is algebraic if it is finite. -/ instance Algebra.IsAlgebraic.of_finite [FiniteDimensional K A] : Algebra.IsAlgebraic K A := (IsIntegral.of_finite K A).isAlgebraic #align algebra.is_algebraic_of_finite Algebra.IsAlgebraic.of_finite end Field end Ring section CommRing variable [Field K] [Field L] [Ring A] variable [Algebra K L] [Algebra L A] [Algebra K A] [IsScalarTower K L A] /-- If L is an algebraic field extension of K and A is an algebraic algebra over L, then A is algebraic over K. -/ protected theorem Algebra.IsAlgebraic.trans [L_alg : Algebra.IsAlgebraic K L] [A_alg : Algebra.IsAlgebraic L A] : Algebra.IsAlgebraic K A := by rw [Algebra.isAlgebraic_iff_isIntegral] at L_alg A_alg ⊢ exact Algebra.IsIntegral.trans L #align algebra.is_algebraic_trans Algebra.IsAlgebraic.trans end CommRing section NoZeroSMulDivisors namespace Algebra.IsAlgebraic variable [CommRing K] [Field L] variable [Algebra K L] [NoZeroSMulDivisors K L] theorem algHom_bijective [Algebra.IsAlgebraic K L] (f : L →ₐ[K] L) : Function.Bijective f := by refine ⟨f.injective, fun b ↦ ?_⟩ obtain ⟨p, hp, he⟩ := Algebra.IsAlgebraic.isAlgebraic (R := K) b let f' : p.rootSet L → p.rootSet L := (rootSet_maps_to' (fun x ↦ x) f).restrict f _ _ have : f'.Surjective := Finite.injective_iff_surjective.1 fun _ _ h ↦ Subtype.eq <| f.injective <| Subtype.ext_iff.1 h obtain ⟨a, ha⟩ := this ⟨b, mem_rootSet.2 ⟨hp, he⟩⟩ exact ⟨a, Subtype.ext_iff.1 ha⟩ #align algebra.is_algebraic.alg_hom_bijective Algebra.IsAlgebraic.algHom_bijective theorem algHom_bijective₂ [Field R] [Algebra K R] [Algebra.IsAlgebraic K L] (f : L →ₐ[K] R) (g : R →ₐ[K] L) : Function.Bijective f ∧ Function.Bijective g := (g.injective.bijective₂_of_surjective f.injective (algHom_bijective <| g.comp f).2).symm theorem bijective_of_isScalarTower [Algebra.IsAlgebraic K L] [Field R] [Algebra K R] [Algebra L R] [IsScalarTower K L R] (f : R →ₐ[K] L) : Function.Bijective f := (algHom_bijective₂ (IsScalarTower.toAlgHom K L R) f).2 theorem bijective_of_isScalarTower' [Field R] [Algebra K R] [NoZeroSMulDivisors K R] [Algebra.IsAlgebraic K R] [Algebra L R] [IsScalarTower K L R] (f : R →ₐ[K] L) : Function.Bijective f := (algHom_bijective₂ f (IsScalarTower.toAlgHom K L R)).1 variable (K L) /-- Bijection between algebra equivalences and algebra homomorphisms -/ @[simps] noncomputable def algEquivEquivAlgHom [Algebra.IsAlgebraic K L] : (L ≃ₐ[K] L) ≃* (L →ₐ[K] L) where toFun ϕ := ϕ.toAlgHom invFun ϕ := AlgEquiv.ofBijective ϕ (algHom_bijective ϕ) left_inv _ := by ext; rfl right_inv _ := by ext; rfl map_mul' _ _ := rfl #align algebra.is_algebraic.alg_equiv_equiv_alg_hom Algebra.IsAlgebraic.algEquivEquivAlgHom end Algebra.IsAlgebraic end NoZeroSMulDivisors section Field variable [Field K] [Field L] variable [Algebra K L] theorem AlgHom.bijective [FiniteDimensional K L] (ϕ : L →ₐ[K] L) : Function.Bijective ϕ := (Algebra.IsAlgebraic.of_finite K L).algHom_bijective ϕ #align alg_hom.bijective AlgHom.bijective variable (K L) /-- Bijection between algebra equivalences and algebra homomorphisms -/ noncomputable abbrev algEquivEquivAlgHom [FiniteDimensional K L] : (L ≃ₐ[K] L) ≃* (L →ₐ[K] L) := Algebra.IsAlgebraic.algEquivEquivAlgHom K L #align alg_equiv_equiv_alg_hom algEquivEquivAlgHom end Field end variable {R S : Type*} [CommRing R] [IsDomain R] [CommRing S] theorem exists_integral_multiple [Algebra R S] {z : S} (hz : IsAlgebraic R z) (inj : ∀ x, algebraMap R S x = 0 → x = 0) : ∃ᵉ (x : integralClosure R S) (y ≠ (0 : R)), z * algebraMap R S y = x := by rcases hz with ⟨p, p_ne_zero, px⟩ set a := p.leadingCoeff have a_ne_zero : a ≠ 0 := mt Polynomial.leadingCoeff_eq_zero.mp p_ne_zero have x_integral : IsIntegral R (z * algebraMap R S a) := ⟨p.integralNormalization, monic_integralNormalization p_ne_zero, integralNormalization_aeval_eq_zero px inj⟩ exact ⟨⟨_, x_integral⟩, a, a_ne_zero, rfl⟩ #align exists_integral_multiple exists_integral_multiple /-- A fraction `(a : S) / (b : S)` can be reduced to `(c : S) / (d : R)`, if `S` is the integral closure of `R` in an algebraic extension `L` of `R`. -/
Mathlib/RingTheory/Algebraic.lean
411
423
theorem IsIntegralClosure.exists_smul_eq_mul {L : Type*} [Field L] [Algebra R S] [Algebra S L] [Algebra R L] [IsScalarTower R S L] [IsIntegralClosure S R L] [Algebra.IsAlgebraic R L] (inj : Function.Injective (algebraMap R L)) (a : S) {b : S} (hb : b ≠ 0) : ∃ᵉ (c : S) (d ≠ (0 : R)), d • a = b * c := by
obtain ⟨c, d, d_ne, hx⟩ := exists_integral_multiple (Algebra.IsAlgebraic.isAlgebraic (algebraMap _ L a / algebraMap _ L b)) ((injective_iff_map_eq_zero _).mp inj) refine ⟨IsIntegralClosure.mk' S (c : L) c.2, d, d_ne, IsIntegralClosure.algebraMap_injective S R L ?_⟩ simp only [Algebra.smul_def, RingHom.map_mul, IsIntegralClosure.algebraMap_mk', ← hx, ← IsScalarTower.algebraMap_apply] rw [← mul_assoc _ (_ / _), mul_div_cancel₀ (algebraMap S L a), mul_comm] exact mt ((injective_iff_map_eq_zero _).mp (IsIntegralClosure.algebraMap_injective S R L) _) hb
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot -/ import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Algebra.Order.Interval.Set.Monoid import Mathlib.Data.Set.Pointwise.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax #align_import data.set.pointwise.interval from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # (Pre)images of intervals In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`, then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove lemmas about preimages and images of all intervals. We also prove a few lemmas about images under `x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`. -/ open Interval Pointwise variable {α : Type*} namespace Set /-! ### Binary pointwise operations Note that the subset operations below only cover the cases with the largest possible intervals on the LHS: to conclude that `Ioo a b * Ioo c d ⊆ Ioo (a * c) (c * d)`, you can use monotonicity of `*` and `Set.Ico_mul_Ioc_subset`. TODO: repeat these lemmas for the generality of `mul_le_mul` (which assumes nonnegativity), which the unprimed names have been reserved for -/ section ContravariantLE variable [Mul α] [Preorder α] variable [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (Function.swap HMul.hMul) LE.le] @[to_additive Icc_add_Icc_subset] theorem Icc_mul_Icc_subset' (a b c d : α) : Icc a b * Icc c d ⊆ Icc (a * c) (b * d) := by rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_le_mul' hyb hzd⟩ @[to_additive Iic_add_Iic_subset] theorem Iic_mul_Iic_subset' (a b : α) : Iic a * Iic b ⊆ Iic (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb @[to_additive Ici_add_Ici_subset] theorem Ici_mul_Ici_subset' (a b : α) : Ici a * Ici b ⊆ Ici (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb end ContravariantLE section ContravariantLT variable [Mul α] [PartialOrder α] variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (Function.swap HMul.hMul) LT.lt] @[to_additive Icc_add_Ico_subset] theorem Icc_mul_Ico_subset' (a b c d : α) : Icc a b * Ico c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Icc_subset] theorem Ico_mul_Icc_subset' (a b c d : α) : Ico a b * Icc c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Ioc_add_Ico_subset] theorem Ioc_mul_Ico_subset' (a b c d : α) : Ioc a b * Ico c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_lt_of_le hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Ioc_subset] theorem Ico_mul_Ioc_subset' (a b c d : α) : Ico a b * Ioc c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_le_of_lt hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Iic_add_Iio_subset] theorem Iic_mul_Iio_subset' (a b : α) : Iic a * Iio b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb @[to_additive Iio_add_Iic_subset] theorem Iio_mul_Iic_subset' (a b : α) : Iio a * Iic b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ioi_add_Ici_subset] theorem Ioi_mul_Ici_subset' (a b : α) : Ioi a * Ici b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ici_add_Ioi_subset] theorem Ici_mul_Ioi_subset' (a b : α) : Ici a * Ioi b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb end ContravariantLT section OrderedAddCommGroup variable [OrderedAddCommGroup α] (a b c : α) /-! ### Preimages under `x ↦ a + x` -/ @[simp] theorem preimage_const_add_Ici : (fun x => a + x) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add'.symm #align set.preimage_const_add_Ici Set.preimage_const_add_Ici @[simp] theorem preimage_const_add_Ioi : (fun x => a + x) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add'.symm #align set.preimage_const_add_Ioi Set.preimage_const_add_Ioi @[simp] theorem preimage_const_add_Iic : (fun x => a + x) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le'.symm #align set.preimage_const_add_Iic Set.preimage_const_add_Iic @[simp] theorem preimage_const_add_Iio : (fun x => a + x) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt'.symm #align set.preimage_const_add_Iio Set.preimage_const_add_Iio @[simp] theorem preimage_const_add_Icc : (fun x => a + x) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_const_add_Icc Set.preimage_const_add_Icc @[simp] theorem preimage_const_add_Ico : (fun x => a + x) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_const_add_Ico Set.preimage_const_add_Ico @[simp] theorem preimage_const_add_Ioc : (fun x => a + x) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_const_add_Ioc Set.preimage_const_add_Ioc @[simp] theorem preimage_const_add_Ioo : (fun x => a + x) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_const_add_Ioo Set.preimage_const_add_Ioo /-! ### Preimages under `x ↦ x + a` -/ @[simp] theorem preimage_add_const_Ici : (fun x => x + a) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add.symm #align set.preimage_add_const_Ici Set.preimage_add_const_Ici @[simp] theorem preimage_add_const_Ioi : (fun x => x + a) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add.symm #align set.preimage_add_const_Ioi Set.preimage_add_const_Ioi @[simp] theorem preimage_add_const_Iic : (fun x => x + a) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le.symm #align set.preimage_add_const_Iic Set.preimage_add_const_Iic @[simp] theorem preimage_add_const_Iio : (fun x => x + a) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt.symm #align set.preimage_add_const_Iio Set.preimage_add_const_Iio @[simp] theorem preimage_add_const_Icc : (fun x => x + a) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_add_const_Icc Set.preimage_add_const_Icc @[simp] theorem preimage_add_const_Ico : (fun x => x + a) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_add_const_Ico Set.preimage_add_const_Ico @[simp] theorem preimage_add_const_Ioc : (fun x => x + a) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_add_const_Ioc Set.preimage_add_const_Ioc @[simp] theorem preimage_add_const_Ioo : (fun x => x + a) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_add_const_Ioo Set.preimage_add_const_Ioo /-! ### Preimages under `x ↦ -x` -/ @[simp] theorem preimage_neg_Ici : -Ici a = Iic (-a) := ext fun _x => le_neg #align set.preimage_neg_Ici Set.preimage_neg_Ici @[simp] theorem preimage_neg_Iic : -Iic a = Ici (-a) := ext fun _x => neg_le #align set.preimage_neg_Iic Set.preimage_neg_Iic @[simp] theorem preimage_neg_Ioi : -Ioi a = Iio (-a) := ext fun _x => lt_neg #align set.preimage_neg_Ioi Set.preimage_neg_Ioi @[simp] theorem preimage_neg_Iio : -Iio a = Ioi (-a) := ext fun _x => neg_lt #align set.preimage_neg_Iio Set.preimage_neg_Iio @[simp] theorem preimage_neg_Icc : -Icc a b = Icc (-b) (-a) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_neg_Icc Set.preimage_neg_Icc @[simp] theorem preimage_neg_Ico : -Ico a b = Ioc (-b) (-a) := by simp [← Ici_inter_Iio, ← Ioi_inter_Iic, inter_comm] #align set.preimage_neg_Ico Set.preimage_neg_Ico @[simp] theorem preimage_neg_Ioc : -Ioc a b = Ico (-b) (-a) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_neg_Ioc Set.preimage_neg_Ioc @[simp] theorem preimage_neg_Ioo : -Ioo a b = Ioo (-b) (-a) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_neg_Ioo Set.preimage_neg_Ioo /-! ### Preimages under `x ↦ x - a` -/ @[simp] theorem preimage_sub_const_Ici : (fun x => x - a) ⁻¹' Ici b = Ici (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ici Set.preimage_sub_const_Ici @[simp] theorem preimage_sub_const_Ioi : (fun x => x - a) ⁻¹' Ioi b = Ioi (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioi Set.preimage_sub_const_Ioi @[simp] theorem preimage_sub_const_Iic : (fun x => x - a) ⁻¹' Iic b = Iic (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iic Set.preimage_sub_const_Iic @[simp] theorem preimage_sub_const_Iio : (fun x => x - a) ⁻¹' Iio b = Iio (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iio Set.preimage_sub_const_Iio @[simp] theorem preimage_sub_const_Icc : (fun x => x - a) ⁻¹' Icc b c = Icc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Icc Set.preimage_sub_const_Icc @[simp] theorem preimage_sub_const_Ico : (fun x => x - a) ⁻¹' Ico b c = Ico (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ico Set.preimage_sub_const_Ico @[simp] theorem preimage_sub_const_Ioc : (fun x => x - a) ⁻¹' Ioc b c = Ioc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioc Set.preimage_sub_const_Ioc @[simp] theorem preimage_sub_const_Ioo : (fun x => x - a) ⁻¹' Ioo b c = Ioo (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioo Set.preimage_sub_const_Ioo /-! ### Preimages under `x ↦ a - x` -/ @[simp] theorem preimage_const_sub_Ici : (fun x => a - x) ⁻¹' Ici b = Iic (a - b) := ext fun _x => le_sub_comm #align set.preimage_const_sub_Ici Set.preimage_const_sub_Ici @[simp] theorem preimage_const_sub_Iic : (fun x => a - x) ⁻¹' Iic b = Ici (a - b) := ext fun _x => sub_le_comm #align set.preimage_const_sub_Iic Set.preimage_const_sub_Iic @[simp] theorem preimage_const_sub_Ioi : (fun x => a - x) ⁻¹' Ioi b = Iio (a - b) := ext fun _x => lt_sub_comm #align set.preimage_const_sub_Ioi Set.preimage_const_sub_Ioi @[simp] theorem preimage_const_sub_Iio : (fun x => a - x) ⁻¹' Iio b = Ioi (a - b) := ext fun _x => sub_lt_comm #align set.preimage_const_sub_Iio Set.preimage_const_sub_Iio @[simp] theorem preimage_const_sub_Icc : (fun x => a - x) ⁻¹' Icc b c = Icc (a - c) (a - b) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_const_sub_Icc Set.preimage_const_sub_Icc @[simp] theorem preimage_const_sub_Ico : (fun x => a - x) ⁻¹' Ico b c = Ioc (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ico Set.preimage_const_sub_Ico @[simp] theorem preimage_const_sub_Ioc : (fun x => a - x) ⁻¹' Ioc b c = Ico (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioc Set.preimage_const_sub_Ioc @[simp] theorem preimage_const_sub_Ioo : (fun x => a - x) ⁻¹' Ioo b c = Ioo (a - c) (a - b) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioo Set.preimage_const_sub_Ioo /-! ### Images under `x ↦ a + x` -/ -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iic : (fun x => a + x) '' Iic b = Iic (a + b) := by simp [add_comm] #align set.image_const_add_Iic Set.image_const_add_Iic -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iio : (fun x => a + x) '' Iio b = Iio (a + b) := by simp [add_comm] #align set.image_const_add_Iio Set.image_const_add_Iio /-! ### Images under `x ↦ x + a` -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iic : (fun x => x + a) '' Iic b = Iic (b + a) := by simp #align set.image_add_const_Iic Set.image_add_const_Iic -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iio : (fun x => x + a) '' Iio b = Iio (b + a) := by simp #align set.image_add_const_Iio Set.image_add_const_Iio /-! ### Images under `x ↦ -x` -/ theorem image_neg_Ici : Neg.neg '' Ici a = Iic (-a) := by simp #align set.image_neg_Ici Set.image_neg_Ici theorem image_neg_Iic : Neg.neg '' Iic a = Ici (-a) := by simp #align set.image_neg_Iic Set.image_neg_Iic theorem image_neg_Ioi : Neg.neg '' Ioi a = Iio (-a) := by simp #align set.image_neg_Ioi Set.image_neg_Ioi theorem image_neg_Iio : Neg.neg '' Iio a = Ioi (-a) := by simp #align set.image_neg_Iio Set.image_neg_Iio theorem image_neg_Icc : Neg.neg '' Icc a b = Icc (-b) (-a) := by simp #align set.image_neg_Icc Set.image_neg_Icc theorem image_neg_Ico : Neg.neg '' Ico a b = Ioc (-b) (-a) := by simp #align set.image_neg_Ico Set.image_neg_Ico theorem image_neg_Ioc : Neg.neg '' Ioc a b = Ico (-b) (-a) := by simp #align set.image_neg_Ioc Set.image_neg_Ioc theorem image_neg_Ioo : Neg.neg '' Ioo a b = Ioo (-b) (-a) := by simp #align set.image_neg_Ioo Set.image_neg_Ioo /-! ### Images under `x ↦ a - x` -/ @[simp] theorem image_const_sub_Ici : (fun x => a - x) '' Ici b = Iic (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ici Set.image_const_sub_Ici @[simp] theorem image_const_sub_Iic : (fun x => a - x) '' Iic b = Ici (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iic Set.image_const_sub_Iic @[simp] theorem image_const_sub_Ioi : (fun x => a - x) '' Ioi b = Iio (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioi Set.image_const_sub_Ioi @[simp] theorem image_const_sub_Iio : (fun x => a - x) '' Iio b = Ioi (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iio Set.image_const_sub_Iio @[simp] theorem image_const_sub_Icc : (fun x => a - x) '' Icc b c = Icc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Icc Set.image_const_sub_Icc @[simp] theorem image_const_sub_Ico : (fun x => a - x) '' Ico b c = Ioc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ico Set.image_const_sub_Ico @[simp] theorem image_const_sub_Ioc : (fun x => a - x) '' Ioc b c = Ico (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioc Set.image_const_sub_Ioc @[simp] theorem image_const_sub_Ioo : (fun x => a - x) '' Ioo b c = Ioo (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioo Set.image_const_sub_Ioo /-! ### Images under `x ↦ x - a` -/ @[simp] theorem image_sub_const_Ici : (fun x => x - a) '' Ici b = Ici (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ici Set.image_sub_const_Ici @[simp] theorem image_sub_const_Iic : (fun x => x - a) '' Iic b = Iic (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iic Set.image_sub_const_Iic @[simp] theorem image_sub_const_Ioi : (fun x => x - a) '' Ioi b = Ioi (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioi Set.image_sub_const_Ioi @[simp] theorem image_sub_const_Iio : (fun x => x - a) '' Iio b = Iio (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iio Set.image_sub_const_Iio @[simp] theorem image_sub_const_Icc : (fun x => x - a) '' Icc b c = Icc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Icc Set.image_sub_const_Icc @[simp] theorem image_sub_const_Ico : (fun x => x - a) '' Ico b c = Ico (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ico Set.image_sub_const_Ico @[simp] theorem image_sub_const_Ioc : (fun x => x - a) '' Ioc b c = Ioc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioc Set.image_sub_const_Ioc @[simp] theorem image_sub_const_Ioo : (fun x => x - a) '' Ioo b c = Ioo (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioo Set.image_sub_const_Ioo /-! ### Bijections -/ theorem Iic_add_bij : BijOn (· + a) (Iic b) (Iic (b + a)) := image_add_const_Iic a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iic_add_bij Set.Iic_add_bij theorem Iio_add_bij : BijOn (· + a) (Iio b) (Iio (b + a)) := image_add_const_Iio a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iio_add_bij Set.Iio_add_bij end OrderedAddCommGroup section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup α] (a b c d : α) @[simp] theorem preimage_const_add_uIcc : (fun x => a + x) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simp only [← Icc_min_max, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right] #align set.preimage_const_add_uIcc Set.preimage_const_add_uIcc @[simp] theorem preimage_add_const_uIcc : (fun x => x + a) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simpa only [add_comm] using preimage_const_add_uIcc a b c #align set.preimage_add_const_uIcc Set.preimage_add_const_uIcc -- TODO: Why is the notation `-[[a, b]]` broken? @[simp] theorem preimage_neg_uIcc : @Neg.neg (Set α) Set.neg [[a, b]] = [[-a, -b]] := by simp only [← Icc_min_max, preimage_neg_Icc, min_neg_neg, max_neg_neg] #align set.preimage_neg_uIcc Set.preimage_neg_uIcc @[simp] theorem preimage_sub_const_uIcc : (fun x => x - a) ⁻¹' [[b, c]] = [[b + a, c + a]] := by simp [sub_eq_add_neg] #align set.preimage_sub_const_uIcc Set.preimage_sub_const_uIcc @[simp] theorem preimage_const_sub_uIcc : (fun x => a - x) ⁻¹' [[b, c]] = [[a - b, a - c]] := by simp_rw [← Icc_min_max, preimage_const_sub_Icc] simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg] #align set.preimage_const_sub_uIcc Set.preimage_const_sub_uIcc -- @[simp] -- Porting note (#10618): simp can prove this module `add_comm` theorem image_const_add_uIcc : (fun x => a + x) '' [[b, c]] = [[a + b, a + c]] := by simp [add_comm] #align set.image_const_add_uIcc Set.image_const_add_uIcc -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_uIcc : (fun x => x + a) '' [[b, c]] = [[b + a, c + a]] := by simp #align set.image_add_const_uIcc Set.image_add_const_uIcc @[simp] theorem image_const_sub_uIcc : (fun x => a - x) '' [[b, c]] = [[a - b, a - c]] := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_uIcc Set.image_const_sub_uIcc @[simp] theorem image_sub_const_uIcc : (fun x => x - a) '' [[b, c]] = [[b - a, c - a]] := by simp [sub_eq_add_neg, add_comm] #align set.image_sub_const_uIcc Set.image_sub_const_uIcc theorem image_neg_uIcc : Neg.neg '' [[a, b]] = [[-a, -b]] := by simp #align set.image_neg_uIcc Set.image_neg_uIcc variable {a b c d} /-- If `[c, d]` is a subinterval of `[a, b]`, then the distance between `c` and `d` is less than or equal to that of `a` and `b` -/
Mathlib/Data/Set/Pointwise/Interval.lean
565
568
theorem abs_sub_le_of_uIcc_subset_uIcc (h : [[c, d]] ⊆ [[a, b]]) : |d - c| ≤ |b - a| := by
rw [← max_sub_min_eq_abs, ← max_sub_min_eq_abs] rw [uIcc_subset_uIcc_iff_le] at h exact sub_le_sub h.2 h.1
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Variance #align_import probability.moments from "leanprover-community/mathlib"@"85453a2a14be8da64caf15ca50930cf4c6e5d8de" /-! # Moments and moment generating function ## Main definitions * `ProbabilityTheory.moment X p μ`: `p`th moment of a real random variable `X` with respect to measure `μ`, `μ[X^p]` * `ProbabilityTheory.centralMoment X p μ`:`p`th central moment of `X` with respect to measure `μ`, `μ[(X - μ[X])^p]` * `ProbabilityTheory.mgf X μ t`: moment generating function of `X` with respect to measure `μ`, `μ[exp(t*X)]` * `ProbabilityTheory.cgf X μ t`: cumulant generating function, logarithm of the moment generating function ## Main results * `ProbabilityTheory.IndepFun.mgf_add`: if two real random variables `X` and `Y` are independent and their mgfs are defined at `t`, then `mgf (X + Y) μ t = mgf X μ t * mgf Y μ t` * `ProbabilityTheory.IndepFun.cgf_add`: if two real random variables `X` and `Y` are independent and their cgfs are defined at `t`, then `cgf (X + Y) μ t = cgf X μ t + cgf Y μ t` * `ProbabilityTheory.measure_ge_le_exp_cgf` and `ProbabilityTheory.measure_le_le_exp_cgf`: Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that the cgf exists, `ℙ(ε ≤ X) ≤ exp(- t*ε + cgf X ℙ t)`. See also `ProbabilityTheory.measure_ge_le_exp_mul_mgf` and `ProbabilityTheory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead of `cgf`. -/ open MeasureTheory Filter Finset Real noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {p : ℕ} {μ : Measure Ω} /-- Moment of a real random variable, `μ[X ^ p]`. -/ def moment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := μ[X ^ p] #align probability_theory.moment ProbabilityTheory.moment /-- Central moment of a real random variable, `μ[(X - μ[X]) ^ p]`. -/ def centralMoment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := by have m := fun (x : Ω) => μ[X] -- Porting note: Lean deems `μ[(X - fun x => μ[X]) ^ p]` ambiguous exact μ[(X - m) ^ p] #align probability_theory.central_moment ProbabilityTheory.centralMoment @[simp] theorem moment_zero (hp : p ≠ 0) : moment 0 p μ = 0 := by simp only [moment, hp, zero_pow, Ne, not_false_iff, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, integral_zero] #align probability_theory.moment_zero ProbabilityTheory.moment_zero @[simp] theorem centralMoment_zero (hp : p ≠ 0) : centralMoment 0 p μ = 0 := by simp only [centralMoment, hp, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, zero_sub, Pi.pow_apply, Pi.neg_apply, neg_zero, zero_pow, Ne, not_false_iff] #align probability_theory.central_moment_zero ProbabilityTheory.centralMoment_zero theorem centralMoment_one' [IsFiniteMeasure μ] (h_int : Integrable X μ) : centralMoment X 1 μ = (1 - (μ Set.univ).toReal) * μ[X] := by simp only [centralMoment, Pi.sub_apply, pow_one] rw [integral_sub h_int (integrable_const _)] simp only [sub_mul, integral_const, smul_eq_mul, one_mul] #align probability_theory.central_moment_one' ProbabilityTheory.centralMoment_one' @[simp] theorem centralMoment_one [IsProbabilityMeasure μ] : centralMoment X 1 μ = 0 := by by_cases h_int : Integrable X μ · rw [centralMoment_one' h_int] simp only [measure_univ, ENNReal.one_toReal, sub_self, zero_mul] · simp only [centralMoment, Pi.sub_apply, pow_one] have : ¬Integrable (fun x => X x - integral μ X) μ := by refine fun h_sub => h_int ?_ have h_add : X = (fun x => X x - integral μ X) + fun _ => integral μ X := by ext1 x; simp rw [h_add] exact h_sub.add (integrable_const _) rw [integral_undef this] #align probability_theory.central_moment_one ProbabilityTheory.centralMoment_one theorem centralMoment_two_eq_variance [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : centralMoment X 2 μ = variance X μ := by rw [hX.variance_eq]; rfl #align probability_theory.central_moment_two_eq_variance ProbabilityTheory.centralMoment_two_eq_variance section MomentGeneratingFunction variable {t : ℝ} /-- Moment generating function of a real random variable `X`: `fun t => μ[exp(t*X)]`. -/ def mgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := μ[fun ω => exp (t * X ω)] #align probability_theory.mgf ProbabilityTheory.mgf /-- Cumulant generating function of a real random variable `X`: `fun t => log μ[exp(t*X)]`. -/ def cgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := log (mgf X μ t) #align probability_theory.cgf ProbabilityTheory.cgf @[simp] theorem mgf_zero_fun : mgf 0 μ t = (μ Set.univ).toReal := by simp only [mgf, Pi.zero_apply, mul_zero, exp_zero, integral_const, smul_eq_mul, mul_one] #align probability_theory.mgf_zero_fun ProbabilityTheory.mgf_zero_fun @[simp] theorem cgf_zero_fun : cgf 0 μ t = log (μ Set.univ).toReal := by simp only [cgf, mgf_zero_fun] #align probability_theory.cgf_zero_fun ProbabilityTheory.cgf_zero_fun @[simp] theorem mgf_zero_measure : mgf X (0 : Measure Ω) t = 0 := by simp only [mgf, integral_zero_measure] #align probability_theory.mgf_zero_measure ProbabilityTheory.mgf_zero_measure @[simp] theorem cgf_zero_measure : cgf X (0 : Measure Ω) t = 0 := by simp only [cgf, log_zero, mgf_zero_measure] #align probability_theory.cgf_zero_measure ProbabilityTheory.cgf_zero_measure @[simp] theorem mgf_const' (c : ℝ) : mgf (fun _ => c) μ t = (μ Set.univ).toReal * exp (t * c) := by simp only [mgf, integral_const, smul_eq_mul] #align probability_theory.mgf_const' ProbabilityTheory.mgf_const' -- @[simp] -- Porting note: `simp only` already proves this theorem mgf_const (c : ℝ) [IsProbabilityMeasure μ] : mgf (fun _ => c) μ t = exp (t * c) := by simp only [mgf_const', measure_univ, ENNReal.one_toReal, one_mul] #align probability_theory.mgf_const ProbabilityTheory.mgf_const @[simp] theorem cgf_const' [IsFiniteMeasure μ] (hμ : μ ≠ 0) (c : ℝ) : cgf (fun _ => c) μ t = log (μ Set.univ).toReal + t * c := by simp only [cgf, mgf_const'] rw [log_mul _ (exp_pos _).ne'] · rw [log_exp _] · rw [Ne, ENNReal.toReal_eq_zero_iff, Measure.measure_univ_eq_zero] simp only [hμ, measure_ne_top μ Set.univ, or_self_iff, not_false_iff] #align probability_theory.cgf_const' ProbabilityTheory.cgf_const' @[simp] theorem cgf_const [IsProbabilityMeasure μ] (c : ℝ) : cgf (fun _ => c) μ t = t * c := by simp only [cgf, mgf_const, log_exp] #align probability_theory.cgf_const ProbabilityTheory.cgf_const @[simp] theorem mgf_zero' : mgf X μ 0 = (μ Set.univ).toReal := by simp only [mgf, zero_mul, exp_zero, integral_const, smul_eq_mul, mul_one] #align probability_theory.mgf_zero' ProbabilityTheory.mgf_zero' -- @[simp] -- Porting note: `simp only` already proves this theorem mgf_zero [IsProbabilityMeasure μ] : mgf X μ 0 = 1 := by simp only [mgf_zero', measure_univ, ENNReal.one_toReal] #align probability_theory.mgf_zero ProbabilityTheory.mgf_zero @[simp] theorem cgf_zero' : cgf X μ 0 = log (μ Set.univ).toReal := by simp only [cgf, mgf_zero'] #align probability_theory.cgf_zero' ProbabilityTheory.cgf_zero' -- @[simp] -- Porting note: `simp only` already proves this theorem cgf_zero [IsProbabilityMeasure μ] : cgf X μ 0 = 0 := by simp only [cgf_zero', measure_univ, ENNReal.one_toReal, log_one] #align probability_theory.cgf_zero ProbabilityTheory.cgf_zero theorem mgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : mgf X μ t = 0 := by simp only [mgf, integral_undef hX] #align probability_theory.mgf_undef ProbabilityTheory.mgf_undef theorem cgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : cgf X μ t = 0 := by simp only [cgf, mgf_undef hX, log_zero] #align probability_theory.cgf_undef ProbabilityTheory.cgf_undef theorem mgf_nonneg : 0 ≤ mgf X μ t := by unfold mgf; positivity #align probability_theory.mgf_nonneg ProbabilityTheory.mgf_nonneg theorem mgf_pos' (hμ : μ ≠ 0) (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) : 0 < mgf X μ t := by simp_rw [mgf] have : ∫ x : Ω, exp (t * X x) ∂μ = ∫ x : Ω in Set.univ, exp (t * X x) ∂μ := by simp only [Measure.restrict_univ] rw [this, setIntegral_pos_iff_support_of_nonneg_ae _ _] · have h_eq_univ : (Function.support fun x : Ω => exp (t * X x)) = Set.univ := by ext1 x simp only [Function.mem_support, Set.mem_univ, iff_true_iff] exact (exp_pos _).ne' rw [h_eq_univ, Set.inter_univ _] refine Ne.bot_lt ?_ simp only [hμ, ENNReal.bot_eq_zero, Ne, Measure.measure_univ_eq_zero, not_false_iff] · filter_upwards with x rw [Pi.zero_apply] exact (exp_pos _).le · rwa [integrableOn_univ] #align probability_theory.mgf_pos' ProbabilityTheory.mgf_pos' theorem mgf_pos [IsProbabilityMeasure μ] (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) : 0 < mgf X μ t := mgf_pos' (IsProbabilityMeasure.ne_zero μ) h_int_X #align probability_theory.mgf_pos ProbabilityTheory.mgf_pos theorem mgf_neg : mgf (-X) μ t = mgf X μ (-t) := by simp_rw [mgf, Pi.neg_apply, mul_neg, neg_mul] #align probability_theory.mgf_neg ProbabilityTheory.mgf_neg theorem cgf_neg : cgf (-X) μ t = cgf X μ (-t) := by simp_rw [cgf, mgf_neg] #align probability_theory.cgf_neg ProbabilityTheory.cgf_neg /-- This is a trivial application of `IndepFun.comp` but it will come up frequently. -/ theorem IndepFun.exp_mul {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (s t : ℝ) : IndepFun (fun ω => exp (s * X ω)) (fun ω => exp (t * Y ω)) μ := by have h_meas : ∀ t, Measurable fun x => exp (t * x) := fun t => (measurable_id'.const_mul t).exp change IndepFun ((fun x => exp (s * x)) ∘ X) ((fun x => exp (t * x)) ∘ Y) μ exact IndepFun.comp h_indep (h_meas s) (h_meas t) #align probability_theory.indep_fun.exp_mul ProbabilityTheory.IndepFun.exp_mul theorem IndepFun.mgf_add {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (hX : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ) (hY : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ) : mgf (X + Y) μ t = mgf X μ t * mgf Y μ t := by simp_rw [mgf, Pi.add_apply, mul_add, exp_add] exact (h_indep.exp_mul t t).integral_mul hX hY #align probability_theory.indep_fun.mgf_add ProbabilityTheory.IndepFun.mgf_add
Mathlib/Probability/Moments.lean
232
239
theorem IndepFun.mgf_add' {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) : mgf (X + Y) μ t = mgf X μ t * mgf Y μ t := by
have A : Continuous fun x : ℝ => exp (t * x) := by fun_prop have h'X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ := A.aestronglyMeasurable.comp_aemeasurable hX.aemeasurable have h'Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ := A.aestronglyMeasurable.comp_aemeasurable hY.aemeasurable exact h_indep.mgf_add h'X h'Y
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.Data.Finset.PiAntidiagonal import Mathlib.LinearAlgebra.StdBasis import Mathlib.Tactic.Linarith #align_import ring_theory.power_series.basic from "leanprover-community/mathlib"@"2d5739b61641ee4e7e53eca5688a08f66f2e6a60" /-! # Formal (multivariate) power series This file defines multivariate formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. We provide the natural inclusion from multivariate polynomials to multivariate formal power series. ## Note This file sets up the (semi)ring structure on multivariate power series: additional results are in: * `Mathlib.RingTheory.MvPowerSeries.Inverse` : invertibility, formal power series over a local ring form a local ring; * `Mathlib.RingTheory.MvPowerSeries.Trunc`: truncation of power series. In `Mathlib.RingTheory.PowerSeries.Basic`, formal power series in one variable will be obtained as a particular case, defined by `PowerSeries R := MvPowerSeries Unit R`. See that file for a specific description. ## Implementation notes In this file we define multivariate formal power series with variables indexed by `σ` and coefficients in `R` as `MvPowerSeries σ R := (σ →₀ ℕ) → R`. Unfortunately there is not yet enough API to show that they are the completion of the ring of multivariate polynomials. However, we provide most of the infrastructure that is needed to do this. Once I-adic completion (topological or algebraic) is available it should not be hard to fill in the details. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Multivariate formal power series, where `σ` is the index set of the variables and `R` is the coefficient ring. -/ def MvPowerSeries (σ : Type*) (R : Type*) := (σ →₀ ℕ) → R #align mv_power_series MvPowerSeries namespace MvPowerSeries open Finsupp variable {σ R : Type*} instance [Inhabited R] : Inhabited (MvPowerSeries σ R) := ⟨fun _ => default⟩ instance [Zero R] : Zero (MvPowerSeries σ R) := Pi.instZero instance [AddMonoid R] : AddMonoid (MvPowerSeries σ R) := Pi.addMonoid instance [AddGroup R] : AddGroup (MvPowerSeries σ R) := Pi.addGroup instance [AddCommMonoid R] : AddCommMonoid (MvPowerSeries σ R) := Pi.addCommMonoid instance [AddCommGroup R] : AddCommGroup (MvPowerSeries σ R) := Pi.addCommGroup instance [Nontrivial R] : Nontrivial (MvPowerSeries σ R) := Function.nontrivial instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R (MvPowerSeries σ A) := Pi.module _ _ _ instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S (MvPowerSeries σ A) := Pi.isScalarTower section Semiring variable (R) [Semiring R] /-- The `n`th monomial as multivariate formal power series: it is defined as the `R`-linear map from `R` to the semi-ring of multivariate formal power series associating to each `a` the map sending `n : σ →₀ ℕ` to the value `a` and sending all other `x : σ →₀ ℕ` different from `n` to `0`. -/ def monomial (n : σ →₀ ℕ) : R →ₗ[R] MvPowerSeries σ R := letI := Classical.decEq σ LinearMap.stdBasis R (fun _ ↦ R) n #align mv_power_series.monomial MvPowerSeries.monomial /-- The `n`th coefficient of a multivariate formal power series. -/ def coeff (n : σ →₀ ℕ) : MvPowerSeries σ R →ₗ[R] R := LinearMap.proj n #align mv_power_series.coeff MvPowerSeries.coeff variable {R} /-- Two multivariate formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ} (h : ∀ n : σ →₀ ℕ, coeff R n φ = coeff R n ψ) : φ = ψ := funext h #align mv_power_series.ext MvPowerSeries.ext /-- Two multivariate formal power series are equal if and only if all their coefficients are equal. -/ theorem ext_iff {φ ψ : MvPowerSeries σ R} : φ = ψ ↔ ∀ n : σ →₀ ℕ, coeff R n φ = coeff R n ψ := Function.funext_iff #align mv_power_series.ext_iff MvPowerSeries.ext_iff theorem monomial_def [DecidableEq σ] (n : σ →₀ ℕ) : (monomial R n) = LinearMap.stdBasis R (fun _ ↦ R) n := by rw [monomial] -- unify the `Decidable` arguments convert rfl #align mv_power_series.monomial_def MvPowerSeries.monomial_def theorem coeff_monomial [DecidableEq σ] (m n : σ →₀ ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 := by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [coeff, monomial_def, LinearMap.proj_apply (i := m)] dsimp only -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [LinearMap.stdBasis_apply, Function.update_apply, Pi.zero_apply] #align mv_power_series.coeff_monomial MvPowerSeries.coeff_monomial @[simp] theorem coeff_monomial_same (n : σ →₀ ℕ) (a : R) : coeff R n (monomial R n a) = a := by classical rw [monomial_def] exact LinearMap.stdBasis_same R (fun _ ↦ R) n a #align mv_power_series.coeff_monomial_same MvPowerSeries.coeff_monomial_same theorem coeff_monomial_ne {m n : σ →₀ ℕ} (h : m ≠ n) (a : R) : coeff R m (monomial R n a) = 0 := by classical rw [monomial_def] exact LinearMap.stdBasis_ne R (fun _ ↦ R) _ _ h a #align mv_power_series.coeff_monomial_ne MvPowerSeries.coeff_monomial_ne theorem eq_of_coeff_monomial_ne_zero {m n : σ →₀ ℕ} {a : R} (h : coeff R m (monomial R n a) ≠ 0) : m = n := by_contra fun h' => h <| coeff_monomial_ne h' a #align mv_power_series.eq_of_coeff_monomial_ne_zero MvPowerSeries.eq_of_coeff_monomial_ne_zero @[simp] theorem coeff_comp_monomial (n : σ →₀ ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n #align mv_power_series.coeff_comp_monomial MvPowerSeries.coeff_comp_monomial -- Porting note (#10618): simp can prove this. -- @[simp] theorem coeff_zero (n : σ →₀ ℕ) : coeff R n (0 : MvPowerSeries σ R) = 0 := rfl #align mv_power_series.coeff_zero MvPowerSeries.coeff_zero variable (m n : σ →₀ ℕ) (φ ψ : MvPowerSeries σ R) instance : One (MvPowerSeries σ R) := ⟨monomial R (0 : σ →₀ ℕ) 1⟩ theorem coeff_one [DecidableEq σ] : coeff R n (1 : MvPowerSeries σ R) = if n = 0 then 1 else 0 := coeff_monomial _ _ _ #align mv_power_series.coeff_one MvPowerSeries.coeff_one theorem coeff_zero_one : coeff R (0 : σ →₀ ℕ) 1 = 1 := coeff_monomial_same 0 1 #align mv_power_series.coeff_zero_one MvPowerSeries.coeff_zero_one theorem monomial_zero_one : monomial R (0 : σ →₀ ℕ) 1 = 1 := rfl #align mv_power_series.monomial_zero_one MvPowerSeries.monomial_zero_one instance : AddMonoidWithOne (MvPowerSeries σ R) := { show AddMonoid (MvPowerSeries σ R) by infer_instance with natCast := fun n => monomial R 0 n natCast_zero := by simp [Nat.cast] natCast_succ := by simp [Nat.cast, monomial_zero_one] one := 1 } instance : Mul (MvPowerSeries σ R) := letI := Classical.decEq σ ⟨fun φ ψ n => ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ⟩ theorem coeff_mul [DecidableEq σ] : coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by refine Finset.sum_congr ?_ fun _ _ => rfl rw [Subsingleton.elim (Classical.decEq σ) ‹DecidableEq σ›] #align mv_power_series.coeff_mul MvPowerSeries.coeff_mul protected theorem zero_mul : (0 : MvPowerSeries σ R) * φ = 0 := ext fun n => by classical simp [coeff_mul] #align mv_power_series.zero_mul MvPowerSeries.zero_mul protected theorem mul_zero : φ * 0 = 0 := ext fun n => by classical simp [coeff_mul] #align mv_power_series.mul_zero MvPowerSeries.mul_zero theorem coeff_monomial_mul (a : R) : coeff R m (monomial R n a * φ) = if n ≤ m then a * coeff R (m - n) φ else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 (monomial R n a) * coeff R p.2 φ ≠ 0 → p.1 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (left_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_fst_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] #align mv_power_series.coeff_monomial_mul MvPowerSeries.coeff_monomial_mul theorem coeff_mul_monomial (a : R) : coeff R m (φ * monomial R n a) = if n ≤ m then coeff R (m - n) φ * a else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 φ * coeff R p.2 (monomial R n a) ≠ 0 → p.2 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (right_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_snd_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] #align mv_power_series.coeff_mul_monomial MvPowerSeries.coeff_mul_monomial theorem coeff_add_monomial_mul (a : R) : coeff R (m + n) (monomial R m a * φ) = a * coeff R n φ := by rw [coeff_monomial_mul, if_pos, add_tsub_cancel_left] exact le_add_right le_rfl #align mv_power_series.coeff_add_monomial_mul MvPowerSeries.coeff_add_monomial_mul theorem coeff_add_mul_monomial (a : R) : coeff R (m + n) (φ * monomial R n a) = coeff R m φ * a := by rw [coeff_mul_monomial, if_pos, add_tsub_cancel_right] exact le_add_left le_rfl #align mv_power_series.coeff_add_mul_monomial MvPowerSeries.coeff_add_mul_monomial @[simp] theorem commute_monomial {a : R} {n} : Commute φ (monomial R n a) ↔ ∀ m, Commute (coeff R m φ) a := by refine ext_iff.trans ⟨fun h m => ?_, fun h m => ?_⟩ · have := h (m + n) rwa [coeff_add_mul_monomial, add_comm, coeff_add_monomial_mul] at this · rw [coeff_mul_monomial, coeff_monomial_mul] split_ifs <;> [apply h; rfl] #align mv_power_series.commute_monomial MvPowerSeries.commute_monomial protected theorem one_mul : (1 : MvPowerSeries σ R) * φ = φ := ext fun n => by simpa using coeff_add_monomial_mul 0 n φ 1 #align mv_power_series.one_mul MvPowerSeries.one_mul protected theorem mul_one : φ * 1 = φ := ext fun n => by simpa using coeff_add_mul_monomial n 0 φ 1 #align mv_power_series.mul_one MvPowerSeries.mul_one protected theorem mul_add (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ := ext fun n => by classical simp only [coeff_mul, mul_add, Finset.sum_add_distrib, LinearMap.map_add] #align mv_power_series.mul_add MvPowerSeries.mul_add protected theorem add_mul (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : (φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ := ext fun n => by classical simp only [coeff_mul, add_mul, Finset.sum_add_distrib, LinearMap.map_add] #align mv_power_series.add_mul MvPowerSeries.add_mul protected theorem mul_assoc (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * φ₂ * φ₃ = φ₁ * (φ₂ * φ₃) := by ext1 n classical simp only [coeff_mul, Finset.sum_mul, Finset.mul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l + j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i + k, l), (i, k)⟩) <;> aesop (add simp [add_assoc, mul_assoc]) #align mv_power_series.mul_assoc MvPowerSeries.mul_assoc instance : Semiring (MvPowerSeries σ R) := { inferInstanceAs (AddMonoidWithOne (MvPowerSeries σ R)), inferInstanceAs (Mul (MvPowerSeries σ R)), inferInstanceAs (AddCommMonoid (MvPowerSeries σ R)) with mul_one := MvPowerSeries.mul_one one_mul := MvPowerSeries.one_mul mul_assoc := MvPowerSeries.mul_assoc mul_zero := MvPowerSeries.mul_zero zero_mul := MvPowerSeries.zero_mul left_distrib := MvPowerSeries.mul_add right_distrib := MvPowerSeries.add_mul } end Semiring instance [CommSemiring R] : CommSemiring (MvPowerSeries σ R) := { show Semiring (MvPowerSeries σ R) by infer_instance with mul_comm := fun φ ψ => ext fun n => by classical simpa only [coeff_mul, mul_comm] using sum_antidiagonal_swap n fun a b => coeff R a φ * coeff R b ψ } instance [Ring R] : Ring (MvPowerSeries σ R) := { inferInstanceAs (Semiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } instance [CommRing R] : CommRing (MvPowerSeries σ R) := { inferInstanceAs (CommSemiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } section Semiring variable [Semiring R] theorem monomial_mul_monomial (m n : σ →₀ ℕ) (a b : R) : monomial R m a * monomial R n b = monomial R (m + n) (a * b) := by classical ext k simp only [coeff_mul_monomial, coeff_monomial] split_ifs with h₁ h₂ h₃ h₃ h₂ <;> try rfl · rw [← h₂, tsub_add_cancel_of_le h₁] at h₃ exact (h₃ rfl).elim · rw [h₃, add_tsub_cancel_right] at h₂ exact (h₂ rfl).elim · exact zero_mul b · rw [h₂] at h₁ exact (h₁ <| le_add_left le_rfl).elim #align mv_power_series.monomial_mul_monomial MvPowerSeries.monomial_mul_monomial variable (σ) (R) /-- The constant multivariate formal power series. -/ def C : R →+* MvPowerSeries σ R := { monomial R (0 : σ →₀ ℕ) with map_one' := rfl map_mul' := fun a b => (monomial_mul_monomial 0 0 a b).symm map_zero' := (monomial R (0 : _)).map_zero } set_option linter.uppercaseLean3 false in #align mv_power_series.C MvPowerSeries.C variable {σ} {R} @[simp] theorem monomial_zero_eq_C : ⇑(monomial R (0 : σ →₀ ℕ)) = C σ R := rfl set_option linter.uppercaseLean3 false in #align mv_power_series.monomial_zero_eq_C MvPowerSeries.monomial_zero_eq_C theorem monomial_zero_eq_C_apply (a : R) : monomial R (0 : σ →₀ ℕ) a = C σ R a := rfl set_option linter.uppercaseLean3 false in #align mv_power_series.monomial_zero_eq_C_apply MvPowerSeries.monomial_zero_eq_C_apply theorem coeff_C [DecidableEq σ] (n : σ →₀ ℕ) (a : R) : coeff R n (C σ R a) = if n = 0 then a else 0 := coeff_monomial _ _ _ set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_C MvPowerSeries.coeff_C theorem coeff_zero_C (a : R) : coeff R (0 : σ →₀ ℕ) (C σ R a) = a := coeff_monomial_same 0 a set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_zero_C MvPowerSeries.coeff_zero_C /-- The variables of the multivariate formal power series ring. -/ def X (s : σ) : MvPowerSeries σ R := monomial R (single s 1) 1 set_option linter.uppercaseLean3 false in #align mv_power_series.X MvPowerSeries.X theorem coeff_X [DecidableEq σ] (n : σ →₀ ℕ) (s : σ) : coeff R n (X s : MvPowerSeries σ R) = if n = single s 1 then 1 else 0 := coeff_monomial _ _ _ set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_X MvPowerSeries.coeff_X theorem coeff_index_single_X [DecidableEq σ] (s t : σ) : coeff R (single t 1) (X s : MvPowerSeries σ R) = if t = s then 1 else 0 := by simp only [coeff_X, single_left_inj (one_ne_zero : (1 : ℕ) ≠ 0)] set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_index_single_X MvPowerSeries.coeff_index_single_X @[simp] theorem coeff_index_single_self_X (s : σ) : coeff R (single s 1) (X s : MvPowerSeries σ R) = 1 := coeff_monomial_same _ _ set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_index_single_self_X MvPowerSeries.coeff_index_single_self_X theorem coeff_zero_X (s : σ) : coeff R (0 : σ →₀ ℕ) (X s : MvPowerSeries σ R) = 0 := by classical rw [coeff_X, if_neg] intro h exact one_ne_zero (single_eq_zero.mp h.symm) set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_zero_X MvPowerSeries.coeff_zero_X theorem commute_X (φ : MvPowerSeries σ R) (s : σ) : Commute φ (X s) := φ.commute_monomial.mpr fun _m => Commute.one_right _ set_option linter.uppercaseLean3 false in #align mv_power_series.commute_X MvPowerSeries.commute_X theorem X_def (s : σ) : X s = monomial R (single s 1) 1 := rfl set_option linter.uppercaseLean3 false in #align mv_power_series.X_def MvPowerSeries.X_def theorem X_pow_eq (s : σ) (n : ℕ) : (X s : MvPowerSeries σ R) ^ n = monomial R (single s n) 1 := by induction' n with n ih · simp · rw [pow_succ, ih, Finsupp.single_add, X, monomial_mul_monomial, one_mul] set_option linter.uppercaseLean3 false in #align mv_power_series.X_pow_eq MvPowerSeries.X_pow_eq theorem coeff_X_pow [DecidableEq σ] (m : σ →₀ ℕ) (s : σ) (n : ℕ) : coeff R m ((X s : MvPowerSeries σ R) ^ n) = if m = single s n then 1 else 0 := by rw [X_pow_eq s n, coeff_monomial] set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_X_pow MvPowerSeries.coeff_X_pow @[simp] theorem coeff_mul_C (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (φ * C σ R a) = coeff R n φ * a := by simpa using coeff_add_mul_monomial n 0 φ a set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_mul_C MvPowerSeries.coeff_mul_C @[simp] theorem coeff_C_mul (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (C σ R a * φ) = a * coeff R n φ := by simpa using coeff_add_monomial_mul 0 n φ a set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_C_mul MvPowerSeries.coeff_C_mul theorem coeff_zero_mul_X (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (φ * X s) = 0 := by have : ¬single s 1 ≤ 0 := fun h => by simpa using h s simp only [X, coeff_mul_monomial, if_neg this] set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_zero_mul_X MvPowerSeries.coeff_zero_mul_X theorem coeff_zero_X_mul (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (X s * φ) = 0 := by rw [← (φ.commute_X s).eq, coeff_zero_mul_X] set_option linter.uppercaseLean3 false in #align mv_power_series.coeff_zero_X_mul MvPowerSeries.coeff_zero_X_mul variable (σ) (R) /-- The constant coefficient of a formal power series. -/ def constantCoeff : MvPowerSeries σ R →+* R := { coeff R (0 : σ →₀ ℕ) with toFun := coeff R (0 : σ →₀ ℕ) map_one' := coeff_zero_one map_mul' := fun φ ψ => by classical simp [coeff_mul, support_single_ne_zero] map_zero' := LinearMap.map_zero _ } #align mv_power_series.constant_coeff MvPowerSeries.constantCoeff variable {σ} {R} @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff R (0 : σ →₀ ℕ)) = constantCoeff σ R := rfl #align mv_power_series.coeff_zero_eq_constant_coeff MvPowerSeries.coeff_zero_eq_constantCoeff theorem coeff_zero_eq_constantCoeff_apply (φ : MvPowerSeries σ R) : coeff R (0 : σ →₀ ℕ) φ = constantCoeff σ R φ := rfl #align mv_power_series.coeff_zero_eq_constant_coeff_apply MvPowerSeries.coeff_zero_eq_constantCoeff_apply @[simp] theorem constantCoeff_C (a : R) : constantCoeff σ R (C σ R a) = a := rfl set_option linter.uppercaseLean3 false in #align mv_power_series.constant_coeff_C MvPowerSeries.constantCoeff_C @[simp] theorem constantCoeff_comp_C : (constantCoeff σ R).comp (C σ R) = RingHom.id R := rfl set_option linter.uppercaseLean3 false in #align mv_power_series.constant_coeff_comp_C MvPowerSeries.constantCoeff_comp_C -- Porting note (#10618): simp can prove this. -- @[simp] theorem constantCoeff_zero : constantCoeff σ R 0 = 0 := rfl #align mv_power_series.constant_coeff_zero MvPowerSeries.constantCoeff_zero -- Porting note (#10618): simp can prove this. -- @[simp] theorem constantCoeff_one : constantCoeff σ R 1 = 1 := rfl #align mv_power_series.constant_coeff_one MvPowerSeries.constantCoeff_one @[simp] theorem constantCoeff_X (s : σ) : constantCoeff σ R (X s) = 0 := coeff_zero_X s set_option linter.uppercaseLean3 false in #align mv_power_series.constant_coeff_X MvPowerSeries.constantCoeff_X /-- If a multivariate formal power series is invertible, then so is its constant coefficient. -/ theorem isUnit_constantCoeff (φ : MvPowerSeries σ R) (h : IsUnit φ) : IsUnit (constantCoeff σ R φ) := h.map _ #align mv_power_series.is_unit_constant_coeff MvPowerSeries.isUnit_constantCoeff -- Porting note (#10618): simp can prove this. -- @[simp] theorem coeff_smul (f : MvPowerSeries σ R) (n) (a : R) : coeff _ n (a • f) = a * coeff _ n f := rfl #align mv_power_series.coeff_smul MvPowerSeries.coeff_smul
Mathlib/RingTheory/MvPowerSeries/Basic.lean
514
516
theorem smul_eq_C_mul (f : MvPowerSeries σ R) (a : R) : a • f = C σ R a * f := by
ext simp
/- 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 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) end GoodProducts namespace Products theorem eval_eq (l : Products I) (x : C) : l.eval C x = if ∀ i, i ∈ l.val → (x.val i = true) then 1 else 0 := by change LocallyConstant.evalMonoidHom x (l.eval C) = _ rw [eval, map_list_prod] split_ifs with h · simp only [List.map_map] apply List.prod_eq_one simp only [List.mem_map, Function.comp_apply] rintro _ ⟨i, hi, rfl⟩ exact if_pos (h i hi) · simp only [List.map_map, List.prod_eq_zero_iff, List.mem_map, Function.comp_apply] push_neg at h convert h with i dsimp [LocallyConstant.evalMonoidHom, e] simp only [ite_eq_right_iff, one_ne_zero] theorem evalFacProp {l : Products I} (J : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] : l.eval (π C J) ∘ ProjRestrict C J = l.eval C := by ext x dsimp [ProjRestrict] rw [Products.eval_eq, Products.eval_eq] congr apply forall_congr; intro i apply forall_congr; intro hi simp [h i hi, Proj] theorem evalFacProps {l : Products I} (J K : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] [∀ j, Decidable (K j)] (hJK : ∀ i, J i → K i) : l.eval (π C J) ∘ ProjRestricts C hJK = l.eval (π C K) := by have : l.eval (π C J) ∘ Homeomorph.setCongr (proj_eq_of_subset C J K hJK) = l.eval (π (π C K) J) := by ext; simp [Homeomorph.setCongr, Products.eval_eq] rw [ProjRestricts, ← Function.comp.assoc, this, ← evalFacProp (π C K) J h] theorem prop_of_isGood {l : Products I} (J : I → Prop) [∀ j, Decidable (J j)] (h : l.isGood (π C J)) : ∀ a, a ∈ l.val → J a := by intro i hi by_contra h' apply h suffices eval (π C J) l = 0 by rw [this] exact Submodule.zero_mem _ ext ⟨_, _, _, rfl⟩ rw [eval_eq, if_neg fun h ↦ ?_, LocallyConstant.zero_apply] simpa [Proj, h'] using h i hi end Products /-- The good products span `LocallyConstant C ℤ` if and only all the products do. -/ theorem GoodProducts.span_iff_products : ⊤ ≤ span ℤ (Set.range (eval C)) ↔ ⊤ ≤ span ℤ (Set.range (Products.eval C)) := by refine ⟨fun h ↦ le_trans h (span_mono (fun a ⟨b, hb⟩ ↦ ⟨b.val, hb⟩)), fun h ↦ le_trans h ?_⟩ rw [span_le] rintro f ⟨l, rfl⟩ let L : Products I → Prop := fun m ↦ m.eval C ∈ span ℤ (Set.range (GoodProducts.eval C)) suffices L l by assumption apply IsWellFounded.induction (·<· : Products I → Products I → Prop) intro l h dsimp by_cases hl : l.isGood C · apply subset_span exact ⟨⟨l, hl⟩, rfl⟩ · simp only [Products.isGood, not_not] at hl suffices Products.eval C '' {m | m < l} ⊆ span ℤ (Set.range (GoodProducts.eval C)) by rw [← span_le] at this exact this hl rintro a ⟨m, hm, rfl⟩ exact h m hm end Products section Span /-! ## The good products span Most of the argument is developing an API for `π C (· ∈ s)` when `s : Finset I`; then the image of `C` is finite with the discrete topology. In this case, there is a direct argument that the good products span. The general result is deduced from this. ### Main theorems * `GoodProducts.spanFin` : The good products span the locally constant functions on `π C (· ∈ s)` if `s` is finite. * `GoodProducts.span` : The good products span `LocallyConstant C ℤ` for every closed subset `C`. -/ section Fin variable (s : Finset I) /-- The `ℤ`-linear map induced by precomposition of the projection `C → π C (· ∈ s)`. -/ noncomputable def πJ : LocallyConstant (π C (· ∈ s)) ℤ →ₗ[ℤ] LocallyConstant C ℤ := LocallyConstant.comapₗ ℤ ⟨_, (continuous_projRestrict C (· ∈ s))⟩ theorem eval_eq_πJ (l : Products I) (hl : l.isGood (π C (· ∈ s))) : l.eval C = πJ C s (l.eval (π C (· ∈ s))) := by ext f simp only [πJ, LocallyConstant.comapₗ, LinearMap.coe_mk, AddHom.coe_mk, (continuous_projRestrict C (· ∈ s)), LocallyConstant.coe_comap, Function.comp_apply] exact (congr_fun (Products.evalFacProp C (· ∈ s) (Products.prop_of_isGood C (· ∈ s) hl)) _).symm /-- `π C (· ∈ s)` is finite for a finite set `s`. -/ noncomputable instance : Fintype (π C (· ∈ s)) := by let f : π C (· ∈ s) → (s → Bool) := fun x j ↦ x.val j.val refine Fintype.ofInjective f ?_ intro ⟨_, x, hx, rfl⟩ ⟨_, y, hy, rfl⟩ h ext i by_cases hi : i ∈ s · exact congrFun h ⟨i, hi⟩ · simp only [Proj, if_neg hi] open scoped Classical in /-- The Kronecker delta as a locally constant map from `π C (· ∈ s)` to `ℤ`. -/ noncomputable def spanFinBasis (x : π C (· ∈ s)) : LocallyConstant (π C (· ∈ s)) ℤ where toFun := fun y ↦ if y = x then 1 else 0 isLocallyConstant := haveI : DiscreteTopology (π C (· ∈ s)) := discrete_of_t1_of_finite IsLocallyConstant.of_discrete _ open scoped Classical in theorem spanFinBasis.span : ⊤ ≤ Submodule.span ℤ (Set.range (spanFinBasis C s)) := by intro f _ rw [Finsupp.mem_span_range_iff_exists_finsupp] use Finsupp.onFinset (Finset.univ) f.toFun (fun _ _ ↦ Finset.mem_univ _) ext x change LocallyConstant.evalₗ ℤ x _ = _ simp only [zsmul_eq_mul, map_finsupp_sum, LocallyConstant.evalₗ_apply, LocallyConstant.coe_mul, Pi.mul_apply, spanFinBasis, LocallyConstant.coe_mk, mul_ite, mul_one, mul_zero, Finsupp.sum_ite_eq, Finsupp.mem_support_iff, ne_eq, ite_not] split_ifs with h <;> [exact h.symm; rfl] /-- A certain explicit list of locally constant maps. The theorem `factors_prod_eq_basis` shows that the product of the elements in this list is the delta function `spanFinBasis C s x`. -/ def factors (x : π C (· ∈ s)) : List (LocallyConstant (π C (· ∈ s)) ℤ) := List.map (fun i ↦ if x.val i = true then e (π C (· ∈ s)) i else (1 - (e (π C (· ∈ s)) i))) (s.sort (·≥·)) theorem list_prod_apply (x : C) (l : List (LocallyConstant C ℤ)) : l.prod x = (l.map (LocallyConstant.evalMonoidHom x)).prod := by rw [← map_list_prod (LocallyConstant.evalMonoidHom x) l] rfl theorem factors_prod_eq_basis_of_eq {x y : (π C fun x ↦ x ∈ s)} (h : y = x) : (factors C s x).prod y = 1 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_one simp only [h, List.mem_map, LocallyConstant.evalMonoidHom, factors] rintro _ ⟨a, ⟨b, _, rfl⟩, rfl⟩ dsimp split_ifs with hh · rw [e, LocallyConstant.coe_mk, if_pos hh] · rw [LocallyConstant.sub_apply, e, LocallyConstant.coe_mk, LocallyConstant.coe_mk, if_neg hh] simp only [LocallyConstant.toFun_eq_coe, LocallyConstant.coe_one, Pi.one_apply, sub_zero] theorem e_mem_of_eq_true {x : (π C (· ∈ s))} {a : I} (hx : x.val a = true) : e (π C (· ∈ s)) a ∈ factors C s x := by rcases x with ⟨_, z, hz, rfl⟩ simp only [factors, List.mem_map, Finset.mem_sort] refine ⟨a, ?_, if_pos hx⟩ aesop (add simp Proj) theorem one_sub_e_mem_of_false {x y : (π C (· ∈ s))} {a : I} (ha : y.val a = true) (hx : x.val a = false) : 1 - e (π C (· ∈ s)) a ∈ factors C s x := by simp only [factors, List.mem_map, Finset.mem_sort] use a simp only [hx, ite_false, and_true] rcases y with ⟨_, z, hz, rfl⟩ aesop (add simp Proj) theorem factors_prod_eq_basis_of_ne {x y : (π C (· ∈ s))} (h : y ≠ x) : (factors C s x).prod y = 0 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_zero simp only [List.mem_map] obtain ⟨a, ha⟩ : ∃ a, y.val a ≠ x.val a := by contrapose! h; ext; apply h cases hx : x.val a · rw [hx, ne_eq, Bool.not_eq_false] at ha refine ⟨1 - (e (π C (· ∈ s)) a), ⟨one_sub_e_mem_of_false _ _ ha hx, ?_⟩⟩ rw [e, LocallyConstant.evalMonoidHom_apply, LocallyConstant.sub_apply, LocallyConstant.coe_one, Pi.one_apply, LocallyConstant.coe_mk, if_pos ha, sub_self] · refine ⟨e (π C (· ∈ s)) a, ⟨e_mem_of_eq_true _ _ hx, ?_⟩⟩ rw [hx] at ha rw [LocallyConstant.evalMonoidHom_apply, e, LocallyConstant.coe_mk, if_neg ha] /-- If `s` is finite, the product of the elements of the list `factors C s x` is the delta function at `x`. -/ theorem factors_prod_eq_basis (x : π C (· ∈ s)) : (factors C s x).prod = spanFinBasis C s x := by ext y dsimp [spanFinBasis] split_ifs with h <;> [exact factors_prod_eq_basis_of_eq _ _ h; exact factors_prod_eq_basis_of_ne _ _ h] theorem GoodProducts.finsupp_sum_mem_span_eval {a : I} {as : List I} (ha : List.Chain' (· > ·) (a :: as)) {c : Products I →₀ ℤ} (hc : (c.support : Set (Products I)) ⊆ {m | m.val ≤ as}) : (Finsupp.sum c fun a_1 b ↦ e (π C (· ∈ s)) a * b • Products.eval (π C (· ∈ s)) a_1) ∈ Submodule.span ℤ (Products.eval (π C (· ∈ s)) '' {m | m.val ≤ a :: as}) := by apply Submodule.finsupp_sum_mem intro m hm have hsm := (LinearMap.mulLeft ℤ (e (π C (· ∈ s)) a)).map_smul dsimp at hsm rw [hsm] apply Submodule.smul_mem apply Submodule.subset_span have hmas : m.val ≤ as := by apply hc simpa only [Finset.mem_coe, Finsupp.mem_support_iff] using hm refine ⟨⟨a :: m.val, ha.cons_of_le m.prop hmas⟩, ⟨List.cons_le_cons a hmas, ?_⟩⟩ simp only [Products.eval, List.map, List.prod_cons] /-- If `s` is a finite subset of `I`, then the good products span. -/
Mathlib/Topology/Category/Profinite/Nobeling.lean
599
649
theorem GoodProducts.spanFin : ⊤ ≤ Submodule.span ℤ (Set.range (eval (π C (· ∈ s)))) := by
rw [span_iff_products] refine le_trans (spanFinBasis.span C s) ?_ rw [Submodule.span_le] rintro _ ⟨x, rfl⟩ rw [← factors_prod_eq_basis] let l := s.sort (·≥·) dsimp [factors] suffices l.Chain' (·>·) → (l.map (fun i ↦ if x.val i = true then e (π C (· ∈ s)) i else (1 - (e (π C (· ∈ s)) i)))).prod ∈ Submodule.span ℤ ((Products.eval (π C (· ∈ s))) '' {m | m.val ≤ l}) from Submodule.span_mono (Set.image_subset_range _ _) (this (Finset.sort_sorted_gt _).chain') induction l with | nil => intro _ apply Submodule.subset_span exact ⟨⟨[], List.chain'_nil⟩,⟨Or.inl rfl, rfl⟩⟩ | cons a as ih => rw [List.map_cons, List.prod_cons] intro ha specialize ih (by rw [List.chain'_cons'] at ha; exact ha.2) rw [Finsupp.mem_span_image_iff_total] at ih simp only [Finsupp.mem_supported, Finsupp.total_apply] at ih obtain ⟨c, hc, hc'⟩ := ih rw [← hc']; clear hc' have hmap := fun g ↦ map_finsupp_sum (LinearMap.mulLeft ℤ (e (π C (· ∈ s)) a)) c g dsimp at hmap ⊢ split_ifs · rw [hmap] exact finsupp_sum_mem_span_eval _ _ ha hc · ring_nf rw [hmap] apply Submodule.add_mem · apply Submodule.neg_mem exact finsupp_sum_mem_span_eval _ _ ha hc · apply Submodule.finsupp_sum_mem intro m hm apply Submodule.smul_mem apply Submodule.subset_span refine ⟨m, ⟨?_, rfl⟩⟩ simp only [Set.mem_setOf_eq] have hmas : m.val ≤ as := hc (by simpa only [Finset.mem_coe, Finsupp.mem_support_iff] using hm) refine le_trans hmas ?_ cases as with | nil => exact (List.nil_lt_cons a []).le | cons b bs => apply le_of_lt rw [List.chain'_cons] at ha have hlex := List.lt.head bs (b :: bs) ha.1 exact (List.lt_iff_lex_lt _ _).mp hlex
/- 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'
Mathlib/Data/Ordmap/Ordset.lean
316
318
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]
/- Copyright (c) 2023 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli -/ import Mathlib.Data.Set.Function import Mathlib.Analysis.BoundedVariation #align_import analysis.constant_speed from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Constant speed This file defines the notion of constant (and unit) speed for a function `f : ℝ → E` with pseudo-emetric structure on `E` with respect to a set `s : Set ℝ` and "speed" `l : ℝ≥0`, and shows that if `f` has locally bounded variation on `s`, it can be obtained (up to distance zero, on `s`), as a composite `φ ∘ (variationOnFromTo f s a)`, where `φ` has unit speed and `a ∈ s`. ## Main definitions * `HasConstantSpeedOnWith f s l`, stating that the speed of `f` on `s` is `l`. * `HasUnitSpeedOn f s`, stating that the speed of `f` on `s` is `1`. * `naturalParameterization f s a : ℝ → E`, the unit speed reparameterization of `f` on `s` relative to `a`. ## Main statements * `unique_unit_speed_on_Icc_zero` proves that if `f` and `f ∘ φ` are both naturally parameterized on closed intervals starting at `0`, then `φ` must be the identity on those intervals. * `edist_naturalParameterization_eq_zero` proves that if `f` has locally bounded variation, then precomposing `naturalParameterization f s a` with `variationOnFromTo f s a` yields a function at distance zero from `f` on `s`. * `has_unit_speed_naturalParameterization` proves that if `f` has locally bounded variation, then `naturalParameterization f s a` has unit speed on `s`. ## Tags arc-length, parameterization -/ open scoped NNReal ENNReal open Set MeasureTheory Classical variable {α : Type*} [LinearOrder α] {E : Type*} [PseudoEMetricSpace E] variable (f : ℝ → E) (s : Set ℝ) (l : ℝ≥0) /-- `f` has constant speed `l` on `s` if the variation of `f` on `s ∩ Icc x y` is equal to `l * (y - x)` for any `x y` in `s`. -/ def HasConstantSpeedOnWith := ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), eVariationOn f (s ∩ Icc x y) = ENNReal.ofReal (l * (y - x)) #align has_constant_speed_on_with HasConstantSpeedOnWith variable {f s l} theorem HasConstantSpeedOnWith.hasLocallyBoundedVariationOn (h : HasConstantSpeedOnWith f s l) : LocallyBoundedVariationOn f s := fun x y hx hy => by simp only [BoundedVariationOn, h hx hy, Ne, ENNReal.ofReal_ne_top, not_false_iff] #align has_constant_speed_on_with.has_locally_bounded_variation_on HasConstantSpeedOnWith.hasLocallyBoundedVariationOn theorem hasConstantSpeedOnWith_of_subsingleton (f : ℝ → E) {s : Set ℝ} (hs : s.Subsingleton) (l : ℝ≥0) : HasConstantSpeedOnWith f s l := by rintro x hx y hy; cases hs hx hy rw [eVariationOn.subsingleton f (fun y hy z hz => hs hy.1 hz.1 : (s ∩ Icc x x).Subsingleton)] simp only [sub_self, mul_zero, ENNReal.ofReal_zero] #align has_constant_speed_on_with_of_subsingleton hasConstantSpeedOnWith_of_subsingleton theorem hasConstantSpeedOnWith_iff_ordered : HasConstantSpeedOnWith f s l ↔ ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), x ≤ y → eVariationOn f (s ∩ Icc x y) = ENNReal.ofReal (l * (y - x)) := by refine ⟨fun h x xs y ys _ => h xs ys, fun h x xs y ys => ?_⟩ rcases le_total x y with (xy | yx) · exact h xs ys xy · rw [eVariationOn.subsingleton, ENNReal.ofReal_of_nonpos] · exact mul_nonpos_of_nonneg_of_nonpos l.prop (sub_nonpos_of_le yx) · rintro z ⟨zs, xz, zy⟩ w ⟨ws, xw, wy⟩ cases le_antisymm (zy.trans yx) xz cases le_antisymm (wy.trans yx) xw rfl #align has_constant_speed_on_with_iff_ordered hasConstantSpeedOnWith_iff_ordered theorem hasConstantSpeedOnWith_iff_variationOnFromTo_eq : HasConstantSpeedOnWith f s l ↔ LocallyBoundedVariationOn f s ∧ ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), variationOnFromTo f s x y = l * (y - x) := by constructor · rintro h; refine ⟨h.hasLocallyBoundedVariationOn, fun x xs y ys => ?_⟩ rw [hasConstantSpeedOnWith_iff_ordered] at h rcases le_total x y with (xy | yx) · rw [variationOnFromTo.eq_of_le f s xy, h xs ys xy] exact ENNReal.toReal_ofReal (mul_nonneg l.prop (sub_nonneg.mpr xy)) · rw [variationOnFromTo.eq_of_ge f s yx, h ys xs yx] have := ENNReal.toReal_ofReal (mul_nonneg l.prop (sub_nonneg.mpr yx)) simp_all only [NNReal.val_eq_coe]; ring · rw [hasConstantSpeedOnWith_iff_ordered] rintro h x xs y ys xy rw [← h.2 xs ys, variationOnFromTo.eq_of_le f s xy, ENNReal.ofReal_toReal (h.1 x y xs ys)] #align has_constant_speed_on_with_iff_variation_on_from_to_eq hasConstantSpeedOnWith_iff_variationOnFromTo_eq theorem HasConstantSpeedOnWith.union {t : Set ℝ} (hfs : HasConstantSpeedOnWith f s l) (hft : HasConstantSpeedOnWith f t l) {x : ℝ} (hs : IsGreatest s x) (ht : IsLeast t x) : HasConstantSpeedOnWith f (s ∪ t) l := by rw [hasConstantSpeedOnWith_iff_ordered] at hfs hft ⊢ rintro z (zs | zt) y (ys | yt) zy · have : (s ∪ t) ∩ Icc z y = s ∩ Icc z y := by ext w; constructor · rintro ⟨ws | wt, zw, wy⟩ · exact ⟨ws, zw, wy⟩ · exact ⟨(le_antisymm (wy.trans (hs.2 ys)) (ht.2 wt)).symm ▸ hs.1, zw, wy⟩ · rintro ⟨ws, zwy⟩; exact ⟨Or.inl ws, zwy⟩ rw [this, hfs zs ys zy] · have : (s ∪ t) ∩ Icc z y = s ∩ Icc z x ∪ t ∩ Icc x y := by ext w; constructor · rintro ⟨ws | wt, zw, wy⟩ exacts [Or.inl ⟨ws, zw, hs.2 ws⟩, Or.inr ⟨wt, ht.2 wt, wy⟩] · rintro (⟨ws, zw, wx⟩ | ⟨wt, xw, wy⟩) exacts [⟨Or.inl ws, zw, wx.trans (ht.2 yt)⟩, ⟨Or.inr wt, (hs.2 zs).trans xw, wy⟩] rw [this, @eVariationOn.union _ _ _ _ f _ _ x, hfs zs hs.1 (hs.2 zs), hft ht.1 yt (ht.2 yt)] · have q := ENNReal.ofReal_add (mul_nonneg l.prop (sub_nonneg.mpr (hs.2 zs))) (mul_nonneg l.prop (sub_nonneg.mpr (ht.2 yt))) simp only [NNReal.val_eq_coe] at q rw [← q] ring_nf exacts [⟨⟨hs.1, hs.2 zs, le_rfl⟩, fun w ⟨_, _, wx⟩ => wx⟩, ⟨⟨ht.1, le_rfl, ht.2 yt⟩, fun w ⟨_, xw, _⟩ => xw⟩] · cases le_antisymm zy ((hs.2 ys).trans (ht.2 zt)) simp only [Icc_self, sub_self, mul_zero, ENNReal.ofReal_zero] exact eVariationOn.subsingleton _ fun _ ⟨_, uz⟩ _ ⟨_, vz⟩ => uz.trans vz.symm · have : (s ∪ t) ∩ Icc z y = t ∩ Icc z y := by ext w; constructor · rintro ⟨ws | wt, zw, wy⟩ · exact ⟨le_antisymm ((ht.2 zt).trans zw) (hs.2 ws) ▸ ht.1, zw, wy⟩ · exact ⟨wt, zw, wy⟩ · rintro ⟨wt, zwy⟩; exact ⟨Or.inr wt, zwy⟩ rw [this, hft zt yt zy] #align has_constant_speed_on_with.union HasConstantSpeedOnWith.union theorem HasConstantSpeedOnWith.Icc_Icc {x y z : ℝ} (hfs : HasConstantSpeedOnWith f (Icc x y) l) (hft : HasConstantSpeedOnWith f (Icc y z) l) : HasConstantSpeedOnWith f (Icc x z) l := by rcases le_total x y with (xy | yx) · rcases le_total y z with (yz | zy) · rw [← Set.Icc_union_Icc_eq_Icc xy yz] exact hfs.union hft (isGreatest_Icc xy) (isLeast_Icc yz) · rintro u ⟨xu, uz⟩ v ⟨xv, vz⟩ rw [Icc_inter_Icc, sup_of_le_right xu, inf_of_le_right vz, ← hfs ⟨xu, uz.trans zy⟩ ⟨xv, vz.trans zy⟩, Icc_inter_Icc, sup_of_le_right xu, inf_of_le_right (vz.trans zy)] · rintro u ⟨xu, uz⟩ v ⟨xv, vz⟩ rw [Icc_inter_Icc, sup_of_le_right xu, inf_of_le_right vz, ← hft ⟨yx.trans xu, uz⟩ ⟨yx.trans xv, vz⟩, Icc_inter_Icc, sup_of_le_right (yx.trans xu), inf_of_le_right vz] #align has_constant_speed_on_with.Icc_Icc HasConstantSpeedOnWith.Icc_Icc theorem hasConstantSpeedOnWith_zero_iff : HasConstantSpeedOnWith f s 0 ↔ ∀ᵉ (x ∈ s) (y ∈ s), edist (f x) (f y) = 0 := by dsimp [HasConstantSpeedOnWith] simp only [zero_mul, ENNReal.ofReal_zero, ← eVariationOn.eq_zero_iff] constructor · by_contra! obtain ⟨h, hfs⟩ := this simp_rw [ne_eq, eVariationOn.eq_zero_iff] at hfs h push_neg at hfs obtain ⟨x, xs, y, ys, hxy⟩ := hfs rcases le_total x y with (xy | yx) · exact hxy (h xs ys x ⟨xs, le_rfl, xy⟩ y ⟨ys, xy, le_rfl⟩) · rw [edist_comm] at hxy exact hxy (h ys xs y ⟨ys, le_rfl, yx⟩ x ⟨xs, yx, le_rfl⟩) · rintro h x _ y _ refine le_antisymm ?_ zero_le' rw [← h] exact eVariationOn.mono f inter_subset_left #align has_constant_speed_on_with_zero_iff hasConstantSpeedOnWith_zero_iff theorem HasConstantSpeedOnWith.ratio {l' : ℝ≥0} (hl' : l' ≠ 0) {φ : ℝ → ℝ} (φm : MonotoneOn φ s) (hfφ : HasConstantSpeedOnWith (f ∘ φ) s l) (hf : HasConstantSpeedOnWith f (φ '' s) l') ⦃x : ℝ⦄ (xs : x ∈ s) : EqOn φ (fun y => l / l' * (y - x) + φ x) s := by rintro y ys rw [← sub_eq_iff_eq_add, mul_comm, ← mul_div_assoc, eq_div_iff (NNReal.coe_ne_zero.mpr hl')] rw [hasConstantSpeedOnWith_iff_variationOnFromTo_eq] at hf rw [hasConstantSpeedOnWith_iff_variationOnFromTo_eq] at hfφ symm calc (y - x) * l = l * (y - x) := by rw [mul_comm] _ = variationOnFromTo (f ∘ φ) s x y := (hfφ.2 xs ys).symm _ = variationOnFromTo f (φ '' s) (φ x) (φ y) := (variationOnFromTo.comp_eq_of_monotoneOn f φ φm xs ys) _ = l' * (φ y - φ x) := (hf.2 ⟨x, xs, rfl⟩ ⟨y, ys, rfl⟩) _ = (φ y - φ x) * l' := by rw [mul_comm] #align has_constant_speed_on_with.ratio HasConstantSpeedOnWith.ratio /-- `f` has unit speed on `s` if it is linearly parameterized by `l = 1` on `s`. -/ def HasUnitSpeedOn (f : ℝ → E) (s : Set ℝ) := HasConstantSpeedOnWith f s 1 #align has_unit_speed_on HasUnitSpeedOn theorem HasUnitSpeedOn.union {t : Set ℝ} {x : ℝ} (hfs : HasUnitSpeedOn f s) (hft : HasUnitSpeedOn f t) (hs : IsGreatest s x) (ht : IsLeast t x) : HasUnitSpeedOn f (s ∪ t) := HasConstantSpeedOnWith.union hfs hft hs ht #align has_unit_speed_on.union HasUnitSpeedOn.union theorem HasUnitSpeedOn.Icc_Icc {x y z : ℝ} (hfs : HasUnitSpeedOn f (Icc x y)) (hft : HasUnitSpeedOn f (Icc y z)) : HasUnitSpeedOn f (Icc x z) := HasConstantSpeedOnWith.Icc_Icc hfs hft #align has_unit_speed_on.Icc_Icc HasUnitSpeedOn.Icc_Icc /-- If both `f` and `f ∘ φ` have unit speed (on `t` and `s` respectively) and `φ` monotonically maps `s` onto `t`, then `φ` is just a translation (on `s`). -/ theorem unique_unit_speed {φ : ℝ → ℝ} (φm : MonotoneOn φ s) (hfφ : HasUnitSpeedOn (f ∘ φ) s) (hf : HasUnitSpeedOn f (φ '' s)) ⦃x : ℝ⦄ (xs : x ∈ s) : EqOn φ (fun y => y - x + φ x) s := by dsimp only [HasUnitSpeedOn] at hf hfφ convert HasConstantSpeedOnWith.ratio one_ne_zero φm hfφ hf xs using 3 norm_num #align unique_unit_speed unique_unit_speed /-- If both `f` and `f ∘ φ` have unit speed (on `Icc 0 t` and `Icc 0 s` respectively) and `φ` monotonically maps `Icc 0 s` onto `Icc 0 t`, then `φ` is the identity on `Icc 0 s` -/
Mathlib/Analysis/ConstantSpeed.lean
222
235
theorem unique_unit_speed_on_Icc_zero {s t : ℝ} (hs : 0 ≤ s) (ht : 0 ≤ t) {φ : ℝ → ℝ} (φm : MonotoneOn φ <| Icc 0 s) (φst : φ '' Icc 0 s = Icc 0 t) (hfφ : HasUnitSpeedOn (f ∘ φ) (Icc 0 s)) (hf : HasUnitSpeedOn f (Icc 0 t)) : EqOn φ id (Icc 0 s) := by
rw [← φst] at hf convert unique_unit_speed φm hfφ hf ⟨le_rfl, hs⟩ using 1 have : φ 0 = 0 := by have hm : 0 ∈ φ '' Icc 0 s := by simp only [φst, ht, mem_Icc, le_refl, and_self] obtain ⟨x, xs, hx⟩ := hm apply le_antisymm ((φm ⟨le_rfl, hs⟩ xs xs.1).trans_eq hx) _ have := φst ▸ mapsTo_image φ (Icc 0 s) exact (mem_Icc.mp (@this 0 (by rw [mem_Icc]; exact ⟨le_rfl, hs⟩))).1 simp only [tsub_zero, this, add_zero] rfl
/- 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] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true_iff, le_rfl] #align finset.right_mem_Ioc Finset.right_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 #align finset.left_not_mem_Ioc Finset.left_not_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 #align finset.left_not_mem_Ioo Finset.left_not_mem_Ioo -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 #align finset.right_not_mem_Ico Finset.right_not_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 #align finset.right_not_mem_Ioo Finset.right_not_mem_Ioo theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb #align finset.Icc_subset_Icc Finset.Icc_subset_Icc theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb #align finset.Ico_subset_Ico Finset.Ico_subset_Ico theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb #align finset.Ioc_subset_Ioc Finset.Ioc_subset_Ioc theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb #align finset.Ioo_subset_Ioo Finset.Ioo_subset_Ioo theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align finset.Icc_subset_Icc_left Finset.Icc_subset_Icc_left theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align finset.Ico_subset_Ico_left Finset.Ico_subset_Ico_left theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align finset.Ioc_subset_Ioc_left Finset.Ioc_subset_Ioc_left theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align finset.Ioo_subset_Ioo_left Finset.Ioo_subset_Ioo_left theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align finset.Icc_subset_Icc_right Finset.Icc_subset_Icc_right theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align finset.Ico_subset_Ico_right Finset.Ico_subset_Ico_right theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align finset.Ioc_subset_Ioc_right Finset.Ioc_subset_Ioc_right theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align finset.Ioo_subset_Ioo_right Finset.Ioo_subset_Ioo_right theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h #align finset.Ico_subset_Ioo_left Finset.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h #align finset.Ioc_subset_Ioo_right Finset.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h #align finset.Icc_subset_Ico_right Finset.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self #align finset.Ioo_subset_Ico_self Finset.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self #align finset.Ioo_subset_Ioc_self Finset.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self #align finset.Ico_subset_Icc_self Finset.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self #align finset.Ioc_subset_Icc_self Finset.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self #align finset.Ioo_subset_Icc_self Finset.Ioo_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] #align finset.Icc_subset_Icc_iff Finset.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] #align finset.Icc_subset_Ioo_iff Finset.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] #align finset.Icc_subset_Ico_iff Finset.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm #align finset.Icc_subset_Ioc_iff Finset.Icc_subset_Ioc_iff --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb #align finset.Icc_ssubset_Icc_left Finset.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb #align finset.Icc_ssubset_Icc_right Finset.Icc_ssubset_Icc_right variable (a) -- porting note (#10618): simp can prove this -- @[simp] theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align finset.Ico_self Finset.Ico_self -- porting note (#10618): simp can prove this -- @[simp] theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align finset.Ioc_self Finset.Ioc_self -- porting note (#10618): simp can prove this -- @[simp] theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align finset.Ioo_self Finset.Ioo_self variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ #align set.fintype_of_mem_bounds Set.fintypeOfMemBounds section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : (Ico a b).filter (· < c) = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt #align finset.Ico_filter_lt_of_le_left Finset.Ico_filter_lt_of_le_left theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : (Ico a b).filter (· < c) = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc #align finset.Ico_filter_lt_of_right_le Finset.Ico_filter_lt_of_right_le theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : (Ico a b).filter (· < c) = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb #align finset.Ico_filter_lt_of_le_right Finset.Ico_filter_lt_of_le_right theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : (Ico a b).filter (c ≤ ·) = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 #align finset.Ico_filter_le_of_le_left Finset.Ico_filter_le_of_le_left theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : (Ico a b).filter (b ≤ ·) = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le #align finset.Ico_filter_le_of_right_le Finset.Ico_filter_le_of_right_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : (Ico a b).filter (c ≤ ·) = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 #align finset.Ico_filter_le_of_left_le Finset.Ico_filter_le_of_left_le theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : (Icc a b).filter (· < c) = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h #align finset.Icc_filter_lt_of_lt_right Finset.Icc_filter_lt_of_lt_right theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : (Ioc a b).filter (· < c) = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h #align finset.Ioc_filter_lt_of_lt_right Finset.Ioc_filter_lt_of_lt_right theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : (Iic a).filter (· < c) = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h #align finset.Iic_filter_lt_of_lt_right Finset.Iic_filter_lt_of_lt_right variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : (univ.filter fun j => a < j ∧ j < b) = Ioo a b := by ext simp #align finset.filter_lt_lt_eq_Ioo Finset.filter_lt_lt_eq_Ioo theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : (univ.filter fun j => a < j ∧ j ≤ b) = Ioc a b := by ext simp #align finset.filter_lt_le_eq_Ioc Finset.filter_lt_le_eq_Ioc theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : (univ.filter fun j => a ≤ j ∧ j < b) = Ico a b := by ext simp #align finset.filter_le_lt_eq_Ico Finset.filter_le_lt_eq_Ico theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : (univ.filter fun j => a ≤ j ∧ j ≤ b) = Icc a b := by ext simp #align finset.filter_le_le_eq_Icc Finset.filter_le_le_eq_Icc end Filter section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self #align finset.Icc_subset_Ici_self Finset.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self #align finset.Ico_subset_Ici_self Finset.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self #align finset.Ioc_subset_Ioi_self Finset.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self #align finset.Ioo_subset_Ioi_self Finset.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self #align finset.Ioc_subset_Ici_self Finset.Ioc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self #align finset.Ioo_subset_Ici_self Finset.Ioo_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ @[simp] lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self #align finset.Icc_subset_Iic_self Finset.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self #align finset.Ioc_subset_Iic_self Finset.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self #align finset.Ico_subset_Iio_self Finset.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self #align finset.Ioo_subset_Iio_self Finset.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self #align finset.Ico_subset_Iic_self Finset.Ico_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self #align finset.Ioo_subset_Iic_self Finset.Ioo_subset_Iic_self end LocallyFiniteOrderBot end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a : α} theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self #align finset.Ioi_subset_Ici_self Finset.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set α} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx #align bdd_below.finite BddBelow.finite theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s := mt BddBelow.finite #align set.infinite.not_bdd_below Set.Infinite.not_bddBelow variable [Fintype α] theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : univ.filter (a < ·) = Ioi a := by ext simp #align finset.filter_lt_eq_Ioi Finset.filter_lt_eq_Ioi theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : univ.filter (a ≤ ·) = Ici a := by ext simp #align finset.filter_le_eq_Ici Finset.filter_le_eq_Ici end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {a : α} theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self #align finset.Iio_subset_Iic_self Finset.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite := hs.dual.finite #align bdd_above.finite BddAbove.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s := mt BddAbove.finite #align set.infinite.not_bdd_above Set.Infinite.not_bddAbove variable [Fintype α] theorem filter_gt_eq_Iio [DecidablePred (· < a)] : univ.filter (· < a) = Iio a := by ext simp #align finset.filter_gt_eq_Iio Finset.filter_gt_eq_Iio theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : univ.filter (· ≤ a) = Iic a := by ext simp #align finset.filter_ge_eq_Iic Finset.filter_ge_eq_Iic end LocallyFiniteOrderBot variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem disjoint_Ioi_Iio (a : α) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba #align finset.disjoint_Ioi_Iio Finset.disjoint_Ioi_Iio end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] #align finset.Icc_self Finset.Icc_self @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] #align finset.Icc_eq_singleton_iff Finset.Icc_eq_singleton_iff theorem Ico_disjoint_Ico_consecutive (a b c : α) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 #align finset.Ico_disjoint_Ico_consecutive Finset.Ico_disjoint_Ico_consecutive section DecidableEq variable [DecidableEq α] @[simp] theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] #align finset.Icc_erase_left Finset.Icc_erase_left @[simp] theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] #align finset.Icc_erase_right Finset.Icc_erase_right @[simp] theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] #align finset.Ico_erase_left Finset.Ico_erase_left @[simp] theorem Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj] #align finset.Ioc_erase_right Finset.Ioc_erase_right @[simp] theorem Icc_diff_both (a b : α) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj] #align finset.Icc_diff_both Finset.Icc_diff_both @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h] #align finset.Ico_insert_right Finset.Ico_insert_right @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h] #align finset.Ioc_insert_left Finset.Ioc_insert_left @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h] #align finset.Ioo_insert_left Finset.Ioo_insert_left @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h] #align finset.Ioo_insert_right Finset.Ioo_insert_right @[simp] theorem Icc_diff_Ico_self (h : a ≤ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h] #align finset.Icc_diff_Ico_self Finset.Icc_diff_Ico_self @[simp] theorem Icc_diff_Ioc_self (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h] #align finset.Icc_diff_Ioc_self Finset.Icc_diff_Ioc_self @[simp] theorem Icc_diff_Ioo_self (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h] #align finset.Icc_diff_Ioo_self Finset.Icc_diff_Ioo_self @[simp] theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h] #align finset.Ico_diff_Ioo_self Finset.Ico_diff_Ioo_self @[simp] theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h] #align finset.Ioc_diff_Ioo_self Finset.Ioc_diff_Ioo_self @[simp] theorem Ico_inter_Ico_consecutive (a b c : α) : Ico a b ∩ Ico b c = ∅ := (Ico_disjoint_Ico_consecutive a b c).eq_bot #align finset.Ico_inter_Ico_consecutive Finset.Ico_inter_Ico_consecutive end DecidableEq -- Those lemmas are purposefully the other way around /-- `Finset.cons` version of `Finset.Ico_insert_right`. -/ theorem Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico := by classical rw [cons_eq_insert, Ico_insert_right h] #align finset.Icc_eq_cons_Ico Finset.Icc_eq_cons_Ico /-- `Finset.cons` version of `Finset.Ioc_insert_left`. -/ theorem Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc := by classical rw [cons_eq_insert, Ioc_insert_left h] #align finset.Icc_eq_cons_Ioc Finset.Icc_eq_cons_Ioc /-- `Finset.cons` version of `Finset.Ioo_insert_right`. -/ theorem Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_right h] #align finset.Ioc_eq_cons_Ioo Finset.Ioc_eq_cons_Ioo /-- `Finset.cons` version of `Finset.Ioo_insert_left`. -/ theorem Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_left h] #align finset.Ico_eq_cons_Ioo Finset.Ico_eq_cons_Ioo theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : ((Ico a b).filter fun x => x ≤ a) = {a} := by ext x rw [mem_filter, mem_Ico, mem_singleton, and_right_comm, ← le_antisymm_iff, eq_comm] exact and_iff_left_of_imp fun h => h.le.trans_lt hab #align finset.Ico_filter_le_left Finset.Ico_filter_le_left theorem card_Ico_eq_card_Icc_sub_one (a b : α) : (Ico a b).card = (Icc a b).card - 1 := by classical by_cases h : a ≤ b · rw [Icc_eq_cons_Ico h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ico_eq_empty fun h' => h h'.le, Icc_eq_empty h, card_empty, Nat.zero_sub] #align finset.card_Ico_eq_card_Icc_sub_one Finset.card_Ico_eq_card_Icc_sub_one theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : (Ioc a b).card = (Icc a b).card - 1 := @card_Ico_eq_card_Icc_sub_one αᵒᵈ _ _ _ _ #align finset.card_Ioc_eq_card_Icc_sub_one Finset.card_Ioc_eq_card_Icc_sub_one theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : (Ioo a b).card = (Ico a b).card - 1 := by classical by_cases h : a < b · rw [Ico_eq_cons_Ioo h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, Nat.zero_sub] #align finset.card_Ioo_eq_card_Ico_sub_one Finset.card_Ioo_eq_card_Ico_sub_one theorem card_Ioo_eq_card_Ioc_sub_one (a b : α) : (Ioo a b).card = (Ioc a b).card - 1 := @card_Ioo_eq_card_Ico_sub_one αᵒᵈ _ _ _ _ #align finset.card_Ioo_eq_card_Ioc_sub_one Finset.card_Ioo_eq_card_Ioc_sub_one theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : (Ioo a b).card = (Icc a b).card - 2 := by rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one] rfl #align finset.card_Ioo_eq_card_Icc_sub_two Finset.card_Ioo_eq_card_Icc_sub_two end PartialOrder section BoundedPartialOrder variable [PartialOrder α] section OrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ici_erase [DecidableEq α] (a : α) : (Ici a).erase a = Ioi a := by ext simp_rw [Finset.mem_erase, mem_Ici, mem_Ioi, lt_iff_le_and_ne, and_comm, ne_comm] #align finset.Ici_erase Finset.Ici_erase @[simp] theorem Ioi_insert [DecidableEq α] (a : α) : insert a (Ioi a) = Ici a := by ext simp_rw [Finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm, eq_comm] #align finset.Ioi_insert Finset.Ioi_insert -- porting note (#10618): simp can prove this -- @[simp] theorem not_mem_Ioi_self {b : α} : b ∉ Ioi b := fun h => lt_irrefl _ (mem_Ioi.1 h) #align finset.not_mem_Ioi_self Finset.not_mem_Ioi_self -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Ioi_insert`. -/ theorem Ici_eq_cons_Ioi (a : α) : Ici a = (Ioi a).cons a not_mem_Ioi_self := by classical rw [cons_eq_insert, Ioi_insert] #align finset.Ici_eq_cons_Ioi Finset.Ici_eq_cons_Ioi theorem card_Ioi_eq_card_Ici_sub_one (a : α) : (Ioi a).card = (Ici a).card - 1 := by rw [Ici_eq_cons_Ioi, card_cons, Nat.add_sub_cancel_right] #align finset.card_Ioi_eq_card_Ici_sub_one Finset.card_Ioi_eq_card_Ici_sub_one end OrderTop section OrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iic_erase [DecidableEq α] (b : α) : (Iic b).erase b = Iio b := by ext simp_rw [Finset.mem_erase, mem_Iic, mem_Iio, lt_iff_le_and_ne, and_comm] #align finset.Iic_erase Finset.Iic_erase @[simp] theorem Iio_insert [DecidableEq α] (b : α) : insert b (Iio b) = Iic b := by ext simp_rw [Finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm] #align finset.Iio_insert Finset.Iio_insert -- porting note (#10618): simp can prove this -- @[simp] theorem not_mem_Iio_self {b : α} : b ∉ Iio b := fun h => lt_irrefl _ (mem_Iio.1 h) #align finset.not_mem_Iio_self Finset.not_mem_Iio_self -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Iio_insert`. -/ theorem Iic_eq_cons_Iio (b : α) : Iic b = (Iio b).cons b not_mem_Iio_self := by classical rw [cons_eq_insert, Iio_insert] #align finset.Iic_eq_cons_Iio Finset.Iic_eq_cons_Iio theorem card_Iio_eq_card_Iic_sub_one (a : α) : (Iio a).card = (Iic a).card - 1 := by rw [Iic_eq_cons_Iio, card_cons, Nat.add_sub_cancel_right] #align finset.card_Iio_eq_card_Iic_sub_one Finset.card_Iio_eq_card_Iic_sub_one end OrderBot end BoundedPartialOrder section SemilatticeSup variable [SemilatticeSup α] [LocallyFiniteOrderBot α] -- TODO: Why does `id_eq` simplify the LHS here but not the LHS of `Finset.sup_Iic`? lemma sup'_Iic (a : α) : (Iic a).sup' nonempty_Iic id = a := le_antisymm (sup'_le _ _ fun _ ↦ mem_Iic.1) <| le_sup' (f := id) <| mem_Iic.2 <| le_refl a @[simp] lemma sup_Iic [OrderBot α] (a : α) : (Iic a).sup id = a := le_antisymm (Finset.sup_le fun _ ↦ mem_Iic.1) <| le_sup (f := id) <| mem_Iic.2 <| le_refl a end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [LocallyFiniteOrderTop α] lemma inf'_Ici (a : α) : (Ici a).inf' nonempty_Ici id = a := ge_antisymm (le_inf' _ _ fun _ ↦ mem_Ici.1) <| inf'_le (f := id) <| mem_Ici.2 <| le_refl a @[simp] lemma inf_Ici [OrderTop α] (a : α) : (Ici a).inf id = a := le_antisymm (inf_le (f := id) <| mem_Ici.2 <| le_refl a) <| Finset.le_inf fun _ ↦ mem_Ici.1 end SemilatticeInf section LinearOrder variable [LinearOrder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] {a b : α} theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Ico, coe_Ico, Set.Ico_subset_Ico_iff h] #align finset.Ico_subset_Ico_iff Finset.Ico_subset_Ico_iff theorem Ico_union_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b ∪ Ico b c = Ico a c := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico_eq_Ico hab hbc] #align finset.Ico_union_Ico_eq_Ico Finset.Ico_union_Ico_eq_Ico @[simp] theorem Ioc_union_Ioc_eq_Ioc {a b c : α} (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c := by rw [← coe_inj, coe_union, coe_Ioc, coe_Ioc, coe_Ioc, Set.Ioc_union_Ioc_eq_Ioc h₁ h₂] #align finset.Ioc_union_Ioc_eq_Ioc Finset.Ioc_union_Ioc_eq_Ioc theorem Ico_subset_Ico_union_Ico {a b c : α} : Ico a c ⊆ Ico a b ∪ Ico b c := by rw [← coe_subset, coe_union, coe_Ico, coe_Ico, coe_Ico] exact Set.Ico_subset_Ico_union_Ico #align finset.Ico_subset_Ico_union_Ico Finset.Ico_subset_Ico_union_Ico theorem Ico_union_Ico' {a b c d : α} (hcb : c ≤ b) (had : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico' hcb had] #align finset.Ico_union_Ico' Finset.Ico_union_Ico' theorem Ico_union_Ico {a b c d : α} (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico h₁ h₂] #align finset.Ico_union_Ico Finset.Ico_union_Ico theorem Ico_inter_Ico {a b c d : α} : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [← coe_inj, coe_inter, coe_Ico, coe_Ico, coe_Ico, ← inf_eq_min, ← sup_eq_max, Set.Ico_inter_Ico] #align finset.Ico_inter_Ico Finset.Ico_inter_Ico @[simp] theorem Ico_filter_lt (a b c : α) : ((Ico a b).filter fun x => x < c) = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_filter_lt_of_right_le h, min_eq_left h] | inr h => rw [Ico_filter_lt_of_le_right h, min_eq_right h] #align finset.Ico_filter_lt Finset.Ico_filter_lt @[simp] theorem Ico_filter_le (a b c : α) : ((Ico a b).filter fun x => c ≤ x) = Ico (max a c) b := by cases le_total a c with | inl h => rw [Ico_filter_le_of_left_le h, max_eq_right h] | inr h => rw [Ico_filter_le_of_le_left h, max_eq_left h] #align finset.Ico_filter_le Finset.Ico_filter_le @[simp] theorem Ioo_filter_lt (a b c : α) : (Ioo a b).filter (· < c) = Ioo a (min b c) := by ext simp [and_assoc] #align finset.Ioo_filter_lt Finset.Ioo_filter_lt @[simp] theorem Iio_filter_lt {α} [LinearOrder α] [LocallyFiniteOrderBot α] (a b : α) : (Iio a).filter (· < b) = Iio (min a b) := by ext simp [and_assoc] #align finset.Iio_filter_lt Finset.Iio_filter_lt @[simp] theorem Ico_diff_Ico_left (a b c : α) : Ico a b \ Ico a c = Ico (max a c) b := by cases le_total a c with | inl h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, max_eq_right h, and_right_comm, not_and, not_lt] exact and_congr_left' ⟨fun hx => hx.2 hx.1, fun hx => ⟨h.trans hx, fun _ => hx⟩⟩ | inr h => rw [Ico_eq_empty_of_le h, sdiff_empty, max_eq_left h] #align finset.Ico_diff_Ico_left Finset.Ico_diff_Ico_left @[simp] theorem Ico_diff_Ico_right (a b c : α) : Ico a b \ Ico c b = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_eq_empty_of_le h, sdiff_empty, min_eq_left h] | inr h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, min_eq_right h, and_assoc, not_and', not_le] exact and_congr_right' ⟨fun hx => hx.2 hx.1, fun hx => ⟨hx.trans_le h, fun _ => hx⟩⟩ #align finset.Ico_diff_Ico_right Finset.Ico_diff_Ico_right end LocallyFiniteOrder section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {s : Set α} theorem _root_.Set.Infinite.exists_gt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, a < b := not_bddAbove_iff.1 hs.not_bddAbove #align set.infinite.exists_gt Set.Infinite.exists_gt theorem _root_.Set.infinite_iff_exists_gt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, a < b := ⟨Set.Infinite.exists_gt, Set.infinite_of_forall_exists_gt⟩ #align set.infinite_iff_exists_gt Set.infinite_iff_exists_gt end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {s : Set α} theorem _root_.Set.Infinite.exists_lt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, b < a := not_bddBelow_iff.1 hs.not_bddBelow #align set.infinite.exists_lt Set.Infinite.exists_lt theorem _root_.Set.infinite_iff_exists_lt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, b < a := ⟨Set.Infinite.exists_lt, Set.infinite_of_forall_exists_lt⟩ #align set.infinite_iff_exists_lt Set.infinite_iff_exists_lt end LocallyFiniteOrderTop variable [Fintype α] [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem Ioi_disjUnion_Iio (a : α) : (Ioi a).disjUnion (Iio a) (disjoint_Ioi_Iio a) = ({a} : Finset α)ᶜ := by ext simp [eq_comm] #align finset.Ioi_disj_union_Iio Finset.Ioi_disjUnion_Iio end LinearOrder section Lattice variable [Lattice α] [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α} theorem uIcc_toDual (a b : α) : [[toDual a, toDual b]] = [[a, b]].map toDual.toEmbedding := Icc_toDual _ _ #align finset.uIcc_to_dual Finset.uIcc_toDual @[simp] theorem uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h] #align finset.uIcc_of_le Finset.uIcc_of_le @[simp] theorem uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h] #align finset.uIcc_of_ge Finset.uIcc_of_ge theorem uIcc_comm (a b : α) : [[a, b]] = [[b, a]] := by rw [uIcc, uIcc, inf_comm, sup_comm] #align finset.uIcc_comm Finset.uIcc_comm -- porting note (#10618): simp can prove this -- @[simp] theorem uIcc_self : [[a, a]] = {a} := by simp [uIcc] #align finset.uIcc_self Finset.uIcc_self @[simp] theorem nonempty_uIcc : Finset.Nonempty [[a, b]] := nonempty_Icc.2 inf_le_sup #align finset.nonempty_uIcc Finset.nonempty_uIcc theorem Icc_subset_uIcc : Icc a b ⊆ [[a, b]] := Icc_subset_Icc inf_le_left le_sup_right #align finset.Icc_subset_uIcc Finset.Icc_subset_uIcc theorem Icc_subset_uIcc' : Icc b a ⊆ [[a, b]] := Icc_subset_Icc inf_le_right le_sup_left #align finset.Icc_subset_uIcc' Finset.Icc_subset_uIcc' -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_uIcc : a ∈ [[a, b]] := mem_Icc.2 ⟨inf_le_left, le_sup_left⟩ #align finset.left_mem_uIcc Finset.left_mem_uIcc -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_uIcc : b ∈ [[a, b]] := mem_Icc.2 ⟨inf_le_right, le_sup_right⟩ #align finset.right_mem_uIcc Finset.right_mem_uIcc theorem mem_uIcc_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [[a, b]] := Icc_subset_uIcc <| mem_Icc.2 ⟨ha, hb⟩ #align finset.mem_uIcc_of_le Finset.mem_uIcc_of_le theorem mem_uIcc_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [[a, b]] := Icc_subset_uIcc' <| mem_Icc.2 ⟨hb, ha⟩ #align finset.mem_uIcc_of_ge Finset.mem_uIcc_of_ge theorem uIcc_subset_uIcc (h₁ : a₁ ∈ [[a₂, b₂]]) (h₂ : b₁ ∈ [[a₂, b₂]]) : [[a₁, b₁]] ⊆ [[a₂, b₂]] := by rw [mem_uIcc] at h₁ h₂ exact Icc_subset_Icc (_root_.le_inf h₁.1 h₂.1) (_root_.sup_le h₁.2 h₂.2) #align finset.uIcc_subset_uIcc Finset.uIcc_subset_uIcc
Mathlib/Order/Interval/Finset/Basic.lean
972
974
theorem uIcc_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [[a₁, b₁]] ⊆ Icc a₂ b₂ := by
rw [mem_Icc] at ha hb exact Icc_subset_Icc (_root_.le_inf ha.1 hb.1) (_root_.sup_le ha.2 hb.2)
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Topology.Algebra.Monoid import Mathlib.Topology.Homeomorph #align_import topology.algebra.group_with_zero from "leanprover-community/mathlib"@"c10e724be91096453ee3db13862b9fb9a992fef2" /-! # Topological group with zero In this file we define `HasContinuousInv₀` to be a mixin typeclass a type with `Inv` and `Zero` (e.g., a `GroupWithZero`) such that `fun x ↦ x⁻¹` is continuous at all nonzero points. Any normed (semi)field has this property. Currently the only example of `HasContinuousInv₀` in `mathlib` which is not a normed field is the type `NNReal` (a.k.a. `ℝ≥0`) of nonnegative real numbers. Then we prove lemmas about continuity of `x ↦ x⁻¹` and `f / g` providing dot-style `*.inv₀` and `*.div` operations on `Filter.Tendsto`, `ContinuousAt`, `ContinuousWithinAt`, `ContinuousOn`, and `Continuous`. As a special case, we provide `*.div_const` operations that require only `DivInvMonoid` and `ContinuousMul` instances. All lemmas about `(⁻¹)` use `inv₀` in their names because lemmas without `₀` are used for `TopologicalGroup`s. We also use `'` in the typeclass name `HasContinuousInv₀` for the sake of consistency of notation. On a `GroupWithZero` with continuous multiplication, we also define left and right multiplication as homeomorphisms. -/ open Topology Filter Function /-! ### A `DivInvMonoid` with continuous multiplication If `G₀` is a `DivInvMonoid` with continuous `(*)`, then `(/y)` is continuous for any `y`. In this section we prove lemmas that immediately follow from this fact providing `*.div_const` dot-style operations on `Filter.Tendsto`, `ContinuousAt`, `ContinuousWithinAt`, `ContinuousOn`, and `Continuous`. -/ variable {α β G₀ : Type*} section DivConst variable [DivInvMonoid G₀] [TopologicalSpace G₀] [ContinuousMul G₀] {f : α → G₀} {s : Set α} {l : Filter α} theorem Filter.Tendsto.div_const {x : G₀} (hf : Tendsto f l (𝓝 x)) (y : G₀) : Tendsto (fun a => f a / y) l (𝓝 (x / y)) := by simpa only [div_eq_mul_inv] using hf.mul tendsto_const_nhds #align filter.tendsto.div_const Filter.Tendsto.div_const variable [TopologicalSpace α] nonrec theorem ContinuousAt.div_const {a : α} (hf : ContinuousAt f a) (y : G₀) : ContinuousAt (fun x => f x / y) a := hf.div_const y #align continuous_at.div_const ContinuousAt.div_const nonrec theorem ContinuousWithinAt.div_const {a} (hf : ContinuousWithinAt f s a) (y : G₀) : ContinuousWithinAt (fun x => f x / y) s a := hf.div_const _ #align continuous_within_at.div_const ContinuousWithinAt.div_const
Mathlib/Topology/Algebra/GroupWithZero.lean
69
71
theorem ContinuousOn.div_const (hf : ContinuousOn f s) (y : G₀) : ContinuousOn (fun x => f x / y) s := by
simpa only [div_eq_mul_inv] using hf.mul continuousOn_const
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Finsupp.Encodable import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Span import Mathlib.Data.Set.Countable #align_import linear_algebra.finsupp from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Properties of the module `α →₀ M` Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in `Data.Finsupp.Basic`. In this file we define `Finsupp.supported s` to be the set `{f : α →₀ M | f.support ⊆ s}` interpreted as a submodule of `α →₀ M`. We also define `LinearMap` versions of various maps: * `Finsupp.lsingle a : M →ₗ[R] ι →₀ M`: `Finsupp.single a` as a linear map; * `Finsupp.lapply a : (ι →₀ M) →ₗ[R] M`: the map `fun f ↦ f a` as a linear map; * `Finsupp.lsubtypeDomain (s : Set α) : (α →₀ M) →ₗ[R] (s →₀ M)`: restriction to a subtype as a linear map; * `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`; * `Finsupp.lsum`: `Finsupp.sum` or `Finsupp.liftAddHom` as a `LinearMap`; * `Finsupp.total α M R (v : ι → M)`: sends `l : ι → R` to the linear combination of `v i` with coefficients `l i`; * `Finsupp.totalOn`: a restricted version of `Finsupp.total` with domain `Finsupp.supported R R s` and codomain `Submodule.span R (v '' s)`; * `Finsupp.supportedEquivFinsupp`: a linear equivalence between the functions `α →₀ M` supported on `s` and the functions `s →₀ M`; * `Finsupp.lmapDomain`: a linear map version of `Finsupp.mapDomain`; * `Finsupp.domLCongr`: a `LinearEquiv` version of `Finsupp.domCongr`; * `Finsupp.congr`: if the sets `s` and `t` are equivalent, then `supported M R s` is equivalent to `supported M R t`; * `Finsupp.lcongr`: a `LinearEquiv`alence between `α →₀ M` and `β →₀ N` constructed using `e : α ≃ β` and `e' : M ≃ₗ[R] N`. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp section SMul variable {α : Type*} {β : Type*} {R : Type*} {M : Type*} {M₂ : Type*} theorem smul_sum [Zero β] [AddCommMonoid M] [DistribSMul R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • v.sum h = v.sum fun a b => c • h a b := Finset.smul_sum #align finsupp.smul_sum Finsupp.smul_sum @[simp] theorem sum_smul_index_linearMap' [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] {v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} : ((c • v).sum fun a => h a) = c • v.sum fun a => h a := by rw [Finsupp.sum_smul_index', Finsupp.smul_sum] · simp only [map_smul] · intro i exact (h i).map_zero #align finsupp.sum_smul_index_linear_map' Finsupp.sum_smul_index_linearMap' end SMul section LinearEquivFunOnFinite variable (R : Type*) {S : Type*} (M : Type*) (α : Type*) variable [Finite α] [AddCommMonoid M] [Semiring R] [Module R M] /-- Given `Finite α`, `linearEquivFunOnFinite R` is the natural `R`-linear equivalence between `α →₀ β` and `α → β`. -/ @[simps apply] noncomputable def linearEquivFunOnFinite : (α →₀ M) ≃ₗ[R] α → M := { equivFunOnFinite with toFun := (⇑) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv_fun_on_finite Finsupp.linearEquivFunOnFinite @[simp] theorem linearEquivFunOnFinite_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α) (single x m) = Pi.single x m := equivFunOnFinite_single x m #align finsupp.linear_equiv_fun_on_finite_single Finsupp.linearEquivFunOnFinite_single @[simp] theorem linearEquivFunOnFinite_symm_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α).symm (Pi.single x m) = single x m := equivFunOnFinite_symm_single x m #align finsupp.linear_equiv_fun_on_finite_symm_single Finsupp.linearEquivFunOnFinite_symm_single @[simp] theorem linearEquivFunOnFinite_symm_coe (f : α →₀ M) : (linearEquivFunOnFinite R M α).symm f = f := (linearEquivFunOnFinite R M α).symm_apply_apply f #align finsupp.linear_equiv_fun_on_finite_symm_coe Finsupp.linearEquivFunOnFinite_symm_coe end LinearEquivFunOnFinite section LinearEquiv.finsuppUnique variable (R : Type*) {S : Type*} (M : Type*) variable [AddCommMonoid M] [Semiring R] [Module R M] variable (α : Type*) [Unique α] /-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is `R`-linearly equivalent to `M`. -/ noncomputable def LinearEquiv.finsuppUnique : (α →₀ M) ≃ₗ[R] M := { Finsupp.equivFunOnFinite.trans (Equiv.funUnique α M) with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv.finsupp_unique Finsupp.LinearEquiv.finsuppUnique variable {R M} @[simp] theorem LinearEquiv.finsuppUnique_apply (f : α →₀ M) : LinearEquiv.finsuppUnique R M α f = f default := rfl #align finsupp.linear_equiv.finsupp_unique_apply Finsupp.LinearEquiv.finsuppUnique_apply variable {α} @[simp] theorem LinearEquiv.finsuppUnique_symm_apply [Unique α] (m : M) : (LinearEquiv.finsuppUnique R M α).symm m = Finsupp.single default m := by ext; simp [LinearEquiv.finsuppUnique, Equiv.funUnique, single, Pi.single, equivFunOnFinite, Function.update] #align finsupp.linear_equiv.finsupp_unique_symm_apply Finsupp.LinearEquiv.finsuppUnique_symm_apply end LinearEquiv.finsuppUnique variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] /-- Interpret `Finsupp.single a` as a linear map. -/ def lsingle (a : α) : M →ₗ[R] α →₀ M := { Finsupp.singleAddHom a with map_smul' := fun _ _ => (smul_single _ _ _).symm } #align finsupp.lsingle Finsupp.lsingle /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. -/ theorem lhom_ext ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a b, φ (single a b) = ψ (single a b)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h #align finsupp.lhom_ext Finsupp.lhom_ext /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. We formulate this fact using equality of linear maps `φ.comp (lsingle a)` and `ψ.comp (lsingle a)` so that the `ext` tactic can apply a type-specific extensionality lemma to prove equality of these maps. E.g., if `M = R`, then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/ -- Porting note: The priority should be higher than `LinearMap.ext`. @[ext high] theorem lhom_ext' ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a, φ.comp (lsingle a) = ψ.comp (lsingle a)) : φ = ψ := lhom_ext fun a => LinearMap.congr_fun (h a) #align finsupp.lhom_ext' Finsupp.lhom_ext' /-- Interpret `fun f : α →₀ M ↦ f a` as a linear map. -/ def lapply (a : α) : (α →₀ M) →ₗ[R] M := { Finsupp.applyAddHom a with map_smul' := fun _ _ => rfl } #align finsupp.lapply Finsupp.lapply section CompatibleSMul variable (R S M N ι : Type*) variable [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module S M] [Module S N] instance _root_.LinearMap.CompatibleSMul.finsupp_dom [SMulZeroClass R M] [DistribSMul R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul (ι →₀ M) N R S where map_smul f r m := by conv_rhs => rw [← sum_single m, map_finsupp_sum, smul_sum] erw [← sum_single (r • m), sum_mapRange_index single_zero, map_finsupp_sum] congr; ext i m; exact (f.comp <| lsingle i).map_smul_of_tower r m instance _root_.LinearMap.CompatibleSMul.finsupp_cod [SMul R M] [SMulZeroClass R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι →₀ N) R S where map_smul f r m := by ext i; apply ((lapply i).comp f).map_smul_of_tower end CompatibleSMul /-- Forget that a function is finitely supported. This is the linear version of `Finsupp.toFun`. -/ @[simps] def lcoeFun : (α →₀ M) →ₗ[R] α → M where toFun := (⇑) map_add' x y := by ext simp map_smul' x y := by ext simp #align finsupp.lcoe_fun Finsupp.lcoeFun section LSubtypeDomain variable (s : Set α) /-- Interpret `Finsupp.subtypeDomain s` as a linear map. -/ def lsubtypeDomain : (α →₀ M) →ₗ[R] s →₀ M where toFun := subtypeDomain fun x => x ∈ s map_add' _ _ := subtypeDomain_add map_smul' _ _ := ext fun _ => rfl #align finsupp.lsubtype_domain Finsupp.lsubtypeDomain theorem lsubtypeDomain_apply (f : α →₀ M) : (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M) f = subtypeDomain (fun x => x ∈ s) f := rfl #align finsupp.lsubtype_domain_apply Finsupp.lsubtypeDomain_apply end LSubtypeDomain @[simp] theorem lsingle_apply (a : α) (b : M) : (lsingle a : M →ₗ[R] α →₀ M) b = single a b := rfl #align finsupp.lsingle_apply Finsupp.lsingle_apply @[simp] theorem lapply_apply (a : α) (f : α →₀ M) : (lapply a : (α →₀ M) →ₗ[R] M) f = f a := rfl #align finsupp.lapply_apply Finsupp.lapply_apply @[simp] theorem lapply_comp_lsingle_same (a : α) : lapply a ∘ₗ lsingle a = (.id : M →ₗ[R] M) := by ext; simp @[simp] theorem lapply_comp_lsingle_of_ne (a a' : α) (h : a ≠ a') : lapply a ∘ₗ lsingle a' = (0 : M →ₗ[R] M) := by ext; simp [h.symm] @[simp] theorem ker_lsingle (a : α) : ker (lsingle a : M →ₗ[R] α →₀ M) = ⊥ := ker_eq_bot_of_injective (single_injective a) #align finsupp.ker_lsingle Finsupp.ker_lsingle theorem lsingle_range_le_ker_lapply (s t : Set α) (h : Disjoint s t) : ⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) ≤ ⨅ a ∈ t, ker (lapply a : (α →₀ M) →ₗ[R] M) := by refine iSup_le fun a₁ => iSup_le fun h₁ => range_le_iff_comap.2 ?_ simp only [(ker_comp _ _).symm, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf] intro b _ a₂ h₂ have : a₁ ≠ a₂ := fun eq => h.le_bot ⟨h₁, eq.symm ▸ h₂⟩ exact single_eq_of_ne this #align finsupp.lsingle_range_le_ker_lapply Finsupp.lsingle_range_le_ker_lapply theorem iInf_ker_lapply_le_bot : ⨅ a, ker (lapply a : (α →₀ M) →ₗ[R] M) ≤ ⊥ := by simp only [SetLike.le_def, mem_iInf, mem_ker, mem_bot, lapply_apply] exact fun a h => Finsupp.ext h #align finsupp.infi_ker_lapply_le_bot Finsupp.iInf_ker_lapply_le_bot theorem iSup_lsingle_range : ⨆ a, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) = ⊤ := by refine eq_top_iff.2 <| SetLike.le_def.2 fun f _ => ?_ rw [← sum_single f] exact sum_mem fun a _ => Submodule.mem_iSup_of_mem a ⟨_, rfl⟩ #align finsupp.supr_lsingle_range Finsupp.iSup_lsingle_range theorem disjoint_lsingle_lsingle (s t : Set α) (hs : Disjoint s t) : Disjoint (⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) (⨆ a ∈ t, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) := by -- Porting note: 2 placeholders are added to prevent timeout. refine (Disjoint.mono (lsingle_range_le_ker_lapply s sᶜ ?_) (lsingle_range_le_ker_lapply t tᶜ ?_)) ?_ · apply disjoint_compl_right · apply disjoint_compl_right rw [disjoint_iff_inf_le] refine le_trans (le_iInf fun i => ?_) iInf_ker_lapply_le_bot classical by_cases his : i ∈ s · by_cases hit : i ∈ t · exact (hs.le_bot ⟨his, hit⟩).elim exact inf_le_of_right_le (iInf_le_of_le i <| iInf_le _ hit) exact inf_le_of_left_le (iInf_le_of_le i <| iInf_le _ his) #align finsupp.disjoint_lsingle_lsingle Finsupp.disjoint_lsingle_lsingle theorem span_single_image (s : Set M) (a : α) : Submodule.span R (single a '' s) = (Submodule.span R s).map (lsingle a : M →ₗ[R] α →₀ M) := by rw [← span_image]; rfl #align finsupp.span_single_image Finsupp.span_single_image variable (M R) /-- `Finsupp.supported M R s` is the `R`-submodule of all `p : α →₀ M` such that `p.support ⊆ s`. -/ def supported (s : Set α) : Submodule R (α →₀ M) where carrier := { p | ↑p.support ⊆ s } add_mem' {p q} hp hq := by classical refine Subset.trans (Subset.trans (Finset.coe_subset.2 support_add) ?_) (union_subset hp hq) rw [Finset.coe_union] zero_mem' := by simp only [subset_def, Finset.mem_coe, Set.mem_setOf_eq, mem_support_iff, zero_apply] intro h ha exact (ha rfl).elim smul_mem' a p hp := Subset.trans (Finset.coe_subset.2 support_smul) hp #align finsupp.supported Finsupp.supported variable {M} theorem mem_supported {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ↑p.support ⊆ s := Iff.rfl #align finsupp.mem_supported Finsupp.mem_supported theorem mem_supported' {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ∀ x ∉ s, p x = 0 := by haveI := Classical.decPred fun x : α => x ∈ s; simp [mem_supported, Set.subset_def, not_imp_comm] #align finsupp.mem_supported' Finsupp.mem_supported' theorem mem_supported_support (p : α →₀ M) : p ∈ Finsupp.supported M R (p.support : Set α) := by rw [Finsupp.mem_supported] #align finsupp.mem_supported_support Finsupp.mem_supported_support theorem single_mem_supported {s : Set α} {a : α} (b : M) (h : a ∈ s) : single a b ∈ supported M R s := Set.Subset.trans support_single_subset (Finset.singleton_subset_set_iff.2 h) #align finsupp.single_mem_supported Finsupp.single_mem_supported theorem supported_eq_span_single (s : Set α) : supported R R s = span R ((fun i => single i 1) '' s) := by refine (span_eq_of_le _ ?_ (SetLike.le_def.2 fun l hl => ?_)).symm · rintro _ ⟨_, hp, rfl⟩ exact single_mem_supported R 1 hp · rw [← l.sum_single] refine sum_mem fun i il => ?_ -- Porting note: Needed to help this convert quite a bit replacing underscores convert smul_mem (M := α →₀ R) (x := single i 1) (span R ((fun i => single i 1) '' s)) (l i) ?_ · simp [span] · apply subset_span apply Set.mem_image_of_mem _ (hl il) #align finsupp.supported_eq_span_single Finsupp.supported_eq_span_single variable (M) /-- Interpret `Finsupp.filter s` as a linear map from `α →₀ M` to `supported M R s`. -/ def restrictDom (s : Set α) [DecidablePred (· ∈ s)] : (α →₀ M) →ₗ[R] supported M R s := LinearMap.codRestrict _ { toFun := filter (· ∈ s) map_add' := fun _ _ => filter_add map_smul' := fun _ _ => filter_smul } fun l => (mem_supported' _ _).2 fun _ => filter_apply_neg (· ∈ s) l #align finsupp.restrict_dom Finsupp.restrictDom variable {M R} section @[simp] theorem restrictDom_apply (s : Set α) (l : α →₀ M) [DecidablePred (· ∈ s)]: (restrictDom M R s l : α →₀ M) = Finsupp.filter (· ∈ s) l := rfl #align finsupp.restrict_dom_apply Finsupp.restrictDom_apply end theorem restrictDom_comp_subtype (s : Set α) [DecidablePred (· ∈ s)] : (restrictDom M R s).comp (Submodule.subtype _) = LinearMap.id := by ext l a by_cases h : a ∈ s <;> simp [h] exact ((mem_supported' R l.1).1 l.2 a h).symm #align finsupp.restrict_dom_comp_subtype Finsupp.restrictDom_comp_subtype theorem range_restrictDom (s : Set α) [DecidablePred (· ∈ s)] : LinearMap.range (restrictDom M R s) = ⊤ := range_eq_top.2 <| Function.RightInverse.surjective <| LinearMap.congr_fun (restrictDom_comp_subtype s) #align finsupp.range_restrict_dom Finsupp.range_restrictDom theorem supported_mono {s t : Set α} (st : s ⊆ t) : supported M R s ≤ supported M R t := fun _ h => Set.Subset.trans h st #align finsupp.supported_mono Finsupp.supported_mono @[simp] theorem supported_empty : supported M R (∅ : Set α) = ⊥ := eq_bot_iff.2 fun l h => (Submodule.mem_bot R).2 <| by ext; simp_all [mem_supported'] #align finsupp.supported_empty Finsupp.supported_empty @[simp] theorem supported_univ : supported M R (Set.univ : Set α) = ⊤ := eq_top_iff.2 fun _ _ => Set.subset_univ _ #align finsupp.supported_univ Finsupp.supported_univ theorem supported_iUnion {δ : Type*} (s : δ → Set α) : supported M R (⋃ i, s i) = ⨆ i, supported M R (s i) := by refine le_antisymm ?_ (iSup_le fun i => supported_mono <| Set.subset_iUnion _ _) haveI := Classical.decPred fun x => x ∈ ⋃ i, s i suffices LinearMap.range ((Submodule.subtype _).comp (restrictDom M R (⋃ i, s i))) ≤ ⨆ i, supported M R (s i) by rwa [LinearMap.range_comp, range_restrictDom, Submodule.map_top, range_subtype] at this rw [range_le_iff_comap, eq_top_iff] rintro l ⟨⟩ -- Porting note: Was ported as `induction l using Finsupp.induction` refine Finsupp.induction l ?_ ?_ · exact zero_mem _ · refine fun x a l _ _ => add_mem ?_ by_cases h : ∃ i, x ∈ s i <;> simp [h] cases' h with i hi exact le_iSup (fun i => supported M R (s i)) i (single_mem_supported R _ hi) #align finsupp.supported_Union Finsupp.supported_iUnion theorem supported_union (s t : Set α) : supported M R (s ∪ t) = supported M R s ⊔ supported M R t := by erw [Set.union_eq_iUnion, supported_iUnion, iSup_bool_eq]; rfl #align finsupp.supported_union Finsupp.supported_union theorem supported_iInter {ι : Type*} (s : ι → Set α) : supported M R (⋂ i, s i) = ⨅ i, supported M R (s i) := Submodule.ext fun x => by simp [mem_supported, subset_iInter_iff] #align finsupp.supported_Inter Finsupp.supported_iInter theorem supported_inter (s t : Set α) : supported M R (s ∩ t) = supported M R s ⊓ supported M R t := by rw [Set.inter_eq_iInter, supported_iInter, iInf_bool_eq]; rfl #align finsupp.supported_inter Finsupp.supported_inter theorem disjoint_supported_supported {s t : Set α} (h : Disjoint s t) : Disjoint (supported M R s) (supported M R t) := disjoint_iff.2 <| by rw [← supported_inter, disjoint_iff_inter_eq_empty.1 h, supported_empty] #align finsupp.disjoint_supported_supported Finsupp.disjoint_supported_supported theorem disjoint_supported_supported_iff [Nontrivial M] {s t : Set α} : Disjoint (supported M R s) (supported M R t) ↔ Disjoint s t := by refine ⟨fun h => Set.disjoint_left.mpr fun x hx1 hx2 => ?_, disjoint_supported_supported⟩ rcases exists_ne (0 : M) with ⟨y, hy⟩ have := h.le_bot ⟨single_mem_supported R y hx1, single_mem_supported R y hx2⟩ rw [mem_bot, single_eq_zero] at this exact hy this #align finsupp.disjoint_supported_supported_iff Finsupp.disjoint_supported_supported_iff /-- Interpret `Finsupp.restrictSupportEquiv` as a linear equivalence between `supported M R s` and `s →₀ M`. -/ def supportedEquivFinsupp (s : Set α) : supported M R s ≃ₗ[R] s →₀ M := by let F : supported M R s ≃ (s →₀ M) := restrictSupportEquiv s M refine F.toLinearEquiv ?_ have : (F : supported M R s → ↥s →₀ M) = (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M).comp (Submodule.subtype (supported M R s)) := rfl rw [this] exact LinearMap.isLinear _ #align finsupp.supported_equiv_finsupp Finsupp.supportedEquivFinsupp section LSum variable (S) variable [Module S N] [SMulCommClass R S N] /-- Lift a family of linear maps `M →ₗ[R] N` indexed by `x : α` to a linear map from `α →₀ M` to `N` using `Finsupp.sum`. This is an upgraded version of `Finsupp.liftAddHom`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ def lsum : (α → M →ₗ[R] N) ≃ₗ[S] (α →₀ M) →ₗ[R] N where toFun F := { toFun := fun d => d.sum fun i => F i map_add' := (liftAddHom (α := α) (M := M) (N := N) fun x => (F x).toAddMonoidHom).map_add map_smul' := fun c f => by simp [sum_smul_index', smul_sum] } invFun F x := F.comp (lsingle x) left_inv F := by ext x y simp right_inv F := by ext x y simp map_add' F G := by ext x y simp map_smul' F G := by ext x y simp #align finsupp.lsum Finsupp.lsum @[simp] theorem coe_lsum (f : α → M →ₗ[R] N) : (lsum S f : (α →₀ M) → N) = fun d => d.sum fun i => f i := rfl #align finsupp.coe_lsum Finsupp.coe_lsum theorem lsum_apply (f : α → M →ₗ[R] N) (l : α →₀ M) : Finsupp.lsum S f l = l.sum fun b => f b := rfl #align finsupp.lsum_apply Finsupp.lsum_apply theorem lsum_single (f : α → M →ₗ[R] N) (i : α) (m : M) : Finsupp.lsum S f (Finsupp.single i m) = f i m := Finsupp.sum_single_index (f i).map_zero #align finsupp.lsum_single Finsupp.lsum_single @[simp] theorem lsum_comp_lsingle (f : α → M →ₗ[R] N) (i : α) : Finsupp.lsum S f ∘ₗ lsingle i = f i := by ext; simp theorem lsum_symm_apply (f : (α →₀ M) →ₗ[R] N) (x : α) : (lsum S).symm f x = f.comp (lsingle x) := rfl #align finsupp.lsum_symm_apply Finsupp.lsum_symm_apply end LSum section variable (M) (R) (X : Type*) (S) variable [Module S M] [SMulCommClass R S M] /-- A slight rearrangement from `lsum` gives us the bijection underlying the free-forgetful adjunction for R-modules. -/ noncomputable def lift : (X → M) ≃+ ((X →₀ R) →ₗ[R] M) := (AddEquiv.arrowCongr (Equiv.refl X) (ringLmapEquivSelf R ℕ M).toAddEquiv.symm).trans (lsum _ : _ ≃ₗ[ℕ] _).toAddEquiv #align finsupp.lift Finsupp.lift @[simp] theorem lift_symm_apply (f) (x) : ((lift M R X).symm f) x = f (single x 1) := rfl #align finsupp.lift_symm_apply Finsupp.lift_symm_apply @[simp] theorem lift_apply (f) (g) : ((lift M R X) f) g = g.sum fun x r => r • f x := rfl #align finsupp.lift_apply Finsupp.lift_apply /-- Given compatible `S` and `R`-module structures on `M` and a type `X`, the set of functions `X → M` is `S`-linearly equivalent to the `R`-linear maps from the free `R`-module on `X` to `M`. -/ noncomputable def llift : (X → M) ≃ₗ[S] (X →₀ R) →ₗ[R] M := { lift M R X with map_smul' := by intros dsimp ext simp only [coe_comp, Function.comp_apply, lsingle_apply, lift_apply, Pi.smul_apply, sum_single_index, zero_smul, one_smul, LinearMap.smul_apply] } #align finsupp.llift Finsupp.llift @[simp] theorem llift_apply (f : X → M) (x : X →₀ R) : llift M R S X f x = lift M R X f x := rfl #align finsupp.llift_apply Finsupp.llift_apply @[simp] theorem llift_symm_apply (f : (X →₀ R) →ₗ[R] M) (x : X) : (llift M R S X).symm f x = f (single x 1) := rfl #align finsupp.llift_symm_apply Finsupp.llift_symm_apply end section LMapDomain variable {α' : Type*} {α'' : Type*} (M R) /-- Interpret `Finsupp.mapDomain` as a linear map. -/ def lmapDomain (f : α → α') : (α →₀ M) →ₗ[R] α' →₀ M where toFun := mapDomain f map_add' _ _ := mapDomain_add map_smul' := mapDomain_smul #align finsupp.lmap_domain Finsupp.lmapDomain @[simp] theorem lmapDomain_apply (f : α → α') (l : α →₀ M) : (lmapDomain M R f : (α →₀ M) →ₗ[R] α' →₀ M) l = mapDomain f l := rfl #align finsupp.lmap_domain_apply Finsupp.lmapDomain_apply @[simp] theorem lmapDomain_id : (lmapDomain M R _root_.id : (α →₀ M) →ₗ[R] α →₀ M) = LinearMap.id := LinearMap.ext fun _ => mapDomain_id #align finsupp.lmap_domain_id Finsupp.lmapDomain_id theorem lmapDomain_comp (f : α → α') (g : α' → α'') : lmapDomain M R (g ∘ f) = (lmapDomain M R g).comp (lmapDomain M R f) := LinearMap.ext fun _ => mapDomain_comp #align finsupp.lmap_domain_comp Finsupp.lmapDomain_comp theorem supported_comap_lmapDomain (f : α → α') (s : Set α') : supported M R (f ⁻¹' s) ≤ (supported M R s).comap (lmapDomain M R f) := by classical intro l (hl : (l.support : Set α) ⊆ f ⁻¹' s) show ↑(mapDomain f l).support ⊆ s rw [← Set.image_subset_iff, ← Finset.coe_image] at hl exact Set.Subset.trans mapDomain_support hl #align finsupp.supported_comap_lmap_domain Finsupp.supported_comap_lmapDomain theorem lmapDomain_supported (f : α → α') (s : Set α) : (supported M R s).map (lmapDomain M R f) = supported M R (f '' s) := by classical cases isEmpty_or_nonempty α · simp [s.eq_empty_of_isEmpty] refine le_antisymm (map_le_iff_le_comap.2 <| le_trans (supported_mono <| Set.subset_preimage_image _ _) (supported_comap_lmapDomain M R _ _)) ?_ intro l hl refine ⟨(lmapDomain M R (Function.invFunOn f s) : (α' →₀ M) →ₗ[R] α →₀ M) l, fun x hx => ?_, ?_⟩ · rcases Finset.mem_image.1 (mapDomain_support hx) with ⟨c, hc, rfl⟩ exact Function.invFunOn_mem (by simpa using hl hc) · rw [← LinearMap.comp_apply, ← lmapDomain_comp] refine (mapDomain_congr fun c hc => ?_).trans mapDomain_id exact Function.invFunOn_eq (by simpa using hl hc) #align finsupp.lmap_domain_supported Finsupp.lmapDomain_supported theorem lmapDomain_disjoint_ker (f : α → α') {s : Set α} (H : ∀ a ∈ s, ∀ b ∈ s, f a = f b → a = b) : Disjoint (supported M R s) (ker (lmapDomain M R f)) := by rw [disjoint_iff_inf_le] rintro l ⟨h₁, h₂⟩ rw [SetLike.mem_coe, mem_ker, lmapDomain_apply, mapDomain] at h₂ simp; ext x haveI := Classical.decPred fun x => x ∈ s by_cases xs : x ∈ s · have : Finsupp.sum l (fun a => Finsupp.single (f a)) (f x) = 0 := by rw [h₂] rfl rw [Finsupp.sum_apply, Finsupp.sum_eq_single x, single_eq_same] at this · simpa · intro y hy xy simp only [SetLike.mem_coe, mem_supported, subset_def, Finset.mem_coe, mem_support_iff] at h₁ simp [mt (H _ (h₁ _ hy) _ xs) xy] · simp (config := { contextual := true }) · by_contra h exact xs (h₁ <| Finsupp.mem_support_iff.2 h) #align finsupp.lmap_domain_disjoint_ker Finsupp.lmapDomain_disjoint_ker end LMapDomain section LComapDomain variable {β : Type*} /-- Given `f : α → β` and a proof `hf` that `f` is injective, `lcomapDomain f hf` is the linear map sending `l : β →₀ M` to the finitely supported function from `α` to `M` given by composing `l` with `f`. This is the linear version of `Finsupp.comapDomain`. -/ def lcomapDomain (f : α → β) (hf : Function.Injective f) : (β →₀ M) →ₗ[R] α →₀ M where toFun l := Finsupp.comapDomain f l hf.injOn map_add' x y := by ext; simp map_smul' c x := by ext; simp #align finsupp.lcomap_domain Finsupp.lcomapDomain end LComapDomain section Total variable (α) (M) (R) variable {α' : Type*} {M' : Type*} [AddCommMonoid M'] [Module R M'] (v : α → M) {v' : α' → M'} /-- Interprets (l : α →₀ R) as linear combination of the elements in the family (v : α → M) and evaluates this linear combination. -/ protected def total : (α →₀ R) →ₗ[R] M := Finsupp.lsum ℕ fun i => LinearMap.id.smulRight (v i) #align finsupp.total Finsupp.total variable {α M v} theorem total_apply (l : α →₀ R) : Finsupp.total α M R v l = l.sum fun i a => a • v i := rfl #align finsupp.total_apply Finsupp.total_apply theorem total_apply_of_mem_supported {l : α →₀ R} {s : Finset α} (hs : l ∈ supported R R (↑s : Set α)) : Finsupp.total α M R v l = s.sum fun i => l i • v i := Finset.sum_subset hs fun x _ hxg => show l x • v x = 0 by rw [not_mem_support_iff.1 hxg, zero_smul] #align finsupp.total_apply_of_mem_supported Finsupp.total_apply_of_mem_supported @[simp] theorem total_single (c : R) (a : α) : Finsupp.total α M R v (single a c) = c • v a := by simp [total_apply, sum_single_index] #align finsupp.total_single Finsupp.total_single theorem total_zero_apply (x : α →₀ R) : (Finsupp.total α M R 0) x = 0 := by simp [Finsupp.total_apply] #align finsupp.total_zero_apply Finsupp.total_zero_apply variable (α M) @[simp] theorem total_zero : Finsupp.total α M R 0 = 0 := LinearMap.ext (total_zero_apply R) #align finsupp.total_zero Finsupp.total_zero variable {α M} theorem apply_total (f : M →ₗ[R] M') (v) (l : α →₀ R) : f (Finsupp.total α M R v l) = Finsupp.total α M' R (f ∘ v) l := by apply Finsupp.induction_linear l <;> simp (config := { contextual := true }) #align finsupp.apply_total Finsupp.apply_total theorem apply_total_id (f : M →ₗ[R] M') (l : M →₀ R) : f (Finsupp.total M M R _root_.id l) = Finsupp.total M M' R f l := apply_total .. theorem total_unique [Unique α] (l : α →₀ R) (v) : Finsupp.total α M R v l = l default • v default := by rw [← total_single, ← unique_single l] #align finsupp.total_unique Finsupp.total_unique
Mathlib/LinearAlgebra/Finsupp.lean
705
709
theorem total_surjective (h : Function.Surjective v) : Function.Surjective (Finsupp.total α M R v) := by
intro x obtain ⟨y, hy⟩ := h x exact ⟨Finsupp.single y 1, by simp [hy]⟩
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Measure.MutuallySingular import Mathlib.MeasureTheory.Measure.Count import Mathlib.Topology.IndicatorConstPointwise import Mathlib.MeasureTheory.Constructions.BorelSpace.Real #align_import measure_theory.integral.lebesgue from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Lower Lebesgue integral for `ℝ≥0∞`-valued functions We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function. ## Notation We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`. * `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`; * `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure `volume` on `α`; * `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`; * `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`. -/ assert_not_exists NormedSpace set_option autoImplicit true noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc variable {α β γ δ : Type*} section Lintegral open SimpleFunc variable {m : MeasurableSpace α} {μ ν : Measure α} /-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/ irreducible_def lintegral {_ : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ := ⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ #align measure_theory.lintegral MeasureTheory.lintegral /-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫⁻ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = f.lintegral μ := by rw [MeasureTheory.lintegral] exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl) (le_iSup₂_of_le f le_rfl le_rfl) #align measure_theory.simple_func.lintegral_eq_lintegral MeasureTheory.SimpleFunc.lintegral_eq_lintegral @[mono] theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by rw [lintegral, lintegral] exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩ #align measure_theory.lintegral_mono' MeasureTheory.lintegral_mono' -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn' ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) (h2 : μ ≤ ν) : lintegral μ f ≤ lintegral ν g := lintegral_mono' h2 hfg theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono' (le_refl μ) hfg #align measure_theory.lintegral_mono MeasureTheory.lintegral_mono -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : lintegral μ f ≤ lintegral μ g := lintegral_mono hfg theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a) #align measure_theory.lintegral_mono_nnreal MeasureTheory.lintegral_mono_nnreal theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) : ⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by apply le_antisymm · exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i · rw [lintegral] refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_ exact le_of_eq (i.lintegral_eq_lintegral _).symm #align measure_theory.supr_lintegral_measurable_le_eq_lintegral MeasureTheory.iSup_lintegral_measurable_le_eq_lintegral theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set MeasureTheory.lintegral_mono_set theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set' MeasureTheory.lintegral_mono_set' theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) := lintegral_mono #align measure_theory.monotone_lintegral MeasureTheory.monotone_lintegral @[simp] theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const] rfl #align measure_theory.lintegral_const MeasureTheory.lintegral_const theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp #align measure_theory.lintegral_zero MeasureTheory.lintegral_zero theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 := lintegral_zero #align measure_theory.lintegral_zero_fun MeasureTheory.lintegral_zero_fun -- @[simp] -- Porting note (#10618): simp can prove this theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul] #align measure_theory.lintegral_one MeasureTheory.lintegral_one theorem set_lintegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by rw [lintegral_const, Measure.restrict_apply_univ] #align measure_theory.set_lintegral_const MeasureTheory.set_lintegral_const theorem set_lintegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [set_lintegral_const, one_mul] #align measure_theory.set_lintegral_one MeasureTheory.set_lintegral_one theorem set_lintegral_const_lt_top [IsFiniteMeasure μ] (s : Set α) {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _ in s, c ∂μ < ∞ := by rw [lintegral_const] exact ENNReal.mul_lt_top hc (measure_ne_top (μ.restrict s) univ) #align measure_theory.set_lintegral_const_lt_top MeasureTheory.set_lintegral_const_lt_top theorem lintegral_const_lt_top [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _, c ∂μ < ∞ := by simpa only [Measure.restrict_univ] using set_lintegral_const_lt_top (univ : Set α) hc #align measure_theory.lintegral_const_lt_top MeasureTheory.lintegral_const_lt_top section variable (μ) /-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same integral. -/ theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) : ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀ · exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩ rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩ have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by intro n simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using (hLf n).2 choose g hgm hgf hLg using this refine ⟨fun x => ⨆ n, g n x, measurable_iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩ · refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_ exact le_iSup (fun n => g n x) n · exact lintegral_mono fun x => iSup_le fun n => hgf n x #align measure_theory.exists_measurable_le_lintegral_eq MeasureTheory.exists_measurable_le_lintegral_eq end /-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions `φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take functions `φ : α →ₛ ℝ≥0`. -/ theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = ⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by rw [lintegral] refine le_antisymm (iSup₂_le fun φ hφ => ?_) (iSup_mono' fun φ => ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩) by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞ · let ψ := φ.map ENNReal.toNNReal replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x) exact le_iSup_of_le (φ.map ENNReal.toNNReal) (le_iSup_of_le this (ge_of_eq <| lintegral_congr h)) · have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_nmem.1 h refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_) obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb) use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞}) simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const, ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast, restrict_const_lintegral] refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩ simp only [mem_preimage, mem_singleton_iff] at hx simp only [hx, le_top] #align measure_theory.lintegral_eq_nnreal MeasureTheory.lintegral_eq_nnreal theorem exists_simpleFunc_forall_lintegral_sub_lt_of_pos {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ φ : α →ₛ ℝ≥0, (∀ x, ↑(φ x) ≤ f x) ∧ ∀ ψ : α →ₛ ℝ≥0, (∀ x, ↑(ψ x) ≤ f x) → (map (↑) (ψ - φ)).lintegral μ < ε := by rw [lintegral_eq_nnreal] at h have := ENNReal.lt_add_right h hε erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => zero_le _⟩] simp_rw [lt_iSup_iff, iSup_lt_iff, iSup_le_iff] at this rcases this with ⟨φ, hle : ∀ x, ↑(φ x) ≤ f x, b, hbφ, hb⟩ refine ⟨φ, hle, fun ψ hψ => ?_⟩ have : (map (↑) φ).lintegral μ ≠ ∞ := ne_top_of_le_ne_top h (by exact le_iSup₂ (α := ℝ≥0∞) φ hle) rw [← ENNReal.add_lt_add_iff_left this, ← add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine (hb _ fun x => le_trans ?_ (max_le (hle x) (hψ x))).trans_lt hbφ norm_cast simp only [add_apply, sub_apply, add_tsub_eq_max] rfl #align measure_theory.exists_simple_func_forall_lintegral_sub_lt_of_pos MeasureTheory.exists_simpleFunc_forall_lintegral_sub_lt_of_pos theorem iSup_lintegral_le {ι : Sort*} (f : ι → α → ℝ≥0∞) : ⨆ i, ∫⁻ a, f i a ∂μ ≤ ∫⁻ a, ⨆ i, f i a ∂μ := by simp only [← iSup_apply] exact (monotone_lintegral μ).le_map_iSup #align measure_theory.supr_lintegral_le MeasureTheory.iSup_lintegral_le theorem iSup₂_lintegral_le {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ⨆ (i) (j), ∫⁻ a, f i j a ∂μ ≤ ∫⁻ a, ⨆ (i) (j), f i j a ∂μ := by convert (monotone_lintegral μ).le_map_iSup₂ f with a simp only [iSup_apply] #align measure_theory.supr₂_lintegral_le MeasureTheory.iSup₂_lintegral_le theorem le_iInf_lintegral {ι : Sort*} (f : ι → α → ℝ≥0∞) : ∫⁻ a, ⨅ i, f i a ∂μ ≤ ⨅ i, ∫⁻ a, f i a ∂μ := by simp only [← iInf_apply] exact (monotone_lintegral μ).map_iInf_le #align measure_theory.le_infi_lintegral MeasureTheory.le_iInf_lintegral theorem le_iInf₂_lintegral {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ∫⁻ a, ⨅ (i) (h : ι' i), f i h a ∂μ ≤ ⨅ (i) (h : ι' i), ∫⁻ a, f i h a ∂μ := by convert (monotone_lintegral μ).map_iInf₂_le f with a simp only [iInf_apply] #align measure_theory.le_infi₂_lintegral MeasureTheory.le_iInf₂_lintegral theorem lintegral_mono_ae {f g : α → ℝ≥0∞} (h : ∀ᵐ a ∂μ, f a ≤ g a) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_superset_of_null h with ⟨t, hts, ht, ht0⟩ have : ∀ᵐ x ∂μ, x ∉ t := measure_zero_iff_ae_nmem.1 ht0 rw [lintegral, lintegral] refine iSup_le fun s => iSup_le fun hfs => le_iSup_of_le (s.restrict tᶜ) <| le_iSup_of_le ?_ ?_ · intro a by_cases h : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, h, not_true, not_false_eq_true, indicator_of_not_mem, zero_le, not_false_eq_true, indicator_of_mem] exact le_trans (hfs a) (_root_.by_contradiction fun hnfg => h (hts hnfg)) · refine le_of_eq (SimpleFunc.lintegral_congr <| this.mono fun a hnt => ?_) by_cases hat : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, hat, not_true, not_false_eq_true, indicator_of_not_mem, not_false_eq_true, indicator_of_mem] exact (hnt hat).elim #align measure_theory.lintegral_mono_ae MeasureTheory.lintegral_mono_ae theorem set_lintegral_mono_ae {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff <| measurableSet_le hf hg).2 hfg #align measure_theory.set_lintegral_mono_ae MeasureTheory.set_lintegral_mono_ae theorem set_lintegral_mono {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae hf hg (ae_of_all _ hfg) #align measure_theory.set_lintegral_mono MeasureTheory.set_lintegral_mono theorem set_lintegral_mono_ae' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff' hs).2 hfg theorem set_lintegral_mono' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae' hs (ae_of_all _ hfg) theorem set_lintegral_le_lintegral (s : Set α) (f : α → ℝ≥0∞) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl theorem lintegral_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := le_antisymm (lintegral_mono_ae <| h.le) (lintegral_mono_ae <| h.symm.le) #align measure_theory.lintegral_congr_ae MeasureTheory.lintegral_congr_ae theorem lintegral_congr {f g : α → ℝ≥0∞} (h : ∀ a, f a = g a) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by simp only [h] #align measure_theory.lintegral_congr MeasureTheory.lintegral_congr theorem set_lintegral_congr {f : α → ℝ≥0∞} {s t : Set α} (h : s =ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := by rw [Measure.restrict_congr_set h] #align measure_theory.set_lintegral_congr MeasureTheory.set_lintegral_congr theorem set_lintegral_congr_fun {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := by rw [lintegral_congr_ae] rw [EventuallyEq] rwa [ae_restrict_iff' hs] #align measure_theory.set_lintegral_congr_fun MeasureTheory.set_lintegral_congr_fun theorem lintegral_ofReal_le_lintegral_nnnorm (f : α → ℝ) : ∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [← ofReal_norm_eq_coe_nnnorm] refine lintegral_mono fun x => ENNReal.ofReal_le_ofReal ?_ rw [Real.norm_eq_abs] exact le_abs_self (f x) #align measure_theory.lintegral_of_real_le_lintegral_nnnorm MeasureTheory.lintegral_ofReal_le_lintegral_nnnorm theorem lintegral_nnnorm_eq_of_ae_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ᵐ[μ] f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by apply lintegral_congr_ae filter_upwards [h_nonneg] with x hx rw [Real.nnnorm_of_nonneg hx, ENNReal.ofReal_eq_coe_nnreal hx] #align measure_theory.lintegral_nnnorm_eq_of_ae_nonneg MeasureTheory.lintegral_nnnorm_eq_of_ae_nonneg theorem lintegral_nnnorm_eq_of_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := lintegral_nnnorm_eq_of_ae_nonneg (Filter.eventually_of_forall h_nonneg) #align measure_theory.lintegral_nnnorm_eq_of_nonneg MeasureTheory.lintegral_nnnorm_eq_of_nonneg /-- **Monotone convergence theorem** -- sometimes called **Beppo-Levi convergence**. See `lintegral_iSup_directed` for a more general form. -/ theorem lintegral_iSup {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : Monotone f) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by set c : ℝ≥0 → ℝ≥0∞ := (↑) set F := fun a : α => ⨆ n, f n a refine le_antisymm ?_ (iSup_lintegral_le _) rw [lintegral_eq_nnreal] refine iSup_le fun s => iSup_le fun hsf => ?_ refine ENNReal.le_of_forall_lt_one_mul_le fun a ha => ?_ rcases ENNReal.lt_iff_exists_coe.1 ha with ⟨r, rfl, _⟩ have ha : r < 1 := ENNReal.coe_lt_coe.1 ha let rs := s.map fun a => r * a have eq_rs : rs.map c = (const α r : α →ₛ ℝ≥0∞) * map c s := rfl have eq : ∀ p, rs.map c ⁻¹' {p} = ⋃ n, rs.map c ⁻¹' {p} ∩ { a | p ≤ f n a } := by intro p rw [← inter_iUnion]; nth_rw 1 [← inter_univ (map c rs ⁻¹' {p})] refine Set.ext fun x => and_congr_right fun hx => true_iff_iff.2 ?_ by_cases p_eq : p = 0 · simp [p_eq] simp only [coe_map, mem_preimage, Function.comp_apply, mem_singleton_iff] at hx subst hx have : r * s x ≠ 0 := by rwa [Ne, ← ENNReal.coe_eq_zero] have : s x ≠ 0 := right_ne_zero_of_mul this have : (rs.map c) x < ⨆ n : ℕ, f n x := by refine lt_of_lt_of_le (ENNReal.coe_lt_coe.2 ?_) (hsf x) suffices r * s x < 1 * s x by simpa exact mul_lt_mul_of_pos_right ha (pos_iff_ne_zero.2 this) rcases lt_iSup_iff.1 this with ⟨i, hi⟩ exact mem_iUnion.2 ⟨i, le_of_lt hi⟩ have mono : ∀ r : ℝ≥0∞, Monotone fun n => rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a } := by intro r i j h refine inter_subset_inter_right _ ?_ simp_rw [subset_def, mem_setOf] intro x hx exact le_trans hx (h_mono h x) have h_meas : ∀ n, MeasurableSet {a : α | map c rs a ≤ f n a} := fun n => measurableSet_le (SimpleFunc.measurable _) (hf n) calc (r : ℝ≥0∞) * (s.map c).lintegral μ = ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r}) := by rw [← const_mul_lintegral, eq_rs, SimpleFunc.lintegral] _ = ∑ r ∈ (rs.map c).range, r * μ (⋃ n, rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by simp only [(eq _).symm] _ = ∑ r ∈ (rs.map c).range, ⨆ n, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := (Finset.sum_congr rfl fun x _ => by rw [measure_iUnion_eq_iSup (mono x).directed_le, ENNReal.mul_iSup]) _ = ⨆ n, ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by refine ENNReal.finset_sum_iSup_nat fun p i j h ↦ ?_ gcongr _ * μ ?_ exact mono p h _ ≤ ⨆ n : ℕ, ((rs.map c).restrict { a | (rs.map c) a ≤ f n a }).lintegral μ := by gcongr with n rw [restrict_lintegral _ (h_meas n)] refine le_of_eq (Finset.sum_congr rfl fun r _ => ?_) congr 2 with a refine and_congr_right ?_ simp (config := { contextual := true }) _ ≤ ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [← SimpleFunc.lintegral_eq_lintegral] gcongr with n a simp only [map_apply] at h_meas simp only [coe_map, restrict_apply _ (h_meas _), (· ∘ ·)] exact indicator_apply_le id #align measure_theory.lintegral_supr MeasureTheory.lintegral_iSup /-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence. Version with ae_measurable functions. -/ theorem lintegral_iSup' {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iSup_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Monotone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_mono have h_ae_seq_mono : Monotone (aeSeq hf p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet hf p · exact aeSeq.prop_of_mem_aeSeqSet hf hx hnm · simp only [aeSeq, hx, if_false, le_rfl] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] simp_rw [iSup_apply] rw [lintegral_iSup (aeSeq.measurable hf p) h_ae_seq_mono] congr with n exact lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae hf hp n) #align measure_theory.lintegral_supr' MeasureTheory.lintegral_iSup' /-- Monotone convergence theorem expressed with limits -/ theorem lintegral_tendsto_of_tendsto_of_monotone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 <| F x)) : Tendsto (fun n => ∫⁻ x, f n x ∂μ) atTop (𝓝 <| ∫⁻ x, F x ∂μ) := by have : Monotone fun n => ∫⁻ x, f n x ∂μ := fun i j hij => lintegral_mono_ae (h_mono.mono fun x hx => hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨆ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iSup this rw [← lintegral_iSup' hf h_mono] refine lintegral_congr_ae ?_ filter_upwards [h_mono, h_tendsto] with _ hx_mono hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iSup hx_mono) #align measure_theory.lintegral_tendsto_of_tendsto_of_monotone MeasureTheory.lintegral_tendsto_of_tendsto_of_monotone theorem lintegral_eq_iSup_eapprox_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = ⨆ n, (eapprox f n).lintegral μ := calc ∫⁻ a, f a ∂μ = ∫⁻ a, ⨆ n, (eapprox f n : α → ℝ≥0∞) a ∂μ := by congr; ext a; rw [iSup_eapprox_apply f hf] _ = ⨆ n, ∫⁻ a, (eapprox f n : α → ℝ≥0∞) a ∂μ := by apply lintegral_iSup · measurability · intro i j h exact monotone_eapprox f h _ = ⨆ n, (eapprox f n).lintegral μ := by congr; ext n; rw [(eapprox f n).lintegral_eq_lintegral] #align measure_theory.lintegral_eq_supr_eapprox_lintegral MeasureTheory.lintegral_eq_iSup_eapprox_lintegral /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. This lemma states this fact in terms of `ε` and `δ`. -/ theorem exists_pos_set_lintegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ δ > 0, ∀ s, μ s < δ → ∫⁻ x in s, f x ∂μ < ε := by rcases exists_between (pos_iff_ne_zero.mpr hε) with ⟨ε₂, hε₂0, hε₂ε⟩ rcases exists_between hε₂0 with ⟨ε₁, hε₁0, hε₁₂⟩ rcases exists_simpleFunc_forall_lintegral_sub_lt_of_pos h hε₁0.ne' with ⟨φ, _, hφ⟩ rcases φ.exists_forall_le with ⟨C, hC⟩ use (ε₂ - ε₁) / C, ENNReal.div_pos_iff.2 ⟨(tsub_pos_iff_lt.2 hε₁₂).ne', ENNReal.coe_ne_top⟩ refine fun s hs => lt_of_le_of_lt ?_ hε₂ε simp only [lintegral_eq_nnreal, iSup_le_iff] intro ψ hψ calc (map (↑) ψ).lintegral (μ.restrict s) ≤ (map (↑) φ).lintegral (μ.restrict s) + (map (↑) (ψ - φ)).lintegral (μ.restrict s) := by rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine SimpleFunc.lintegral_mono (fun x => ?_) le_rfl simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add, SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)] _ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by gcongr refine le_trans ?_ (hφ _ hψ).le exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self _ ≤ (SimpleFunc.const α (C : ℝ≥0∞)).lintegral (μ.restrict s) + ε₁ := by gcongr exact SimpleFunc.lintegral_mono (fun x ↦ ENNReal.coe_le_coe.2 (hC x)) le_rfl _ = C * μ s + ε₁ := by simp only [← SimpleFunc.lintegral_eq_lintegral, coe_const, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, Function.const] _ ≤ C * ((ε₂ - ε₁) / C) + ε₁ := by gcongr _ ≤ ε₂ - ε₁ + ε₁ := by gcongr; apply mul_div_le _ = ε₂ := tsub_add_cancel_of_le hε₁₂.le #align measure_theory.exists_pos_set_lintegral_lt_of_measure_lt MeasureTheory.exists_pos_set_lintegral_lt_of_measure_lt /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem tendsto_set_lintegral_zero {ι} {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {l : Filter ι} {s : ι → Set α} (hl : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫⁻ x in s i, f x ∂μ) l (𝓝 0) := by simp only [ENNReal.nhds_zero, tendsto_iInf, tendsto_principal, mem_Iio, ← pos_iff_ne_zero] at hl ⊢ intro ε ε0 rcases exists_pos_set_lintegral_lt_of_measure_lt h ε0.ne' with ⟨δ, δ0, hδ⟩ exact (hl δ δ0).mono fun i => hδ _ #align measure_theory.tendsto_set_lintegral_zero MeasureTheory.tendsto_set_lintegral_zero /-- The sum of the lower Lebesgue integrals of two functions is less than or equal to the integral of their sum. The other inequality needs one of these functions to be (a.e.-)measurable. -/ theorem le_lintegral_add (f g : α → ℝ≥0∞) : ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ ≤ ∫⁻ a, f a + g a ∂μ := by simp only [lintegral] refine ENNReal.biSup_add_biSup_le' (p := fun h : α →ₛ ℝ≥0∞ => h ≤ f) (q := fun h : α →ₛ ℝ≥0∞ => h ≤ g) ⟨0, zero_le f⟩ ⟨0, zero_le g⟩ fun f' hf' g' hg' => ?_ exact le_iSup₂_of_le (f' + g') (add_le_add hf' hg') (add_lintegral _ _).ge #align measure_theory.le_lintegral_add MeasureTheory.le_lintegral_add -- Use stronger lemmas `lintegral_add_left`/`lintegral_add_right` instead theorem lintegral_add_aux {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, (⨆ n, (eapprox f n : α → ℝ≥0∞) a) + ⨆ n, (eapprox g n : α → ℝ≥0∞) a ∂μ := by simp only [iSup_eapprox_apply, hf, hg] _ = ∫⁻ a, ⨆ n, (eapprox f n + eapprox g n : α → ℝ≥0∞) a ∂μ := by congr; funext a rw [ENNReal.iSup_add_iSup_of_monotone] · simp only [Pi.add_apply] · intro i j h exact monotone_eapprox _ h a · intro i j h exact monotone_eapprox _ h a _ = ⨆ n, (eapprox f n).lintegral μ + (eapprox g n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.add_lintegral, ← SimpleFunc.lintegral_eq_lintegral] simp only [Pi.add_apply, SimpleFunc.coe_add] · measurability · intro i j h a dsimp gcongr <;> exact monotone_eapprox _ h _ _ = (⨆ n, (eapprox f n).lintegral μ) + ⨆ n, (eapprox g n).lintegral μ := by refine (ENNReal.iSup_add_iSup_of_monotone ?_ ?_).symm <;> · intro i j h exact SimpleFunc.lintegral_mono (monotone_eapprox _ h) le_rfl _ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral hg] #align measure_theory.lintegral_add_aux MeasureTheory.lintegral_add_aux /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `f` is integrable, see also `MeasureTheory.lintegral_add_right` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by refine le_antisymm ?_ (le_lintegral_add _ _) rcases exists_measurable_le_lintegral_eq μ fun a => f a + g a with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, φ a ∂μ := hφ_eq _ ≤ ∫⁻ a, f a + (φ a - f a) ∂μ := lintegral_mono fun a => le_add_tsub _ = ∫⁻ a, f a ∂μ + ∫⁻ a, φ a - f a ∂μ := lintegral_add_aux hf (hφm.sub hf) _ ≤ ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := add_le_add_left (lintegral_mono fun a => tsub_le_iff_left.2 <| hφ_le a) _ #align measure_theory.lintegral_add_left MeasureTheory.lintegral_add_left theorem lintegral_add_left' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_congr_ae hf.ae_eq_mk, ← lintegral_add_left hf.measurable_mk, lintegral_congr_ae (hf.ae_eq_mk.add (ae_eq_refl g))] #align measure_theory.lintegral_add_left' MeasureTheory.lintegral_add_left' theorem lintegral_add_right' (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by simpa only [add_comm] using lintegral_add_left' hg f #align measure_theory.lintegral_add_right' MeasureTheory.lintegral_add_right' /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `g` is integrable, see also `MeasureTheory.lintegral_add_left` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := lintegral_add_right' f hg.aemeasurable #align measure_theory.lintegral_add_right MeasureTheory.lintegral_add_right @[simp] theorem lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂c • μ = c * ∫⁻ a, f a ∂μ := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_smul, ENNReal.mul_iSup, smul_eq_mul] #align measure_theory.lintegral_smul_measure MeasureTheory.lintegral_smul_measure lemma set_lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂(c • μ) = c * ∫⁻ a in s, f a ∂μ := by rw [Measure.restrict_smul, lintegral_smul_measure] @[simp] theorem lintegral_sum_measure {m : MeasurableSpace α} {ι} (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂Measure.sum μ = ∑' i, ∫⁻ a, f a ∂μ i := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_sum, ENNReal.tsum_eq_iSup_sum] rw [iSup_comm] congr; funext s induction' s using Finset.induction_on with i s hi hs · simp simp only [Finset.sum_insert hi, ← hs] refine (ENNReal.iSup_add_iSup ?_).symm intro φ ψ exact ⟨⟨φ ⊔ ψ, fun x => sup_le (φ.2 x) (ψ.2 x)⟩, add_le_add (SimpleFunc.lintegral_mono le_sup_left le_rfl) (Finset.sum_le_sum fun j _ => SimpleFunc.lintegral_mono le_sup_right le_rfl)⟩ #align measure_theory.lintegral_sum_measure MeasureTheory.lintegral_sum_measure theorem hasSum_lintegral_measure {ι} {_ : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : ι → Measure α) : HasSum (fun i => ∫⁻ a, f a ∂μ i) (∫⁻ a, f a ∂Measure.sum μ) := (lintegral_sum_measure f μ).symm ▸ ENNReal.summable.hasSum #align measure_theory.has_sum_lintegral_measure MeasureTheory.hasSum_lintegral_measure @[simp] theorem lintegral_add_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ ν : Measure α) : ∫⁻ a, f a ∂(μ + ν) = ∫⁻ a, f a ∂μ + ∫⁻ a, f a ∂ν := by simpa [tsum_fintype] using lintegral_sum_measure f fun b => cond b μ ν #align measure_theory.lintegral_add_measure MeasureTheory.lintegral_add_measure @[simp] theorem lintegral_finset_sum_measure {ι} {m : MeasurableSpace α} (s : Finset ι) (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫⁻ a, f a ∂μ i := by rw [← Measure.sum_coe_finset, lintegral_sum_measure, ← Finset.tsum_subtype'] simp only [Finset.coe_sort_coe] #align measure_theory.lintegral_finset_sum_measure MeasureTheory.lintegral_finset_sum_measure @[simp] theorem lintegral_zero_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂(0 : Measure α) = 0 := by simp [lintegral] #align measure_theory.lintegral_zero_measure MeasureTheory.lintegral_zero_measure @[simp] theorem lintegral_of_isEmpty {α} [MeasurableSpace α] [IsEmpty α] (μ : Measure α) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = 0 := by have : Subsingleton (Measure α) := inferInstance convert lintegral_zero_measure f theorem set_lintegral_empty (f : α → ℝ≥0∞) : ∫⁻ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, lintegral_zero_measure] #align measure_theory.set_lintegral_empty MeasureTheory.set_lintegral_empty theorem set_lintegral_univ (f : α → ℝ≥0∞) : ∫⁻ x in univ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [Measure.restrict_univ] #align measure_theory.set_lintegral_univ MeasureTheory.set_lintegral_univ theorem set_lintegral_measure_zero (s : Set α) (f : α → ℝ≥0∞) (hs' : μ s = 0) : ∫⁻ x in s, f x ∂μ = 0 := by convert lintegral_zero_measure _ exact Measure.restrict_eq_zero.2 hs' #align measure_theory.set_lintegral_measure_zero MeasureTheory.set_lintegral_measure_zero theorem lintegral_finset_sum' (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, AEMeasurable (f b) μ) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := by induction' s using Finset.induction_on with a s has ih · simp · simp only [Finset.sum_insert has] rw [Finset.forall_mem_insert] at hf rw [lintegral_add_left' hf.1, ih hf.2] #align measure_theory.lintegral_finset_sum' MeasureTheory.lintegral_finset_sum' theorem lintegral_finset_sum (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, Measurable (f b)) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := lintegral_finset_sum' s fun b hb => (hf b hb).aemeasurable #align measure_theory.lintegral_finset_sum MeasureTheory.lintegral_finset_sum @[simp] theorem lintegral_const_mul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := calc ∫⁻ a, r * f a ∂μ = ∫⁻ a, ⨆ n, (const α r * eapprox f n) a ∂μ := by congr funext a rw [← iSup_eapprox_apply f hf, ENNReal.mul_iSup] simp _ = ⨆ n, r * (eapprox f n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.const_mul_lintegral, ← SimpleFunc.lintegral_eq_lintegral] · intro n exact SimpleFunc.measurable _ · intro i j h a exact mul_le_mul_left' (monotone_eapprox _ h _) _ _ = r * ∫⁻ a, f a ∂μ := by rw [← ENNReal.mul_iSup, lintegral_eq_iSup_eapprox_lintegral hf] #align measure_theory.lintegral_const_mul MeasureTheory.lintegral_const_mul theorem lintegral_const_mul'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by have A : ∫⁻ a, f a ∂μ = ∫⁻ a, hf.mk f a ∂μ := lintegral_congr_ae hf.ae_eq_mk have B : ∫⁻ a, r * f a ∂μ = ∫⁻ a, r * hf.mk f a ∂μ := lintegral_congr_ae (EventuallyEq.fun_comp hf.ae_eq_mk _) rw [A, B, lintegral_const_mul _ hf.measurable_mk] #align measure_theory.lintegral_const_mul'' MeasureTheory.lintegral_const_mul'' theorem lintegral_const_mul_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : r * ∫⁻ a, f a ∂μ ≤ ∫⁻ a, r * f a ∂μ := by rw [lintegral, ENNReal.mul_iSup] refine iSup_le fun s => ?_ rw [ENNReal.mul_iSup, iSup_le_iff] intro hs rw [← SimpleFunc.const_mul_lintegral, lintegral] refine le_iSup_of_le (const α r * s) (le_iSup_of_le (fun x => ?_) le_rfl) exact mul_le_mul_left' (hs x) _ #align measure_theory.lintegral_const_mul_le MeasureTheory.lintegral_const_mul_le theorem lintegral_const_mul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by by_cases h : r = 0 · simp [h] apply le_antisymm _ (lintegral_const_mul_le r f) have rinv : r * r⁻¹ = 1 := ENNReal.mul_inv_cancel h hr have rinv' : r⁻¹ * r = 1 := by rw [mul_comm] exact rinv have := lintegral_const_mul_le (μ := μ) r⁻¹ fun x => r * f x simp? [(mul_assoc _ _ _).symm, rinv'] at this says simp only [(mul_assoc _ _ _).symm, rinv', one_mul] at this simpa [(mul_assoc _ _ _).symm, rinv] using mul_le_mul_left' this r #align measure_theory.lintegral_const_mul' MeasureTheory.lintegral_const_mul' theorem lintegral_mul_const (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul r hf] #align measure_theory.lintegral_mul_const MeasureTheory.lintegral_mul_const theorem lintegral_mul_const'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul'' r hf] #align measure_theory.lintegral_mul_const'' MeasureTheory.lintegral_mul_const'' theorem lintegral_mul_const_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (∫⁻ a, f a ∂μ) * r ≤ ∫⁻ a, f a * r ∂μ := by simp_rw [mul_comm, lintegral_const_mul_le r f] #align measure_theory.lintegral_mul_const_le MeasureTheory.lintegral_mul_const_le theorem lintegral_mul_const' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul' r f hr] #align measure_theory.lintegral_mul_const' MeasureTheory.lintegral_mul_const' /- A double integral of a product where each factor contains only one variable is a product of integrals -/ theorem lintegral_lintegral_mul {β} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g ν) : ∫⁻ x, ∫⁻ y, f x * g y ∂ν ∂μ = (∫⁻ x, f x ∂μ) * ∫⁻ y, g y ∂ν := by simp [lintegral_const_mul'' _ hg, lintegral_mul_const'' _ hf] #align measure_theory.lintegral_lintegral_mul MeasureTheory.lintegral_lintegral_mul -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₁ {f f' : α → β} (h : f =ᵐ[μ] f') (g : β → ℝ≥0∞) : ∫⁻ a, g (f a) ∂μ = ∫⁻ a, g (f' a) ∂μ := lintegral_congr_ae <| h.mono fun a h => by dsimp only; rw [h] #align measure_theory.lintegral_rw₁ MeasureTheory.lintegral_rw₁ -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₂ {f₁ f₁' : α → β} {f₂ f₂' : α → γ} (h₁ : f₁ =ᵐ[μ] f₁') (h₂ : f₂ =ᵐ[μ] f₂') (g : β → γ → ℝ≥0∞) : ∫⁻ a, g (f₁ a) (f₂ a) ∂μ = ∫⁻ a, g (f₁' a) (f₂' a) ∂μ := lintegral_congr_ae <| h₁.mp <| h₂.mono fun _ h₂ h₁ => by dsimp only; rw [h₁, h₂] #align measure_theory.lintegral_rw₂ MeasureTheory.lintegral_rw₂ theorem lintegral_indicator_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a, s.indicator f a ∂μ ≤ ∫⁻ a in s, f a ∂μ := by simp only [lintegral] apply iSup_le (fun g ↦ (iSup_le (fun hg ↦ ?_))) have : g ≤ f := hg.trans (indicator_le_self s f) refine le_iSup_of_le g (le_iSup_of_le this (le_of_eq ?_)) rw [lintegral_restrict, SimpleFunc.lintegral] congr with t by_cases H : t = 0 · simp [H] congr with x simp only [mem_preimage, mem_singleton_iff, mem_inter_iff, iff_self_and] rintro rfl contrapose! H simpa [H] using hg x @[simp] theorem lintegral_indicator (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by apply le_antisymm (lintegral_indicator_le f s) simp only [lintegral, ← restrict_lintegral_eq_lintegral_restrict _ hs, iSup_subtype'] refine iSup_mono' (Subtype.forall.2 fun φ hφ => ?_) refine ⟨⟨φ.restrict s, fun x => ?_⟩, le_rfl⟩ simp [hφ x, hs, indicator_le_indicator] #align measure_theory.lintegral_indicator MeasureTheory.lintegral_indicator theorem lintegral_indicator₀ (f : α → ℝ≥0∞) {s : Set α} (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by rw [← lintegral_congr_ae (indicator_ae_eq_of_ae_eq_set hs.toMeasurable_ae_eq), lintegral_indicator _ (measurableSet_toMeasurable _ _), Measure.restrict_congr_set hs.toMeasurable_ae_eq] #align measure_theory.lintegral_indicator₀ MeasureTheory.lintegral_indicator₀ theorem lintegral_indicator_const_le (s : Set α) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ ≤ c * μ s := (lintegral_indicator_le _ _).trans (set_lintegral_const s c).le theorem lintegral_indicator_const₀ {s : Set α} (hs : NullMeasurableSet s μ) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := by rw [lintegral_indicator₀ _ hs, set_lintegral_const] theorem lintegral_indicator_const {s : Set α} (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := lintegral_indicator_const₀ hs.nullMeasurableSet c #align measure_theory.lintegral_indicator_const MeasureTheory.lintegral_indicator_const theorem set_lintegral_eq_const {f : α → ℝ≥0∞} (hf : Measurable f) (r : ℝ≥0∞) : ∫⁻ x in { x | f x = r }, f x ∂μ = r * μ { x | f x = r } := by have : ∀ᵐ x ∂μ, x ∈ { x | f x = r } → f x = r := ae_of_all μ fun _ hx => hx rw [set_lintegral_congr_fun _ this] · rw [lintegral_const, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter] · exact hf (measurableSet_singleton r) #align measure_theory.set_lintegral_eq_const MeasureTheory.set_lintegral_eq_const theorem lintegral_indicator_one_le (s : Set α) : ∫⁻ a, s.indicator 1 a ∂μ ≤ μ s := (lintegral_indicator_const_le _ _).trans <| (one_mul _).le @[simp] theorem lintegral_indicator_one₀ (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const₀ hs _).trans <| one_mul _ @[simp] theorem lintegral_indicator_one (hs : MeasurableSet s) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const hs _).trans <| one_mul _ #align measure_theory.lintegral_indicator_one MeasureTheory.lintegral_indicator_one /-- A version of **Markov's inequality** for two functions. It doesn't follow from the standard Markov's inequality because we only assume measurability of `g`, not `f`. -/ theorem lintegral_add_mul_meas_add_le_le_lintegral {f g : α → ℝ≥0∞} (hle : f ≤ᵐ[μ] g) (hg : AEMeasurable g μ) (ε : ℝ≥0∞) : ∫⁻ a, f a ∂μ + ε * μ { x | f x + ε ≤ g x } ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_le_lintegral_eq μ f with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ x, f x ∂μ + ε * μ { x | f x + ε ≤ g x } = ∫⁻ x, φ x ∂μ + ε * μ { x | f x + ε ≤ g x } := by rw [hφ_eq] _ ≤ ∫⁻ x, φ x ∂μ + ε * μ { x | φ x + ε ≤ g x } := by gcongr exact fun x => (add_le_add_right (hφ_le _) _).trans _ = ∫⁻ x, φ x + indicator { x | φ x + ε ≤ g x } (fun _ => ε) x ∂μ := by rw [lintegral_add_left hφm, lintegral_indicator₀, set_lintegral_const] exact measurableSet_le (hφm.nullMeasurable.measurable'.add_const _) hg.nullMeasurable _ ≤ ∫⁻ x, g x ∂μ := lintegral_mono_ae (hle.mono fun x hx₁ => ?_) simp only [indicator_apply]; split_ifs with hx₂ exacts [hx₂, (add_zero _).trans_le <| (hφ_le x).trans hx₁] #align measure_theory.lintegral_add_mul_meas_add_le_le_lintegral MeasureTheory.lintegral_add_mul_meas_add_le_le_lintegral /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem mul_meas_ge_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := by simpa only [lintegral_zero, zero_add] using lintegral_add_mul_meas_add_le_le_lintegral (ae_of_all _ fun x => zero_le (f x)) hf ε #align measure_theory.mul_meas_ge_le_lintegral₀ MeasureTheory.mul_meas_ge_le_lintegral₀ /-- **Markov's inequality** also known as **Chebyshev's first inequality**. For a version assuming `AEMeasurable`, see `mul_meas_ge_le_lintegral₀`. -/ theorem mul_meas_ge_le_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := mul_meas_ge_le_lintegral₀ hf.aemeasurable ε #align measure_theory.mul_meas_ge_le_lintegral MeasureTheory.mul_meas_ge_le_lintegral lemma meas_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {s : Set α} (hs : ∀ x ∈ s, 1 ≤ f x) : μ s ≤ ∫⁻ a, f a ∂μ := by apply le_trans _ (mul_meas_ge_le_lintegral₀ hf 1) rw [one_mul] exact measure_mono hs lemma lintegral_le_meas {s : Set α} {f : α → ℝ≥0∞} (hf : ∀ a, f a ≤ 1) (h'f : ∀ a ∈ sᶜ, f a = 0) : ∫⁻ a, f a ∂μ ≤ μ s := by apply (lintegral_mono (fun x ↦ ?_)).trans (lintegral_indicator_one_le s) by_cases hx : x ∈ s · simpa [hx] using hf x · simpa [hx] using h'f x hx theorem lintegral_eq_top_of_measure_eq_top_ne_zero {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hμf : μ {x | f x = ∞} ≠ 0) : ∫⁻ x, f x ∂μ = ∞ := eq_top_iff.mpr <| calc ∞ = ∞ * μ { x | ∞ ≤ f x } := by simp [mul_eq_top, hμf] _ ≤ ∫⁻ x, f x ∂μ := mul_meas_ge_le_lintegral₀ hf ∞ #align measure_theory.lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.lintegral_eq_top_of_measure_eq_top_ne_zero theorem setLintegral_eq_top_of_measure_eq_top_ne_zero (hf : AEMeasurable f (μ.restrict s)) (hμf : μ ({x ∈ s | f x = ∞}) ≠ 0) : ∫⁻ x in s, f x ∂μ = ∞ := lintegral_eq_top_of_measure_eq_top_ne_zero hf <| mt (eq_bot_mono <| by rw [← setOf_inter_eq_sep]; exact Measure.le_restrict_apply _ _) hμf #align measure_theory.set_lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.setLintegral_eq_top_of_measure_eq_top_ne_zero theorem measure_eq_top_of_lintegral_ne_top (hf : AEMeasurable f μ) (hμf : ∫⁻ x, f x ∂μ ≠ ∞) : μ {x | f x = ∞} = 0 := of_not_not fun h => hμf <| lintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_lintegral_ne_top MeasureTheory.measure_eq_top_of_lintegral_ne_top theorem measure_eq_top_of_setLintegral_ne_top (hf : AEMeasurable f (μ.restrict s)) (hμf : ∫⁻ x in s, f x ∂μ ≠ ∞) : μ ({x ∈ s | f x = ∞}) = 0 := of_not_not fun h => hμf <| setLintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_set_lintegral_ne_top MeasureTheory.measure_eq_top_of_setLintegral_ne_top /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem meas_ge_le_lintegral_div {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) (hε' : ε ≠ ∞) : μ { x | ε ≤ f x } ≤ (∫⁻ a, f a ∂μ) / ε := (ENNReal.le_div_iff_mul_le (Or.inl hε) (Or.inl hε')).2 <| by rw [mul_comm] exact mul_meas_ge_le_lintegral₀ hf ε #align measure_theory.meas_ge_le_lintegral_div MeasureTheory.meas_ge_le_lintegral_div theorem ae_eq_of_ae_le_of_lintegral_le {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) (hf : ∫⁻ x, f x ∂μ ≠ ∞) (hg : AEMeasurable g μ) (hgf : ∫⁻ x, g x ∂μ ≤ ∫⁻ x, f x ∂μ) : f =ᵐ[μ] g := by have : ∀ n : ℕ, ∀ᵐ x ∂μ, g x < f x + (n : ℝ≥0∞)⁻¹ := by intro n simp only [ae_iff, not_lt] have : ∫⁻ x, f x ∂μ + (↑n)⁻¹ * μ { x : α | f x + (n : ℝ≥0∞)⁻¹ ≤ g x } ≤ ∫⁻ x, f x ∂μ := (lintegral_add_mul_meas_add_le_le_lintegral hfg hg n⁻¹).trans hgf rw [(ENNReal.cancel_of_ne hf).add_le_iff_nonpos_right, nonpos_iff_eq_zero, mul_eq_zero] at this exact this.resolve_left (ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _)) refine hfg.mp ((ae_all_iff.2 this).mono fun x hlt hle => hle.antisymm ?_) suffices Tendsto (fun n : ℕ => f x + (n : ℝ≥0∞)⁻¹) atTop (𝓝 (f x)) from ge_of_tendsto' this fun i => (hlt i).le simpa only [inv_top, add_zero] using tendsto_const_nhds.add (ENNReal.tendsto_inv_iff.2 ENNReal.tendsto_nat_nhds_top) #align measure_theory.ae_eq_of_ae_le_of_lintegral_le MeasureTheory.ae_eq_of_ae_le_of_lintegral_le @[simp] theorem lintegral_eq_zero_iff' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := have : ∫⁻ _ : α, 0 ∂μ ≠ ∞ := by simp [lintegral_zero, zero_ne_top] ⟨fun h => (ae_eq_of_ae_le_of_lintegral_le (ae_of_all _ <| zero_le f) this hf (h.trans lintegral_zero.symm).le).symm, fun h => (lintegral_congr_ae h).trans lintegral_zero⟩ #align measure_theory.lintegral_eq_zero_iff' MeasureTheory.lintegral_eq_zero_iff' @[simp] theorem lintegral_eq_zero_iff {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := lintegral_eq_zero_iff' hf.aemeasurable #align measure_theory.lintegral_eq_zero_iff MeasureTheory.lintegral_eq_zero_iff theorem lintegral_pos_iff_support {f : α → ℝ≥0∞} (hf : Measurable f) : (0 < ∫⁻ a, f a ∂μ) ↔ 0 < μ (Function.support f) := by simp [pos_iff_ne_zero, hf, Filter.EventuallyEq, ae_iff, Function.support] #align measure_theory.lintegral_pos_iff_support MeasureTheory.lintegral_pos_iff_support theorem setLintegral_pos_iff {f : α → ℝ≥0∞} (hf : Measurable f) {s : Set α} : 0 < ∫⁻ a in s, f a ∂μ ↔ 0 < μ (Function.support f ∩ s) := by rw [lintegral_pos_iff_support hf, Measure.restrict_apply (measurableSet_support hf)] /-- Weaker version of the monotone convergence theorem-/ theorem lintegral_iSup_ae {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f n.succ a) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by let ⟨s, hs⟩ := exists_measurable_superset_of_null (ae_iff.1 (ae_all_iff.2 h_mono)) let g n a := if a ∈ s then 0 else f n a have g_eq_f : ∀ᵐ a ∂μ, ∀ n, g n a = f n a := (measure_zero_iff_ae_nmem.1 hs.2.2).mono fun a ha n => if_neg ha calc ∫⁻ a, ⨆ n, f n a ∂μ = ∫⁻ a, ⨆ n, g n a ∂μ := lintegral_congr_ae <| g_eq_f.mono fun a ha => by simp only [ha] _ = ⨆ n, ∫⁻ a, g n a ∂μ := (lintegral_iSup (fun n => measurable_const.piecewise hs.2.1 (hf n)) (monotone_nat_of_le_succ fun n a => ?_)) _ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [lintegral_congr_ae (g_eq_f.mono fun _a ha => ha _)] simp only [g] split_ifs with h · rfl · have := Set.not_mem_subset hs.1 h simp only [not_forall, not_le, mem_setOf_eq, not_exists, not_lt] at this exact this n #align measure_theory.lintegral_supr_ae MeasureTheory.lintegral_iSup_ae theorem lintegral_sub' {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := by refine ENNReal.eq_sub_of_add_eq hg_fin ?_ rw [← lintegral_add_right' _ hg] exact lintegral_congr_ae (h_le.mono fun x hx => tsub_add_cancel_of_le hx) #align measure_theory.lintegral_sub' MeasureTheory.lintegral_sub' theorem lintegral_sub {f g : α → ℝ≥0∞} (hg : Measurable g) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := lintegral_sub' hg.aemeasurable hg_fin h_le #align measure_theory.lintegral_sub MeasureTheory.lintegral_sub theorem lintegral_sub_le' (f g : α → ℝ≥0∞) (hf : AEMeasurable f μ) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := by rw [tsub_le_iff_right] by_cases hfi : ∫⁻ x, f x ∂μ = ∞ · rw [hfi, add_top] exact le_top · rw [← lintegral_add_right' _ hf] gcongr exact le_tsub_add #align measure_theory.lintegral_sub_le' MeasureTheory.lintegral_sub_le' theorem lintegral_sub_le (f g : α → ℝ≥0∞) (hf : Measurable f) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := lintegral_sub_le' f g hf.aemeasurable #align measure_theory.lintegral_sub_le MeasureTheory.lintegral_sub_le theorem lintegral_strict_mono_of_ae_le_of_frequently_ae_lt {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) (h : ∃ᵐ x ∂μ, f x ≠ g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by contrapose! h simp only [not_frequently, Ne, Classical.not_not] exact ae_eq_of_ae_le_of_lintegral_le h_le hfi hg h #align measure_theory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt MeasureTheory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt theorem lintegral_strict_mono_of_ae_le_of_ae_lt_on {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) {s : Set α} (hμs : μ s ≠ 0) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := lintegral_strict_mono_of_ae_le_of_frequently_ae_lt hg hfi h_le <| ((frequently_ae_mem_iff.2 hμs).and_eventually h).mono fun _x hx => (hx.2 hx.1).ne #align measure_theory.lintegral_strict_mono_of_ae_le_of_ae_lt_on MeasureTheory.lintegral_strict_mono_of_ae_le_of_ae_lt_on theorem lintegral_strict_mono {f g : α → ℝ≥0∞} (hμ : μ ≠ 0) (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by rw [Ne, ← Measure.measure_univ_eq_zero] at hμ refine lintegral_strict_mono_of_ae_le_of_ae_lt_on hg hfi (ae_le_of_ae_lt h) hμ ?_ simpa using h #align measure_theory.lintegral_strict_mono MeasureTheory.lintegral_strict_mono theorem set_lintegral_strict_mono {f g : α → ℝ≥0∞} {s : Set α} (hsm : MeasurableSet s) (hs : μ s ≠ 0) (hg : Measurable g) (hfi : ∫⁻ x in s, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x in s, f x ∂μ < ∫⁻ x in s, g x ∂μ := lintegral_strict_mono (by simp [hs]) hg.aemeasurable hfi ((ae_restrict_iff' hsm).mpr h) #align measure_theory.set_lintegral_strict_mono MeasureTheory.set_lintegral_strict_mono /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf_ae {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_mono : ∀ n : ℕ, f n.succ ≤ᵐ[μ] f n) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := have fn_le_f0 : ∫⁻ a, ⨅ n, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := lintegral_mono fun a => iInf_le_of_le 0 le_rfl have fn_le_f0' : ⨅ n, ∫⁻ a, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := iInf_le_of_le 0 le_rfl (ENNReal.sub_right_inj h_fin fn_le_f0 fn_le_f0').1 <| show ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ from calc ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a - ⨅ n, f n a ∂μ := (lintegral_sub (measurable_iInf h_meas) (ne_top_of_le_ne_top h_fin <| lintegral_mono fun a => iInf_le _ _) (ae_of_all _ fun a => iInf_le _ _)).symm _ = ∫⁻ a, ⨆ n, f 0 a - f n a ∂μ := congr rfl (funext fun a => ENNReal.sub_iInf) _ = ⨆ n, ∫⁻ a, f 0 a - f n a ∂μ := (lintegral_iSup_ae (fun n => (h_meas 0).sub (h_meas n)) fun n => (h_mono n).mono fun a ha => tsub_le_tsub le_rfl ha) _ = ⨆ n, ∫⁻ a, f 0 a ∂μ - ∫⁻ a, f n a ∂μ := (have h_mono : ∀ᵐ a ∂μ, ∀ n : ℕ, f n.succ a ≤ f n a := ae_all_iff.2 h_mono have h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f 0 a := fun n => h_mono.mono fun a h => by induction' n with n ih · exact le_rfl · exact le_trans (h n) ih congr_arg iSup <| funext fun n => lintegral_sub (h_meas _) (ne_top_of_le_ne_top h_fin <| lintegral_mono_ae <| h_mono n) (h_mono n)) _ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ := ENNReal.sub_iInf.symm #align measure_theory.lintegral_infi_ae MeasureTheory.lintegral_iInf_ae /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_anti : Antitone f) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := lintegral_iInf_ae h_meas (fun n => ae_of_all _ <| h_anti n.le_succ) h_fin #align measure_theory.lintegral_infi MeasureTheory.lintegral_iInf theorem lintegral_iInf' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a)) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iInf_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Antitone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_anti have h_ae_seq_mono : Antitone (aeSeq h_meas p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet h_meas p · exact aeSeq.prop_of_mem_aeSeqSet h_meas hx hnm · simp only [aeSeq, hx, if_false] exact le_rfl rw [lintegral_congr_ae (aeSeq.iInf h_meas hp).symm] simp_rw [iInf_apply] rw [lintegral_iInf (aeSeq.measurable h_meas p) h_ae_seq_mono] · congr exact funext fun n ↦ lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp n) · rwa [lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp 0)] /-- Monotone convergence for an infimum over a directed family and indexed by a countable type -/ theorem lintegral_iInf_directed_of_measurable {mα : MeasurableSpace α} [Countable β] {f : β → α → ℝ≥0∞} {μ : Measure α} (hμ : μ ≠ 0) (hf : ∀ b, Measurable (f b)) (hf_int : ∀ b, ∫⁻ a, f b a ∂μ ≠ ∞) (h_directed : Directed (· ≥ ·) f) : ∫⁻ a, ⨅ b, f b a ∂μ = ⨅ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp only [iInf_of_empty, lintegral_const, ENNReal.top_mul (Measure.measure_univ_ne_zero.mpr hμ)] inhabit β have : ∀ a, ⨅ b, f b a = ⨅ n, f (h_directed.sequence f n) a := by refine fun a => le_antisymm (le_iInf fun n => iInf_le _ _) (le_iInf fun b => iInf_le_of_le (Encodable.encode b + 1) ?_) exact h_directed.sequence_le b a -- Porting note: used `∘` below to deal with its reduced reducibility calc ∫⁻ a, ⨅ b, f b a ∂μ _ = ∫⁻ a, ⨅ n, (f ∘ h_directed.sequence f) n a ∂μ := by simp only [this, Function.comp_apply] _ = ⨅ n, ∫⁻ a, (f ∘ h_directed.sequence f) n a ∂μ := by rw [lintegral_iInf ?_ h_directed.sequence_anti] · exact hf_int _ · exact fun n => hf _ _ = ⨅ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (le_iInf fun b => ?_) (le_iInf fun n => ?_) · exact iInf_le_of_le (Encodable.encode b + 1) (lintegral_mono <| h_directed.sequence_le b) · exact iInf_le (fun b => ∫⁻ a, f b a ∂μ) _ #align lintegral_infi_directed_of_measurable MeasureTheory.lintegral_iInf_directed_of_measurable /-- Known as Fatou's lemma, version with `AEMeasurable` functions -/ theorem lintegral_liminf_le' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := calc ∫⁻ a, liminf (fun n => f n a) atTop ∂μ = ∫⁻ a, ⨆ n : ℕ, ⨅ i ≥ n, f i a ∂μ := by simp only [liminf_eq_iSup_iInf_of_nat] _ = ⨆ n : ℕ, ∫⁻ a, ⨅ i ≥ n, f i a ∂μ := (lintegral_iSup' (fun n => aemeasurable_biInf _ (to_countable _) (fun i _ ↦ h_meas i)) (ae_of_all μ fun a n m hnm => iInf_le_iInf_of_subset fun i hi => le_trans hnm hi)) _ ≤ ⨆ n : ℕ, ⨅ i ≥ n, ∫⁻ a, f i a ∂μ := iSup_mono fun n => le_iInf₂_lintegral _ _ = atTop.liminf fun n => ∫⁻ a, f n a ∂μ := Filter.liminf_eq_iSup_iInf_of_nat.symm #align measure_theory.lintegral_liminf_le' MeasureTheory.lintegral_liminf_le' /-- Known as Fatou's lemma -/ theorem lintegral_liminf_le {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := lintegral_liminf_le' fun n => (h_meas n).aemeasurable #align measure_theory.lintegral_liminf_le MeasureTheory.lintegral_liminf_le theorem limsup_lintegral_le {f : ℕ → α → ℝ≥0∞} {g : α → ℝ≥0∞} (hf_meas : ∀ n, Measurable (f n)) (h_bound : ∀ n, f n ≤ᵐ[μ] g) (h_fin : ∫⁻ a, g a ∂μ ≠ ∞) : limsup (fun n => ∫⁻ a, f n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := calc limsup (fun n => ∫⁻ a, f n a ∂μ) atTop = ⨅ n : ℕ, ⨆ i ≥ n, ∫⁻ a, f i a ∂μ := limsup_eq_iInf_iSup_of_nat _ ≤ ⨅ n : ℕ, ∫⁻ a, ⨆ i ≥ n, f i a ∂μ := iInf_mono fun n => iSup₂_lintegral_le _ _ = ∫⁻ a, ⨅ n : ℕ, ⨆ i ≥ n, f i a ∂μ := by refine (lintegral_iInf ?_ ?_ ?_).symm · intro n exact measurable_biSup _ (to_countable _) (fun i _ ↦ hf_meas i) · intro n m hnm a exact iSup_le_iSup_of_subset fun i hi => le_trans hnm hi · refine ne_top_of_le_ne_top h_fin (lintegral_mono_ae ?_) refine (ae_all_iff.2 h_bound).mono fun n hn => ?_ exact iSup_le fun i => iSup_le fun _ => hn i _ = ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := by simp only [limsup_eq_iInf_iSup_of_nat] #align measure_theory.limsup_lintegral_le MeasureTheory.limsup_lintegral_le /-- Dominated convergence theorem for nonnegative functions -/ theorem tendsto_lintegral_of_dominated_convergence {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, Measurable (F n)) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := tendsto_of_le_liminf_of_limsup_le (calc ∫⁻ a, f a ∂μ = ∫⁻ a, liminf (fun n : ℕ => F n a) atTop ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.liminf_eq.symm _ ≤ liminf (fun n => ∫⁻ a, F n a ∂μ) atTop := lintegral_liminf_le hF_meas ) (calc limsup (fun n : ℕ => ∫⁻ a, F n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => F n a) atTop ∂μ := limsup_lintegral_le hF_meas h_bound h_fin _ = ∫⁻ a, f a ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.limsup_eq ) #align measure_theory.tendsto_lintegral_of_dominated_convergence MeasureTheory.tendsto_lintegral_of_dominated_convergence /-- Dominated convergence theorem for nonnegative functions which are just almost everywhere measurable. -/ theorem tendsto_lintegral_of_dominated_convergence' {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, AEMeasurable (F n) μ) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := by have : ∀ n, ∫⁻ a, F n a ∂μ = ∫⁻ a, (hF_meas n).mk (F n) a ∂μ := fun n => lintegral_congr_ae (hF_meas n).ae_eq_mk simp_rw [this] apply tendsto_lintegral_of_dominated_convergence bound (fun n => (hF_meas n).measurable_mk) _ h_fin · have : ∀ n, ∀ᵐ a ∂μ, (hF_meas n).mk (F n) a = F n a := fun n => (hF_meas n).ae_eq_mk.symm have : ∀ᵐ a ∂μ, ∀ n, (hF_meas n).mk (F n) a = F n a := ae_all_iff.mpr this filter_upwards [this, h_lim] with a H H' simp_rw [H] exact H' · intro n filter_upwards [h_bound n, (hF_meas n).ae_eq_mk] with a H H' rwa [H'] at H #align measure_theory.tendsto_lintegral_of_dominated_convergence' MeasureTheory.tendsto_lintegral_of_dominated_convergence' /-- Dominated convergence theorem for filters with a countable basis -/ theorem tendsto_lintegral_filter_of_dominated_convergence {ι} {l : Filter ι} [l.IsCountablyGenerated] {F : ι → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ᶠ n in l, Measurable (F n)) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, F n a ≤ bound a) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) l (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) l (𝓝 <| ∫⁻ a, f a ∂μ) := by rw [tendsto_iff_seq_tendsto] intro x xl have hxl := by rw [tendsto_atTop'] at xl exact xl have h := inter_mem hF_meas h_bound replace h := hxl _ h rcases h with ⟨k, h⟩ rw [← tendsto_add_atTop_iff_nat k] refine tendsto_lintegral_of_dominated_convergence ?_ ?_ ?_ ?_ ?_ · exact bound · intro refine (h _ ?_).1 exact Nat.le_add_left _ _ · intro refine (h _ ?_).2 exact Nat.le_add_left _ _ · assumption · refine h_lim.mono fun a h_lim => ?_ apply @Tendsto.comp _ _ _ (fun n => x (n + k)) fun n => F n a · assumption rw [tendsto_add_atTop_iff_nat] assumption #align measure_theory.tendsto_lintegral_filter_of_dominated_convergence MeasureTheory.tendsto_lintegral_filter_of_dominated_convergence theorem lintegral_tendsto_of_tendsto_of_antitone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ x ∂μ, Antitone fun n ↦ f n x) (h0 : ∫⁻ a, f 0 a ∂μ ≠ ∞) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) : Tendsto (fun n ↦ ∫⁻ x, f n x ∂μ) atTop (𝓝 (∫⁻ x, F x ∂μ)) := by have : Antitone fun n ↦ ∫⁻ x, f n x ∂μ := fun i j hij ↦ lintegral_mono_ae (h_anti.mono fun x hx ↦ hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨅ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iInf this rw [← lintegral_iInf' hf h_anti h0] refine lintegral_congr_ae ?_ filter_upwards [h_anti, h_tendsto] with _ hx_anti hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iInf hx_anti) section open Encodable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type -/ theorem lintegral_iSup_directed_of_measurable [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, Measurable (f b)) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp [iSup_of_empty] inhabit β have : ∀ a, ⨆ b, f b a = ⨆ n, f (h_directed.sequence f n) a := by intro a refine le_antisymm (iSup_le fun b => ?_) (iSup_le fun n => le_iSup (fun n => f n a) _) exact le_iSup_of_le (encode b + 1) (h_directed.le_sequence b a) calc ∫⁻ a, ⨆ b, f b a ∂μ = ∫⁻ a, ⨆ n, f (h_directed.sequence f n) a ∂μ := by simp only [this] _ = ⨆ n, ∫⁻ a, f (h_directed.sequence f n) a ∂μ := (lintegral_iSup (fun n => hf _) h_directed.sequence_mono) _ = ⨆ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (iSup_le fun n => ?_) (iSup_le fun b => ?_) · exact le_iSup (fun b => ∫⁻ a, f b a ∂μ) _ · exact le_iSup_of_le (encode b + 1) (lintegral_mono <| h_directed.le_sequence b) #align measure_theory.lintegral_supr_directed_of_measurable MeasureTheory.lintegral_iSup_directed_of_measurable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type. -/ theorem lintegral_iSup_directed [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, AEMeasurable (f b) μ) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by simp_rw [← iSup_apply] let p : α → (β → ENNReal) → Prop := fun x f' => Directed LE.le f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := by filter_upwards [] with x i j obtain ⟨z, hz₁, hz₂⟩ := h_directed i j exact ⟨z, hz₁ x, hz₂ x⟩ have h_ae_seq_directed : Directed LE.le (aeSeq hf p) := by intro b₁ b₂ obtain ⟨z, hz₁, hz₂⟩ := h_directed b₁ b₂ refine ⟨z, ?_, ?_⟩ <;> · intro x by_cases hx : x ∈ aeSeqSet hf p · repeat rw [aeSeq.aeSeq_eq_fun_of_mem_aeSeqSet hf hx] apply_rules [hz₁, hz₂] · simp only [aeSeq, hx, if_false] exact le_rfl convert lintegral_iSup_directed_of_measurable (aeSeq.measurable hf p) h_ae_seq_directed using 1 · simp_rw [← iSup_apply] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] · congr 1 ext1 b rw [lintegral_congr_ae] apply EventuallyEq.symm exact aeSeq.aeSeq_n_eq_fun_n_ae hf hp _ #align measure_theory.lintegral_supr_directed MeasureTheory.lintegral_iSup_directed end theorem lintegral_tsum [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ i, AEMeasurable (f i) μ) : ∫⁻ a, ∑' i, f i a ∂μ = ∑' i, ∫⁻ a, f i a ∂μ := by simp only [ENNReal.tsum_eq_iSup_sum] rw [lintegral_iSup_directed] · simp [lintegral_finset_sum' _ fun i _ => hf i] · intro b exact Finset.aemeasurable_sum _ fun i _ => hf i · intro s t use s ∪ t constructor · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_left · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_right #align measure_theory.lintegral_tsum MeasureTheory.lintegral_tsum open Measure theorem lintegral_iUnion₀ [Countable β] {s : β → Set α} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := by simp only [Measure.restrict_iUnion_ae hd hm, lintegral_sum_measure] #align measure_theory.lintegral_Union₀ MeasureTheory.lintegral_iUnion₀ theorem lintegral_iUnion [Countable β] {s : β → Set α} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := lintegral_iUnion₀ (fun i => (hm i).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_Union MeasureTheory.lintegral_iUnion theorem lintegral_biUnion₀ {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, NullMeasurableSet (s i) μ) (hd : t.Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, lintegral_iUnion₀ (SetCoe.forall'.1 hm) (hd.subtype _ _)] #align measure_theory.lintegral_bUnion₀ MeasureTheory.lintegral_biUnion₀ theorem lintegral_biUnion {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, MeasurableSet (s i)) (hd : t.PairwiseDisjoint s) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := lintegral_biUnion₀ ht (fun i hi => (hm i hi).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_bUnion MeasureTheory.lintegral_biUnion theorem lintegral_biUnion_finset₀ {s : Finset β} {t : β → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on t)) (hm : ∀ b ∈ s, NullMeasurableSet (t b) μ) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := by simp only [← Finset.mem_coe, lintegral_biUnion₀ s.countable_toSet hm hd, ← Finset.tsum_subtype'] #align measure_theory.lintegral_bUnion_finset₀ MeasureTheory.lintegral_biUnion_finset₀ theorem lintegral_biUnion_finset {s : Finset β} {t : β → Set α} (hd : Set.PairwiseDisjoint (↑s) t) (hm : ∀ b ∈ s, MeasurableSet (t b)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := lintegral_biUnion_finset₀ hd.aedisjoint (fun b hb => (hm b hb).nullMeasurableSet) f #align measure_theory.lintegral_bUnion_finset MeasureTheory.lintegral_biUnion_finset theorem lintegral_iUnion_le [Countable β] (s : β → Set α) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ ≤ ∑' i, ∫⁻ a in s i, f a ∂μ := by rw [← lintegral_sum_measure] exact lintegral_mono' restrict_iUnion_le le_rfl #align measure_theory.lintegral_Union_le MeasureTheory.lintegral_iUnion_le theorem lintegral_union {f : α → ℝ≥0∞} {A B : Set α} (hB : MeasurableSet B) (hAB : Disjoint A B) : ∫⁻ a in A ∪ B, f a ∂μ = ∫⁻ a in A, f a ∂μ + ∫⁻ a in B, f a ∂μ := by rw [restrict_union hAB hB, lintegral_add_measure] #align measure_theory.lintegral_union MeasureTheory.lintegral_union theorem lintegral_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∫⁻ a in s ∪ t, f a ∂μ ≤ ∫⁻ a in s, f a ∂μ + ∫⁻ a in t, f a ∂μ := by rw [← lintegral_add_measure] exact lintegral_mono' (restrict_union_le _ _) le_rfl theorem lintegral_inter_add_diff {B : Set α} (f : α → ℝ≥0∞) (A : Set α) (hB : MeasurableSet B) : ∫⁻ x in A ∩ B, f x ∂μ + ∫⁻ x in A \ B, f x ∂μ = ∫⁻ x in A, f x ∂μ := by rw [← lintegral_add_measure, restrict_inter_add_diff _ hB] #align measure_theory.lintegral_inter_add_diff MeasureTheory.lintegral_inter_add_diff theorem lintegral_add_compl (f : α → ℝ≥0∞) {A : Set α} (hA : MeasurableSet A) : ∫⁻ x in A, f x ∂μ + ∫⁻ x in Aᶜ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [← lintegral_add_measure, Measure.restrict_add_restrict_compl hA] #align measure_theory.lintegral_add_compl MeasureTheory.lintegral_add_compl theorem lintegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ x, max (f x) (g x) ∂μ = ∫⁻ x in { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in { x | g x < f x }, f x ∂μ := by have hm : MeasurableSet { x | f x ≤ g x } := measurableSet_le hf hg rw [← lintegral_add_compl (fun x => max (f x) (g x)) hm] simp only [← compl_setOf, ← not_le] refine congr_arg₂ (· + ·) (set_lintegral_congr_fun hm ?_) (set_lintegral_congr_fun hm.compl ?_) exacts [ae_of_all _ fun x => max_eq_right (a := f x) (b := g x), ae_of_all _ fun x (hx : ¬ f x ≤ g x) => max_eq_left (not_le.1 hx).le] #align measure_theory.lintegral_max MeasureTheory.lintegral_max theorem set_lintegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (s : Set α) : ∫⁻ x in s, max (f x) (g x) ∂μ = ∫⁻ x in s ∩ { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in s ∩ { x | g x < f x }, f x ∂μ := by rw [lintegral_max hf hg, restrict_restrict, restrict_restrict, inter_comm s, inter_comm s] exacts [measurableSet_lt hg hf, measurableSet_le hf hg] #align measure_theory.set_lintegral_max MeasureTheory.set_lintegral_max theorem lintegral_map {mβ : MeasurableSpace β} {f : β → ℝ≥0∞} {g : α → β} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := by erw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral (hf.comp hg)] congr with n : 1 convert SimpleFunc.lintegral_map _ hg ext1 x; simp only [eapprox_comp hf hg, coe_comp] #align measure_theory.lintegral_map MeasureTheory.lintegral_map theorem lintegral_map' {mβ : MeasurableSpace β} {f : β → ℝ≥0∞} {g : α → β} (hf : AEMeasurable f (Measure.map g μ)) (hg : AEMeasurable g μ) : ∫⁻ a, f a ∂Measure.map g μ = ∫⁻ a, f (g a) ∂μ := calc ∫⁻ a, f a ∂Measure.map g μ = ∫⁻ a, hf.mk f a ∂Measure.map g μ := lintegral_congr_ae hf.ae_eq_mk _ = ∫⁻ a, hf.mk f a ∂Measure.map (hg.mk g) μ := by congr 1 exact Measure.map_congr hg.ae_eq_mk _ = ∫⁻ a, hf.mk f (hg.mk g a) ∂μ := lintegral_map hf.measurable_mk hg.measurable_mk _ = ∫⁻ a, hf.mk f (g a) ∂μ := lintegral_congr_ae <| hg.ae_eq_mk.symm.fun_comp _ _ = ∫⁻ a, f (g a) ∂μ := lintegral_congr_ae (ae_eq_comp hg hf.ae_eq_mk.symm) #align measure_theory.lintegral_map' MeasureTheory.lintegral_map' theorem lintegral_map_le {mβ : MeasurableSpace β} (f : β → ℝ≥0∞) {g : α → β} (hg : Measurable g) : ∫⁻ a, f a ∂Measure.map g μ ≤ ∫⁻ a, f (g a) ∂μ := by rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral] refine iSup₂_le fun i hi => iSup_le fun h'i => ?_ refine le_iSup₂_of_le (i ∘ g) (hi.comp hg) ?_ exact le_iSup_of_le (fun x => h'i (g x)) (le_of_eq (lintegral_map hi hg)) #align measure_theory.lintegral_map_le MeasureTheory.lintegral_map_le theorem lintegral_comp [MeasurableSpace β] {f : β → ℝ≥0∞} {g : α → β} (hf : Measurable f) (hg : Measurable g) : lintegral μ (f ∘ g) = ∫⁻ a, f a ∂map g μ := (lintegral_map hf hg).symm #align measure_theory.lintegral_comp MeasureTheory.lintegral_comp theorem set_lintegral_map [MeasurableSpace β] {f : β → ℝ≥0∞} {g : α → β} {s : Set β} (hs : MeasurableSet s) (hf : Measurable f) (hg : Measurable g) : ∫⁻ y in s, f y ∂map g μ = ∫⁻ x in g ⁻¹' s, f (g x) ∂μ := by rw [restrict_map hg hs, lintegral_map hf hg] #align measure_theory.set_lintegral_map MeasureTheory.set_lintegral_map theorem lintegral_indicator_const_comp {mβ : MeasurableSpace β} {f : α → β} {s : Set β} (hf : Measurable f) (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) (f a) ∂μ = c * μ (f ⁻¹' s) := by erw [lintegral_comp (measurable_const.indicator hs) hf, lintegral_indicator_const hs, Measure.map_apply hf hs] #align measure_theory.lintegral_indicator_const_comp MeasureTheory.lintegral_indicator_const_comp /-- If `g : α → β` is a measurable embedding and `f : β → ℝ≥0∞` is any function (not necessarily measurable), then `∫⁻ a, f a ∂(map g μ) = ∫⁻ a, f (g a) ∂μ`. Compare with `lintegral_map` which applies to any measurable `g : α → β` but requires that `f` is measurable as well. -/
Mathlib/MeasureTheory/Integral/Lebesgue.lean
1,437
1,447
theorem _root_.MeasurableEmbedding.lintegral_map [MeasurableSpace β] {g : α → β} (hg : MeasurableEmbedding g) (f : β → ℝ≥0∞) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := by
rw [lintegral, lintegral] refine le_antisymm (iSup₂_le fun f₀ hf₀ => ?_) (iSup₂_le fun f₀ hf₀ => ?_) · rw [SimpleFunc.lintegral_map _ hg.measurable] have : (f₀.comp g hg.measurable : α → ℝ≥0∞) ≤ f ∘ g := fun x => hf₀ (g x) exact le_iSup_of_le (comp f₀ g hg.measurable) (by exact le_iSup (α := ℝ≥0∞) _ this) · rw [← f₀.extend_comp_eq hg (const _ 0), ← SimpleFunc.lintegral_map, ← SimpleFunc.lintegral_eq_lintegral, ← lintegral] refine lintegral_mono_ae (hg.ae_map_iff.2 <| eventually_of_forall fun x => ?_) exact (extend_apply _ _ _ _).trans_le (hf₀ _)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Order.Interval.Set.Basic import Mathlib.Data.Set.NAry import Mathlib.Order.Directed #align_import order.bounds.basic from "leanprover-community/mathlib"@"b1abe23ae96fef89ad30d9f4362c307f72a55010" /-! # Upper / lower bounds In this file we define: * `upperBounds`, `lowerBounds` : the set of upper bounds (resp., lower bounds) of a set; * `BddAbove s`, `BddBelow s` : the set `s` is bounded above (resp., below), i.e., the set of upper (resp., lower) bounds of `s` is nonempty; * `IsLeast s a`, `IsGreatest s a` : `a` is a least (resp., greatest) element of `s`; for a partial order, it is unique if exists; * `IsLUB s a`, `IsGLB s a` : `a` is a least upper bound (resp., a greatest lower bound) of `s`; for a partial order, it is unique if exists. We also prove various lemmas about monotonicity, behaviour under `∪`, `∩`, `insert`, and provide formulas for `∅`, `univ`, and intervals. -/ open Function Set open OrderDual (toDual ofDual) universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} section variable [Preorder α] [Preorder β] {s t : Set α} {a b : α} /-! ### Definitions -/ /-- The set of upper bounds of a set. -/ def upperBounds (s : Set α) : Set α := { x | ∀ ⦃a⦄, a ∈ s → a ≤ x } #align upper_bounds upperBounds /-- The set of lower bounds of a set. -/ def lowerBounds (s : Set α) : Set α := { x | ∀ ⦃a⦄, a ∈ s → x ≤ a } #align lower_bounds lowerBounds /-- A set is bounded above if there exists an upper bound. -/ def BddAbove (s : Set α) := (upperBounds s).Nonempty #align bdd_above BddAbove /-- A set is bounded below if there exists a lower bound. -/ def BddBelow (s : Set α) := (lowerBounds s).Nonempty #align bdd_below BddBelow /-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/ def IsLeast (s : Set α) (a : α) : Prop := a ∈ s ∧ a ∈ lowerBounds s #align is_least IsLeast /-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists. -/ def IsGreatest (s : Set α) (a : α) : Prop := a ∈ s ∧ a ∈ upperBounds s #align is_greatest IsGreatest /-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/ def IsLUB (s : Set α) : α → Prop := IsLeast (upperBounds s) #align is_lub IsLUB /-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/ def IsGLB (s : Set α) : α → Prop := IsGreatest (lowerBounds s) #align is_glb IsGLB theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a := Iff.rfl #align mem_upper_bounds mem_upperBounds theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x := Iff.rfl #align mem_lower_bounds mem_lowerBounds lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl #align mem_upper_bounds_iff_subset_Iic mem_upperBounds_iff_subset_Iic lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl #align mem_lower_bounds_iff_subset_Ici mem_lowerBounds_iff_subset_Ici theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x := Iff.rfl #align bdd_above_def bddAbove_def theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y := Iff.rfl #align bdd_below_def bddBelow_def theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le #align bot_mem_lower_bounds bot_mem_lowerBounds theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top #align top_mem_upper_bounds top_mem_upperBounds @[simp] theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s := and_iff_left <| bot_mem_lowerBounds _ #align is_least_bot_iff isLeast_bot_iff @[simp] theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s := and_iff_left <| top_mem_upperBounds _ #align is_greatest_top_iff isGreatest_top_iff /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x` is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/ theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by simp [BddAbove, upperBounds, Set.Nonempty] #align not_bdd_above_iff' not_bddAbove_iff' /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x` is not less than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/ theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y := @not_bddAbove_iff' αᵒᵈ _ _ #align not_bdd_below_iff' not_bddBelow_iff' /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater than `x`. A version for preorders is called `not_bddAbove_iff'`. -/ theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by simp only [not_bddAbove_iff', not_le] #align not_bdd_above_iff not_bddAbove_iff /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less than `x`. A version for preorders is called `not_bddBelow_iff'`. -/ theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x := @not_bddAbove_iff αᵒᵈ _ _ #align not_bdd_below_iff not_bddBelow_iff @[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl @[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} : BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} : BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) := h #align bdd_above.dual BddAbove.dual theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) := h #align bdd_below.dual BddBelow.dual theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) := h #align is_least.dual IsLeast.dual theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) := h #align is_greatest.dual IsGreatest.dual theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) := h #align is_lub.dual IsLUB.dual theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) := h #align is_glb.dual IsGLB.dual /-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/ abbrev IsLeast.orderBot (h : IsLeast s a) : OrderBot s where bot := ⟨a, h.1⟩ bot_le := Subtype.forall.2 h.2 #align is_least.order_bot IsLeast.orderBot /-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/ abbrev IsGreatest.orderTop (h : IsGreatest s a) : OrderTop s where top := ⟨a, h.1⟩ le_top := Subtype.forall.2 h.2 #align is_greatest.order_top IsGreatest.orderTop /-! ### Monotonicity -/ theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s := fun _ hb _ h => hb <| hst h #align upper_bounds_mono_set upperBounds_mono_set theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s := fun _ hb _ h => hb <| hst h #align lower_bounds_mono_set lowerBounds_mono_set theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s := fun ha _ h => le_trans (ha h) hab #align upper_bounds_mono_mem upperBounds_mono_mem theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s := fun hb _ h => le_trans hab (hb h) #align lower_bounds_mono_mem lowerBounds_mono_mem theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds t → b ∈ upperBounds s := fun ha => upperBounds_mono_set hst <| upperBounds_mono_mem hab ha #align upper_bounds_mono upperBounds_mono theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb => lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb #align lower_bounds_mono lowerBounds_mono /-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/ theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s := Nonempty.mono <| upperBounds_mono_set h #align bdd_above.mono BddAbove.mono /-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/ theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s := Nonempty.mono <| lowerBounds_mono_set h #align bdd_below.mono BddBelow.mono /-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsLUB t a := ⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩ #align is_lub.of_subset_of_superset IsLUB.of_subset_of_superset /-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsGLB t a := hs.dual.of_subset_of_superset hp hst htp #align is_glb.of_subset_of_superset IsGLB.of_subset_of_superset theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a := hb.2 (hst ha.1) #align is_least.mono IsLeast.mono theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b := hb.2 (hst ha.1) #align is_greatest.mono IsGreatest.mono theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b := IsLeast.mono hb ha <| upperBounds_mono_set hst #align is_lub.mono IsLUB.mono theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a := IsGreatest.mono hb ha <| lowerBounds_mono_set hst #align is_glb.mono IsGLB.mono theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) := fun _ hx _ hy => hy hx #align subset_lower_bounds_upper_bounds subset_lowerBounds_upperBounds theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) := fun _ hx _ hy => hy hx #align subset_upper_bounds_lower_bounds subset_upperBounds_lowerBounds theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) := hs.mono (subset_upperBounds_lowerBounds s) #align set.nonempty.bdd_above_lower_bounds Set.Nonempty.bddAbove_lowerBounds theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) := hs.mono (subset_lowerBounds_upperBounds s) #align set.nonempty.bdd_below_upper_bounds Set.Nonempty.bddBelow_upperBounds /-! ### Conversions -/ theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a := ⟨h.2, fun _ hb => hb h.1⟩ #align is_least.is_glb IsLeast.isGLB theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a := ⟨h.2, fun _ hb => hb h.1⟩ #align is_greatest.is_lub IsGreatest.isLUB theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a := Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩ #align is_lub.upper_bounds_eq IsLUB.upperBounds_eq theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a := h.dual.upperBounds_eq #align is_glb.lower_bounds_eq IsGLB.lowerBounds_eq theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a := h.isGLB.lowerBounds_eq #align is_least.lower_bounds_eq IsLeast.lowerBounds_eq theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a := h.isLUB.upperBounds_eq #align is_greatest.upper_bounds_eq IsGreatest.upperBounds_eq -- Porting note (#10756): new lemma theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b := ⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩ -- Porting note (#10756): new lemma theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x := h.dual.lt_iff theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by rw [h.upperBounds_eq] rfl #align is_lub_le_iff isLUB_le_iff theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by rw [h.lowerBounds_eq] rfl #align le_is_glb_iff le_isGLB_iff theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s := ⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩ #align is_lub_iff_le_iff isLUB_iff_le_iff theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s := @isLUB_iff_le_iff αᵒᵈ _ _ _ #align is_glb_iff_le_iff isGLB_iff_le_iff /-- If `s` has a least upper bound, then it is bounded above. -/ theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s := ⟨a, h.1⟩ #align is_lub.bdd_above IsLUB.bddAbove /-- If `s` has a greatest lower bound, then it is bounded below. -/ theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s := ⟨a, h.1⟩ #align is_glb.bdd_below IsGLB.bddBelow /-- If `s` has a greatest element, then it is bounded above. -/ theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s := ⟨a, h.2⟩ #align is_greatest.bdd_above IsGreatest.bddAbove /-- If `s` has a least element, then it is bounded below. -/ theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s := ⟨a, h.2⟩ #align is_least.bdd_below IsLeast.bddBelow theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty := ⟨a, h.1⟩ #align is_least.nonempty IsLeast.nonempty theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty := ⟨a, h.1⟩ #align is_greatest.nonempty IsGreatest.nonempty /-! ### Union and intersection -/ @[simp] theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t := Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩) fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht #align upper_bounds_union upperBounds_union @[simp] theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t := @upperBounds_union αᵒᵈ _ s t #align lower_bounds_union lowerBounds_union theorem union_upperBounds_subset_upperBounds_inter : upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) := union_subset (upperBounds_mono_set inter_subset_left) (upperBounds_mono_set inter_subset_right) #align union_upper_bounds_subset_upper_bounds_inter union_upperBounds_subset_upperBounds_inter theorem union_lowerBounds_subset_lowerBounds_inter : lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) := @union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t #align union_lower_bounds_subset_lower_bounds_inter union_lowerBounds_subset_lowerBounds_inter theorem isLeast_union_iff {a : α} {s t : Set α} : IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc] #align is_least_union_iff isLeast_union_iff theorem isGreatest_union_iff : IsGreatest (s ∪ t) a ↔ IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a := @isLeast_union_iff αᵒᵈ _ a s t #align is_greatest_union_iff isGreatest_union_iff /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) := h.mono inter_subset_left #align bdd_above.inter_of_left BddAbove.inter_of_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) := h.mono inter_subset_right #align bdd_above.inter_of_right BddAbove.inter_of_right /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) := h.mono inter_subset_left #align bdd_below.inter_of_left BddBelow.inter_of_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) := h.mono inter_subset_right #align bdd_below.inter_of_right BddBelow.inter_of_right /-- In a directed order, the union of bounded above sets is bounded above. -/ theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove s → BddAbove t → BddAbove (s ∪ t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b rw [BddAbove, upperBounds_union] exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩ #align bdd_above.union BddAbove.union /-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/ theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t := ⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h => h.1.union h.2⟩ #align bdd_above_union bddAbove_union /-- In a codirected order, the union of bounded below sets is bounded below. -/ theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow s → BddBelow t → BddBelow (s ∪ t) := @BddAbove.union αᵒᵈ _ _ _ _ #align bdd_below.union BddBelow.union /-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/ theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t := @bddAbove_union αᵒᵈ _ _ _ _ #align bdd_below_union bddBelow_union /-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`, then `a ⊔ b` is the least upper bound of `s ∪ t`. -/ theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) : IsLUB (s ∪ t) (a ⊔ b) := ⟨fun _ h => h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h, fun _ hc => sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩ #align is_lub.union IsLUB.union /-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`, then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/ theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁) (ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) := hs.dual.union ht #align is_glb.union IsGLB.union /-- If `a` is the least element of `s` and `b` is the least element of `t`, then `min a b` is the least element of `s ∪ t`. -/ theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a) (hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩ #align is_least.union IsLeast.union /-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`, then `max a b` is the greatest element of `s ∪ t`. -/ theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a) (hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩ #align is_greatest.union IsGreatest.union theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) : IsLUB (s ∩ Ici b) a := ⟨fun _ hx => ha.1 hx.1, fun c hc => have hbc : b ≤ c := hc ⟨hb, le_rfl⟩ ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩ #align is_lub.inter_Ici_of_mem IsLUB.inter_Ici_of_mem theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) : IsGLB (s ∩ Iic b) a := ha.dual.inter_Ici_of_mem hb #align is_glb.inter_Iic_of_mem IsGLB.inter_Iic_of_mem theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) : BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by rw [bddAbove_def, exists_ge_and_iff_exists] exact Monotone.ball fun x _ => monotone_le #align bdd_above_iff_exists_ge bddAbove_iff_exists_ge theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) : BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := bddAbove_iff_exists_ge (toDual x₀) #align bdd_below_iff_exists_le bddBelow_iff_exists_le theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) : ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := (bddAbove_iff_exists_ge x₀).mp hs #align bdd_above.exists_ge BddAbove.exists_ge theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) : ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := (bddBelow_iff_exists_le x₀).mp hs #align bdd_below.exists_le BddBelow.exists_le /-! ### Specific sets #### Unbounded intervals -/ theorem isLeast_Ici : IsLeast (Ici a) a := ⟨left_mem_Ici, fun _ => id⟩ #align is_least_Ici isLeast_Ici theorem isGreatest_Iic : IsGreatest (Iic a) a := ⟨right_mem_Iic, fun _ => id⟩ #align is_greatest_Iic isGreatest_Iic theorem isLUB_Iic : IsLUB (Iic a) a := isGreatest_Iic.isLUB #align is_lub_Iic isLUB_Iic theorem isGLB_Ici : IsGLB (Ici a) a := isLeast_Ici.isGLB #align is_glb_Ici isGLB_Ici theorem upperBounds_Iic : upperBounds (Iic a) = Ici a := isLUB_Iic.upperBounds_eq #align upper_bounds_Iic upperBounds_Iic theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a := isGLB_Ici.lowerBounds_eq #align lower_bounds_Ici lowerBounds_Ici theorem bddAbove_Iic : BddAbove (Iic a) := isLUB_Iic.bddAbove #align bdd_above_Iic bddAbove_Iic theorem bddBelow_Ici : BddBelow (Ici a) := isGLB_Ici.bddBelow #align bdd_below_Ici bddBelow_Ici theorem bddAbove_Iio : BddAbove (Iio a) := ⟨a, fun _ hx => le_of_lt hx⟩ #align bdd_above_Iio bddAbove_Iio theorem bddBelow_Ioi : BddBelow (Ioi a) := ⟨a, fun _ hx => le_of_lt hx⟩ #align bdd_below_Ioi bddBelow_Ioi theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a := (isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk #align lub_Iio_le lub_Iio_le theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b := @lub_Iio_le αᵒᵈ _ _ a hb #align le_glb_Ioi le_glb_Ioi theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) : j = i ∨ Iio i = Iic j := by cases' eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i · exact Or.inl hj_eq_i · right exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩ #align lub_Iio_eq_self_or_Iio_eq_Iic lub_Iio_eq_self_or_Iio_eq_Iic theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) : j = i ∨ Ioi i = Ici j := @lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj #align glb_Ioi_eq_self_or_Ioi_eq_Ici glb_Ioi_eq_self_or_Ioi_eq_Ici section variable [LinearOrder γ] theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by by_cases h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i · obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩ · refine ⟨i, fun j hj => le_of_lt hj, ?_⟩ rw [mem_lowerBounds] by_contra h refine h_exists_lt ?_ push_neg at h exact h #align exists_lub_Iio exists_lub_Iio theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j := @exists_lub_Iio γᵒᵈ _ i #align exists_glb_Ioi exists_glb_Ioi variable [DenselyOrdered γ] theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a := ⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_ge_of_dense hy⟩ #align is_lub_Iio isLUB_Iio theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a := @isLUB_Iio γᵒᵈ _ _ a #align is_glb_Ioi isGLB_Ioi theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a := isLUB_Iio.upperBounds_eq #align upper_bounds_Iio upperBounds_Iio theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a := isGLB_Ioi.lowerBounds_eq #align lower_bounds_Ioi lowerBounds_Ioi end /-! #### Singleton -/ theorem isGreatest_singleton : IsGreatest {a} a := ⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩ #align is_greatest_singleton isGreatest_singleton theorem isLeast_singleton : IsLeast {a} a := @isGreatest_singleton αᵒᵈ _ a #align is_least_singleton isLeast_singleton theorem isLUB_singleton : IsLUB {a} a := isGreatest_singleton.isLUB #align is_lub_singleton isLUB_singleton theorem isGLB_singleton : IsGLB {a} a := isLeast_singleton.isGLB #align is_glb_singleton isGLB_singleton @[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove #align bdd_above_singleton bddAbove_singleton @[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow #align bdd_below_singleton bddBelow_singleton @[simp] theorem upperBounds_singleton : upperBounds {a} = Ici a := isLUB_singleton.upperBounds_eq #align upper_bounds_singleton upperBounds_singleton @[simp] theorem lowerBounds_singleton : lowerBounds {a} = Iic a := isGLB_singleton.lowerBounds_eq #align lower_bounds_singleton lowerBounds_singleton /-! #### Bounded intervals -/ theorem bddAbove_Icc : BddAbove (Icc a b) := ⟨b, fun _ => And.right⟩ #align bdd_above_Icc bddAbove_Icc theorem bddBelow_Icc : BddBelow (Icc a b) := ⟨a, fun _ => And.left⟩ #align bdd_below_Icc bddBelow_Icc theorem bddAbove_Ico : BddAbove (Ico a b) := bddAbove_Icc.mono Ico_subset_Icc_self #align bdd_above_Ico bddAbove_Ico theorem bddBelow_Ico : BddBelow (Ico a b) := bddBelow_Icc.mono Ico_subset_Icc_self #align bdd_below_Ico bddBelow_Ico theorem bddAbove_Ioc : BddAbove (Ioc a b) := bddAbove_Icc.mono Ioc_subset_Icc_self #align bdd_above_Ioc bddAbove_Ioc theorem bddBelow_Ioc : BddBelow (Ioc a b) := bddBelow_Icc.mono Ioc_subset_Icc_self #align bdd_below_Ioc bddBelow_Ioc theorem bddAbove_Ioo : BddAbove (Ioo a b) := bddAbove_Icc.mono Ioo_subset_Icc_self #align bdd_above_Ioo bddAbove_Ioo theorem bddBelow_Ioo : BddBelow (Ioo a b) := bddBelow_Icc.mono Ioo_subset_Icc_self #align bdd_below_Ioo bddBelow_Ioo theorem isGreatest_Icc (h : a ≤ b) : IsGreatest (Icc a b) b := ⟨right_mem_Icc.2 h, fun _ => And.right⟩ #align is_greatest_Icc isGreatest_Icc theorem isLUB_Icc (h : a ≤ b) : IsLUB (Icc a b) b := (isGreatest_Icc h).isLUB #align is_lub_Icc isLUB_Icc theorem upperBounds_Icc (h : a ≤ b) : upperBounds (Icc a b) = Ici b := (isLUB_Icc h).upperBounds_eq #align upper_bounds_Icc upperBounds_Icc theorem isLeast_Icc (h : a ≤ b) : IsLeast (Icc a b) a := ⟨left_mem_Icc.2 h, fun _ => And.left⟩ #align is_least_Icc isLeast_Icc theorem isGLB_Icc (h : a ≤ b) : IsGLB (Icc a b) a := (isLeast_Icc h).isGLB #align is_glb_Icc isGLB_Icc theorem lowerBounds_Icc (h : a ≤ b) : lowerBounds (Icc a b) = Iic a := (isGLB_Icc h).lowerBounds_eq #align lower_bounds_Icc lowerBounds_Icc theorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b := ⟨right_mem_Ioc.2 h, fun _ => And.right⟩ #align is_greatest_Ioc isGreatest_Ioc theorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b := (isGreatest_Ioc h).isLUB #align is_lub_Ioc isLUB_Ioc theorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b := (isLUB_Ioc h).upperBounds_eq #align upper_bounds_Ioc upperBounds_Ioc theorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a := ⟨left_mem_Ico.2 h, fun _ => And.left⟩ #align is_least_Ico isLeast_Ico theorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a := (isLeast_Ico h).isGLB #align is_glb_Ico isGLB_Ico theorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a := (isGLB_Ico h).lowerBounds_eq #align lower_bounds_Ico lowerBounds_Ico section variable [SemilatticeSup γ] [DenselyOrdered γ] theorem isGLB_Ioo {a b : γ} (h : a < b) : IsGLB (Ioo a b) a := ⟨fun x hx => hx.1.le, fun x hx => by cases' eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ h₂ · exact h₁.symm ▸ le_sup_left obtain ⟨y, lty, ylt⟩ := exists_between h₂ apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim obtain ⟨u, au, ub⟩ := exists_between h apply (hx ⟨au, ub⟩).trans ub.le⟩ #align is_glb_Ioo isGLB_Ioo theorem lowerBounds_Ioo {a b : γ} (hab : a < b) : lowerBounds (Ioo a b) = Iic a := (isGLB_Ioo hab).lowerBounds_eq #align lower_bounds_Ioo lowerBounds_Ioo theorem isGLB_Ioc {a b : γ} (hab : a < b) : IsGLB (Ioc a b) a := (isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self #align is_glb_Ioc isGLB_Ioc theorem lowerBounds_Ioc {a b : γ} (hab : a < b) : lowerBounds (Ioc a b) = Iic a := (isGLB_Ioc hab).lowerBounds_eq #align lower_bound_Ioc lowerBounds_Ioc end section variable [SemilatticeInf γ] [DenselyOrdered γ] theorem isLUB_Ioo {a b : γ} (hab : a < b) : IsLUB (Ioo a b) b := by simpa only [dual_Ioo] using isGLB_Ioo hab.dual #align is_lub_Ioo isLUB_Ioo theorem upperBounds_Ioo {a b : γ} (hab : a < b) : upperBounds (Ioo a b) = Ici b := (isLUB_Ioo hab).upperBounds_eq #align upper_bounds_Ioo upperBounds_Ioo theorem isLUB_Ico {a b : γ} (hab : a < b) : IsLUB (Ico a b) b := by simpa only [dual_Ioc] using isGLB_Ioc hab.dual #align is_lub_Ico isLUB_Ico theorem upperBounds_Ico {a b : γ} (hab : a < b) : upperBounds (Ico a b) = Ici b := (isLUB_Ico hab).upperBounds_eq #align upper_bounds_Ico upperBounds_Ico end theorem bddBelow_iff_subset_Ici : BddBelow s ↔ ∃ a, s ⊆ Ici a := Iff.rfl #align bdd_below_iff_subset_Ici bddBelow_iff_subset_Ici theorem bddAbove_iff_subset_Iic : BddAbove s ↔ ∃ a, s ⊆ Iic a := Iff.rfl #align bdd_above_iff_subset_Iic bddAbove_iff_subset_Iic theorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ Icc a b := by simp [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici, bddAbove_iff_subset_Iic, exists_and_left, exists_and_right] #align bdd_below_bdd_above_iff_subset_Icc bddBelow_bddAbove_iff_subset_Icc /-! #### Univ -/ @[simp] theorem isGreatest_univ_iff : IsGreatest univ a ↔ IsTop a := by simp [IsGreatest, mem_upperBounds, IsTop] #align is_greatest_univ_iff isGreatest_univ_iff theorem isGreatest_univ [OrderTop α] : IsGreatest (univ : Set α) ⊤ := isGreatest_univ_iff.2 isTop_top #align is_greatest_univ isGreatest_univ @[simp] theorem OrderTop.upperBounds_univ [PartialOrder γ] [OrderTop γ] : upperBounds (univ : Set γ) = {⊤} := by rw [isGreatest_univ.upperBounds_eq, Ici_top] #align order_top.upper_bounds_univ OrderTop.upperBounds_univ theorem isLUB_univ [OrderTop α] : IsLUB (univ : Set α) ⊤ := isGreatest_univ.isLUB #align is_lub_univ isLUB_univ @[simp] theorem OrderBot.lowerBounds_univ [PartialOrder γ] [OrderBot γ] : lowerBounds (univ : Set γ) = {⊥} := @OrderTop.upperBounds_univ γᵒᵈ _ _ #align order_bot.lower_bounds_univ OrderBot.lowerBounds_univ @[simp] theorem isLeast_univ_iff : IsLeast univ a ↔ IsBot a := @isGreatest_univ_iff αᵒᵈ _ _ #align is_least_univ_iff isLeast_univ_iff theorem isLeast_univ [OrderBot α] : IsLeast (univ : Set α) ⊥ := @isGreatest_univ αᵒᵈ _ _ #align is_least_univ isLeast_univ theorem isGLB_univ [OrderBot α] : IsGLB (univ : Set α) ⊥ := isLeast_univ.isGLB #align is_glb_univ isGLB_univ @[simp] theorem NoMaxOrder.upperBounds_univ [NoMaxOrder α] : upperBounds (univ : Set α) = ∅ := eq_empty_of_subset_empty fun b hb => let ⟨_, hx⟩ := exists_gt b not_le_of_lt hx (hb trivial) #align no_max_order.upper_bounds_univ NoMaxOrder.upperBounds_univ @[simp] theorem NoMinOrder.lowerBounds_univ [NoMinOrder α] : lowerBounds (univ : Set α) = ∅ := @NoMaxOrder.upperBounds_univ αᵒᵈ _ _ #align no_min_order.lower_bounds_univ NoMinOrder.lowerBounds_univ @[simp] theorem not_bddAbove_univ [NoMaxOrder α] : ¬BddAbove (univ : Set α) := by simp [BddAbove] #align not_bdd_above_univ not_bddAbove_univ @[simp] theorem not_bddBelow_univ [NoMinOrder α] : ¬BddBelow (univ : Set α) := @not_bddAbove_univ αᵒᵈ _ _ #align not_bdd_below_univ not_bddBelow_univ /-! #### Empty set -/ @[simp] theorem upperBounds_empty : upperBounds (∅ : Set α) = univ := by simp only [upperBounds, eq_univ_iff_forall, mem_setOf_eq, forall_mem_empty, forall_true_iff] #align upper_bounds_empty upperBounds_empty @[simp] theorem lowerBounds_empty : lowerBounds (∅ : Set α) = univ := @upperBounds_empty αᵒᵈ _ #align lower_bounds_empty lowerBounds_empty @[simp] theorem bddAbove_empty [Nonempty α] : BddAbove (∅ : Set α) := by simp only [BddAbove, upperBounds_empty, univ_nonempty] #align bdd_above_empty bddAbove_empty @[simp] theorem bddBelow_empty [Nonempty α] : BddBelow (∅ : Set α) := by simp only [BddBelow, lowerBounds_empty, univ_nonempty] #align bdd_below_empty bddBelow_empty @[simp] theorem isGLB_empty_iff : IsGLB ∅ a ↔ IsTop a := by simp [IsGLB] #align is_glb_empty_iff isGLB_empty_iff @[simp] theorem isLUB_empty_iff : IsLUB ∅ a ↔ IsBot a := @isGLB_empty_iff αᵒᵈ _ _ #align is_lub_empty_iff isLUB_empty_iff theorem isGLB_empty [OrderTop α] : IsGLB ∅ (⊤ : α) := isGLB_empty_iff.2 isTop_top #align is_glb_empty isGLB_empty theorem isLUB_empty [OrderBot α] : IsLUB ∅ (⊥ : α) := @isGLB_empty αᵒᵈ _ _ #align is_lub_empty isLUB_empty theorem IsLUB.nonempty [NoMinOrder α] (hs : IsLUB s a) : s.Nonempty := let ⟨a', ha'⟩ := exists_lt a nonempty_iff_ne_empty.2 fun h => not_le_of_lt ha' <| hs.right <| by rw [h, upperBounds_empty]; exact mem_univ _ #align is_lub.nonempty IsLUB.nonempty theorem IsGLB.nonempty [NoMaxOrder α] (hs : IsGLB s a) : s.Nonempty := hs.dual.nonempty #align is_glb.nonempty IsGLB.nonempty theorem nonempty_of_not_bddAbove [ha : Nonempty α] (h : ¬BddAbove s) : s.Nonempty := (Nonempty.elim ha) fun x => (not_bddAbove_iff'.1 h x).imp fun _ ha => ha.1 #align nonempty_of_not_bdd_above nonempty_of_not_bddAbove theorem nonempty_of_not_bddBelow [Nonempty α] (h : ¬BddBelow s) : s.Nonempty := @nonempty_of_not_bddAbove αᵒᵈ _ _ _ h #align nonempty_of_not_bdd_below nonempty_of_not_bddBelow /-! #### insert -/ /-- Adding a point to a set preserves its boundedness above. -/ @[simp]
Mathlib/Order/Bounds/Basic.lean
935
937
theorem bddAbove_insert [IsDirected α (· ≤ ·)] {s : Set α} {a : α} : BddAbove (insert a s) ↔ BddAbove s := by
simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and_iff]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import measure_theory.measure.measure_space from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace open scoped Classical symmDiff open Topology Filter ENNReal NNReal Interval MeasureTheory variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ #align measure_theory.ae_is_measurably_generated MeasureTheory.ae_isMeasurablyGenerated /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] #align measure_theory.ae_uIoc_iff MeasureTheory.ae_uIoc_iff theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union MeasureTheory.measure_union theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union' MeasureTheory.measure_union' theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet #align measure_theory.measure_inter_add_diff MeasureTheory.measure_inter_add_diff theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) #align measure_theory.measure_diff_add_inter MeasureTheory.measure_diff_add_inter theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl #align measure_theory.measure_union_add_inter MeasureTheory.measure_union_add_inter theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] #align measure_theory.measure_union_add_inter' MeasureTheory.measure_union_add_inter' lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs) lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet #align measure_theory.measure_add_measure_compl MeasureTheory.measure_add_measure_compl theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 #align measure_theory.measure_bUnion₀ MeasureTheory.measure_biUnion₀ theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet #align measure_theory.measure_bUnion MeasureTheory.measure_biUnion theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] #align measure_theory.measure_sUnion₀ MeasureTheory.measure_sUnion₀ theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] #align measure_theory.measure_sUnion MeasureTheory.measure_sUnion theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm #align measure_theory.measure_bUnion_finset₀ MeasureTheory.measure_biUnion_finset₀ theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet #align measure_theory.measure_bUnion_finset MeasureTheory.measure_biUnion_finset /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) #align measure_theory.tsum_meas_le_meas_Union_of_disjoint MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] #align measure_theory.tsum_measure_preimage_singleton MeasureTheory.tsum_measure_preimage_singleton lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] #align measure_theory.sum_measure_preimage_singleton MeasureTheory.sum_measure_preimage_singleton theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h #align measure_theory.measure_diff_null' MeasureTheory.measure_diff_null' theorem measure_add_diff (hs : MeasurableSet s) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union' disjoint_sdiff_right hs, union_diff_self] #align measure_theory.measure_add_diff MeasureTheory.measure_add_diff theorem measure_diff' (s : Set α) (hm : MeasurableSet t) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := Eq.symm <| ENNReal.sub_eq_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] #align measure_theory.measure_diff' MeasureTheory.measure_diff' theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : MeasurableSet s₂) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] #align measure_theory.measure_diff MeasureTheory.measure_diff theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right #align measure_theory.le_measure_diff MeasureTheory.le_measure_diff /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := (WithTop.sub_eq_top_iff.2 ⟨hμu, hμv⟩).symm _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h #align measure_theory.measure_diff_lt_of_lt_add MeasureTheory.measure_diff_lt_of_lt_add theorem measure_diff_le_iff_le_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] #align measure_theory.measure_diff_le_iff_le_add MeasureTheory.measure_diff_le_iff_le_add theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) #align measure_theory.measure_eq_measure_of_null_diff MeasureTheory.measure_eq_measure_of_null_diff theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ #align measure_theory.measure_eq_measure_of_between_null_diff MeasureTheory.measure_eq_measure_of_between_null_diff theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 #align measure_theory.measure_eq_measure_smaller_of_between_null_diff MeasureTheory.measure_eq_measure_smaller_of_between_null_diff theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 #align measure_theory.measure_eq_measure_larger_of_between_null_diff MeasureTheory.measure_eq_measure_larger_of_between_null_diff lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin #align measure_theory.measure_compl MeasureTheory.measure_compl lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ #align measure_theory.union_ae_eq_left_iff_ae_subset MeasureTheory.union_ae_eq_left_iff_ae_subset @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] #align measure_theory.union_ae_eq_right_iff_ae_subset MeasureTheory.union_ae_eq_right_iff_ae_subset theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] #align measure_theory.ae_eq_of_ae_subset_of_measure_ge MeasureTheory.ae_eq_of_ae_subset_of_measure_ge /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht #align measure_theory.ae_eq_of_subset_of_measure_ge MeasureTheory.ae_eq_of_subset_of_measure_ge theorem measure_iUnion_congr_of_subset [Countable β] {s : β → Set α} {t : β → Set α} (hsub : ∀ b, s b ⊆ t b) (h_le : ∀ b, μ (t b) ≤ μ (s b)) : μ (⋃ b, s b) = μ (⋃ b, t b) := by rcases Classical.em (∃ b, μ (t b) = ∞) with (⟨b, hb⟩ | htop) · calc μ (⋃ b, s b) = ∞ := top_unique (hb ▸ (h_le b).trans <| measure_mono <| subset_iUnion _ _) _ = μ (⋃ b, t b) := Eq.symm <| top_unique <| hb ▸ measure_mono (subset_iUnion _ _) push_neg at htop refine le_antisymm (measure_mono (iUnion_mono hsub)) ?_ set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _) · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ #align measure_theory.measure_Union_congr_of_subset MeasureTheory.measure_iUnion_congr_of_subset theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) #align measure_theory.measure_union_congr_of_subset MeasureTheory.measure_union_congr_of_subset @[simp] theorem measure_iUnion_toMeasurable [Countable β] (s : β → Set α) : μ (⋃ b, toMeasurable μ (s b)) = μ (⋃ b, s b) := Eq.symm <| measure_iUnion_congr_of_subset (fun _b => subset_toMeasurable _ _) fun _b => (measure_toMeasurable _).le #align measure_theory.measure_Union_to_measurable MeasureTheory.measure_iUnion_toMeasurable theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] #align measure_theory.measure_bUnion_to_measurable MeasureTheory.measure_biUnion_toMeasurable @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl #align measure_theory.measure_to_measurable_union MeasureTheory.measure_toMeasurable_union @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le #align measure_theory.measure_union_to_measurable MeasureTheory.measure_union_toMeasurable theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : Set.PairwiseDisjoint (↑s) t) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset H h] exact measure_mono (subset_univ _) #align measure_theory.sum_measure_le_measure_univ MeasureTheory.sum_measure_le_measure_univ theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : Pairwise (Disjoint on s)) : (∑' i, μ (s i)) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij #align measure_theory.tsum_measure_le_measure_univ MeasureTheory.tsum_measure_le_measure_univ /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact disjoint_iff_inter_eq_empty.mpr (H i j hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_sum_measure /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `t` is measurable. -/ theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [← Set.not_disjoint_iff_nonempty_inter] contrapose! h calc μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm _ ≤ μ u := measure_mono (union_subset h's h't) #align measure_theory.nonempty_inter_of_measure_lt_add MeasureTheory.nonempty_inter_of_measure_lt_add /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `s` is measurable. -/ theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [add_comm] at h rw [inter_comm] exact nonempty_inter_of_measure_lt_add μ hs h't h's h #align measure_theory.nonempty_inter_of_measure_lt_add' MeasureTheory.nonempty_inter_of_measure_lt_add' /-- Continuity from below: the measure of the union of a directed sequence of (not necessarily -measurable) sets is the supremum of the measures. -/ theorem measure_iUnion_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by cases nonempty_encodable ι -- WLOG, `ι = ℕ` generalize ht : Function.extend Encodable.encode s ⊥ = t replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot Encodable.encode_injective suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot Encodable.encode_injective, (· ∘ ·), Pi.bot_apply, bot_eq_empty, measure_empty] at this exact this.trans (iSup_extend_bot Encodable.encode_injective _) clear! ι -- The `≥` inequality is trivial refine le_antisymm ?_ (iSup_le fun i => measure_mono <| subset_iUnion _ _) -- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T` set T : ℕ → Set α := fun n => toMeasurable μ (t n) set Td : ℕ → Set α := disjointed T have hm : ∀ n, MeasurableSet (Td n) := MeasurableSet.disjointed fun n => measurableSet_toMeasurable _ _ calc μ (⋃ n, t n) ≤ μ (⋃ n, T n) := measure_mono (iUnion_mono fun i => subset_toMeasurable _ _) _ = μ (⋃ n, Td n) := by rw [iUnion_disjointed] _ ≤ ∑' n, μ (Td n) := measure_iUnion_le _ _ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum _ ≤ ⨆ n, μ (t n) := iSup_le fun I => by rcases hd.finset_le I with ⟨N, hN⟩ calc (∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) := (measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm _ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _) _ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _ _ ≤ μ (t N) := measure_mono (iUnion₂_subset hN) _ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N #align measure_theory.measure_Union_eq_supr MeasureTheory.measure_iUnion_eq_iSup /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the supremum of the measures of the partial unions. -/ theorem measure_iUnion_eq_iSup' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by have hd : Directed (· ⊆ ·) (Accumulate f) := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biUnion_subset_biUnion_left fun l rli ↦ le_trans rli rik, biUnion_subset_biUnion_left fun l rlj ↦ le_trans rlj rjk⟩ rw [← iUnion_accumulate] exact measure_iUnion_eq_iSup hd theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable) (hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, measure_iUnion_eq_iSup hd.directed_val, ← iSup_subtype''] #align measure_theory.measure_bUnion_eq_supr MeasureTheory.measure_biUnion_eq_iSup /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the infimum of the measures. -/ theorem measure_iInter_eq_iInf [Countable ι] {s : ι → Set α} (h : ∀ i, MeasurableSet (s i)) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by rcases hfin with ⟨k, hk⟩ have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht) rw [← ENNReal.sub_sub_cancel hk (iInf_le _ k), ENNReal.sub_iInf, ← ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ← measure_diff (iInter_subset _ k) (MeasurableSet.iInter h) (this _ (iInter_subset _ k)), diff_iInter, measure_iUnion_eq_iSup] · congr 1 refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => ?_) · rcases hd i k with ⟨j, hji, hjk⟩ use j rw [← measure_diff hjk (h _) (this _ hjk)] gcongr · rw [tsub_le_iff_right, ← measure_union, Set.union_comm] · exact measure_mono (diff_subset_iff.1 Subset.rfl) · apply disjoint_sdiff_left · apply h i · exact hd.mono_comp _ fun _ _ => diff_subset_diff_right #align measure_theory.measure_Inter_eq_infi MeasureTheory.measure_iInter_eq_iInf /-- Continuity from above: the measure of the intersection of a sequence of measurable sets is the infimum of the measures of the partial intersections. -/ theorem measure_iInter_eq_iInf' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (h : ∀ i, MeasurableSet (f i)) (hfin : ∃ i, μ (f i) ≠ ∞) : μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by let s := fun i ↦ ⋂ j ≤ i, f j have iInter_eq : ⋂ i, f i = ⋂ i, s i := by ext x; simp [s]; constructor · exact fun h _ j _ ↦ h j · intro h i rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact h j i rij have ms : ∀ i, MeasurableSet (s i) := fun i ↦ MeasurableSet.biInter (countable_univ.mono <| subset_univ _) fun i _ ↦ h i have hd : Directed (· ⊇ ·) s := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biInter_subset_biInter_left fun j rji ↦ le_trans rji rik, biInter_subset_biInter_left fun i rij ↦ le_trans rij rjk⟩ have hfin' : ∃ i, μ (s i) ≠ ∞ := by rcases hfin with ⟨i, hi⟩ rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact ⟨j, ne_top_of_le_ne_top hi <| measure_mono <| biInter_subset_of_mem rij⟩ exact iInter_eq ▸ measure_iInter_eq_iInf ms hd hfin' /-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily measurable) sets is the limit of the measures. -/ theorem tendsto_measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)] [Countable ι] {s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by rw [measure_iUnion_eq_iSup hm.directed_le] exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Union MeasureTheory.tendsto_measure_iUnion /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ theorem tendsto_measure_iUnion' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by rw [measure_iUnion_eq_iSup'] exact tendsto_atTop_iSup fun i j hij ↦ by gcongr /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {s : ι → Set α} (hs : ∀ n, MeasurableSet (s n)) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by rw [measure_iInter_eq_iInf hs hm.directed_ge hf] exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Inter MeasureTheory.tendsto_measure_iInter /-- Continuity from above: the measure of the intersection of a sequence of measurable sets such that one has finite measure is the limit of the measures of the partial intersections. -/ theorem tendsto_measure_iInter' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (hm : ∀ i, MeasurableSet (f i)) (hf : ∃ i, μ (f i) ≠ ∞) : Tendsto (fun i ↦ μ (⋂ j ∈ {j | j ≤ i}, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by rw [measure_iInter_eq_iInf' hm hf] exact tendsto_atTop_iInf fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij /-- The measure of the intersection of a decreasing sequence of measurable sets indexed by a linear order with first countable topology is the limit of the measures. -/ theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α} {a : ι} (hs : ∀ r > a, MeasurableSet (s r)) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j) (hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by refine tendsto_order.2 ⟨fun l hl => ?_, fun L hL => ?_⟩ · filter_upwards [self_mem_nhdsWithin (s := Ioi a)] with r hr using hl.trans_le (measure_mono (biInter_subset_of_mem hr)) obtain ⟨u, u_anti, u_pos, u_lim⟩ : ∃ u : ℕ → ι, StrictAnti u ∧ (∀ n : ℕ, a < u n) ∧ Tendsto u atTop (𝓝 a) := by rcases hf with ⟨r, ar, _⟩ rcases exists_seq_strictAnti_tendsto' ar with ⟨w, w_anti, w_mem, w_lim⟩ exact ⟨w, w_anti, fun n => (w_mem n).1, w_lim⟩ have A : Tendsto (μ ∘ s ∘ u) atTop (𝓝 (μ (⋂ n, s (u n)))) := by refine tendsto_measure_iInter (fun n => hs _ (u_pos n)) ?_ ?_ · intro m n hmn exact hm _ _ (u_pos n) (u_anti.antitone hmn) · rcases hf with ⟨r, rpos, hr⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, u n < r := ((tendsto_order.1 u_lim).2 r rpos).exists refine ⟨n, ne_of_lt (lt_of_le_of_lt ?_ hr.lt_top)⟩ exact measure_mono (hm _ _ (u_pos n) hn.le) have B : ⋂ n, s (u n) = ⋂ r > a, s r := by apply Subset.antisymm · simp only [subset_iInter_iff, gt_iff_lt] intro r rpos obtain ⟨n, hn⟩ : ∃ n, u n < r := ((tendsto_order.1 u_lim).2 _ rpos).exists exact Subset.trans (iInter_subset _ n) (hm (u n) r (u_pos n) hn.le) · simp only [subset_iInter_iff, gt_iff_lt] intro n apply biInter_subset_of_mem exact u_pos n rw [B] at A obtain ⟨n, hn⟩ : ∃ n, μ (s (u n)) < L := ((tendsto_order.1 A).2 _ hL).exists have : Ioc a (u n) ∈ 𝓝[>] a := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, u_pos n⟩ filter_upwards [this] with r hr using lt_of_le_of_lt (measure_mono (hm _ _ hr.1 hr.2)) hn #align measure_theory.tendsto_measure_bInter_gt MeasureTheory.tendsto_measure_biInter_gt /-- One direction of the **Borel-Cantelli lemma** (sometimes called the "*first* Borel-Cantelli lemma"): if (sᵢ) is a sequence of sets such that `∑ μ sᵢ` is finite, then the limit superior of the `sᵢ` is a null set. Note: for the *second* Borel-Cantelli lemma (applying to independent sets in a probability space), see `ProbabilityTheory.measure_limsup_eq_one`. -/ theorem measure_limsup_eq_zero {s : ℕ → Set α} (hs : (∑' i, μ (s i)) ≠ ∞) : μ (limsup s atTop) = 0 := by -- First we replace the sequence `sₙ` with a sequence of measurable sets `tₙ ⊇ sₙ` of the same -- measure. set t : ℕ → Set α := fun n => toMeasurable μ (s n) have ht : (∑' i, μ (t i)) ≠ ∞ := by simpa only [t, measure_toMeasurable] using hs suffices μ (limsup t atTop) = 0 by have A : s ≤ t := fun n => subset_toMeasurable μ (s n) -- TODO default args fail exact measure_mono_null (limsup_le_limsup (eventually_of_forall (Pi.le_def.mp A))) this -- Next we unfold `limsup` for sets and replace equality with an inequality simp only [limsup_eq_iInf_iSup_of_nat', Set.iInf_eq_iInter, Set.iSup_eq_iUnion, ← nonpos_iff_eq_zero] -- Finally, we estimate `μ (⋃ i, t (i + n))` by `∑ i', μ (t (i + n))` refine le_of_tendsto_of_tendsto' (tendsto_measure_iInter (fun i => MeasurableSet.iUnion fun b => measurableSet_toMeasurable _ _) ?_ ⟨0, ne_top_of_le_ne_top ht (measure_iUnion_le t)⟩) (ENNReal.tendsto_sum_nat_add (μ ∘ t) ht) fun n => measure_iUnion_le _ intro n m hnm x simp only [Set.mem_iUnion] exact fun ⟨i, hi⟩ => ⟨i + (m - n), by simpa only [add_assoc, tsub_add_cancel_of_le hnm] using hi⟩ #align measure_theory.measure_limsup_eq_zero MeasureTheory.measure_limsup_eq_zero theorem measure_liminf_eq_zero {s : ℕ → Set α} (h : (∑' i, μ (s i)) ≠ ∞) : μ (liminf s atTop) = 0 := by rw [← le_zero_iff] have : liminf s atTop ≤ limsup s atTop := liminf_le_limsup exact (μ.mono this).trans (by simp [measure_limsup_eq_zero h]) #align measure_theory.measure_liminf_eq_zero MeasureTheory.measure_liminf_eq_zero -- Need to specify `α := Set α` below because of diamond; see #19041 theorem limsup_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : limsup (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.limsup_sdiff s t] apply measure_limsup_eq_zero simp [h] · rw [atTop.sdiff_limsup s t] apply measure_liminf_eq_zero simp [h] #align measure_theory.limsup_ae_eq_of_forall_ae_eq MeasureTheory.limsup_ae_eq_of_forall_ae_eq -- Need to specify `α := Set α` above because of diamond; see #19041 theorem liminf_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : liminf (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.liminf_sdiff s t] apply measure_liminf_eq_zero simp [h] · rw [atTop.sdiff_liminf s t] apply measure_limsup_eq_zero simp [h] #align measure_theory.liminf_ae_eq_of_forall_ae_eq MeasureTheory.liminf_ae_eq_of_forall_ae_eq theorem measure_if {x : β} {t : Set β} {s : Set α} : μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h] #align measure_theory.measure_if MeasureTheory.measure_if end section OuterMeasure variable [ms : MeasurableSpace α] {s t : Set α} /-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are Carathéodory measurable. -/ def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α := Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd => m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd #align measure_theory.outer_measure.to_measure MeasureTheory.OuterMeasure.toMeasure theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory := fun _s hs _t => (measure_inter_add_diff _ hs).symm #align measure_theory.le_to_outer_measure_caratheodory MeasureTheory.le_toOuterMeasure_caratheodory @[simp] theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : (m.toMeasure h).toOuterMeasure = m.trim := rfl #align measure_theory.to_measure_to_outer_measure MeasureTheory.toMeasure_toOuterMeasure @[simp] theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : MeasurableSet s) : m.toMeasure h s = m s := m.trim_eq hs #align measure_theory.to_measure_apply MeasureTheory.toMeasure_apply theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) : m s ≤ m.toMeasure h s := m.le_trim s #align measure_theory.le_to_measure_apply MeasureTheory.le_toMeasure_apply theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by refine le_antisymm ?_ (le_toMeasure_apply _ _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩ calc m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm _ = m t := toMeasure_apply m h htm _ ≤ m s := m.mono hts #align measure_theory.to_measure_apply₀ MeasureTheory.toMeasure_apply₀ @[simp] theorem toOuterMeasure_toMeasure {μ : Measure α} : μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ := Measure.ext fun _s => μ.toOuterMeasure.trim_eq #align measure_theory.to_outer_measure_to_measure MeasureTheory.toOuterMeasure_toMeasure @[simp] theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure := μ.toOuterMeasure.boundedBy_eq_self #align measure_theory.bounded_by_measure MeasureTheory.boundedBy_measure end OuterMeasure section /- Porting note: These variables are wrapped by an anonymous section because they interrupt synthesizing instances in `MeasureSpace` section. -/ variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable), then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/ theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u) (htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by rw [h] at ht_ne_top refine le_antisymm (by gcongr) ?_ have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) := calc μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs _ = μ t := h.symm _ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm _ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne exact ENNReal.le_of_add_le_add_right B A #align measure_theory.measure.measure_inter_eq_of_measure_eq MeasureTheory.Measure.measure_inter_eq_of_measure_eq /-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`. Here, we require that the measure of `t` is finite. The conclusion holds without this assumption when the measure is s-finite (for example when it is σ-finite), see `measure_toMeasurable_inter_of_sFinite`. -/ theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := (measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t) ht).symm #align measure_theory.measure.measure_to_measurable_inter MeasureTheory.Measure.measure_toMeasurable_inter /-! ### The `ℝ≥0∞`-module of measures -/ instance instZero [MeasurableSpace α] : Zero (Measure α) := ⟨{ toOuterMeasure := 0 m_iUnion := fun _f _hf _hd => tsum_zero.symm trim_le := OuterMeasure.trim_zero.le }⟩ #align measure_theory.measure.has_zero MeasureTheory.Measure.instZero @[simp] theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 := rfl #align measure_theory.measure.zero_to_outer_measure MeasureTheory.Measure.zero_toOuterMeasure @[simp, norm_cast] theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 := rfl #align measure_theory.measure.coe_zero MeasureTheory.Measure.coe_zero @[nontriviality] lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : μ s = 0 := by rw [eq_empty_of_isEmpty s, measure_empty] instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) := ⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩ #align measure_theory.measure.subsingleton MeasureTheory.Measure.instSubsingleton theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 := Subsingleton.elim μ 0 #align measure_theory.measure.eq_zero_of_is_empty MeasureTheory.Measure.eq_zero_of_isEmpty instance instInhabited [MeasurableSpace α] : Inhabited (Measure α) := ⟨0⟩ #align measure_theory.measure.inhabited MeasureTheory.Measure.instInhabited instance instAdd [MeasurableSpace α] : Add (Measure α) := ⟨fun μ₁ μ₂ => { toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure m_iUnion := fun s hs hd => show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩ #align measure_theory.measure.has_add MeasureTheory.Measure.instAdd @[simp] theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : (μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure := rfl #align measure_theory.measure.add_to_outer_measure MeasureTheory.Measure.add_toOuterMeasure @[simp, norm_cast] theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl #align measure_theory.measure.coe_add MeasureTheory.Measure.coe_add theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl #align measure_theory.measure.add_apply MeasureTheory.Measure.add_apply section SMul variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞] instance instSMul [MeasurableSpace α] : SMul R (Measure α) := ⟨fun c μ => { toOuterMeasure := c • μ.toOuterMeasure m_iUnion := fun s hs hd => by simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩ #align measure_theory.measure.has_smul MeasureTheory.Measure.instSMul @[simp] theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) : (c • μ).toOuterMeasure = c • μ.toOuterMeasure := rfl #align measure_theory.measure.smul_to_outer_measure MeasureTheory.Measure.smul_toOuterMeasure @[simp, norm_cast] theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ := rfl #align measure_theory.measure.coe_smul MeasureTheory.Measure.coe_smul @[simp] theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) : (c • μ) s = c • μ s := rfl #align measure_theory.measure.smul_apply MeasureTheory.Measure.smul_apply instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] [MeasurableSpace α] : SMulCommClass R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩ #align measure_theory.measure.smul_comm_class MeasureTheory.Measure.instSMulCommClass instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] [MeasurableSpace α] : IsScalarTower R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩ #align measure_theory.measure.is_scalar_tower MeasureTheory.Measure.instIsScalarTower instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] [MeasurableSpace α] : IsCentralScalar R (Measure α) := ⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩ #align measure_theory.measure.is_central_scalar MeasureTheory.Measure.instIsCentralScalar end SMul instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : MulAction R (Measure α) := Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.mul_action MeasureTheory.Measure.instMulAction instance instAddCommMonoid [MeasurableSpace α] : AddCommMonoid (Measure α) := toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure fun _ _ => smul_toOuterMeasure _ _ #align measure_theory.measure.add_comm_monoid MeasureTheory.Measure.instAddCommMonoid /-- Coercion to function as an additive monoid homomorphism. -/ def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align measure_theory.measure.coe_add_hom MeasureTheory.Measure.coeAddHom @[simp] theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) : ⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I #align measure_theory.measure.coe_finset_sum MeasureTheory.Measure.coe_finset_sum theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) : (∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply] #align measure_theory.measure.finset_sum_apply MeasureTheory.Measure.finset_sum_apply instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : DistribMulAction R (Measure α) := Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.distrib_mul_action MeasureTheory.Measure.instDistribMulAction instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : Module R (Measure α) := Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.module MeasureTheory.Measure.instModule @[simp] theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : (c • μ) s = c * μ s := rfl #align measure_theory.measure.coe_nnreal_smul_apply MeasureTheory.Measure.coe_nnreal_smul_apply @[simp] theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : c • μ s = c * μ s := by rfl theorem ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by simp only [ae_iff, Algebra.id.smul_eq_mul, smul_apply, or_iff_right_iff_imp, mul_eq_zero] simp only [IsEmpty.forall_iff, hc] #align measure_theory.measure.ae_smul_measure_iff MeasureTheory.Measure.ae_smul_measure_iff theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by refine le_antisymm (measure_mono h') ?_ have : μ t + ν t ≤ μ s + ν t := calc μ t + ν t = μ s + ν s := h''.symm _ ≤ μ s + ν t := by gcongr apply ENNReal.le_of_add_le_add_right _ this exact ne_top_of_le_ne_top h (le_add_left le_rfl) #align measure_theory.measure.measure_eq_left_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_left_of_subset_of_measure_add_eq theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by rw [add_comm] at h'' h exact measure_eq_left_of_subset_of_measure_add_eq h h' h'' #align measure_theory.measure.measure_eq_right_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_right_of_subset_of_measure_add_eq theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm · refine measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _) (measure_toMeasurable t).symm rwa [measure_toMeasurable t] · simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht exact ht.1 #align measure_theory.measure.measure_to_measurable_add_inter_left MeasureTheory.Measure.measure_toMeasurable_add_inter_left theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by rw [add_comm] at ht ⊢ exact measure_toMeasurable_add_inter_left hs ht #align measure_theory.measure.measure_to_measurable_add_inter_right MeasureTheory.Measure.measure_toMeasurable_add_inter_right /-! ### The complete lattice of measures -/ /-- Measures are partially ordered. -/ instance instPartialOrder [MeasurableSpace α] : PartialOrder (Measure α) where le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s le_refl m s := le_rfl le_trans m₁ m₂ m₃ h₁ h₂ s := le_trans (h₁ s) (h₂ s) le_antisymm m₁ m₂ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s) #align measure_theory.measure.partial_order MeasureTheory.Measure.instPartialOrder theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl #align measure_theory.measure.to_outer_measure_le MeasureTheory.Measure.toOuterMeasure_le theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff #align measure_theory.measure.le_iff MeasureTheory.Measure.le_iff theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ := le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs) theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl #align measure_theory.measure.le_iff' MeasureTheory.Measure.le_iff' theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop] #align measure_theory.measure.lt_iff MeasureTheory.Measure.lt_iff theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le] #align measure_theory.measure.lt_iff' MeasureTheory.Measure.lt_iff' instance covariantAddLE [MeasurableSpace α] : CovariantClass (Measure α) (Measure α) (· + ·) (· ≤ ·) := ⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩ #align measure_theory.measure.covariant_add_le MeasureTheory.Measure.covariantAddLE protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s) #align measure_theory.measure.le_add_left MeasureTheory.Measure.le_add_left protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s) #align measure_theory.measure.le_add_right MeasureTheory.Measure.le_add_right section sInf variable {m : Set (Measure α)} theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) : MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by rw [OuterMeasure.sInf_eq_boundedBy_sInfGen] refine OuterMeasure.boundedBy_caratheodory fun t => ?_ simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t, coe_toOuterMeasure] intro μ hμ u htu _hu have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by intro s t hst rw [OuterMeasure.sInfGen_def, iInf_image] exact iInf₂_le_of_le μ hμ <| measure_mono hst rw [← measure_inter_add_diff u hs] exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu) #align measure_theory.measure.Inf_caratheodory MeasureTheory.Measure.sInf_caratheodory instance [MeasurableSpace α] : InfSet (Measure α) := ⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩ theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s := toMeasure_apply _ _ hs #align measure_theory.measure.Inf_apply MeasureTheory.Measure.sInf_apply private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ := have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h) le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m := have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) := le_sInf <| forall_mem_image.2 fun μ hμ ↦ toOuterMeasure_le.2 <| h _ hμ le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s instance instCompleteSemilatticeInf [MeasurableSpace α] : CompleteSemilatticeInf (Measure α) := { (by infer_instance : PartialOrder (Measure α)), (by infer_instance : InfSet (Measure α)) with sInf_le := fun _s _a => measure_sInf_le le_sInf := fun _s _a => measure_le_sInf } #align measure_theory.measure.complete_semilattice_Inf MeasureTheory.Measure.instCompleteSemilatticeInf instance instCompleteLattice [MeasurableSpace α] : CompleteLattice (Measure α) := { completeLatticeOfCompleteSemilatticeInf (Measure α) with top := { toOuterMeasure := ⊤, m_iUnion := by intro f _ _ refine (measure_iUnion_le _).antisymm ?_ if hne : (⋃ i, f i).Nonempty then rw [OuterMeasure.top_apply hne] exact le_top else simp_all [Set.not_nonempty_iff_eq_empty] trim_le := le_top }, le_top := fun μ => toOuterMeasure_le.mp le_top bot := 0 bot_le := fun _a _s => bot_le } #align measure_theory.measure.complete_lattice MeasureTheory.Measure.instCompleteLattice end sInf @[simp] theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top : (⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) = (⊤ : Measure α) := toOuterMeasure_toMeasure (μ := ⊤) #align measure_theory.outer_measure.to_measure_top MeasureTheory.OuterMeasure.toMeasure_top @[simp] theorem toOuterMeasure_top [MeasurableSpace α] : (⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) := rfl #align measure_theory.measure.to_outer_measure_top MeasureTheory.Measure.toOuterMeasure_top @[simp] theorem top_add : ⊤ + μ = ⊤ := top_unique <| Measure.le_add_right le_rfl #align measure_theory.measure.top_add MeasureTheory.Measure.top_add @[simp] theorem add_top : μ + ⊤ = ⊤ := top_unique <| Measure.le_add_left le_rfl #align measure_theory.measure.add_top MeasureTheory.Measure.add_top protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ := bot_le #align measure_theory.measure.zero_le MeasureTheory.Measure.zero_le theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 := μ.zero_le.le_iff_eq #align measure_theory.measure.nonpos_iff_eq_zero' MeasureTheory.Measure.nonpos_iff_eq_zero' @[simp] theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 := ⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h => h.symm ▸ rfl⟩ #align measure_theory.measure.measure_univ_eq_zero MeasureTheory.Measure.measure_univ_eq_zero theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 := measure_univ_eq_zero.not #align measure_theory.measure.measure_univ_ne_zero MeasureTheory.Measure.measure_univ_ne_zero instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩ @[simp] theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 := pos_iff_ne_zero.trans measure_univ_ne_zero #align measure_theory.measure.measure_univ_pos MeasureTheory.Measure.measure_univ_pos /-! ### Pushforward and pullback -/ /-- Lift a linear map between `OuterMeasure` spaces such that for each measure `μ` every measurable set is caratheodory-measurable w.r.t. `f μ` to a linear map between `Measure` spaces. -/ def liftLinear {m0 : MeasurableSpace α} (f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β) (hf : ∀ μ : Measure α, ‹_› ≤ (f μ.toOuterMeasure).caratheodory) : Measure α →ₗ[ℝ≥0∞] Measure β where toFun μ := (f μ.toOuterMeasure).toMeasure (hf μ) map_add' μ₁ μ₂ := ext fun s hs => by simp only [map_add, coe_add, Pi.add_apply, toMeasure_apply, add_toOuterMeasure, OuterMeasure.coe_add, hs] map_smul' c μ := ext fun s hs => by simp only [LinearMap.map_smulₛₗ, coe_smul, Pi.smul_apply, toMeasure_apply, smul_toOuterMeasure (R := ℝ≥0∞), OuterMeasure.coe_smul (R := ℝ≥0∞), smul_apply, hs] #align measure_theory.measure.lift_linear MeasureTheory.Measure.liftLinear lemma liftLinear_apply₀ {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : NullMeasurableSet s (liftLinear f hf μ)) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply₀ _ (hf μ) hs @[simp] theorem liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : MeasurableSet s) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply _ (hf μ) hs #align measure_theory.measure.lift_linear_apply MeasureTheory.Measure.liftLinear_apply theorem le_liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) (s : Set β) : f μ.toOuterMeasure s ≤ liftLinear f hf μ s := le_toMeasure_apply _ (hf μ) s #align measure_theory.measure.le_lift_linear_apply MeasureTheory.Measure.le_liftLinear_apply /-- The pushforward of a measure as a linear map. It is defined to be `0` if `f` is not a measurable function. -/ def mapₗ [MeasurableSpace α] (f : α → β) : Measure α →ₗ[ℝ≥0∞] Measure β := if hf : Measurable f then liftLinear (OuterMeasure.map f) fun μ _s hs t => le_toOuterMeasure_caratheodory μ _ (hf hs) (f ⁻¹' t) else 0 #align measure_theory.measure.mapₗ MeasureTheory.Measure.mapₗ theorem mapₗ_congr {f g : α → β} (hf : Measurable f) (hg : Measurable g) (h : f =ᵐ[μ] g) : mapₗ f μ = mapₗ g μ := by ext1 s hs simpa only [mapₗ, hf, hg, hs, dif_pos, liftLinear_apply, OuterMeasure.map_apply] using measure_congr (h.preimage s) #align measure_theory.measure.mapₗ_congr MeasureTheory.Measure.mapₗ_congr /-- The pushforward of a measure. It is defined to be `0` if `f` is not an almost everywhere measurable function. -/ irreducible_def map [MeasurableSpace α] (f : α → β) (μ : Measure α) : Measure β := if hf : AEMeasurable f μ then mapₗ (hf.mk f) μ else 0 #align measure_theory.measure.map MeasureTheory.Measure.map theorem mapₗ_mk_apply_of_aemeasurable {f : α → β} (hf : AEMeasurable f μ) : mapₗ (hf.mk f) μ = map f μ := by simp [map, hf] #align measure_theory.measure.mapₗ_mk_apply_of_ae_measurable MeasureTheory.Measure.mapₗ_mk_apply_of_aemeasurable theorem mapₗ_apply_of_measurable {f : α → β} (hf : Measurable f) (μ : Measure α) : mapₗ f μ = map f μ := by simp only [← mapₗ_mk_apply_of_aemeasurable hf.aemeasurable] exact mapₗ_congr hf hf.aemeasurable.measurable_mk hf.aemeasurable.ae_eq_mk #align measure_theory.measure.mapₗ_apply_of_measurable MeasureTheory.Measure.mapₗ_apply_of_measurable @[simp] theorem map_add (μ ν : Measure α) {f : α → β} (hf : Measurable f) : (μ + ν).map f = μ.map f + ν.map f := by simp [← mapₗ_apply_of_measurable hf] #align measure_theory.measure.map_add MeasureTheory.Measure.map_add @[simp] theorem map_zero (f : α → β) : (0 : Measure α).map f = 0 := by by_cases hf : AEMeasurable f (0 : Measure α) <;> simp [map, hf] #align measure_theory.measure.map_zero MeasureTheory.Measure.map_zero @[simp] theorem map_of_not_aemeasurable {f : α → β} {μ : Measure α} (hf : ¬AEMeasurable f μ) : μ.map f = 0 := by simp [map, hf] #align measure_theory.measure.map_of_not_ae_measurable MeasureTheory.Measure.map_of_not_aemeasurable theorem map_congr {f g : α → β} (h : f =ᵐ[μ] g) : Measure.map f μ = Measure.map g μ := by by_cases hf : AEMeasurable f μ · have hg : AEMeasurable g μ := hf.congr h simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hg] exact mapₗ_congr hf.measurable_mk hg.measurable_mk (hf.ae_eq_mk.symm.trans (h.trans hg.ae_eq_mk)) · have hg : ¬AEMeasurable g μ := by simpa [← aemeasurable_congr h] using hf simp [map_of_not_aemeasurable, hf, hg] #align measure_theory.measure.map_congr MeasureTheory.Measure.map_congr @[simp] protected theorem map_smul (c : ℝ≥0∞) (μ : Measure α) (f : α → β) : (c • μ).map f = c • μ.map f := by rcases eq_or_ne c 0 with (rfl | hc); · simp by_cases hf : AEMeasurable f μ · have hfc : AEMeasurable f (c • μ) := ⟨hf.mk f, hf.measurable_mk, (ae_smul_measure_iff hc).2 hf.ae_eq_mk⟩ simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hfc, LinearMap.map_smulₛₗ, RingHom.id_apply] congr 1 apply mapₗ_congr hfc.measurable_mk hf.measurable_mk exact EventuallyEq.trans ((ae_smul_measure_iff hc).1 hfc.ae_eq_mk.symm) hf.ae_eq_mk · have hfc : ¬AEMeasurable f (c • μ) := by intro hfc exact hf ⟨hfc.mk f, hfc.measurable_mk, (ae_smul_measure_iff hc).1 hfc.ae_eq_mk⟩ simp [map_of_not_aemeasurable hf, map_of_not_aemeasurable hfc] #align measure_theory.measure.map_smul MeasureTheory.Measure.map_smul @[simp] protected theorem map_smul_nnreal (c : ℝ≥0) (μ : Measure α) (f : α → β) : (c • μ).map f = c • μ.map f := μ.map_smul (c : ℝ≥0∞) f #align measure_theory.measure.map_smul_nnreal MeasureTheory.Measure.map_smul_nnreal variable {f : α → β} lemma map_apply₀ {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : NullMeasurableSet s (map f μ)) : μ.map f s = μ (f ⁻¹' s) := by rw [map, dif_pos hf, mapₗ, dif_pos hf.measurable_mk] at hs ⊢ rw [liftLinear_apply₀ _ hs, measure_congr (hf.ae_eq_mk.preimage s)] rfl /-- We can evaluate the pushforward on measurable sets. For non-measurable sets, see `MeasureTheory.Measure.le_map_apply` and `MeasurableEquiv.map_apply`. -/ @[simp] theorem map_apply_of_aemeasurable (hf : AEMeasurable f μ) {s : Set β} (hs : MeasurableSet s) : μ.map f s = μ (f ⁻¹' s) := map_apply₀ hf hs.nullMeasurableSet #align measure_theory.measure.map_apply_of_ae_measurable MeasureTheory.Measure.map_apply_of_aemeasurable @[simp] theorem map_apply (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : μ.map f s = μ (f ⁻¹' s) := map_apply_of_aemeasurable hf.aemeasurable hs #align measure_theory.measure.map_apply MeasureTheory.Measure.map_apply theorem map_toOuterMeasure (hf : AEMeasurable f μ) : (μ.map f).toOuterMeasure = (OuterMeasure.map f μ.toOuterMeasure).trim := by rw [← trimmed, OuterMeasure.trim_eq_trim_iff] intro s hs simp [hf, hs] #align measure_theory.measure.map_to_outer_measure MeasureTheory.Measure.map_toOuterMeasure @[simp] lemma map_eq_zero_iff (hf : AEMeasurable f μ) : μ.map f = 0 ↔ μ = 0 := by simp_rw [← measure_univ_eq_zero, map_apply_of_aemeasurable hf .univ, preimage_univ] @[simp] lemma mapₗ_eq_zero_iff (hf : Measurable f) : Measure.mapₗ f μ = 0 ↔ μ = 0 := by rw [mapₗ_apply_of_measurable hf, map_eq_zero_iff hf.aemeasurable] lemma map_ne_zero_iff (hf : AEMeasurable f μ) : μ.map f ≠ 0 ↔ μ ≠ 0 := (map_eq_zero_iff hf).not lemma mapₗ_ne_zero_iff (hf : Measurable f) : Measure.mapₗ f μ ≠ 0 ↔ μ ≠ 0 := (mapₗ_eq_zero_iff hf).not @[simp] theorem map_id : map id μ = μ := ext fun _ => map_apply measurable_id #align measure_theory.measure.map_id MeasureTheory.Measure.map_id @[simp] theorem map_id' : map (fun x => x) μ = μ := map_id #align measure_theory.measure.map_id' MeasureTheory.Measure.map_id' theorem map_map {g : β → γ} {f : α → β} (hg : Measurable g) (hf : Measurable f) : (μ.map f).map g = μ.map (g ∘ f) := ext fun s hs => by simp [hf, hg, hs, hg hs, hg.comp hf, ← preimage_comp] #align measure_theory.measure.map_map MeasureTheory.Measure.map_map @[mono] theorem map_mono {f : α → β} (h : μ ≤ ν) (hf : Measurable f) : μ.map f ≤ ν.map f := le_iff.2 fun s hs ↦ by simp [hf.aemeasurable, hs, h _] #align measure_theory.measure.map_mono MeasureTheory.Measure.map_mono /-- Even if `s` is not measurable, we can bound `map f μ s` from below. See also `MeasurableEquiv.map_apply`. -/ theorem le_map_apply {f : α → β} (hf : AEMeasurable f μ) (s : Set β) : μ (f ⁻¹' s) ≤ μ.map f s := calc μ (f ⁻¹' s) ≤ μ (f ⁻¹' toMeasurable (μ.map f) s) := by gcongr; apply subset_toMeasurable _ = μ.map f (toMeasurable (μ.map f) s) := (map_apply_of_aemeasurable hf <| measurableSet_toMeasurable _ _).symm _ = μ.map f s := measure_toMeasurable _ #align measure_theory.measure.le_map_apply MeasureTheory.Measure.le_map_apply theorem le_map_apply_image {f : α → β} (hf : AEMeasurable f μ) (s : Set α) : μ s ≤ μ.map f (f '' s) := (measure_mono (subset_preimage_image f s)).trans (le_map_apply hf _) /-- Even if `s` is not measurable, `map f μ s = 0` implies that `μ (f ⁻¹' s) = 0`. -/ theorem preimage_null_of_map_null {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : μ.map f s = 0) : μ (f ⁻¹' s) = 0 := nonpos_iff_eq_zero.mp <| (le_map_apply hf s).trans_eq hs #align measure_theory.measure.preimage_null_of_map_null MeasureTheory.Measure.preimage_null_of_map_null theorem tendsto_ae_map {f : α → β} (hf : AEMeasurable f μ) : Tendsto f (ae μ) (ae (μ.map f)) := fun _ hs => preimage_null_of_map_null hf hs #align measure_theory.measure.tendsto_ae_map MeasureTheory.Measure.tendsto_ae_map /-- Pullback of a `Measure` as a linear map. If `f` sends each measurable set to a measurable set, then for each measurable set `s` we have `comapₗ f μ s = μ (f '' s)`. If the linearity is not needed, please use `comap` instead, which works for a larger class of functions. -/ def comapₗ [MeasurableSpace α] (f : α → β) : Measure β →ₗ[ℝ≥0∞] Measure α := if hf : Injective f ∧ ∀ s, MeasurableSet s → MeasurableSet (f '' s) then liftLinear (OuterMeasure.comap f) fun μ s hs t => by simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1] apply le_toOuterMeasure_caratheodory exact hf.2 s hs else 0 #align measure_theory.measure.comapₗ MeasureTheory.Measure.comapₗ theorem comapₗ_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comapₗ f μ s = μ (f '' s) := by rw [comapₗ, dif_pos, liftLinear_apply _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure] exact ⟨hfi, hf⟩ #align measure_theory.measure.comapₗ_apply MeasureTheory.Measure.comapₗ_apply /-- Pullback of a `Measure`. If `f` sends each measurable set to a null-measurable set, then for each measurable set `s` we have `comap f μ s = μ (f '' s)`. -/ def comap [MeasurableSpace α] (f : α → β) (μ : Measure β) : Measure α := if hf : Injective f ∧ ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ then (OuterMeasure.comap f μ.toOuterMeasure).toMeasure fun s hs t => by simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1] exact (measure_inter_add_diff₀ _ (hf.2 s hs)).symm else 0 #align measure_theory.measure.comap MeasureTheory.Measure.comap theorem comap_apply₀ [MeasurableSpace α] (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) (hs : NullMeasurableSet s (comap f μ)) : comap f μ s = μ (f '' s) := by rw [comap, dif_pos (And.intro hfi hf)] at hs ⊢ rw [toMeasure_apply₀ _ _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure] #align measure_theory.measure.comap_apply₀ MeasureTheory.Measure.comap_apply₀ theorem le_comap_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) (s : Set α) : μ (f '' s) ≤ comap f μ s := by rw [comap, dif_pos (And.intro hfi hf)] exact le_toMeasure_apply _ _ _ #align measure_theory.measure.le_comap_apply MeasureTheory.Measure.le_comap_apply theorem comap_apply {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comap f μ s = μ (f '' s) := comap_apply₀ f μ hfi (fun s hs => (hf s hs).nullMeasurableSet) hs.nullMeasurableSet #align measure_theory.measure.comap_apply MeasureTheory.Measure.comap_apply theorem comapₗ_eq_comap {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comapₗ f μ s = comap f μ s := (comapₗ_apply f hfi hf μ hs).trans (comap_apply f hfi hf μ hs).symm #align measure_theory.measure.comapₗ_eq_comap MeasureTheory.Measure.comapₗ_eq_comap theorem measure_image_eq_zero_of_comap_eq_zero {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s : Set α} (hs : comap f μ s = 0) : μ (f '' s) = 0 := le_antisymm ((le_comap_apply f μ hfi hf s).trans hs.le) (zero_le _) #align measure_theory.measure.measure_image_eq_zero_of_comap_eq_zero MeasureTheory.Measure.measure_image_eq_zero_of_comap_eq_zero theorem ae_eq_image_of_ae_eq_comap {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s t : Set α} (hst : s =ᵐ[comap f μ] t) : f '' s =ᵐ[μ] f '' t := by rw [EventuallyEq, ae_iff] at hst ⊢ have h_eq_α : { a : α | ¬s a = t a } = s \ t ∪ t \ s := by ext1 x simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff] tauto have h_eq_β : { a : β | ¬(f '' s) a = (f '' t) a } = f '' s \ f '' t ∪ f '' t \ f '' s := by ext1 x simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff] tauto rw [← Set.image_diff hfi, ← Set.image_diff hfi, ← Set.image_union] at h_eq_β rw [h_eq_β] rw [h_eq_α] at hst exact measure_image_eq_zero_of_comap_eq_zero f μ hfi hf hst #align measure_theory.measure.ae_eq_image_of_ae_eq_comap MeasureTheory.Measure.ae_eq_image_of_ae_eq_comap theorem NullMeasurableSet.image {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s : Set α} (hs : NullMeasurableSet s (μ.comap f)) : NullMeasurableSet (f '' s) μ := by refine ⟨toMeasurable μ (f '' toMeasurable (μ.comap f) s), measurableSet_toMeasurable _ _, ?_⟩ refine EventuallyEq.trans ?_ (NullMeasurableSet.toMeasurable_ae_eq ?_).symm swap · exact hf _ (measurableSet_toMeasurable _ _) have h : toMeasurable (comap f μ) s =ᵐ[comap f μ] s := NullMeasurableSet.toMeasurable_ae_eq hs exact ae_eq_image_of_ae_eq_comap f μ hfi hf h.symm #align measure_theory.measure.null_measurable_set.image MeasureTheory.Measure.NullMeasurableSet.image theorem comap_preimage {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) {s : Set β} (hf : Injective f) (hf' : Measurable f) (h : ∀ t, MeasurableSet t → NullMeasurableSet (f '' t) μ) (hs : MeasurableSet s) : μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by rw [comap_apply₀ _ _ hf h (hf' hs).nullMeasurableSet, image_preimage_eq_inter_range] #align measure_theory.measure.comap_preimage MeasureTheory.Measure.comap_preimage section Sum /-- Sum of an indexed family of measures. -/ noncomputable def sum (f : ι → Measure α) : Measure α := (OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <| le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _) (OuterMeasure.le_sum_caratheodory _) #align measure_theory.measure.sum MeasureTheory.Measure.sum theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s := le_toMeasure_apply _ _ _ #align measure_theory.measure.le_sum_apply MeasureTheory.Measure.le_sum_apply @[simp] theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : sum f s = ∑' i, f i s := toMeasure_apply _ _ hs #align measure_theory.measure.sum_apply MeasureTheory.Measure.sum_apply theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩ calc sum f s = sum f t := measure_congr ht.symm _ = ∑' i, f i t := sum_apply _ t_meas _ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts /-! For the next theorem, the countability assumption is necessary. For a counterexample, consider an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets not containing `x₀`, and their complements. All points but `x₀` are measurable. Consider the sum of the Dirac masses at points different from `x₀`, and `s = x₀`. For any Dirac mass `δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure `sum δ_x` gives mass one to each point different from `x₀`, so it gives infinite mass to any measurable set containing `x₀` (as such a set is uncountable), and by outer regularity one get `sum δ_x {x₀} = ∞`. -/ theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩ calc sum f s ≤ sum f t := measure_mono hst _ = ∑' i, f i t := sum_apply _ htm _ = ∑' i, f i s := by simp [ht] theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ := le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i #align measure_theory.measure.le_sum MeasureTheory.Measure.le_sum @[simp] theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [sum_apply_of_countable] #align measure_theory.measure.sum_apply_eq_zero MeasureTheory.Measure.sum_apply_eq_zero theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs] #align measure_theory.measure.sum_apply_eq_zero' MeasureTheory.Measure.sum_apply_eq_zero' @[simp] lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by ext s hs simp [Measure.sum_apply _ hs] theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by ext1 s hs simp [sum_apply _ hs, ENNReal.tsum_prod'] theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by ext1 s hs simp_rw [sum_apply _ hs] rw [ENNReal.tsum_comm] #align measure_theory.measure.sum_comm MeasureTheory.Measure.sum_comm theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero #align measure_theory.measure.ae_sum_iff MeasureTheory.Measure.ae_sum_iff theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero' h.compl #align measure_theory.measure.ae_sum_iff' MeasureTheory.Measure.ae_sum_iff' @[simp] theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by ext1 s hs simp only [sum_apply, finset_sum_apply, hs, tsum_fintype] #align measure_theory.measure.sum_fintype MeasureTheory.Measure.sum_fintype theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) : (sum fun i : s => μ i) = ∑ i ∈ s, μ i := by rw [sum_fintype, Finset.sum_coe_sort s μ] #align measure_theory.measure.sum_coe_finset MeasureTheory.Measure.sum_coe_finset @[simp] theorem ae_sum_eq [Countable ι] (μ : ι → Measure α) : ae (sum μ) = ⨆ i, ae (μ i) := Filter.ext fun _ => ae_sum_iff.trans mem_iSup.symm #align measure_theory.measure.ae_sum_eq MeasureTheory.Measure.ae_sum_eq theorem sum_bool (f : Bool → Measure α) : sum f = f true + f false := by rw [sum_fintype, Fintype.sum_bool] #align measure_theory.measure.sum_bool MeasureTheory.Measure.sum_bool theorem sum_cond (μ ν : Measure α) : (sum fun b => cond b μ ν) = μ + ν := sum_bool _ #align measure_theory.measure.sum_cond MeasureTheory.Measure.sum_cond @[simp] theorem sum_of_empty [IsEmpty ι] (μ : ι → Measure α) : sum μ = 0 := by rw [← measure_univ_eq_zero, sum_apply _ MeasurableSet.univ, tsum_empty] #align measure_theory.measure.sum_of_empty MeasureTheory.Measure.sum_of_empty theorem sum_add_sum_compl (s : Set ι) (μ : ι → Measure α) : ((sum fun i : s => μ i) + sum fun i : ↥sᶜ => μ i) = sum μ := by ext1 t ht simp only [add_apply, sum_apply _ ht] exact tsum_add_tsum_compl (f := fun i => μ i t) ENNReal.summable ENNReal.summable #align measure_theory.measure.sum_add_sum_compl MeasureTheory.Measure.sum_add_sum_compl theorem sum_congr {μ ν : ℕ → Measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν := congr_arg sum (funext h) #align measure_theory.measure.sum_congr MeasureTheory.Measure.sum_congr theorem sum_add_sum {ι : Type*} (μ ν : ι → Measure α) : sum μ + sum ν = sum fun n => μ n + ν n := by ext1 s hs simp only [add_apply, sum_apply _ hs, Pi.add_apply, coe_add, tsum_add ENNReal.summable ENNReal.summable] #align measure_theory.measure.sum_add_sum MeasureTheory.Measure.sum_add_sum @[simp] lemma sum_comp_equiv {ι ι' : Type*} (e : ι' ≃ ι) (m : ι → Measure α) : sum (m ∘ e) = sum m := by ext s hs simpa [hs, sum_apply] using e.tsum_eq (fun n ↦ m n s) @[simp] lemma sum_extend_zero {ι ι' : Type*} {f : ι → ι'} (hf : Injective f) (m : ι → Measure α) : sum (Function.extend f m 0) = sum m := by ext s hs simp [*, Function.apply_extend (fun μ : Measure α ↦ μ s)] end Sum /-! ### Absolute continuity -/ /-- We say that `μ` is absolutely continuous with respect to `ν`, or that `μ` is dominated by `ν`, if `ν(A) = 0` implies that `μ(A) = 0`. -/ def AbsolutelyContinuous {_m0 : MeasurableSpace α} (μ ν : Measure α) : Prop := ∀ ⦃s : Set α⦄, ν s = 0 → μ s = 0 #align measure_theory.measure.absolutely_continuous MeasureTheory.Measure.AbsolutelyContinuous @[inherit_doc MeasureTheory.Measure.AbsolutelyContinuous] scoped[MeasureTheory] infixl:50 " ≪ " => MeasureTheory.Measure.AbsolutelyContinuous theorem absolutelyContinuous_of_le (h : μ ≤ ν) : μ ≪ ν := fun s hs => nonpos_iff_eq_zero.1 <| hs ▸ le_iff'.1 h s #align measure_theory.measure.absolutely_continuous_of_le MeasureTheory.Measure.absolutelyContinuous_of_le alias _root_.LE.le.absolutelyContinuous := absolutelyContinuous_of_le #align has_le.le.absolutely_continuous LE.le.absolutelyContinuous theorem absolutelyContinuous_of_eq (h : μ = ν) : μ ≪ ν := h.le.absolutelyContinuous #align measure_theory.measure.absolutely_continuous_of_eq MeasureTheory.Measure.absolutelyContinuous_of_eq alias _root_.Eq.absolutelyContinuous := absolutelyContinuous_of_eq #align eq.absolutely_continuous Eq.absolutelyContinuous namespace AbsolutelyContinuous theorem mk (h : ∀ ⦃s : Set α⦄, MeasurableSet s → ν s = 0 → μ s = 0) : μ ≪ ν := by intro s hs rcases exists_measurable_superset_of_null hs with ⟨t, h1t, h2t, h3t⟩ exact measure_mono_null h1t (h h2t h3t) #align measure_theory.measure.absolutely_continuous.mk MeasureTheory.Measure.AbsolutelyContinuous.mk @[refl] protected theorem refl {_m0 : MeasurableSpace α} (μ : Measure α) : μ ≪ μ := rfl.absolutelyContinuous #align measure_theory.measure.absolutely_continuous.refl MeasureTheory.Measure.AbsolutelyContinuous.refl protected theorem rfl : μ ≪ μ := fun _s hs => hs #align measure_theory.measure.absolutely_continuous.rfl MeasureTheory.Measure.AbsolutelyContinuous.rfl instance instIsRefl [MeasurableSpace α] : IsRefl (Measure α) (· ≪ ·) := ⟨fun _ => AbsolutelyContinuous.rfl⟩ #align measure_theory.measure.absolutely_continuous.is_refl MeasureTheory.Measure.AbsolutelyContinuous.instIsRefl @[simp] protected lemma zero (μ : Measure α) : 0 ≪ μ := fun s _ ↦ by simp @[trans] protected theorem trans (h1 : μ₁ ≪ μ₂) (h2 : μ₂ ≪ μ₃) : μ₁ ≪ μ₃ := fun _s hs => h1 <| h2 hs #align measure_theory.measure.absolutely_continuous.trans MeasureTheory.Measure.AbsolutelyContinuous.trans @[mono] protected theorem map (h : μ ≪ ν) {f : α → β} (hf : Measurable f) : μ.map f ≪ ν.map f := AbsolutelyContinuous.mk fun s hs => by simpa [hf, hs] using @h _ #align measure_theory.measure.absolutely_continuous.map MeasureTheory.Measure.AbsolutelyContinuous.map protected theorem smul [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (h : μ ≪ ν) (c : R) : c • μ ≪ ν := fun s hνs => by simp only [h hνs, smul_eq_mul, smul_apply, smul_zero] #align measure_theory.measure.absolutely_continuous.smul MeasureTheory.Measure.AbsolutelyContinuous.smul protected lemma add (h1 : μ₁ ≪ ν) (h2 : μ₂ ≪ ν') : μ₁ + μ₂ ≪ ν + ν' := by intro s hs simp only [coe_add, Pi.add_apply, add_eq_zero] at hs ⊢ exact ⟨h1 hs.1, h2 hs.2⟩ lemma add_left_iff {μ₁ μ₂ ν : Measure α} : μ₁ + μ₂ ≪ ν ↔ μ₁ ≪ ν ∧ μ₂ ≪ ν := by refine ⟨fun h ↦ ?_, fun h ↦ (h.1.add h.2).trans ?_⟩ · have : ∀ s, ν s = 0 → μ₁ s = 0 ∧ μ₂ s = 0 := by intro s hs0; simpa using h hs0 exact ⟨fun s hs0 ↦ (this s hs0).1, fun s hs0 ↦ (this s hs0).2⟩ · have : ν + ν = 2 • ν := by ext; simp [two_mul] rw [this] exact AbsolutelyContinuous.rfl.smul 2 lemma add_right (h1 : μ ≪ ν) (ν' : Measure α) : μ ≪ ν + ν' := by intro s hs simp only [coe_add, Pi.add_apply, add_eq_zero] at hs ⊢ exact h1 hs.1 end AbsolutelyContinuous @[simp] lemma absolutelyContinuous_zero_iff : μ ≪ 0 ↔ μ = 0 := ⟨fun h ↦ measure_univ_eq_zero.mp (h rfl), fun h ↦ h.symm ▸ AbsolutelyContinuous.zero _⟩ alias absolutelyContinuous_refl := AbsolutelyContinuous.refl alias absolutelyContinuous_rfl := AbsolutelyContinuous.rfl lemma absolutelyContinuous_sum_left {μs : ι → Measure α} (hμs : ∀ i, μs i ≪ ν) : Measure.sum μs ≪ ν := AbsolutelyContinuous.mk fun s hs hs0 ↦ by simp [sum_apply _ hs, fun i ↦ hμs i hs0] lemma absolutelyContinuous_sum_right {μs : ι → Measure α} (i : ι) (hνμ : ν ≪ μs i) : ν ≪ Measure.sum μs := by refine AbsolutelyContinuous.mk fun s hs hs0 ↦ ?_ simp only [sum_apply _ hs, ENNReal.tsum_eq_zero] at hs0 exact hνμ (hs0 i) theorem absolutelyContinuous_of_le_smul {μ' : Measure α} {c : ℝ≥0∞} (hμ'_le : μ' ≤ c • μ) : μ' ≪ μ := (Measure.absolutelyContinuous_of_le hμ'_le).trans (Measure.AbsolutelyContinuous.rfl.smul c) #align measure_theory.measure.absolutely_continuous_of_le_smul MeasureTheory.Measure.absolutelyContinuous_of_le_smul lemma smul_absolutelyContinuous {c : ℝ≥0∞} : c • μ ≪ μ := absolutelyContinuous_of_le_smul le_rfl lemma absolutelyContinuous_smul {c : ℝ≥0∞} (hc : c ≠ 0) : μ ≪ c • μ := by simp [AbsolutelyContinuous, hc] theorem ae_le_iff_absolutelyContinuous : ae μ ≤ ae ν ↔ μ ≪ ν := ⟨fun h s => by rw [measure_zero_iff_ae_nmem, measure_zero_iff_ae_nmem] exact fun hs => h hs, fun h s hs => h hs⟩ #align measure_theory.measure.ae_le_iff_absolutely_continuous MeasureTheory.Measure.ae_le_iff_absolutelyContinuous alias ⟨_root_.LE.le.absolutelyContinuous_of_ae, AbsolutelyContinuous.ae_le⟩ := ae_le_iff_absolutelyContinuous #align has_le.le.absolutely_continuous_of_ae LE.le.absolutelyContinuous_of_ae #align measure_theory.measure.absolutely_continuous.ae_le MeasureTheory.Measure.AbsolutelyContinuous.ae_le alias ae_mono' := AbsolutelyContinuous.ae_le #align measure_theory.measure.ae_mono' MeasureTheory.Measure.ae_mono' theorem AbsolutelyContinuous.ae_eq (h : μ ≪ ν) {f g : α → δ} (h' : f =ᵐ[ν] g) : f =ᵐ[μ] g := h.ae_le h' #align measure_theory.measure.absolutely_continuous.ae_eq MeasureTheory.Measure.AbsolutelyContinuous.ae_eq protected theorem _root_.MeasureTheory.AEDisjoint.of_absolutelyContinuous (h : AEDisjoint μ s t) {ν : Measure α} (h' : ν ≪ μ) : AEDisjoint ν s t := h' h protected theorem _root_.MeasureTheory.AEDisjoint.of_le (h : AEDisjoint μ s t) {ν : Measure α} (h' : ν ≤ μ) : AEDisjoint ν s t := h.of_absolutelyContinuous (Measure.absolutelyContinuous_of_le h') /-! ### Quasi measure preserving maps (a.k.a. non-singular maps) -/ /-- A map `f : α → β` is said to be *quasi measure preserving* (a.k.a. non-singular) w.r.t. measures `μa` and `μb` if it is measurable and `μb s = 0` implies `μa (f ⁻¹' s) = 0`. -/ structure QuasiMeasurePreserving {m0 : MeasurableSpace α} (f : α → β) (μa : Measure α := by volume_tac) (μb : Measure β := by volume_tac) : Prop where protected measurable : Measurable f protected absolutelyContinuous : μa.map f ≪ μb #align measure_theory.measure.quasi_measure_preserving MeasureTheory.Measure.QuasiMeasurePreserving #align measure_theory.measure.quasi_measure_preserving.measurable MeasureTheory.Measure.QuasiMeasurePreserving.measurable #align measure_theory.measure.quasi_measure_preserving.absolutely_continuous MeasureTheory.Measure.QuasiMeasurePreserving.absolutelyContinuous namespace QuasiMeasurePreserving protected theorem id {_m0 : MeasurableSpace α} (μ : Measure α) : QuasiMeasurePreserving id μ μ := ⟨measurable_id, map_id.absolutelyContinuous⟩ #align measure_theory.measure.quasi_measure_preserving.id MeasureTheory.Measure.QuasiMeasurePreserving.id variable {μa μa' : Measure α} {μb μb' : Measure β} {μc : Measure γ} {f : α → β} protected theorem _root_.Measurable.quasiMeasurePreserving {_m0 : MeasurableSpace α} (hf : Measurable f) (μ : Measure α) : QuasiMeasurePreserving f μ (μ.map f) := ⟨hf, AbsolutelyContinuous.rfl⟩ #align measurable.quasi_measure_preserving Measurable.quasiMeasurePreserving theorem mono_left (h : QuasiMeasurePreserving f μa μb) (ha : μa' ≪ μa) : QuasiMeasurePreserving f μa' μb := ⟨h.1, (ha.map h.1).trans h.2⟩ #align measure_theory.measure.quasi_measure_preserving.mono_left MeasureTheory.Measure.QuasiMeasurePreserving.mono_left theorem mono_right (h : QuasiMeasurePreserving f μa μb) (ha : μb ≪ μb') : QuasiMeasurePreserving f μa μb' := ⟨h.1, h.2.trans ha⟩ #align measure_theory.measure.quasi_measure_preserving.mono_right MeasureTheory.Measure.QuasiMeasurePreserving.mono_right @[mono] theorem mono (ha : μa' ≪ μa) (hb : μb ≪ μb') (h : QuasiMeasurePreserving f μa μb) : QuasiMeasurePreserving f μa' μb' := (h.mono_left ha).mono_right hb #align measure_theory.measure.quasi_measure_preserving.mono MeasureTheory.Measure.QuasiMeasurePreserving.mono protected theorem comp {g : β → γ} {f : α → β} (hg : QuasiMeasurePreserving g μb μc) (hf : QuasiMeasurePreserving f μa μb) : QuasiMeasurePreserving (g ∘ f) μa μc := ⟨hg.measurable.comp hf.measurable, by rw [← map_map hg.1 hf.1] exact (hf.2.map hg.1).trans hg.2⟩ #align measure_theory.measure.quasi_measure_preserving.comp MeasureTheory.Measure.QuasiMeasurePreserving.comp protected theorem iterate {f : α → α} (hf : QuasiMeasurePreserving f μa μa) : ∀ n, QuasiMeasurePreserving f^[n] μa μa | 0 => QuasiMeasurePreserving.id μa | n + 1 => (hf.iterate n).comp hf #align measure_theory.measure.quasi_measure_preserving.iterate MeasureTheory.Measure.QuasiMeasurePreserving.iterate protected theorem aemeasurable (hf : QuasiMeasurePreserving f μa μb) : AEMeasurable f μa := hf.1.aemeasurable #align measure_theory.measure.quasi_measure_preserving.ae_measurable MeasureTheory.Measure.QuasiMeasurePreserving.aemeasurable theorem ae_map_le (h : QuasiMeasurePreserving f μa μb) : ae (μa.map f) ≤ ae μb := h.2.ae_le #align measure_theory.measure.quasi_measure_preserving.ae_map_le MeasureTheory.Measure.QuasiMeasurePreserving.ae_map_le theorem tendsto_ae (h : QuasiMeasurePreserving f μa μb) : Tendsto f (ae μa) (ae μb) := (tendsto_ae_map h.aemeasurable).mono_right h.ae_map_le #align measure_theory.measure.quasi_measure_preserving.tendsto_ae MeasureTheory.Measure.QuasiMeasurePreserving.tendsto_ae theorem ae (h : QuasiMeasurePreserving f μa μb) {p : β → Prop} (hg : ∀ᵐ x ∂μb, p x) : ∀ᵐ x ∂μa, p (f x) := h.tendsto_ae hg #align measure_theory.measure.quasi_measure_preserving.ae MeasureTheory.Measure.QuasiMeasurePreserving.ae theorem ae_eq (h : QuasiMeasurePreserving f μa μb) {g₁ g₂ : β → δ} (hg : g₁ =ᵐ[μb] g₂) : g₁ ∘ f =ᵐ[μa] g₂ ∘ f := h.ae hg #align measure_theory.measure.quasi_measure_preserving.ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.ae_eq theorem preimage_null (h : QuasiMeasurePreserving f μa μb) {s : Set β} (hs : μb s = 0) : μa (f ⁻¹' s) = 0 := preimage_null_of_map_null h.aemeasurable (h.2 hs) #align measure_theory.measure.quasi_measure_preserving.preimage_null MeasureTheory.Measure.QuasiMeasurePreserving.preimage_null theorem preimage_mono_ae {s t : Set β} (hf : QuasiMeasurePreserving f μa μb) (h : s ≤ᵐ[μb] t) : f ⁻¹' s ≤ᵐ[μa] f ⁻¹' t := eventually_map.mp <| Eventually.filter_mono (tendsto_ae_map hf.aemeasurable) (Eventually.filter_mono hf.ae_map_le h) #align measure_theory.measure.quasi_measure_preserving.preimage_mono_ae MeasureTheory.Measure.QuasiMeasurePreserving.preimage_mono_ae theorem preimage_ae_eq {s t : Set β} (hf : QuasiMeasurePreserving f μa μb) (h : s =ᵐ[μb] t) : f ⁻¹' s =ᵐ[μa] f ⁻¹' t := EventuallyLE.antisymm (hf.preimage_mono_ae h.le) (hf.preimage_mono_ae h.symm.le) #align measure_theory.measure.quasi_measure_preserving.preimage_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.preimage_ae_eq theorem preimage_iterate_ae_eq {s : Set α} {f : α → α} (hf : QuasiMeasurePreserving f μ μ) (k : ℕ) (hs : f ⁻¹' s =ᵐ[μ] s) : f^[k] ⁻¹' s =ᵐ[μ] s := by induction' k with k ih; · rfl rw [iterate_succ, preimage_comp] exact EventuallyEq.trans (hf.preimage_ae_eq ih) hs #align measure_theory.measure.quasi_measure_preserving.preimage_iterate_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.preimage_iterate_ae_eq theorem image_zpow_ae_eq {s : Set α} {e : α ≃ α} (he : QuasiMeasurePreserving e μ μ) (he' : QuasiMeasurePreserving e.symm μ μ) (k : ℤ) (hs : e '' s =ᵐ[μ] s) : (⇑(e ^ k)) '' s =ᵐ[μ] s := by rw [Equiv.image_eq_preimage] obtain ⟨k, rfl | rfl⟩ := k.eq_nat_or_neg · replace hs : (⇑e⁻¹) ⁻¹' s =ᵐ[μ] s := by rwa [Equiv.image_eq_preimage] at hs replace he' : (⇑e⁻¹)^[k] ⁻¹' s =ᵐ[μ] s := he'.preimage_iterate_ae_eq k hs rwa [Equiv.Perm.iterate_eq_pow e⁻¹ k, inv_pow e k] at he' · rw [zpow_neg, zpow_natCast] replace hs : e ⁻¹' s =ᵐ[μ] s := by convert he.preimage_ae_eq hs.symm rw [Equiv.preimage_image] replace he : (⇑e)^[k] ⁻¹' s =ᵐ[μ] s := he.preimage_iterate_ae_eq k hs rwa [Equiv.Perm.iterate_eq_pow e k] at he #align measure_theory.measure.quasi_measure_preserving.image_zpow_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.image_zpow_ae_eq -- Need to specify `α := Set α` below because of diamond; see #19041 theorem limsup_preimage_iterate_ae_eq {f : α → α} (hf : QuasiMeasurePreserving f μ μ) (hs : f ⁻¹' s =ᵐ[μ] s) : limsup (α := Set α) (fun n => (preimage f)^[n] s) atTop =ᵐ[μ] s := haveI : ∀ n, (preimage f)^[n] s =ᵐ[μ] s := by intro n induction' n with n ih · rfl simpa only [iterate_succ', comp_apply] using ae_eq_trans (hf.ae_eq ih) hs (limsup_ae_eq_of_forall_ae_eq (fun n => (preimage f)^[n] s) this).trans (ae_eq_refl _) #align measure_theory.measure.quasi_measure_preserving.limsup_preimage_iterate_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.limsup_preimage_iterate_ae_eq -- Need to specify `α := Set α` below because of diamond; see #19041 theorem liminf_preimage_iterate_ae_eq {f : α → α} (hf : QuasiMeasurePreserving f μ μ) (hs : f ⁻¹' s =ᵐ[μ] s) : liminf (α := Set α) (fun n => (preimage f)^[n] s) atTop =ᵐ[μ] s := by rw [← ae_eq_set_compl_compl, @Filter.liminf_compl (Set α)] rw [← ae_eq_set_compl_compl, ← preimage_compl] at hs convert hf.limsup_preimage_iterate_ae_eq hs ext1 n simp only [← Set.preimage_iterate_eq, comp_apply, preimage_compl] #align measure_theory.measure.quasi_measure_preserving.liminf_preimage_iterate_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.liminf_preimage_iterate_ae_eq /-- By replacing a measurable set that is almost invariant with the `limsup` of its preimages, we obtain a measurable set that is almost equal and strictly invariant. (The `liminf` would work just as well.) -/ theorem exists_preimage_eq_of_preimage_ae {f : α → α} (h : QuasiMeasurePreserving f μ μ) (hs : MeasurableSet s) (hs' : f ⁻¹' s =ᵐ[μ] s) : ∃ t : Set α, MeasurableSet t ∧ t =ᵐ[μ] s ∧ f ⁻¹' t = t := ⟨limsup (fun n => (preimage f)^[n] s) atTop, MeasurableSet.measurableSet_limsup fun n => preimage_iterate_eq ▸ h.measurable.iterate n hs, h.limsup_preimage_iterate_ae_eq hs', Filter.CompleteLatticeHom.apply_limsup_iterate (CompleteLatticeHom.setPreimage f) s⟩ #align measure_theory.measure.quasi_measure_preserving.exists_preimage_eq_of_preimage_ae MeasureTheory.Measure.QuasiMeasurePreserving.exists_preimage_eq_of_preimage_ae open Pointwise @[to_additive] theorem smul_ae_eq_of_ae_eq {G α : Type*} [Group G] [MulAction G α] [MeasurableSpace α] {s t : Set α} {μ : Measure α} (g : G) (h_qmp : QuasiMeasurePreserving (g⁻¹ • · : α → α) μ μ) (h_ae_eq : s =ᵐ[μ] t) : (g • s : Set α) =ᵐ[μ] (g • t : Set α) := by simpa only [← preimage_smul_inv] using h_qmp.ae_eq h_ae_eq #align measure_theory.measure.quasi_measure_preserving.smul_ae_eq_of_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.smul_ae_eq_of_ae_eq #align measure_theory.measure.quasi_measure_preserving.vadd_ae_eq_of_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.vadd_ae_eq_of_ae_eq end QuasiMeasurePreserving section Pointwise open Pointwise @[to_additive] theorem pairwise_aedisjoint_of_aedisjoint_forall_ne_one {G α : Type*} [Group G] [MulAction G α] [MeasurableSpace α] {μ : Measure α} {s : Set α} (h_ae_disjoint : ∀ g ≠ (1 : G), AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving (g • ·) μ μ) : Pairwise (AEDisjoint μ on fun g : G => g • s) := by intro g₁ g₂ hg let g := g₂⁻¹ * g₁ replace hg : g ≠ 1 := by rw [Ne, inv_mul_eq_one] exact hg.symm have : (g₂⁻¹ • ·) ⁻¹' (g • s ∩ s) = g₁ • s ∩ g₂ • s := by rw [preimage_eq_iff_eq_image (MulAction.bijective g₂⁻¹), image_smul, smul_set_inter, smul_smul, smul_smul, inv_mul_self, one_smul] change μ (g₁ • s ∩ g₂ • s) = 0 exact this ▸ (h_qmp g₂⁻¹).preimage_null (h_ae_disjoint g hg) #align measure_theory.measure.pairwise_ae_disjoint_of_ae_disjoint_forall_ne_one MeasureTheory.Measure.pairwise_aedisjoint_of_aedisjoint_forall_ne_one #align measure_theory.measure.pairwise_ae_disjoint_of_ae_disjoint_forall_ne_zero MeasureTheory.Measure.pairwise_aedisjoint_of_aedisjoint_forall_ne_zero end Pointwise /-! ### The `cofinite` filter -/ /-- The filter of sets `s` such that `sᶜ` has finite measure. -/ def cofinite {m0 : MeasurableSpace α} (μ : Measure α) : Filter α := comk (μ · < ∞) (by simp) (fun t ht s hs ↦ (measure_mono hs).trans_lt ht) fun s hs t ht ↦ (measure_union_le s t).trans_lt <| ENNReal.add_lt_top.2 ⟨hs, ht⟩ #align measure_theory.measure.cofinite MeasureTheory.Measure.cofinite theorem mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ := Iff.rfl #align measure_theory.measure.mem_cofinite MeasureTheory.Measure.mem_cofinite theorem compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ := by rw [mem_cofinite, compl_compl] #align measure_theory.measure.compl_mem_cofinite MeasureTheory.Measure.compl_mem_cofinite theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ { x | ¬p x } < ∞ := Iff.rfl #align measure_theory.measure.eventually_cofinite MeasureTheory.Measure.eventually_cofinite end Measure open Measure open MeasureTheory protected theorem _root_.AEMeasurable.nullMeasurable {f : α → β} (h : AEMeasurable f μ) : NullMeasurable f μ := let ⟨_g, hgm, hg⟩ := h; hgm.nullMeasurable.congr hg.symm #align ae_measurable.null_measurable AEMeasurable.nullMeasurable lemma _root_.AEMeasurable.nullMeasurableSet_preimage {f : α → β} {s : Set β} (hf : AEMeasurable f μ) (hs : MeasurableSet s) : NullMeasurableSet (f ⁻¹' s) μ := hf.nullMeasurable hs /-- The preimage of a null measurable set under a (quasi) measure preserving map is a null measurable set. -/ theorem NullMeasurableSet.preimage {ν : Measure β} {f : α → β} {t : Set β} (ht : NullMeasurableSet t ν) (hf : QuasiMeasurePreserving f μ ν) : NullMeasurableSet (f ⁻¹' t) μ := ⟨f ⁻¹' toMeasurable ν t, hf.measurable (measurableSet_toMeasurable _ _), hf.ae_eq ht.toMeasurable_ae_eq.symm⟩ #align measure_theory.null_measurable_set.preimage MeasureTheory.NullMeasurableSet.preimage theorem NullMeasurableSet.mono_ac (h : NullMeasurableSet s μ) (hle : ν ≪ μ) : NullMeasurableSet s ν := h.preimage <| (QuasiMeasurePreserving.id μ).mono_left hle #align measure_theory.null_measurable_set.mono_ac MeasureTheory.NullMeasurableSet.mono_ac theorem NullMeasurableSet.mono (h : NullMeasurableSet s μ) (hle : ν ≤ μ) : NullMeasurableSet s ν := h.mono_ac hle.absolutelyContinuous #align measure_theory.null_measurable_set.mono MeasureTheory.NullMeasurableSet.mono theorem AEDisjoint.preimage {ν : Measure β} {f : α → β} {s t : Set β} (ht : AEDisjoint ν s t) (hf : QuasiMeasurePreserving f μ ν) : AEDisjoint μ (f ⁻¹' s) (f ⁻¹' t) := hf.preimage_null ht #align measure_theory.ae_disjoint.preimage MeasureTheory.AEDisjoint.preimage @[simp] theorem ae_eq_bot : ae μ = ⊥ ↔ μ = 0 := by rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero] #align measure_theory.ae_eq_bot MeasureTheory.ae_eq_bot @[simp] theorem ae_neBot : (ae μ).NeBot ↔ μ ≠ 0 := neBot_iff.trans (not_congr ae_eq_bot) #align measure_theory.ae_ne_bot MeasureTheory.ae_neBot instance Measure.ae.neBot [NeZero μ] : (ae μ).NeBot := ae_neBot.2 <| NeZero.ne μ @[simp] theorem ae_zero {_m0 : MeasurableSpace α} : ae (0 : Measure α) = ⊥ := ae_eq_bot.2 rfl #align measure_theory.ae_zero MeasureTheory.ae_zero @[mono] theorem ae_mono (h : μ ≤ ν) : ae μ ≤ ae ν := h.absolutelyContinuous.ae_le #align measure_theory.ae_mono MeasureTheory.ae_mono theorem mem_ae_map_iff {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : MeasurableSet s) : s ∈ ae (μ.map f) ↔ f ⁻¹' s ∈ ae μ := by simp only [mem_ae_iff, map_apply_of_aemeasurable hf hs.compl, preimage_compl] #align measure_theory.mem_ae_map_iff MeasureTheory.mem_ae_map_iff theorem mem_ae_of_mem_ae_map {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : s ∈ ae (μ.map f)) : f ⁻¹' s ∈ ae μ := (tendsto_ae_map hf).eventually hs #align measure_theory.mem_ae_of_mem_ae_map MeasureTheory.mem_ae_of_mem_ae_map theorem ae_map_iff {f : α → β} (hf : AEMeasurable f μ) {p : β → Prop} (hp : MeasurableSet { x | p x }) : (∀ᵐ y ∂μ.map f, p y) ↔ ∀ᵐ x ∂μ, p (f x) := mem_ae_map_iff hf hp #align measure_theory.ae_map_iff MeasureTheory.ae_map_iff theorem ae_of_ae_map {f : α → β} (hf : AEMeasurable f μ) {p : β → Prop} (h : ∀ᵐ y ∂μ.map f, p y) : ∀ᵐ x ∂μ, p (f x) := mem_ae_of_mem_ae_map hf h #align measure_theory.ae_of_ae_map MeasureTheory.ae_of_ae_map theorem ae_map_mem_range {m0 : MeasurableSpace α} (f : α → β) (hf : MeasurableSet (range f)) (μ : Measure α) : ∀ᵐ x ∂μ.map f, x ∈ range f := by by_cases h : AEMeasurable f μ · change range f ∈ ae (μ.map f) rw [mem_ae_map_iff h hf] filter_upwards using mem_range_self · simp [map_of_not_aemeasurable h] #align measure_theory.ae_map_mem_range MeasureTheory.ae_map_mem_range section Intervals
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
2,039
2,046
theorem biSup_measure_Iic [Preorder α] {s : Set α} (hsc : s.Countable) (hst : ∀ x : α, ∃ y ∈ s, x ≤ y) (hdir : DirectedOn (· ≤ ·) s) : ⨆ x ∈ s, μ (Iic x) = μ univ := by
rw [← measure_biUnion_eq_iSup hsc] · congr simp only [← bex_def] at hst exact iUnion₂_eq_univ_iff.2 hst · exact directedOn_iff_directed.2 (hdir.directed_val.mono_comp _ fun x y => Iic_subset_Iic.2)
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Order.Group.Nat import Mathlib.Data.Finset.Antidiagonal import Mathlib.Data.Finset.Card import Mathlib.Data.Multiset.NatAntidiagonal #align_import data.finset.nat_antidiagonal from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Antidiagonals in ℕ × ℕ as finsets This file defines the antidiagonals of ℕ × ℕ as finsets: the `n`-th antidiagonal is the finset of pairs `(i, j)` such that `i + j = n`. This is useful for polynomial multiplication and more generally for sums going from `0` to `n`. ## Notes This refines files `Data.List.NatAntidiagonal` and `Data.Multiset.NatAntidiagonal`, providing an instance enabling `Finset.antidiagonal` on `Nat`. -/ open Function namespace Finset namespace Nat /-- The antidiagonal of a natural number `n` is the finset of pairs `(i, j)` such that `i + j = n`. -/ instance instHasAntidiagonal : HasAntidiagonal ℕ where antidiagonal n := ⟨Multiset.Nat.antidiagonal n, Multiset.Nat.nodup_antidiagonal n⟩ mem_antidiagonal {n} {xy} := by rw [mem_def, Multiset.Nat.mem_antidiagonal] lemma antidiagonal_eq_map (n : ℕ) : antidiagonal n = (range (n + 1)).map ⟨fun i ↦ (i, n - i), fun _ _ h ↦ (Prod.ext_iff.1 h).1⟩ := rfl lemma antidiagonal_eq_map' (n : ℕ) : antidiagonal n = (range (n + 1)).map ⟨fun i ↦ (n - i, i), fun _ _ h ↦ (Prod.ext_iff.1 h).2⟩ := by rw [← map_swap_antidiagonal, antidiagonal_eq_map, map_map]; rfl lemma antidiagonal_eq_image (n : ℕ) : antidiagonal n = (range (n + 1)).image fun i ↦ (i, n - i) := by simp only [antidiagonal_eq_map, map_eq_image, Function.Embedding.coeFn_mk] lemma antidiagonal_eq_image' (n : ℕ) : antidiagonal n = (range (n + 1)).image fun i ↦ (n - i, i) := by simp only [antidiagonal_eq_map', map_eq_image, Function.Embedding.coeFn_mk] /-- The cardinality of the antidiagonal of `n` is `n + 1`. -/ @[simp] theorem card_antidiagonal (n : ℕ) : (antidiagonal n).card = n + 1 := by simp [antidiagonal] #align finset.nat.card_antidiagonal Finset.Nat.card_antidiagonal /-- The antidiagonal of `0` is the list `[(0, 0)]` -/ -- nolint as this is for dsimp @[simp, nolint simpNF] theorem antidiagonal_zero : antidiagonal 0 = {(0, 0)} := rfl #align finset.nat.antidiagonal_zero Finset.Nat.antidiagonal_zero theorem antidiagonal_succ (n : ℕ) : antidiagonal (n + 1) = cons (0, n + 1) ((antidiagonal n).map (Embedding.prodMap ⟨Nat.succ, Nat.succ_injective⟩ (Embedding.refl _))) (by simp) := by apply eq_of_veq rw [cons_val, map_val] apply Multiset.Nat.antidiagonal_succ #align finset.nat.antidiagonal_succ Finset.Nat.antidiagonal_succ theorem antidiagonal_succ' (n : ℕ) : antidiagonal (n + 1) = cons (n + 1, 0) ((antidiagonal n).map (Embedding.prodMap (Embedding.refl _) ⟨Nat.succ, Nat.succ_injective⟩)) (by simp) := by apply eq_of_veq rw [cons_val, map_val] exact Multiset.Nat.antidiagonal_succ' #align finset.nat.antidiagonal_succ' Finset.Nat.antidiagonal_succ'
Mathlib/Data/Finset/NatAntidiagonal.lean
89
99
theorem antidiagonal_succ_succ' {n : ℕ} : antidiagonal (n + 2) = cons (0, n + 2) (cons (n + 2, 0) ((antidiagonal n).map (Embedding.prodMap ⟨Nat.succ, Nat.succ_injective⟩ ⟨Nat.succ, Nat.succ_injective⟩)) <| by simp) (by simp) := by
simp_rw [antidiagonal_succ (n + 1), antidiagonal_succ', Finset.map_cons, map_map] rfl
/- Copyright (c) 2021 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Adam Topaz, Johan Commelin -/ import Mathlib.Algebra.Homology.Additive import Mathlib.AlgebraicTopology.MooreComplex import Mathlib.Algebra.BigOperators.Fin import Mathlib.CategoryTheory.Preadditive.Opposite import Mathlib.CategoryTheory.Idempotents.FunctorCategories #align_import algebraic_topology.alternating_face_map_complex from "leanprover-community/mathlib"@"88bca0ce5d22ebfd9e73e682e51d60ea13b48347" /-! # The alternating face map complex of a simplicial object in a preadditive category We construct the alternating face map complex, as a functor `alternatingFaceMapComplex : SimplicialObject C ⥤ ChainComplex C ℕ` for any preadditive category `C`. For any simplicial object `X` in `C`, this is the homological complex `... → X_2 → X_1 → X_0` where the differentials are alternating sums of faces. The dual version `alternatingCofaceMapComplex : CosimplicialObject C ⥤ CochainComplex C ℕ` is also constructed. We also construct the natural transformation `inclusionOfMooreComplex : normalizedMooreComplex A ⟶ alternatingFaceMapComplex A` when `A` is an abelian category. ## References * https://stacks.math.columbia.edu/tag/0194 * https://ncatlab.org/nlab/show/Moore+complex -/ open CategoryTheory CategoryTheory.Limits CategoryTheory.Subobject open CategoryTheory.Preadditive CategoryTheory.Category CategoryTheory.Idempotents open Opposite open Simplicial noncomputable section namespace AlgebraicTopology namespace AlternatingFaceMapComplex /-! ## Construction of the alternating face map complex -/ variable {C : Type*} [Category C] [Preadditive C] variable (X : SimplicialObject C) variable (Y : SimplicialObject C) /-- The differential on the alternating face map complex is the alternate sum of the face maps -/ @[simp] def objD (n : ℕ) : X _[n + 1] ⟶ X _[n] := ∑ i : Fin (n + 2), (-1 : ℤ) ^ (i : ℕ) • X.δ i #align algebraic_topology.alternating_face_map_complex.obj_d AlgebraicTopology.AlternatingFaceMapComplex.objD /-- ## The chain complex relation `d ≫ d` -/
Mathlib/AlgebraicTopology/AlternatingFaceMapComplex.lean
70
112
theorem d_squared (n : ℕ) : objD X (n + 1) ≫ objD X n = 0 := by
-- we start by expanding d ≫ d as a double sum dsimp simp only [comp_sum, sum_comp, ← Finset.sum_product'] -- then, we decompose the index set P into a subset S and its complement Sᶜ let P := Fin (n + 2) × Fin (n + 3) let S := Finset.univ.filter fun ij : P => (ij.2 : ℕ) ≤ (ij.1 : ℕ) erw [← Finset.sum_add_sum_compl S, ← eq_neg_iff_add_eq_zero, ← Finset.sum_neg_distrib] /- we are reduced to showing that two sums are equal, and this is obtained by constructing a bijection φ : S -> Sᶜ, which maps (i,j) to (j,i+1), and by comparing the terms -/ let φ : ∀ ij : P, ij ∈ S → P := fun ij hij => (Fin.castLT ij.2 (lt_of_le_of_lt (Finset.mem_filter.mp hij).right (Fin.is_lt ij.1)), ij.1.succ) apply Finset.sum_bij φ · -- φ(S) is contained in Sᶜ intro ij hij simp only [S, Finset.mem_univ, Finset.compl_filter, Finset.mem_filter, true_and_iff, Fin.val_succ, Fin.coe_castLT] at hij ⊢ linarith · -- φ : S → Sᶜ is injective rintro ⟨i, j⟩ hij ⟨i', j'⟩ hij' h rw [Prod.mk.inj_iff] exact ⟨by simpa using congr_arg Prod.snd h, by simpa [Fin.castSucc_castLT] using congr_arg Fin.castSucc (congr_arg Prod.fst h)⟩ · -- φ : S → Sᶜ is surjective rintro ⟨i', j'⟩ hij' simp only [S, Finset.mem_univ, forall_true_left, Prod.forall, ge_iff_le, Finset.compl_filter, not_le, Finset.mem_filter, true_and] at hij' refine ⟨(j'.pred <| ?_, Fin.castSucc i'), ?_, ?_⟩ · rintro rfl simp only [Fin.val_zero, not_lt_zero'] at hij' · simpa only [S, Finset.mem_univ, forall_true_left, Prod.forall, ge_iff_le, Finset.mem_filter, Fin.coe_castSucc, Fin.coe_pred, true_and] using Nat.le_sub_one_of_lt hij' · simp only [φ, Fin.castLT_castSucc, Fin.succ_pred] · -- identification of corresponding terms in both sums rintro ⟨i, j⟩ hij dsimp simp only [zsmul_comp, comp_zsmul, smul_smul, ← neg_smul] congr 1 · simp only [Fin.val_succ, pow_add, pow_one, mul_neg, neg_neg, mul_one] apply mul_comm · rw [CategoryTheory.SimplicialObject.δ_comp_δ''] simpa [S] using hij
/- Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn -/ import Mathlib.Data.Fin.VecNotation import Mathlib.SetTheory.Cardinal.Basic #align_import model_theory.basic from "leanprover-community/mathlib"@"369525b73f229ccd76a6ec0e0e0bf2be57599768" /-! # Basics on First-Order Structures This file defines first-order languages and structures in the style of the [Flypitch project](https://flypitch.github.io/), as well as several important maps between structures. ## Main Definitions * A `FirstOrder.Language` defines a language as a pair of functions from the natural numbers to `Type l`. One sends `n` to the type of `n`-ary functions, and the other sends `n` to the type of `n`-ary relations. * A `FirstOrder.Language.Structure` interprets the symbols of a given `FirstOrder.Language` in the context of a given type. * A `FirstOrder.Language.Hom`, denoted `M →[L] N`, is a map from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations (although only in the forward direction). * A `FirstOrder.Language.Embedding`, denoted `M ↪[L] N`, is an embedding from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations in both directions. * A `FirstOrder.Language.Equiv`, denoted `M ≃[L] N`, is an equivalence from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations in both directions. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ set_option autoImplicit true universe u v u' v' w w' open Cardinal open Cardinal namespace FirstOrder /-! ### Languages and Structures -/ -- intended to be used with explicit universe parameters /-- A first-order language consists of a type of functions of every natural-number arity and a type of relations of every natural-number arity. -/ @[nolint checkUnivs] structure Language where /-- For every arity, a `Type*` of functions of that arity -/ Functions : ℕ → Type u /-- For every arity, a `Type*` of relations of that arity -/ Relations : ℕ → Type v #align first_order.language FirstOrder.Language /-- Used to define `FirstOrder.Language₂`. -/ --@[simp] def Sequence₂ (a₀ a₁ a₂ : Type u) : ℕ → Type u | 0 => a₀ | 1 => a₁ | 2 => a₂ | _ => PEmpty #align first_order.sequence₂ FirstOrder.Sequence₂ namespace Sequence₂ variable (a₀ a₁ a₂ : Type u) instance inhabited₀ [h : Inhabited a₀] : Inhabited (Sequence₂ a₀ a₁ a₂ 0) := h #align first_order.sequence₂.inhabited₀ FirstOrder.Sequence₂.inhabited₀ instance inhabited₁ [h : Inhabited a₁] : Inhabited (Sequence₂ a₀ a₁ a₂ 1) := h #align first_order.sequence₂.inhabited₁ FirstOrder.Sequence₂.inhabited₁ instance inhabited₂ [h : Inhabited a₂] : Inhabited (Sequence₂ a₀ a₁ a₂ 2) := h #align first_order.sequence₂.inhabited₂ FirstOrder.Sequence₂.inhabited₂ instance {n : ℕ} : IsEmpty (Sequence₂ a₀ a₁ a₂ (n + 3)) := inferInstanceAs (IsEmpty PEmpty) @[simp] theorem lift_mk {i : ℕ} : Cardinal.lift.{v,u} #(Sequence₂ a₀ a₁ a₂ i) = #(Sequence₂ (ULift.{v,u} a₀) (ULift.{v,u} a₁) (ULift.{v,u} a₂) i) := by rcases i with (_ | _ | _ | i) <;> simp only [Sequence₂, mk_uLift, Nat.succ_ne_zero, IsEmpty.forall_iff, Nat.succ.injEq, add_eq_zero, OfNat.ofNat_ne_zero, and_false, one_ne_zero, mk_eq_zero, lift_zero] #align first_order.sequence₂.lift_mk FirstOrder.Sequence₂.lift_mk @[simp] theorem sum_card : Cardinal.sum (fun i => #(Sequence₂ a₀ a₁ a₂ i)) = #a₀ + #a₁ + #a₂ := by rw [sum_nat_eq_add_sum_succ, sum_nat_eq_add_sum_succ, sum_nat_eq_add_sum_succ] simp [add_assoc, Sequence₂] #align first_order.sequence₂.sum_card FirstOrder.Sequence₂.sum_card end Sequence₂ namespace Language /-- A constructor for languages with only constants, unary and binary functions, and unary and binary relations. -/ @[simps] protected def mk₂ (c f₁ f₂ : Type u) (r₁ r₂ : Type v) : Language := ⟨Sequence₂ c f₁ f₂, Sequence₂ PEmpty r₁ r₂⟩ #align first_order.language.mk₂ FirstOrder.Language.mk₂ /-- The empty language has no symbols. -/ protected def empty : Language := ⟨fun _ => Empty, fun _ => Empty⟩ #align first_order.language.empty FirstOrder.Language.empty instance : Inhabited Language := ⟨Language.empty⟩ /-- The sum of two languages consists of the disjoint union of their symbols. -/ protected def sum (L : Language.{u, v}) (L' : Language.{u', v'}) : Language := ⟨fun n => Sum (L.Functions n) (L'.Functions n), fun n => Sum (L.Relations n) (L'.Relations n)⟩ #align first_order.language.sum FirstOrder.Language.sum variable (L : Language.{u, v}) /-- The type of constants in a given language. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] protected def Constants := L.Functions 0 #align first_order.language.constants FirstOrder.Language.Constants @[simp] theorem constants_mk₂ (c f₁ f₂ : Type u) (r₁ r₂ : Type v) : (Language.mk₂ c f₁ f₂ r₁ r₂).Constants = c := rfl #align first_order.language.constants_mk₂ FirstOrder.Language.constants_mk₂ /-- The type of symbols in a given language. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] def Symbols := Sum (Σl, L.Functions l) (Σl, L.Relations l) #align first_order.language.symbols FirstOrder.Language.Symbols /-- The cardinality of a language is the cardinality of its type of symbols. -/ def card : Cardinal := #L.Symbols #align first_order.language.card FirstOrder.Language.card /-- A language is relational when it has no function symbols. -/ class IsRelational : Prop where /-- There are no function symbols in the language. -/ empty_functions : ∀ n, IsEmpty (L.Functions n) #align first_order.language.is_relational FirstOrder.Language.IsRelational /-- A language is algebraic when it has no relation symbols. -/ class IsAlgebraic : Prop where /-- There are no relation symbols in the language. -/ empty_relations : ∀ n, IsEmpty (L.Relations n) #align first_order.language.is_algebraic FirstOrder.Language.IsAlgebraic variable {L} {L' : Language.{u', v'}} theorem card_eq_card_functions_add_card_relations : L.card = (Cardinal.sum fun l => Cardinal.lift.{v} #(L.Functions l)) + Cardinal.sum fun l => Cardinal.lift.{u} #(L.Relations l) := by simp [card, Symbols] #align first_order.language.card_eq_card_functions_add_card_relations FirstOrder.Language.card_eq_card_functions_add_card_relations instance [L.IsRelational] {n : ℕ} : IsEmpty (L.Functions n) := IsRelational.empty_functions n instance [L.IsAlgebraic] {n : ℕ} : IsEmpty (L.Relations n) := IsAlgebraic.empty_relations n instance isRelational_of_empty_functions {symb : ℕ → Type*} : IsRelational ⟨fun _ => Empty, symb⟩ := ⟨fun _ => instIsEmptyEmpty⟩ #align first_order.language.is_relational_of_empty_functions FirstOrder.Language.isRelational_of_empty_functions instance isAlgebraic_of_empty_relations {symb : ℕ → Type*} : IsAlgebraic ⟨symb, fun _ => Empty⟩ := ⟨fun _ => instIsEmptyEmpty⟩ #align first_order.language.is_algebraic_of_empty_relations FirstOrder.Language.isAlgebraic_of_empty_relations instance isRelational_empty : IsRelational Language.empty := Language.isRelational_of_empty_functions #align first_order.language.is_relational_empty FirstOrder.Language.isRelational_empty instance isAlgebraic_empty : IsAlgebraic Language.empty := Language.isAlgebraic_of_empty_relations #align first_order.language.is_algebraic_empty FirstOrder.Language.isAlgebraic_empty instance isRelational_sum [L.IsRelational] [L'.IsRelational] : IsRelational (L.sum L') := ⟨fun _ => instIsEmptySum⟩ #align first_order.language.is_relational_sum FirstOrder.Language.isRelational_sum instance isAlgebraic_sum [L.IsAlgebraic] [L'.IsAlgebraic] : IsAlgebraic (L.sum L') := ⟨fun _ => instIsEmptySum⟩ #align first_order.language.is_algebraic_sum FirstOrder.Language.isAlgebraic_sum instance isRelational_mk₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h0 : IsEmpty c] [h1 : IsEmpty f₁] [h2 : IsEmpty f₂] : IsRelational (Language.mk₂ c f₁ f₂ r₁ r₂) := ⟨fun n => Nat.casesOn n h0 fun n => Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ => inferInstanceAs (IsEmpty PEmpty)⟩ #align first_order.language.is_relational_mk₂ FirstOrder.Language.isRelational_mk₂ instance isAlgebraic_mk₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h1 : IsEmpty r₁] [h2 : IsEmpty r₂] : IsAlgebraic (Language.mk₂ c f₁ f₂ r₁ r₂) := ⟨fun n => Nat.casesOn n (inferInstanceAs (IsEmpty PEmpty)) fun n => Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ => inferInstanceAs (IsEmpty PEmpty)⟩ #align first_order.language.is_algebraic_mk₂ FirstOrder.Language.isAlgebraic_mk₂ instance subsingleton_mk₂_functions {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h0 : Subsingleton c] [h1 : Subsingleton f₁] [h2 : Subsingleton f₂] {n : ℕ} : Subsingleton ((Language.mk₂ c f₁ f₂ r₁ r₂).Functions n) := Nat.casesOn n h0 fun n => Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ => ⟨fun x => PEmpty.elim x⟩ #align first_order.language.subsingleton_mk₂_functions FirstOrder.Language.subsingleton_mk₂_functions instance subsingleton_mk₂_relations {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h1 : Subsingleton r₁] [h2 : Subsingleton r₂] {n : ℕ} : Subsingleton ((Language.mk₂ c f₁ f₂ r₁ r₂).Relations n) := Nat.casesOn n ⟨fun x => PEmpty.elim x⟩ fun n => Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ => ⟨fun x => PEmpty.elim x⟩ #align first_order.language.subsingleton_mk₂_relations FirstOrder.Language.subsingleton_mk₂_relations @[simp] theorem empty_card : Language.empty.card = 0 := by simp [card_eq_card_functions_add_card_relations] #align first_order.language.empty_card FirstOrder.Language.empty_card instance isEmpty_empty : IsEmpty Language.empty.Symbols := by simp only [Language.Symbols, isEmpty_sum, isEmpty_sigma] exact ⟨fun _ => inferInstance, fun _ => inferInstance⟩ #align first_order.language.is_empty_empty FirstOrder.Language.isEmpty_empty instance Countable.countable_functions [h : Countable L.Symbols] : Countable (Σl, L.Functions l) := @Function.Injective.countable _ _ h _ Sum.inl_injective #align first_order.language.countable.countable_functions FirstOrder.Language.Countable.countable_functions @[simp] theorem card_functions_sum (i : ℕ) : #((L.sum L').Functions i) = (Cardinal.lift.{u'} #(L.Functions i) + Cardinal.lift.{u} #(L'.Functions i) : Cardinal) := by simp [Language.sum] #align first_order.language.card_functions_sum FirstOrder.Language.card_functions_sum @[simp] theorem card_relations_sum (i : ℕ) : #((L.sum L').Relations i) = Cardinal.lift.{v'} #(L.Relations i) + Cardinal.lift.{v} #(L'.Relations i) := by simp [Language.sum] #align first_order.language.card_relations_sum FirstOrder.Language.card_relations_sum @[simp] theorem card_sum : (L.sum L').card = Cardinal.lift.{max u' v'} L.card + Cardinal.lift.{max u v} L'.card := by simp only [card_eq_card_functions_add_card_relations, card_functions_sum, card_relations_sum, sum_add_distrib', lift_add, lift_sum, lift_lift] simp only [add_assoc, add_comm (Cardinal.sum fun i => (#(L'.Functions i)).lift)] #align first_order.language.card_sum FirstOrder.Language.card_sum @[simp] theorem card_mk₂ (c f₁ f₂ : Type u) (r₁ r₂ : Type v) : (Language.mk₂ c f₁ f₂ r₁ r₂).card = Cardinal.lift.{v} #c + Cardinal.lift.{v} #f₁ + Cardinal.lift.{v} #f₂ + Cardinal.lift.{u} #r₁ + Cardinal.lift.{u} #r₂ := by simp [card_eq_card_functions_add_card_relations, add_assoc] #align first_order.language.card_mk₂ FirstOrder.Language.card_mk₂ variable (L) (M : Type w) /-- A first-order structure on a type `M` consists of interpretations of all the symbols in a given language. Each function of arity `n` is interpreted as a function sending tuples of length `n` (modeled as `(Fin n → M)`) to `M`, and a relation of arity `n` is a function from tuples of length `n` to `Prop`. -/ @[ext] class Structure where /-- Interpretation of the function symbols -/ funMap : ∀ {n}, L.Functions n → (Fin n → M) → M /-- Interpretation of the relation symbols -/ RelMap : ∀ {n}, L.Relations n → (Fin n → M) → Prop set_option linter.uppercaseLean3 false in #align first_order.language.Structure FirstOrder.Language.Structure set_option linter.uppercaseLean3 false in #align first_order.language.Structure.fun_map FirstOrder.Language.Structure.funMap set_option linter.uppercaseLean3 false in #align first_order.language.Structure.rel_map FirstOrder.Language.Structure.RelMap variable (N : Type w') [L.Structure M] [L.Structure N] open Structure /-- Used for defining `FirstOrder.Language.Theory.ModelType.instInhabited`. -/ def Inhabited.trivialStructure {α : Type*} [Inhabited α] : L.Structure α := ⟨default, default⟩ #align first_order.language.inhabited.trivial_structure FirstOrder.Language.Inhabited.trivialStructure /-! ### Maps -/ /-- A homomorphism between first-order structures is a function that commutes with the interpretations of functions and maps tuples in one structure where a given relation is true to tuples in the second structure where that relation is still true. -/ structure Hom where /-- The underlying function of a homomorphism of structures -/ toFun : M → N /-- The homomorphism commutes with the interpretations of the function symbols -/ -- 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_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by intros; trivial /-- The homomorphism sends related elements to related elements -/ map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r x → RelMap r (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial #align first_order.language.hom FirstOrder.Language.Hom @[inherit_doc] scoped[FirstOrder] notation:25 A " →[" L "] " B => FirstOrder.Language.Hom L A B /-- An embedding of first-order structures is an embedding that commutes with the interpretations of functions and relations. -/ structure Embedding extends M ↪ N where map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial #align first_order.language.embedding FirstOrder.Language.Embedding @[inherit_doc] scoped[FirstOrder] notation:25 A " ↪[" L "] " B => FirstOrder.Language.Embedding L A B /-- An equivalence of first-order structures is an equivalence that commutes with the interpretations of functions and relations. -/ structure Equiv extends M ≃ N where map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial #align first_order.language.equiv FirstOrder.Language.Equiv @[inherit_doc] scoped[FirstOrder] notation:25 A " ≃[" L "] " B => FirstOrder.Language.Equiv L A B -- Porting note: was [L.Structure P] and [L.Structure Q] -- The former reported an error. variable {L M N} {P : Type*} [Structure L P] {Q : Type*} [Structure L Q] -- Porting note (#11445): new definition /-- Interpretation of a constant symbol -/ @[coe] def constantMap (c : L.Constants) : M := funMap c default instance : CoeTC L.Constants M := ⟨constantMap⟩ theorem funMap_eq_coe_constants {c : L.Constants} {x : Fin 0 → M} : funMap c x = c := congr rfl (funext finZeroElim) #align first_order.language.fun_map_eq_coe_constants FirstOrder.Language.funMap_eq_coe_constants /-- Given a language with a nonempty type of constants, any structure will be nonempty. This cannot be a global instance, because `L` becomes a metavariable. -/ theorem nonempty_of_nonempty_constants [h : Nonempty L.Constants] : Nonempty M := h.map (↑) #align first_order.language.nonempty_of_nonempty_constants FirstOrder.Language.nonempty_of_nonempty_constants /-- The function map for `FirstOrder.Language.Structure₂`. -/ def funMap₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} (c' : c → M) (f₁' : f₁ → M → M) (f₂' : f₂ → M → M → M) : ∀ {n}, (Language.mk₂ c f₁ f₂ r₁ r₂).Functions n → (Fin n → M) → M | 0, f, _ => c' f | 1, f, x => f₁' f (x 0) | 2, f, x => f₂' f (x 0) (x 1) | _ + 3, f, _ => PEmpty.elim f #align first_order.language.fun_map₂ FirstOrder.Language.funMap₂ /-- The relation map for `FirstOrder.Language.Structure₂`. -/ def RelMap₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} (r₁' : r₁ → Set M) (r₂' : r₂ → M → M → Prop) : ∀ {n}, (Language.mk₂ c f₁ f₂ r₁ r₂).Relations n → (Fin n → M) → Prop | 0, r, _ => PEmpty.elim r | 1, r, x => x 0 ∈ r₁' r | 2, r, x => r₂' r (x 0) (x 1) | _ + 3, r, _ => PEmpty.elim r #align first_order.language.rel_map₂ FirstOrder.Language.RelMap₂ /-- A structure constructor to match `FirstOrder.Language₂`. -/ protected def Structure.mk₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} (c' : c → M) (f₁' : f₁ → M → M) (f₂' : f₂ → M → M → M) (r₁' : r₁ → Set M) (r₂' : r₂ → M → M → Prop) : (Language.mk₂ c f₁ f₂ r₁ r₂).Structure M := ⟨funMap₂ c' f₁' f₂', RelMap₂ r₁' r₂'⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Structure.mk₂ FirstOrder.Language.Structure.mk₂ namespace Structure variable {c f₁ f₂ : Type u} {r₁ r₂ : Type v} variable {c' : c → M} {f₁' : f₁ → M → M} {f₂' : f₂ → M → M → M} variable {r₁' : r₁ → Set M} {r₂' : r₂ → M → M → Prop} @[simp] theorem funMap_apply₀ (c₀ : c) {x : Fin 0 → M} : @Structure.funMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 0 c₀ x = c' c₀ := rfl set_option linter.uppercaseLean3 false in #align first_order.language.Structure.fun_map_apply₀ FirstOrder.Language.Structure.funMap_apply₀ @[simp] theorem funMap_apply₁ (f : f₁) (x : M) : @Structure.funMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 1 f ![x] = f₁' f x := rfl set_option linter.uppercaseLean3 false in #align first_order.language.Structure.fun_map_apply₁ FirstOrder.Language.Structure.funMap_apply₁ @[simp] theorem funMap_apply₂ (f : f₂) (x y : M) : @Structure.funMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 2 f ![x, y] = f₂' f x y := rfl set_option linter.uppercaseLean3 false in #align first_order.language.Structure.fun_map_apply₂ FirstOrder.Language.Structure.funMap_apply₂ @[simp] theorem relMap_apply₁ (r : r₁) (x : M) : @Structure.RelMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 1 r ![x] = (x ∈ r₁' r) := rfl set_option linter.uppercaseLean3 false in #align first_order.language.Structure.rel_map_apply₁ FirstOrder.Language.Structure.relMap_apply₁ @[simp] theorem relMap_apply₂ (r : r₂) (x y : M) : @Structure.RelMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 2 r ![x, y] = r₂' r x y := rfl set_option linter.uppercaseLean3 false in #align first_order.language.Structure.rel_map_apply₂ FirstOrder.Language.Structure.relMap_apply₂ end Structure /-- `HomClass L F M N` states that `F` is a type of `L`-homomorphisms. You should extend this typeclass when you extend `FirstOrder.Language.Hom`. -/ class HomClass (L : outParam Language) (F M N : Type*) [FunLike F M N] [L.Structure M] [L.Structure N] : Prop where map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x) map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r x → RelMap r (φ ∘ x) #align first_order.language.hom_class FirstOrder.Language.HomClass /-- `StrongHomClass L F M N` states that `F` is a type of `L`-homomorphisms which preserve relations in both directions. -/ class StrongHomClass (L : outParam Language) (F M N : Type*) [FunLike F M N] [L.Structure M] [L.Structure N] : Prop where map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x) map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r (φ ∘ x) ↔ RelMap r x #align first_order.language.strong_hom_class FirstOrder.Language.StrongHomClass -- Porting note: using implicit brackets for `Structure` arguments instance (priority := 100) StrongHomClass.homClass [L.Structure M] [L.Structure N] [FunLike F M N] [StrongHomClass L F M N] : HomClass L F M N where map_fun := StrongHomClass.map_fun map_rel φ _ R x := (StrongHomClass.map_rel φ R x).2 #align first_order.language.strong_hom_class.hom_class FirstOrder.Language.StrongHomClass.homClass /-- Not an instance to avoid a loop. -/ theorem HomClass.strongHomClassOfIsAlgebraic [L.IsAlgebraic] {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] : StrongHomClass L F M N where map_fun := HomClass.map_fun map_rel _ n R _ := (IsAlgebraic.empty_relations n).elim R #align first_order.language.hom_class.strong_hom_class_of_is_algebraic FirstOrder.Language.HomClass.strongHomClassOfIsAlgebraic theorem HomClass.map_constants {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] (φ : F) (c : L.Constants) : φ c = c := (HomClass.map_fun φ c default).trans (congr rfl (funext default)) #align first_order.language.hom_class.map_constants FirstOrder.Language.HomClass.map_constants attribute [inherit_doc FirstOrder.Language.Hom.map_fun'] FirstOrder.Language.Embedding.map_fun' FirstOrder.Language.HomClass.map_fun FirstOrder.Language.StrongHomClass.map_fun FirstOrder.Language.Equiv.map_fun' attribute [inherit_doc FirstOrder.Language.Hom.map_rel'] FirstOrder.Language.Embedding.map_rel' FirstOrder.Language.HomClass.map_rel FirstOrder.Language.StrongHomClass.map_rel FirstOrder.Language.Equiv.map_rel' namespace Hom instance instFunLike : FunLike (M →[L] N) M N where coe := Hom.toFun coe_injective' f g h := by cases f; cases g; cases h; rfl #align first_order.language.hom.fun_like FirstOrder.Language.Hom.instFunLike instance homClass : HomClass L (M →[L] N) M N where map_fun := map_fun' map_rel := map_rel' #align first_order.language.hom.hom_class FirstOrder.Language.Hom.homClass instance [L.IsAlgebraic] : StrongHomClass L (M →[L] N) M N := HomClass.strongHomClassOfIsAlgebraic instance hasCoeToFun : CoeFun (M →[L] N) fun _ => M → N := DFunLike.hasCoeToFun #align first_order.language.hom.has_coe_to_fun FirstOrder.Language.Hom.hasCoeToFun @[simp] theorem toFun_eq_coe {f : M →[L] N} : f.toFun = (f : M → N) := rfl #align first_order.language.hom.to_fun_eq_coe FirstOrder.Language.Hom.toFun_eq_coe @[ext] theorem ext ⦃f g : M →[L] N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align first_order.language.hom.ext FirstOrder.Language.Hom.ext theorem ext_iff {f g : M →[L] N} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align first_order.language.hom.ext_iff FirstOrder.Language.Hom.ext_iff @[simp] theorem map_fun (φ : M →[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x #align first_order.language.hom.map_fun FirstOrder.Language.Hom.map_fun @[simp] theorem map_constants (φ : M →[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c #align first_order.language.hom.map_constants FirstOrder.Language.Hom.map_constants @[simp] theorem map_rel (φ : M →[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r x → RelMap r (φ ∘ x) := HomClass.map_rel φ r x #align first_order.language.hom.map_rel FirstOrder.Language.Hom.map_rel variable (L) (M) /-- The identity map from a structure to itself. -/ @[refl] def id : M →[L] M where toFun m := m #align first_order.language.hom.id FirstOrder.Language.Hom.id variable {L} {M} instance : Inhabited (M →[L] M) := ⟨id L M⟩ @[simp] theorem id_apply (x : M) : id L M x = x := rfl #align first_order.language.hom.id_apply FirstOrder.Language.Hom.id_apply /-- Composition of first-order homomorphisms. -/ @[trans] def comp (hnp : N →[L] P) (hmn : M →[L] N) : M →[L] P where toFun := hnp ∘ hmn -- Porting note: should be done by autoparam? map_fun' _ _ := by simp; rfl -- Porting note: should be done by autoparam? map_rel' _ _ h := map_rel _ _ _ (map_rel _ _ _ h) #align first_order.language.hom.comp FirstOrder.Language.Hom.comp @[simp] theorem comp_apply (g : N →[L] P) (f : M →[L] N) (x : M) : g.comp f x = g (f x) := rfl #align first_order.language.hom.comp_apply FirstOrder.Language.Hom.comp_apply /-- Composition of first-order homomorphisms is associative. -/ theorem comp_assoc (f : M →[L] N) (g : N →[L] P) (h : P →[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align first_order.language.hom.comp_assoc FirstOrder.Language.Hom.comp_assoc @[simp] theorem comp_id (f : M →[L] N) : f.comp (id L M) = f := rfl @[simp] theorem id_comp (f : M →[L] N) : (id L N).comp f = f := rfl end Hom /-- Any element of a `HomClass` can be realized as a first_order homomorphism. -/ def HomClass.toHom {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] : F → M →[L] N := fun φ => ⟨φ, HomClass.map_fun φ, HomClass.map_rel φ⟩ #align first_order.language.hom_class.to_hom FirstOrder.Language.HomClass.toHom namespace Embedding instance funLike : FunLike (M ↪[L] N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g congr ext x exact Function.funext_iff.1 h x instance embeddingLike : EmbeddingLike (M ↪[L] N) M N where injective' f := f.toEmbedding.injective #align first_order.language.embedding.embedding_like FirstOrder.Language.Embedding.embeddingLike instance strongHomClass : StrongHomClass L (M ↪[L] N) M N where map_fun := map_fun' map_rel := map_rel' #align first_order.language.embedding.strong_hom_class FirstOrder.Language.Embedding.strongHomClass #noalign first_order.language.embedding.has_coe_to_fun -- Porting note: replaced by funLike instance @[simp] theorem map_fun (φ : M ↪[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x #align first_order.language.embedding.map_fun FirstOrder.Language.Embedding.map_fun @[simp] theorem map_constants (φ : M ↪[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c #align first_order.language.embedding.map_constants FirstOrder.Language.Embedding.map_constants @[simp] theorem map_rel (φ : M ↪[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r (φ ∘ x) ↔ RelMap r x := StrongHomClass.map_rel φ r x #align first_order.language.embedding.map_rel FirstOrder.Language.Embedding.map_rel /-- A first-order embedding is also a first-order homomorphism. -/ def toHom : (M ↪[L] N) → M →[L] N := HomClass.toHom #align first_order.language.embedding.to_hom FirstOrder.Language.Embedding.toHom @[simp] theorem coe_toHom {f : M ↪[L] N} : (f.toHom : M → N) = f := rfl #align first_order.language.embedding.coe_to_hom FirstOrder.Language.Embedding.coe_toHom theorem coe_injective : @Function.Injective (M ↪[L] N) (M → N) (↑) | f, g, h => by cases f cases g congr ext x exact Function.funext_iff.1 h x #align first_order.language.embedding.coe_injective FirstOrder.Language.Embedding.coe_injective @[ext] theorem ext ⦃f g : M ↪[L] N⦄ (h : ∀ x, f x = g x) : f = g := coe_injective (funext h) #align first_order.language.embedding.ext FirstOrder.Language.Embedding.ext theorem ext_iff {f g : M ↪[L] N} : f = g ↔ ∀ x, f x = g x := ⟨fun h _ => h ▸ rfl, fun h => ext h⟩ #align first_order.language.embedding.ext_iff FirstOrder.Language.Embedding.ext_iff theorem toHom_injective : @Function.Injective (M ↪[L] N) (M →[L] N) (·.toHom) := by intro f f' h ext exact congr_fun (congr_arg (↑) h) _ @[simp] theorem toHom_inj {f g : M ↪[L] N} : f.toHom = g.toHom ↔ f = g := ⟨fun h ↦ toHom_injective h, fun h ↦ congr_arg (·.toHom) h⟩ theorem injective (f : M ↪[L] N) : Function.Injective f := f.toEmbedding.injective #align first_order.language.embedding.injective FirstOrder.Language.Embedding.injective /-- In an algebraic language, any injective homomorphism is an embedding. -/ @[simps!] def ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : M ↪[L] N := { f with inj' := hf map_rel' := fun {_} r x => StrongHomClass.map_rel f r x } #align first_order.language.embedding.of_injective FirstOrder.Language.Embedding.ofInjective @[simp] theorem coeFn_ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : (ofInjective hf : M → N) = f := rfl #align first_order.language.embedding.coe_fn_of_injective FirstOrder.Language.Embedding.coeFn_ofInjective @[simp] theorem ofInjective_toHom [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : (ofInjective hf).toHom = f := by ext; simp #align first_order.language.embedding.of_injective_to_hom FirstOrder.Language.Embedding.ofInjective_toHom variable (L) (M) /-- The identity embedding from a structure to itself. -/ @[refl] def refl : M ↪[L] M where toEmbedding := Function.Embedding.refl M #align first_order.language.embedding.refl FirstOrder.Language.Embedding.refl variable {L} {M} instance : Inhabited (M ↪[L] M) := ⟨refl L M⟩ @[simp] theorem refl_apply (x : M) : refl L M x = x := rfl #align first_order.language.embedding.refl_apply FirstOrder.Language.Embedding.refl_apply /-- Composition of first-order embeddings. -/ @[trans] def comp (hnp : N ↪[L] P) (hmn : M ↪[L] N) : M ↪[L] P where toFun := hnp ∘ hmn inj' := hnp.injective.comp hmn.injective -- Porting note: should be done by autoparam? map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial -- Porting note: should be done by autoparam? map_rel' := by intros; rw [Function.comp.assoc, map_rel, map_rel] #align first_order.language.embedding.comp FirstOrder.Language.Embedding.comp @[simp] theorem comp_apply (g : N ↪[L] P) (f : M ↪[L] N) (x : M) : g.comp f x = g (f x) := rfl #align first_order.language.embedding.comp_apply FirstOrder.Language.Embedding.comp_apply /-- Composition of first-order embeddings is associative. -/ theorem comp_assoc (f : M ↪[L] N) (g : N ↪[L] P) (h : P ↪[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align first_order.language.embedding.comp_assoc FirstOrder.Language.Embedding.comp_assoc theorem comp_injective (h : N ↪[L] P) : Function.Injective (h.comp : (M ↪[L] N) → (M ↪[L] P)) := by intro f g hfg ext x; exact h.injective (DFunLike.congr_fun hfg x) @[simp] theorem comp_inj (h : N ↪[L] P) (f g : M ↪[L] N) : h.comp f = h.comp g ↔ f = g := ⟨fun eq ↦ h.comp_injective eq, congr_arg h.comp⟩ theorem toHom_comp_injective (h : N ↪[L] P) : Function.Injective (h.toHom.comp : (M →[L] N) → (M →[L] P)) := by intro f g hfg ext x; exact h.injective (DFunLike.congr_fun hfg x) @[simp] theorem toHom_comp_inj (h : N ↪[L] P) (f g : M →[L] N) : h.toHom.comp f = h.toHom.comp g ↔ f = g := ⟨fun eq ↦ h.toHom_comp_injective eq, congr_arg h.toHom.comp⟩ @[simp] theorem comp_toHom (hnp : N ↪[L] P) (hmn : M ↪[L] N) : (hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom := rfl #align first_order.language.embedding.comp_to_hom FirstOrder.Language.Embedding.comp_toHom @[simp] theorem comp_refl (f : M ↪[L] N) : f.comp (refl L M) = f := DFunLike.coe_injective rfl @[simp] theorem refl_comp (f : M ↪[L] N) : (refl L N).comp f = f := DFunLike.coe_injective rfl @[simp] theorem refl_toHom : (refl L M).toHom = Hom.id L M := rfl end Embedding /-- Any element of an injective `StrongHomClass` can be realized as a first_order embedding. -/ def StrongHomClass.toEmbedding {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [EmbeddingLike F M N] [StrongHomClass L F M N] : F → M ↪[L] N := fun φ => ⟨⟨φ, EmbeddingLike.injective φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩ #align first_order.language.strong_hom_class.to_embedding FirstOrder.Language.StrongHomClass.toEmbedding namespace Equiv instance : EquivLike (M ≃[L] N) M N where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by cases f cases g simp only [mk.injEq] ext x exact Function.funext_iff.1 h₁ x instance : StrongHomClass L (M ≃[L] N) M N where map_fun := map_fun' map_rel := map_rel' /-- The inverse of a first-order equivalence is a first-order equivalence. -/ @[symm] def symm (f : M ≃[L] N) : N ≃[L] M := { f.toEquiv.symm with map_fun' := fun n f' {x} => by simp only [Equiv.toFun_as_coe] rw [Equiv.symm_apply_eq] refine Eq.trans ?_ (f.map_fun' f' (f.toEquiv.symm ∘ x)).symm rw [← Function.comp.assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] map_rel' := fun n r {x} => by simp only [Equiv.toFun_as_coe] refine (f.map_rel' r (f.toEquiv.symm ∘ x)).symm.trans ?_ rw [← Function.comp.assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] } #align first_order.language.equiv.symm FirstOrder.Language.Equiv.symm instance hasCoeToFun : CoeFun (M ≃[L] N) fun _ => M → N := DFunLike.hasCoeToFun #align first_order.language.equiv.has_coe_to_fun FirstOrder.Language.Equiv.hasCoeToFun @[simp] theorem symm_symm (f : M ≃[L] N) : f.symm.symm = f := rfl @[simp] theorem apply_symm_apply (f : M ≃[L] N) (a : N) : f (f.symm a) = a := f.toEquiv.apply_symm_apply a #align first_order.language.equiv.apply_symm_apply FirstOrder.Language.Equiv.apply_symm_apply @[simp] theorem symm_apply_apply (f : M ≃[L] N) (a : M) : f.symm (f a) = a := f.toEquiv.symm_apply_apply a #align first_order.language.equiv.symm_apply_apply FirstOrder.Language.Equiv.symm_apply_apply @[simp] theorem map_fun (φ : M ≃[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x #align first_order.language.equiv.map_fun FirstOrder.Language.Equiv.map_fun @[simp] theorem map_constants (φ : M ≃[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c #align first_order.language.equiv.map_constants FirstOrder.Language.Equiv.map_constants @[simp] theorem map_rel (φ : M ≃[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r (φ ∘ x) ↔ RelMap r x := StrongHomClass.map_rel φ r x #align first_order.language.equiv.map_rel FirstOrder.Language.Equiv.map_rel /-- A first-order equivalence is also a first-order embedding. -/ def toEmbedding : (M ≃[L] N) → M ↪[L] N := StrongHomClass.toEmbedding #align first_order.language.equiv.to_embedding FirstOrder.Language.Equiv.toEmbedding /-- A first-order equivalence is also a first-order homomorphism. -/ def toHom : (M ≃[L] N) → M →[L] N := HomClass.toHom #align first_order.language.equiv.to_hom FirstOrder.Language.Equiv.toHom @[simp] theorem toEmbedding_toHom (f : M ≃[L] N) : f.toEmbedding.toHom = f.toHom := rfl #align first_order.language.equiv.to_embedding_to_hom FirstOrder.Language.Equiv.toEmbedding_toHom @[simp] theorem coe_toHom {f : M ≃[L] N} : (f.toHom : M → N) = (f : M → N) := rfl #align first_order.language.equiv.coe_to_hom FirstOrder.Language.Equiv.coe_toHom @[simp] theorem coe_toEmbedding (f : M ≃[L] N) : (f.toEmbedding : M → N) = (f : M → N) := rfl #align first_order.language.equiv.coe_to_embedding FirstOrder.Language.Equiv.coe_toEmbedding theorem injective_toEmbedding : Function.Injective (toEmbedding : (M ≃[L] N) → M ↪[L] N) := by intro _ _ h; apply DFunLike.coe_injective; exact congr_arg (DFunLike.coe ∘ Embedding.toHom) h theorem coe_injective : @Function.Injective (M ≃[L] N) (M → N) (↑) := DFunLike.coe_injective #align first_order.language.equiv.coe_injective FirstOrder.Language.Equiv.coe_injective @[ext] theorem ext ⦃f g : M ≃[L] N⦄ (h : ∀ x, f x = g x) : f = g := coe_injective (funext h) #align first_order.language.equiv.ext FirstOrder.Language.Equiv.ext theorem ext_iff {f g : M ≃[L] N} : f = g ↔ ∀ x, f x = g x := ⟨fun h _ => h ▸ rfl, fun h => ext h⟩ #align first_order.language.equiv.ext_iff FirstOrder.Language.Equiv.ext_iff theorem bijective (f : M ≃[L] N) : Function.Bijective f := EquivLike.bijective f #align first_order.language.equiv.bijective FirstOrder.Language.Equiv.bijective theorem injective (f : M ≃[L] N) : Function.Injective f := EquivLike.injective f #align first_order.language.equiv.injective FirstOrder.Language.Equiv.injective theorem surjective (f : M ≃[L] N) : Function.Surjective f := EquivLike.surjective f #align first_order.language.equiv.surjective FirstOrder.Language.Equiv.surjective variable (L) (M) /-- The identity equivalence from a structure to itself. -/ @[refl] def refl : M ≃[L] M where toEquiv := _root_.Equiv.refl M #align first_order.language.equiv.refl FirstOrder.Language.Equiv.refl variable {L} {M} instance : Inhabited (M ≃[L] M) := ⟨refl L M⟩ @[simp] theorem refl_apply (x : M) : refl L M x = x := by simp [refl]; rfl #align first_order.language.equiv.refl_apply FirstOrder.Language.Equiv.refl_apply /-- Composition of first-order equivalences. -/ @[trans] def comp (hnp : N ≃[L] P) (hmn : M ≃[L] N) : M ≃[L] P := { hmn.toEquiv.trans hnp.toEquiv with toFun := hnp ∘ hmn -- Porting note: should be done by autoparam? map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial -- Porting note: should be done by autoparam? map_rel' := by intros; rw [Function.comp.assoc, map_rel, map_rel] } #align first_order.language.equiv.comp FirstOrder.Language.Equiv.comp @[simp] theorem comp_apply (g : N ≃[L] P) (f : M ≃[L] N) (x : M) : g.comp f x = g (f x) := rfl #align first_order.language.equiv.comp_apply FirstOrder.Language.Equiv.comp_apply @[simp] theorem comp_refl (g : M ≃[L] N) : g.comp (refl L M) = g := rfl @[simp] theorem refl_comp (g : M ≃[L] N) : (refl L N).comp g = g := rfl @[simp] theorem refl_toEmbedding : (refl L M).toEmbedding = Embedding.refl L M := rfl @[simp] theorem refl_toHom : (refl L M).toHom = Hom.id L M := rfl /-- Composition of first-order homomorphisms is associative. -/ theorem comp_assoc (f : M ≃[L] N) (g : N ≃[L] P) (h : P ≃[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align first_order.language.equiv.comp_assoc FirstOrder.Language.Equiv.comp_assoc theorem injective_comp (h : N ≃[L] P) : Function.Injective (h.comp : (M ≃[L] N) → (M ≃[L] P)) := by intro f g hfg ext x; exact h.injective (congr_fun (congr_arg DFunLike.coe hfg) x) @[simp] theorem comp_toHom (hnp : N ≃[L] P) (hmn : M ≃[L] N) : (hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom := rfl @[simp] theorem comp_toEmbedding (hnp : N ≃[L] P) (hmn : M ≃[L] N) : (hnp.comp hmn).toEmbedding = hnp.toEmbedding.comp hmn.toEmbedding := rfl @[simp] theorem self_comp_symm (f : M ≃[L] N) : f.comp f.symm = refl L N := by ext; rw [comp_apply, apply_symm_apply, refl_apply] @[simp] theorem symm_comp_self (f : M ≃[L] N) : f.symm.comp f = refl L M := by ext; rw [comp_apply, symm_apply_apply, refl_apply] @[simp] theorem symm_comp_self_toEmbedding (f : M ≃[L] N) : f.symm.toEmbedding.comp f.toEmbedding = Embedding.refl L M := by rw [← comp_toEmbedding, symm_comp_self, refl_toEmbedding] @[simp] theorem self_comp_symm_toEmbedding (f : M ≃[L] N) : f.toEmbedding.comp f.symm.toEmbedding = Embedding.refl L N := by rw [← comp_toEmbedding, self_comp_symm, refl_toEmbedding] @[simp] theorem symm_comp_self_toHom (f : M ≃[L] N) : f.symm.toHom.comp f.toHom = Hom.id L M := by rw [← comp_toHom, symm_comp_self, refl_toHom] @[simp]
Mathlib/ModelTheory/Basic.lean
999
1,001
theorem self_comp_symm_toHom (f : M ≃[L] N) : f.toHom.comp f.symm.toHom = Hom.id L N := by
rw [← comp_toHom, self_comp_symm, refl_toHom]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Data.ENat.Lattice import Mathlib.Order.OrderIsoNat import Mathlib.Tactic.TFAE #align_import order.height from "leanprover-community/mathlib"@"bf27744463e9620ca4e4ebe951fe83530ae6949b" /-! # Maximal length of chains This file contains lemmas to work with the maximal length of strictly descending finite sequences (chains) in a partial order. ## Main definition - `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`. - `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order. This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`. ## Main results - `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there exists `s.subchain` of length `n`. - `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`. - `Set.chainHeight_image`: If `f` is an order embedding, then `(f '' s).chainHeight = s.chainHeight`. - `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then `(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`. - `Set.wellFoundedGT_of_chainHeight_ne_top`: If `s` has finite height, then `>` is well-founded on `s`. - `Set.wellFoundedLT_of_chainHeight_ne_top`: If `s` has finite height, then `<` is well-founded on `s`. -/ open List hiding le_antisymm open OrderDual universe u v variable {α β : Type*} namespace Set section LT variable [LT α] [LT β] (s t : Set α) /-- The set of strictly ascending lists of `α` contained in a `Set α`. -/ def subchain : Set (List α) := { l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s } #align set.subchain Set.subchain @[simp] -- porting note: new `simp` theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩ #align set.nil_mem_subchain Set.nil_mem_subchain variable {s} {l : List α} {a : α} theorem cons_mem_subchain_iff : (a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm, and_assoc] #align set.cons_mem_subchain_iff Set.cons_mem_subchain_iff @[simp] -- Porting note (#10756): new lemma + `simp` theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff] instance : Nonempty s.subchain := ⟨⟨[], s.nil_mem_subchain⟩⟩ variable (s) /-- The maximal length of a strictly ascending sequence in a partial order. -/ noncomputable def chainHeight : ℕ∞ := ⨆ l ∈ s.subchain, length l #align set.chain_height Set.chainHeight theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length := iSup_subtype' #align set.chain_height_eq_supr_subtype Set.chainHeight_eq_iSup_subtype theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) : ∃ l ∈ s.subchain, length l = n := by rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;> rw [chainHeight_eq_iSup_subtype] at ha · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ := not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take n).trans <| min_eq_left <| le_of_not_ge h₃⟩ · rw [ENat.iSup_coe_lt_top] at ha obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha refine ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take n).trans <| min_eq_left <| ?_⟩ rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype] #align set.exists_chain_of_le_chain_height Set.exists_chain_of_le_chainHeight theorem le_chainHeight_TFAE (n : ℕ) : TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩ tfae_have 3 → 1; · rintro ⟨l, hs, hn⟩; exact le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn) tfae_finish #align set.le_chain_height_tfae Set.le_chainHeight_TFAE variable {s t} theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n := (le_chainHeight_TFAE s n).out 0 1 #align set.le_chain_height_iff Set.le_chainHeight_iff theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight := le_chainHeight_iff.mpr ⟨l, hl, rfl⟩ #align set.length_le_chain_height_of_mem_subchain Set.length_le_chainHeight_of_mem_subchain theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩ contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <| (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩ #align set.chain_height_eq_top_iff Set.chainHeight_eq_top_iff @[simp] theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by rw [← Nat.cast_one, Set.le_chainHeight_iff] simp only [length_eq_one, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and, singleton_mem_subchain_iff, Set.Nonempty] #align set.one_le_chain_height_iff Set.one_le_chainHeight_iff @[simp] theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff, nonempty_iff_ne_empty] #align set.chain_height_eq_zero_iff Set.chainHeight_eq_zero_iff @[simp] theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 := chainHeight_eq_zero_iff.2 rfl #align set.chain_height_empty Set.chainHeight_empty @[simp] theorem chainHeight_of_isEmpty [IsEmpty α] : s.chainHeight = 0 := chainHeight_eq_zero_iff.mpr (Subsingleton.elim _ _) #align set.chain_height_of_is_empty Set.chainHeight_of_isEmpty theorem le_chainHeight_add_nat_iff {n m : ℕ} : ↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2] #align set.le_chain_height_add_nat_iff Set.le_chainHeight_add_nat_iff theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) : s.chainHeight + n ≤ t.chainHeight + m ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by refine ⟨fun e l h ↦ le_chainHeight_add_nat_iff.1 ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e), fun H ↦ ?_⟩ by_cases h : s.chainHeight = ⊤ · suffices t.chainHeight = ⊤ by rw [this, top_add] exact le_top rw [chainHeight_eq_top_iff] at h ⊢ intro k have := (le_chainHeight_TFAE t k).out 1 2 rw [this] obtain ⟨l, hs, hl⟩ := h (k + m) obtain ⟨l', ht, hl'⟩ := H l hs exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩ · obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le rw [← hk, ← hl] exact le_chainHeight_add_nat_iff.2 (H l hs) #align set.chain_height_add_le_chain_height_add Set.chainHeight_add_le_chainHeight_add theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) : TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l', ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by tfae_have 1 ↔ 3 · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero tfae_have 2 ↔ 3 · refine forall₂_congr fun l hl ↦ ?_ simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm] tfae_finish #align set.chain_height_le_chain_height_tfae Set.chainHeight_le_chainHeight_TFAE theorem chainHeight_le_chainHeight_iff {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 1 #align set.chain_height_le_chain_height_iff Set.chainHeight_le_chainHeight_iff theorem chainHeight_le_chainHeight_iff_le {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 2 #align set.chain_height_le_chain_height_iff_le Set.chainHeight_le_chainHeight_iff_le theorem chainHeight_mono (h : s ⊆ t) : s.chainHeight ≤ t.chainHeight := chainHeight_le_chainHeight_iff.2 fun l hl ↦ ⟨l, ⟨hl.1, fun i hi ↦ h <| hl.2 i hi⟩, rfl⟩ #align set.chain_height_mono Set.chainHeight_mono theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) : (f '' s).chainHeight = s.chainHeight := by apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff] · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by intro l hl obtain ⟨l', h₁, rfl⟩ := this l hl exact ⟨l', h₁, length_map _ _⟩ intro l induction' l with x xs hx · exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩ · intro h rw [cons_mem_subchain_iff] at h obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h obtain ⟨l', h₃, rfl⟩ := hx h₁ refine ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, ?_⟩, rfl⟩ cases l' · simp · simpa [← hf] using h₂ · intro l hl refine ⟨l.map f, ⟨?_, ?_⟩, ?_⟩ · simp_rw [chain'_map, ← hf] exact hl.1 · intro _ e obtain ⟨a, ha, rfl⟩ := mem_map.mp e exact Set.mem_image_of_mem _ (hl.2 _ ha) · rw [length_map] #align set.chain_height_image Set.chainHeight_image variable (s) @[simp] theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by apply le_antisymm <;> · rw [chainHeight_le_chainHeight_iff] rintro l ⟨h₁, h₂⟩ exact ⟨l.reverse, ⟨chain'_reverse.mpr h₁, fun i h ↦ h₂ i (mem_reverse.mp h)⟩, (length_reverse _).symm⟩ #align set.chain_height_dual Set.chainHeight_dual end LT section Preorder variable (s t : Set α) [Preorder α] theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by apply le_antisymm · refine iSup₂_le ?_ rintro (_ | ⟨x, xs⟩) h · exact zero_le _ · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1) apply length_le_chainHeight_of_mem_subchain refine ⟨h.1, fun i hi ↦ ⟨h.2 i hi, ?_⟩⟩ cases hi · exact left_mem_Ici rename_i hi cases' chain'_iff_pairwise.mp h.1 with _ _ h' exact (h' _ hi).le · exact iSup₂_le fun i _ ↦ chainHeight_mono Set.inter_subset_left #align set.chain_height_eq_supr_Ici Set.chainHeight_eq_iSup_Ici theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by simp_rw [← chainHeight_dual (_ ∩ _)] rw [← chainHeight_dual, chainHeight_eq_iSup_Ici] rfl #align set.chain_height_eq_supr_Iic Set.chainHeight_eq_iSup_Iic variable {s t} theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) : (insert a s).chainHeight = s.chainHeight + 1 := by rw [← add_zero (insert a s).chainHeight] change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ) apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add] · rintro (_ | ⟨y, ys⟩) h · exact ⟨[], nil_mem_subchain _, zero_le _⟩ · have h' := cons_mem_subchain_iff.mp h refine ⟨ys, ⟨h'.2.1.1, fun i hi ↦ ?_⟩, by simp⟩ apply (h'.2.1.2 i hi).resolve_left rintro rfl cases' chain'_iff_pairwise.mp h.1 with _ _ hy cases' h'.1 with h' h' exacts [(hy _ hi).ne h', not_le_of_gt (hy _ hi) (hx _ h').le] · intro l hl refine ⟨a::l, ⟨?_, ?_⟩, by simp⟩ · rw [chain'_cons'] exact ⟨fun y hy ↦ hx _ (hl.2 _ (mem_of_mem_head? hy)), hl.1⟩ · -- Porting note: originally this was -- rintro x (rfl | hx) -- exacts [Or.inl (Set.mem_singleton x), Or.inr (hl.2 x hx)] -- but this fails because `List.Mem` is now an inductive prop. -- I couldn't work out how to drive `rcases` here but asked at -- https://leanprover.zulipchat.com/#narrow/stream/348111-std4/topic/rcases.3F/near/347976083 rintro x (_ | _) exacts [Or.inl (Set.mem_singleton a), Or.inr (hl.2 x ‹_›)] #align set.chain_height_insert_of_forall_gt Set.chainHeight_insert_of_forall_gt theorem chainHeight_insert_of_forall_lt (a : α) (ha : ∀ b ∈ s, b < a) : (insert a s).chainHeight = s.chainHeight + 1 := by rw [← chainHeight_dual, ← chainHeight_dual s] exact chainHeight_insert_of_forall_gt _ ha #align set.chain_height_insert_of_forall_lt Set.chainHeight_insert_of_forall_lt theorem chainHeight_union_le : (s ∪ t).chainHeight ≤ s.chainHeight + t.chainHeight := by classical refine iSup₂_le fun l hl ↦ ?_ let l₁ := l.filter (· ∈ s) let l₂ := l.filter (· ∈ t) have hl₁ : ↑l₁.length ≤ s.chainHeight := by apply Set.length_le_chainHeight_of_mem_subchain exact ⟨hl.1.sublist (filter_sublist _), fun i h ↦ by simpa using (of_mem_filter h : _)⟩ have hl₂ : ↑l₂.length ≤ t.chainHeight := by apply Set.length_le_chainHeight_of_mem_subchain exact ⟨hl.1.sublist (filter_sublist _), fun i h ↦ by simpa using (of_mem_filter h : _)⟩ refine le_trans ?_ (add_le_add hl₁ hl₂) simp_rw [l₁, l₂, ← Nat.cast_add, ← Multiset.coe_card, ← Multiset.card_add, ← Multiset.filter_coe] rw [Multiset.filter_add_filter, Multiset.filter_eq_self.mpr, Multiset.card_add, Nat.cast_add] exacts [le_add_right rfl.le, hl.2] #align set.chain_height_union_le Set.chainHeight_union_le
Mathlib/Order/Height.lean
333
349
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) : (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
cases h : t.chainHeight · rw [add_top, eq_top_iff, ← h] exact Set.chainHeight_mono subset_union_right apply le_antisymm · rw [← h] exact chainHeight_union_le rw [← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero, ENat.some_eq_coe, chainHeight_add_le_chainHeight_add] intro l hl obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le refine ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ ?_, fun i hi ↦ ?_⟩, by simp⟩ · exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy) · rw [mem_append] at hi cases' hi with hi hi exacts [Or.inl (hl.2 _ hi), Or.inr (hl'.2 _ hi)]
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Batteries.Control.ForInStep.Lemmas import Batteries.Data.List.Basic import Batteries.Tactic.Init import Batteries.Tactic.Alias namespace List open Nat /-! ### mem -/ @[simp] theorem mem_toArray {a : α} {l : List α} : a ∈ l.toArray ↔ a ∈ l := by simp [Array.mem_def] /-! ### drop -/ @[simp] theorem drop_one : ∀ l : List α, drop 1 l = tail l | [] | _ :: _ => rfl /-! ### zipWith -/ theorem zipWith_distrib_tail : (zipWith f l l').tail = zipWith f l.tail l'.tail := by rw [← drop_one]; simp [zipWith_distrib_drop] /-! ### List subset -/ theorem subset_def {l₁ l₂ : List α} : l₁ ⊆ l₂ ↔ ∀ {a : α}, a ∈ l₁ → a ∈ l₂ := .rfl @[simp] theorem nil_subset (l : List α) : [] ⊆ l := nofun @[simp] theorem Subset.refl (l : List α) : l ⊆ l := fun _ i => i theorem Subset.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ ⊆ l₂) (h₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ := fun _ i => h₂ (h₁ i) instance : Trans (Membership.mem : α → List α → Prop) Subset Membership.mem := ⟨fun h₁ h₂ => h₂ h₁⟩ instance : Trans (Subset : List α → List α → Prop) Subset Subset := ⟨Subset.trans⟩ @[simp] theorem subset_cons (a : α) (l : List α) : l ⊆ a :: l := fun _ => Mem.tail _ theorem subset_of_cons_subset {a : α} {l₁ l₂ : List α} : a :: l₁ ⊆ l₂ → l₁ ⊆ l₂ := fun s _ i => s (mem_cons_of_mem _ i) theorem subset_cons_of_subset (a : α) {l₁ l₂ : List α} : l₁ ⊆ l₂ → l₁ ⊆ a :: l₂ := fun s _ i => .tail _ (s i) theorem cons_subset_cons {l₁ l₂ : List α} (a : α) (s : l₁ ⊆ l₂) : a :: l₁ ⊆ a :: l₂ := fun _ => by simp only [mem_cons]; exact Or.imp_right (@s _) @[simp] theorem subset_append_left (l₁ l₂ : List α) : l₁ ⊆ l₁ ++ l₂ := fun _ => mem_append_left _ @[simp] theorem subset_append_right (l₁ l₂ : List α) : l₂ ⊆ l₁ ++ l₂ := fun _ => mem_append_right _ theorem subset_append_of_subset_left (l₂ : List α) : l ⊆ l₁ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_left _ _ theorem subset_append_of_subset_right (l₁ : List α) : l ⊆ l₂ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_right _ _ @[simp] theorem cons_subset : a :: l ⊆ m ↔ a ∈ m ∧ l ⊆ m := by simp only [subset_def, mem_cons, or_imp, forall_and, forall_eq] @[simp] theorem append_subset {l₁ l₂ l : List α} : l₁ ++ l₂ ⊆ l ↔ l₁ ⊆ l ∧ l₂ ⊆ l := by simp [subset_def, or_imp, forall_and] theorem subset_nil {l : List α} : l ⊆ [] ↔ l = [] := ⟨fun h => match l with | [] => rfl | _::_ => (nomatch h (.head ..)), fun | rfl => Subset.refl _⟩ theorem map_subset {l₁ l₂ : List α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ := fun x => by simp only [mem_map]; exact .imp fun a => .imp_left (@H _) /-! ### sublists -/ @[simp] theorem nil_sublist : ∀ l : List α, [] <+ l | [] => .slnil | a :: l => (nil_sublist l).cons a @[simp] theorem Sublist.refl : ∀ l : List α, l <+ l | [] => .slnil | a :: l => (Sublist.refl l).cons₂ a theorem Sublist.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ <+ l₂) (h₂ : l₂ <+ l₃) : l₁ <+ l₃ := by induction h₂ generalizing l₁ with | slnil => exact h₁ | cons _ _ IH => exact (IH h₁).cons _ | @cons₂ l₂ _ a _ IH => generalize e : a :: l₂ = l₂' match e ▸ h₁ with | .slnil => apply nil_sublist | .cons a' h₁' => cases e; apply (IH h₁').cons | .cons₂ a' h₁' => cases e; apply (IH h₁').cons₂ instance : Trans (@Sublist α) Sublist Sublist := ⟨Sublist.trans⟩ @[simp] theorem sublist_cons (a : α) (l : List α) : l <+ a :: l := (Sublist.refl l).cons _ theorem sublist_of_cons_sublist : a :: l₁ <+ l₂ → l₁ <+ l₂ := (sublist_cons a l₁).trans @[simp] theorem sublist_append_left : ∀ l₁ l₂ : List α, l₁ <+ l₁ ++ l₂ | [], _ => nil_sublist _ | _ :: l₁, l₂ => (sublist_append_left l₁ l₂).cons₂ _ @[simp] theorem sublist_append_right : ∀ l₁ l₂ : List α, l₂ <+ l₁ ++ l₂ | [], _ => Sublist.refl _ | _ :: l₁, l₂ => (sublist_append_right l₁ l₂).cons _ theorem sublist_append_of_sublist_left (s : l <+ l₁) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_left .. theorem sublist_append_of_sublist_right (s : l <+ l₂) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_right .. @[simp] theorem cons_sublist_cons : a :: l₁ <+ a :: l₂ ↔ l₁ <+ l₂ := ⟨fun | .cons _ s => sublist_of_cons_sublist s | .cons₂ _ s => s, .cons₂ _⟩ @[simp] theorem append_sublist_append_left : ∀ l, l ++ l₁ <+ l ++ l₂ ↔ l₁ <+ l₂ | [] => Iff.rfl | _ :: l => cons_sublist_cons.trans (append_sublist_append_left l) theorem Sublist.append_left : l₁ <+ l₂ → ∀ l, l ++ l₁ <+ l ++ l₂ := fun h l => (append_sublist_append_left l).mpr h theorem Sublist.append_right : l₁ <+ l₂ → ∀ l, l₁ ++ l <+ l₂ ++ l | .slnil, _ => Sublist.refl _ | .cons _ h, _ => (h.append_right _).cons _ | .cons₂ _ h, _ => (h.append_right _).cons₂ _ theorem sublist_or_mem_of_sublist (h : l <+ l₁ ++ a :: l₂) : l <+ l₁ ++ l₂ ∨ a ∈ l := by induction l₁ generalizing l with | nil => match h with | .cons _ h => exact .inl h | .cons₂ _ h => exact .inr (.head ..) | cons b l₁ IH => match h with | .cons _ h => exact (IH h).imp_left (Sublist.cons _) | .cons₂ _ h => exact (IH h).imp (Sublist.cons₂ _) (.tail _) theorem Sublist.reverse : l₁ <+ l₂ → l₁.reverse <+ l₂.reverse | .slnil => Sublist.refl _ | .cons _ h => by rw [reverse_cons]; exact sublist_append_of_sublist_left h.reverse | .cons₂ _ h => by rw [reverse_cons, reverse_cons]; exact h.reverse.append_right _ @[simp] theorem reverse_sublist : l₁.reverse <+ l₂.reverse ↔ l₁ <+ l₂ := ⟨fun h => l₁.reverse_reverse ▸ l₂.reverse_reverse ▸ h.reverse, Sublist.reverse⟩ @[simp] theorem append_sublist_append_right (l) : l₁ ++ l <+ l₂ ++ l ↔ l₁ <+ l₂ := ⟨fun h => by have := h.reverse simp only [reverse_append, append_sublist_append_left, reverse_sublist] at this exact this, fun h => h.append_right l⟩ theorem Sublist.append (hl : l₁ <+ l₂) (hr : r₁ <+ r₂) : l₁ ++ r₁ <+ l₂ ++ r₂ := (hl.append_right _).trans ((append_sublist_append_left _).2 hr) theorem Sublist.subset : l₁ <+ l₂ → l₁ ⊆ l₂ | .slnil, _, h => h | .cons _ s, _, h => .tail _ (s.subset h) | .cons₂ .., _, .head .. => .head .. | .cons₂ _ s, _, .tail _ h => .tail _ (s.subset h) instance : Trans (@Sublist α) Subset Subset := ⟨fun h₁ h₂ => trans h₁.subset h₂⟩ instance : Trans Subset (@Sublist α) Subset := ⟨fun h₁ h₂ => trans h₁ h₂.subset⟩ instance : Trans (Membership.mem : α → List α → Prop) Sublist Membership.mem := ⟨fun h₁ h₂ => h₂.subset h₁⟩ theorem Sublist.length_le : l₁ <+ l₂ → length l₁ ≤ length l₂ | .slnil => Nat.le_refl 0 | .cons _l s => le_succ_of_le (length_le s) | .cons₂ _ s => succ_le_succ (length_le s) @[simp] theorem sublist_nil {l : List α} : l <+ [] ↔ l = [] := ⟨fun s => subset_nil.1 s.subset, fun H => H ▸ Sublist.refl _⟩ theorem Sublist.eq_of_length : l₁ <+ l₂ → length l₁ = length l₂ → l₁ = l₂ | .slnil, _ => rfl | .cons a s, h => nomatch Nat.not_lt.2 s.length_le (h ▸ lt_succ_self _) | .cons₂ a s, h => by rw [s.eq_of_length (succ.inj h)] theorem Sublist.eq_of_length_le (s : l₁ <+ l₂) (h : length l₂ ≤ length l₁) : l₁ = l₂ := s.eq_of_length <| Nat.le_antisymm s.length_le h @[simp] theorem singleton_sublist {a : α} {l} : [a] <+ l ↔ a ∈ l := by refine ⟨fun h => h.subset (mem_singleton_self _), fun h => ?_⟩ obtain ⟨_, _, rfl⟩ := append_of_mem h exact ((nil_sublist _).cons₂ _).trans (sublist_append_right ..) @[simp] theorem replicate_sublist_replicate {m n} (a : α) : replicate m a <+ replicate n a ↔ m ≤ n := by refine ⟨fun h => ?_, fun h => ?_⟩ · have := h.length_le; simp only [length_replicate] at this ⊢; exact this · induction h with | refl => apply Sublist.refl | step => simp [*, replicate, Sublist.cons] theorem isSublist_iff_sublist [BEq α] [LawfulBEq α] {l₁ l₂ : List α} : l₁.isSublist l₂ ↔ l₁ <+ l₂ := by cases l₁ <;> cases l₂ <;> simp [isSublist] case cons.cons hd₁ tl₁ hd₂ tl₂ => if h_eq : hd₁ = hd₂ then simp [h_eq, cons_sublist_cons, isSublist_iff_sublist] else simp only [beq_iff_eq, h_eq] constructor · intro h_sub apply Sublist.cons exact isSublist_iff_sublist.mp h_sub · intro h_sub cases h_sub case cons h_sub => exact isSublist_iff_sublist.mpr h_sub case cons₂ => contradiction instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ <+ l₂) := decidable_of_iff (l₁.isSublist l₂) isSublist_iff_sublist /-! ### tail -/ theorem tail_eq_tailD (l) : @tail α l = tailD l [] := by cases l <;> rfl theorem tail_eq_tail? (l) : @tail α l = (tail? l).getD [] := by simp [tail_eq_tailD] /-! ### next? -/ @[simp] theorem next?_nil : @next? α [] = none := rfl @[simp] theorem next?_cons (a l) : @next? α (a :: l) = some (a, l) := rfl /-! ### get? -/ theorem get_eq_iff : List.get l n = x ↔ l.get? n.1 = some x := by simp [get?_eq_some] theorem get?_inj (h₀ : i < xs.length) (h₁ : Nodup xs) (h₂ : xs.get? i = xs.get? j) : i = j := by induction xs generalizing i j with | nil => cases h₀ | cons x xs ih => match i, j with | 0, 0 => rfl | i+1, j+1 => simp; cases h₁ with | cons ha h₁ => exact ih (Nat.lt_of_succ_lt_succ h₀) h₁ h₂ | i+1, 0 => ?_ | 0, j+1 => ?_ all_goals simp at h₂ cases h₁; rename_i h' h have := h x ?_ rfl; cases this rw [mem_iff_get?] exact ⟨_, h₂⟩; exact ⟨_ , h₂.symm⟩ /-! ### drop -/ theorem tail_drop (l : List α) (n : Nat) : (l.drop n).tail = l.drop (n + 1) := by induction l generalizing n with | nil => simp | cons hd tl hl => cases n · simp · simp [hl] /-! ### modifyNth -/ @[simp] theorem modifyNth_nil (f : α → α) (n) : [].modifyNth f n = [] := by cases n <;> rfl @[simp] theorem modifyNth_zero_cons (f : α → α) (a : α) (l : List α) : (a :: l).modifyNth f 0 = f a :: l := rfl @[simp] theorem modifyNth_succ_cons (f : α → α) (a : α) (l : List α) (n) : (a :: l).modifyNth f (n + 1) = a :: l.modifyNth f n := by rfl theorem modifyNthTail_id : ∀ n (l : List α), l.modifyNthTail id n = l | 0, _ => rfl | _+1, [] => rfl | n+1, a :: l => congrArg (cons a) (modifyNthTail_id n l) theorem eraseIdx_eq_modifyNthTail : ∀ n (l : List α), eraseIdx l n = modifyNthTail tail n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, a :: l => congrArg (cons _) (eraseIdx_eq_modifyNthTail _ _) @[deprecated] alias removeNth_eq_nth_tail := eraseIdx_eq_modifyNthTail theorem get?_modifyNth (f : α → α) : ∀ n (l : List α) m, (modifyNth f n l).get? m = (fun a => if n = m then f a else a) <$> l.get? m | n, l, 0 => by cases l <;> cases n <;> rfl | n, [], _+1 => by cases n <;> rfl | 0, _ :: l, m+1 => by cases h : l.get? m <;> simp [h, modifyNth, m.succ_ne_zero.symm] | n+1, a :: l, m+1 => (get?_modifyNth f n l m).trans <| by cases h' : l.get? m <;> by_cases h : n = m <;> simp [h, if_pos, if_neg, Option.map, mt Nat.succ.inj, not_false_iff, h'] theorem modifyNthTail_length (f : List α → List α) (H : ∀ l, length (f l) = length l) : ∀ n l, length (modifyNthTail f n l) = length l | 0, _ => H _ | _+1, [] => rfl | _+1, _ :: _ => congrArg (·+1) (modifyNthTail_length _ H _ _) theorem modifyNthTail_add (f : List α → List α) (n) (l₁ l₂ : List α) : modifyNthTail f (l₁.length + n) (l₁ ++ l₂) = l₁ ++ modifyNthTail f n l₂ := by induction l₁ <;> simp [*, Nat.succ_add] theorem exists_of_modifyNthTail (f : List α → List α) {n} {l : List α} (h : n ≤ l.length) : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n ∧ modifyNthTail f n l = l₁ ++ f l₂ := have ⟨_, _, eq, hl⟩ : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n := ⟨_, _, (take_append_drop n l).symm, length_take_of_le h⟩ ⟨_, _, eq, hl, hl ▸ eq ▸ modifyNthTail_add (n := 0) ..⟩ @[simp] theorem modify_get?_length (f : α → α) : ∀ n l, length (modifyNth f n l) = length l := modifyNthTail_length _ fun l => by cases l <;> rfl @[simp] theorem get?_modifyNth_eq (f : α → α) (n) (l : List α) : (modifyNth f n l).get? n = f <$> l.get? n := by simp only [get?_modifyNth, if_pos] @[simp] theorem get?_modifyNth_ne (f : α → α) {m n} (l : List α) (h : m ≠ n) : (modifyNth f m l).get? n = l.get? n := by simp only [get?_modifyNth, if_neg h, id_map'] theorem exists_of_modifyNth (f : α → α) {n} {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ modifyNth f n l = l₁ ++ f a :: l₂ := match exists_of_modifyNthTail _ (Nat.le_of_lt h) with | ⟨_, _::_, eq, hl, H⟩ => ⟨_, _, _, eq, hl, H⟩ | ⟨_, [], eq, hl, _⟩ => nomatch Nat.ne_of_gt h (eq ▸ append_nil _ ▸ hl) theorem modifyNthTail_eq_take_drop (f : List α → List α) (H : f [] = []) : ∀ n l, modifyNthTail f n l = take n l ++ f (drop n l) | 0, _ => rfl | _ + 1, [] => H.symm | n + 1, b :: l => congrArg (cons b) (modifyNthTail_eq_take_drop f H n l) theorem modifyNth_eq_take_drop (f : α → α) : ∀ n l, modifyNth f n l = take n l ++ modifyHead f (drop n l) := modifyNthTail_eq_take_drop _ rfl theorem modifyNth_eq_take_cons_drop (f : α → α) {n l} (h) : modifyNth f n l = take n l ++ f (get l ⟨n, h⟩) :: drop (n + 1) l := by rw [modifyNth_eq_take_drop, drop_eq_get_cons h]; rfl /-! ### set -/ theorem set_eq_modifyNth (a : α) : ∀ n (l : List α), set l n a = modifyNth (fun _ => a) n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => congrArg (cons _) (set_eq_modifyNth _ _ _) theorem set_eq_take_cons_drop (a : α) {n l} (h : n < length l) : set l n a = take n l ++ a :: drop (n + 1) l := by rw [set_eq_modifyNth, modifyNth_eq_take_cons_drop _ h] theorem modifyNth_eq_set_get? (f : α → α) : ∀ n (l : List α), l.modifyNth f n = ((fun a => l.set n (f a)) <$> l.get? n).getD l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => (congrArg (cons _) (modifyNth_eq_set_get? ..)).trans <| by cases h : l.get? n <;> simp [h] theorem modifyNth_eq_set_get (f : α → α) {n} {l : List α} (h) : l.modifyNth f n = l.set n (f (l.get ⟨n, h⟩)) := by rw [modifyNth_eq_set_get?, get?_eq_get h]; rfl theorem exists_of_set {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := by rw [set_eq_modifyNth]; exact exists_of_modifyNth _ h theorem exists_of_set' {l : List α} (h : n < l.length) : ∃ l₁ l₂, l = l₁ ++ l.get ⟨n, h⟩ :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := have ⟨_, _, _, h₁, h₂, h₃⟩ := exists_of_set h; ⟨_, _, get_of_append h₁ h₂ ▸ h₁, h₂, h₃⟩ @[simp] theorem get?_set_eq (a : α) (n) (l : List α) : (set l n a).get? n = (fun _ => a) <$> l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_eq] theorem get?_set_eq_of_lt (a : α) {n} {l : List α} (h : n < length l) : (set l n a).get? n = some a := by rw [get?_set_eq, get?_eq_get h]; rfl @[simp] theorem get?_set_ne (a : α) {m n} (l : List α) (h : m ≠ n) : (set l m a).get? n = l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_ne _ _ h] theorem get?_set (a : α) {m n} (l : List α) : (set l m a).get? n = if m = n then (fun _ => a) <$> l.get? n else l.get? n := by by_cases m = n <;> simp [*, get?_set_eq, get?_set_ne] theorem get?_set_of_lt (a : α) {m n} (l : List α) (h : n < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set, get?_eq_get h] theorem get?_set_of_lt' (a : α) {m n} (l : List α) (h : m < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set]; split <;> subst_vars <;> simp [*, get?_eq_get h] theorem drop_set_of_lt (a : α) {n m : Nat} (l : List α) (h : n < m) : (l.set n a).drop m = l.drop m := List.ext fun i => by rw [get?_drop, get?_drop, get?_set_ne _ _ (by omega)] theorem take_set_of_lt (a : α) {n m : Nat} (l : List α) (h : m < n) : (l.set n a).take m = l.take m := List.ext fun i => by rw [get?_take_eq_if, get?_take_eq_if] split · next h' => rw [get?_set_ne _ _ (by omega)] · rfl /-! ### removeNth -/ theorem length_eraseIdx : ∀ {l i}, i < length l → length (@eraseIdx α l i) = length l - 1 | [], _, _ => rfl | _::_, 0, _ => by simp [eraseIdx] | x::xs, i+1, h => by have : i < length xs := Nat.lt_of_succ_lt_succ h simp [eraseIdx, ← Nat.add_one] rw [length_eraseIdx this, Nat.sub_add_cancel (Nat.lt_of_le_of_lt (Nat.zero_le _) this)] @[deprecated] alias length_removeNth := length_eraseIdx /-! ### tail -/ @[simp] theorem length_tail (l : List α) : length (tail l) = length l - 1 := by cases l <;> rfl /-! ### eraseP -/ @[simp] theorem eraseP_nil : [].eraseP p = [] := rfl theorem eraseP_cons (a : α) (l : List α) : (a :: l).eraseP p = bif p a then l else a :: l.eraseP p := rfl @[simp] theorem eraseP_cons_of_pos {l : List α} (p) (h : p a) : (a :: l).eraseP p = l := by simp [eraseP_cons, h] @[simp] theorem eraseP_cons_of_neg {l : List α} (p) (h : ¬p a) : (a :: l).eraseP p = a :: l.eraseP p := by simp [eraseP_cons, h] theorem eraseP_of_forall_not {l : List α} (h : ∀ a, a ∈ l → ¬p a) : l.eraseP p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_eraseP : ∀ {l : List α} {a} (al : a ∈ l) (pa : p a), ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ | b :: l, a, al, pa => if pb : p b then ⟨b, [], l, forall_mem_nil _, pb, by simp [pb]⟩ else match al with | .head .. => nomatch pb pa | .tail _ al => let ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_eraseP al pa ⟨c, b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_eraseP (p) (l : List α) : l.eraseP p = l ∨ ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ := if h : ∃ a ∈ l, p a then let ⟨_, ha, pa⟩ := h .inr (exists_of_eraseP ha pa) else .inl (eraseP_of_forall_not (h ⟨·, ·, ·⟩)) @[simp] theorem length_eraseP_of_mem (al : a ∈ l) (pa : p a) : length (l.eraseP p) = Nat.pred (length l) := by let ⟨_, l₁, l₂, _, _, e₁, e₂⟩ := exists_of_eraseP al pa rw [e₂]; simp [length_append, e₁]; rfl theorem eraseP_append_left {a : α} (pa : p a) : ∀ {l₁ : List α} l₂, a ∈ l₁ → (l₁++l₂).eraseP p = l₁.eraseP p ++ l₂ | x :: xs, l₂, h => by by_cases h' : p x <;> simp [h'] rw [eraseP_append_left pa l₂ ((mem_cons.1 h).resolve_left (mt _ h'))] intro | rfl => exact pa theorem eraseP_append_right : ∀ {l₁ : List α} l₂, (∀ b ∈ l₁, ¬p b) → eraseP p (l₁++l₂) = l₁ ++ l₂.eraseP p | [], l₂, _ => rfl | x :: xs, l₂, h => by simp [(forall_mem_cons.1 h).1, eraseP_append_right _ (forall_mem_cons.1 h).2] theorem eraseP_sublist (l : List α) : l.eraseP p <+ l := by match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; apply Sublist.refl | .inr ⟨c, l₁, l₂, _, _, h₃, h₄⟩ => rw [h₄, h₃]; simp theorem eraseP_subset (l : List α) : l.eraseP p ⊆ l := (eraseP_sublist l).subset protected theorem Sublist.eraseP : l₁ <+ l₂ → l₁.eraseP p <+ l₂.eraseP p | .slnil => Sublist.refl _ | .cons a s => by by_cases h : p a <;> simp [h] exacts [s.eraseP.trans (eraseP_sublist _), s.eraseP.cons _] | .cons₂ a s => by by_cases h : p a <;> simp [h] exacts [s, s.eraseP] theorem mem_of_mem_eraseP {l : List α} : a ∈ l.eraseP p → a ∈ l := (eraseP_subset _ ·) @[simp] theorem mem_eraseP_of_neg {l : List α} (pa : ¬p a) : a ∈ l.eraseP p ↔ a ∈ l := by refine ⟨mem_of_mem_eraseP, fun al => ?_⟩ match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; assumption | .inr ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ => rw [h₄]; rw [h₃] at al have : a ≠ c := fun h => (h ▸ pa).elim h₂ simp [this] at al; simp [al] theorem eraseP_map (f : β → α) : ∀ (l : List β), (map f l).eraseP p = map f (l.eraseP (p ∘ f)) | [] => rfl | b::l => by by_cases h : p (f b) <;> simp [h, eraseP_map f l, eraseP_cons_of_pos] @[simp] theorem extractP_eq_find?_eraseP (l : List α) : extractP p l = (find? p l, eraseP p l) := by let rec go (acc) : ∀ xs, l = acc.data ++ xs → extractP.go p l xs acc = (xs.find? p, acc.data ++ xs.eraseP p) | [] => fun h => by simp [extractP.go, find?, eraseP, h] | x::xs => by simp [extractP.go, find?, eraseP]; cases p x <;> simp · intro h; rw [go _ xs]; {simp}; simp [h] exact go #[] _ rfl /-! ### erase -/ section erase variable [BEq α] theorem erase_eq_eraseP' (a : α) (l : List α) : l.erase a = l.eraseP (· == a) := by induction l · simp · next b t ih => rw [erase_cons, eraseP_cons, ih] if h : b == a then simp [h] else simp [h] theorem erase_eq_eraseP [LawfulBEq α] (a : α) : ∀ l : List α, l.erase a = l.eraseP (a == ·) | [] => rfl | b :: l => by if h : a = b then simp [h] else simp [h, Ne.symm h, erase_eq_eraseP a l] theorem exists_erase_eq [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : ∃ l₁ l₂, a ∉ l₁ ∧ l = l₁ ++ a :: l₂ ∧ l.erase a = l₁ ++ l₂ := by let ⟨_, l₁, l₂, h₁, e, h₂, h₃⟩ := exists_of_eraseP h (beq_self_eq_true _) rw [erase_eq_eraseP]; exact ⟨l₁, l₂, fun h => h₁ _ h (beq_self_eq_true _), eq_of_beq e ▸ h₂, h₃⟩ @[simp] theorem length_erase_of_mem [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : length (l.erase a) = Nat.pred (length l) := by rw [erase_eq_eraseP]; exact length_eraseP_of_mem h (beq_self_eq_true a) theorem erase_append_left [LawfulBEq α] {l₁ : List α} (l₂) (h : a ∈ l₁) : (l₁ ++ l₂).erase a = l₁.erase a ++ l₂ := by simp [erase_eq_eraseP]; exact eraseP_append_left (beq_self_eq_true a) l₂ h theorem erase_append_right [LawfulBEq α] {a : α} {l₁ : List α} (l₂ : List α) (h : a ∉ l₁) : (l₁ ++ l₂).erase a = (l₁ ++ l₂.erase a) := by rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_append_right] intros b h' h''; rw [eq_of_beq h''] at h; exact h h' theorem erase_sublist (a : α) (l : List α) : l.erase a <+ l := erase_eq_eraseP' a l ▸ eraseP_sublist l theorem erase_subset (a : α) (l : List α) : l.erase a ⊆ l := (erase_sublist a l).subset theorem Sublist.erase (a : α) {l₁ l₂ : List α} (h : l₁ <+ l₂) : l₁.erase a <+ l₂.erase a := by simp only [erase_eq_eraseP']; exact h.eraseP @[deprecated] alias sublist.erase := Sublist.erase theorem mem_of_mem_erase {a b : α} {l : List α} (h : a ∈ l.erase b) : a ∈ l := erase_subset _ _ h @[simp] theorem mem_erase_of_ne [LawfulBEq α] {a b : α} {l : List α} (ab : a ≠ b) : a ∈ l.erase b ↔ a ∈ l := erase_eq_eraseP b l ▸ mem_eraseP_of_neg (mt eq_of_beq ab.symm) theorem erase_comm [LawfulBEq α] (a b : α) (l : List α) : (l.erase a).erase b = (l.erase b).erase a := by if ab : a == b then rw [eq_of_beq ab] else ?_ if ha : a ∈ l then ?_ else simp only [erase_of_not_mem ha, erase_of_not_mem (mt mem_of_mem_erase ha)] if hb : b ∈ l then ?_ else simp only [erase_of_not_mem hb, erase_of_not_mem (mt mem_of_mem_erase hb)] match l, l.erase a, exists_erase_eq ha with | _, _, ⟨l₁, l₂, ha', rfl, rfl⟩ => if h₁ : b ∈ l₁ then rw [erase_append_left _ h₁, erase_append_left _ h₁, erase_append_right _ (mt mem_of_mem_erase ha'), erase_cons_head] else rw [erase_append_right _ h₁, erase_append_right _ h₁, erase_append_right _ ha', erase_cons_tail _ ab, erase_cons_head] end erase /-! ### filter and partition -/ @[simp] theorem filter_sublist {p : α → Bool} : ∀ (l : List α), filter p l <+ l | [] => .slnil | a :: l => by rw [filter]; split <;> simp [Sublist.cons, Sublist.cons₂, filter_sublist l] /-! ### filterMap -/ theorem length_filter_le (p : α → Bool) (l : List α) : (l.filter p).length ≤ l.length := (filter_sublist _).length_le theorem length_filterMap_le (f : α → Option β) (l : List α) : (filterMap f l).length ≤ l.length := by rw [← length_map _ some, map_filterMap_some_eq_filter_map_is_some, ← length_map _ f] apply length_filter_le protected theorem Sublist.filterMap (f : α → Option β) (s : l₁ <+ l₂) : filterMap f l₁ <+ filterMap f l₂ := by induction s <;> simp <;> split <;> simp [*, cons, cons₂] theorem Sublist.filter (p : α → Bool) {l₁ l₂} (s : l₁ <+ l₂) : filter p l₁ <+ filter p l₂ := by rw [← filterMap_eq_filter]; apply s.filterMap @[simp] theorem filter_eq_self {l} : filter p l = l ↔ ∀ a ∈ l, p a := by induction l with simp | cons a l ih => cases h : p a <;> simp [*] intro h; exact Nat.lt_irrefl _ (h ▸ length_filter_le p l) @[simp] theorem filter_length_eq_length {l} : (filter p l).length = l.length ↔ ∀ a ∈ l, p a := Iff.trans ⟨l.filter_sublist.eq_of_length, congrArg length⟩ filter_eq_self /-! ### findIdx -/ @[simp] theorem findIdx_nil {α : Type _} (p : α → Bool) : [].findIdx p = 0 := rfl theorem findIdx_cons (p : α → Bool) (b : α) (l : List α) : (b :: l).findIdx p = bif p b then 0 else (l.findIdx p) + 1 := by cases H : p b with | true => simp [H, findIdx, findIdx.go] | false => simp [H, findIdx, findIdx.go, findIdx_go_succ] where findIdx_go_succ (p : α → Bool) (l : List α) (n : Nat) : List.findIdx.go p l (n + 1) = (findIdx.go p l n) + 1 := by cases l with | nil => unfold findIdx.go; exact Nat.succ_eq_add_one n | cons head tail => unfold findIdx.go cases p head <;> simp only [cond_false, cond_true] exact findIdx_go_succ p tail (n + 1) theorem findIdx_of_get?_eq_some {xs : List α} (w : xs.get? (xs.findIdx p) = some y) : p y := by induction xs with | nil => simp_all | cons x xs ih => by_cases h : p x <;> simp_all [findIdx_cons] theorem findIdx_get {xs : List α} {w : xs.findIdx p < xs.length} : p (xs.get ⟨xs.findIdx p, w⟩) := xs.findIdx_of_get?_eq_some (get?_eq_get w) theorem findIdx_lt_length_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.findIdx p < xs.length := by induction xs with | nil => simp_all | cons x xs ih => by_cases p x · simp_all only [forall_exists_index, and_imp, mem_cons, exists_eq_or_imp, true_or, findIdx_cons, cond_true, length_cons] apply Nat.succ_pos · simp_all [findIdx_cons] refine Nat.succ_lt_succ ?_ obtain ⟨x', m', h'⟩ := h exact ih x' m' h' theorem findIdx_get?_eq_get_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.get? (xs.findIdx p) = some (xs.get ⟨xs.findIdx p, xs.findIdx_lt_length_of_exists h⟩) := get?_eq_get (findIdx_lt_length_of_exists h) /-! ### findIdx? -/ @[simp] theorem findIdx?_nil : ([] : List α).findIdx? p i = none := rfl @[simp] theorem findIdx?_cons : (x :: xs).findIdx? p i = if p x then some i else findIdx? p xs (i + 1) := rfl @[simp] theorem findIdx?_succ : (xs : List α).findIdx? p (i+1) = (xs.findIdx? p i).map fun i => i + 1 := by induction xs generalizing i with simp | cons _ _ _ => split <;> simp_all theorem findIdx?_eq_some_iff (xs : List α) (p : α → Bool) : xs.findIdx? p = some i ↔ (xs.take (i + 1)).map p = replicate i false ++ [true] := by induction xs generalizing i with | nil => simp | cons x xs ih => simp only [findIdx?_cons, Nat.zero_add, findIdx?_succ, take_succ_cons, map_cons] split <;> cases i <;> simp_all theorem findIdx?_of_eq_some {xs : List α} {p : α → Bool} (w : xs.findIdx? p = some i) : match xs.get? i with | some a => p a | none => false := by induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [findIdx?_cons, Nat.zero_add, findIdx?_succ] split at w <;> cases i <;> simp_all theorem findIdx?_of_eq_none {xs : List α} {p : α → Bool} (w : xs.findIdx? p = none) : ∀ i, match xs.get? i with | some a => ¬ p a | none => true := by intro i induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [Bool.not_eq_true, findIdx?_cons, Nat.zero_add, findIdx?_succ] cases i with | zero => split at w <;> simp_all | succ i => simp only [get?_cons_succ] apply ih split at w <;> simp_all @[simp] theorem findIdx?_append : (xs ++ ys : List α).findIdx? p = (xs.findIdx? p <|> (ys.findIdx? p).map fun i => i + xs.length) := by induction xs with simp | cons _ _ _ => split <;> simp_all [Option.map_orElse, Option.map_map]; rfl @[simp] theorem findIdx?_replicate : (replicate n a).findIdx? p = if 0 < n ∧ p a then some 0 else none := by induction n with | zero => simp | succ n ih => simp only [replicate, findIdx?_cons, Nat.zero_add, findIdx?_succ, Nat.zero_lt_succ, true_and] split <;> simp_all /-! ### pairwise -/ theorem Pairwise.sublist : l₁ <+ l₂ → l₂.Pairwise R → l₁.Pairwise R | .slnil, h => h | .cons _ s, .cons _ h₂ => h₂.sublist s | .cons₂ _ s, .cons h₁ h₂ => (h₂.sublist s).cons fun _ h => h₁ _ (s.subset h) theorem pairwise_map {l : List α} : (l.map f).Pairwise R ↔ l.Pairwise fun a b => R (f a) (f b) := by induction l · simp · simp only [map, pairwise_cons, forall_mem_map_iff, *] theorem pairwise_append {l₁ l₂ : List α} : (l₁ ++ l₂).Pairwise R ↔ l₁.Pairwise R ∧ l₂.Pairwise R ∧ ∀ a ∈ l₁, ∀ b ∈ l₂, R a b := by induction l₁ <;> simp [*, or_imp, forall_and, and_assoc, and_left_comm] theorem pairwise_reverse {l : List α} : l.reverse.Pairwise R ↔ l.Pairwise (fun a b => R b a) := by induction l <;> simp [*, pairwise_append, and_comm] theorem Pairwise.imp {α R S} (H : ∀ {a b}, R a b → S a b) : ∀ {l : List α}, l.Pairwise R → l.Pairwise S | _, .nil => .nil | _, .cons h₁ h₂ => .cons (H ∘ h₁ ·) (h₂.imp H) /-! ### replaceF -/ theorem replaceF_nil : [].replaceF p = [] := rfl theorem replaceF_cons (a : α) (l : List α) : (a :: l).replaceF p = match p a with | none => a :: replaceF p l | some a' => a' :: l := rfl theorem replaceF_cons_of_some {l : List α} (p) (h : p a = some a') : (a :: l).replaceF p = a' :: l := by simp [replaceF_cons, h] theorem replaceF_cons_of_none {l : List α} (p) (h : p a = none) : (a :: l).replaceF p = a :: l.replaceF p := by simp [replaceF_cons, h] theorem replaceF_of_forall_none {l : List α} (h : ∀ a, a ∈ l → p a = none) : l.replaceF p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_replaceF : ∀ {l : List α} {a a'} (al : a ∈ l) (pa : p a = some a'), ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ | b :: l, a, a', al, pa => match pb : p b with | some b' => ⟨b, b', [], l, forall_mem_nil _, pb, by simp [pb]⟩ | none => match al with | .head .. => nomatch pb.symm.trans pa | .tail _ al => let ⟨c, c', l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_replaceF al pa ⟨c, c', b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_replaceF (p) (l : List α) : l.replaceF p = l ∨ ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ := if h : ∃ a ∈ l, (p a).isSome then let ⟨_, ha, pa⟩ := h .inr (exists_of_replaceF ha (Option.get_mem pa)) else .inl <| replaceF_of_forall_none fun a ha => Option.not_isSome_iff_eq_none.1 fun h' => h ⟨a, ha, h'⟩ @[simp] theorem length_replaceF : length (replaceF f l) = length l := by induction l <;> simp [replaceF]; split <;> simp [*] /-! ### disjoint -/ theorem disjoint_symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂ theorem disjoint_comm : Disjoint l₁ l₂ ↔ Disjoint l₂ l₁ := ⟨disjoint_symm, disjoint_symm⟩
.lake/packages/batteries/Batteries/Data/List/Lemmas.lean
819
819
theorem disjoint_left : Disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₁ → a ∉ l₂ := by
simp [Disjoint]
/- 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.MeasureTheory.Function.LpSeminorm.Basic import Mathlib.MeasureTheory.Integral.MeanInequalities #align_import measure_theory.function.lp_seminorm from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # Triangle inequality for `Lp`-seminorm In this file we prove several versions of the triangle inequality for the `Lp` seminorm, as well as simple corollaries. -/ open Filter open scoped ENNReal Topology namespace MeasureTheory variable {α E : Type*} {m : MeasurableSpace α} [NormedAddCommGroup E] {p : ℝ≥0∞} {q : ℝ} {μ : Measure α} {f g : α → E} theorem snorm'_add_le {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (hq1 : 1 ≤ q) : snorm' (f + g) q μ ≤ snorm' f q μ + snorm' g q μ := calc (∫⁻ a, (‖(f + g) a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) ≤ (∫⁻ a, ((fun a => (‖f a‖₊ : ℝ≥0∞)) + fun a => (‖g a‖₊ : ℝ≥0∞)) a ^ q ∂μ) ^ (1 / q) := by gcongr with a simp only [Pi.add_apply, ← ENNReal.coe_add, ENNReal.coe_le_coe, nnnorm_add_le] _ ≤ snorm' f q μ + snorm' g q μ := ENNReal.lintegral_Lp_add_le hf.ennnorm hg.ennnorm hq1 #align measure_theory.snorm'_add_le MeasureTheory.snorm'_add_le theorem snorm'_add_le_of_le_one {f g : α → E} (hf : AEStronglyMeasurable f μ) (hq0 : 0 ≤ q) (hq1 : q ≤ 1) : snorm' (f + g) q μ ≤ (2 : ℝ≥0∞) ^ (1 / q - 1) * (snorm' f q μ + snorm' g q μ) := calc (∫⁻ a, (‖(f + g) a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) ≤ (∫⁻ a, ((fun a => (‖f a‖₊ : ℝ≥0∞)) + fun a => (‖g a‖₊ : ℝ≥0∞)) a ^ q ∂μ) ^ (1 / q) := by gcongr with a simp only [Pi.add_apply, ← ENNReal.coe_add, ENNReal.coe_le_coe, nnnorm_add_le] _ ≤ (2 : ℝ≥0∞) ^ (1 / q - 1) * (snorm' f q μ + snorm' g q μ) := ENNReal.lintegral_Lp_add_le_of_le_one hf.ennnorm hq0 hq1 #align measure_theory.snorm'_add_le_of_le_one MeasureTheory.snorm'_add_le_of_le_one theorem snormEssSup_add_le {f g : α → E} : snormEssSup (f + g) μ ≤ snormEssSup f μ + snormEssSup g μ := by refine le_trans (essSup_mono_ae (eventually_of_forall fun x => ?_)) (ENNReal.essSup_add_le _ _) simp_rw [Pi.add_apply, ← ENNReal.coe_add, ENNReal.coe_le_coe] exact nnnorm_add_le _ _ #align measure_theory.snorm_ess_sup_add_le MeasureTheory.snormEssSup_add_le theorem snorm_add_le {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (hp1 : 1 ≤ p) : snorm (f + g) p μ ≤ snorm f p μ + snorm g p μ := by by_cases hp0 : p = 0 · simp [hp0] by_cases hp_top : p = ∞ · simp [hp_top, snormEssSup_add_le] have hp1_real : 1 ≤ p.toReal := by rwa [← ENNReal.one_toReal, ENNReal.toReal_le_toReal ENNReal.one_ne_top hp_top] repeat rw [snorm_eq_snorm' hp0 hp_top] exact snorm'_add_le hf hg hp1_real #align measure_theory.snorm_add_le MeasureTheory.snorm_add_le /-- A constant for the inequality `‖f + g‖_{L^p} ≤ C * (‖f‖_{L^p} + ‖g‖_{L^p})`. It is equal to `1` for `p ≥ 1` or `p = 0`, and `2^(1/p-1)` in the more tricky interval `(0, 1)`. -/ noncomputable def LpAddConst (p : ℝ≥0∞) : ℝ≥0∞ := if p ∈ Set.Ioo (0 : ℝ≥0∞) 1 then (2 : ℝ≥0∞) ^ (1 / p.toReal - 1) else 1 set_option linter.uppercaseLean3 false in #align measure_theory.Lp_add_const MeasureTheory.LpAddConst theorem LpAddConst_of_one_le {p : ℝ≥0∞} (hp : 1 ≤ p) : LpAddConst p = 1 := by rw [LpAddConst, if_neg] intro h exact lt_irrefl _ (h.2.trans_le hp) set_option linter.uppercaseLean3 false in #align measure_theory.Lp_add_const_of_one_le MeasureTheory.LpAddConst_of_one_le theorem LpAddConst_zero : LpAddConst 0 = 1 := by rw [LpAddConst, if_neg] intro h exact lt_irrefl _ h.1 set_option linter.uppercaseLean3 false in #align measure_theory.Lp_add_const_zero MeasureTheory.LpAddConst_zero theorem LpAddConst_lt_top (p : ℝ≥0∞) : LpAddConst p < ∞ := by rw [LpAddConst] split_ifs with h · apply ENNReal.rpow_lt_top_of_nonneg _ ENNReal.two_ne_top simp only [one_div, sub_nonneg] apply one_le_inv (ENNReal.toReal_pos h.1.ne' (h.2.trans ENNReal.one_lt_top).ne) simpa using ENNReal.toReal_mono ENNReal.one_ne_top h.2.le · exact ENNReal.one_lt_top set_option linter.uppercaseLean3 false in #align measure_theory.Lp_add_const_lt_top MeasureTheory.LpAddConst_lt_top theorem snorm_add_le' {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (p : ℝ≥0∞) : snorm (f + g) p μ ≤ LpAddConst p * (snorm f p μ + snorm g p μ) := by rcases eq_or_ne p 0 with (rfl | hp) · simp only [snorm_exponent_zero, add_zero, mul_zero, le_zero_iff] rcases lt_or_le p 1 with (h'p | h'p) · simp only [snorm_eq_snorm' hp (h'p.trans ENNReal.one_lt_top).ne] convert snorm'_add_le_of_le_one hf ENNReal.toReal_nonneg _ · have : p ∈ Set.Ioo (0 : ℝ≥0∞) 1 := ⟨hp.bot_lt, h'p⟩ simp only [LpAddConst, if_pos this] · simpa using ENNReal.toReal_mono ENNReal.one_ne_top h'p.le · simp [LpAddConst_of_one_le h'p] exact snorm_add_le hf hg h'p #align measure_theory.snorm_add_le' MeasureTheory.snorm_add_le' variable (μ E) /-- Technical lemma to control the addition of functions in `L^p` even for `p < 1`: Given `δ > 0`, there exists `η` such that two functions bounded by `η` in `L^p` have a sum bounded by `δ`. One could take `η = δ / 2` for `p ≥ 1`, but the point of the lemma is that it works also for `p < 1`. -/ theorem exists_Lp_half (p : ℝ≥0∞) {δ : ℝ≥0∞} (hδ : δ ≠ 0) : ∃ η : ℝ≥0∞, 0 < η ∧ ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ := by have : Tendsto (fun η : ℝ≥0∞ => LpAddConst p * (η + η)) (𝓝[>] 0) (𝓝 (LpAddConst p * (0 + 0))) := (ENNReal.Tendsto.const_mul (tendsto_id.add tendsto_id) (Or.inr (LpAddConst_lt_top p).ne)).mono_left nhdsWithin_le_nhds simp only [add_zero, mul_zero] at this rcases (((tendsto_order.1 this).2 δ hδ.bot_lt).and self_mem_nhdsWithin).exists with ⟨η, hη, ηpos⟩ refine ⟨η, ηpos, fun f g hf hg Hf Hg => ?_⟩ calc snorm (f + g) p μ ≤ LpAddConst p * (snorm f p μ + snorm g p μ) := snorm_add_le' hf hg p _ ≤ LpAddConst p * (η + η) := by gcongr _ < δ := hη set_option linter.uppercaseLean3 false in #align measure_theory.exists_Lp_half MeasureTheory.exists_Lp_half variable {μ E} theorem snorm_sub_le' {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (p : ℝ≥0∞) : snorm (f - g) p μ ≤ LpAddConst p * (snorm f p μ + snorm g p μ) := by simpa only [sub_eq_add_neg, snorm_neg] using snorm_add_le' hf hg.neg p #align measure_theory.snorm_sub_le' MeasureTheory.snorm_sub_le'
Mathlib/MeasureTheory/Function/LpSeminorm/TriangleInequality.lean
145
147
theorem snorm_sub_le {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (hp : 1 ≤ p) : snorm (f - g) p μ ≤ snorm f p μ + snorm g p μ := by
simpa [LpAddConst_of_one_le hp] using snorm_sub_le' hf hg p
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Ext import Mathlib.CategoryTheory.Limits.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Preadditive.Basic import Mathlib.Tactic.Abel #align_import category_theory.preadditive.biproducts from "leanprover-community/mathlib"@"a176cb1219e300e85793d44583dede42377b51af" /-! # Basic facts about biproducts in preadditive categories. In (or between) preadditive categories, * Any biproduct satisfies the equality `total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`, or, in the binary case, `total : fst ≫ inl + snd ≫ inr = 𝟙 X`. * Any (binary) `product` or (binary) `coproduct` is a (binary) `biproduct`. * In any category (with zero morphisms), if `biprod.map f g` is an isomorphism, then both `f` and `g` are isomorphisms. * If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂` so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`), via Gaussian elimination. * As a corollary of the previous two facts, if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, we can construct an isomorphism `X₂ ≅ Y₂`. * If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`, or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero. * If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, then every column (corresponding to a nonzero summand in the domain) has some nonzero matrix entry. * A functor preserves a biproduct if and only if it preserves the corresponding product if and only if it preserves the corresponding coproduct. There are connections between this material and the special case of the category whose morphisms are matrices over a ring, in particular the Schur complement (see `Mathlib.LinearAlgebra.Matrix.SchurComplement`). In particular, the declarations `CategoryTheory.Biprod.isoElim`, `CategoryTheory.Biprod.gaussian` and `Matrix.invertibleOfFromBlocks₁₁Invertible` are all closely related. -/ open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits open CategoryTheory.Functor open CategoryTheory.Preadditive open scoped Classical universe v v' u u' noncomputable section namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] namespace Limits section Fintype variable {J : Type} [Fintype J] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBilimitOfTotal {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => ∑ j : J, s.π.app ⟨j⟩ ≫ b.ι j uniq := fun s m h => by erw [← Category.comp_id m, ← total, comp_sum] apply Finset.sum_congr rfl intro j _ have reassoced : m ≫ Bicone.π b j ≫ Bicone.ι b j = s.π.app ⟨j⟩ ≫ Bicone.ι b j := by erw [← Category.assoc, eq_whisker (h ⟨j⟩)] rw [reassoced] fac := fun s j => by cases j simp only [sum_comp, Category.assoc, Bicone.toCone_π_app, b.ι_π, comp_dite] -- See note [dsimp, simp]. dsimp; simp } isColimit := { desc := fun s => ∑ j : J, b.π j ≫ s.ι.app ⟨j⟩ uniq := fun s m h => by erw [← Category.id_comp m, ← total, sum_comp] apply Finset.sum_congr rfl intro j _ erw [Category.assoc, h ⟨j⟩] fac := fun s j => by cases j simp only [comp_sum, ← Category.assoc, Bicone.toCocone_ι_app, b.ι_π, dite_comp] dsimp; simp } #align category_theory.limits.is_bilimit_of_total CategoryTheory.Limits.isBilimitOfTotal theorem IsBilimit.total {f : J → C} {b : Bicone f} (i : b.IsBilimit) : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt := i.isLimit.hom_ext fun j => by cases j simp [sum_comp, b.ι_π, comp_dite] #align category_theory.limits.is_bilimit.total CategoryTheory.Limits.IsBilimit.total /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBiproduct_of_total {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : HasBiproduct f := HasBiproduct.mk { bicone := b isBilimit := isBilimitOfTotal b total } #align category_theory.limits.has_biproduct_of_total CategoryTheory.Limits.hasBiproduct_of_total /-- In a preadditive category, any finite bicone which is a limit cone is in fact a bilimit bicone. -/ def isBilimitOfIsLimit {f : J → C} (t : Bicone f) (ht : IsLimit t.toCone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by cases j simp [sum_comp, t.ι_π, dite_comp, comp_dite] #align category_theory.limits.is_bilimit_of_is_limit CategoryTheory.Limits.isBilimitOfIsLimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfLimitConeOfIsLimit {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : (Bicone.ofLimitCone ht).IsBilimit := isBilimitOfIsLimit _ <| IsLimit.ofIsoLimit ht <| Cones.ext (Iso.refl _) (by rintro ⟨j⟩ aesop_cat) #align category_theory.limits.bicone_is_bilimit_of_limit_cone_of_is_limit CategoryTheory.Limits.biconeIsBilimitOfLimitConeOfIsLimit /-- In a preadditive category, any finite bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBilimitOfIsColimit {f : J → C} (t : Bicone f) (ht : IsColimit t.toCocone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by cases j simp_rw [Bicone.toCocone_ι_app, comp_sum, ← Category.assoc, t.ι_π, dite_comp] simp #align category_theory.limits.is_bilimit_of_is_colimit CategoryTheory.Limits.isBilimitOfIsColimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfColimitCoconeOfIsColimit {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : (Bicone.ofColimitCocone ht).IsBilimit := isBilimitOfIsColimit _ <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) <| by rintro ⟨j⟩; simp #align category_theory.limits.bicone_is_bilimit_of_colimit_cocone_of_is_colimit CategoryTheory.Limits.biconeIsBilimitOfColimitCoconeOfIsColimit end Fintype section Finite variable {J : Type} [Finite J] /-- In a preadditive category, if the product over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasProduct (f : J → C) [HasProduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } #align category_theory.limits.has_biproduct.of_has_product CategoryTheory.Limits.HasBiproduct.of_hasProduct /-- In a preadditive category, if the coproduct over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasCoproduct (f : J → C) [HasCoproduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } #align category_theory.limits.has_biproduct.of_has_coproduct CategoryTheory.Limits.HasBiproduct.of_hasCoproduct end Finite /-- A preadditive category with finite products has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteProducts [HasFiniteProducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasProduct _ }⟩ #align category_theory.limits.has_finite_biproducts.of_has_finite_products CategoryTheory.Limits.HasFiniteBiproducts.of_hasFiniteProducts /-- A preadditive category with finite coproducts has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteCoproducts [HasFiniteCoproducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasCoproduct _ }⟩ #align category_theory.limits.has_finite_biproducts.of_has_finite_coproducts CategoryTheory.Limits.HasFiniteBiproducts.of_hasFiniteCoproducts section HasBiproduct variable {J : Type} [Fintype J] {f : J → C} [HasBiproduct f] /-- In any preadditive category, any biproduct satsifies `∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)` -/ @[simp] theorem biproduct.total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f) := IsBilimit.total (biproduct.isBilimit _) #align category_theory.limits.biproduct.total CategoryTheory.Limits.biproduct.total theorem biproduct.lift_eq {T : C} {g : ∀ j, T ⟶ f j} : biproduct.lift g = ∑ j, g j ≫ biproduct.ι f j := by ext j simp only [sum_comp, biproduct.ι_π, comp_dite, biproduct.lift_π, Category.assoc, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, if_true] #align category_theory.limits.biproduct.lift_eq CategoryTheory.Limits.biproduct.lift_eq theorem biproduct.desc_eq {T : C} {g : ∀ j, f j ⟶ T} : biproduct.desc g = ∑ j, biproduct.π f j ≫ g j := by ext j simp [comp_sum, biproduct.ι_π_assoc, dite_comp] #align category_theory.limits.biproduct.desc_eq CategoryTheory.Limits.biproduct.desc_eq @[reassoc] theorem biproduct.lift_desc {T U : C} {g : ∀ j, T ⟶ f j} {h : ∀ j, f j ⟶ U} : biproduct.lift g ≫ biproduct.desc h = ∑ j : J, g j ≫ h j := by simp [biproduct.lift_eq, biproduct.desc_eq, comp_sum, sum_comp, biproduct.ι_π_assoc, comp_dite, dite_comp] #align category_theory.limits.biproduct.lift_desc CategoryTheory.Limits.biproduct.lift_desc theorem biproduct.map_eq [HasFiniteBiproducts C] {f g : J → C} {h : ∀ j, f j ⟶ g j} : biproduct.map h = ∑ j : J, biproduct.π f j ≫ h j ≫ biproduct.ι g j := by ext simp [biproduct.ι_π, biproduct.ι_π_assoc, comp_sum, sum_comp, comp_dite, dite_comp] #align category_theory.limits.biproduct.map_eq CategoryTheory.Limits.biproduct.map_eq @[reassoc] theorem biproduct.lift_matrix {K : Type} [Finite K] [HasFiniteBiproducts C] {f : J → C} {g : K → C} {P} (x : ∀ j, P ⟶ f j) (m : ∀ j k, f j ⟶ g k) : biproduct.lift x ≫ biproduct.matrix m = biproduct.lift fun k => ∑ j, x j ≫ m j k := by ext simp [biproduct.lift_desc] #align category_theory.limits.biproduct.lift_matrix CategoryTheory.Limits.biproduct.lift_matrix end HasBiproduct section HasFiniteBiproducts variable {J K : Type} [Finite J] {f : J → C} [HasFiniteBiproducts C] @[reassoc] theorem biproduct.matrix_desc [Fintype K] {f : J → C} {g : K → C} (m : ∀ j k, f j ⟶ g k) {P} (x : ∀ k, g k ⟶ P) : biproduct.matrix m ≫ biproduct.desc x = biproduct.desc fun j => ∑ k, m j k ≫ x k := by ext simp [lift_desc] #align category_theory.limits.biproduct.matrix_desc CategoryTheory.Limits.biproduct.matrix_desc variable [Finite K] @[reassoc] theorem biproduct.matrix_map {f : J → C} {g : K → C} {h : K → C} (m : ∀ j k, f j ⟶ g k) (n : ∀ k, g k ⟶ h k) : biproduct.matrix m ≫ biproduct.map n = biproduct.matrix fun j k => m j k ≫ n k := by ext simp #align category_theory.limits.biproduct.matrix_map CategoryTheory.Limits.biproduct.matrix_map @[reassoc] theorem biproduct.map_matrix {f : J → C} {g : J → C} {h : K → C} (m : ∀ k, f k ⟶ g k) (n : ∀ j k, g j ⟶ h k) : biproduct.map m ≫ biproduct.matrix n = biproduct.matrix fun j k => m j ≫ n j k := by ext simp #align category_theory.limits.biproduct.map_matrix CategoryTheory.Limits.biproduct.map_matrix end HasFiniteBiproducts /-- Reindex a categorical biproduct via an equivalence of the index types. -/ @[simps] def biproduct.reindex {β γ : Type} [Finite β] (ε : β ≃ γ) (f : γ → C) [HasBiproduct f] [HasBiproduct (f ∘ ε)] : ⨁ f ∘ ε ≅ ⨁ f where hom := biproduct.desc fun b => biproduct.ι f (ε b) inv := biproduct.lift fun b => biproduct.π f (ε b) hom_inv_id := by ext b b' by_cases h : b' = b · subst h; simp · have : ε b' ≠ ε b := by simp [h] simp [biproduct.ι_π_ne _ h, biproduct.ι_π_ne _ this] inv_hom_id := by cases nonempty_fintype β ext g g' by_cases h : g' = g <;> simp [Preadditive.sum_comp, Preadditive.comp_sum, biproduct.lift_desc, biproduct.ι_π, biproduct.ι_π_assoc, comp_dite, Equiv.apply_eq_iff_eq_symm_apply, Finset.sum_dite_eq' Finset.univ (ε.symm g') _, h] #align category_theory.limits.biproduct.reindex CategoryTheory.Limits.biproduct.reindex /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBinaryBilimitOfTotal {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => (BinaryFan.fst s ≫ b.inl : s.pt ⟶ b.pt) + (BinaryFan.snd s ≫ b.inr : s.pt ⟶ b.pt) uniq := fun s m h => by have reassoced (j : WalkingPair) {W : C} (h' : _ ⟶ W) : m ≫ b.toCone.π.app ⟨j⟩ ≫ h' = s.π.app ⟨j⟩ ≫ h' := by rw [← Category.assoc, eq_whisker (h ⟨j⟩)] erw [← Category.comp_id m, ← total, comp_add, reassoced WalkingPair.left, reassoced WalkingPair.right] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } isColimit := { desc := fun s => (b.fst ≫ BinaryCofan.inl s : b.pt ⟶ s.pt) + (b.snd ≫ BinaryCofan.inr s : b.pt ⟶ s.pt) uniq := fun s m h => by erw [← Category.id_comp m, ← total, add_comp, Category.assoc, Category.assoc, h ⟨WalkingPair.left⟩, h ⟨WalkingPair.right⟩] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } #align category_theory.limits.is_binary_bilimit_of_total CategoryTheory.Limits.isBinaryBilimitOfTotal theorem IsBilimit.binary_total {X Y : C} {b : BinaryBicone X Y} (i : b.IsBilimit) : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt := i.isLimit.hom_ext fun j => by rcases j with ⟨⟨⟩⟩ <;> simp #align category_theory.limits.is_bilimit.binary_total CategoryTheory.Limits.IsBilimit.binary_total /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBinaryBiproduct_of_total {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := b isBilimit := isBinaryBilimitOfTotal b total } #align category_theory.limits.has_binary_biproduct_of_total CategoryTheory.Limits.hasBinaryBiproduct_of_total /-- We can turn any limit cone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofLimitCone {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : BinaryBicone X Y where pt := t.pt fst := t.π.app ⟨WalkingPair.left⟩ snd := t.π.app ⟨WalkingPair.right⟩ inl := ht.lift (BinaryFan.mk (𝟙 X) 0) inr := ht.lift (BinaryFan.mk 0 (𝟙 Y)) #align category_theory.limits.binary_bicone.of_limit_cone CategoryTheory.Limits.BinaryBicone.ofLimitCone theorem inl_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inl = ht.lift (BinaryFan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryFan.mk (𝟙 X) 0); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.inl_of_is_limit CategoryTheory.Limits.inl_of_isLimit theorem inr_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inr = ht.lift (BinaryFan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryFan.mk 0 (𝟙 Y)); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.inr_of_is_limit CategoryTheory.Limits.inr_of_isLimit /-- In a preadditive category, any binary bicone which is a limit cone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsLimit {X Y : C} (t : BinaryBicone X Y) (ht : IsLimit t.toCone) : t.IsBilimit := isBinaryBilimitOfTotal _ (by refine BinaryFan.IsLimit.hom_ext ht ?_ ?_ <;> simp) #align category_theory.limits.is_binary_bilimit_of_is_limit CategoryTheory.Limits.isBinaryBilimitOfIsLimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfLimitConeOfIsLimit {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : (BinaryBicone.ofLimitCone ht).IsBilimit := isBinaryBilimitOfTotal _ <| BinaryFan.IsLimit.hom_ext ht (by simp) (by simp) #align category_theory.limits.binary_bicone_is_bilimit_of_limit_cone_of_is_limit CategoryTheory.Limits.binaryBiconeIsBilimitOfLimitConeOfIsLimit /-- In a preadditive category, if the product of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryProduct (X Y : C) [HasBinaryProduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } #align category_theory.limits.has_binary_biproduct.of_has_binary_product CategoryTheory.Limits.HasBinaryBiproduct.of_hasBinaryProduct /-- In a preadditive category, if all binary products exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryProducts [HasBinaryProducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryProduct X Y } #align category_theory.limits.has_binary_biproducts.of_has_binary_products CategoryTheory.Limits.HasBinaryBiproducts.of_hasBinaryProducts /-- We can turn any colimit cocone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofColimitCocone {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : BinaryBicone X Y where pt := t.pt fst := ht.desc (BinaryCofan.mk (𝟙 X) 0) snd := ht.desc (BinaryCofan.mk 0 (𝟙 Y)) inl := t.ι.app ⟨WalkingPair.left⟩ inr := t.ι.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_bicone.of_colimit_cocone CategoryTheory.Limits.BinaryBicone.ofColimitCocone theorem fst_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.fst = ht.desc (BinaryCofan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryCofan.mk (𝟙 X) 0) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.fst_of_is_colimit CategoryTheory.Limits.fst_of_isColimit
Mathlib/CategoryTheory/Preadditive/Biproducts.lean
421
424
theorem snd_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.snd = ht.desc (BinaryCofan.mk 0 (𝟙 Y)) := by
apply ht.uniq (BinaryCofan.mk 0 (𝟙 Y)) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp
/- 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, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊤`) (and hence not all elements may have complements). One example in mathlib is `Finset α`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `α`. `GeneralizedBooleanAlgebra α` is defined to be a distributive lattice with bottom (`⊥`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[⊥, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : α` where `a ≤ b`, the equations `x ⊔ a = b` and `x ⊓ a = ⊥` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {α : Type u} {β : Type*} {w x y z : α} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `⊥` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a ⊓ b) ⊔ (a \ b) = a` and `(a ⊓ b) ⊓ (a \ b) = ⊥`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset α` for arbitrary (not-necessarily-`Fintype`) `α`. -/ class GeneralizedBooleanAlgebra (α : Type u) extends DistribLattice α, SDiff α, Bot α where /-- For any `a`, `b`, `(a ⊓ b) ⊔ (a / b) = a` -/ sup_inf_sdiff : ∀ a b : α, a ⊓ b ⊔ a \ b = a /-- For any `a`, `b`, `(a ⊓ b) ⊓ (a / b) = ⊥` -/ inf_inf_sdiff : ∀ a b : α, a ⊓ b ⊓ a \ b = ⊥ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] @[simp] theorem sup_inf_sdiff (x y : α) : x ⊓ y ⊔ x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : α) : x ⊓ y ⊓ x \ y = ⊥ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : α) : x \ y ⊔ x ⊓ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : α) : x \ y ⊓ (x ⊓ y) = ⊥ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot α where __ := GeneralizedBooleanAlgebra.toBot bot_le a := by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x ⊓ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x ⊓ y ⊔ z = x) (i : x ⊓ y ⊓ z = ⊥) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≤ x := calc x \ y ≤ x ⊓ y ⊔ x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x ⊔ x = y ⊔ x := calc y \ x ⊔ x = y \ x ⊔ (x ⊔ x ⊓ y) := by rw [sup_inf_self] _ = y ⊓ x ⊔ y \ x ⊔ x := by ac_rfl _ = y ⊔ x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y ⊓ y \ x = ⊥ := Eq.symm <| calc ⊥ = x ⊓ y ⊓ x \ y := by rw [inf_inf_sdiff] _ = x ⊓ (y ⊓ x ⊔ y \ x) ⊓ x \ y := by rw [sup_inf_sdiff] _ = (x ⊓ (y ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by rw [inf_sup_left] _ = (y ⊓ (x ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by ac_rfl _ = (y ⊓ x ⊔ x ⊓ y \ x) ⊓ x \ y := by rw [inf_idem] _ = x ⊓ y ⊓ x \ y ⊔ x ⊓ y \ x ⊓ x \ y := by rw [inf_sup_right, inf_comm x y] _ = x ⊓ y \ x ⊓ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x ⊓ x \ y ⊓ y \ x := by ac_rfl _ = x \ y ⊓ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x ⊓ y \ x = ⊥ := calc x ⊓ y \ x = (x ⊓ y ⊔ x \ y) ⊓ y \ x := by rw [sup_inf_sdiff] _ = x ⊓ y ⊓ y \ x ⊔ x \ y ⊓ y \ x := by rw [inf_sup_right] _ = ⊥ := by rw [inf_comm x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x ⊓ x = ⊥ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra α where __ := ‹GeneralizedBooleanAlgebra α› __ := GeneralizedBooleanAlgebra.toOrderBot sdiff := (· \ ·) sdiff_le_iff y x z := ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y ⊓ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x ⊓ y \ x ⊔ z ⊓ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x ⊔ z) ⊓ y \ x := by rw [← inf_sup_right])) (calc y ⊔ y \ x = y := sup_of_le_left sdiff_le' _ ≤ y ⊔ (x ⊔ z) := le_sup_left _ = y \ x ⊔ x ⊔ z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x ⊔ z ⊔ y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x ⊓ x = ⊥ := inf_sdiff_self_left _ ≤ z ⊓ x := bot_le) (calc y \ x ⊔ x = y ⊔ x := sdiff_sup_self' _ ≤ x ⊔ z ⊔ x := sup_le_sup_right h x _ ≤ z ⊔ x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≤ y \ z ↔ x ≤ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x ⊔ (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x ⊔ z = y) : y \ x = z := have h : y ⊓ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≤ y) (hs : y ≤ x ⊔ z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, sup_comm x, inf_sup_self, inf_comm, sup_comm z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≤ y) (hx : x ≤ y) : Disjoint z (y \ x) ↔ z ≤ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine le_trans (sup_le_sup_left sdiff_le z) ?_ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≤ y) (hx : x ≤ y) : z ≤ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≤ y) (hx : x ≤ y) : z ⊓ y \ x = ⊥ ↔ z ≤ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≤ y) (hx : x ≤ y) : x ≤ z ↔ y = z ⊔ y \ x := ⟨fun H => by apply le_antisymm · conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] · apply le_trans · apply sup_le_sup_right hz · rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine le_of_inf_le_sup_le ?_ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x ⊔ z) = y \ x ⊓ y \ z := sdiff_unique (calc y ⊓ (x ⊔ z) ⊔ y \ x ⊓ y \ z = (y ⊓ (x ⊔ z) ⊔ y \ x) ⊓ (y ⊓ (x ⊔ z) ⊔ y \ z) := by rw [sup_inf_left] _ = (y ⊓ x ⊔ y ⊓ z ⊔ y \ x) ⊓ (y ⊓ x ⊔ y ⊓ z ⊔ y \ z) := by rw [@inf_sup_left _ _ y] _ = (y ⊓ z ⊔ (y ⊓ x ⊔ y \ x)) ⊓ (y ⊓ x ⊔ (y ⊓ z ⊔ y \ z)) := by ac_rfl _ = (y ⊓ z ⊔ y) ⊓ (y ⊓ x ⊔ y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y ⊔ y ⊓ z) ⊓ (y ⊔ y ⊓ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y ⊓ (x ⊔ z) ⊓ (y \ x ⊓ y \ z) = (y ⊓ x ⊔ y ⊓ z) ⊓ (y \ x ⊓ y \ z) := by rw [inf_sup_left] _ = y ⊓ x ⊓ (y \ x ⊓ y \ z) ⊔ y ⊓ z ⊓ (y \ x ⊓ y \ z) := by rw [inf_sup_right] _ = y ⊓ x ⊓ y \ x ⊓ y \ z ⊔ y \ x ⊓ (y \ z ⊓ (y ⊓ z)) := by ac_rfl _ = ⊥ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, inf_comm (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y ⊓ x = y ⊓ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ ⊥ := by rw [sdiff_bot] _ ↔ x ⊓ y = x ⊓ ⊥ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint'
Mathlib/Order/BooleanAlgebra.lean
319
322
theorem sdiff_lt (hx : y ≤ x) (hy : y ≠ ⊥) : x \ y < x := by
refine sdiff_le.lt_of_ne fun h => hy ?_ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx]
/- 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.Basic import Mathlib.Topology.Order.ProjIcc #align_import analysis.special_functions.trigonometric.inverse from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Inverse trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function. (This is delayed as it is easier to set up after developing complex trigonometric functions.) Basic inequalities on trigonometric functions. -/ noncomputable section open scoped Classical open Topology Filter open Set Filter open Real namespace Real variable {x y : ℝ} /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ -- @[pp_nodot] Porting note: not implemented noncomputable def arcsin : ℝ → ℝ := Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm #align real.arcsin Real.arcsin theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := Subtype.coe_prop _ #align real.arcsin_mem_Icc Real.arcsin_mem_Icc @[simp] theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by rw [arcsin, range_comp Subtype.val] simp [Icc] #align real.range_arcsin Real.range_arcsin theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 #align real.arcsin_le_pi_div_two Real.arcsin_le_pi_div_two theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 #align real.neg_pi_div_two_le_arcsin Real.neg_pi_div_two_le_arcsin theorem arcsin_projIcc (x : ℝ) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend, Function.comp_apply] #align real.arcsin_proj_Icc Real.arcsin_projIcc theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩) #align real.sin_arcsin' Real.sin_arcsin' theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ #align real.sin_arcsin Real.sin_arcsin theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] #align real.arcsin_sin' Real.arcsin_sin' theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ #align real.arcsin_sin Real.arcsin_sin theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) := (Subtype.strictMono_coe _).comp_strictMonoOn <| sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _ #align real.strict_mono_on_arcsin Real.strictMonoOn_arcsin theorem monotone_arcsin : Monotone arcsin := (Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _ #align real.monotone_arcsin Real.monotone_arcsin theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) := strictMonoOn_arcsin.injOn #align real.inj_on_arcsin Real.injOn_arcsin theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ #align real.arcsin_inj Real.arcsin_inj @[continuity] theorem continuous_arcsin : Continuous arcsin := continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend' #align real.continuous_arcsin Real.continuous_arcsin theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x := continuous_arcsin.continuousAt #align real.continuous_at_arcsin Real.continuousAt_arcsin theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := by subst y exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) #align real.arcsin_eq_of_sin_eq Real.arcsin_eq_of_sin_eq @[simp] theorem arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ #align real.arcsin_zero Real.arcsin_zero @[simp] theorem arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) #align real.arcsin_one Real.arcsin_one theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one] #align real.arcsin_of_one_le Real.arcsin_of_one_le theorem arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <| left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) #align real.arcsin_neg_one Real.arcsin_neg_one theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one] #align real.arcsin_of_le_neg_one Real.arcsin_of_le_neg_one @[simp] theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by rcases le_total x (-1) with hx₁ | hx₁ · rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] rcases le_total 1 x with hx₂ | hx₂ · rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] refine arcsin_eq_of_sin_eq ?_ ?_ · rw [sin_neg, sin_arcsin hx₁ hx₂] · exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ #align real.arcsin_neg Real.arcsin_neg theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] #align real.arcsin_le_iff_le_sin Real.arcsin_le_iff_le_sin theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rcases le_total x (-1) with hx₁ | hx₁ · simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] cases' lt_or_le 1 x with hx₂ hx₂ · simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy) #align real.arcsin_le_iff_le_sin' Real.arcsin_le_iff_le_sin' theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff] #align real.le_arcsin_iff_sin_le Real.le_arcsin_iff_sin_le theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩, sin_neg, neg_le_neg_iff] #align real.le_arcsin_iff_sin_le' Real.le_arcsin_iff_sin_le' theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le #align real.arcsin_lt_iff_lt_sin Real.arcsin_lt_iff_lt_sin theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le #align real.arcsin_lt_iff_lt_sin' Real.arcsin_lt_iff_lt_sin' theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le #align real.lt_arcsin_iff_sin_lt Real.lt_arcsin_iff_sin_lt theorem lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le #align real.lt_arcsin_iff_sin_lt' Real.lt_arcsin_iff_sin_lt' theorem arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) : arcsin x = y ↔ x = sin y := by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy), le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)] #align real.arcsin_eq_iff_eq_sin Real.arcsin_eq_iff_eq_sin @[simp] theorem arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x := (le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans <| by rw [sin_zero] #align real.arcsin_nonneg Real.arcsin_nonneg @[simp] theorem arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 := neg_nonneg.symm.trans <| arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg #align real.arcsin_nonpos Real.arcsin_nonpos @[simp] theorem arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff] #align real.arcsin_eq_zero_iff Real.arcsin_eq_zero_iff @[simp] theorem zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 := eq_comm.trans arcsin_eq_zero_iff #align real.zero_eq_arcsin_iff Real.zero_eq_arcsin_iff @[simp] theorem arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x := lt_iff_lt_of_le_iff_le arcsin_nonpos #align real.arcsin_pos Real.arcsin_pos @[simp] theorem arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 := lt_iff_lt_of_le_iff_le arcsin_nonneg #align real.arcsin_lt_zero Real.arcsin_lt_zero @[simp] theorem arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 := (arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by rw [sin_pi_div_two] #align real.arcsin_lt_pi_div_two Real.arcsin_lt_pi_div_two @[simp] theorem neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x := (lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by rw [sin_neg, sin_pi_div_two] #align real.neg_pi_div_two_lt_arcsin Real.neg_pi_div_two_lt_arcsin @[simp] theorem arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x := ⟨fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩ #align real.arcsin_eq_pi_div_two Real.arcsin_eq_pi_div_two @[simp] theorem pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x := eq_comm.trans arcsin_eq_pi_div_two #align real.pi_div_two_eq_arcsin Real.pi_div_two_eq_arcsin @[simp] theorem pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x := (arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin #align real.pi_div_two_le_arcsin Real.pi_div_two_le_arcsin @[simp] theorem arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 := ⟨fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩ #align real.arcsin_eq_neg_pi_div_two Real.arcsin_eq_neg_pi_div_two @[simp] theorem neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 := eq_comm.trans arcsin_eq_neg_pi_div_two #align real.neg_pi_div_two_eq_arcsin Real.neg_pi_div_two_eq_arcsin @[simp] theorem arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 := (neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two #align real.arcsin_le_neg_pi_div_two Real.arcsin_le_neg_pi_div_two @[simp] theorem pi_div_four_le_arcsin {x} : π / 4 ≤ arcsin x ↔ √2 / 2 ≤ x := by rw [← sin_pi_div_four, le_arcsin_iff_sin_le'] have := pi_pos constructor <;> linarith #align real.pi_div_four_le_arcsin Real.pi_div_four_le_arcsin theorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := fun x h => by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le] #align real.maps_to_sin_Ioo Real.mapsTo_sin_Ioo /-- `Real.sin` as a `PartialHomeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/ @[simp] def sinPartialHomeomorph : PartialHomeomorph ℝ ℝ where toFun := sin invFun := arcsin source := Ioo (-(π / 2)) (π / 2) target := Ioo (-1) 1 map_source' := mapsTo_sin_Ioo map_target' _ hy := ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩ left_inv' _ hx := arcsin_sin hx.1.le hx.2.le right_inv' _ hy := sin_arcsin hy.1.le hy.2.le open_source := isOpen_Ioo open_target := isOpen_Ioo continuousOn_toFun := continuous_sin.continuousOn continuousOn_invFun := continuous_arcsin.continuousOn #align real.sin_local_homeomorph Real.sinPartialHomeomorph theorem cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) := cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ #align real.cos_arcsin_nonneg Real.cos_arcsin_nonneg -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem cos_arcsin (x : ℝ) : cos (arcsin x) = √(1 - x ^ 2) := by by_cases hx₁ : -1 ≤ x; swap · rw [not_le] at hx₁ rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith by_cases hx₂ : x ≤ 1; swap · rw [not_le] at hx₂ rw [arcsin_of_one_le hx₂.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x) rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq, sqrt_mul_self (cos_arcsin_nonneg _)] at this rw [this, sin_arcsin hx₁ hx₂] #align real.cos_arcsin Real.cos_arcsin -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem tan_arcsin (x : ℝ) : tan (arcsin x) = x / √(1 - x ^ 2) := by rw [tan_eq_sin_div_cos, cos_arcsin] by_cases hx₁ : -1 ≤ x; swap · have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp by_cases hx₂ : x ≤ 1; swap · have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp rw [sin_arcsin hx₁ hx₂] #align real.tan_arcsin Real.tan_arcsin /-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`. It defaults to `π` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/ -- @[pp_nodot] Porting note: not implemented noncomputable def arccos (x : ℝ) : ℝ := π / 2 - arcsin x #align real.arccos Real.arccos theorem arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl #align real.arccos_eq_pi_div_two_sub_arcsin Real.arccos_eq_pi_div_two_sub_arcsin theorem arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [arccos] #align real.arcsin_eq_pi_div_two_sub_arccos Real.arcsin_eq_pi_div_two_sub_arccos theorem arccos_le_pi (x : ℝ) : arccos x ≤ π := by unfold arccos; linarith [neg_pi_div_two_le_arcsin x] #align real.arccos_le_pi Real.arccos_le_pi theorem arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by unfold arccos; linarith [arcsin_le_pi_div_two x] #align real.arccos_nonneg Real.arccos_nonneg @[simp] theorem arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 := by simp [arccos] #align real.arccos_pos Real.arccos_pos theorem cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂] #align real.cos_arccos Real.cos_arccos theorem arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith #align real.arccos_cos Real.arccos_cos lemma arccos_eq_of_eq_cos (hy₀ : 0 ≤ y) (hy₁ : y ≤ π) (hxy : x = cos y) : arccos x = y := by rw [hxy, arccos_cos hy₀ hy₁] theorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun _ hx _ hy h => sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _ #align real.strict_anti_on_arccos Real.strictAntiOn_arccos theorem arccos_injOn : InjOn arccos (Icc (-1) 1) := strictAntiOn_arccos.injOn #align real.arccos_inj_on Real.arccos_injOn theorem arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arccos x = arccos y ↔ x = y := arccos_injOn.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ #align real.arccos_inj Real.arccos_inj @[simp] theorem arccos_zero : arccos 0 = π / 2 := by simp [arccos] #align real.arccos_zero Real.arccos_zero @[simp] theorem arccos_one : arccos 1 = 0 := by simp [arccos] #align real.arccos_one Real.arccos_one @[simp] theorem arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves] #align real.arccos_neg_one Real.arccos_neg_one @[simp] theorem arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x := by simp [arccos, sub_eq_zero] #align real.arccos_eq_zero Real.arccos_eq_zero @[simp]
Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean
402
402
theorem arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 := by
simp [arccos]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Data.Finset.Piecewise import Mathlib.Data.Finset.Preimage #align_import algebra.big_operators.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Big operators In this file we define products and sums indexed by finite sets (specifically, `Finset`). ## Notation We introduce the following notation. Let `s` be a `Finset α`, and `f : α → β` a function. * `∏ x ∈ s, f x` is notation for `Finset.prod s f` (assuming `β` is a `CommMonoid`) * `∑ x ∈ s, f x` is notation for `Finset.sum s f` (assuming `β` is an `AddCommMonoid`) * `∏ x, f x` is notation for `Finset.prod Finset.univ f` (assuming `α` is a `Fintype` and `β` is a `CommMonoid`) * `∑ x, f x` is notation for `Finset.sum Finset.univ f` (assuming `α` is a `Fintype` and `β` is an `AddCommMonoid`) ## Implementation Notes The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. -/ -- TODO -- assert_not_exists AddCommMonoidWithOne assert_not_exists MonoidWithZero assert_not_exists MulAction variable {ι κ α β γ : Type*} open Fin Function namespace Finset /-- `∏ x ∈ s, f x` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/ @[to_additive "`∑ x ∈ s, f x` is the sum of `f x` as `x` ranges over the elements of the finite set `s`."] protected def prod [CommMonoid β] (s : Finset α) (f : α → β) : β := (s.1.map f).prod #align finset.prod Finset.prod #align finset.sum Finset.sum @[to_additive (attr := simp)] theorem prod_mk [CommMonoid β] (s : Multiset α) (hs : s.Nodup) (f : α → β) : (⟨s, hs⟩ : Finset α).prod f = (s.map f).prod := rfl #align finset.prod_mk Finset.prod_mk #align finset.sum_mk Finset.sum_mk @[to_additive (attr := simp)] theorem prod_val [CommMonoid α] (s : Finset α) : s.1.prod = s.prod id := by rw [Finset.prod, Multiset.map_id] #align finset.prod_val Finset.prod_val #align finset.sum_val Finset.sum_val end Finset library_note "operator precedence of big operators"/-- There is no established mathematical convention for the operator precedence of big operators like `∏` and `∑`. We will have to make a choice. Online discussions, such as https://math.stackexchange.com/q/185538/30839 seem to suggest that `∏` and `∑` should have the same precedence, and that this should be somewhere between `*` and `+`. The latter have precedence levels `70` and `65` respectively, and we therefore choose the level `67`. In practice, this means that parentheses should be placed as follows: ```lean ∑ k ∈ K, (a k + b k) = ∑ k ∈ K, a k + ∑ k ∈ K, b k → ∏ k ∈ K, a k * b k = (∏ k ∈ K, a k) * (∏ k ∈ K, b k) ``` (Example taken from page 490 of Knuth's *Concrete Mathematics*.) -/ namespace BigOperators open Batteries.ExtendedBinder Lean Meta -- TODO: contribute this modification back to `extBinder` /-- A `bigOpBinder` is like an `extBinder` and has the form `x`, `x : ty`, or `x pred` where `pred` is a `binderPred` like `< 2`. Unlike `extBinder`, `x` is a term. -/ syntax bigOpBinder := term:max ((" : " term) <|> binderPred)? /-- A BigOperator binder in parentheses -/ syntax bigOpBinderParenthesized := " (" bigOpBinder ")" /-- A list of parenthesized binders -/ syntax bigOpBinderCollection := bigOpBinderParenthesized+ /-- A single (unparenthesized) binder, or a list of parenthesized binders -/ syntax bigOpBinders := bigOpBinderCollection <|> (ppSpace bigOpBinder) /-- Collects additional binder/Finset pairs for the given `bigOpBinder`. Note: this is not extensible at the moment, unlike the usual `bigOpBinder` expansions. -/ def processBigOpBinder (processed : (Array (Term × Term))) (binder : TSyntax ``bigOpBinder) : MacroM (Array (Term × Term)) := set_option hygiene false in withRef binder do match binder with | `(bigOpBinder| $x:term) => match x with | `(($a + $b = $n)) => -- Maybe this is too cute. return processed |>.push (← `(⟨$a, $b⟩), ← `(Finset.Nat.antidiagonal $n)) | _ => return processed |>.push (x, ← ``(Finset.univ)) | `(bigOpBinder| $x : $t) => return processed |>.push (x, ← ``((Finset.univ : Finset $t))) | `(bigOpBinder| $x ∈ $s) => return processed |>.push (x, ← `(finset% $s)) | `(bigOpBinder| $x < $n) => return processed |>.push (x, ← `(Finset.Iio $n)) | `(bigOpBinder| $x ≤ $n) => return processed |>.push (x, ← `(Finset.Iic $n)) | `(bigOpBinder| $x > $n) => return processed |>.push (x, ← `(Finset.Ioi $n)) | `(bigOpBinder| $x ≥ $n) => return processed |>.push (x, ← `(Finset.Ici $n)) | _ => Macro.throwUnsupported /-- Collects the binder/Finset pairs for the given `bigOpBinders`. -/ def processBigOpBinders (binders : TSyntax ``bigOpBinders) : MacroM (Array (Term × Term)) := match binders with | `(bigOpBinders| $b:bigOpBinder) => processBigOpBinder #[] b | `(bigOpBinders| $[($bs:bigOpBinder)]*) => bs.foldlM processBigOpBinder #[] | _ => Macro.throwUnsupported /-- Collect the binderIdents into a `⟨...⟩` expression. -/ def bigOpBindersPattern (processed : (Array (Term × Term))) : MacroM Term := do let ts := processed.map Prod.fst if ts.size == 1 then return ts[0]! else `(⟨$ts,*⟩) /-- Collect the terms into a product of sets. -/ def bigOpBindersProd (processed : (Array (Term × Term))) : MacroM Term := do if processed.isEmpty then `((Finset.univ : Finset Unit)) else if processed.size == 1 then return processed[0]!.2 else processed.foldrM (fun s p => `(SProd.sprod $(s.2) $p)) processed.back.2 (start := processed.size - 1) /-- - `∑ x, f x` is notation for `Finset.sum Finset.univ f`. It is the sum of `f x`, where `x` ranges over the finite domain of `f`. - `∑ x ∈ s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`, where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance). - `∑ x ∈ s with p x, f x` is notation for `Finset.sum (Finset.filter p s) f`. - `∑ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.sum (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`. These support destructuring, for example `∑ ⟨x, y⟩ ∈ s ×ˢ t, f x y`. Notation: `"∑" bigOpBinders* ("with" term)? "," term` -/ syntax (name := bigsum) "∑ " bigOpBinders ("with " term)? ", " term:67 : term /-- - `∏ x, f x` is notation for `Finset.prod Finset.univ f`. It is the product of `f x`, where `x` ranges over the finite domain of `f`. - `∏ x ∈ s, f x` is notation for `Finset.prod s f`. It is the product of `f x`, where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance). - `∏ x ∈ s with p x, f x` is notation for `Finset.prod (Finset.filter p s) f`. - `∏ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.prod (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`. These support destructuring, for example `∏ ⟨x, y⟩ ∈ s ×ˢ t, f x y`. Notation: `"∏" bigOpBinders* ("with" term)? "," term` -/ syntax (name := bigprod) "∏ " bigOpBinders ("with " term)? ", " term:67 : term macro_rules (kind := bigsum) | `(∑ $bs:bigOpBinders $[with $p?]?, $v) => do let processed ← processBigOpBinders bs let x ← bigOpBindersPattern processed let s ← bigOpBindersProd processed match p? with | some p => `(Finset.sum (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v)) | none => `(Finset.sum $s (fun $x ↦ $v)) macro_rules (kind := bigprod) | `(∏ $bs:bigOpBinders $[with $p?]?, $v) => do let processed ← processBigOpBinders bs let x ← bigOpBindersPattern processed let s ← bigOpBindersProd processed match p? with | some p => `(Finset.prod (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v)) | none => `(Finset.prod $s (fun $x ↦ $v)) /-- (Deprecated, use `∑ x ∈ s, f x`) `∑ x in s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`, where `x` ranges over the finite set `s`. -/ syntax (name := bigsumin) "∑ " extBinder " in " term ", " term:67 : term macro_rules (kind := bigsumin) | `(∑ $x:ident in $s, $r) => `(∑ $x:ident ∈ $s, $r) | `(∑ $x:ident : $t in $s, $r) => `(∑ $x:ident ∈ ($s : Finset $t), $r) /-- (Deprecated, use `∏ x ∈ s, f x`) `∏ x in s, f x` is notation for `Finset.prod s f`. It is the product of `f x`, where `x` ranges over the finite set `s`. -/ syntax (name := bigprodin) "∏ " extBinder " in " term ", " term:67 : term macro_rules (kind := bigprodin) | `(∏ $x:ident in $s, $r) => `(∏ $x:ident ∈ $s, $r) | `(∏ $x:ident : $t in $s, $r) => `(∏ $x:ident ∈ ($s : Finset $t), $r) open Lean Meta Parser.Term PrettyPrinter.Delaborator SubExpr open Batteries.ExtendedBinder /-- Delaborator for `Finset.prod`. The `pp.piBinderTypes` option controls whether to show the domain type when the product is over `Finset.univ`. -/ @[delab app.Finset.prod] def delabFinsetProd : Delab := whenPPOption getPPNotation <| withOverApp 5 <| do let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure guard <| f.isLambda let ppDomain ← getPPOption getPPPiBinderTypes let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do return (i, ← delab) if s.isAppOfArity ``Finset.univ 2 then let binder ← if ppDomain then let ty ← withNaryArg 0 delab `(bigOpBinder| $(.mk i):ident : $ty) else `(bigOpBinder| $(.mk i):ident) `(∏ $binder:bigOpBinder, $body) else let ss ← withNaryArg 3 <| delab `(∏ $(.mk i):ident ∈ $ss, $body) /-- Delaborator for `Finset.sum`. The `pp.piBinderTypes` option controls whether to show the domain type when the sum is over `Finset.univ`. -/ @[delab app.Finset.sum] def delabFinsetSum : Delab := whenPPOption getPPNotation <| withOverApp 5 <| do let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure guard <| f.isLambda let ppDomain ← getPPOption getPPPiBinderTypes let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do return (i, ← delab) if s.isAppOfArity ``Finset.univ 2 then let binder ← if ppDomain then let ty ← withNaryArg 0 delab `(bigOpBinder| $(.mk i):ident : $ty) else `(bigOpBinder| $(.mk i):ident) `(∑ $binder:bigOpBinder, $body) else let ss ← withNaryArg 3 <| delab `(∑ $(.mk i):ident ∈ $ss, $body) end BigOperators namespace Finset variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β} @[to_additive] theorem prod_eq_multiset_prod [CommMonoid β] (s : Finset α) (f : α → β) : ∏ x ∈ s, f x = (s.1.map f).prod := rfl #align finset.prod_eq_multiset_prod Finset.prod_eq_multiset_prod #align finset.sum_eq_multiset_sum Finset.sum_eq_multiset_sum @[to_additive (attr := simp)] lemma prod_map_val [CommMonoid β] (s : Finset α) (f : α → β) : (s.1.map f).prod = ∏ a ∈ s, f a := rfl #align finset.prod_map_val Finset.prod_map_val #align finset.sum_map_val Finset.sum_map_val @[to_additive] theorem prod_eq_fold [CommMonoid β] (s : Finset α) (f : α → β) : ∏ x ∈ s, f x = s.fold ((· * ·) : β → β → β) 1 f := rfl #align finset.prod_eq_fold Finset.prod_eq_fold #align finset.sum_eq_fold Finset.sum_eq_fold @[simp] theorem sum_multiset_singleton (s : Finset α) : (s.sum fun x => {x}) = s.val := by simp only [sum_eq_multiset_sum, Multiset.sum_map_singleton] #align finset.sum_multiset_singleton Finset.sum_multiset_singleton end Finset @[to_additive (attr := simp)] theorem map_prod [CommMonoid β] [CommMonoid γ] {G : Type*} [FunLike G β γ] [MonoidHomClass G β γ] (g : G) (f : α → β) (s : Finset α) : g (∏ x ∈ s, f x) = ∏ x ∈ s, g (f x) := by simp only [Finset.prod_eq_multiset_prod, map_multiset_prod, Multiset.map_map]; rfl #align map_prod map_prod #align map_sum map_sum @[to_additive] theorem MonoidHom.coe_finset_prod [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) : ⇑(∏ x ∈ s, f x) = ∏ x ∈ s, ⇑(f x) := map_prod (MonoidHom.coeFn β γ) _ _ #align monoid_hom.coe_finset_prod MonoidHom.coe_finset_prod #align add_monoid_hom.coe_finset_sum AddMonoidHom.coe_finset_sum /-- See also `Finset.prod_apply`, with the same conclusion but with the weaker hypothesis `f : α → β → γ` -/ @[to_additive (attr := simp) "See also `Finset.sum_apply`, with the same conclusion but with the weaker hypothesis `f : α → β → γ`"] theorem MonoidHom.finset_prod_apply [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) (b : β) : (∏ x ∈ s, f x) b = ∏ x ∈ s, f x b := map_prod (MonoidHom.eval b) _ _ #align monoid_hom.finset_prod_apply MonoidHom.finset_prod_apply #align add_monoid_hom.finset_sum_apply AddMonoidHom.finset_sum_apply variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β} namespace Finset section CommMonoid variable [CommMonoid β] @[to_additive (attr := simp)] theorem prod_empty : ∏ x ∈ ∅, f x = 1 := rfl #align finset.prod_empty Finset.prod_empty #align finset.sum_empty Finset.sum_empty @[to_additive] theorem prod_of_empty [IsEmpty α] (s : Finset α) : ∏ i ∈ s, f i = 1 := by rw [eq_empty_of_isEmpty s, prod_empty] #align finset.prod_of_empty Finset.prod_of_empty #align finset.sum_of_empty Finset.sum_of_empty @[to_additive (attr := simp)] theorem prod_cons (h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x := fold_cons h #align finset.prod_cons Finset.prod_cons #align finset.sum_cons Finset.sum_cons @[to_additive (attr := simp)] theorem prod_insert [DecidableEq α] : a ∉ s → ∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x := fold_insert #align finset.prod_insert Finset.prod_insert #align finset.sum_insert Finset.sum_insert /-- The product of `f` over `insert a s` is the same as the product over `s`, as long as `a` is in `s` or `f a = 1`. -/ @[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `a` is in `s` or `f a = 0`."] theorem prod_insert_of_eq_one_if_not_mem [DecidableEq α] (h : a ∉ s → f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := by by_cases hm : a ∈ s · simp_rw [insert_eq_of_mem hm] · rw [prod_insert hm, h hm, one_mul] #align finset.prod_insert_of_eq_one_if_not_mem Finset.prod_insert_of_eq_one_if_not_mem #align finset.sum_insert_of_eq_zero_if_not_mem Finset.sum_insert_of_eq_zero_if_not_mem /-- The product of `f` over `insert a s` is the same as the product over `s`, as long as `f a = 1`. -/ @[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `f a = 0`."] theorem prod_insert_one [DecidableEq α] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := prod_insert_of_eq_one_if_not_mem fun _ => h #align finset.prod_insert_one Finset.prod_insert_one #align finset.sum_insert_zero Finset.sum_insert_zero @[to_additive] theorem prod_insert_div {M : Type*} [CommGroup M] [DecidableEq α] (ha : a ∉ s) {f : α → M} : (∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x := by simp [ha] @[to_additive (attr := simp)] theorem prod_singleton (f : α → β) (a : α) : ∏ x ∈ singleton a, f x = f a := Eq.trans fold_singleton <| mul_one _ #align finset.prod_singleton Finset.prod_singleton #align finset.sum_singleton Finset.sum_singleton @[to_additive] theorem prod_pair [DecidableEq α] {a b : α} (h : a ≠ b) : (∏ x ∈ ({a, b} : Finset α), f x) = f a * f b := by rw [prod_insert (not_mem_singleton.2 h), prod_singleton] #align finset.prod_pair Finset.prod_pair #align finset.sum_pair Finset.sum_pair @[to_additive (attr := simp)] theorem prod_const_one : (∏ _x ∈ s, (1 : β)) = 1 := by simp only [Finset.prod, Multiset.map_const', Multiset.prod_replicate, one_pow] #align finset.prod_const_one Finset.prod_const_one #align finset.sum_const_zero Finset.sum_const_zero @[to_additive (attr := simp)] theorem prod_image [DecidableEq α] {s : Finset γ} {g : γ → α} : (∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x) := fold_image #align finset.prod_image Finset.prod_image #align finset.sum_image Finset.sum_image @[to_additive (attr := simp)] theorem prod_map (s : Finset α) (e : α ↪ γ) (f : γ → β) : ∏ x ∈ s.map e, f x = ∏ x ∈ s, f (e x) := by rw [Finset.prod, Finset.map_val, Multiset.map_map]; rfl #align finset.prod_map Finset.prod_map #align finset.sum_map Finset.sum_map @[to_additive] lemma prod_attach (s : Finset α) (f : α → β) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x := by classical rw [← prod_image Subtype.coe_injective.injOn, attach_image_val] #align finset.prod_attach Finset.prod_attach #align finset.sum_attach Finset.sum_attach @[to_additive (attr := congr)] theorem prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g := by rw [h]; exact fold_congr #align finset.prod_congr Finset.prod_congr #align finset.sum_congr Finset.sum_congr @[to_additive] theorem prod_eq_one {f : α → β} {s : Finset α} (h : ∀ x ∈ s, f x = 1) : ∏ x ∈ s, f x = 1 := calc ∏ x ∈ s, f x = ∏ _x ∈ s, 1 := Finset.prod_congr rfl h _ = 1 := Finset.prod_const_one #align finset.prod_eq_one Finset.prod_eq_one #align finset.sum_eq_zero Finset.sum_eq_zero @[to_additive] theorem prod_disjUnion (h) : ∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by refine Eq.trans ?_ (fold_disjUnion h) rw [one_mul] rfl #align finset.prod_disj_union Finset.prod_disjUnion #align finset.sum_disj_union Finset.sum_disjUnion @[to_additive] theorem prod_disjiUnion (s : Finset ι) (t : ι → Finset α) (h) : ∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x := by refine Eq.trans ?_ (fold_disjiUnion h) dsimp [Finset.prod, Multiset.prod, Multiset.fold, Finset.disjUnion, Finset.fold] congr exact prod_const_one.symm #align finset.prod_disj_Union Finset.prod_disjiUnion #align finset.sum_disj_Union Finset.sum_disjiUnion @[to_additive] theorem prod_union_inter [DecidableEq α] : (∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := fold_union_inter #align finset.prod_union_inter Finset.prod_union_inter #align finset.sum_union_inter Finset.sum_union_inter @[to_additive] theorem prod_union [DecidableEq α] (h : Disjoint s₁ s₂) : ∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by rw [← prod_union_inter, disjoint_iff_inter_eq_empty.mp h]; exact (mul_one _).symm #align finset.prod_union Finset.prod_union #align finset.sum_union Finset.sum_union @[to_additive] theorem prod_filter_mul_prod_filter_not (s : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : α → β) : (∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, f x = ∏ x ∈ s, f x := by have := Classical.decEq α rw [← prod_union (disjoint_filter_filter_neg s s p), filter_union_filter_neg_eq] #align finset.prod_filter_mul_prod_filter_not Finset.prod_filter_mul_prod_filter_not #align finset.sum_filter_add_sum_filter_not Finset.sum_filter_add_sum_filter_not section ToList @[to_additive (attr := simp)] theorem prod_to_list (s : Finset α) (f : α → β) : (s.toList.map f).prod = s.prod f := by rw [Finset.prod, ← Multiset.prod_coe, ← Multiset.map_coe, Finset.coe_toList] #align finset.prod_to_list Finset.prod_to_list #align finset.sum_to_list Finset.sum_to_list end ToList @[to_additive] theorem _root_.Equiv.Perm.prod_comp (σ : Equiv.Perm α) (s : Finset α) (f : α → β) (hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x)) = ∏ x ∈ s, f x := by convert (prod_map s σ.toEmbedding f).symm exact (map_perm hs).symm #align equiv.perm.prod_comp Equiv.Perm.prod_comp #align equiv.perm.sum_comp Equiv.Perm.sum_comp @[to_additive] theorem _root_.Equiv.Perm.prod_comp' (σ : Equiv.Perm α) (s : Finset α) (f : α → α → β) (hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x) x) = ∏ x ∈ s, f x (σ.symm x) := by convert σ.prod_comp s (fun x => f x (σ.symm x)) hs rw [Equiv.symm_apply_apply] #align equiv.perm.prod_comp' Equiv.Perm.prod_comp' #align equiv.perm.sum_comp' Equiv.Perm.sum_comp' /-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets of `s`, and over all subsets of `s` to which one adds `x`. -/ @[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets of `s`, and over all subsets of `s` to which one adds `x`."] lemma prod_powerset_insert [DecidableEq α] (ha : a ∉ s) (f : Finset α → β) : ∏ t ∈ (insert a s).powerset, f t = (∏ t ∈ s.powerset, f t) * ∏ t ∈ s.powerset, f (insert a t) := by rw [powerset_insert, prod_union, prod_image] · exact insert_erase_invOn.2.injOn.mono fun t ht ↦ not_mem_mono (mem_powerset.1 ht) ha · aesop (add simp [disjoint_left, insert_subset_iff]) #align finset.prod_powerset_insert Finset.prod_powerset_insert #align finset.sum_powerset_insert Finset.sum_powerset_insert /-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets of `s`, and over all subsets of `s` to which one adds `x`. -/ @[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets of `s`, and over all subsets of `s` to which one adds `x`."] lemma prod_powerset_cons (ha : a ∉ s) (f : Finset α → β) : ∏ t ∈ (s.cons a ha).powerset, f t = (∏ t ∈ s.powerset, f t) * ∏ t ∈ s.powerset.attach, f (cons a t $ not_mem_mono (mem_powerset.1 t.2) ha) := by classical simp_rw [cons_eq_insert] rw [prod_powerset_insert ha, prod_attach _ fun t ↦ f (insert a t)] /-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with `card s = k`, for `k = 1, ..., card s`. -/ @[to_additive "A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with `card s = k`, for `k = 1, ..., card s`"] lemma prod_powerset (s : Finset α) (f : Finset α → β) : ∏ t ∈ powerset s, f t = ∏ j ∈ range (card s + 1), ∏ t ∈ powersetCard j s, f t := by rw [powerset_card_disjiUnion, prod_disjiUnion] #align finset.prod_powerset Finset.prod_powerset #align finset.sum_powerset Finset.sum_powerset end CommMonoid end Finset section open Finset variable [Fintype α] [CommMonoid β] @[to_additive] theorem IsCompl.prod_mul_prod {s t : Finset α} (h : IsCompl s t) (f : α → β) : (∏ i ∈ s, f i) * ∏ i ∈ t, f i = ∏ i, f i := (Finset.prod_disjUnion h.disjoint).symm.trans <| by classical rw [Finset.disjUnion_eq_union, ← Finset.sup_eq_union, h.sup_eq_top]; rfl #align is_compl.prod_mul_prod IsCompl.prod_mul_prod #align is_compl.sum_add_sum IsCompl.sum_add_sum end namespace Finset section CommMonoid variable [CommMonoid β] /-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product. For a version expressed with subtypes, see `Fintype.prod_subtype_mul_prod_subtype`. -/ @[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum. For a version expressed with subtypes, see `Fintype.sum_subtype_add_sum_subtype`. "] theorem prod_mul_prod_compl [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) : (∏ i ∈ s, f i) * ∏ i ∈ sᶜ, f i = ∏ i, f i := IsCompl.prod_mul_prod isCompl_compl f #align finset.prod_mul_prod_compl Finset.prod_mul_prod_compl #align finset.sum_add_sum_compl Finset.sum_add_sum_compl @[to_additive] theorem prod_compl_mul_prod [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) : (∏ i ∈ sᶜ, f i) * ∏ i ∈ s, f i = ∏ i, f i := (@isCompl_compl _ s _).symm.prod_mul_prod f #align finset.prod_compl_mul_prod Finset.prod_compl_mul_prod #align finset.sum_compl_add_sum Finset.sum_compl_add_sum @[to_additive] theorem prod_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) : (∏ x ∈ s₂ \ s₁, f x) * ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := by rw [← prod_union sdiff_disjoint, sdiff_union_of_subset h] #align finset.prod_sdiff Finset.prod_sdiff #align finset.sum_sdiff Finset.sum_sdiff @[to_additive] theorem prod_subset_one_on_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ s₂ \ s₁, g x = 1) (hfg : ∀ x ∈ s₁, f x = g x) : ∏ i ∈ s₁, f i = ∏ i ∈ s₂, g i := by rw [← prod_sdiff h, prod_eq_one hg, one_mul] exact prod_congr rfl hfg #align finset.prod_subset_one_on_sdiff Finset.prod_subset_one_on_sdiff #align finset.sum_subset_zero_on_sdiff Finset.sum_subset_zero_on_sdiff @[to_additive] theorem prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) : ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := haveI := Classical.decEq α prod_subset_one_on_sdiff h (by simpa) fun _ _ => rfl #align finset.prod_subset Finset.prod_subset #align finset.sum_subset Finset.sum_subset @[to_additive (attr := simp)] theorem prod_disj_sum (s : Finset α) (t : Finset γ) (f : Sum α γ → β) : ∏ x ∈ s.disjSum t, f x = (∏ x ∈ s, f (Sum.inl x)) * ∏ x ∈ t, f (Sum.inr x) := by rw [← map_inl_disjUnion_map_inr, prod_disjUnion, prod_map, prod_map] rfl #align finset.prod_disj_sum Finset.prod_disj_sum #align finset.sum_disj_sum Finset.sum_disj_sum @[to_additive] theorem prod_sum_elim (s : Finset α) (t : Finset γ) (f : α → β) (g : γ → β) : ∏ x ∈ s.disjSum t, Sum.elim f g x = (∏ x ∈ s, f x) * ∏ x ∈ t, g x := by simp #align finset.prod_sum_elim Finset.prod_sum_elim #align finset.sum_sum_elim Finset.sum_sum_elim @[to_additive] theorem prod_biUnion [DecidableEq α] {s : Finset γ} {t : γ → Finset α} (hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i := by rw [← disjiUnion_eq_biUnion _ _ hs, prod_disjiUnion] #align finset.prod_bUnion Finset.prod_biUnion #align finset.sum_bUnion Finset.sum_biUnion /-- Product over a sigma type equals the product of fiberwise products. For rewriting in the reverse direction, use `Finset.prod_sigma'`. -/ @[to_additive "Sum over a sigma type equals the sum of fiberwise sums. For rewriting in the reverse direction, use `Finset.sum_sigma'`"] theorem prod_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : Sigma σ → β) : ∏ x ∈ s.sigma t, f x = ∏ a ∈ s, ∏ s ∈ t a, f ⟨a, s⟩ := by simp_rw [← disjiUnion_map_sigma_mk, prod_disjiUnion, prod_map, Function.Embedding.sigmaMk_apply] #align finset.prod_sigma Finset.prod_sigma #align finset.sum_sigma Finset.sum_sigma @[to_additive] theorem prod_sigma' {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : ∀ a, σ a → β) : (∏ a ∈ s, ∏ s ∈ t a, f a s) = ∏ x ∈ s.sigma t, f x.1 x.2 := Eq.symm <| prod_sigma s t fun x => f x.1 x.2 #align finset.prod_sigma' Finset.prod_sigma' #align finset.sum_sigma' Finset.sum_sigma' section bij variable {ι κ α : Type*} [CommMonoid α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α} /-- Reorder a product. The difference with `Finset.prod_bij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.prod_nbij` is that the bijection is allowed to use membership of the domain of the product, rather than being a non-dependent function. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_bij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.sum_nbij` is that the bijection is allowed to use membership of the domain of the sum, rather than being a non-dependent function."] theorem prod_bij (i : ∀ a ∈ s, κ) (hi : ∀ a ha, i a ha ∈ t) (i_inj : ∀ a₁ ha₁ a₂ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀ b ∈ t, ∃ a ha, i a ha = b) (h : ∀ a ha, f a = g (i a ha)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := congr_arg Multiset.prod (Multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi i_inj i_surj h) #align finset.prod_bij Finset.prod_bij #align finset.sum_bij Finset.sum_bij /-- Reorder a product. The difference with `Finset.prod_bij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.prod_nbij'` is that the bijection and its inverse are allowed to use membership of the domains of the products, rather than being non-dependent functions. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_bij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.sum_nbij'` is that the bijection and its inverse are allowed to use membership of the domains of the sums, rather than being non-dependent functions."] theorem prod_bij' (i : ∀ a ∈ s, κ) (j : ∀ a ∈ t, ι) (hi : ∀ a ha, i a ha ∈ t) (hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a) (right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) (h : ∀ a ha, f a = g (i a ha)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := by refine prod_bij i hi (fun a1 h1 a2 h2 eq ↦ ?_) (fun b hb ↦ ⟨_, hj b hb, right_inv b hb⟩) h rw [← left_inv a1 h1, ← left_inv a2 h2] simp only [eq] #align finset.prod_bij' Finset.prod_bij' #align finset.sum_bij' Finset.sum_bij' /-- Reorder a product. The difference with `Finset.prod_nbij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.prod_bij` is that the bijection is a non-dependent function, rather than being allowed to use membership of the domain of the product. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_nbij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.sum_bij` is that the bijection is a non-dependent function, rather than being allowed to use membership of the domain of the sum."] lemma prod_nbij (i : ι → κ) (hi : ∀ a ∈ s, i a ∈ t) (i_inj : (s : Set ι).InjOn i) (i_surj : (s : Set ι).SurjOn i t) (h : ∀ a ∈ s, f a = g (i a)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := prod_bij (fun a _ ↦ i a) hi i_inj (by simpa using i_surj) h /-- Reorder a product. The difference with `Finset.prod_nbij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.prod_bij'` is that the bijection and its inverse are non-dependent functions, rather than being allowed to use membership of the domains of the products. The difference with `Finset.prod_equiv` is that bijectivity is only required to hold on the domains of the products, rather than on the entire types. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_nbij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.sum_bij'` is that the bijection and its inverse are non-dependent functions, rather than being allowed to use membership of the domains of the sums. The difference with `Finset.sum_equiv` is that bijectivity is only required to hold on the domains of the sums, rather than on the entire types."] lemma prod_nbij' (i : ι → κ) (j : κ → ι) (hi : ∀ a ∈ s, i a ∈ t) (hj : ∀ a ∈ t, j a ∈ s) (left_inv : ∀ a ∈ s, j (i a) = a) (right_inv : ∀ a ∈ t, i (j a) = a) (h : ∀ a ∈ s, f a = g (i a)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := prod_bij' (fun a _ ↦ i a) (fun b _ ↦ j b) hi hj left_inv right_inv h /-- Specialization of `Finset.prod_nbij'` that automatically fills in most arguments. See `Fintype.prod_equiv` for the version where `s` and `t` are `univ`. -/ @[to_additive "`Specialization of `Finset.sum_nbij'` that automatically fills in most arguments. See `Fintype.sum_equiv` for the version where `s` and `t` are `univ`."] lemma prod_equiv (e : ι ≃ κ) (hst : ∀ i, i ∈ s ↔ e i ∈ t) (hfg : ∀ i ∈ s, f i = g (e i)) : ∏ i ∈ s, f i = ∏ i ∈ t, g i := by refine prod_nbij' e e.symm ?_ ?_ ?_ ?_ hfg <;> simp [hst] #align finset.equiv.prod_comp_finset Finset.prod_equiv #align finset.equiv.sum_comp_finset Finset.sum_equiv /-- Specialization of `Finset.prod_bij` that automatically fills in most arguments. See `Fintype.prod_bijective` for the version where `s` and `t` are `univ`. -/ @[to_additive "`Specialization of `Finset.sum_bij` that automatically fills in most arguments. See `Fintype.sum_bijective` for the version where `s` and `t` are `univ`."] lemma prod_bijective (e : ι → κ) (he : e.Bijective) (hst : ∀ i, i ∈ s ↔ e i ∈ t) (hfg : ∀ i ∈ s, f i = g (e i)) : ∏ i ∈ s, f i = ∏ i ∈ t, g i := prod_equiv (.ofBijective e he) hst hfg @[to_additive] lemma prod_of_injOn (e : ι → κ) (he : Set.InjOn e s) (hest : Set.MapsTo e s t) (h' : ∀ i ∈ t, i ∉ e '' s → g i = 1) (h : ∀ i ∈ s, f i = g (e i)) : ∏ i ∈ s, f i = ∏ j ∈ t, g j := by classical exact (prod_nbij e (fun a ↦ mem_image_of_mem e) he (by simp [Set.surjOn_image]) h).trans <| prod_subset (image_subset_iff.2 hest) <| by simpa using h' variable [DecidableEq κ] @[to_additive] lemma prod_fiberwise_eq_prod_filter (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : ι → α) : ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f i := by rw [← prod_disjiUnion, disjiUnion_filter_eq] @[to_additive] lemma prod_fiberwise_eq_prod_filter' (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : κ → α) : ∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f (g i) := by calc _ = ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f (g i) := prod_congr rfl fun j _ ↦ prod_congr rfl fun i hi ↦ by rw [(mem_filter.1 hi).2] _ = _ := prod_fiberwise_eq_prod_filter _ _ _ _ @[to_additive] lemma prod_fiberwise_of_maps_to {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : ι → α) : ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i := by rw [← prod_disjiUnion, disjiUnion_filter_eq_of_maps_to h] #align finset.prod_fiberwise_of_maps_to Finset.prod_fiberwise_of_maps_to #align finset.sum_fiberwise_of_maps_to Finset.sum_fiberwise_of_maps_to @[to_additive] lemma prod_fiberwise_of_maps_to' {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : κ → α) : ∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) := by calc _ = ∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f (g x) := prod_congr rfl fun y _ ↦ prod_congr rfl fun x hx ↦ by rw [(mem_filter.1 hx).2] _ = _ := prod_fiberwise_of_maps_to h _ variable [Fintype κ] @[to_additive] lemma prod_fiberwise (s : Finset ι) (g : ι → κ) (f : ι → α) : ∏ j, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i := prod_fiberwise_of_maps_to (fun _ _ ↦ mem_univ _) _ #align finset.prod_fiberwise Finset.prod_fiberwise #align finset.sum_fiberwise Finset.sum_fiberwise @[to_additive] lemma prod_fiberwise' (s : Finset ι) (g : ι → κ) (f : κ → α) : ∏ j, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) := prod_fiberwise_of_maps_to' (fun _ _ ↦ mem_univ _) _ end bij /-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and `Fintype.piFinset t` is a `Finset (Π a, t a)`. -/ @[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over `Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and `Fintype.piFinset t` is a `Finset (Π a, t a)`."] lemma prod_univ_pi [DecidableEq ι] [Fintype ι] {κ : ι → Type*} (t : ∀ i, Finset (κ i)) (f : (∀ i ∈ (univ : Finset ι), κ i) → β) : ∏ x ∈ univ.pi t, f x = ∏ x ∈ Fintype.piFinset t, f fun a _ ↦ x a := by apply prod_nbij' (fun x i ↦ x i $ mem_univ _) (fun x i _ ↦ x i) <;> simp #align finset.prod_univ_pi Finset.prod_univ_pi #align finset.sum_univ_pi Finset.sum_univ_pi @[to_additive (attr := simp)] lemma prod_diag [DecidableEq α] (s : Finset α) (f : α × α → β) : ∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i) := by apply prod_nbij' Prod.fst (fun i ↦ (i, i)) <;> simp @[to_additive] theorem prod_finset_product (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ × α → β} : ∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (c, a) := by refine Eq.trans ?_ (prod_sigma s t fun p => f (p.1, p.2)) apply prod_equiv (Equiv.sigmaEquivProd _ _).symm <;> simp [h] #align finset.prod_finset_product Finset.prod_finset_product #align finset.sum_finset_product Finset.sum_finset_product @[to_additive] theorem prod_finset_product' (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ → α → β} : ∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f c a := prod_finset_product r s t h #align finset.prod_finset_product' Finset.prod_finset_product' #align finset.sum_finset_product' Finset.sum_finset_product' @[to_additive] theorem prod_finset_product_right (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α × γ → β} : ∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (a, c) := by refine Eq.trans ?_ (prod_sigma s t fun p => f (p.2, p.1)) apply prod_equiv ((Equiv.prodComm _ _).trans (Equiv.sigmaEquivProd _ _).symm) <;> simp [h] #align finset.prod_finset_product_right Finset.prod_finset_product_right #align finset.sum_finset_product_right Finset.sum_finset_product_right @[to_additive] theorem prod_finset_product_right' (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α → γ → β} : ∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f a c := prod_finset_product_right r s t h #align finset.prod_finset_product_right' Finset.prod_finset_product_right' #align finset.sum_finset_product_right' Finset.sum_finset_product_right' @[to_additive] theorem prod_image' [DecidableEq α] {s : Finset γ} {g : γ → α} (h : γ → β) (eq : ∀ c ∈ s, f (g c) = ∏ x ∈ s.filter fun c' => g c' = g c, h x) : ∏ x ∈ s.image g, f x = ∏ x ∈ s, h x := calc ∏ x ∈ s.image g, f x = ∏ x ∈ s.image g, ∏ x ∈ s.filter fun c' => g c' = x, h x := (prod_congr rfl) fun _x hx => let ⟨c, hcs, hc⟩ := mem_image.1 hx hc ▸ eq c hcs _ = ∏ x ∈ s, h x := prod_fiberwise_of_maps_to (fun _x => mem_image_of_mem g) _ #align finset.prod_image' Finset.prod_image' #align finset.sum_image' Finset.sum_image' @[to_additive] theorem prod_mul_distrib : ∏ x ∈ s, f x * g x = (∏ x ∈ s, f x) * ∏ x ∈ s, g x := Eq.trans (by rw [one_mul]; rfl) fold_op_distrib #align finset.prod_mul_distrib Finset.prod_mul_distrib #align finset.sum_add_distrib Finset.sum_add_distrib @[to_additive] lemma prod_mul_prod_comm (f g h i : α → β) : (∏ a ∈ s, f a * g a) * ∏ a ∈ s, h a * i a = (∏ a ∈ s, f a * h a) * ∏ a ∈ s, g a * i a := by simp_rw [prod_mul_distrib, mul_mul_mul_comm] @[to_additive] theorem prod_product {s : Finset γ} {t : Finset α} {f : γ × α → β} : ∏ x ∈ s ×ˢ t, f x = ∏ x ∈ s, ∏ y ∈ t, f (x, y) := prod_finset_product (s ×ˢ t) s (fun _a => t) fun _p => mem_product #align finset.prod_product Finset.prod_product #align finset.sum_product Finset.sum_product /-- An uncurried version of `Finset.prod_product`. -/ @[to_additive "An uncurried version of `Finset.sum_product`"] theorem prod_product' {s : Finset γ} {t : Finset α} {f : γ → α → β} : ∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ x ∈ s, ∏ y ∈ t, f x y := prod_product #align finset.prod_product' Finset.prod_product' #align finset.sum_product' Finset.sum_product' @[to_additive] theorem prod_product_right {s : Finset γ} {t : Finset α} {f : γ × α → β} : ∏ x ∈ s ×ˢ t, f x = ∏ y ∈ t, ∏ x ∈ s, f (x, y) := prod_finset_product_right (s ×ˢ t) t (fun _a => s) fun _p => mem_product.trans and_comm #align finset.prod_product_right Finset.prod_product_right #align finset.sum_product_right Finset.sum_product_right /-- An uncurried version of `Finset.prod_product_right`. -/ @[to_additive "An uncurried version of `Finset.sum_product_right`"] theorem prod_product_right' {s : Finset γ} {t : Finset α} {f : γ → α → β} : ∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ y ∈ t, ∏ x ∈ s, f x y := prod_product_right #align finset.prod_product_right' Finset.prod_product_right' #align finset.sum_product_right' Finset.sum_product_right' /-- Generalization of `Finset.prod_comm` to the case when the inner `Finset`s depend on the outer variable. -/ @[to_additive "Generalization of `Finset.sum_comm` to the case when the inner `Finset`s depend on the outer variable."] theorem prod_comm' {s : Finset γ} {t : γ → Finset α} {t' : Finset α} {s' : α → Finset γ} (h : ∀ x y, x ∈ s ∧ y ∈ t x ↔ x ∈ s' y ∧ y ∈ t') {f : γ → α → β} : (∏ x ∈ s, ∏ y ∈ t x, f x y) = ∏ y ∈ t', ∏ x ∈ s' y, f x y := by classical have : ∀ z : γ × α, (z ∈ s.biUnion fun x => (t x).map <| Function.Embedding.sectr x _) ↔ z.1 ∈ s ∧ z.2 ∈ t z.1 := by rintro ⟨x, y⟩ simp only [mem_biUnion, mem_map, Function.Embedding.sectr_apply, Prod.mk.injEq, exists_eq_right, ← and_assoc] exact (prod_finset_product' _ _ _ this).symm.trans ((prod_finset_product_right' _ _ _) fun ⟨x, y⟩ => (this _).trans ((h x y).trans and_comm)) #align finset.prod_comm' Finset.prod_comm' #align finset.sum_comm' Finset.sum_comm' @[to_additive] theorem prod_comm {s : Finset γ} {t : Finset α} {f : γ → α → β} : (∏ x ∈ s, ∏ y ∈ t, f x y) = ∏ y ∈ t, ∏ x ∈ s, f x y := prod_comm' fun _ _ => Iff.rfl #align finset.prod_comm Finset.prod_comm #align finset.sum_comm Finset.sum_comm @[to_additive] theorem prod_hom_rel [CommMonoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : Finset α} (h₁ : r 1 1) (h₂ : ∀ a b c, r b c → r (f a * b) (g a * c)) : r (∏ x ∈ s, f x) (∏ x ∈ s, g x) := by delta Finset.prod apply Multiset.prod_hom_rel <;> assumption #align finset.prod_hom_rel Finset.prod_hom_rel #align finset.sum_hom_rel Finset.sum_hom_rel @[to_additive] theorem prod_filter_of_ne {p : α → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) : ∏ x ∈ s.filter p, f x = ∏ x ∈ s, f x := (prod_subset (filter_subset _ _)) fun x => by classical rw [not_imp_comm, mem_filter] exact fun h₁ h₂ => ⟨h₁, by simpa using hp _ h₁ h₂⟩ #align finset.prod_filter_of_ne Finset.prod_filter_of_ne #align finset.sum_filter_of_ne Finset.sum_filter_of_ne -- If we use `[DecidableEq β]` here, some rewrites fail because they find a wrong `Decidable` -- instance first; `{∀ x, Decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one` @[to_additive] theorem prod_filter_ne_one (s : Finset α) [∀ x, Decidable (f x ≠ 1)] : ∏ x ∈ s.filter fun x => f x ≠ 1, f x = ∏ x ∈ s, f x := prod_filter_of_ne fun _ _ => id #align finset.prod_filter_ne_one Finset.prod_filter_ne_one #align finset.sum_filter_ne_zero Finset.sum_filter_ne_zero @[to_additive] theorem prod_filter (p : α → Prop) [DecidablePred p] (f : α → β) : ∏ a ∈ s.filter p, f a = ∏ a ∈ s, if p a then f a else 1 := calc ∏ a ∈ s.filter p, f a = ∏ a ∈ s.filter p, if p a then f a else 1 := prod_congr rfl fun a h => by rw [if_pos]; simpa using (mem_filter.1 h).2 _ = ∏ a ∈ s, if p a then f a else 1 := by { refine prod_subset (filter_subset _ s) fun x hs h => ?_ rw [mem_filter, not_and] at h exact if_neg (by simpa using h hs) } #align finset.prod_filter Finset.prod_filter #align finset.sum_filter Finset.sum_filter @[to_additive] theorem prod_eq_single_of_mem {s : Finset α} {f : α → β} (a : α) (h : a ∈ s) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : ∏ x ∈ s, f x = f a := by haveI := Classical.decEq α calc ∏ x ∈ s, f x = ∏ x ∈ {a}, f x := by { refine (prod_subset ?_ ?_).symm · intro _ H rwa [mem_singleton.1 H] · simpa only [mem_singleton] } _ = f a := prod_singleton _ _ #align finset.prod_eq_single_of_mem Finset.prod_eq_single_of_mem #align finset.sum_eq_single_of_mem Finset.sum_eq_single_of_mem @[to_additive] theorem prod_eq_single {s : Finset α} {f : α → β} (a : α) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : ∏ x ∈ s, f x = f a := haveI := Classical.decEq α by_cases (prod_eq_single_of_mem a · h₀) fun this => (prod_congr rfl fun b hb => h₀ b hb <| by rintro rfl; exact this hb).trans <| prod_const_one.trans (h₁ this).symm #align finset.prod_eq_single Finset.prod_eq_single #align finset.sum_eq_single Finset.sum_eq_single @[to_additive] lemma prod_union_eq_left [DecidableEq α] (hs : ∀ a ∈ s₂, a ∉ s₁ → f a = 1) : ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₁, f a := Eq.symm <| prod_subset subset_union_left fun _a ha ha' ↦ hs _ ((mem_union.1 ha).resolve_left ha') ha' @[to_additive] lemma prod_union_eq_right [DecidableEq α] (hs : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) : ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₂, f a := by rw [union_comm, prod_union_eq_left hs] @[to_additive] theorem prod_eq_mul_of_mem {s : Finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s) (hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : ∏ x ∈ s, f x = f a * f b := by haveI := Classical.decEq α; let s' := ({a, b} : Finset α) have hu : s' ⊆ s := by refine insert_subset_iff.mpr ?_ apply And.intro ha apply singleton_subset_iff.mpr hb have hf : ∀ c ∈ s, c ∉ s' → f c = 1 := by intro c hc hcs apply h₀ c hc apply not_or.mp intro hab apply hcs rw [mem_insert, mem_singleton] exact hab rw [← prod_subset hu hf] exact Finset.prod_pair hn #align finset.prod_eq_mul_of_mem Finset.prod_eq_mul_of_mem #align finset.sum_eq_add_of_mem Finset.sum_eq_add_of_mem @[to_additive] theorem prod_eq_mul {s : Finset α} {f : α → β} (a b : α) (hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) : ∏ x ∈ s, f x = f a * f b := by haveI := Classical.decEq α; by_cases h₁ : a ∈ s <;> by_cases h₂ : b ∈ s · exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀ · rw [hb h₂, mul_one] apply prod_eq_single_of_mem a h₁ exact fun c hc hca => h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩ · rw [ha h₁, one_mul] apply prod_eq_single_of_mem b h₂ exact fun c hc hcb => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩ · rw [ha h₁, hb h₂, mul_one] exact _root_.trans (prod_congr rfl fun c hc => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩) prod_const_one #align finset.prod_eq_mul Finset.prod_eq_mul #align finset.sum_eq_add Finset.sum_eq_add -- Porting note: simpNF linter complains that LHS doesn't simplify, but it does /-- A product over `s.subtype p` equals one over `s.filter p`. -/ @[to_additive (attr := simp, nolint simpNF) "A sum over `s.subtype p` equals one over `s.filter p`."] theorem prod_subtype_eq_prod_filter (f : α → β) {p : α → Prop} [DecidablePred p] : ∏ x ∈ s.subtype p, f x = ∏ x ∈ s.filter p, f x := by conv_lhs => erw [← prod_map (s.subtype p) (Function.Embedding.subtype _) f] exact prod_congr (subtype_map _) fun x _hx => rfl #align finset.prod_subtype_eq_prod_filter Finset.prod_subtype_eq_prod_filter #align finset.sum_subtype_eq_sum_filter Finset.sum_subtype_eq_sum_filter /-- If all elements of a `Finset` satisfy the predicate `p`, a product over `s.subtype p` equals that product over `s`. -/ @[to_additive "If all elements of a `Finset` satisfy the predicate `p`, a sum over `s.subtype p` equals that sum over `s`."] theorem prod_subtype_of_mem (f : α → β) {p : α → Prop} [DecidablePred p] (h : ∀ x ∈ s, p x) : ∏ x ∈ s.subtype p, f x = ∏ x ∈ s, f x := by rw [prod_subtype_eq_prod_filter, filter_true_of_mem] simpa using h #align finset.prod_subtype_of_mem Finset.prod_subtype_of_mem #align finset.sum_subtype_of_mem Finset.sum_subtype_of_mem /-- A product of a function over a `Finset` in a subtype equals a product in the main type of a function that agrees with the first function on that `Finset`. -/ @[to_additive "A sum of a function over a `Finset` in a subtype equals a sum in the main type of a function that agrees with the first function on that `Finset`."] theorem prod_subtype_map_embedding {p : α → Prop} {s : Finset { x // p x }} {f : { x // p x } → β} {g : α → β} (h : ∀ x : { x // p x }, x ∈ s → g x = f x) : (∏ x ∈ s.map (Function.Embedding.subtype _), g x) = ∏ x ∈ s, f x := by rw [Finset.prod_map] exact Finset.prod_congr rfl h #align finset.prod_subtype_map_embedding Finset.prod_subtype_map_embedding #align finset.sum_subtype_map_embedding Finset.sum_subtype_map_embedding variable (f s) @[to_additive] theorem prod_coe_sort_eq_attach (f : s → β) : ∏ i : s, f i = ∏ i ∈ s.attach, f i := rfl #align finset.prod_coe_sort_eq_attach Finset.prod_coe_sort_eq_attach #align finset.sum_coe_sort_eq_attach Finset.sum_coe_sort_eq_attach @[to_additive] theorem prod_coe_sort : ∏ i : s, f i = ∏ i ∈ s, f i := prod_attach _ _ #align finset.prod_coe_sort Finset.prod_coe_sort #align finset.sum_coe_sort Finset.sum_coe_sort @[to_additive] theorem prod_finset_coe (f : α → β) (s : Finset α) : (∏ i : (s : Set α), f i) = ∏ i ∈ s, f i := prod_coe_sort s f #align finset.prod_finset_coe Finset.prod_finset_coe #align finset.sum_finset_coe Finset.sum_finset_coe variable {f s} @[to_additive] theorem prod_subtype {p : α → Prop} {F : Fintype (Subtype p)} (s : Finset α) (h : ∀ x, x ∈ s ↔ p x) (f : α → β) : ∏ a ∈ s, f a = ∏ a : Subtype p, f a := by have : (· ∈ s) = p := Set.ext h subst p rw [← prod_coe_sort] congr! #align finset.prod_subtype Finset.prod_subtype #align finset.sum_subtype Finset.sum_subtype @[to_additive] lemma prod_preimage' (f : ι → κ) [DecidablePred (· ∈ Set.range f)] (s : Finset κ) (hf) (g : κ → β) : ∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s.filter (· ∈ Set.range f), g x := by classical calc ∏ x ∈ preimage s f hf, g (f x) = ∏ x ∈ image f (preimage s f hf), g x := Eq.symm <| prod_image <| by simpa only [mem_preimage, Set.InjOn] using hf _ = ∏ x ∈ s.filter fun x => x ∈ Set.range f, g x := by rw [image_preimage] #align finset.prod_preimage' Finset.prod_preimage' #align finset.sum_preimage' Finset.sum_preimage' @[to_additive] lemma prod_preimage (f : ι → κ) (s : Finset κ) (hf) (g : κ → β) (hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) : ∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s, g x := by classical rw [prod_preimage', prod_filter_of_ne]; exact fun x hx ↦ Not.imp_symm (hg x hx) #align finset.prod_preimage Finset.prod_preimage #align finset.sum_preimage Finset.sum_preimage @[to_additive] lemma prod_preimage_of_bij (f : ι → κ) (s : Finset κ) (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) (g : κ → β) : ∏ x ∈ s.preimage f hf.injOn, g (f x) = ∏ x ∈ s, g x := prod_preimage _ _ hf.injOn g fun _ hs h_f ↦ (h_f <| hf.subset_range hs).elim #align finset.prod_preimage_of_bij Finset.prod_preimage_of_bij #align finset.sum_preimage_of_bij Finset.sum_preimage_of_bij @[to_additive] theorem prod_set_coe (s : Set α) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i := (Finset.prod_subtype s.toFinset (fun _ ↦ Set.mem_toFinset) f).symm /-- The product of a function `g` defined only on a set `s` is equal to the product of a function `f` defined everywhere, as long as `f` and `g` agree on `s`, and `f = 1` off `s`. -/ @[to_additive "The sum of a function `g` defined only on a set `s` is equal to the sum of a function `f` defined everywhere, as long as `f` and `g` agree on `s`, and `f = 0` off `s`."] theorem prod_congr_set {α : Type*} [CommMonoid α] {β : Type*} [Fintype β] (s : Set β) [DecidablePred (· ∈ s)] (f : β → α) (g : s → α) (w : ∀ (x : β) (h : x ∈ s), f x = g ⟨x, h⟩) (w' : ∀ x : β, x ∉ s → f x = 1) : Finset.univ.prod f = Finset.univ.prod g := by rw [← @Finset.prod_subset _ _ s.toFinset Finset.univ f _ (by simp)] · rw [Finset.prod_subtype] · apply Finset.prod_congr rfl exact fun ⟨x, h⟩ _ => w x h · simp · rintro x _ h exact w' x (by simpa using h) #align finset.prod_congr_set Finset.prod_congr_set #align finset.sum_congr_set Finset.sum_congr_set @[to_additive] theorem prod_apply_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} [DecidablePred fun x => ¬p x] (f : ∀ x : α, p x → γ) (g : ∀ x : α, ¬p x → γ) (h : γ → β) : (∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) = (∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) * ∏ x ∈ (s.filter fun x => ¬p x).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) := calc (∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) = (∏ x ∈ s.filter p, h (if hx : p x then f x hx else g x hx)) * ∏ x ∈ s.filter (¬p ·), h (if hx : p x then f x hx else g x hx) := (prod_filter_mul_prod_filter_not s p _).symm _ = (∏ x ∈ (s.filter p).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) * ∏ x ∈ (s.filter (¬p ·)).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx) := congr_arg₂ _ (prod_attach _ _).symm (prod_attach _ _).symm _ = (∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) * ∏ x ∈ (s.filter (¬p ·)).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) := congr_arg₂ _ (prod_congr rfl fun x _hx ↦ congr_arg h (dif_pos <| by simpa using (mem_filter.mp x.2).2)) (prod_congr rfl fun x _hx => congr_arg h (dif_neg <| by simpa using (mem_filter.mp x.2).2)) #align finset.prod_apply_dite Finset.prod_apply_dite #align finset.sum_apply_dite Finset.sum_apply_dite @[to_additive] theorem prod_apply_ite {s : Finset α} {p : α → Prop} {_hp : DecidablePred p} (f g : α → γ) (h : γ → β) : (∏ x ∈ s, h (if p x then f x else g x)) = (∏ x ∈ s.filter p, h (f x)) * ∏ x ∈ s.filter fun x => ¬p x, h (g x) := (prod_apply_dite _ _ _).trans <| congr_arg₂ _ (prod_attach _ (h ∘ f)) (prod_attach _ (h ∘ g)) #align finset.prod_apply_ite Finset.prod_apply_ite #align finset.sum_apply_ite Finset.sum_apply_ite @[to_additive] theorem prod_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) : ∏ x ∈ s, (if hx : p x then f x hx else g x hx) = (∏ x ∈ (s.filter p).attach, f x.1 (by simpa using (mem_filter.mp x.2).2)) * ∏ x ∈ (s.filter fun x => ¬p x).attach, g x.1 (by simpa using (mem_filter.mp x.2).2) := by simp [prod_apply_dite _ _ fun x => x] #align finset.prod_dite Finset.prod_dite #align finset.sum_dite Finset.sum_dite @[to_additive] theorem prod_ite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f g : α → β) : ∏ x ∈ s, (if p x then f x else g x) = (∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, g x := by simp [prod_apply_ite _ _ fun x => x] #align finset.prod_ite Finset.prod_ite #align finset.sum_ite Finset.sum_ite @[to_additive]
Mathlib/Algebra/BigOperators/Group/Finset.lean
1,222
1,226
theorem prod_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, ¬p x) : ∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, g x := by
rw [prod_ite, filter_false_of_mem, filter_true_of_mem] · simp only [prod_empty, one_mul] all_goals intros; apply h; assumption
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Shing Tak Lam, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Log import Mathlib.Data.List.Indexes import Mathlib.Data.List.Palindrome import Mathlib.Tactic.IntervalCases import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring #align_import data.nat.digits from "leanprover-community/mathlib"@"369525b73f229ccd76a6ec0e0e0bf2be57599768" /-! # Digits of a natural number This provides a basic API for extracting the digits of a natural number in a given base, and reconstructing numbers from their digits. We also prove some divisibility tests based on digits, in particular completing Theorem #85 from https://www.cs.ru.nl/~freek/100/. Also included is a bound on the length of `Nat.toDigits` from core. ## TODO A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b` are numerals is not yet ported. -/ namespace Nat variable {n : ℕ} /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux0 : ℕ → List ℕ | 0 => [] | n + 1 => [n + 1] #align nat.digits_aux_0 Nat.digitsAux0 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux1 (n : ℕ) : List ℕ := List.replicate n 1 #align nat.digits_aux_1 Nat.digitsAux1 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ | 0 => [] | n + 1 => ((n + 1) % b) :: digitsAux b h ((n + 1) / b) decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h #align nat.digits_aux Nat.digitsAux @[simp] theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux] #align nat.digits_aux_zero Nat.digitsAux_zero theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) : digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by cases n · cases w · rw [digitsAux] #align nat.digits_aux_def Nat.digitsAux_def /-- `digits b n` gives the digits, in little-endian order, of a natural number `n` in a specified base `b`. In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`. * For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`, and the last digit is not zero. This uniquely specifies the behaviour of `digits b`. * For `b = 1`, we define `digits 1 n = List.replicate n 1`. * For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`. Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals. In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`. -/ def digits : ℕ → ℕ → List ℕ | 0 => digitsAux0 | 1 => digitsAux1 | b + 2 => digitsAux (b + 2) (by norm_num) #align nat.digits Nat.digits @[simp] theorem digits_zero (b : ℕ) : digits b 0 = [] := by rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1] #align nat.digits_zero Nat.digits_zero -- @[simp] -- Porting note (#10618): simp can prove this theorem digits_zero_zero : digits 0 0 = [] := rfl #align nat.digits_zero_zero Nat.digits_zero_zero @[simp] theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] := rfl #align nat.digits_zero_succ Nat.digits_zero_succ theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n] | 0, h => (h rfl).elim | _ + 1, _ => rfl #align nat.digits_zero_succ' Nat.digits_zero_succ' @[simp] theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 := rfl #align nat.digits_one Nat.digits_one -- @[simp] -- Porting note (#10685): dsimp can prove this theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n := rfl #align nat.digits_one_succ Nat.digits_one_succ theorem digits_add_two_add_one (b n : ℕ) : digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by simp [digits, digitsAux_def] #align nat.digits_add_two_add_one Nat.digits_add_two_add_one @[simp] lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) : Nat.digits b n = n % b :: Nat.digits b (n / b) := by rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one] theorem digits_def' : ∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b) | 0, h => absurd h (by decide) | 1, h => absurd h (by decide) | b + 2, _ => digitsAux_def _ (by simp) _ #align nat.digits_def' Nat.digits_def' @[simp] theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩ rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩ rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb] #align nat.digits_of_lt Nat.digits_of_lt theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) : digits b (x + b * y) = x :: digits b y := by rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩ cases y · simp [hxb, hxy.resolve_right (absurd rfl)] dsimp [digits] rw [digitsAux_def] · congr · simp [Nat.add_mod, mod_eq_of_lt hxb] · simp [add_mul_div_left, div_eq_of_lt hxb] · apply Nat.succ_pos #align nat.digits_add Nat.digits_add -- If we had a function converting a list into a polynomial, -- and appropriate lemmas about that function, -- we could rewrite this in terms of that. /-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them as a number in semiring, as the little-endian digits in base `b`. -/ def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α | [] => 0 | h :: t => h + b * ofDigits b t #align nat.of_digits Nat.ofDigits theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) : ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by induction' L with d L ih · rfl · dsimp [ofDigits] rw [ih] #align nat.of_digits_eq_foldr Nat.ofDigits_eq_foldr theorem ofDigits_eq_sum_map_with_index_aux (b : ℕ) (l : List ℕ) : ((List.range l.length).zipWith ((fun i a : ℕ => a * b ^ (i + 1))) l).sum = b * ((List.range l.length).zipWith (fun i a => a * b ^ i) l).sum := by suffices (List.range l.length).zipWith (fun i a : ℕ => a * b ^ (i + 1)) l = (List.range l.length).zipWith (fun i a => b * (a * b ^ i)) l by simp [this] congr; ext; simp [pow_succ]; ring #align nat.of_digits_eq_sum_map_with_index_aux Nat.ofDigits_eq_sum_map_with_index_aux theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) : ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by rw [List.mapIdx_eq_enum_map, List.enum_eq_zip_range, List.map_uncurry_zip_eq_zipWith, ofDigits_eq_foldr] induction' L with hd tl hl · simp · simpa [List.range_succ_eq_map, List.zipWith_map_left, ofDigits_eq_sum_map_with_index_aux] using Or.inl hl #align nat.of_digits_eq_sum_map_with_index Nat.ofDigits_eq_sum_mapIdx @[simp] theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl @[simp] theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits] #align nat.of_digits_singleton Nat.ofDigits_singleton @[simp] theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) : ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits] #align nat.of_digits_one_cons Nat.ofDigits_one_cons theorem ofDigits_cons {b hd} {tl : List ℕ} : ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} : ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by induction' l1 with hd tl IH · simp [ofDigits] · rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ'] ring #align nat.of_digits_append Nat.ofDigits_append @[norm_cast] theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by induction' L with d L ih · simp [ofDigits] · dsimp [ofDigits]; push_cast; rw [ih] #align nat.coe_of_digits Nat.coe_ofDigits @[norm_cast] theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by induction' L with d L _ · rfl · dsimp [ofDigits]; push_cast; simp only #align nat.coe_int_of_digits Nat.coe_int_ofDigits theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) : ∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0 | _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0 | _ :: _, h0, _, List.Mem.tail _ hL => digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL #align nat.digits_zero_of_eq_zero Nat.digits_zero_of_eq_zero theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b) (w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by induction' L with d L ih · dsimp [ofDigits] simp · dsimp [ofDigits] replace w₂ := w₂ (by simp) rw [digits_add b h] · rw [ih] · intro l m apply w₁ exact List.mem_cons_of_mem _ m · intro h rw [List.getLast_cons h] at w₂ convert w₂ · exact w₁ d (List.mem_cons_self _ _) · by_cases h' : L = [] · rcases h' with rfl left simpa using w₂ · right contrapose! w₂ refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_ rw [List.getLast_cons h'] exact List.getLast_mem h' #align nat.digits_of_digits Nat.digits_ofDigits theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by cases' b with b · cases' n with n · rfl · change ofDigits 0 [n + 1] = n + 1 dsimp [ofDigits] · cases' b with b · induction' n with n ih · rfl · rw [Nat.zero_add] at ih ⊢ simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ] · apply Nat.strongInductionOn n _ clear n intro n h cases n · rw [digits_zero] rfl · simp only [Nat.succ_eq_add_one, digits_add_two_add_one] dsimp [ofDigits] rw [h _ (Nat.div_lt_self' _ b)] rw [Nat.mod_add_div] #align nat.of_digits_digits Nat.ofDigits_digits theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by induction' L with _ _ ih · rfl · simp [ofDigits, List.sum_cons, ih] #align nat.of_digits_one Nat.ofDigits_one /-! ### Properties This section contains various lemmas of properties relating to `digits` and `ofDigits`. -/ theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by constructor · intro h have : ofDigits b (digits b n) = ofDigits b [] := by rw [h] convert this rw [ofDigits_digits] · rintro rfl simp #align nat.digits_eq_nil_iff_eq_zero Nat.digits_eq_nil_iff_eq_zero theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 := not_congr digits_eq_nil_iff_eq_zero #align nat.digits_ne_nil_iff_ne_zero Nat.digits_ne_nil_iff_ne_zero theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) : digits b n = (n % b) :: digits b (n / b) := by rcases b with (_ | _ | b) · rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero] · norm_num at h rcases n with (_ | n) · norm_num at w · simp only [digits_add_two_add_one, ne_eq] #align nat.digits_eq_cons_digits_div Nat.digits_eq_cons_digits_div theorem digits_getLast {b : ℕ} (m : ℕ) (h : 1 < b) (p q) : (digits b m).getLast p = (digits b (m / b)).getLast q := by by_cases hm : m = 0 · simp [hm] simp only [digits_eq_cons_digits_div h hm] rw [List.getLast_cons] #align nat.digits_last Nat.digits_getLast theorem digits.injective (b : ℕ) : Function.Injective b.digits := Function.LeftInverse.injective (ofDigits_digits b) #align nat.digits.injective Nat.digits.injective @[simp] theorem digits_inj_iff {b n m : ℕ} : b.digits n = b.digits m ↔ n = m := (digits.injective b).eq_iff #align nat.digits_inj_iff Nat.digits_inj_iff theorem digits_len (b n : ℕ) (hb : 1 < b) (hn : n ≠ 0) : (b.digits n).length = b.log n + 1 := by induction' n using Nat.strong_induction_on with n IH rw [digits_eq_cons_digits_div hb hn, List.length] by_cases h : n / b = 0 · have hb0 : b ≠ 0 := (Nat.succ_le_iff.1 hb).ne_bot simp [h, log_eq_zero_iff, ← Nat.div_eq_zero_iff hb0.bot_lt] · have : n / b < n := div_lt_self (Nat.pos_of_ne_zero hn) hb rw [IH _ this h, log_div_base, tsub_add_cancel_of_le] refine Nat.succ_le_of_lt (log_pos hb ?_) contrapose! h exact div_eq_of_lt h #align nat.digits_len Nat.digits_len theorem getLast_digit_ne_zero (b : ℕ) {m : ℕ} (hm : m ≠ 0) : (digits b m).getLast (digits_ne_nil_iff_ne_zero.mpr hm) ≠ 0 := by rcases b with (_ | _ | b) · cases m · cases hm rfl · simp · cases m · cases hm rfl rename ℕ => m simp only [zero_add, digits_one, List.getLast_replicate_succ m 1] exact Nat.one_ne_zero revert hm apply Nat.strongInductionOn m intro n IH hn by_cases hnb : n < b + 2 · simpa only [digits_of_lt (b + 2) n hn hnb] · rw [digits_getLast n (le_add_left 2 b)] refine IH _ (Nat.div_lt_self hn.bot_lt (one_lt_succ_succ b)) ?_ rw [← pos_iff_ne_zero] exact Nat.div_pos (le_of_not_lt hnb) (zero_lt_succ (succ b)) #align nat.last_digit_ne_zero Nat.getLast_digit_ne_zero theorem mul_ofDigits (n : ℕ) {b : ℕ} {l : List ℕ} : n * ofDigits b l = ofDigits b (l.map (n * ·)) := by induction l with | nil => rfl | cons hd tl ih => rw [List.map_cons, ofDigits_cons, ofDigits_cons, ← ih] ring /-- The addition of ofDigits of two lists is equal to ofDigits of digit-wise addition of them-/ theorem ofDigits_add_ofDigits_eq_ofDigits_zipWith_of_length_eq {b : ℕ} {l1 l2 : List ℕ} (h : l1.length = l2.length) : ofDigits b l1 + ofDigits b l2 = ofDigits b (l1.zipWith (· + ·) l2) := by induction l1 generalizing l2 with | nil => simp_all [eq_comm, List.length_eq_zero, ofDigits] | cons hd₁ tl₁ ih₁ => induction l2 generalizing tl₁ with | nil => simp_all | cons hd₂ tl₂ ih₂ => simp_all only [List.length_cons, succ_eq_add_one, ofDigits_cons, add_left_inj, eq_comm, List.zipWith_cons_cons, add_eq] rw [← ih₁ h.symm, mul_add] ac_rfl /-- The digits in the base b+2 expansion of n are all less than b+2 -/ theorem digits_lt_base' {b m : ℕ} : ∀ {d}, d ∈ digits (b + 2) m → d < b + 2 := by apply Nat.strongInductionOn m intro n IH d hd cases' n with n · rw [digits_zero] at hd cases hd -- base b+2 expansion of 0 has no digits rw [digits_add_two_add_one] at hd cases hd · exact n.succ.mod_lt (by simp) -- Porting note: Previous code (single line) contained linarith. -- . exact IH _ (Nat.div_lt_self (Nat.succ_pos _) (by linarith)) hd · apply IH ((n + 1) / (b + 2)) · apply Nat.div_lt_self <;> omega · assumption #align nat.digits_lt_base' Nat.digits_lt_base' /-- The digits in the base b expansion of n are all less than b, if b ≥ 2 -/ theorem digits_lt_base {b m d : ℕ} (hb : 1 < b) (hd : d ∈ digits b m) : d < b := by rcases b with (_ | _ | b) <;> try simp_all exact digits_lt_base' hd #align nat.digits_lt_base Nat.digits_lt_base /-- an n-digit number in base b + 2 is less than (b + 2)^n -/ theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) : ofDigits (b + 2) l < (b + 2) ^ l.length := by induction' l with hd tl IH · simp [ofDigits] · rw [ofDigits, List.length_cons, pow_succ] have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) := mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le]) (Nat.zero_le _) suffices ↑hd < b + 2 by linarith exact hl hd (List.mem_cons_self _ _) #align nat.of_digits_lt_base_pow_length' Nat.ofDigits_lt_base_pow_length' /-- an n-digit number in base b is less than b^n if b > 1 -/ theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) : ofDigits b l < b ^ l.length := by rcases b with (_ | _ | b) <;> try simp_all exact ofDigits_lt_base_pow_length' hl #align nat.of_digits_lt_base_pow_length Nat.ofDigits_lt_base_pow_length /-- Any number m is less than (b+2)^(number of digits in the base b + 2 representation of m) -/ theorem lt_base_pow_length_digits' {b m : ℕ} : m < (b + 2) ^ (digits (b + 2) m).length := by convert @ofDigits_lt_base_pow_length' b (digits (b + 2) m) fun _ => digits_lt_base' rw [ofDigits_digits (b + 2) m] #align nat.lt_base_pow_length_digits' Nat.lt_base_pow_length_digits' /-- Any number m is less than b^(number of digits in the base b representation of m) -/ theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by rcases b with (_ | _ | b) <;> try simp_all exact lt_base_pow_length_digits' #align nat.lt_base_pow_length_digits Nat.lt_base_pow_length_digits theorem ofDigits_digits_append_digits {b m n : ℕ} : ofDigits b (digits b n ++ digits b m) = n + b ^ (digits b n).length * m := by rw [ofDigits_append, ofDigits_digits, ofDigits_digits] #align nat.of_digits_digits_append_digits Nat.ofDigits_digits_append_digits theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) : digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb) · simp [List.replicate_add] rw [← ofDigits_digits_append_digits] refine (digits_ofDigits b hb _ (fun l hl => ?_) (fun h_append => ?_)).symm · rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h · by_cases h : digits b m = [] · simp only [h, List.append_nil] at h_append ⊢ exact getLast_digit_ne_zero b <| digits_ne_nil_iff_ne_zero.mp h_append · exact (List.getLast_append' _ _ h) ▸ (getLast_digit_ne_zero _ <| digits_ne_nil_iff_ne_zero.mp h) theorem digits_len_le_digits_len_succ (b n : ℕ) : (digits b n).length ≤ (digits b (n + 1)).length := by rcases Decidable.eq_or_ne n 0 with (rfl | hn) · simp rcases le_or_lt b 1 with hb | hb · interval_cases b <;> simp_arith [digits_zero_succ', hn] simpa [digits_len, hb, hn] using log_mono_right (le_succ _) #align nat.digits_len_le_digits_len_succ Nat.digits_len_le_digits_len_succ theorem le_digits_len_le (b n m : ℕ) (h : n ≤ m) : (digits b n).length ≤ (digits b m).length := monotone_nat_of_le_succ (digits_len_le_digits_len_succ b) h #align nat.le_digits_len_le Nat.le_digits_len_le @[mono] theorem ofDigits_monotone {p q : ℕ} (L : List ℕ) (h : p ≤ q) : ofDigits p L ≤ ofDigits q L := by induction' L with _ _ hi · rfl · simp only [ofDigits, cast_id, add_le_add_iff_left] exact Nat.mul_le_mul h hi theorem sum_le_ofDigits {p : ℕ} (L : List ℕ) (h : 1 ≤ p) : L.sum ≤ ofDigits p L := (ofDigits_one L).symm ▸ ofDigits_monotone L h theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by induction' n with n · exact digits_zero _ ▸ Nat.le_refl (List.sum []) · induction' p with p · rw [digits_zero_succ, List.sum_cons, List.sum_nil, add_zero] · nth_rw 2 [← ofDigits_digits p.succ (n + 1)] rw [← ofDigits_one <| digits p.succ n.succ] exact ofDigits_monotone (digits p.succ n.succ) <| Nat.succ_pos p theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) : (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by rw [← List.dropLast_append_getLast hl] simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append, List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one] apply Nat.mul_le_mul_left refine le_trans ?_ (Nat.le_add_left _ _) have : 0 < l.getLast hl := by rwa [pos_iff_ne_zero] convert Nat.mul_le_mul_left ((b + 2) ^ (l.length - 1)) this using 1 rw [Nat.mul_one] #align nat.pow_length_le_mul_of_digits Nat.pow_length_le_mul_ofDigits /-- Any non-zero natural number `m` is greater than (b+2)^((number of digits in the base (b+2) representation of m) - 1) -/ theorem base_pow_length_digits_le' (b m : ℕ) (hm : m ≠ 0) : (b + 2) ^ (digits (b + 2) m).length ≤ (b + 2) * m := by have : digits (b + 2) m ≠ [] := digits_ne_nil_iff_ne_zero.mpr hm convert @pow_length_le_mul_ofDigits b (digits (b+2) m) this (getLast_digit_ne_zero _ hm) rw [ofDigits_digits] #align nat.base_pow_length_digits_le' Nat.base_pow_length_digits_le' /-- Any non-zero natural number `m` is greater than b^((number of digits in the base b representation of m) - 1) -/ theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) : m ≠ 0 → b ^ (digits b m).length ≤ b * m := by rcases b with (_ | _ | b) <;> try simp_all exact base_pow_length_digits_le' b m #align nat.base_pow_length_digits_le Nat.base_pow_length_digits_le /-- Interpreting as a base `p` number and dividing by `p` is the same as interpreting the tail. -/ lemma ofDigits_div_eq_ofDigits_tail {p : ℕ} (hpos : 0 < p) (digits : List ℕ) (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p = ofDigits p digits.tail := by induction' digits with hd tl · simp [ofDigits] · refine Eq.trans (add_mul_div_left hd _ hpos) ?_ rw [Nat.div_eq_of_lt <| w₁ _ <| List.mem_cons_self _ _, zero_add] rfl /-- Interpreting as a base `p` number and dividing by `p^i` is the same as dropping `i`. -/ lemma ofDigits_div_pow_eq_ofDigits_drop {p : ℕ} (i : ℕ) (hpos : 0 < p) (digits : List ℕ) (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p ^ i = ofDigits p (digits.drop i) := by induction' i with i hi · simp · rw [Nat.pow_succ, ← Nat.div_div_eq_div_mul, hi, ofDigits_div_eq_ofDigits_tail hpos (List.drop i digits) fun x hx ↦ w₁ x <| List.mem_of_mem_drop hx, ← List.drop_one, List.drop_drop, add_comm] /-- Dividing `n` by `p^i` is like truncating the first `i` digits of `n` in base `p`. -/ lemma self_div_pow_eq_ofDigits_drop {p : ℕ} (i n : ℕ) (h : 2 ≤ p): n / p ^ i = ofDigits p ((p.digits n).drop i) := by convert ofDigits_div_pow_eq_ofDigits_drop i (zero_lt_of_lt h) (p.digits n) (fun l hl ↦ digits_lt_base h hl) exact (ofDigits_digits p n).symm open Finset theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits {p : ℕ} (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) : (p - 1) * ∑ i ∈ range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p · induction' L with hd tl ih · simp [ofDigits] · simp only [List.length_cons, List.sum_cons, self_div_pow_eq_ofDigits_drop _ _ h, digits_ofDigits p h (hd :: tl) h_lt (fun _ => h_ne_zero)] simp only [ofDigits] rw [sum_range_succ, Nat.cast_id] simp only [List.drop, List.drop_length] obtain rfl | h' := em <| tl = [] · simp [ofDigits] · have w₁' := fun l hl ↦ h_lt l <| List.mem_cons_of_mem hd hl have w₂' := fun (h : tl ≠ []) ↦ (List.getLast_cons h) ▸ h_ne_zero have ih := ih (w₂' h') w₁' simp only [self_div_pow_eq_ofDigits_drop _ _ h, digits_ofDigits p h tl w₁' w₂', ← Nat.one_add] at ih have := sum_singleton (fun x ↦ ofDigits p <| tl.drop x) tl.length rw [← Ico_succ_singleton, List.drop_length, ofDigits] at this have h₁ : 1 ≤ tl.length := List.length_pos.mpr h' rw [← sum_range_add_sum_Ico _ <| h₁, ← add_zero (∑ x ∈ Ico _ _, ofDigits p (tl.drop x)), ← this, sum_Ico_consecutive _ h₁ <| (le_add_right tl.length 1), ← sum_Ico_add _ 0 tl.length 1, Ico_zero_eq_range, mul_add, mul_add, ih, range_one, sum_singleton, List.drop, ofDigits, mul_zero, add_zero, ← Nat.add_sub_assoc <| sum_le_ofDigits _ <| Nat.le_of_lt h] nth_rw 2 [← one_mul <| ofDigits p tl] rw [← add_mul, one_eq_succ_zero, Nat.sub_add_cancel <| zero_lt_of_lt h, Nat.add_sub_add_left] · simp [ofDigits_one] · simp [lt_one_iff.mp h] cases L · rfl · simp [ofDigits] theorem sub_one_mul_sum_log_div_pow_eq_sub_sum_digits {p : ℕ} (n : ℕ) : (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum := by obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p · rcases eq_or_ne n 0 with rfl | hn · simp · convert sub_one_mul_sum_div_pow_eq_sub_sum_digits (p.digits n) (getLast_digit_ne_zero p hn) <| (fun l a ↦ digits_lt_base h a) · refine (digits_len p n h hn).symm all_goals exact (ofDigits_digits p n).symm · simp · simp [lt_one_iff.mp h] cases n all_goals simp /-! ### Binary -/ theorem digits_two_eq_bits (n : ℕ) : digits 2 n = n.bits.map fun b => cond b 1 0 := by induction' n using Nat.binaryRecFromOne with b n h ih · simp · rfl rw [bits_append_bit _ _ fun hn => absurd hn h] cases b · rw [digits_def' one_lt_two] · simpa [Nat.bit, Nat.bit0_val n] · simpa [pos_iff_ne_zero, Nat.bit0_eq_zero] · simpa [Nat.bit, Nat.bit1_val n, add_comm, digits_add 2 one_lt_two 1 n, Nat.add_mul_div_left] #align nat.digits_two_eq_bits Nat.digits_two_eq_bits /-! ### Modular Arithmetic -/ -- This is really a theorem about polynomials.
Mathlib/Data/Nat/Digits.lean
639
645
theorem dvd_ofDigits_sub_ofDigits {α : Type*} [CommRing α] {a b k : α} (h : k ∣ a - b) (L : List ℕ) : k ∣ ofDigits a L - ofDigits b L := by
induction' L with d L ih · change k ∣ 0 - 0 simp · simp only [ofDigits, add_sub_add_left_eq_sub] exact dvd_mul_sub_mul h ih
/- Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn -/ import Mathlib.Data.Finset.Basic import Mathlib.ModelTheory.Syntax import Mathlib.Data.List.ProdSigma #align_import model_theory.semantics from "leanprover-community/mathlib"@"d565b3df44619c1498326936be16f1a935df0728" /-! # Basics on First-Order Semantics This file defines the interpretations of first-order terms, formulas, sentences, and theories in a style inspired by the [Flypitch project](https://flypitch.github.io/). ## Main Definitions * `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at variables `v`. * `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded formula `φ` evaluated at tuples of variables `v` and `xs`. * `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ` evaluated at variables `v`. * `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ` evaluated in the structure `M`. Also denoted `M ⊨ φ`. * `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`. ## Main Results * `FirstOrder.Language.BoundedFormula.realize_toPrenex` shows that the prenex normal form of a formula has the same realization as the original formula. * Several results in this file show that syntactic constructions such as `relabel`, `castLE`, `liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas, sentences, and theories. ## Implementation Notes * Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n` is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula `∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by `n : Fin (n + 1)`. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} {L' : Language} variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P] variable {α : Type u'} {β : Type v'} {γ : Type*} open FirstOrder Cardinal open Structure Cardinal Fin namespace Term -- Porting note: universes in different order /-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/ def realize (v : α → M) : ∀ _t : L.Term α, M | var k => v k | func f ts => funMap f fun i => (ts i).realize v #align first_order.language.term.realize FirstOrder.Language.Term.realize /- Porting note: The equation lemma of `realize` is too strong; it simplifies terms like the LHS of `realize_functions_apply₁`. Even `eqns` can't fix this. We removed `simp` attr from `realize` and prepare new simp lemmas for `realize`. -/ @[simp] theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl @[simp] theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) : realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl @[simp] theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} : (t.relabel g).realize v = t.realize (v ∘ g) := by induction' t with _ n f ts ih · rfl · simp [ih] #align first_order.language.term.realize_relabel FirstOrder.Language.Term.realize_relabel @[simp] theorem realize_liftAt {n n' m : ℕ} {t : L.Term (Sum α (Fin n))} {v : Sum α (Fin (n + n')) → M} : (t.liftAt n' m).realize v = t.realize (v ∘ Sum.map id fun i : Fin _ => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := realize_relabel #align first_order.language.term.realize_lift_at FirstOrder.Language.Term.realize_liftAt @[simp] theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c := funMap_eq_coe_constants #align first_order.language.term.realize_constants FirstOrder.Language.Term.realize_constants @[simp] theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} : (f.apply₁ t).realize v = funMap f ![t.realize v] := by rw [Functions.apply₁, Term.realize] refine congr rfl (funext fun i => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.term.realize_functions_apply₁ FirstOrder.Language.Term.realize_functions_apply₁ @[simp] theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} : (f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by rw [Functions.apply₂, Term.realize] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.term.realize_functions_apply₂ FirstOrder.Language.Term.realize_functions_apply₂ theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a := rfl #align first_order.language.term.realize_con FirstOrder.Language.Term.realize_con @[simp] theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} : (t.subst tf).realize v = t.realize fun a => (tf a).realize v := by induction' t with _ _ _ _ ih · rfl · simp [ih] #align first_order.language.term.realize_subst FirstOrder.Language.Term.realize_subst @[simp] theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s) {v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := by induction' t with _ _ _ _ ih · rfl · simp_rw [varFinset, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var FirstOrder.Language.Term.realize_restrictVar @[simp] theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (Sum α γ)} {s : Set α} (h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} : (t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) = t.realize (Sum.elim v xs) := by induction' t with a _ _ _ ih · cases a <;> rfl · simp_rw [varFinsetLeft, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var_left FirstOrder.Language.Term.realize_restrictVarLeft @[simp] theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L[[α]].Term β} {v : β → M} : t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by induction' t with _ n f ts ih · simp · cases n · cases f · simp only [realize, ih, Nat.zero_eq, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants] rfl · cases' f with _ f · simp only [realize, ih, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · exact isEmptyElim f #align first_order.language.term.realize_constants_to_vars FirstOrder.Language.Term.realize_constantsToVars @[simp] theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L.Term (Sum α β)} {v : β → M} : t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by induction' t with ab n f ts ih · cases' ab with a b -- Porting note: both cases were `simp [Language.con]` · simp [Language.con, realize, funMap_eq_coe_constants] · simp [realize, constantMap] · simp only [realize, constantsOn, mk₂_Functions, ih] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] #align first_order.language.term.realize_vars_to_constants FirstOrder.Language.Term.realize_varsToConstants theorem realize_constantsVarsEquivLeft [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (Sum β (Fin n))} {v : β → M} {xs : Fin n → M} : (constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) = t.realize (Sum.elim v xs) := by simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply, constantsVarsEquiv_apply, relabelEquiv_symm_apply] refine _root_.trans ?_ realize_constantsToVars rcongr x rcases x with (a | (b | i)) <;> simp #align first_order.language.term.realize_constants_vars_equiv_left FirstOrder.Language.Term.realize_constantsVarsEquivLeft end Term namespace LHom @[simp] theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α) (v : α → M) : (φ.onTerm t).realize v = t.realize v := by induction' t with _ n f ts ih · rfl · simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_term FirstOrder.Language.LHom.realize_onTerm end LHom @[simp] theorem Hom.realize_term (g : M →[L] N) {t : L.Term α} {v : α → M} : t.realize (g ∘ v) = g (t.realize v) := by induction t · rfl · rw [Term.realize, Term.realize, g.map_fun] refine congr rfl ?_ ext x simp [*] #align first_order.language.hom.realize_term FirstOrder.Language.Hom.realize_term @[simp] theorem Embedding.realize_term {v : α → M} (t : L.Term α) (g : M ↪[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.embedding.realize_term FirstOrder.Language.Embedding.realize_term @[simp] theorem Equiv.realize_term {v : α → M} (t : L.Term α) (g : M ≃[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.equiv.realize_term FirstOrder.Language.Equiv.realize_term variable {n : ℕ} namespace BoundedFormula open Term -- Porting note: universes in different order /-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/ def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop | _, falsum, _v, _xs => False | _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) | _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs) | _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs | _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x) #align first_order.language.bounded_formula.realize FirstOrder.Language.BoundedFormula.Realize variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ} variable {v : α → M} {xs : Fin l → M} @[simp] theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False := Iff.rfl #align first_order.language.bounded_formula.realize_bot FirstOrder.Language.BoundedFormula.realize_bot @[simp] theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs := Iff.rfl #align first_order.language.bounded_formula.realize_not FirstOrder.Language.BoundedFormula.realize_not @[simp] theorem realize_bdEqual (t₁ t₂ : L.Term (Sum α (Fin l))) : (t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) := Iff.rfl #align first_order.language.bounded_formula.realize_bd_equal FirstOrder.Language.BoundedFormula.realize_bdEqual @[simp] theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top] #align first_order.language.bounded_formula.realize_top FirstOrder.Language.BoundedFormula.realize_top @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by simp [Inf.inf, Realize] #align first_order.language.bounded_formula.realize_inf FirstOrder.Language.BoundedFormula.realize_inf @[simp] theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp [ih] #align first_order.language.bounded_formula.realize_foldr_inf FirstOrder.Language.BoundedFormula.realize_foldr_inf @[simp] theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by simp only [Realize] #align first_order.language.bounded_formula.realize_imp FirstOrder.Language.BoundedFormula.realize_imp @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} : (R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) := Iff.rfl #align first_order.language.bounded_formula.realize_rel FirstOrder.Language.BoundedFormula.realize_rel @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.bounded_formula.realize_rel₁ FirstOrder.Language.BoundedFormula.realize_rel₁ @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.boundedFormula₂ t₁ t₂).Realize v xs ↔ RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.bounded_formula.realize_rel₂ FirstOrder.Language.BoundedFormula.realize_rel₂ @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by simp only [realize, Sup.sup, realize_not, eq_iff_iff] tauto #align first_order.language.bounded_formula.realize_sup FirstOrder.Language.BoundedFormula.realize_sup @[simp] theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or, exists_eq_left] #align first_order.language.bounded_formula.realize_foldr_sup FirstOrder.Language.BoundedFormula.realize_foldr_sup @[simp] theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) := Iff.rfl #align first_order.language.bounded_formula.realize_all FirstOrder.Language.BoundedFormula.realize_all @[simp] theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by rw [BoundedFormula.ex, realize_not, realize_all, not_forall] simp_rw [realize_not, Classical.not_not] #align first_order.language.bounded_formula.realize_ex FirstOrder.Language.BoundedFormula.realize_ex @[simp] theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def] #align first_order.language.bounded_formula.realize_iff FirstOrder.Language.BoundedFormula.realize_iff theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m} {v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ cast h) := by subst h simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id] #align first_order.language.bounded_formula.realize_cast_le_of_eq FirstOrder.Language.BoundedFormula.realize_castLE_of_eq theorem realize_mapTermRel_id [L'.Structure M] {ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin n))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M} {v' : β → M} {xs : Fin n → M} (h1 : ∀ (n) (t : L.Term (Sum α (Fin n))) (xs : Fin n → M), (ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs)) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) : (φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih · rfl · simp [mapTermRel, Realize, h1] · simp [mapTermRel, Realize, h1, h2] · simp [mapTermRel, Realize, ih1, ih2] · simp only [mapTermRel, Realize, ih, id] #align first_order.language.bounded_formula.realize_map_term_rel_id FirstOrder.Language.BoundedFormula.realize_mapTermRel_id theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ} {ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin (k + n)))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} (v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M) (h1 : ∀ (n) (t : L.Term (Sum α (Fin n))) (xs' : Fin (k + n) → M), (ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _))) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) (hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) : (φ.mapTermRel ft fr fun n => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔ φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih · rfl · simp [mapTermRel, Realize, h1] · simp [mapTermRel, Realize, h1, h2] · simp [mapTermRel, Realize, ih1, ih2] · simp [mapTermRel, Realize, ih, hv] #align first_order.language.bounded_formula.realize_map_term_rel_add_cast_le FirstOrder.Language.BoundedFormula.realize_mapTermRel_add_castLe @[simp] theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → Sum β (Fin m)} {v : β → M} {xs : Fin (m + n) → M} : (φ.relabel g).Realize v xs ↔ φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by rw [relabel, realize_mapTermRel_add_castLe] <;> intros <;> simp #align first_order.language.bounded_formula.realize_relabel FirstOrder.Language.BoundedFormula.realize_relabel theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M} (hmn : m + n' ≤ n + 1) : (φ.liftAt n' m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by rw [liftAt] induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 k _ ih3 · simp [mapTermRel, Realize] · simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] · simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] · simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn] · have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc] simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)] refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_))) · simp only [Function.comp_apply, val_last, snoc_last] by_cases h : k < m · rw [if_pos h] refine (congr rfl (ext ?_)).trans (snoc_last _ _) simp only [coe_cast, coe_castAdd, val_last, self_eq_add_right] refine le_antisymm (le_of_add_le_add_left ((hmn.trans (Nat.succ_le_of_lt h)).trans ?_)) n'.zero_le rw [add_zero] · rw [if_neg h] refine (congr rfl (ext ?_)).trans (snoc_last _ _) simp · simp only [Function.comp_apply, Fin.snoc_castSucc] refine (congr rfl (ext ?_)).trans (snoc_castSucc _ _ _) simp only [coe_castSucc, coe_cast] split_ifs <;> simp #align first_order.language.bounded_formula.realize_lift_at FirstOrder.Language.BoundedFormula.realize_liftAt theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} (hmn : m ≤ n) : (φ.liftAt 1 m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by simp [realize_liftAt (add_le_add_right hmn 1), castSucc] #align first_order.language.bounded_formula.realize_lift_at_one FirstOrder.Language.BoundedFormula.realize_liftAt_one @[simp] theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by rw [realize_liftAt_one (refl n), iff_eq_eq] refine congr rfl (congr rfl (funext fun i => ?_)) rw [if_pos i.is_lt] #align first_order.language.bounded_formula.realize_lift_at_one_self FirstOrder.Language.BoundedFormula.realize_liftAt_one_self @[simp] theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} : (φ.subst tf).Realize v xs ↔ φ.Realize (fun a => (tf a).realize v) xs := realize_mapTermRel_id (fun n t x => by rw [Term.realize_subst] rcongr a cases a · simp only [Sum.elim_inl, Function.comp_apply, Term.realize_relabel, Sum.elim_comp_inl] · rfl) (by simp) #align first_order.language.bounded_formula.realize_subst FirstOrder.Language.BoundedFormula.realize_subst @[simp] theorem realize_restrictFreeVar [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {s : Set α} (h : ↑φ.freeVarFinset ⊆ s) {v : α → M} {xs : Fin n → M} : (φ.restrictFreeVar (Set.inclusion h)).Realize (v ∘ (↑)) xs ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 · rfl · simp [restrictFreeVar, Realize] · simp [restrictFreeVar, Realize] · simp [restrictFreeVar, Realize, ih1, ih2] · simp [restrictFreeVar, Realize, ih3] #align first_order.language.bounded_formula.realize_restrict_free_var FirstOrder.Language.BoundedFormula.realize_restrictFreeVar theorem realize_constantsVarsEquiv [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {φ : L[[α]].BoundedFormula β n} {v : β → M} {xs : Fin n → M} : (constantsVarsEquiv φ).Realize (Sum.elim (fun a => ↑(L.con a)) v) xs ↔ φ.Realize v xs := by refine realize_mapTermRel_id (fun n t xs => realize_constantsVarsEquivLeft) fun n R xs => ?_ -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← (lhomWithConstants L α).map_onRelation (Equiv.sumEmpty (L.Relations n) ((constantsOn α).Relations n) R) xs] rcongr cases' R with R R · simp · exact isEmptyElim R #align first_order.language.bounded_formula.realize_constants_vars_equiv FirstOrder.Language.BoundedFormula.realize_constantsVarsEquiv @[simp] theorem realize_relabelEquiv {g : α ≃ β} {k} {φ : L.BoundedFormula α k} {v : β → M} {xs : Fin k → M} : (relabelEquiv g φ).Realize v xs ↔ φ.Realize (v ∘ g) xs := by simp only [relabelEquiv, mapTermRelEquiv_apply, Equiv.coe_refl] refine realize_mapTermRel_id (fun n t xs => ?_) fun _ _ _ => rfl simp only [relabelEquiv_apply, Term.realize_relabel] refine congr (congr rfl ?_) rfl ext (i | i) <;> rfl #align first_order.language.bounded_formula.realize_relabel_equiv FirstOrder.Language.BoundedFormula.realize_relabelEquiv variable [Nonempty M] theorem realize_all_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin n → M} : (φ.liftAt 1 n).all.Realize v xs ↔ φ.Realize v xs := by inhabit M simp only [realize_all, realize_liftAt_one_self] refine ⟨fun h => ?_, fun h a => ?_⟩ · refine (congr rfl (funext fun i => ?_)).mp (h default) simp · refine (congr rfl (funext fun i => ?_)).mp h simp #align first_order.language.bounded_formula.realize_all_lift_at_one_self FirstOrder.Language.BoundedFormula.realize_all_liftAt_one_self theorem realize_toPrenexImpRight {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsPrenex ψ) {v : α → M} {xs : Fin n → M} : (φ.toPrenexImpRight ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by induction' hψ with _ _ hψ _ _ _hψ ih _ _ _hψ ih · rw [hψ.toPrenexImpRight] · refine _root_.trans (forall_congr' fun _ => ih hφ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all] exact ⟨fun h1 a h2 => h1 h2 a, fun h1 h2 a => h1 a h2⟩ · unfold toPrenexImpRight rw [realize_ex] refine _root_.trans (exists_congr fun _ => ih hφ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_ex] refine ⟨?_, fun h' => ?_⟩ · rintro ⟨a, ha⟩ h exact ⟨a, ha h⟩ · by_cases h : φ.Realize v xs · obtain ⟨a, ha⟩ := h' h exact ⟨a, fun _ => ha⟩ · inhabit M exact ⟨default, fun h'' => (h h'').elim⟩ #align first_order.language.bounded_formula.realize_to_prenex_imp_right FirstOrder.Language.BoundedFormula.realize_toPrenexImpRight theorem realize_toPrenexImp {φ ψ : L.BoundedFormula α n} (hφ : IsPrenex φ) (hψ : IsPrenex ψ) {v : α → M} {xs : Fin n → M} : (φ.toPrenexImp ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by revert ψ induction' hφ with _ _ hφ _ _ _hφ ih _ _ _hφ ih <;> intro ψ hψ · rw [hφ.toPrenexImp] exact realize_toPrenexImpRight hφ hψ · unfold toPrenexImp rw [realize_ex] refine _root_.trans (exists_congr fun _ => ih hψ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all] refine ⟨?_, fun h' => ?_⟩ · rintro ⟨a, ha⟩ h exact ha (h a) · by_cases h : ψ.Realize v xs · inhabit M exact ⟨default, fun _h'' => h⟩ · obtain ⟨a, ha⟩ := not_forall.1 (h ∘ h') exact ⟨a, fun h => (ha h).elim⟩ · refine _root_.trans (forall_congr' fun _ => ih hψ.liftAt) ?_ simp #align first_order.language.bounded_formula.realize_to_prenex_imp FirstOrder.Language.BoundedFormula.realize_toPrenexImp @[simp] theorem realize_toPrenex (φ : L.BoundedFormula α n) {v : α → M} : ∀ {xs : Fin n → M}, φ.toPrenex.Realize v xs ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ f1 f2 h1 h2 _ _ h · exact Iff.rfl · exact Iff.rfl · exact Iff.rfl · intros rw [toPrenex, realize_toPrenexImp f1.toPrenex_isPrenex f2.toPrenex_isPrenex, realize_imp, realize_imp, h1, h2] · intros rw [realize_all, toPrenex, realize_all] exact forall_congr' fun a => h #align first_order.language.bounded_formula.realize_to_prenex FirstOrder.Language.BoundedFormula.realize_toPrenex end BoundedFormula -- Porting note: no `protected` attribute in Lean4 -- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel -- attribute [protected] bounded_formula.imp bounded_formula.all namespace LHom open BoundedFormula @[simp] theorem realize_onBoundedFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] {n : ℕ} (ψ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} : (φ.onBoundedFormula ψ).Realize v xs ↔ ψ.Realize v xs := by induction' ψ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 · rfl · simp only [onBoundedFormula, realize_bdEqual, realize_onTerm] rfl · simp only [onBoundedFormula, realize_rel, LHom.map_onRelation, Function.comp_apply, realize_onTerm] rfl · simp only [onBoundedFormula, ih1, ih2, realize_imp] · simp only [onBoundedFormula, ih3, realize_all] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_bounded_formula FirstOrder.Language.LHom.realize_onBoundedFormula end LHom -- Porting note: no `protected` attribute in Lean4 -- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel -- attribute [protected] bounded_formula.imp bounded_formula.all namespace Formula /-- A formula can be evaluated as true or false by giving values to each free variable. -/ nonrec def Realize (φ : L.Formula α) (v : α → M) : Prop := φ.Realize v default #align first_order.language.formula.realize FirstOrder.Language.Formula.Realize variable {φ ψ : L.Formula α} {v : α → M} @[simp] theorem realize_not : φ.not.Realize v ↔ ¬φ.Realize v := Iff.rfl #align first_order.language.formula.realize_not FirstOrder.Language.Formula.realize_not @[simp] theorem realize_bot : (⊥ : L.Formula α).Realize v ↔ False := Iff.rfl #align first_order.language.formula.realize_bot FirstOrder.Language.Formula.realize_bot @[simp] theorem realize_top : (⊤ : L.Formula α).Realize v ↔ True := BoundedFormula.realize_top #align first_order.language.formula.realize_top FirstOrder.Language.Formula.realize_top @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v ↔ φ.Realize v ∧ ψ.Realize v := BoundedFormula.realize_inf #align first_order.language.formula.realize_inf FirstOrder.Language.Formula.realize_inf @[simp] theorem realize_imp : (φ.imp ψ).Realize v ↔ φ.Realize v → ψ.Realize v := BoundedFormula.realize_imp #align first_order.language.formula.realize_imp FirstOrder.Language.Formula.realize_imp @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term α} : (R.formula ts).Realize v ↔ RelMap R fun i => (ts i).realize v := BoundedFormula.realize_rel.trans (by simp) #align first_order.language.formula.realize_rel FirstOrder.Language.Formula.realize_rel @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.formula₁ t).Realize v ↔ RelMap R ![t.realize v] := by rw [Relations.formula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.formula.realize_rel₁ FirstOrder.Language.Formula.realize_rel₁ @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.formula₂ t₁ t₂).Realize v ↔ RelMap R ![t₁.realize v, t₂.realize v] := by rw [Relations.formula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.formula.realize_rel₂ FirstOrder.Language.Formula.realize_rel₂ @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v ↔ φ.Realize v ∨ ψ.Realize v := BoundedFormula.realize_sup #align first_order.language.formula.realize_sup FirstOrder.Language.Formula.realize_sup @[simp] theorem realize_iff : (φ.iff ψ).Realize v ↔ (φ.Realize v ↔ ψ.Realize v) := BoundedFormula.realize_iff #align first_order.language.formula.realize_iff FirstOrder.Language.Formula.realize_iff @[simp] theorem realize_relabel {φ : L.Formula α} {g : α → β} {v : β → M} : (φ.relabel g).Realize v ↔ φ.Realize (v ∘ g) := by rw [Realize, Realize, relabel, BoundedFormula.realize_relabel, iff_eq_eq, Fin.castAdd_zero] exact congr rfl (funext finZeroElim) #align first_order.language.formula.realize_relabel FirstOrder.Language.Formula.realize_relabel theorem realize_relabel_sum_inr (φ : L.Formula (Fin n)) {v : Empty → M} {x : Fin n → M} : (BoundedFormula.relabel Sum.inr φ).Realize v x ↔ φ.Realize x := by rw [BoundedFormula.realize_relabel, Formula.Realize, Sum.elim_comp_inr, Fin.castAdd_zero, cast_refl, Function.comp_id, Subsingleton.elim (x ∘ (natAdd n : Fin 0 → Fin n)) default] #align first_order.language.formula.realize_relabel_sum_inr FirstOrder.Language.Formula.realize_relabel_sum_inr @[simp] theorem realize_equal {t₁ t₂ : L.Term α} {x : α → M} : (t₁.equal t₂).Realize x ↔ t₁.realize x = t₂.realize x := by simp [Term.equal, Realize] #align first_order.language.formula.realize_equal FirstOrder.Language.Formula.realize_equal @[simp] theorem realize_graph {f : L.Functions n} {x : Fin n → M} {y : M} : (Formula.graph f).Realize (Fin.cons y x : _ → M) ↔ funMap f x = y := by simp only [Formula.graph, Term.realize, realize_equal, Fin.cons_zero, Fin.cons_succ] rw [eq_comm] #align first_order.language.formula.realize_graph FirstOrder.Language.Formula.realize_graph end Formula @[simp] theorem LHom.realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) {v : α → M} : (φ.onFormula ψ).Realize v ↔ ψ.Realize v := φ.realize_onBoundedFormula ψ set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_formula FirstOrder.Language.LHom.realize_onFormula @[simp] theorem LHom.setOf_realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) : (setOf (φ.onFormula ψ).Realize : Set (α → M)) = setOf ψ.Realize := by ext simp set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.set_of_realize_on_formula FirstOrder.Language.LHom.setOf_realize_onFormula variable (M) /-- A sentence can be evaluated as true or false in a structure. -/ nonrec def Sentence.Realize (φ : L.Sentence) : Prop := φ.Realize (default : _ → M) #align first_order.language.sentence.realize FirstOrder.Language.Sentence.Realize -- input using \|= or \vDash, but not using \models @[inherit_doc Sentence.Realize] infixl:51 " ⊨ " => Sentence.Realize @[simp] theorem Sentence.realize_not {φ : L.Sentence} : M ⊨ φ.not ↔ ¬M ⊨ φ := Iff.rfl #align first_order.language.sentence.realize_not FirstOrder.Language.Sentence.realize_not namespace Formula @[simp] theorem realize_equivSentence_symm_con [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L[[α]].Sentence) : ((equivSentence.symm φ).Realize fun a => (L.con a : M)) ↔ φ.Realize M := by simp only [equivSentence, _root_.Equiv.symm_symm, Equiv.coe_trans, Realize, BoundedFormula.realize_relabelEquiv, Function.comp] refine _root_.trans ?_ BoundedFormula.realize_constantsVarsEquiv rw [iff_iff_eq] congr with (_ | a) · simp · cases a #align first_order.language.formula.realize_equiv_sentence_symm_con FirstOrder.Language.Formula.realize_equivSentence_symm_con @[simp] theorem realize_equivSentence [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L.Formula α) : (equivSentence φ).Realize M ↔ φ.Realize fun a => (L.con a : M) := by rw [← realize_equivSentence_symm_con M (equivSentence φ), _root_.Equiv.symm_apply_apply] #align first_order.language.formula.realize_equiv_sentence FirstOrder.Language.Formula.realize_equivSentence theorem realize_equivSentence_symm (φ : L[[α]].Sentence) (v : α → M) : (equivSentence.symm φ).Realize v ↔ @Sentence.Realize _ M (@Language.withConstantsStructure L M _ α (constantsOn.structure v)) φ := letI := constantsOn.structure v realize_equivSentence_symm_con M φ #align first_order.language.formula.realize_equiv_sentence_symm FirstOrder.Language.Formula.realize_equivSentence_symm end Formula @[simp] theorem LHom.realize_onSentence [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Sentence) : M ⊨ φ.onSentence ψ ↔ M ⊨ ψ := φ.realize_onFormula ψ set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_sentence FirstOrder.Language.LHom.realize_onSentence variable (L) /-- The complete theory of a structure `M` is the set of all sentences `M` satisfies. -/ def completeTheory : L.Theory := { φ | M ⊨ φ } #align first_order.language.complete_theory FirstOrder.Language.completeTheory variable (N) /-- Two structures are elementarily equivalent when they satisfy the same sentences. -/ def ElementarilyEquivalent : Prop := L.completeTheory M = L.completeTheory N #align first_order.language.elementarily_equivalent FirstOrder.Language.ElementarilyEquivalent @[inherit_doc FirstOrder.Language.ElementarilyEquivalent] scoped[FirstOrder] notation:25 A " ≅[" L "] " B:50 => FirstOrder.Language.ElementarilyEquivalent L A B variable {L} {M} {N} @[simp] theorem mem_completeTheory {φ : Sentence L} : φ ∈ L.completeTheory M ↔ M ⊨ φ := Iff.rfl #align first_order.language.mem_complete_theory FirstOrder.Language.mem_completeTheory theorem elementarilyEquivalent_iff : M ≅[L] N ↔ ∀ φ : L.Sentence, M ⊨ φ ↔ N ⊨ φ := by simp only [ElementarilyEquivalent, Set.ext_iff, completeTheory, Set.mem_setOf_eq] #align first_order.language.elementarily_equivalent_iff FirstOrder.Language.elementarilyEquivalent_iff variable (M) /-- A model of a theory is a structure in which every sentence is realized as true. -/ class Theory.Model (T : L.Theory) : Prop where realize_of_mem : ∀ φ ∈ T, M ⊨ φ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model FirstOrder.Language.Theory.Model -- input using \|= or \vDash, but not using \models @[inherit_doc Theory.Model] infixl:51 " ⊨ " => Theory.Model variable {M} (T : L.Theory) @[simp default-10] theorem Theory.model_iff : M ⊨ T ↔ ∀ φ ∈ T, M ⊨ φ := ⟨fun h => h.realize_of_mem, fun h => ⟨h⟩⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_iff FirstOrder.Language.Theory.model_iff theorem Theory.realize_sentence_of_mem [M ⊨ T] {φ : L.Sentence} (h : φ ∈ T) : M ⊨ φ := Theory.Model.realize_of_mem φ h set_option linter.uppercaseLean3 false in #align first_order.language.Theory.realize_sentence_of_mem FirstOrder.Language.Theory.realize_sentence_of_mem @[simp] theorem LHom.onTheory_model [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (T : L.Theory) : M ⊨ φ.onTheory T ↔ M ⊨ T := by simp [Theory.model_iff, LHom.onTheory] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.on_Theory_model FirstOrder.Language.LHom.onTheory_model variable {T} instance model_empty : M ⊨ (∅ : L.Theory) := ⟨fun φ hφ => (Set.not_mem_empty φ hφ).elim⟩ #align first_order.language.model_empty FirstOrder.Language.model_empty namespace Theory theorem Model.mono {T' : L.Theory} (_h : M ⊨ T') (hs : T ⊆ T') : M ⊨ T := ⟨fun _φ hφ => T'.realize_sentence_of_mem (hs hφ)⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model.mono FirstOrder.Language.Theory.Model.mono theorem Model.union {T' : L.Theory} (h : M ⊨ T) (h' : M ⊨ T') : M ⊨ T ∪ T' := by simp only [model_iff, Set.mem_union] at * exact fun φ hφ => hφ.elim (h _) (h' _) set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model.union FirstOrder.Language.Theory.Model.union @[simp] theorem model_union_iff {T' : L.Theory} : M ⊨ T ∪ T' ↔ M ⊨ T ∧ M ⊨ T' := ⟨fun h => ⟨h.mono Set.subset_union_left, h.mono Set.subset_union_right⟩, fun h => h.1.union h.2⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_union_iff FirstOrder.Language.Theory.model_union_iff theorem model_singleton_iff {φ : L.Sentence} : M ⊨ ({φ} : L.Theory) ↔ M ⊨ φ := by simp set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_singleton_iff FirstOrder.Language.Theory.model_singleton_iff theorem model_iff_subset_completeTheory : M ⊨ T ↔ T ⊆ L.completeTheory M := T.model_iff set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_iff_subset_complete_theory FirstOrder.Language.Theory.model_iff_subset_completeTheory theorem completeTheory.subset [MT : M ⊨ T] : T ⊆ L.completeTheory M := model_iff_subset_completeTheory.1 MT set_option linter.uppercaseLean3 false in #align first_order.language.Theory.complete_theory.subset FirstOrder.Language.Theory.completeTheory.subset end Theory instance model_completeTheory : M ⊨ L.completeTheory M := Theory.model_iff_subset_completeTheory.2 (subset_refl _) #align first_order.language.model_complete_theory FirstOrder.Language.model_completeTheory variable (M N) theorem realize_iff_of_model_completeTheory [N ⊨ L.completeTheory M] (φ : L.Sentence) : N ⊨ φ ↔ M ⊨ φ := by refine ⟨fun h => ?_, (L.completeTheory M).realize_sentence_of_mem⟩ contrapose! h rw [← Sentence.realize_not] at * exact (L.completeTheory M).realize_sentence_of_mem (mem_completeTheory.2 h) #align first_order.language.realize_iff_of_model_complete_theory FirstOrder.Language.realize_iff_of_model_completeTheory variable {M N} namespace BoundedFormula @[simp] theorem realize_alls {φ : L.BoundedFormula α n} {v : α → M} : φ.alls.Realize v ↔ ∀ xs : Fin n → M, φ.Realize v xs := by induction' n with n ih · exact Unique.forall_iff.symm · simp only [alls, ih, Realize] exact ⟨fun h xs => Fin.snoc_init_self xs ▸ h _ _, fun h xs x => h (Fin.snoc xs x)⟩ #align first_order.language.bounded_formula.realize_alls FirstOrder.Language.BoundedFormula.realize_alls @[simp] theorem realize_exs {φ : L.BoundedFormula α n} {v : α → M} : φ.exs.Realize v ↔ ∃ xs : Fin n → M, φ.Realize v xs := by induction' n with n ih · exact Unique.exists_iff.symm · simp only [BoundedFormula.exs, ih, realize_ex] constructor · rintro ⟨xs, x, h⟩ exact ⟨_, h⟩ · rintro ⟨xs, h⟩ rw [← Fin.snoc_init_self xs] at h exact ⟨_, _, h⟩ #align first_order.language.bounded_formula.realize_exs FirstOrder.Language.BoundedFormula.realize_exs @[simp] theorem _root_.FirstOrder.Language.Formula.realize_iAlls [Finite γ] {f : α → β ⊕ γ} {φ : L.Formula α} {v : β → M} : (φ.iAlls f).Realize v ↔ ∀ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ)) rw [Formula.iAlls] simp only [Nat.add_zero, realize_alls, realize_relabel, Function.comp, castAdd_zero, finCongr_refl, OrderIso.refl_apply, Sum.elim_map, id_eq] refine Equiv.forall_congr ?_ ?_ · exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm, fun _ => by simp [Function.comp], fun _ => by simp [Function.comp]⟩ · intro x rw [Formula.Realize, iff_iff_eq] congr funext i exact i.elim0 @[simp] theorem realize_iAlls [Finite γ] {f : α → β ⊕ γ} {φ : L.Formula α} {v : β → M} {v' : Fin 0 → M} : BoundedFormula.Realize (φ.iAlls f) v v' ↔ ∀ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by rw [← Formula.realize_iAlls, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton] @[simp] theorem _root_.FirstOrder.Language.Formula.realize_iExs [Finite γ] {f : α → β ⊕ γ} {φ : L.Formula α} {v : β → M} : (φ.iExs f).Realize v ↔ ∃ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ)) rw [Formula.iExs] simp only [Nat.add_zero, realize_exs, realize_relabel, Function.comp, castAdd_zero, finCongr_refl, OrderIso.refl_apply, Sum.elim_map, id_eq] rw [← not_iff_not, not_exists, not_exists] refine Equiv.forall_congr ?_ ?_ · exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm, fun _ => by simp [Function.comp], fun _ => by simp [Function.comp]⟩ · intro x rw [Formula.Realize, iff_iff_eq] congr funext i exact i.elim0 @[simp] theorem realize_iExs [Finite γ] {f : α → β ⊕ γ} {φ : L.Formula α} {v : β → M} {v' : Fin 0 → M} : BoundedFormula.Realize (φ.iExs f) v v' ↔ ∃ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by rw [← Formula.realize_iExs, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton] @[simp] theorem realize_toFormula (φ : L.BoundedFormula α n) (v : Sum α (Fin n) → M) : φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0 · rfl · simp [BoundedFormula.Realize] · simp [BoundedFormula.Realize] · rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2, realize_imp] · rw [toFormula, Formula.Realize, realize_all, realize_all] refine forall_congr' fun a => ?_ have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h rw [← h, realize_relabel, Formula.Realize, iff_iff_eq] simp only [Function.comp] congr with x · cases' x with _ x · simp · refine Fin.lastCases ?_ ?_ x · rw [Sum.elim_inr, Sum.elim_inr, finSumFinEquiv_symm_last, Sum.map_inr, Sum.elim_inr] simp [Fin.snoc] · simp only [castSucc, Function.comp_apply, Sum.elim_inr, finSumFinEquiv_symm_apply_castAdd, Sum.map_inl, Sum.elim_inl] rw [← castSucc] simp · exact Fin.elim0 x #align first_order.language.bounded_formula.realize_to_formula FirstOrder.Language.BoundedFormula.realize_toFormula @[simp] theorem realize_iSup (s : Finset β) (f : β → L.BoundedFormula α n) (v : α → M) (v' : Fin n → M) : (iSup s f).Realize v v' ↔ ∃ b ∈ s, (f b).Realize v v' := by simp only [iSup, realize_foldr_sup, List.mem_map, Finset.mem_toList, exists_exists_and_eq_and] @[simp] theorem realize_iInf (s : Finset β) (f : β → L.BoundedFormula α n) (v : α → M) (v' : Fin n → M) : (iInf s f).Realize v v' ↔ ∀ b ∈ s, (f b).Realize v v' := by simp only [iInf, realize_foldr_inf, List.mem_map, Finset.mem_toList, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] end BoundedFormula namespace Equiv @[simp] theorem realize_boundedFormula (g : M ≃[L] N) (φ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} : φ.Realize (g ∘ v) (g ∘ xs) ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 · rfl · simp only [BoundedFormula.Realize, ← Sum.comp_elim, Equiv.realize_term, g.injective.eq_iff] · simp only [BoundedFormula.Realize, ← Sum.comp_elim, Equiv.realize_term] exact g.map_rel _ _ · rw [BoundedFormula.Realize, ih1, ih2, BoundedFormula.Realize] · rw [BoundedFormula.Realize, BoundedFormula.Realize] constructor · intro h a have h' := h (g a) rw [← Fin.comp_snoc, ih3] at h' exact h' · intro h a have h' := h (g.symm a) rw [← ih3, Fin.comp_snoc, g.apply_symm_apply] at h' exact h' #align first_order.language.equiv.realize_bounded_formula FirstOrder.Language.Equiv.realize_boundedFormula @[simp] theorem realize_formula (g : M ≃[L] N) (φ : L.Formula α) {v : α → M} : φ.Realize (g ∘ v) ↔ φ.Realize v := by rw [Formula.Realize, Formula.Realize, ← g.realize_boundedFormula φ, iff_eq_eq, Unique.eq_default (g ∘ default)] #align first_order.language.equiv.realize_formula FirstOrder.Language.Equiv.realize_formula theorem realize_sentence (g : M ≃[L] N) (φ : L.Sentence) : M ⊨ φ ↔ N ⊨ φ := by rw [Sentence.Realize, Sentence.Realize, ← g.realize_formula, Unique.eq_default (g ∘ default)] #align first_order.language.equiv.realize_sentence FirstOrder.Language.Equiv.realize_sentence theorem theory_model (g : M ≃[L] N) [M ⊨ T] : N ⊨ T := ⟨fun φ hφ => (g.realize_sentence φ).1 (Theory.realize_sentence_of_mem T hφ)⟩ set_option linter.uppercaseLean3 false in #align first_order.language.equiv.Theory_model FirstOrder.Language.Equiv.theory_model theorem elementarilyEquivalent (g : M ≃[L] N) : M ≅[L] N := elementarilyEquivalent_iff.2 g.realize_sentence #align first_order.language.equiv.elementarily_equivalent FirstOrder.Language.Equiv.elementarilyEquivalent end Equiv namespace Relations open BoundedFormula variable {r : L.Relations 2} @[simp] theorem realize_reflexive : M ⊨ r.reflexive ↔ Reflexive fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => realize_rel₂ #align first_order.language.relations.realize_reflexive FirstOrder.Language.Relations.realize_reflexive @[simp] theorem realize_irreflexive : M ⊨ r.irreflexive ↔ Irreflexive fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => not_congr realize_rel₂ #align first_order.language.relations.realize_irreflexive FirstOrder.Language.Relations.realize_irreflexive @[simp] theorem realize_symmetric : M ⊨ r.symmetric ↔ Symmetric fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => imp_congr realize_rel₂ realize_rel₂ #align first_order.language.relations.realize_symmetric FirstOrder.Language.Relations.realize_symmetric @[simp] theorem realize_antisymmetric : M ⊨ r.antisymmetric ↔ AntiSymmetric fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => imp_congr realize_rel₂ (imp_congr realize_rel₂ Iff.rfl) #align first_order.language.relations.realize_antisymmetric FirstOrder.Language.Relations.realize_antisymmetric @[simp] theorem realize_transitive : M ⊨ r.transitive ↔ Transitive fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => forall_congr' fun _ => imp_congr realize_rel₂ (imp_congr realize_rel₂ realize_rel₂) #align first_order.language.relations.realize_transitive FirstOrder.Language.Relations.realize_transitive @[simp] theorem realize_total : M ⊨ r.total ↔ Total fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => realize_sup.trans (or_congr realize_rel₂ realize_rel₂) #align first_order.language.relations.realize_total FirstOrder.Language.Relations.realize_total end Relations section Cardinality variable (L) @[simp] theorem Sentence.realize_cardGe (n) : M ⊨ Sentence.cardGe L n ↔ ↑n ≤ #M := by rw [← lift_mk_fin, ← lift_le.{0}, lift_lift, lift_mk_le, Sentence.cardGe, Sentence.Realize, BoundedFormula.realize_exs] simp_rw [BoundedFormula.realize_foldr_inf] simp only [Function.comp_apply, List.mem_map, Prod.exists, Ne, List.mem_product, List.mem_finRange, forall_exists_index, and_imp, List.mem_filter, true_and_iff] refine ⟨?_, fun xs => ⟨xs.some, ?_⟩⟩ · rintro ⟨xs, h⟩ refine ⟨⟨xs, fun i j ij => ?_⟩⟩ contrapose! ij have hij := h _ i j (by simpa using ij) rfl simp only [BoundedFormula.realize_not, Term.realize, BoundedFormula.realize_bdEqual, Sum.elim_inr] at hij exact hij · rintro _ i j ij rfl simpa using ij #align first_order.language.sentence.realize_card_ge FirstOrder.Language.Sentence.realize_cardGe @[simp]
Mathlib/ModelTheory/Semantics.lean
1,119
1,120
theorem model_infiniteTheory_iff : M ⊨ L.infiniteTheory ↔ Infinite M := by
simp [infiniteTheory, infinite_iff, aleph0_le]
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Topology.Algebra.Group.Basic import Mathlib.Topology.Order.Basic #align_import analysis.convex.strict from "leanprover-community/mathlib"@"84dc0bd6619acaea625086d6f53cb35cdd554219" /-! # Strictly convex sets This file defines strictly convex sets. A set is strictly convex if the open segment between any two distinct points lies in its interior. -/ open Set open Convex Pointwise variable {𝕜 𝕝 E F β : Type*} open Function Set open Convex section OrderedSemiring variable [OrderedSemiring 𝕜] [TopologicalSpace E] [TopologicalSpace F] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) variable [SMul 𝕜 E] [SMul 𝕜 F] (s : Set E) /-- A set is strictly convex if the open segment between any two distinct points lies is in its interior. This basically means "convex and not flat on the boundary". -/ def StrictConvex : Prop := s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ interior s #align strict_convex StrictConvex variable {𝕜 s} variable {x y : E} {a b : 𝕜} theorem strictConvex_iff_openSegment_subset : StrictConvex 𝕜 s ↔ s.Pairwise fun x y => openSegment 𝕜 x y ⊆ interior s := forall₅_congr fun _ _ _ _ _ => (openSegment_subset_iff 𝕜).symm #align strict_convex_iff_open_segment_subset strictConvex_iff_openSegment_subset theorem StrictConvex.openSegment_subset (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s) (h : x ≠ y) : openSegment 𝕜 x y ⊆ interior s := strictConvex_iff_openSegment_subset.1 hs hx hy h #align strict_convex.open_segment_subset StrictConvex.openSegment_subset theorem strictConvex_empty : StrictConvex 𝕜 (∅ : Set E) := pairwise_empty _ #align strict_convex_empty strictConvex_empty theorem strictConvex_univ : StrictConvex 𝕜 (univ : Set E) := by intro x _ y _ _ a b _ _ _ rw [interior_univ] exact mem_univ _ #align strict_convex_univ strictConvex_univ protected nonrec theorem StrictConvex.eq (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (h : a • x + b • y ∉ interior s) : x = y := hs.eq hx hy fun H => h <| H ha hb hab #align strict_convex.eq StrictConvex.eq protected theorem StrictConvex.inter {t : Set E} (hs : StrictConvex 𝕜 s) (ht : StrictConvex 𝕜 t) : StrictConvex 𝕜 (s ∩ t) := by intro x hx y hy hxy a b ha hb hab rw [interior_inter] exact ⟨hs hx.1 hy.1 hxy ha hb hab, ht hx.2 hy.2 hxy ha hb hab⟩ #align strict_convex.inter StrictConvex.inter theorem Directed.strictConvex_iUnion {ι : Sort*} {s : ι → Set E} (hdir : Directed (· ⊆ ·) s) (hs : ∀ ⦃i : ι⦄, StrictConvex 𝕜 (s i)) : StrictConvex 𝕜 (⋃ i, s i) := by rintro x hx y hy hxy a b ha hb hab rw [mem_iUnion] at hx hy obtain ⟨i, hx⟩ := hx obtain ⟨j, hy⟩ := hy obtain ⟨k, hik, hjk⟩ := hdir i j exact interior_mono (subset_iUnion s k) (hs (hik hx) (hjk hy) hxy ha hb hab) #align directed.strict_convex_Union Directed.strictConvex_iUnion theorem DirectedOn.strictConvex_sUnion {S : Set (Set E)} (hdir : DirectedOn (· ⊆ ·) S) (hS : ∀ s ∈ S, StrictConvex 𝕜 s) : StrictConvex 𝕜 (⋃₀ S) := by rw [sUnion_eq_iUnion] exact (directedOn_iff_directed.1 hdir).strictConvex_iUnion fun s => hS _ s.2 #align directed_on.strict_convex_sUnion DirectedOn.strictConvex_sUnion end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {s : Set E} protected theorem StrictConvex.convex (hs : StrictConvex 𝕜 s) : Convex 𝕜 s := convex_iff_pairwise_pos.2 fun _ hx _ hy hxy _ _ ha hb hab => interior_subset <| hs hx hy hxy ha hb hab #align strict_convex.convex StrictConvex.convex /-- An open convex set is strictly convex. -/ protected theorem Convex.strictConvex_of_isOpen (h : IsOpen s) (hs : Convex 𝕜 s) : StrictConvex 𝕜 s := fun _ hx _ hy _ _ _ ha hb hab => h.interior_eq.symm ▸ hs hx hy ha.le hb.le hab #align convex.strict_convex_of_open Convex.strictConvex_of_isOpen theorem IsOpen.strictConvex_iff (h : IsOpen s) : StrictConvex 𝕜 s ↔ Convex 𝕜 s := ⟨StrictConvex.convex, Convex.strictConvex_of_isOpen h⟩ #align is_open.strict_convex_iff IsOpen.strictConvex_iff theorem strictConvex_singleton (c : E) : StrictConvex 𝕜 ({c} : Set E) := pairwise_singleton _ _ #align strict_convex_singleton strictConvex_singleton theorem Set.Subsingleton.strictConvex (hs : s.Subsingleton) : StrictConvex 𝕜 s := hs.pairwise _ #align set.subsingleton.strict_convex Set.Subsingleton.strictConvex theorem StrictConvex.linear_image [Semiring 𝕝] [Module 𝕝 E] [Module 𝕝 F] [LinearMap.CompatibleSMul E F 𝕜 𝕝] (hs : StrictConvex 𝕜 s) (f : E →ₗ[𝕝] F) (hf : IsOpenMap f) : StrictConvex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ hxy a b ha hb hab refine hf.image_interior_subset _ ⟨a • x + b • y, hs hx hy (ne_of_apply_ne _ hxy) ha hb hab, ?_⟩ rw [map_add, f.map_smul_of_tower a, f.map_smul_of_tower b] #align strict_convex.linear_image StrictConvex.linear_image theorem StrictConvex.is_linear_image (hs : StrictConvex 𝕜 s) {f : E → F} (h : IsLinearMap 𝕜 f) (hf : IsOpenMap f) : StrictConvex 𝕜 (f '' s) := hs.linear_image (h.mk' f) hf #align strict_convex.is_linear_image StrictConvex.is_linear_image theorem StrictConvex.linear_preimage {s : Set F} (hs : StrictConvex 𝕜 s) (f : E →ₗ[𝕜] F) (hf : Continuous f) (hfinj : Injective f) : StrictConvex 𝕜 (s.preimage f) := by intro x hx y hy hxy a b ha hb hab refine preimage_interior_subset_interior_preimage hf ?_ rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hx hy (hfinj.ne hxy) ha hb hab #align strict_convex.linear_preimage StrictConvex.linear_preimage theorem StrictConvex.is_linear_preimage {s : Set F} (hs : StrictConvex 𝕜 s) {f : E → F} (h : IsLinearMap 𝕜 f) (hf : Continuous f) (hfinj : Injective f) : StrictConvex 𝕜 (s.preimage f) := hs.linear_preimage (h.mk' f) hf hfinj #align strict_convex.is_linear_preimage StrictConvex.is_linear_preimage section LinearOrderedCancelAddCommMonoid variable [TopologicalSpace β] [LinearOrderedCancelAddCommMonoid β] [OrderTopology β] [Module 𝕜 β] [OrderedSMul 𝕜 β] protected theorem Set.OrdConnected.strictConvex {s : Set β} (hs : OrdConnected s) : StrictConvex 𝕜 s := by refine strictConvex_iff_openSegment_subset.2 fun x hx y hy hxy => ?_ cases' hxy.lt_or_lt with hlt hlt <;> [skip; rw [openSegment_symm]] <;> exact (openSegment_subset_Ioo hlt).trans (isOpen_Ioo.subset_interior_iff.2 <| Ioo_subset_Icc_self.trans <| hs.out ‹_› ‹_›) #align set.ord_connected.strict_convex Set.OrdConnected.strictConvex theorem strictConvex_Iic (r : β) : StrictConvex 𝕜 (Iic r) := ordConnected_Iic.strictConvex #align strict_convex_Iic strictConvex_Iic theorem strictConvex_Ici (r : β) : StrictConvex 𝕜 (Ici r) := ordConnected_Ici.strictConvex #align strict_convex_Ici strictConvex_Ici theorem strictConvex_Iio (r : β) : StrictConvex 𝕜 (Iio r) := ordConnected_Iio.strictConvex #align strict_convex_Iio strictConvex_Iio theorem strictConvex_Ioi (r : β) : StrictConvex 𝕜 (Ioi r) := ordConnected_Ioi.strictConvex #align strict_convex_Ioi strictConvex_Ioi theorem strictConvex_Icc (r s : β) : StrictConvex 𝕜 (Icc r s) := ordConnected_Icc.strictConvex #align strict_convex_Icc strictConvex_Icc theorem strictConvex_Ioo (r s : β) : StrictConvex 𝕜 (Ioo r s) := ordConnected_Ioo.strictConvex #align strict_convex_Ioo strictConvex_Ioo theorem strictConvex_Ico (r s : β) : StrictConvex 𝕜 (Ico r s) := ordConnected_Ico.strictConvex #align strict_convex_Ico strictConvex_Ico theorem strictConvex_Ioc (r s : β) : StrictConvex 𝕜 (Ioc r s) := ordConnected_Ioc.strictConvex #align strict_convex_Ioc strictConvex_Ioc theorem strictConvex_uIcc (r s : β) : StrictConvex 𝕜 (uIcc r s) := strictConvex_Icc _ _ #align strict_convex_uIcc strictConvex_uIcc theorem strictConvex_uIoc (r s : β) : StrictConvex 𝕜 (uIoc r s) := strictConvex_Ioc _ _ #align strict_convex_uIoc strictConvex_uIoc end LinearOrderedCancelAddCommMonoid end Module end AddCommMonoid section AddCancelCommMonoid variable [AddCancelCommMonoid E] [ContinuousAdd E] [Module 𝕜 E] {s : Set E} /-- The translation of a strictly convex set is also strictly convex. -/ theorem StrictConvex.preimage_add_right (hs : StrictConvex 𝕜 s) (z : E) : StrictConvex 𝕜 ((fun x => z + x) ⁻¹' s) := by intro x hx y hy hxy a b ha hb hab refine preimage_interior_subset_interior_preimage (continuous_add_left _) ?_ have h := hs hx hy ((add_right_injective _).ne hxy) ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← _root_.add_smul, hab, one_smul] at h #align strict_convex.preimage_add_right StrictConvex.preimage_add_right /-- The translation of a strictly convex set is also strictly convex. -/ theorem StrictConvex.preimage_add_left (hs : StrictConvex 𝕜 s) (z : E) : StrictConvex 𝕜 ((fun x => x + z) ⁻¹' s) := by simpa only [add_comm] using hs.preimage_add_right z #align strict_convex.preimage_add_left StrictConvex.preimage_add_left end AddCancelCommMonoid section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] section continuous_add variable [ContinuousAdd E] {s t : Set E}
Mathlib/Analysis/Convex/Strict.lean
246
258
theorem StrictConvex.add (hs : StrictConvex 𝕜 s) (ht : StrictConvex 𝕜 t) : StrictConvex 𝕜 (s + t) := by
rintro _ ⟨v, hv, w, hw, rfl⟩ _ ⟨x, hx, y, hy, rfl⟩ h a b ha hb hab rw [smul_add, smul_add, add_add_add_comm] obtain rfl | hvx := eq_or_ne v x · refine interior_mono (add_subset_add (singleton_subset_iff.2 hv) Subset.rfl) ?_ rw [Convex.combo_self hab, singleton_add] exact (isOpenMap_add_left _).image_interior_subset _ (mem_image_of_mem _ <| ht hw hy (ne_of_apply_ne _ h) ha hb hab) exact subset_interior_add_left (add_mem_add (hs hv hx hvx ha hb hab) <| ht.convex hw hy ha.le hb.le hab)
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Normed.Group.Lemmas import Mathlib.Analysis.NormedSpace.AddTorsor import Mathlib.Analysis.NormedSpace.AffineIsometry import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Analysis.NormedSpace.RieszLemma import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Topology.Algebra.Module.FiniteDimension import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Topology.Instances.Matrix #align_import analysis.normed_space.finite_dimension from "leanprover-community/mathlib"@"9425b6f8220e53b059f5a4904786c3c4b50fc057" /-! # Finite dimensional normed spaces over complete fields Over a complete nontrivially normed field, in finite dimension, all norms are equivalent and all linear maps are continuous. Moreover, a finite-dimensional subspace is always complete and closed. ## Main results: * `FiniteDimensional.complete` : a finite-dimensional space over a complete field is complete. This is not registered as an instance, as the field would be an unknown metavariable in typeclass resolution. * `Submodule.closed_of_finiteDimensional` : a finite-dimensional subspace over a complete field is closed * `FiniteDimensional.proper` : a finite-dimensional space over a proper field is proper. This is not registered as an instance, as the field would be an unknown metavariable in typeclass resolution. It is however registered as an instance for `𝕜 = ℝ` and `𝕜 = ℂ`. As properness implies completeness, there is no need to also register `FiniteDimensional.complete` on `ℝ` or `ℂ`. * `FiniteDimensional.of_isCompact_closedBall`: Riesz' theorem: if the closed unit ball is compact, then the space is finite-dimensional. ## Implementation notes The fact that all norms are equivalent is not written explicitly, as it would mean having two norms on a single space, which is not the way type classes work. However, if one has a finite-dimensional vector space `E` with a norm, and a copy `E'` of this type with another norm, then the identities from `E` to `E'` and from `E'`to `E` are continuous thanks to `LinearMap.continuous_of_finiteDimensional`. This gives the desired norm equivalence. -/ universe u v w x noncomputable section open Set FiniteDimensional TopologicalSpace Filter Asymptotics Classical Topology NNReal Metric namespace LinearIsometry open LinearMap variable {R : Type*} [Semiring R] variable {F E₁ : Type*} [SeminormedAddCommGroup F] [NormedAddCommGroup E₁] [Module R E₁] variable {R₁ : Type*} [Field R₁] [Module R₁ E₁] [Module R₁ F] [FiniteDimensional R₁ E₁] [FiniteDimensional R₁ F] /-- A linear isometry between finite dimensional spaces of equal dimension can be upgraded to a linear isometry equivalence. -/ def toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) : E₁ ≃ₗᵢ[R₁] F where toLinearEquiv := li.toLinearMap.linearEquivOfInjective li.injective h norm_map' := li.norm_map' #align linear_isometry.to_linear_isometry_equiv LinearIsometry.toLinearIsometryEquiv @[simp] theorem coe_toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) : (li.toLinearIsometryEquiv h : E₁ → F) = li := rfl #align linear_isometry.coe_to_linear_isometry_equiv LinearIsometry.coe_toLinearIsometryEquiv @[simp] theorem toLinearIsometryEquiv_apply (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) (x : E₁) : (li.toLinearIsometryEquiv h) x = li x := rfl #align linear_isometry.to_linear_isometry_equiv_apply LinearIsometry.toLinearIsometryEquiv_apply end LinearIsometry namespace AffineIsometry open AffineMap variable {𝕜 : Type*} {V₁ V₂ : Type*} {P₁ P₂ : Type*} [NormedField 𝕜] [NormedAddCommGroup V₁] [SeminormedAddCommGroup V₂] [NormedSpace 𝕜 V₁] [NormedSpace 𝕜 V₂] [MetricSpace P₁] [PseudoMetricSpace P₂] [NormedAddTorsor V₁ P₁] [NormedAddTorsor V₂ P₂] variable [FiniteDimensional 𝕜 V₁] [FiniteDimensional 𝕜 V₂] /-- An affine isometry between finite dimensional spaces of equal dimension can be upgraded to an affine isometry equivalence. -/ def toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : P₁ ≃ᵃⁱ[𝕜] P₂ := AffineIsometryEquiv.mk' li (li.linearIsometry.toLinearIsometryEquiv h) (Inhabited.default (α := P₁)) fun p => by simp #align affine_isometry.to_affine_isometry_equiv AffineIsometry.toAffineIsometryEquiv @[simp] theorem coe_toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : (li.toAffineIsometryEquiv h : P₁ → P₂) = li := rfl #align affine_isometry.coe_to_affine_isometry_equiv AffineIsometry.coe_toAffineIsometryEquiv @[simp] theorem toAffineIsometryEquiv_apply [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) (x : P₁) : (li.toAffineIsometryEquiv h) x = li x := rfl #align affine_isometry.to_affine_isometry_equiv_apply AffineIsometry.toAffineIsometryEquiv_apply end AffineIsometry section CompleteField variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type w} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {F' : Type x} [AddCommGroup F'] [Module 𝕜 F'] [TopologicalSpace F'] [TopologicalAddGroup F'] [ContinuousSMul 𝕜 F'] [CompleteSpace 𝕜] section Affine variable {PE PF : Type*} [MetricSpace PE] [NormedAddTorsor E PE] [MetricSpace PF] [NormedAddTorsor F PF] [FiniteDimensional 𝕜 E] theorem AffineMap.continuous_of_finiteDimensional (f : PE →ᵃ[𝕜] PF) : Continuous f := AffineMap.continuous_linear_iff.1 f.linear.continuous_of_finiteDimensional #align affine_map.continuous_of_finite_dimensional AffineMap.continuous_of_finiteDimensional theorem AffineEquiv.continuous_of_finiteDimensional (f : PE ≃ᵃ[𝕜] PF) : Continuous f := f.toAffineMap.continuous_of_finiteDimensional #align affine_equiv.continuous_of_finite_dimensional AffineEquiv.continuous_of_finiteDimensional /-- Reinterpret an affine equivalence as a homeomorphism. -/ def AffineEquiv.toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) : PE ≃ₜ PF where toEquiv := f.toEquiv continuous_toFun := f.continuous_of_finiteDimensional continuous_invFun := haveI : FiniteDimensional 𝕜 F := f.linear.finiteDimensional f.symm.continuous_of_finiteDimensional #align affine_equiv.to_homeomorph_of_finite_dimensional AffineEquiv.toHomeomorphOfFiniteDimensional @[simp] theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) : ⇑f.toHomeomorphOfFiniteDimensional = f := rfl #align affine_equiv.coe_to_homeomorph_of_finite_dimensional AffineEquiv.coe_toHomeomorphOfFiniteDimensional @[simp] theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional_symm (f : PE ≃ᵃ[𝕜] PF) : ⇑f.toHomeomorphOfFiniteDimensional.symm = f.symm := rfl #align affine_equiv.coe_to_homeomorph_of_finite_dimensional_symm AffineEquiv.coe_toHomeomorphOfFiniteDimensional_symm end Affine theorem ContinuousLinearMap.continuous_det : Continuous fun f : E →L[𝕜] E => f.det := by change Continuous fun f : E →L[𝕜] E => LinearMap.det (f : E →ₗ[𝕜] E) -- Porting note: this could be easier with `det_cases` by_cases h : ∃ s : Finset E, Nonempty (Basis (↥s) 𝕜 E) · rcases h with ⟨s, ⟨b⟩⟩ haveI : FiniteDimensional 𝕜 E := FiniteDimensional.of_fintype_basis b simp_rw [LinearMap.det_eq_det_toMatrix_of_finset b] refine Continuous.matrix_det ?_ exact ((LinearMap.toMatrix b b).toLinearMap.comp (ContinuousLinearMap.coeLM 𝕜)).continuous_of_finiteDimensional · -- Porting note: was `unfold LinearMap.det` rw [LinearMap.det_def] simpa only [h, MonoidHom.one_apply, dif_neg, not_false_iff] using continuous_const #align continuous_linear_map.continuous_det ContinuousLinearMap.continuous_det /-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse constant `C * K` where `C` only depends on `E'`. We record a working value for this constant `C` as `lipschitzExtensionConstant E'`. -/ irreducible_def lipschitzExtensionConstant (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] : ℝ≥0 := let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv max (‖A.symm.toContinuousLinearMap‖₊ * ‖A.toContinuousLinearMap‖₊) 1 #align lipschitz_extension_constant lipschitzExtensionConstant theorem lipschitzExtensionConstant_pos (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] : 0 < lipschitzExtensionConstant E' := by rw [lipschitzExtensionConstant] exact zero_lt_one.trans_le (le_max_right _ _) #align lipschitz_extension_constant_pos lipschitzExtensionConstant_pos /-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse constant `lipschitzExtensionConstant E' * K`. -/ theorem LipschitzOnWith.extend_finite_dimension {α : Type*} [PseudoMetricSpace α] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] {s : Set α} {f : α → E'} {K : ℝ≥0} (hf : LipschitzOnWith K f s) : ∃ g : α → E', LipschitzWith (lipschitzExtensionConstant E' * K) g ∧ EqOn f g s := by /- This result is already known for spaces `ι → ℝ`. We use a continuous linear equiv between `E'` and such a space to transfer the result to `E'`. -/ let ι : Type _ := Basis.ofVectorSpaceIndex ℝ E' let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv have LA : LipschitzWith ‖A.toContinuousLinearMap‖₊ A := by apply A.lipschitz have L : LipschitzOnWith (‖A.toContinuousLinearMap‖₊ * K) (A ∘ f) s := LA.comp_lipschitzOnWith hf obtain ⟨g, hg, gs⟩ : ∃ g : α → ι → ℝ, LipschitzWith (‖A.toContinuousLinearMap‖₊ * K) g ∧ EqOn (A ∘ f) g s := L.extend_pi refine ⟨A.symm ∘ g, ?_, ?_⟩ · have LAsymm : LipschitzWith ‖A.symm.toContinuousLinearMap‖₊ A.symm := by apply A.symm.lipschitz apply (LAsymm.comp hg).weaken rw [lipschitzExtensionConstant, ← mul_assoc] exact mul_le_mul' (le_max_left _ _) le_rfl · intro x hx have : A (f x) = g x := gs hx simp only [(· ∘ ·), ← this, A.symm_apply_apply] #align lipschitz_on_with.extend_finite_dimension LipschitzOnWith.extend_finite_dimension theorem LinearMap.exists_antilipschitzWith [FiniteDimensional 𝕜 E] (f : E →ₗ[𝕜] F) (hf : LinearMap.ker f = ⊥) : ∃ K > 0, AntilipschitzWith K f := by cases subsingleton_or_nontrivial E · exact ⟨1, zero_lt_one, AntilipschitzWith.of_subsingleton⟩ · rw [LinearMap.ker_eq_bot] at hf let e : E ≃L[𝕜] LinearMap.range f := (LinearEquiv.ofInjective f hf).toContinuousLinearEquiv exact ⟨_, e.nnnorm_symm_pos, e.antilipschitz⟩ #align linear_map.exists_antilipschitz_with LinearMap.exists_antilipschitzWith open Function in /-- A `LinearMap` on a finite-dimensional space over a complete field is injective iff it is anti-Lipschitz. -/ theorem LinearMap.injective_iff_antilipschitz [FiniteDimensional 𝕜 E] (f : E →ₗ[𝕜] F) : Injective f ↔ ∃ K > 0, AntilipschitzWith K f := by constructor · rw [← LinearMap.ker_eq_bot] exact f.exists_antilipschitzWith · rintro ⟨K, -, H⟩ exact H.injective open Function in /-- The set of injective continuous linear maps `E → F` is open, if `E` is finite-dimensional over a complete field. -/ theorem ContinuousLinearMap.isOpen_injective [FiniteDimensional 𝕜 E] : IsOpen { L : E →L[𝕜] F | Injective L } := by rw [isOpen_iff_eventually] rintro φ₀ hφ₀ rcases φ₀.injective_iff_antilipschitz.mp hφ₀ with ⟨K, K_pos, H⟩ have : ∀ᶠ φ in 𝓝 φ₀, ‖φ - φ₀‖₊ < K⁻¹ := eventually_nnnorm_sub_lt _ <| inv_pos_of_pos K_pos filter_upwards [this] with φ hφ apply φ.injective_iff_antilipschitz.mpr exact ⟨(K⁻¹ - ‖φ - φ₀‖₊)⁻¹, inv_pos_of_pos (tsub_pos_of_lt hφ), H.add_sub_lipschitzWith (φ - φ₀).lipschitz hφ⟩ protected theorem LinearIndependent.eventually {ι} [Finite ι] {f : ι → E} (hf : LinearIndependent 𝕜 f) : ∀ᶠ g in 𝓝 f, LinearIndependent 𝕜 g := by cases nonempty_fintype ι simp only [Fintype.linearIndependent_iff'] at hf ⊢ rcases LinearMap.exists_antilipschitzWith _ hf with ⟨K, K0, hK⟩ have : Tendsto (fun g : ι → E => ∑ i, ‖g i - f i‖) (𝓝 f) (𝓝 <| ∑ i, ‖f i - f i‖) := tendsto_finset_sum _ fun i _ => Tendsto.norm <| ((continuous_apply i).tendsto _).sub tendsto_const_nhds simp only [sub_self, norm_zero, Finset.sum_const_zero] at this refine (this.eventually (gt_mem_nhds <| inv_pos.2 K0)).mono fun g hg => ?_ replace hg : ∑ i, ‖g i - f i‖₊ < K⁻¹ := by rw [← NNReal.coe_lt_coe] push_cast exact hg rw [LinearMap.ker_eq_bot] refine (hK.add_sub_lipschitzWith (LipschitzWith.of_dist_le_mul fun v u => ?_) hg).injective simp only [dist_eq_norm, LinearMap.lsum_apply, Pi.sub_apply, LinearMap.sum_apply, LinearMap.comp_apply, LinearMap.proj_apply, LinearMap.smulRight_apply, LinearMap.id_apply, ← Finset.sum_sub_distrib, ← smul_sub, ← sub_smul, NNReal.coe_sum, coe_nnnorm, Finset.sum_mul] refine norm_sum_le_of_le _ fun i _ => ?_ rw [norm_smul, mul_comm] gcongr exact norm_le_pi_norm (v - u) i #align linear_independent.eventually LinearIndependent.eventually theorem isOpen_setOf_linearIndependent {ι : Type*} [Finite ι] : IsOpen { f : ι → E | LinearIndependent 𝕜 f } := isOpen_iff_mem_nhds.2 fun _ => LinearIndependent.eventually #align is_open_set_of_linear_independent isOpen_setOf_linearIndependent theorem isOpen_setOf_nat_le_rank (n : ℕ) : IsOpen { f : E →L[𝕜] F | ↑n ≤ (f : E →ₗ[𝕜] F).rank } := by simp only [LinearMap.le_rank_iff_exists_linearIndependent_finset, setOf_exists, ← exists_prop] refine isOpen_biUnion fun t _ => ?_ have : Continuous fun f : E →L[𝕜] F => fun x : (t : Set E) => f x := continuous_pi fun x => (ContinuousLinearMap.apply 𝕜 F (x : E)).continuous exact isOpen_setOf_linearIndependent.preimage this #align is_open_set_of_nat_le_rank isOpen_setOf_nat_le_rank theorem Basis.opNNNorm_le {ι : Type*} [Fintype ι] (v : Basis ι 𝕜 E) {u : E →L[𝕜] F} (M : ℝ≥0) (hu : ∀ i, ‖u (v i)‖₊ ≤ M) : ‖u‖₊ ≤ Fintype.card ι • ‖v.equivFunL.toContinuousLinearMap‖₊ * M := u.opNNNorm_le_bound _ fun e => by set φ := v.equivFunL.toContinuousLinearMap calc ‖u e‖₊ = ‖u (∑ i, v.equivFun e i • v i)‖₊ := by rw [v.sum_equivFun] _ = ‖∑ i, v.equivFun e i • (u <| v i)‖₊ := by simp [map_sum, LinearMap.map_smul] _ ≤ ∑ i, ‖v.equivFun e i • (u <| v i)‖₊ := nnnorm_sum_le _ _ _ = ∑ i, ‖v.equivFun e i‖₊ * ‖u (v i)‖₊ := by simp only [nnnorm_smul] _ ≤ ∑ i, ‖v.equivFun e i‖₊ * M := by gcongr; apply hu _ = (∑ i, ‖v.equivFun e i‖₊) * M := by rw [Finset.sum_mul] _ ≤ Fintype.card ι • (‖φ‖₊ * ‖e‖₊) * M := by gcongr calc ∑ i, ‖v.equivFun e i‖₊ ≤ Fintype.card ι • ‖φ e‖₊ := Pi.sum_nnnorm_apply_le_nnnorm _ _ ≤ Fintype.card ι • (‖φ‖₊ * ‖e‖₊) := nsmul_le_nsmul_right (φ.le_opNNNorm e) _ _ = Fintype.card ι • ‖φ‖₊ * M * ‖e‖₊ := by simp only [smul_mul_assoc, mul_right_comm] #align basis.op_nnnorm_le Basis.opNNNorm_le @[deprecated (since := "2024-02-02")] alias Basis.op_nnnorm_le := Basis.opNNNorm_le
Mathlib/Analysis/NormedSpace/FiniteDimension.lean
317
320
theorem Basis.opNorm_le {ι : Type*} [Fintype ι] (v : Basis ι 𝕜 E) {u : E →L[𝕜] F} {M : ℝ} (hM : 0 ≤ M) (hu : ∀ i, ‖u (v i)‖ ≤ M) : ‖u‖ ≤ Fintype.card ι • ‖v.equivFunL.toContinuousLinearMap‖ * M := by
simpa using NNReal.coe_le_coe.mpr (v.opNNNorm_le ⟨M, hM⟩ hu)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Measure.MutuallySingular import Mathlib.MeasureTheory.Measure.Count import Mathlib.Topology.IndicatorConstPointwise import Mathlib.MeasureTheory.Constructions.BorelSpace.Real #align_import measure_theory.integral.lebesgue from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Lower Lebesgue integral for `ℝ≥0∞`-valued functions We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function. ## Notation We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`. * `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`; * `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure `volume` on `α`; * `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`; * `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`. -/ assert_not_exists NormedSpace set_option autoImplicit true noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc variable {α β γ δ : Type*} section Lintegral open SimpleFunc variable {m : MeasurableSpace α} {μ ν : Measure α} /-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/ irreducible_def lintegral {_ : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ := ⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ #align measure_theory.lintegral MeasureTheory.lintegral /-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫⁻ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = f.lintegral μ := by rw [MeasureTheory.lintegral] exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl) (le_iSup₂_of_le f le_rfl le_rfl) #align measure_theory.simple_func.lintegral_eq_lintegral MeasureTheory.SimpleFunc.lintegral_eq_lintegral @[mono] theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by rw [lintegral, lintegral] exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩ #align measure_theory.lintegral_mono' MeasureTheory.lintegral_mono' -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn' ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) (h2 : μ ≤ ν) : lintegral μ f ≤ lintegral ν g := lintegral_mono' h2 hfg theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono' (le_refl μ) hfg #align measure_theory.lintegral_mono MeasureTheory.lintegral_mono -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : lintegral μ f ≤ lintegral μ g := lintegral_mono hfg theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a) #align measure_theory.lintegral_mono_nnreal MeasureTheory.lintegral_mono_nnreal theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) : ⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by apply le_antisymm · exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i · rw [lintegral] refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_ exact le_of_eq (i.lintegral_eq_lintegral _).symm #align measure_theory.supr_lintegral_measurable_le_eq_lintegral MeasureTheory.iSup_lintegral_measurable_le_eq_lintegral theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set MeasureTheory.lintegral_mono_set theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set' MeasureTheory.lintegral_mono_set' theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) := lintegral_mono #align measure_theory.monotone_lintegral MeasureTheory.monotone_lintegral @[simp] theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const] rfl #align measure_theory.lintegral_const MeasureTheory.lintegral_const theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp #align measure_theory.lintegral_zero MeasureTheory.lintegral_zero theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 := lintegral_zero #align measure_theory.lintegral_zero_fun MeasureTheory.lintegral_zero_fun -- @[simp] -- Porting note (#10618): simp can prove this theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul] #align measure_theory.lintegral_one MeasureTheory.lintegral_one theorem set_lintegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by rw [lintegral_const, Measure.restrict_apply_univ] #align measure_theory.set_lintegral_const MeasureTheory.set_lintegral_const theorem set_lintegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [set_lintegral_const, one_mul] #align measure_theory.set_lintegral_one MeasureTheory.set_lintegral_one theorem set_lintegral_const_lt_top [IsFiniteMeasure μ] (s : Set α) {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _ in s, c ∂μ < ∞ := by rw [lintegral_const] exact ENNReal.mul_lt_top hc (measure_ne_top (μ.restrict s) univ) #align measure_theory.set_lintegral_const_lt_top MeasureTheory.set_lintegral_const_lt_top theorem lintegral_const_lt_top [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _, c ∂μ < ∞ := by simpa only [Measure.restrict_univ] using set_lintegral_const_lt_top (univ : Set α) hc #align measure_theory.lintegral_const_lt_top MeasureTheory.lintegral_const_lt_top section variable (μ) /-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same integral. -/ theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) : ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀ · exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩ rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩ have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by intro n simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using (hLf n).2 choose g hgm hgf hLg using this refine ⟨fun x => ⨆ n, g n x, measurable_iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩ · refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_ exact le_iSup (fun n => g n x) n · exact lintegral_mono fun x => iSup_le fun n => hgf n x #align measure_theory.exists_measurable_le_lintegral_eq MeasureTheory.exists_measurable_le_lintegral_eq end /-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions `φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take functions `φ : α →ₛ ℝ≥0`. -/
Mathlib/MeasureTheory/Integral/Lebesgue.lean
199
220
theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = ⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by
rw [lintegral] refine le_antisymm (iSup₂_le fun φ hφ => ?_) (iSup_mono' fun φ => ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩) by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞ · let ψ := φ.map ENNReal.toNNReal replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x) exact le_iSup_of_le (φ.map ENNReal.toNNReal) (le_iSup_of_le this (ge_of_eq <| lintegral_congr h)) · have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_nmem.1 h refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_) obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb) use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞}) simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const, ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast, restrict_const_lintegral] refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩ simp only [mem_preimage, mem_singleton_iff] at hx simp only [hx, le_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, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse #align_import analysis.special_functions.complex.arg from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # The argument of a complex number. We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, while `arg 0` defaults to `0` -/ open Filter Metric Set open scoped ComplexConjugate Real Topology namespace Complex variable {a x z : ℂ} /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then Real.arcsin (x.im / abs x) else if 0 ≤ x.im then Real.arcsin ((-x).im / abs x) + π else Real.arcsin ((-x).im / abs x) - π #align complex.arg Complex.arg theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / abs x := by unfold arg; split_ifs <;> simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg] #align complex.sin_arg Complex.sin_arg theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / abs x := by rw [arg] split_ifs with h₁ h₂ · rw [Real.cos_arcsin] field_simp [Real.sqrt_sq, (abs.pos hx).le, *] · rw [Real.cos_add_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] · rw [Real.cos_sub_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] #align complex.cos_arg Complex.cos_arg @[simp] theorem abs_mul_exp_arg_mul_I (x : ℂ) : ↑(abs x) * exp (arg x * I) = x := by rcases eq_or_ne x 0 with (rfl | hx) · simp · have : abs x ≠ 0 := abs.ne_zero hx apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)] set_option linter.uppercaseLean3 false in #align complex.abs_mul_exp_arg_mul_I Complex.abs_mul_exp_arg_mul_I @[simp] theorem abs_mul_cos_add_sin_mul_I (x : ℂ) : (abs x * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by rw [← exp_mul_I, abs_mul_exp_arg_mul_I] set_option linter.uppercaseLean3 false in #align complex.abs_mul_cos_add_sin_mul_I Complex.abs_mul_cos_add_sin_mul_I @[simp] lemma abs_mul_cos_arg (x : ℂ) : abs x * Real.cos (arg x) = x.re := by simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg re (abs_mul_cos_add_sin_mul_I x) @[simp] lemma abs_mul_sin_arg (x : ℂ) : abs x * Real.sin (arg x) = x.im := by simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg im (abs_mul_cos_add_sin_mul_I x) theorem abs_eq_one_iff (z : ℂ) : abs z = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z := by refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩ · calc exp (arg z * I) = abs z * exp (arg z * I) := by rw [hz, ofReal_one, one_mul] _ = z := abs_mul_exp_arg_mul_I z · rintro ⟨θ, rfl⟩ exact Complex.abs_exp_ofReal_mul_I θ #align complex.abs_eq_one_iff Complex.abs_eq_one_iff @[simp] theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by ext x simp only [mem_sphere_zero_iff_norm, norm_eq_abs, abs_eq_one_iff, Set.mem_range] set_option linter.uppercaseLean3 false in #align complex.range_exp_mul_I Complex.range_exp_mul_I theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (r * (cos θ + sin θ * I)) = θ := by simp only [arg, map_mul, abs_cos_add_sin_mul_I, abs_of_nonneg hr.le, mul_one] simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ← mk_eq_add_mul_I, neg_div, mul_div_cancel_left₀ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr] by_cases h₁ : θ ∈ Set.Icc (-(π / 2)) (π / 2) · rw [if_pos] exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁] · rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁ cases' h₁ with h₁ h₁ · replace hθ := hθ.1 have hcos : Real.cos θ < 0 := by rw [← neg_pos, ← Real.cos_add_pi] refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith have hsin : Real.sin θ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith; linarith; exact hsin.not_le; exact hcos.not_le] · replace hθ := hθ.2 have hcos : Real.cos θ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith) have hsin : 0 ≤ Real.sin θ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩ rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith; linarith; exact hsin; exact hcos.not_le] set_option linter.uppercaseLean3 false in #align complex.arg_mul_cos_add_sin_mul_I Complex.arg_mul_cos_add_sin_mul_I theorem arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (cos θ + sin θ * I) = θ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ] set_option linter.uppercaseLean3 false in #align complex.arg_cos_add_sin_mul_I Complex.arg_cos_add_sin_mul_I lemma arg_exp_mul_I (θ : ℝ) : arg (exp (θ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ := by convert arg_cos_add_sin_mul_I (θ := toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ) _ using 2 · rw [← exp_mul_I, eq_sub_of_add_eq $ toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] · convert toIocMod_mem_Ioc _ _ _ ring @[simp] theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl] #align complex.arg_zero Complex.arg_zero theorem ext_abs_arg {x y : ℂ} (h₁ : abs x = abs y) (h₂ : x.arg = y.arg) : x = y := by rw [← abs_mul_exp_arg_mul_I x, ← abs_mul_exp_arg_mul_I y, h₁, h₂] #align complex.ext_abs_arg Complex.ext_abs_arg theorem ext_abs_arg_iff {x y : ℂ} : x = y ↔ abs x = abs y ∧ arg x = arg y := ⟨fun h => h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_abs_arg⟩ #align complex.ext_abs_arg_iff Complex.ext_abs_arg_iff theorem arg_mem_Ioc (z : ℂ) : arg z ∈ Set.Ioc (-π) π := by have hπ : 0 < π := Real.pi_pos rcases eq_or_ne z 0 with (rfl | hz) · simp [hπ, hπ.le] rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩ rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN rw [← abs_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N] have := arg_mul_cos_add_sin_mul_I (abs.pos hz) hN push_cast at this rwa [this] #align complex.arg_mem_Ioc Complex.arg_mem_Ioc @[simp] theorem range_arg : Set.range arg = Set.Ioc (-π) π := (Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩ #align complex.range_arg Complex.range_arg theorem arg_le_pi (x : ℂ) : arg x ≤ π := (arg_mem_Ioc x).2 #align complex.arg_le_pi Complex.arg_le_pi theorem neg_pi_lt_arg (x : ℂ) : -π < arg x := (arg_mem_Ioc x).1 #align complex.neg_pi_lt_arg Complex.neg_pi_lt_arg theorem abs_arg_le_pi (z : ℂ) : |arg z| ≤ π := abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩ #align complex.abs_arg_le_pi Complex.abs_arg_le_pi @[simp] theorem arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im := by rcases eq_or_ne z 0 with (rfl | h₀); · simp calc 0 ≤ arg z ↔ 0 ≤ Real.sin (arg z) := ⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by contrapose! intro h exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩ _ ↔ _ := by rw [sin_arg, le_div_iff (abs.pos h₀), zero_mul] #align complex.arg_nonneg_iff Complex.arg_nonneg_iff @[simp] theorem arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 := lt_iff_lt_of_le_iff_le arg_nonneg_iff #align complex.arg_neg_iff Complex.arg_neg_iff theorem arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by rcases eq_or_ne x 0 with (rfl | hx); · rw [mul_zero] conv_lhs => rw [← abs_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul, arg_mul_cos_add_sin_mul_I (mul_pos hr (abs.pos hx)) x.arg_mem_Ioc] #align complex.arg_real_mul Complex.arg_real_mul theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : ℂ) : arg (x * r) = arg x := mul_comm x r ▸ arg_real_mul x hr theorem arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := by simp only [ext_abs_arg_iff, map_mul, map_div₀, abs_ofReal, abs_abs, div_mul_cancel₀ _ (abs.ne_zero hx), eq_self_iff_true, true_and_iff] rw [← ofReal_div, arg_real_mul] exact div_pos (abs.pos hy) (abs.pos hx) #align complex.arg_eq_arg_iff Complex.arg_eq_arg_iff @[simp] theorem arg_one : arg 1 = 0 := by simp [arg, zero_le_one] #align complex.arg_one Complex.arg_one @[simp] theorem arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)] #align complex.arg_neg_one Complex.arg_neg_one @[simp] theorem arg_I : arg I = π / 2 := by simp [arg, le_refl] set_option linter.uppercaseLean3 false in #align complex.arg_I Complex.arg_I @[simp]
Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean
222
222
theorem arg_neg_I : arg (-I) = -(π / 2) := by
simp [arg, le_refl]
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.Prod import Mathlib.Data.Set.Finite #align_import data.finset.n_ary from "leanprover-community/mathlib"@"eba7871095e834365616b5e43c8c7bb0b37058d0" /-! # N-ary images of finsets This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of `Set.image2`. This is mostly useful to define pointwise operations. ## Notes This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please keep them in sync. We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂` and `Set.image2` already fulfills this task. -/ open Function Set variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} namespace Finset variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ'] [DecidableEq δ] [DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ} {s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ} /-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ := (s ×ˢ t).image <| uncurry f #align finset.image₂ Finset.image₂ @[simp] theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by simp [image₂, and_assoc] #align finset.mem_image₂ Finset.mem_image₂ @[simp, norm_cast] theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : (image₂ f s t : Set γ) = Set.image2 f s t := Set.ext fun _ => mem_image₂ #align finset.coe_image₂ Finset.coe_image₂ theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) : (image₂ f s t).card ≤ s.card * t.card := card_image_le.trans_eq <| card_product _ _ #align finset.card_image₂_le Finset.card_image₂_le theorem card_image₂_iff : (image₂ f s t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by rw [← card_product, ← coe_product] exact card_image_iff #align finset.card_image₂_iff Finset.card_image₂_iff theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) : (image₂ f s t).card = s.card * t.card := (card_image_of_injective _ hf.uncurry).trans <| card_product _ _ #align finset.card_image₂ Finset.card_image₂ theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t := mem_image₂.2 ⟨a, ha, b, hb, rfl⟩ #align finset.mem_image₂_of_mem Finset.mem_image₂_of_mem theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe] #align finset.mem_image₂_iff Finset.mem_image₂_iff theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by rw [← coe_subset, coe_image₂, coe_image₂] exact image2_subset hs ht #align finset.image₂_subset Finset.image₂_subset theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' := image₂_subset Subset.rfl ht #align finset.image₂_subset_left Finset.image₂_subset_left theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t := image₂_subset hs Subset.rfl #align finset.image₂_subset_right Finset.image₂_subset_right theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb #align finset.image_subset_image₂_left Finset.image_subset_image₂_left theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ => mem_image₂_of_mem ha #align finset.image_subset_image₂_right Finset.image_subset_image₂_right theorem forall_image₂_iff {p : γ → Prop} : (∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by simp_rw [← mem_coe, coe_image₂, forall_image2_iff] #align finset.forall_image₂_iff Finset.forall_image₂_iff @[simp] theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u := forall_image₂_iff #align finset.image₂_subset_iff Finset.image₂_subset_iff theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff] #align finset.image₂_subset_iff_left Finset.image₂_subset_iff_left theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α] #align finset.image₂_subset_iff_right Finset.image₂_subset_iff_right @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by rw [← coe_nonempty, coe_image₂] exact image2_nonempty_iff #align finset.image₂_nonempty_iff Finset.image₂_nonempty_iff theorem Nonempty.image₂ (hs : s.Nonempty) (ht : t.Nonempty) : (image₂ f s t).Nonempty := image₂_nonempty_iff.2 ⟨hs, ht⟩ #align finset.nonempty.image₂ Finset.Nonempty.image₂ theorem Nonempty.of_image₂_left (h : (s.image₂ f t).Nonempty) : s.Nonempty := (image₂_nonempty_iff.1 h).1 #align finset.nonempty.of_image₂_left Finset.Nonempty.of_image₂_left theorem Nonempty.of_image₂_right (h : (s.image₂ f t).Nonempty) : t.Nonempty := (image₂_nonempty_iff.1 h).2 #align finset.nonempty.of_image₂_right Finset.Nonempty.of_image₂_right @[simp] theorem image₂_empty_left : image₂ f ∅ t = ∅ := coe_injective <| by simp #align finset.image₂_empty_left Finset.image₂_empty_left @[simp] theorem image₂_empty_right : image₂ f s ∅ = ∅ := coe_injective <| by simp #align finset.image₂_empty_right Finset.image₂_empty_right @[simp]
Mathlib/Data/Finset/NAry.lean
145
146
theorem image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp_rw [← not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_or]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Shing Tak Lam, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Log import Mathlib.Data.List.Indexes import Mathlib.Data.List.Palindrome import Mathlib.Tactic.IntervalCases import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring #align_import data.nat.digits from "leanprover-community/mathlib"@"369525b73f229ccd76a6ec0e0e0bf2be57599768" /-! # Digits of a natural number This provides a basic API for extracting the digits of a natural number in a given base, and reconstructing numbers from their digits. We also prove some divisibility tests based on digits, in particular completing Theorem #85 from https://www.cs.ru.nl/~freek/100/. Also included is a bound on the length of `Nat.toDigits` from core. ## TODO A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b` are numerals is not yet ported. -/ namespace Nat variable {n : ℕ} /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux0 : ℕ → List ℕ | 0 => [] | n + 1 => [n + 1] #align nat.digits_aux_0 Nat.digitsAux0 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux1 (n : ℕ) : List ℕ := List.replicate n 1 #align nat.digits_aux_1 Nat.digitsAux1 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ | 0 => [] | n + 1 => ((n + 1) % b) :: digitsAux b h ((n + 1) / b) decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h #align nat.digits_aux Nat.digitsAux @[simp] theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux] #align nat.digits_aux_zero Nat.digitsAux_zero theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) : digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by cases n · cases w · rw [digitsAux] #align nat.digits_aux_def Nat.digitsAux_def /-- `digits b n` gives the digits, in little-endian order, of a natural number `n` in a specified base `b`. In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`. * For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`, and the last digit is not zero. This uniquely specifies the behaviour of `digits b`. * For `b = 1`, we define `digits 1 n = List.replicate n 1`. * For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`. Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals. In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`. -/ def digits : ℕ → ℕ → List ℕ | 0 => digitsAux0 | 1 => digitsAux1 | b + 2 => digitsAux (b + 2) (by norm_num) #align nat.digits Nat.digits @[simp] theorem digits_zero (b : ℕ) : digits b 0 = [] := by rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1] #align nat.digits_zero Nat.digits_zero -- @[simp] -- Porting note (#10618): simp can prove this theorem digits_zero_zero : digits 0 0 = [] := rfl #align nat.digits_zero_zero Nat.digits_zero_zero @[simp] theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] := rfl #align nat.digits_zero_succ Nat.digits_zero_succ theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n] | 0, h => (h rfl).elim | _ + 1, _ => rfl #align nat.digits_zero_succ' Nat.digits_zero_succ' @[simp] theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 := rfl #align nat.digits_one Nat.digits_one -- @[simp] -- Porting note (#10685): dsimp can prove this theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n := rfl #align nat.digits_one_succ Nat.digits_one_succ theorem digits_add_two_add_one (b n : ℕ) : digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by simp [digits, digitsAux_def] #align nat.digits_add_two_add_one Nat.digits_add_two_add_one @[simp] lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) : Nat.digits b n = n % b :: Nat.digits b (n / b) := by rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one] theorem digits_def' : ∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b) | 0, h => absurd h (by decide) | 1, h => absurd h (by decide) | b + 2, _ => digitsAux_def _ (by simp) _ #align nat.digits_def' Nat.digits_def' @[simp] theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩ rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩ rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb] #align nat.digits_of_lt Nat.digits_of_lt theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) : digits b (x + b * y) = x :: digits b y := by rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩ cases y · simp [hxb, hxy.resolve_right (absurd rfl)] dsimp [digits] rw [digitsAux_def] · congr · simp [Nat.add_mod, mod_eq_of_lt hxb] · simp [add_mul_div_left, div_eq_of_lt hxb] · apply Nat.succ_pos #align nat.digits_add Nat.digits_add -- If we had a function converting a list into a polynomial, -- and appropriate lemmas about that function, -- we could rewrite this in terms of that. /-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them as a number in semiring, as the little-endian digits in base `b`. -/ def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α | [] => 0 | h :: t => h + b * ofDigits b t #align nat.of_digits Nat.ofDigits theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) : ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by induction' L with d L ih · rfl · dsimp [ofDigits] rw [ih] #align nat.of_digits_eq_foldr Nat.ofDigits_eq_foldr theorem ofDigits_eq_sum_map_with_index_aux (b : ℕ) (l : List ℕ) : ((List.range l.length).zipWith ((fun i a : ℕ => a * b ^ (i + 1))) l).sum = b * ((List.range l.length).zipWith (fun i a => a * b ^ i) l).sum := by suffices (List.range l.length).zipWith (fun i a : ℕ => a * b ^ (i + 1)) l = (List.range l.length).zipWith (fun i a => b * (a * b ^ i)) l by simp [this] congr; ext; simp [pow_succ]; ring #align nat.of_digits_eq_sum_map_with_index_aux Nat.ofDigits_eq_sum_map_with_index_aux theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) : ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by rw [List.mapIdx_eq_enum_map, List.enum_eq_zip_range, List.map_uncurry_zip_eq_zipWith, ofDigits_eq_foldr] induction' L with hd tl hl · simp · simpa [List.range_succ_eq_map, List.zipWith_map_left, ofDigits_eq_sum_map_with_index_aux] using Or.inl hl #align nat.of_digits_eq_sum_map_with_index Nat.ofDigits_eq_sum_mapIdx @[simp] theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl @[simp] theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits] #align nat.of_digits_singleton Nat.ofDigits_singleton @[simp] theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) : ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits] #align nat.of_digits_one_cons Nat.ofDigits_one_cons theorem ofDigits_cons {b hd} {tl : List ℕ} : ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} : ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by induction' l1 with hd tl IH · simp [ofDigits] · rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ'] ring #align nat.of_digits_append Nat.ofDigits_append @[norm_cast] theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by induction' L with d L ih · simp [ofDigits] · dsimp [ofDigits]; push_cast; rw [ih] #align nat.coe_of_digits Nat.coe_ofDigits @[norm_cast] theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by induction' L with d L _ · rfl · dsimp [ofDigits]; push_cast; simp only #align nat.coe_int_of_digits Nat.coe_int_ofDigits theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) : ∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0 | _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0 | _ :: _, h0, _, List.Mem.tail _ hL => digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL #align nat.digits_zero_of_eq_zero Nat.digits_zero_of_eq_zero theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b) (w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by induction' L with d L ih · dsimp [ofDigits] simp · dsimp [ofDigits] replace w₂ := w₂ (by simp) rw [digits_add b h] · rw [ih] · intro l m apply w₁ exact List.mem_cons_of_mem _ m · intro h rw [List.getLast_cons h] at w₂ convert w₂ · exact w₁ d (List.mem_cons_self _ _) · by_cases h' : L = [] · rcases h' with rfl left simpa using w₂ · right contrapose! w₂ refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_ rw [List.getLast_cons h'] exact List.getLast_mem h' #align nat.digits_of_digits Nat.digits_ofDigits
Mathlib/Data/Nat/Digits.lean
267
287
theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by
cases' b with b · cases' n with n · rfl · change ofDigits 0 [n + 1] = n + 1 dsimp [ofDigits] · cases' b with b · induction' n with n ih · rfl · rw [Nat.zero_add] at ih ⊢ simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ] · apply Nat.strongInductionOn n _ clear n intro n h cases n · rw [digits_zero] rfl · simp only [Nat.succ_eq_add_one, digits_add_two_add_one] dsimp [ofDigits] rw [h _ (Nat.div_lt_self' _ b)] rw [Nat.mod_add_div]
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import Mathlib.Algebra.NeZero import Mathlib.Data.Nat.Defs import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common #align_import data.fin.basic from "leanprover-community/mathlib"@"3a2b5524a138b5d0b818b858b516d4ac8a484b03" /-! # The finite type with `n` elements `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`. * `Fin.succRec` : Define `C n i` by induction on `i : Fin n` interpreted as `(0 : Fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple. * `Fin.succRecOn` : same as `Fin.succRec` but `i : Fin n` is the first argument; * `Fin.induction` : Define `C i` by induction on `i : Fin (n + 1)`, separating into the `Nat`-like base cases of `C 0` and `C (i.succ)`. * `Fin.inductionOn` : same as `Fin.induction` but with `i : Fin (n + 1)` as the first argument. * `Fin.cases` : define `f : Π i : Fin n.succ, C i` by separately handling the cases `i = 0` and `i = Fin.succ j`, `j : Fin n`, defined using `Fin.induction`. * `Fin.reverseInduction`: reverse induction on `i : Fin (n + 1)`; given `C (Fin.last n)` and `∀ i : Fin n, C (Fin.succ i) → C (Fin.castSucc i)`, constructs all values `C i` by going down; * `Fin.lastCases`: define `f : Π i, Fin (n + 1), C i` by separately handling the cases `i = Fin.last n` and `i = Fin.castSucc j`, a special case of `Fin.reverseInduction`; * `Fin.addCases`: define a function on `Fin (m + n)` by separately handling the cases `Fin.castAdd n i` and `Fin.natAdd m i`; * `Fin.succAboveCases`: given `i : Fin (n + 1)`, define a function on `Fin (n + 1)` by separately handling the cases `j = i` and `j = Fin.succAbove i k`, same as `Fin.insertNth` but marked as eliminator and works for `Sort*`. -- Porting note: this is in another file ### Embeddings and isomorphisms * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.succEmb` : `Fin.succ` as an `Embedding`; * `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`; * `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`; * `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left; ### Other casts * `Fin.ofNat'`: given a positive number `n` (deduced from `[NeZero n]`), `Fin.ofNat' i` is `i % n` interpreted as an element of `Fin n`; * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; ### Misc definitions * `Fin.revPerm : Equiv.Perm (Fin n)` : `Fin.rev` as an `Equiv.Perm`, the antitone involution given by `i ↦ n-(i+1)` -/ assert_not_exists Monoid universe u v open Fin Nat Function /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 #align fin_zero_elim finZeroElim namespace Fin instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where prf k hk := ⟨⟨k, hk⟩, rfl⟩ /-- A dependent variant of `Fin.elim0`. -/ def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _) #align fin.elim0' Fin.elim0 variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff #align fin.fin_to_nat Fin.coeToNat theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n #align fin.val_injective Fin.val_injective /-- If you actually have an element of `Fin n`, then the `n` is always positive -/ lemma size_positive : Fin n → 0 < n := Fin.pos lemma size_positive' [Nonempty (Fin n)] : 0 < n := ‹Nonempty (Fin n)›.elim Fin.pos protected theorem prop (a : Fin n) : a.val < n := a.2 #align fin.prop Fin.prop #align fin.is_lt Fin.is_lt #align fin.pos Fin.pos #align fin.pos_iff_nonempty Fin.pos_iff_nonempty section Order variable {a b c : Fin n} protected lemma lt_of_le_of_lt : a ≤ b → b < c → a < c := Nat.lt_of_le_of_lt protected lemma lt_of_lt_of_le : a < b → b ≤ c → a < c := Nat.lt_of_lt_of_le protected lemma le_rfl : a ≤ a := Nat.le_refl _ protected lemma lt_iff_le_and_ne : a < b ↔ a ≤ b ∧ a ≠ b := by rw [← val_ne_iff]; exact Nat.lt_iff_le_and_ne protected lemma lt_or_lt_of_ne (h : a ≠ b) : a < b ∨ b < a := Nat.lt_or_lt_of_ne $ val_ne_iff.2 h protected lemma lt_or_le (a b : Fin n) : a < b ∨ b ≤ a := Nat.lt_or_ge _ _ protected lemma le_or_lt (a b : Fin n) : a ≤ b ∨ b < a := (b.lt_or_le a).symm protected lemma le_of_eq (hab : a = b) : a ≤ b := Nat.le_of_eq $ congr_arg val hab protected lemma ge_of_eq (hab : a = b) : b ≤ a := Fin.le_of_eq hab.symm protected lemma eq_or_lt_of_le : a ≤ b → a = b ∨ a < b := by rw [ext_iff]; exact Nat.eq_or_lt_of_le protected lemma lt_or_eq_of_le : a ≤ b → a < b ∨ a = b := by rw [ext_iff]; exact Nat.lt_or_eq_of_le end Order lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by simp [Fin.lt_iff_le_and_ne, le_last] lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 := Fin.ne_of_gt $ Fin.lt_of_le_of_lt a.zero_le hab lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n := Fin.ne_of_lt $ Fin.lt_of_lt_of_le hab b.le_last /-- Equivalence between `Fin n` and `{ i // i < n }`. -/ @[simps apply symm_apply] def equivSubtype : Fin n ≃ { i // i < n } where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl #align fin.equiv_subtype Fin.equivSubtype #align fin.equiv_subtype_symm_apply Fin.equivSubtype_symm_apply #align fin.equiv_subtype_apply Fin.equivSubtype_apply section coe /-! ### coercions and constructions -/ #align fin.eta Fin.eta #align fin.ext Fin.ext #align fin.ext_iff Fin.ext_iff #align fin.coe_injective Fin.val_injective theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := ext_iff.symm #align fin.coe_eq_coe Fin.val_eq_val @[deprecated ext_iff (since := "2024-02-20")] theorem eq_iff_veq (a b : Fin n) : a = b ↔ a.1 = b.1 := ext_iff #align fin.eq_iff_veq Fin.eq_iff_veq theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := ext_iff.not #align fin.ne_iff_vne Fin.ne_iff_vne -- Porting note: I'm not sure if this comment still applies. -- built-in reduction doesn't always work @[simp, nolint simpNF] theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := ext_iff #align fin.mk_eq_mk Fin.mk_eq_mk #align fin.mk.inj_iff Fin.mk.inj_iff #align fin.mk_val Fin.val_mk #align fin.eq_mk_iff_coe_eq Fin.eq_mk_iff_val_eq #align fin.coe_mk Fin.val_mk #align fin.mk_coe Fin.mk_val -- syntactic tautologies now #noalign fin.coe_eq_val #noalign fin.val_eq_coe /-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element, then they coincide (in the heq sense). -/ protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by subst h simp [Function.funext_iff] #align fin.heq_fun_iff Fin.heq_fun_iff /-- Assume `k = l` and `k' = l'`. If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair, then they coincide (in the heq sense). -/ protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by subst h subst h' simp [Function.funext_iff] protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ) := by subst h simp [val_eq_val] #align fin.heq_ext_iff Fin.heq_ext_iff #align fin.exists_iff Fin.exists_iff #align fin.forall_iff Fin.forall_iff end coe section Order /-! ### order -/ #align fin.is_le Fin.is_le #align fin.is_le' Fin.is_le' #align fin.lt_iff_coe_lt_coe Fin.lt_iff_val_lt_val theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl #align fin.le_iff_coe_le_coe Fin.le_iff_val_le_val #align fin.mk_lt_of_lt_coe Fin.mk_lt_of_lt_val #align fin.mk_le_of_le_coe Fin.mk_le_of_le_val /-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := Iff.rfl #align fin.coe_fin_lt Fin.val_fin_lt /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := Iff.rfl #align fin.coe_fin_le Fin.val_fin_le #align fin.mk_le_mk Fin.mk_le_mk #align fin.mk_lt_mk Fin.mk_lt_mk -- @[simp] -- Porting note (#10618): simp can prove this theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp #align fin.min_coe Fin.min_val -- @[simp] -- Porting note (#10618): simp can prove this theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp #align fin.max_coe Fin.max_val /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ #align fin.coe_embedding Fin.valEmbedding @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl #align fin.equiv_subtype_symm_trans_val_embedding Fin.equivSubtype_symm_trans_valEmbedding /-- Use the ordering on `Fin n` for checking recursive definitions. For example, the following definition is not accepted by the termination checker, unless we declare the `WellFoundedRelation` instance: ```lean def factorial {n : ℕ} : Fin n → ℕ | ⟨0, _⟩ := 1 | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩ ``` -/ instance {n : ℕ} : WellFoundedRelation (Fin n) := measure (val : Fin n → ℕ) /-- Given a positive `n`, `Fin.ofNat' i` is `i % n` as an element of `Fin n`. -/ def ofNat'' [NeZero n] (i : ℕ) : Fin n := ⟨i % n, mod_lt _ n.pos_of_neZero⟩ #align fin.of_nat' Fin.ofNat''ₓ -- Porting note: `Fin.ofNat'` conflicts with something in core (there the hypothesis is `n > 0`), -- so for now we make this double-prime `''`. This is also the reason for the dubious translation. instance {n : ℕ} [NeZero n] : Zero (Fin n) := ⟨ofNat'' 0⟩ instance {n : ℕ} [NeZero n] : One (Fin n) := ⟨ofNat'' 1⟩ #align fin.coe_zero Fin.val_zero /-- The `Fin.val_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem val_zero' (n : ℕ) [NeZero n] : ((0 : Fin n) : ℕ) = 0 := rfl #align fin.val_zero' Fin.val_zero' #align fin.mk_zero Fin.mk_zero /-- The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a := Nat.zero_le a.val #align fin.zero_le Fin.zero_le' #align fin.zero_lt_one Fin.zero_lt_one #align fin.not_lt_zero Fin.not_lt_zero /-- The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by rw [← val_fin_lt, val_zero', Nat.pos_iff_ne_zero, Ne, Ne, ext_iff, val_zero'] #align fin.pos_iff_ne_zero Fin.pos_iff_ne_zero' #align fin.eq_zero_or_eq_succ Fin.eq_zero_or_eq_succ #align fin.eq_succ_of_ne_zero Fin.eq_succ_of_ne_zero @[simp] lemma cast_eq_self (a : Fin n) : cast rfl a = a := rfl theorem rev_involutive : Involutive (rev : Fin n → Fin n) := fun i => ext <| by dsimp only [rev] rw [← Nat.sub_sub, Nat.sub_sub_self (Nat.add_one_le_iff.2 i.is_lt), Nat.add_sub_cancel_right] #align fin.rev_involutive Fin.rev_involutive /-- `Fin.rev` as an `Equiv.Perm`, the antitone involution `Fin n → Fin n` given by `i ↦ n-(i+1)`. -/ @[simps! apply symm_apply] def revPerm : Equiv.Perm (Fin n) := Involutive.toPerm rev rev_involutive #align fin.rev Fin.revPerm #align fin.coe_rev Fin.val_revₓ theorem rev_injective : Injective (@rev n) := rev_involutive.injective #align fin.rev_injective Fin.rev_injective theorem rev_surjective : Surjective (@rev n) := rev_involutive.surjective #align fin.rev_surjective Fin.rev_surjective theorem rev_bijective : Bijective (@rev n) := rev_involutive.bijective #align fin.rev_bijective Fin.rev_bijective #align fin.rev_inj Fin.rev_injₓ #align fin.rev_rev Fin.rev_revₓ @[simp] theorem revPerm_symm : (@revPerm n).symm = revPerm := rfl #align fin.rev_symm Fin.revPerm_symm #align fin.rev_eq Fin.rev_eqₓ #align fin.rev_le_rev Fin.rev_le_revₓ #align fin.rev_lt_rev Fin.rev_lt_revₓ theorem cast_rev (i : Fin n) (h : n = m) : cast h i.rev = (i.cast h).rev := by subst h; simp theorem rev_eq_iff {i j : Fin n} : rev i = j ↔ i = rev j := by rw [← rev_inj, rev_rev] theorem rev_ne_iff {i j : Fin n} : rev i ≠ j ↔ i ≠ rev j := rev_eq_iff.not theorem rev_lt_iff {i j : Fin n} : rev i < j ↔ rev j < i := by rw [← rev_lt_rev, rev_rev] theorem rev_le_iff {i j : Fin n} : rev i ≤ j ↔ rev j ≤ i := by rw [← rev_le_rev, rev_rev] theorem lt_rev_iff {i j : Fin n} : i < rev j ↔ j < rev i := by rw [← rev_lt_rev, rev_rev] theorem le_rev_iff {i j : Fin n} : i ≤ rev j ↔ j ≤ rev i := by rw [← rev_le_rev, rev_rev] #align fin.last Fin.last #align fin.coe_last Fin.val_last -- Porting note: this is now syntactically equal to `val_last` #align fin.last_val Fin.val_last #align fin.le_last Fin.le_last #align fin.last_pos Fin.last_pos #align fin.eq_last_of_not_lt Fin.eq_last_of_not_lt theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero theorem one_lt_last [NeZero n] : 1 < last (n + 1) := Nat.lt_add_left_iff_pos.2 n.pos_of_neZero end Order section Add /-! ### addition, numerals, and coercion from Nat -/ #align fin.val_one Fin.val_one #align fin.coe_one Fin.val_one @[simp] theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n := rfl #align fin.coe_one' Fin.val_one' -- Porting note: Delete this lemma after porting theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) := rfl #align fin.one_val Fin.val_one'' #align fin.mk_one Fin.mk_one instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩ theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by rcases n with (_ | _ | n) <;> simp [← Nat.one_eq_succ_zero, Fin.nontrivial, not_nontrivial, Nat.succ_le_iff] -- Porting note: here and in the next lemma, had to use `← Nat.one_eq_succ_zero`. #align fin.nontrivial_iff_two_le Fin.nontrivial_iff_two_le #align fin.subsingleton_iff_le_one Fin.subsingleton_iff_le_one section Monoid -- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance protected theorem add_zero [NeZero n] (k : Fin n) : k + 0 = k := by simp only [add_def, val_zero', Nat.add_zero, mod_eq_of_lt (is_lt k)] #align fin.add_zero Fin.add_zero -- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance protected theorem zero_add [NeZero n] (k : Fin n) : 0 + k = k := by simp [ext_iff, add_def, mod_eq_of_lt (is_lt k)] #align fin.zero_add Fin.zero_add instance {a : ℕ} [NeZero n] : OfNat (Fin n) a where ofNat := Fin.ofNat' a n.pos_of_neZero instance inhabited (n : ℕ) [NeZero n] : Inhabited (Fin n) := ⟨0⟩ instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) := haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance inferInstance @[simp] theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 := rfl #align fin.default_eq_zero Fin.default_eq_zero section from_ad_hoc @[simp] lemma ofNat'_zero {h : 0 < n} [NeZero n] : (Fin.ofNat' 0 h : Fin n) = 0 := rfl @[simp] lemma ofNat'_one {h : 0 < n} [NeZero n] : (Fin.ofNat' 1 h : Fin n) = 1 := rfl end from_ad_hoc instance instNatCast [NeZero n] : NatCast (Fin n) where natCast n := Fin.ofNat'' n lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl end Monoid #align fin.val_add Fin.val_add #align fin.coe_add Fin.val_add theorem val_add_eq_ite {n : ℕ} (a b : Fin n) : (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2), Nat.mod_eq_of_lt (show ↑b < n from b.2)] #align fin.coe_add_eq_ite Fin.val_add_eq_ite section deprecated set_option linter.deprecated false @[deprecated] theorem val_bit0 {n : ℕ} (k : Fin n) : ((bit0 k : Fin n) : ℕ) = bit0 (k : ℕ) % n := by cases k rfl #align fin.coe_bit0 Fin.val_bit0 @[deprecated] theorem val_bit1 {n : ℕ} [NeZero n] (k : Fin n) : ((bit1 k : Fin n) : ℕ) = bit1 (k : ℕ) % n := by cases n; · cases' k with k h cases k · show _ % _ = _ simp at h cases' h with _ h simp [bit1, Fin.val_bit0, Fin.val_add, Fin.val_one] #align fin.coe_bit1 Fin.val_bit1 end deprecated #align fin.coe_add_one_of_lt Fin.val_add_one_of_lt #align fin.last_add_one Fin.last_add_one #align fin.coe_add_one Fin.val_add_one section Bit set_option linter.deprecated false @[simp, deprecated] theorem mk_bit0 {m n : ℕ} (h : bit0 m < n) : (⟨bit0 m, h⟩ : Fin n) = (bit0 ⟨m, (Nat.le_add_right m m).trans_lt h⟩ : Fin _) := eq_of_val_eq (Nat.mod_eq_of_lt h).symm #align fin.mk_bit0 Fin.mk_bit0 @[simp, deprecated] theorem mk_bit1 {m n : ℕ} [NeZero n] (h : bit1 m < n) : (⟨bit1 m, h⟩ : Fin n) = (bit1 ⟨m, (Nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ : Fin _) := by ext simp only [bit1, bit0] at h simp only [bit1, bit0, val_add, val_one', ← Nat.add_mod, Nat.mod_eq_of_lt h] #align fin.mk_bit1 Fin.mk_bit1 end Bit #align fin.val_two Fin.val_two --- Porting note: syntactically the same as the above #align fin.coe_two Fin.val_two section OfNatCoe @[simp] theorem ofNat''_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : (Fin.ofNat'' a : Fin n) = a := rfl #align fin.of_nat_eq_coe Fin.ofNat''_eq_cast @[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl @[deprecated (since := "2024-04-17")] alias val_nat_cast := val_natCast -- Porting note: is this the right name for things involving `Nat.cast`? /-- Converting an in-range number to `Fin (n + 1)` produces a result whose value is the original number. -/ theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := Nat.mod_eq_of_lt h #align fin.coe_val_of_lt Fin.val_cast_of_lt /-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results in the same value. -/ @[simp] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := ext <| val_cast_of_lt a.isLt #align fin.coe_val_eq_self Fin.cast_val_eq_self -- Porting note: this is syntactically the same as `val_cast_of_lt` #align fin.coe_coe_of_lt Fin.val_cast_of_lt -- Porting note: this is syntactically the same as `cast_val_of_lt` #align fin.coe_coe_eq_self Fin.cast_val_eq_self @[simp] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp @[deprecated (since := "2024-04-17")] alias nat_cast_self := natCast_self @[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by simp [ext_iff, Nat.dvd_iff_mod_eq_zero] @[deprecated (since := "2024-04-17")] alias nat_cast_eq_zero := natCast_eq_zero @[simp] theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp #align fin.coe_nat_eq_last Fin.natCast_eq_last @[deprecated (since := "2024-05-04")] alias cast_nat_eq_last := natCast_eq_last theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by rw [Fin.natCast_eq_last] exact Fin.le_last i #align fin.le_coe_last Fin.le_val_last variable {a b : ℕ} lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by rw [← Nat.lt_succ_iff] at han hbn simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn] lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn] lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b := (natCast_le_natCast (hab.trans hbn) hbn).2 hab lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b := (natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab end OfNatCoe #align fin.add_one_pos Fin.add_one_pos #align fin.one_pos Fin.one_pos #align fin.zero_ne_one Fin.zero_ne_one @[simp] theorem one_eq_zero_iff [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by obtain _ | _ | n := n <;> simp [Fin.ext_iff] #align fin.one_eq_zero_iff Fin.one_eq_zero_iff @[simp] theorem zero_eq_one_iff [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by rw [eq_comm, one_eq_zero_iff] #align fin.zero_eq_one_iff Fin.zero_eq_one_iff end Add section Succ /-! ### succ and casts into larger Fin types -/ #align fin.coe_succ Fin.val_succ #align fin.succ_pos Fin.succ_pos lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [ext_iff] #align fin.succ_injective Fin.succ_injective /-- `Fin.succ` as an `Embedding` -/ def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where toFun := succ inj' := succ_injective _ @[simp] theorem val_succEmb : ⇑(succEmb n) = Fin.succ := rfl #align fin.succ_le_succ_iff Fin.succ_le_succ_iff #align fin.succ_lt_succ_iff Fin.succ_lt_succ_iff @[simp] theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 := ⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩ #align fin.exists_succ_eq_iff Fin.exists_succ_eq theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x := exists_succ_eq.mpr h #align fin.succ_inj Fin.succ_inj #align fin.succ_ne_zero Fin.succ_ne_zero @[simp] theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl #align fin.succ_zero_eq_one Fin.succ_zero_eq_one' theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _ theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos' #align fin.succ_zero_eq_one' Fin.succ_zero_eq_one /-- The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl #align fin.succ_one_eq_two Fin.succ_one_eq_two' -- Version of `succ_one_eq_two` to be used by `dsimp`. -- Note the `'` swapped around due to a move to std4. #align fin.succ_one_eq_two' Fin.succ_one_eq_two #align fin.succ_mk Fin.succ_mk #align fin.mk_succ_pos Fin.mk_succ_pos #align fin.one_lt_succ_succ Fin.one_lt_succ_succ #align fin.add_one_lt_iff Fin.add_one_lt_iff #align fin.add_one_le_iff Fin.add_one_le_iff #align fin.last_le_iff Fin.last_le_iff #align fin.lt_add_one_iff Fin.lt_add_one_iff /-- The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 := ⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩ #align fin.le_zero_iff Fin.le_zero_iff' #align fin.succ_succ_ne_one Fin.succ_succ_ne_one #align fin.cast_lt Fin.castLT #align fin.coe_cast_lt Fin.coe_castLT #align fin.cast_lt_mk Fin.castLT_mk -- Move to Batteries? @[simp] theorem cast_refl {n : Nat} (h : n = n) : Fin.cast h = id := rfl -- TODO: Move to Batteries @[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by simp [ext_iff] @[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [ext_iff] attribute [simp] castSucc_inj lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) := fun a b hab ↦ ext (by have := congr_arg val hab; exact this) lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _ lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _ #align fin.cast_succ_injective Fin.castSucc_injective /-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/ @[simps! apply] def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where toFun := castLE h inj' := castLE_injective _ @[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl #align fin.coe_cast_le Fin.coe_castLE #align fin.cast_le_mk Fin.castLE_mk #align fin.cast_le_zero Fin.castLE_zero /- The next proof can be golfed a lot using `Fintype.card`. It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency (not done yet). -/ assert_not_exists Fintype lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩ induction n generalizing m with | zero => exact m.zero_le | succ n ihn => cases' h with e rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne' with ⟨m, rfl⟩ refine Nat.succ_le_succ <| ihn ⟨?_⟩ refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero), fun i j h ↦ ?_⟩ simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n := ⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩), fun h ↦ h ▸ ⟨.refl _⟩⟩ #align fin.equiv_iff_eq Fin.equiv_iff_eq @[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) : i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) : Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id := rfl @[simp] theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } := Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, Fin.ext rfl⟩⟩ #align fin.range_cast_le Fin.range_castLE @[simp] theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) : ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castLE h] exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _) #align fin.coe_of_injective_cast_le_symm Fin.coe_of_injective_castLE_symm #align fin.cast_le_succ Fin.castLE_succ #align fin.cast_le_cast_le Fin.castLE_castLE #align fin.cast_le_comp_cast_le Fin.castLE_comp_castLE theorem leftInverse_cast (eq : n = m) : LeftInverse (cast eq.symm) (cast eq) := fun _ => rfl theorem rightInverse_cast (eq : n = m) : RightInverse (cast eq.symm) (cast eq) := fun _ => rfl theorem cast_le_cast (eq : n = m) {a b : Fin n} : cast eq a ≤ cast eq b ↔ a ≤ b := Iff.rfl /-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/ @[simps] def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where toFun := cast eq invFun := cast eq.symm left_inv := leftInverse_cast eq right_inv := rightInverse_cast eq #align fin_congr finCongr @[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl #align fin_congr_apply_mk finCongr_apply_mk @[simp] lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp @[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl #align fin_congr_symm finCongr_symm @[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl #align fin_congr_apply_coe finCongr_apply_coe lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl #align fin_congr_symm_apply_coe finCongr_symm_apply_coe /-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp #align fin.coe_cast Fin.coe_castₓ @[simp] theorem cast_zero {n' : ℕ} [NeZero n] {h : n = n'} : cast h (0 : Fin n) = by { haveI : NeZero n' := by {rw [← h]; infer_instance}; exact 0} := ext rfl #align fin.cast_zero Fin.cast_zero #align fin.cast_last Fin.cast_lastₓ #align fin.cast_mk Fin.cast_mkₓ #align fin.cast_trans Fin.cast_transₓ #align fin.cast_le_of_eq Fin.castLE_of_eq /-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ theorem cast_eq_cast (h : n = m) : (cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by subst h ext rfl #align fin.cast_eq_cast Fin.cast_eq_cast /-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ @[simps! apply] def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m) #align fin.coe_cast_add Fin.coe_castAdd #align fin.cast_add_zero Fin.castAdd_zeroₓ #align fin.cast_add_lt Fin.castAdd_lt #align fin.cast_add_mk Fin.castAdd_mk #align fin.cast_add_cast_lt Fin.castAdd_castLT #align fin.cast_lt_cast_add Fin.castLT_castAdd #align fin.cast_add_cast Fin.castAdd_castₓ #align fin.cast_cast_add_left Fin.cast_castAdd_leftₓ #align fin.cast_cast_add_right Fin.cast_castAdd_rightₓ #align fin.cast_add_cast_add Fin.castAdd_castAdd #align fin.cast_succ_eq Fin.cast_succ_eqₓ #align fin.succ_cast_eq Fin.succ_cast_eqₓ /-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ @[simps! apply] def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _ @[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl #align fin.coe_cast_succ Fin.coe_castSucc #align fin.cast_succ_mk Fin.castSucc_mk #align fin.cast_cast_succ Fin.cast_castSuccₓ #align fin.cast_succ_lt_succ Fin.castSucc_lt_succ #align fin.le_cast_succ_iff Fin.le_castSucc_iff #align fin.cast_succ_lt_iff_succ_le Fin.castSucc_lt_iff_succ_le #align fin.succ_last Fin.succ_last #align fin.succ_eq_last_succ Fin.succ_eq_last_succ #align fin.cast_succ_cast_lt Fin.castSucc_castLT #align fin.cast_lt_cast_succ Fin.castLT_castSucc #align fin.cast_succ_lt_cast_succ_iff Fin.castSucc_lt_castSucc_iff @[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := Iff.rfl @[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by rw [le_castSucc_iff, succ_lt_succ_iff] @[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by rw [castSucc_lt_iff_succ_le, succ_le_succ_iff] theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n} (hl : castSucc i < a) (hu : b < succ i) : b < a := by simp [Fin.lt_def, -val_fin_lt] at *; omega theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by simp [Fin.lt_def, -val_fin_lt]; omega #align fin.succ_above_lt_gt Fin.castSucc_lt_or_lt_succ @[deprecated] alias succAbove_lt_gt := castSucc_lt_or_lt_succ
Mathlib/Data/Fin/Basic.lean
928
930
theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by
rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le] exact p.castSucc_lt_or_lt_succ i
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Analysis.SpecialFunctions.Log.Base import Mathlib.MeasureTheory.Measure.MeasureSpaceDef #align_import measure_theory.measure.doubling from "leanprover-community/mathlib"@"5f6e827d81dfbeb6151d7016586ceeb0099b9655" /-! # Uniformly locally doubling measures A uniformly locally doubling measure `μ` on a metric space is a measure for which there exists a constant `C` such that for all sufficiently small radii `ε`, and for any centre, the measure of a ball of radius `2 * ε` is bounded by `C` times the measure of the concentric ball of radius `ε`. This file records basic facts about uniformly locally doubling measures. ## Main definitions * `IsUnifLocDoublingMeasure`: the definition of a uniformly locally doubling measure (as a typeclass). * `IsUnifLocDoublingMeasure.doublingConstant`: a function yielding the doubling constant `C` appearing in the definition of a uniformly locally doubling measure. -/ noncomputable section open Set Filter Metric MeasureTheory TopologicalSpace ENNReal NNReal Topology /-- A measure `μ` is said to be a uniformly locally doubling measure if there exists a constant `C` such that for all sufficiently small radii `ε`, and for any centre, the measure of a ball of radius `2 * ε` is bounded by `C` times the measure of the concentric ball of radius `ε`. Note: it is important that this definition makes a demand only for sufficiently small `ε`. For example we want hyperbolic space to carry the instance `IsUnifLocDoublingMeasure volume` but volumes grow exponentially in hyperbolic space. To be really explicit, consider the hyperbolic plane of curvature -1, the area of a disc of radius `ε` is `A(ε) = 2π(cosh(ε) - 1)` so `A(2ε)/A(ε) ~ exp(ε)`. -/ class IsUnifLocDoublingMeasure {α : Type*} [MetricSpace α] [MeasurableSpace α] (μ : Measure α) : Prop where exists_measure_closedBall_le_mul'' : ∃ C : ℝ≥0, ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closedBall x (2 * ε)) ≤ C * μ (closedBall x ε) #align is_unif_loc_doubling_measure IsUnifLocDoublingMeasure namespace IsUnifLocDoublingMeasure variable {α : Type*} [MetricSpace α] [MeasurableSpace α] (μ : Measure α) [IsUnifLocDoublingMeasure μ] -- Porting note: added for missing infer kinds theorem exists_measure_closedBall_le_mul : ∃ C : ℝ≥0, ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closedBall x (2 * ε)) ≤ C * μ (closedBall x ε) := exists_measure_closedBall_le_mul'' /-- A doubling constant for a uniformly locally doubling measure. See also `IsUnifLocDoublingMeasure.scalingConstantOf`. -/ def doublingConstant : ℝ≥0 := Classical.choose <| exists_measure_closedBall_le_mul μ #align is_unif_loc_doubling_measure.doubling_constant IsUnifLocDoublingMeasure.doublingConstant theorem exists_measure_closedBall_le_mul' : ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closedBall x (2 * ε)) ≤ doublingConstant μ * μ (closedBall x ε) := Classical.choose_spec <| exists_measure_closedBall_le_mul μ #align is_unif_loc_doubling_measure.exists_measure_closed_ball_le_mul' IsUnifLocDoublingMeasure.exists_measure_closedBall_le_mul' theorem exists_eventually_forall_measure_closedBall_le_mul (K : ℝ) : ∃ C : ℝ≥0, ∀ᶠ ε in 𝓝[>] 0, ∀ x, ∀ t ≤ K, μ (closedBall x (t * ε)) ≤ C * μ (closedBall x ε) := by let C := doublingConstant μ have hμ : ∀ n : ℕ, ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closedBall x ((2 : ℝ) ^ n * ε)) ≤ ↑(C ^ n) * μ (closedBall x ε) := by intro n induction' n with n ih · simp replace ih := eventually_nhdsWithin_pos_mul_left (two_pos : 0 < (2 : ℝ)) ih refine (ih.and (exists_measure_closedBall_le_mul' μ)).mono fun ε hε x => ?_ calc μ (closedBall x ((2 : ℝ) ^ (n + 1) * ε)) = μ (closedBall x ((2 : ℝ) ^ n * (2 * ε))) := by rw [pow_succ, mul_assoc] _ ≤ ↑(C ^ n) * μ (closedBall x (2 * ε)) := hε.1 x _ ≤ ↑(C ^ n) * (C * μ (closedBall x ε)) := by gcongr; exact hε.2 x _ = ↑(C ^ (n + 1)) * μ (closedBall x ε) := by rw [← mul_assoc, pow_succ, ENNReal.coe_mul] rcases lt_or_le K 1 with (hK | hK) · refine ⟨1, ?_⟩ simp only [ENNReal.coe_one, one_mul] refine eventually_mem_nhdsWithin.mono fun ε hε x t ht ↦ ?_ gcongr nlinarith [mem_Ioi.mp hε] · use C ^ ⌈Real.logb 2 K⌉₊ filter_upwards [hμ ⌈Real.logb 2 K⌉₊, eventually_mem_nhdsWithin] with ε hε hε₀ x t ht refine le_trans ?_ (hε x) gcongr · exact (mem_Ioi.mp hε₀).le · refine ht.trans ?_ rw [← Real.rpow_natCast, ← Real.logb_le_iff_le_rpow] exacts [Nat.le_ceil _, by norm_num, by linarith] #align is_unif_loc_doubling_measure.exists_eventually_forall_measure_closed_ball_le_mul IsUnifLocDoublingMeasure.exists_eventually_forall_measure_closedBall_le_mul /-- A variant of `IsUnifLocDoublingMeasure.doublingConstant` which allows for scaling the radius by values other than `2`. -/ def scalingConstantOf (K : ℝ) : ℝ≥0 := max (Classical.choose <| exists_eventually_forall_measure_closedBall_le_mul μ K) 1 #align is_unif_loc_doubling_measure.scaling_constant_of IsUnifLocDoublingMeasure.scalingConstantOf @[simp] theorem one_le_scalingConstantOf (K : ℝ) : 1 ≤ scalingConstantOf μ K := le_max_of_le_right <| le_refl 1 #align is_unif_loc_doubling_measure.one_le_scaling_constant_of IsUnifLocDoublingMeasure.one_le_scalingConstantOf
Mathlib/MeasureTheory/Measure/Doubling.lean
113
129
theorem eventually_measure_mul_le_scalingConstantOf_mul (K : ℝ) : ∃ R : ℝ, 0 < R ∧ ∀ x t r, t ∈ Ioc 0 K → r ≤ R → μ (closedBall x (t * r)) ≤ scalingConstantOf μ K * μ (closedBall x r) := by
have h := Classical.choose_spec (exists_eventually_forall_measure_closedBall_le_mul μ K) rcases mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.1 h with ⟨R, Rpos, hR⟩ refine ⟨R, Rpos, fun x t r ht hr => ?_⟩ rcases lt_trichotomy r 0 with (rneg | rfl | rpos) · have : t * r < 0 := mul_neg_of_pos_of_neg ht.1 rneg simp only [closedBall_eq_empty.2 this, measure_empty, zero_le'] · simp only [mul_zero, closedBall_zero] refine le_mul_of_one_le_of_le ?_ le_rfl apply ENNReal.one_le_coe_iff.2 (le_max_right _ _) · apply (hR ⟨rpos, hr⟩ x t ht.2).trans gcongr apply le_max_left
/- 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
Mathlib/Logic/Equiv/Basic.lean
1,695
1,697
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]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Order.Iterate import Mathlib.Order.SemiconjSup import Mathlib.Tactic.Monotonicity import Mathlib.Topology.Order.MonotoneContinuity #align_import dynamics.circle.rotation_number.translation_number from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Translation number of a monotone real map that commutes with `x ↦ x + 1` Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit $$ \tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n} $$ exists and does not depend on `x`. This number is called the *translation number* of `f`. Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and only if `τ(f)=m/n`. Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and consider a real number `a` such that `⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is not formalized yet). This function is strictly monotone, continuous, and satisfies `F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`. It does not depend on the choice of `a`. ## Main definitions * `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`; the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the multiplication is given by composition: `(f * g) x = f (g x)`. * `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`. ## Main statements We prove the following properties of `CircleDeg1Lift.translationNumber`. * `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0` and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal translation numbers. * `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g` are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`. * `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then the translation number of `f⁻¹` is the negative of the translation number of `f`. * `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then `τ (f * g) = τ f + τ g`. * `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`. * `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these maps are semiconjugate to each other. * `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are equal to each other for all `g : G`, then these two actions are semiconjugate by some `F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]. ## Notation We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`. ## Implementation notes We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence `(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`. This way it is much easier to prove that the limit exists and basic properties of the limit. We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation preserving circle homeomorphisms for two reasons: * non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry cells); * definition and some basic properties still work for this class. ## References * [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes] ## TODO Here are some short-term goals. * Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?). * Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation. * Introduce `ConditionallyCompleteLattice` structure, use it in the proof of `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`. * Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational translation by a continuous `CircleDeg1Lift`. ## Tags circle homeomorphism, rotation number -/ open scoped Classical open Filter Set Int Topology open Function hiding Commute /-! ### Definition and monoid structure -/ /-- A lift of a monotone degree one map `S¹ → S¹`. -/ structure CircleDeg1Lift extends ℝ →o ℝ : Type where map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1 #align circle_deg1_lift CircleDeg1Lift namespace CircleDeg1Lift instance : FunLike CircleDeg1Lift ℝ ℝ where coe f := f.toFun coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl instance : OrderHomClass CircleDeg1Lift ℝ ℝ where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl #align circle_deg1_lift.coe_mk CircleDeg1Lift.coe_mk variable (f g : CircleDeg1Lift) @[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl protected theorem monotone : Monotone f := f.monotone' #align circle_deg1_lift.monotone CircleDeg1Lift.monotone @[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h #align circle_deg1_lift.mono CircleDeg1Lift.mono theorem strictMono_iff_injective : StrictMono f ↔ Injective f := f.monotone.strictMono_iff_injective #align circle_deg1_lift.strict_mono_iff_injective CircleDeg1Lift.strictMono_iff_injective @[simp] theorem map_add_one : ∀ x, f (x + 1) = f x + 1 := f.map_add_one' #align circle_deg1_lift.map_add_one CircleDeg1Lift.map_add_one @[simp] theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1] #align circle_deg1_lift.map_one_add CircleDeg1Lift.map_one_add #noalign circle_deg1_lift.coe_inj -- Use `DFunLike.coe_inj` @[ext] theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align circle_deg1_lift.ext CircleDeg1Lift.ext theorem ext_iff {f g : CircleDeg1Lift} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align circle_deg1_lift.ext_iff CircleDeg1Lift.ext_iff instance : Monoid CircleDeg1Lift where mul f g := { toOrderHom := f.1.comp g.1 map_add_one' := fun x => by simp [map_add_one] } one := ⟨.id, fun _ => rfl⟩ mul_one f := rfl one_mul f := rfl mul_assoc f₁ f₂ f₃ := DFunLike.coe_injective rfl instance : Inhabited CircleDeg1Lift := ⟨1⟩ @[simp] theorem coe_mul : ⇑(f * g) = f ∘ g := rfl #align circle_deg1_lift.coe_mul CircleDeg1Lift.coe_mul theorem mul_apply (x) : (f * g) x = f (g x) := rfl #align circle_deg1_lift.mul_apply CircleDeg1Lift.mul_apply @[simp] theorem coe_one : ⇑(1 : CircleDeg1Lift) = id := rfl #align circle_deg1_lift.coe_one CircleDeg1Lift.coe_one instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ := ⟨fun f => ⇑(f : CircleDeg1Lift)⟩ #align circle_deg1_lift.units_has_coe_to_fun CircleDeg1Lift.unitsHasCoeToFun #noalign circle_deg1_lift.units_coe -- now LHS = RHS @[simp] theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) : (f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id] #align circle_deg1_lift.units_inv_apply_apply CircleDeg1Lift.units_inv_apply_apply @[simp] theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) : f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id] #align circle_deg1_lift.units_apply_inv_apply CircleDeg1Lift.units_apply_inv_apply /-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/ def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where toFun f := { toFun := f invFun := ⇑f⁻¹ left_inv := units_inv_apply_apply f right_inv := units_apply_inv_apply f map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ } map_one' := rfl map_mul' f g := rfl #align circle_deg1_lift.to_order_iso CircleDeg1Lift.toOrderIso @[simp] theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f := rfl #align circle_deg1_lift.coe_to_order_iso CircleDeg1Lift.coe_toOrderIso @[simp] theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_symm CircleDeg1Lift.coe_toOrderIso_symm @[simp] theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_inv CircleDeg1Lift.coe_toOrderIso_inv theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f := ⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h => Units.isUnit { val := f inv := { toFun := (Equiv.ofBijective f h).symm monotone' := fun x y hxy => (f.strictMono_iff_injective.2 h.1).le_iff_le.1 (by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy]) map_add_one' := fun x => h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] } val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩ #align circle_deg1_lift.is_unit_iff_bijective CircleDeg1Lift.isUnit_iff_bijective theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n] | 0 => rfl | n + 1 => by ext x simp [coe_pow n, pow_succ] #align circle_deg1_lift.coe_pow CircleDeg1Lift.coe_pow theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} : SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ := ext_iff #align circle_deg1_lift.semiconj_by_iff_semiconj CircleDeg1Lift.semiconjBy_iff_semiconj theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g := ext_iff #align circle_deg1_lift.commute_iff_commute CircleDeg1Lift.commute_iff_commute /-! ### Translate by a constant -/ /-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from `Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is `translation (Multiplicative.ofAdd x)`. -/ def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <| { toFun := fun x => ⟨⟨fun y => Multiplicative.toAdd x + y, fun _ _ h => add_le_add_left h _⟩, fun _ => (add_assoc _ _ _).symm⟩ map_one' := ext <| zero_add map_mul' := fun _ _ => ext <| add_assoc _ _ } #align circle_deg1_lift.translate CircleDeg1Lift.translate @[simp] theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y := rfl #align circle_deg1_lift.translate_apply CircleDeg1Lift.translate_apply @[simp] theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y := rfl #align circle_deg1_lift.translate_inv_apply CircleDeg1Lift.translate_inv_apply @[simp] theorem translate_zpow (x : ℝ) (n : ℤ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow] #align circle_deg1_lift.translate_zpow CircleDeg1Lift.translate_zpow @[simp] theorem translate_pow (x : ℝ) (n : ℕ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := translate_zpow x n #align circle_deg1_lift.translate_pow CircleDeg1Lift.translate_pow @[simp] theorem translate_iterate (x : ℝ) (n : ℕ) : (translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow] #align circle_deg1_lift.translate_iterate CircleDeg1Lift.translate_iterate /-! ### Commutativity with integer translations In this section we prove that `f` commutes with translations by an integer number. First we formulate these statements (for a natural or an integer number, addition on the left or on the right, addition or subtraction) using `Function.Commute`, then reformulate as `simp` lemmas `map_int_add` etc. -/ theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n #align circle_deg1_lift.commute_nat_add CircleDeg1Lift.commute_nat_add theorem commute_add_nat (n : ℕ) : Function.Commute f (· + n) := by simp only [add_comm _ (n : ℝ), f.commute_nat_add n] #align circle_deg1_lift.commute_add_nat CircleDeg1Lift.commute_add_nat theorem commute_sub_nat (n : ℕ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv #align circle_deg1_lift.commute_sub_nat CircleDeg1Lift.commute_sub_nat theorem commute_add_int : ∀ n : ℤ, Function.Commute f (· + n) | (n : ℕ) => f.commute_add_nat n | -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1) #align circle_deg1_lift.commute_add_int CircleDeg1Lift.commute_add_int theorem commute_int_add (n : ℤ) : Function.Commute f (n + ·) := by simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n #align circle_deg1_lift.commute_int_add CircleDeg1Lift.commute_int_add theorem commute_sub_int (n : ℤ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv #align circle_deg1_lift.commute_sub_int CircleDeg1Lift.commute_sub_int @[simp] theorem map_int_add (m : ℤ) (x : ℝ) : f (m + x) = m + f x := f.commute_int_add m x #align circle_deg1_lift.map_int_add CircleDeg1Lift.map_int_add @[simp] theorem map_add_int (x : ℝ) (m : ℤ) : f (x + m) = f x + m := f.commute_add_int m x #align circle_deg1_lift.map_add_int CircleDeg1Lift.map_add_int @[simp] theorem map_sub_int (x : ℝ) (n : ℤ) : f (x - n) = f x - n := f.commute_sub_int n x #align circle_deg1_lift.map_sub_int CircleDeg1Lift.map_sub_int @[simp] theorem map_add_nat (x : ℝ) (n : ℕ) : f (x + n) = f x + n := f.map_add_int x n #align circle_deg1_lift.map_add_nat CircleDeg1Lift.map_add_nat @[simp] theorem map_nat_add (n : ℕ) (x : ℝ) : f (n + x) = n + f x := f.map_int_add n x #align circle_deg1_lift.map_nat_add CircleDeg1Lift.map_nat_add @[simp] theorem map_sub_nat (x : ℝ) (n : ℕ) : f (x - n) = f x - n := f.map_sub_int x n #align circle_deg1_lift.map_sub_nat CircleDeg1Lift.map_sub_nat theorem map_int_of_map_zero (n : ℤ) : f n = f 0 + n := by rw [← f.map_add_int, zero_add] #align circle_deg1_lift.map_int_of_map_zero CircleDeg1Lift.map_int_of_map_zero @[simp] theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right] #align circle_deg1_lift.map_fract_sub_fract_eq CircleDeg1Lift.map_fract_sub_fract_eq /-! ### Pointwise order on circle maps -/ /-- Monotone circle maps form a lattice with respect to the pointwise order -/ noncomputable instance : Lattice CircleDeg1Lift where sup f g := { toFun := fun x => max (f x) (g x) monotone' := fun x y h => max_le_max (f.mono h) (g.mono h) -- TODO: generalize to `Monotone.max` map_add_one' := fun x => by simp [max_add_add_right] } le f g := ∀ x, f x ≤ g x le_refl f x := le_refl (f x) le_trans f₁ f₂ f₃ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x) le_antisymm f₁ f₂ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x) le_sup_left f g x := le_max_left (f x) (g x) le_sup_right f g x := le_max_right (f x) (g x) sup_le f₁ f₂ f₃ h₁ h₂ x := max_le (h₁ x) (h₂ x) inf f g := { toFun := fun x => min (f x) (g x) monotone' := fun x y h => min_le_min (f.mono h) (g.mono h) map_add_one' := fun x => by simp [min_add_add_right] } inf_le_left f g x := min_le_left (f x) (g x) inf_le_right f g x := min_le_right (f x) (g x) le_inf f₁ f₂ f₃ h₂ h₃ x := le_min (h₂ x) (h₃ x) @[simp] theorem sup_apply (x : ℝ) : (f ⊔ g) x = max (f x) (g x) := rfl #align circle_deg1_lift.sup_apply CircleDeg1Lift.sup_apply @[simp] theorem inf_apply (x : ℝ) : (f ⊓ g) x = min (f x) (g x) := rfl #align circle_deg1_lift.inf_apply CircleDeg1Lift.inf_apply theorem iterate_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f^[n] := fun f _ h => f.monotone.iterate_le_of_le h _ #align circle_deg1_lift.iterate_monotone CircleDeg1Lift.iterate_monotone theorem iterate_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] := iterate_monotone n h #align circle_deg1_lift.iterate_mono CircleDeg1Lift.iterate_mono theorem pow_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f ^ n ≤ g ^ n := fun x => by simp only [coe_pow, iterate_mono h n x] #align circle_deg1_lift.pow_mono CircleDeg1Lift.pow_mono theorem pow_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f ^ n := fun _ _ h => pow_mono h n #align circle_deg1_lift.pow_monotone CircleDeg1Lift.pow_monotone /-! ### Estimates on `(f * g) 0` We prove the estimates `f 0 + ⌊g 0⌋ ≤ f (g 0) ≤ f 0 + ⌈g 0⌉` and some corollaries with added/removed floors and ceils. We also prove that for two semiconjugate maps `g₁`, `g₂`, the distance between `g₁ 0` and `g₂ 0` is less than two. -/ theorem map_le_of_map_zero (x : ℝ) : f x ≤ f 0 + ⌈x⌉ := calc f x ≤ f ⌈x⌉ := f.monotone <| le_ceil _ _ = f 0 + ⌈x⌉ := f.map_int_of_map_zero _ #align circle_deg1_lift.map_le_of_map_zero CircleDeg1Lift.map_le_of_map_zero theorem map_map_zero_le : f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_le_of_map_zero (g 0) #align circle_deg1_lift.map_map_zero_le CircleDeg1Lift.map_map_zero_le theorem floor_map_map_zero_le : ⌊f (g 0)⌋ ≤ ⌊f 0⌋ + ⌈g 0⌉ := calc ⌊f (g 0)⌋ ≤ ⌊f 0 + ⌈g 0⌉⌋ := floor_mono <| f.map_map_zero_le g _ = ⌊f 0⌋ + ⌈g 0⌉ := floor_add_int _ _ #align circle_deg1_lift.floor_map_map_zero_le CircleDeg1Lift.floor_map_map_zero_le theorem ceil_map_map_zero_le : ⌈f (g 0)⌉ ≤ ⌈f 0⌉ + ⌈g 0⌉ := calc ⌈f (g 0)⌉ ≤ ⌈f 0 + ⌈g 0⌉⌉ := ceil_mono <| f.map_map_zero_le g _ = ⌈f 0⌉ + ⌈g 0⌉ := ceil_add_int _ _ #align circle_deg1_lift.ceil_map_map_zero_le CircleDeg1Lift.ceil_map_map_zero_le theorem map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 := calc f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_map_zero_le g _ < f 0 + (g 0 + 1) := add_lt_add_left (ceil_lt_add_one _) _ _ = f 0 + g 0 + 1 := (add_assoc _ _ _).symm #align circle_deg1_lift.map_map_zero_lt CircleDeg1Lift.map_map_zero_lt theorem le_map_of_map_zero (x : ℝ) : f 0 + ⌊x⌋ ≤ f x := calc f 0 + ⌊x⌋ = f ⌊x⌋ := (f.map_int_of_map_zero _).symm _ ≤ f x := f.monotone <| floor_le _ #align circle_deg1_lift.le_map_of_map_zero CircleDeg1Lift.le_map_of_map_zero theorem le_map_map_zero : f 0 + ⌊g 0⌋ ≤ f (g 0) := f.le_map_of_map_zero (g 0) #align circle_deg1_lift.le_map_map_zero CircleDeg1Lift.le_map_map_zero theorem le_floor_map_map_zero : ⌊f 0⌋ + ⌊g 0⌋ ≤ ⌊f (g 0)⌋ := calc ⌊f 0⌋ + ⌊g 0⌋ = ⌊f 0 + ⌊g 0⌋⌋ := (floor_add_int _ _).symm _ ≤ ⌊f (g 0)⌋ := floor_mono <| f.le_map_map_zero g #align circle_deg1_lift.le_floor_map_map_zero CircleDeg1Lift.le_floor_map_map_zero theorem le_ceil_map_map_zero : ⌈f 0⌉ + ⌊g 0⌋ ≤ ⌈(f * g) 0⌉ := calc ⌈f 0⌉ + ⌊g 0⌋ = ⌈f 0 + ⌊g 0⌋⌉ := (ceil_add_int _ _).symm _ ≤ ⌈f (g 0)⌉ := ceil_mono <| f.le_map_map_zero g #align circle_deg1_lift.le_ceil_map_map_zero CircleDeg1Lift.le_ceil_map_map_zero theorem lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) := calc f 0 + g 0 - 1 = f 0 + (g 0 - 1) := add_sub_assoc _ _ _ _ < f 0 + ⌊g 0⌋ := add_lt_add_left (sub_one_lt_floor _) _ _ ≤ f (g 0) := f.le_map_map_zero g #align circle_deg1_lift.lt_map_map_zero CircleDeg1Lift.lt_map_map_zero theorem dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 := by rw [dist_comm, Real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', ← sub_eq_add_neg] exact ⟨f.lt_map_map_zero g, f.map_map_zero_lt g⟩ #align circle_deg1_lift.dist_map_map_zero_lt CircleDeg1Lift.dist_map_map_zero_lt theorem dist_map_zero_lt_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (h : Function.Semiconj f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := calc dist (g₁ 0) (g₂ 0) ≤ dist (g₁ 0) (f (g₁ 0) - f 0) + dist _ (g₂ 0) := dist_triangle _ _ _ _ = dist (f 0 + g₁ 0) (f (g₁ 0)) + dist (g₂ 0 + f 0) (g₂ (f 0)) := by simp only [h.eq, Real.dist_eq, sub_sub, add_comm (f 0), sub_sub_eq_add_sub, abs_sub_comm (g₂ (f 0))] _ < 1 + 1 := add_lt_add (f.dist_map_map_zero_lt g₁) (g₂.dist_map_map_zero_lt f) _ = 2 := one_add_one_eq_two #align circle_deg1_lift.dist_map_zero_lt_of_semiconj CircleDeg1Lift.dist_map_zero_lt_of_semiconj theorem dist_map_zero_lt_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (h : SemiconjBy f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := dist_map_zero_lt_of_semiconj <| semiconjBy_iff_semiconj.1 h #align circle_deg1_lift.dist_map_zero_lt_of_semiconj_by CircleDeg1Lift.dist_map_zero_lt_of_semiconjBy /-! ### Limits at infinities and continuity -/ protected theorem tendsto_atBot : Tendsto f atBot atBot := tendsto_atBot_mono f.map_le_of_map_zero <| tendsto_atBot_add_const_left _ _ <| (tendsto_atBot_mono fun x => (ceil_lt_add_one x).le) <| tendsto_atBot_add_const_right _ _ tendsto_id #align circle_deg1_lift.tendsto_at_bot CircleDeg1Lift.tendsto_atBot protected theorem tendsto_atTop : Tendsto f atTop atTop := tendsto_atTop_mono f.le_map_of_map_zero <| tendsto_atTop_add_const_left _ _ <| (tendsto_atTop_mono fun x => (sub_one_lt_floor x).le) <| by simpa [sub_eq_add_neg] using tendsto_atTop_add_const_right _ _ tendsto_id #align circle_deg1_lift.tendsto_at_top CircleDeg1Lift.tendsto_atTop theorem continuous_iff_surjective : Continuous f ↔ Function.Surjective f := ⟨fun h => h.surjective f.tendsto_atTop f.tendsto_atBot, f.monotone.continuous_of_surjective⟩ #align circle_deg1_lift.continuous_iff_surjective CircleDeg1Lift.continuous_iff_surjective /-! ### Estimates on `(f^n) x` If we know that `f x` is `≤`/`<`/`≥`/`>`/`=` to `x + m`, then we have a similar estimate on `f^[n] x` and `x + n * m`. For `≤`, `≥`, and `=` we formulate both `of` (implication) and `iff` versions because implications work for `n = 0`. For `<` and `>` we formulate only `iff` versions. -/ theorem iterate_le_of_map_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) (n : ℕ) : f^[n] x ≤ x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_le_of_map_le f.monotone (monotone_id.add_const (m : ℝ)) h n #align circle_deg1_lift.iterate_le_of_map_le_add_int CircleDeg1Lift.iterate_le_of_map_le_add_int theorem le_iterate_of_add_int_le_map {x : ℝ} {m : ℤ} (h : x + m ≤ f x) (n : ℕ) : x + n * m ≤ f^[n] x := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).symm.iterate_le_of_map_le (monotone_id.add_const (m : ℝ)) f.monotone h n #align circle_deg1_lift.le_iterate_of_add_int_le_map CircleDeg1Lift.le_iterate_of_add_int_le_map theorem iterate_eq_of_map_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) (n : ℕ) : f^[n] x = x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_eq_of_map_eq n h #align circle_deg1_lift.iterate_eq_of_map_eq_add_int CircleDeg1Lift.iterate_eq_of_map_eq_add_int theorem iterate_pos_le_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x ≤ x + n * m ↔ f x ≤ x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_le_iff_map_le f.monotone (strictMono_id.add_const (m : ℝ)) hn #align circle_deg1_lift.iterate_pos_le_iff CircleDeg1Lift.iterate_pos_le_iff theorem iterate_pos_lt_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x < x + n * m ↔ f x < x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_lt_iff_map_lt f.monotone (strictMono_id.add_const (m : ℝ)) hn #align circle_deg1_lift.iterate_pos_lt_iff CircleDeg1Lift.iterate_pos_lt_iff theorem iterate_pos_eq_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x = x + n * m ↔ f x = x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_eq_iff_map_eq f.monotone (strictMono_id.add_const (m : ℝ)) hn #align circle_deg1_lift.iterate_pos_eq_iff CircleDeg1Lift.iterate_pos_eq_iff theorem le_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m ≤ f^[n] x ↔ x + m ≤ f x := by simpa only [not_lt] using not_congr (f.iterate_pos_lt_iff hn) #align circle_deg1_lift.le_iterate_pos_iff CircleDeg1Lift.le_iterate_pos_iff theorem lt_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m < f^[n] x ↔ x + m < f x := by simpa only [not_le] using not_congr (f.iterate_pos_le_iff hn) #align circle_deg1_lift.lt_iterate_pos_iff CircleDeg1Lift.lt_iterate_pos_iff theorem mul_floor_map_zero_le_floor_iterate_zero (n : ℕ) : ↑n * ⌊f 0⌋ ≤ ⌊f^[n] 0⌋ := by rw [le_floor, Int.cast_mul, Int.cast_natCast, ← zero_add ((n : ℝ) * _)] apply le_iterate_of_add_int_le_map simp [floor_le] #align circle_deg1_lift.mul_floor_map_zero_le_floor_iterate_zero CircleDeg1Lift.mul_floor_map_zero_le_floor_iterate_zero /-! ### Definition of translation number -/ noncomputable section /-- An auxiliary sequence used to define the translation number. -/ def transnumAuxSeq (n : ℕ) : ℝ := (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n #align circle_deg1_lift.transnum_aux_seq CircleDeg1Lift.transnumAuxSeq /-- The translation number of a `CircleDeg1Lift`, $τ(f)=\lim_{n→∞}\frac{f^n(x)-x}{n}$. We use an auxiliary sequence `\frac{f^{2^n}(0)}{2^n}` to define `τ(f)` because some proofs are simpler this way. -/ def translationNumber : ℝ := limUnder atTop f.transnumAuxSeq #align circle_deg1_lift.translation_number CircleDeg1Lift.translationNumber end -- TODO: choose two different symbols for `CircleDeg1Lift.translationNumber` and the future -- `circle_mono_homeo.rotation_number`, then make them `localized notation`s local notation "τ" => translationNumber theorem transnumAuxSeq_def : f.transnumAuxSeq = fun n : ℕ => (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n := rfl #align circle_deg1_lift.transnum_aux_seq_def CircleDeg1Lift.transnumAuxSeq_def theorem translationNumber_eq_of_tendsto_aux {τ' : ℝ} (h : Tendsto f.transnumAuxSeq atTop (𝓝 τ')) : τ f = τ' := h.limUnder_eq #align circle_deg1_lift.translation_number_eq_of_tendsto_aux CircleDeg1Lift.translationNumber_eq_of_tendsto_aux theorem translationNumber_eq_of_tendsto₀ {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n] 0 / n) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto_aux <| by simpa [(· ∘ ·), transnumAuxSeq_def, coe_pow] using h.comp (Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two) #align circle_deg1_lift.translation_number_eq_of_tendsto₀ CircleDeg1Lift.translationNumber_eq_of_tendsto₀ theorem translationNumber_eq_of_tendsto₀' {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n + 1] 0 / (n + 1)) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto₀ <| (tendsto_add_atTop_iff_nat 1).1 (mod_cast h) #align circle_deg1_lift.translation_number_eq_of_tendsto₀' CircleDeg1Lift.translationNumber_eq_of_tendsto₀' theorem transnumAuxSeq_zero : f.transnumAuxSeq 0 = f 0 := by simp [transnumAuxSeq] #align circle_deg1_lift.transnum_aux_seq_zero CircleDeg1Lift.transnumAuxSeq_zero theorem transnumAuxSeq_dist_lt (n : ℕ) : dist (f.transnumAuxSeq n) (f.transnumAuxSeq (n + 1)) < 1 / 2 / 2 ^ n := by have : 0 < (2 ^ (n + 1) : ℝ) := pow_pos zero_lt_two _ rw [div_div, ← pow_succ', ← abs_of_pos this] replace := abs_pos.2 (ne_of_gt this) convert (div_lt_div_right this).2 ((f ^ 2 ^ n).dist_map_map_zero_lt (f ^ 2 ^ n)) using 1 simp_rw [transnumAuxSeq, Real.dist_eq] rw [← abs_div, sub_div, pow_succ, pow_succ', ← two_mul, mul_div_mul_left _ _ (two_ne_zero' ℝ), pow_mul, sq, mul_apply] #align circle_deg1_lift.transnum_aux_seq_dist_lt CircleDeg1Lift.transnumAuxSeq_dist_lt theorem tendsto_translationNumber_aux : Tendsto f.transnumAuxSeq atTop (𝓝 <| τ f) := (cauchySeq_of_le_geometric_two 1 fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n).tendsto_limUnder #align circle_deg1_lift.tendsto_translation_number_aux CircleDeg1Lift.tendsto_translationNumber_aux theorem dist_map_zero_translationNumber_le : dist (f 0) (τ f) ≤ 1 := f.transnumAuxSeq_zero ▸ dist_le_of_le_geometric_two_of_tendsto₀ 1 (fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n) f.tendsto_translationNumber_aux #align circle_deg1_lift.dist_map_zero_translation_number_le CircleDeg1Lift.dist_map_zero_translationNumber_le theorem tendsto_translationNumber_of_dist_bounded_aux (x : ℕ → ℝ) (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) (x n) ≤ C) : Tendsto (fun n : ℕ => x (2 ^ n) / 2 ^ n) atTop (𝓝 <| τ f) := by apply f.tendsto_translationNumber_aux.congr_dist (squeeze_zero (fun _ => dist_nonneg) _ _) · exact fun n => C / 2 ^ n · intro n have : 0 < (2 ^ n : ℝ) := pow_pos zero_lt_two _ convert (div_le_div_right this).2 (H (2 ^ n)) using 1 rw [transnumAuxSeq, Real.dist_eq, ← sub_div, abs_div, abs_of_pos this, Real.dist_eq] · exact mul_zero C ▸ tendsto_const_nhds.mul <| tendsto_inv_atTop_zero.comp <| tendsto_pow_atTop_atTop_of_one_lt one_lt_two #align circle_deg1_lift.tendsto_translation_number_of_dist_bounded_aux CircleDeg1Lift.tendsto_translationNumber_of_dist_bounded_aux theorem translationNumber_eq_of_dist_bounded {f g : CircleDeg1Lift} (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) ((g ^ n) 0) ≤ C) : τ f = τ g := Eq.symm <| g.translationNumber_eq_of_tendsto_aux <| f.tendsto_translationNumber_of_dist_bounded_aux _ C H #align circle_deg1_lift.translation_number_eq_of_dist_bounded CircleDeg1Lift.translationNumber_eq_of_dist_bounded @[simp] theorem translationNumber_one : τ 1 = 0 := translationNumber_eq_of_tendsto₀ _ <| by simp [tendsto_const_nhds] #align circle_deg1_lift.translation_number_one CircleDeg1Lift.translationNumber_one theorem translationNumber_eq_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (H : SemiconjBy f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_dist_bounded 2 fun n => le_of_lt <| dist_map_zero_lt_of_semiconjBy <| H.pow_right n #align circle_deg1_lift.translation_number_eq_of_semiconj_by CircleDeg1Lift.translationNumber_eq_of_semiconjBy theorem translationNumber_eq_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (H : Function.Semiconj f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_semiconjBy <| semiconjBy_iff_semiconj.2 H #align circle_deg1_lift.translation_number_eq_of_semiconj CircleDeg1Lift.translationNumber_eq_of_semiconj theorem translationNumber_mul_of_commute {f g : CircleDeg1Lift} (h : Commute f g) : τ (f * g) = τ f + τ g := by refine tendsto_nhds_unique ?_ (f.tendsto_translationNumber_aux.add g.tendsto_translationNumber_aux) simp only [transnumAuxSeq, ← add_div] refine (f * g).tendsto_translationNumber_of_dist_bounded_aux (fun n ↦ (f ^ n) 0 + (g ^ n) 0) 1 fun n ↦ ?_ rw [h.mul_pow, dist_comm] exact le_of_lt ((f ^ n).dist_map_map_zero_lt (g ^ n)) #align circle_deg1_lift.translation_number_mul_of_commute CircleDeg1Lift.translationNumber_mul_of_commute @[simp] theorem translationNumber_units_inv (f : CircleDeg1Liftˣ) : τ ↑f⁻¹ = -τ f := eq_neg_iff_add_eq_zero.2 <| by simp [← translationNumber_mul_of_commute (Commute.refl _).units_inv_left] #align circle_deg1_lift.translation_number_units_inv CircleDeg1Lift.translationNumber_units_inv @[simp] theorem translationNumber_pow : ∀ n : ℕ, τ (f ^ n) = n * τ f | 0 => by simp | n + 1 => by rw [pow_succ, translationNumber_mul_of_commute (Commute.pow_self f n), translationNumber_pow n, Nat.cast_add_one, add_mul, one_mul] #align circle_deg1_lift.translation_number_pow CircleDeg1Lift.translationNumber_pow @[simp] theorem translationNumber_zpow (f : CircleDeg1Liftˣ) : ∀ n : ℤ, τ (f ^ n : Units _) = n * τ f | (n : ℕ) => by simp [translationNumber_pow f n] | -[n+1] => by simp; ring #align circle_deg1_lift.translation_number_zpow CircleDeg1Lift.translationNumber_zpow @[simp] theorem translationNumber_conj_eq (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f * g * ↑f⁻¹) = τ g := (translationNumber_eq_of_semiconjBy (f.mk_semiconjBy g)).symm #align circle_deg1_lift.translation_number_conj_eq CircleDeg1Lift.translationNumber_conj_eq @[simp] theorem translationNumber_conj_eq' (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f⁻¹ * g * f) = τ g := translationNumber_conj_eq f⁻¹ g #align circle_deg1_lift.translation_number_conj_eq' CircleDeg1Lift.translationNumber_conj_eq' theorem dist_pow_map_zero_mul_translationNumber_le (n : ℕ) : dist ((f ^ n) 0) (n * f.translationNumber) ≤ 1 := f.translationNumber_pow n ▸ (f ^ n).dist_map_zero_translationNumber_le #align circle_deg1_lift.dist_pow_map_zero_mul_translation_number_le CircleDeg1Lift.dist_pow_map_zero_mul_translationNumber_le theorem tendsto_translation_number₀' : Tendsto (fun n : ℕ => (f ^ (n + 1) : CircleDeg1Lift) 0 / ((n : ℝ) + 1)) atTop (𝓝 <| τ f) := by refine tendsto_iff_dist_tendsto_zero.2 <| squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) ((tendsto_const_div_atTop_nhds_zero_nat 1).comp (tendsto_add_atTop_nat 1)) dsimp have : (0 : ℝ) < n + 1 := n.cast_add_one_pos rw [Real.dist_eq, div_sub' _ _ _ (ne_of_gt this), abs_div, ← Real.dist_eq, abs_of_pos this, Nat.cast_add_one, div_le_div_right this, ← Nat.cast_add_one] apply dist_pow_map_zero_mul_translationNumber_le #align circle_deg1_lift.tendsto_translation_number₀' CircleDeg1Lift.tendsto_translation_number₀' theorem tendsto_translation_number₀ : Tendsto (fun n : ℕ => (f ^ n) 0 / n) atTop (𝓝 <| τ f) := (tendsto_add_atTop_iff_nat 1).1 (mod_cast f.tendsto_translation_number₀') #align circle_deg1_lift.tendsto_translation_number₀ CircleDeg1Lift.tendsto_translation_number₀ /-- For any `x : ℝ` the sequence $\frac{f^n(x)-x}{n}$ tends to the translation number of `f`. In particular, this limit does not depend on `x`. -/ theorem tendsto_translationNumber (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ n) x - x) / n) atTop (𝓝 <| τ f) := by rw [← translationNumber_conj_eq' (translate <| Multiplicative.ofAdd x)] refine (tendsto_translation_number₀ _).congr fun n ↦ ?_ simp [sub_eq_neg_add, Units.conj_pow'] #align circle_deg1_lift.tendsto_translation_number CircleDeg1Lift.tendsto_translationNumber theorem tendsto_translation_number' (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ (n + 1) : CircleDeg1Lift) x - x) / (n + 1)) atTop (𝓝 <| τ f) := mod_cast (tendsto_add_atTop_iff_nat 1).2 (f.tendsto_translationNumber x) #align circle_deg1_lift.tendsto_translation_number' CircleDeg1Lift.tendsto_translation_number' theorem translationNumber_mono : Monotone τ := fun f g h => le_of_tendsto_of_tendsto' f.tendsto_translation_number₀ g.tendsto_translation_number₀ fun n => by gcongr; exact pow_mono h _ _ #align circle_deg1_lift.translation_number_mono CircleDeg1Lift.translationNumber_mono theorem translationNumber_translate (x : ℝ) : τ (translate <| Multiplicative.ofAdd x) = x := translationNumber_eq_of_tendsto₀' _ <| by simp only [translate_iterate, translate_apply, add_zero, Nat.cast_succ, mul_div_cancel_left₀ (M₀ := ℝ) _ (Nat.cast_add_one_ne_zero _), tendsto_const_nhds] #align circle_deg1_lift.translation_number_translate CircleDeg1Lift.translationNumber_translate theorem translationNumber_le_of_le_add {z : ℝ} (hz : ∀ x, f x ≤ x + z) : τ f ≤ z := translationNumber_translate z ▸ translationNumber_mono fun x => (hz x).trans_eq (add_comm _ _) #align circle_deg1_lift.translation_number_le_of_le_add CircleDeg1Lift.translationNumber_le_of_le_add theorem le_translationNumber_of_add_le {z : ℝ} (hz : ∀ x, x + z ≤ f x) : z ≤ τ f := translationNumber_translate z ▸ translationNumber_mono fun x => (add_comm _ _).trans_le (hz x) #align circle_deg1_lift.le_translation_number_of_add_le CircleDeg1Lift.le_translationNumber_of_add_le theorem translationNumber_le_of_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) : τ f ≤ m := le_of_tendsto' (f.tendsto_translation_number' x) fun n => (div_le_iff' (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| sub_le_iff_le_add'.2 <| (coe_pow f (n + 1)).symm ▸ @Nat.cast_add_one ℝ _ n ▸ f.iterate_le_of_map_le_add_int h (n + 1) #align circle_deg1_lift.translation_number_le_of_le_add_int CircleDeg1Lift.translationNumber_le_of_le_add_int theorem translationNumber_le_of_le_add_nat {x : ℝ} {m : ℕ} (h : f x ≤ x + m) : τ f ≤ m := @translationNumber_le_of_le_add_int f x m h #align circle_deg1_lift.translation_number_le_of_le_add_nat CircleDeg1Lift.translationNumber_le_of_le_add_nat theorem le_translationNumber_of_add_int_le {x : ℝ} {m : ℤ} (h : x + m ≤ f x) : ↑m ≤ τ f := ge_of_tendsto' (f.tendsto_translation_number' x) fun n => (le_div_iff (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| le_sub_iff_add_le'.2 <| by simp only [coe_pow, mul_comm (m : ℝ), ← Nat.cast_add_one, f.le_iterate_of_add_int_le_map h] #align circle_deg1_lift.le_translation_number_of_add_int_le CircleDeg1Lift.le_translationNumber_of_add_int_le theorem le_translationNumber_of_add_nat_le {x : ℝ} {m : ℕ} (h : x + m ≤ f x) : ↑m ≤ τ f := @le_translationNumber_of_add_int_le f x m h #align circle_deg1_lift.le_translation_number_of_add_nat_le CircleDeg1Lift.le_translationNumber_of_add_nat_le /-- If `f x - x` is an integer number `m` for some point `x`, then `τ f = m`. On the circle this means that a map with a fixed point has rotation number zero. -/ theorem translationNumber_of_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) : τ f = m := le_antisymm (translationNumber_le_of_le_add_int f <| le_of_eq h) (le_translationNumber_of_add_int_le f <| le_of_eq h.symm) #align circle_deg1_lift.translation_number_of_eq_add_int CircleDeg1Lift.translationNumber_of_eq_add_int theorem floor_sub_le_translationNumber (x : ℝ) : ↑⌊f x - x⌋ ≤ τ f := le_translationNumber_of_add_int_le f <| le_sub_iff_add_le'.1 (floor_le <| f x - x) #align circle_deg1_lift.floor_sub_le_translation_number CircleDeg1Lift.floor_sub_le_translationNumber theorem translationNumber_le_ceil_sub (x : ℝ) : τ f ≤ ⌈f x - x⌉ := translationNumber_le_of_le_add_int f <| sub_le_iff_le_add'.1 (le_ceil <| f x - x) #align circle_deg1_lift.translation_number_le_ceil_sub CircleDeg1Lift.translationNumber_le_ceil_sub theorem map_lt_of_translationNumber_lt_int {n : ℤ} (h : τ f < n) (x : ℝ) : f x < x + n := not_le.1 <| mt f.le_translationNumber_of_add_int_le <| not_le.2 h #align circle_deg1_lift.map_lt_of_translation_number_lt_int CircleDeg1Lift.map_lt_of_translationNumber_lt_int theorem map_lt_of_translationNumber_lt_nat {n : ℕ} (h : τ f < n) (x : ℝ) : f x < x + n := @map_lt_of_translationNumber_lt_int f n h x #align circle_deg1_lift.map_lt_of_translation_number_lt_nat CircleDeg1Lift.map_lt_of_translationNumber_lt_nat theorem map_lt_add_floor_translationNumber_add_one (x : ℝ) : f x < x + ⌊τ f⌋ + 1 := by rw [add_assoc] norm_cast refine map_lt_of_translationNumber_lt_int _ ?_ _ push_cast exact lt_floor_add_one _ #align circle_deg1_lift.map_lt_add_floor_translation_number_add_one CircleDeg1Lift.map_lt_add_floor_translationNumber_add_one theorem map_lt_add_translationNumber_add_one (x : ℝ) : f x < x + τ f + 1 := calc f x < x + ⌊τ f⌋ + 1 := f.map_lt_add_floor_translationNumber_add_one x _ ≤ x + τ f + 1 := by gcongr; apply floor_le #align circle_deg1_lift.map_lt_add_translation_number_add_one CircleDeg1Lift.map_lt_add_translationNumber_add_one theorem lt_map_of_int_lt_translationNumber {n : ℤ} (h : ↑n < τ f) (x : ℝ) : x + n < f x := not_le.1 <| mt f.translationNumber_le_of_le_add_int <| not_le.2 h #align circle_deg1_lift.lt_map_of_int_lt_translation_number CircleDeg1Lift.lt_map_of_int_lt_translationNumber theorem lt_map_of_nat_lt_translationNumber {n : ℕ} (h : ↑n < τ f) (x : ℝ) : x + n < f x := @lt_map_of_int_lt_translationNumber f n h x #align circle_deg1_lift.lt_map_of_nat_lt_translation_number CircleDeg1Lift.lt_map_of_nat_lt_translationNumber /-- If `f^n x - x`, `n > 0`, is an integer number `m` for some point `x`, then `τ f = m / n`. On the circle this means that a map with a periodic orbit has a rational rotation number. -/ theorem translationNumber_of_map_pow_eq_add_int {x : ℝ} {n : ℕ} {m : ℤ} (h : (f ^ n) x = x + m) (hn : 0 < n) : τ f = m / n := by have := (f ^ n).translationNumber_of_eq_add_int h rwa [translationNumber_pow, mul_comm, ← eq_div_iff] at this exact Nat.cast_ne_zero.2 (ne_of_gt hn) #align circle_deg1_lift.translation_number_of_map_pow_eq_add_int CircleDeg1Lift.translationNumber_of_map_pow_eq_add_int /-- If a predicate depends only on `f x - x` and holds for all `0 ≤ x ≤ 1`, then it holds for all `x`. -/ theorem forall_map_sub_of_Icc (P : ℝ → Prop) (h : ∀ x ∈ Icc (0 : ℝ) 1, P (f x - x)) (x : ℝ) : P (f x - x) := f.map_fract_sub_fract_eq x ▸ h _ ⟨fract_nonneg _, le_of_lt (fract_lt_one _)⟩ #align circle_deg1_lift.forall_map_sub_of_Icc CircleDeg1Lift.forall_map_sub_of_Icc
Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean
906
914
theorem translationNumber_lt_of_forall_lt_add (hf : Continuous f) {z : ℝ} (hz : ∀ x, f x < x + z) : τ f < z := by
obtain ⟨x, -, hx⟩ : ∃ x ∈ Icc (0 : ℝ) 1, ∀ y ∈ Icc (0 : ℝ) 1, f y - y ≤ f x - x := isCompact_Icc.exists_isMaxOn (nonempty_Icc.2 zero_le_one) (hf.sub continuous_id).continuousOn refine lt_of_le_of_lt ?_ (sub_lt_iff_lt_add'.2 <| hz x) apply translationNumber_le_of_le_add simp only [← sub_le_iff_le_add'] exact f.forall_map_sub_of_Icc (fun a => a ≤ f x - x) hx
/- 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.Topology.Baire.Lemmas import Mathlib.Topology.Baire.CompleteMetrizable import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Analysis.NormedSpace.AffineIsometry import Mathlib.Analysis.Normed.Group.InfiniteSum #align_import analysis.normed_space.banach from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Banach open mapping theorem This file contains the Banach open mapping theorem, i.e., the fact that a bijective bounded linear map between Banach spaces has a bounded inverse. -/ open scoped Classical open Function Metric Set Filter Finset Topology NNReal open LinearMap (range ker) variable {𝕜 𝕜' : Type*} [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜'] {σ : 𝕜 →+* 𝕜'} {σ' : 𝕜' →+* 𝕜} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [RingHomIsometric σ] [RingHomIsometric σ'] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜' F] (f : E →SL[σ] F) namespace ContinuousLinearMap /-- A (possibly nonlinear) right inverse to a continuous linear map, which doesn't have to be linear itself but which satisfies a bound `‖inverse x‖ ≤ C * ‖x‖`. A surjective continuous linear map doesn't always have a continuous linear right inverse, but it always has a nonlinear inverse in this sense, by Banach's open mapping theorem. -/ structure NonlinearRightInverse where toFun : F → E nnnorm : ℝ≥0 bound' : ∀ y, ‖toFun y‖ ≤ nnnorm * ‖y‖ right_inv' : ∀ y, f (toFun y) = y #align continuous_linear_map.nonlinear_right_inverse ContinuousLinearMap.NonlinearRightInverse instance : CoeFun (NonlinearRightInverse f) fun _ => F → E := ⟨fun fsymm => fsymm.toFun⟩ @[simp] theorem NonlinearRightInverse.right_inv {f : E →SL[σ] F} (fsymm : NonlinearRightInverse f) (y : F) : f (fsymm y) = y := fsymm.right_inv' y #align continuous_linear_map.nonlinear_right_inverse.right_inv ContinuousLinearMap.NonlinearRightInverse.right_inv theorem NonlinearRightInverse.bound {f : E →SL[σ] F} (fsymm : NonlinearRightInverse f) (y : F) : ‖fsymm y‖ ≤ fsymm.nnnorm * ‖y‖ := fsymm.bound' y #align continuous_linear_map.nonlinear_right_inverse.bound ContinuousLinearMap.NonlinearRightInverse.bound end ContinuousLinearMap /-- Given a continuous linear equivalence, the inverse is in particular an instance of `ContinuousLinearMap.NonlinearRightInverse` (which turns out to be linear). -/ noncomputable def ContinuousLinearEquiv.toNonlinearRightInverse (f : E ≃SL[σ] F) : ContinuousLinearMap.NonlinearRightInverse (f : E →SL[σ] F) where toFun := f.invFun nnnorm := ‖(f.symm : F →SL[σ'] E)‖₊ bound' _ := ContinuousLinearMap.le_opNorm (f.symm : F →SL[σ'] E) _ right_inv' := f.apply_symm_apply #align continuous_linear_equiv.to_nonlinear_right_inverse ContinuousLinearEquiv.toNonlinearRightInverse noncomputable instance (f : E ≃SL[σ] F) : Inhabited (ContinuousLinearMap.NonlinearRightInverse (f : E →SL[σ] F)) := ⟨f.toNonlinearRightInverse⟩ /-! ### Proof of the Banach open mapping theorem -/ variable [CompleteSpace F] namespace ContinuousLinearMap /-- First step of the proof of the Banach open mapping theorem (using completeness of `F`): by Baire's theorem, there exists a ball in `E` whose image closure has nonempty interior. Rescaling everything, it follows that any `y ∈ F` is arbitrarily well approached by images of elements of norm at most `C * ‖y‖`. For further use, we will only need such an element whose image is within distance `‖y‖/2` of `y`, to apply an iterative process. -/ theorem exists_approx_preimage_norm_le (surj : Surjective f) : ∃ C ≥ 0, ∀ y, ∃ x, dist (f x) y ≤ 1 / 2 * ‖y‖ ∧ ‖x‖ ≤ C * ‖y‖ := by have A : ⋃ n : ℕ, closure (f '' ball 0 n) = Set.univ := by refine Subset.antisymm (subset_univ _) fun y _ => ?_ rcases surj y with ⟨x, hx⟩ rcases exists_nat_gt ‖x‖ with ⟨n, hn⟩ refine mem_iUnion.2 ⟨n, subset_closure ?_⟩ refine (mem_image _ _ _).2 ⟨x, ⟨?_, hx⟩⟩ rwa [mem_ball, dist_eq_norm, sub_zero] have : ∃ (n : ℕ) (x : _), x ∈ interior (closure (f '' ball 0 n)) := nonempty_interior_of_iUnion_of_closed (fun n => isClosed_closure) A simp only [mem_interior_iff_mem_nhds, Metric.mem_nhds_iff] at this rcases this with ⟨n, a, ε, ⟨εpos, H⟩⟩ rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ refine ⟨(ε / 2)⁻¹ * ‖c‖ * 2 * n, by positivity, fun y => ?_⟩ rcases eq_or_ne y 0 with rfl | hy · use 0 simp · have hc' : 1 < ‖σ c‖ := by simp only [RingHomIsometric.is_iso, hc] rcases rescale_to_shell hc' (half_pos εpos) hy with ⟨d, hd, ydlt, -, dinv⟩ let δ := ‖d‖ * ‖y‖ / 4 have δpos : 0 < δ := div_pos (mul_pos (norm_pos_iff.2 hd) (norm_pos_iff.2 hy)) (by norm_num) have : a + d • y ∈ ball a ε := by simp [dist_eq_norm, lt_of_le_of_lt ydlt.le (half_lt_self εpos)] rcases Metric.mem_closure_iff.1 (H this) _ δpos with ⟨z₁, z₁im, h₁⟩ rcases (mem_image _ _ _).1 z₁im with ⟨x₁, hx₁, xz₁⟩ rw [← xz₁] at h₁ rw [mem_ball, dist_eq_norm, sub_zero] at hx₁ have : a ∈ ball a ε := by simp only [mem_ball, dist_self] exact εpos rcases Metric.mem_closure_iff.1 (H this) _ δpos with ⟨z₂, z₂im, h₂⟩ rcases (mem_image _ _ _).1 z₂im with ⟨x₂, hx₂, xz₂⟩ rw [← xz₂] at h₂ rw [mem_ball, dist_eq_norm, sub_zero] at hx₂ let x := x₁ - x₂ have I : ‖f x - d • y‖ ≤ 2 * δ := calc ‖f x - d • y‖ = ‖f x₁ - (a + d • y) - (f x₂ - a)‖ := by congr 1 simp only [f.map_sub] abel _ ≤ ‖f x₁ - (a + d • y)‖ + ‖f x₂ - a‖ := norm_sub_le _ _ _ ≤ δ + δ := by rw [dist_eq_norm'] at h₁ h₂; gcongr _ = 2 * δ := (two_mul _).symm have J : ‖f (σ' d⁻¹ • x) - y‖ ≤ 1 / 2 * ‖y‖ := calc ‖f (σ' d⁻¹ • x) - y‖ = ‖d⁻¹ • f x - (d⁻¹ * d) • y‖ := by rwa [f.map_smulₛₗ _, inv_mul_cancel, one_smul, map_inv₀, map_inv₀, RingHomCompTriple.comp_apply, RingHom.id_apply] _ = ‖d⁻¹ • (f x - d • y)‖ := by rw [mul_smul, smul_sub] _ = ‖d‖⁻¹ * ‖f x - d • y‖ := by rw [norm_smul, norm_inv] _ ≤ ‖d‖⁻¹ * (2 * δ) := by gcongr _ = ‖d‖⁻¹ * ‖d‖ * ‖y‖ / 2 := by simp only [δ] ring _ = ‖y‖ / 2 := by rw [inv_mul_cancel, one_mul] simp [norm_eq_zero, hd] _ = 1 / 2 * ‖y‖ := by ring rw [← dist_eq_norm] at J have K : ‖σ' d⁻¹ • x‖ ≤ (ε / 2)⁻¹ * ‖c‖ * 2 * ↑n * ‖y‖ := calc ‖σ' d⁻¹ • x‖ = ‖d‖⁻¹ * ‖x₁ - x₂‖ := by rw [norm_smul, RingHomIsometric.is_iso, norm_inv] _ ≤ (ε / 2)⁻¹ * ‖c‖ * ‖y‖ * (n + n) := by gcongr · simpa using dinv · exact le_trans (norm_sub_le _ _) (by gcongr) _ = (ε / 2)⁻¹ * ‖c‖ * 2 * ↑n * ‖y‖ := by ring exact ⟨σ' d⁻¹ • x, J, K⟩ #align continuous_linear_map.exists_approx_preimage_norm_le ContinuousLinearMap.exists_approx_preimage_norm_le variable [CompleteSpace E] /-- The Banach open mapping theorem: if a bounded linear map between Banach spaces is onto, then any point has a preimage with controlled norm. -/
Mathlib/Analysis/NormedSpace/Banach.lean
164
226
theorem exists_preimage_norm_le (surj : Surjective f) : ∃ C > 0, ∀ y, ∃ x, f x = y ∧ ‖x‖ ≤ C * ‖y‖ := by
obtain ⟨C, C0, hC⟩ := exists_approx_preimage_norm_le f surj /- Second step of the proof: starting from `y`, we want an exact preimage of `y`. Let `g y` be the approximate preimage of `y` given by the first step, and `h y = y - f(g y)` the part that has no preimage yet. We will iterate this process, taking the approximate preimage of `h y`, leaving only `h^2 y` without preimage yet, and so on. Let `u n` be the approximate preimage of `h^n y`. Then `u` is a converging series, and by design the sum of the series is a preimage of `y`. This uses completeness of `E`. -/ choose g hg using hC let h y := y - f (g y) have hle : ∀ y, ‖h y‖ ≤ 1 / 2 * ‖y‖ := by intro y rw [← dist_eq_norm, dist_comm] exact (hg y).1 refine ⟨2 * C + 1, by linarith, fun y => ?_⟩ have hnle : ∀ n : ℕ, ‖h^[n] y‖ ≤ (1 / 2) ^ n * ‖y‖ := by intro n induction' n with n IH · simp only [one_div, Nat.zero_eq, one_mul, iterate_zero_apply, pow_zero, le_rfl] · rw [iterate_succ'] apply le_trans (hle _) _ rw [pow_succ', mul_assoc] gcongr let u n := g (h^[n] y) have ule : ∀ n, ‖u n‖ ≤ (1 / 2) ^ n * (C * ‖y‖) := fun n ↦ by apply le_trans (hg _).2 calc C * ‖h^[n] y‖ ≤ C * ((1 / 2) ^ n * ‖y‖) := mul_le_mul_of_nonneg_left (hnle n) C0 _ = (1 / 2) ^ n * (C * ‖y‖) := by ring have sNu : Summable fun n => ‖u n‖ := by refine .of_nonneg_of_le (fun n => norm_nonneg _) ule ?_ exact Summable.mul_right _ (summable_geometric_of_lt_one (by norm_num) (by norm_num)) have su : Summable u := sNu.of_norm let x := tsum u have x_ineq : ‖x‖ ≤ (2 * C + 1) * ‖y‖ := calc ‖x‖ ≤ ∑' n, ‖u n‖ := norm_tsum_le_tsum_norm sNu _ ≤ ∑' n, (1 / 2) ^ n * (C * ‖y‖) := tsum_le_tsum ule sNu (Summable.mul_right _ summable_geometric_two) _ = (∑' n, (1 / 2) ^ n) * (C * ‖y‖) := tsum_mul_right _ = 2 * C * ‖y‖ := by rw [tsum_geometric_two, mul_assoc] _ ≤ 2 * C * ‖y‖ + ‖y‖ := le_add_of_nonneg_right (norm_nonneg y) _ = (2 * C + 1) * ‖y‖ := by ring have fsumeq : ∀ n : ℕ, f (∑ i ∈ Finset.range n, u i) = y - h^[n] y := by intro n induction' n with n IH · simp [f.map_zero] · rw [sum_range_succ, f.map_add, IH, iterate_succ_apply', sub_add] have : Tendsto (fun n => ∑ i ∈ Finset.range n, u i) atTop (𝓝 x) := su.hasSum.tendsto_sum_nat have L₁ : Tendsto (fun n => f (∑ i ∈ Finset.range n, u i)) atTop (𝓝 (f x)) := (f.continuous.tendsto _).comp this simp only [fsumeq] at L₁ have L₂ : Tendsto (fun n => y - h^[n] y) atTop (𝓝 (y - 0)) := by refine tendsto_const_nhds.sub ?_ rw [tendsto_iff_norm_sub_tendsto_zero] simp only [sub_zero] refine squeeze_zero (fun _ => norm_nonneg _) hnle ?_ rw [← zero_mul ‖y‖] refine (_root_.tendsto_pow_atTop_nhds_zero_of_lt_one ?_ ?_).mul tendsto_const_nhds <;> norm_num have feq : f x = y - 0 := tendsto_nhds_unique L₁ L₂ rw [sub_zero] at feq exact ⟨x, feq, x_ineq⟩
/- 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, Yaël Dillies -/ import Mathlib.Topology.Sets.Opens #align_import topology.sets.closeds from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Closed sets We define a few types of closed sets in a topological space. ## Main Definitions For a topological space `α`, * `TopologicalSpace.Closeds α`: The type of closed sets. * `TopologicalSpace.Clopens α`: The type of clopen sets. -/ open Order OrderDual Set variable {ι α β : Type*} [TopologicalSpace α] [TopologicalSpace β] namespace TopologicalSpace /-! ### Closed sets -/ /-- The type of closed subsets of a topological space. -/ structure Closeds (α : Type*) [TopologicalSpace α] where /-- the carrier set, i.e. the points in this set -/ carrier : Set α closed' : IsClosed carrier #align topological_space.closeds TopologicalSpace.Closeds namespace Closeds instance : SetLike (Closeds α) α where coe := Closeds.carrier coe_injective' s t h := by cases s; cases t; congr instance : CanLift (Set α) (Closeds α) (↑) IsClosed where prf s hs := ⟨⟨s, hs⟩, rfl⟩ theorem closed (s : Closeds α) : IsClosed (s : Set α) := s.closed' #align topological_space.closeds.closed TopologicalSpace.Closeds.closed /-- See Note [custom simps projection]. -/ def Simps.coe (s : Closeds α) : Set α := s initialize_simps_projections Closeds (carrier → coe, as_prefix coe) @[ext] protected theorem ext {s t : Closeds α} (h : (s : Set α) = t) : s = t := SetLike.ext' h #align topological_space.closeds.ext TopologicalSpace.Closeds.ext @[simp] theorem coe_mk (s : Set α) (h) : (mk s h : Set α) = s := rfl #align topological_space.closeds.coe_mk TopologicalSpace.Closeds.coe_mk /-- The closure of a set, as an element of `TopologicalSpace.Closeds`. -/ @[simps] protected def closure (s : Set α) : Closeds α := ⟨closure s, isClosed_closure⟩ #align topological_space.closeds.closure TopologicalSpace.Closeds.closure theorem gc : GaloisConnection Closeds.closure ((↑) : Closeds α → Set α) := fun _ U => ⟨subset_closure.trans, fun h => closure_minimal h U.closed⟩ #align topological_space.closeds.gc TopologicalSpace.Closeds.gc /-- The galois coinsertion between sets and opens. -/ def gi : GaloisInsertion (@Closeds.closure α _) (↑) where choice s hs := ⟨s, closure_eq_iff_isClosed.1 <| hs.antisymm subset_closure⟩ gc := gc le_l_u _ := subset_closure choice_eq _s hs := SetLike.coe_injective <| subset_closure.antisymm hs #align topological_space.closeds.gi TopologicalSpace.Closeds.gi instance completeLattice : CompleteLattice (Closeds α) := CompleteLattice.copy (GaloisInsertion.liftCompleteLattice gi) -- le _ rfl -- top ⟨univ, isClosed_univ⟩ rfl -- bot ⟨∅, isClosed_empty⟩ (SetLike.coe_injective closure_empty.symm) -- sup (fun s t => ⟨s ∪ t, s.2.union t.2⟩) (funext fun s => funext fun t => SetLike.coe_injective (s.2.union t.2).closure_eq.symm) -- inf (fun s t => ⟨s ∩ t, s.2.inter t.2⟩) rfl -- sSup _ rfl -- sInf (fun S => ⟨⋂ s ∈ S, ↑s, isClosed_biInter fun s _ => s.2⟩) (funext fun _ => SetLike.coe_injective sInf_image.symm) /-- The type of closed sets is inhabited, with default element the empty set. -/ instance : Inhabited (Closeds α) := ⟨⊥⟩ @[simp, norm_cast]
Mathlib/Topology/Sets/Closeds.lean
110
111
theorem coe_sup (s t : Closeds α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := by
rfl
/- 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 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 #align prime_spectrum.localization_comap_injective PrimeSpectrum.localization_comap_injective theorem localization_comap_embedding [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Embedding (comap (algebraMap R S)) := ⟨localization_comap_inducing S M, localization_comap_injective S M⟩ #align prime_spectrum.localization_comap_embedding PrimeSpectrum.localization_comap_embedding theorem localization_comap_range [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Set.range (comap (algebraMap R S)) = { p | Disjoint (M : Set R) p.asIdeal } := by ext x constructor · simp_rw [disjoint_iff_inf_le] rintro ⟨p, rfl⟩ x ⟨hx₁, hx₂⟩ exact (p.2.1 : ¬_) (p.asIdeal.eq_top_of_isUnit_mem hx₂ (IsLocalization.map_units S ⟨x, hx₁⟩)) · intro h use ⟨x.asIdeal.map (algebraMap R S), IsLocalization.isPrime_of_isPrime_disjoint M S _ x.2 h⟩ ext1 exact IsLocalization.comap_map_of_isPrime_disjoint M S _ x.2 h #align prime_spectrum.localization_comap_range PrimeSpectrum.localization_comap_range open Function RingHom theorem comap_inducing_of_surjective (hf : Surjective f) : Inducing (comap f) where induced := by set_option tactic.skipAssignedInstances false in simp_rw [TopologicalSpace.ext_iff, ← isClosed_compl_iff, ← @isClosed_compl_iff (PrimeSpectrum S) ((TopologicalSpace.induced (comap f) zariskiTopology)), isClosed_induced_iff, isClosed_iff_zeroLocus] refine fun s => ⟨fun ⟨F, hF⟩ => ⟨zeroLocus (f ⁻¹' F), ⟨f ⁻¹' F, rfl⟩, by rw [preimage_comap_zeroLocus, Function.Surjective.image_preimage hf, hF]⟩, ?_⟩ rintro ⟨-, ⟨F, rfl⟩, hF⟩ exact ⟨f '' F, hF.symm.trans (preimage_comap_zeroLocus f F)⟩ #align prime_spectrum.comap_inducing_of_surjective PrimeSpectrum.comap_inducing_of_surjective end Comap end CommSemiRing section SpecOfSurjective /-! The comap of a surjective ring homomorphism is a closed embedding between the prime spectra. -/ open Function RingHom variable [CommRing R] [CommRing S] variable (f : R →+* S) variable {R} theorem comap_singleton_isClosed_of_surjective (f : R →+* S) (hf : Function.Surjective f) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := haveI : x.asIdeal.IsMaximal := (isClosed_singleton_iff_isMaximal x).1 hx (isClosed_singleton_iff_isMaximal _).2 (Ideal.comap_isMaximal_of_surjective f hf) #align prime_spectrum.comap_singleton_is_closed_of_surjective PrimeSpectrum.comap_singleton_isClosed_of_surjective theorem comap_singleton_isClosed_of_isIntegral (f : R →+* S) (hf : f.IsIntegral) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := have := (isClosed_singleton_iff_isMaximal x).1 hx (isClosed_singleton_iff_isMaximal _).2 (Ideal.isMaximal_comap_of_isIntegral_of_isMaximal' f hf x.asIdeal) #align prime_spectrum.comap_singleton_is_closed_of_is_integral PrimeSpectrum.comap_singleton_isClosed_of_isIntegral theorem image_comap_zeroLocus_eq_zeroLocus_comap (hf : Surjective f) (I : Ideal S) : comap f '' zeroLocus I = zeroLocus (I.comap f) := by simp only [Set.ext_iff, Set.mem_image, mem_zeroLocus, SetLike.coe_subset_coe] refine fun p => ⟨?_, fun h_I_p => ?_⟩ · rintro ⟨p, hp, rfl⟩ a ha exact hp ha · have hp : ker f ≤ p.asIdeal := (Ideal.comap_mono bot_le).trans h_I_p refine ⟨⟨p.asIdeal.map f, Ideal.map_isPrime_of_surjective hf hp⟩, fun x hx => ?_, ?_⟩ · obtain ⟨x', rfl⟩ := hf x exact Ideal.mem_map_of_mem f (h_I_p hx) · ext x rw [comap_asIdeal, Ideal.mem_comap, Ideal.mem_map_iff_of_surjective f hf] refine ⟨?_, fun hx => ⟨x, hx, rfl⟩⟩ rintro ⟨x', hx', heq⟩ rw [← sub_sub_cancel x' x] refine p.asIdeal.sub_mem hx' (hp ?_) rwa [mem_ker, map_sub, sub_eq_zero] #align prime_spectrum.image_comap_zero_locus_eq_zero_locus_comap PrimeSpectrum.image_comap_zeroLocus_eq_zeroLocus_comap theorem range_comap_of_surjective (hf : Surjective f) : Set.range (comap f) = zeroLocus (ker f) := by rw [← Set.image_univ] convert image_comap_zeroLocus_eq_zeroLocus_comap _ _ hf _ rw [zeroLocus_bot] #align prime_spectrum.range_comap_of_surjective PrimeSpectrum.range_comap_of_surjective theorem isClosed_range_comap_of_surjective (hf : Surjective f) : IsClosed (Set.range (comap f)) := by rw [range_comap_of_surjective _ f hf] exact isClosed_zeroLocus _ #align prime_spectrum.is_closed_range_comap_of_surjective PrimeSpectrum.isClosed_range_comap_of_surjective theorem closedEmbedding_comap_of_surjective (hf : Surjective f) : ClosedEmbedding (comap f) := { induced := (comap_inducing_of_surjective S f hf).induced inj := comap_injective_of_surjective f hf isClosed_range := isClosed_range_comap_of_surjective S f hf } #align prime_spectrum.closed_embedding_comap_of_surjective PrimeSpectrum.closedEmbedding_comap_of_surjective end SpecOfSurjective section CommSemiRing variable [CommSemiring R] [CommSemiring S] variable {R S} section BasicOpen /-- `basicOpen r` is the open subset containing all prime ideals not containing `r`. -/ def basicOpen (r : R) : TopologicalSpace.Opens (PrimeSpectrum R) where carrier := { x | r ∉ x.asIdeal } is_open' := ⟨{r}, Set.ext fun _ => Set.singleton_subset_iff.trans <| Classical.not_not.symm⟩ #align prime_spectrum.basic_open PrimeSpectrum.basicOpen @[simp] theorem mem_basicOpen (f : R) (x : PrimeSpectrum R) : x ∈ basicOpen f ↔ f ∉ x.asIdeal := Iff.rfl #align prime_spectrum.mem_basic_open PrimeSpectrum.mem_basicOpen theorem isOpen_basicOpen {a : R} : IsOpen (basicOpen a : Set (PrimeSpectrum R)) := (basicOpen a).isOpen #align prime_spectrum.is_open_basic_open PrimeSpectrum.isOpen_basicOpen @[simp] theorem basicOpen_eq_zeroLocus_compl (r : R) : (basicOpen r : Set (PrimeSpectrum R)) = (zeroLocus {r})ᶜ := Set.ext fun x => by simp only [SetLike.mem_coe, mem_basicOpen, Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff] #align prime_spectrum.basic_open_eq_zero_locus_compl PrimeSpectrum.basicOpen_eq_zeroLocus_compl @[simp] theorem basicOpen_one : basicOpen (1 : R) = ⊤ := TopologicalSpace.Opens.ext <| by simp #align prime_spectrum.basic_open_one PrimeSpectrum.basicOpen_one @[simp] theorem basicOpen_zero : basicOpen (0 : R) = ⊥ := TopologicalSpace.Opens.ext <| by simp #align prime_spectrum.basic_open_zero PrimeSpectrum.basicOpen_zero theorem basicOpen_le_basicOpen_iff (f g : R) : basicOpen f ≤ basicOpen g ↔ f ∈ (Ideal.span ({g} : Set R)).radical := by rw [← SetLike.coe_subset_coe, basicOpen_eq_zeroLocus_compl, basicOpen_eq_zeroLocus_compl, Set.compl_subset_compl, zeroLocus_subset_zeroLocus_singleton_iff] #align prime_spectrum.basic_open_le_basic_open_iff PrimeSpectrum.basicOpen_le_basicOpen_iff theorem basicOpen_mul (f g : R) : basicOpen (f * g) = basicOpen f ⊓ basicOpen g := TopologicalSpace.Opens.ext <| by simp [zeroLocus_singleton_mul] #align prime_spectrum.basic_open_mul PrimeSpectrum.basicOpen_mul theorem basicOpen_mul_le_left (f g : R) : basicOpen (f * g) ≤ basicOpen f := by rw [basicOpen_mul f g] exact inf_le_left #align prime_spectrum.basic_open_mul_le_left PrimeSpectrum.basicOpen_mul_le_left theorem basicOpen_mul_le_right (f g : R) : basicOpen (f * g) ≤ basicOpen g := by rw [basicOpen_mul f g] exact inf_le_right #align prime_spectrum.basic_open_mul_le_right PrimeSpectrum.basicOpen_mul_le_right @[simp] theorem basicOpen_pow (f : R) (n : ℕ) (hn : 0 < n) : basicOpen (f ^ n) = basicOpen f := TopologicalSpace.Opens.ext <| by simpa using zeroLocus_singleton_pow f n hn #align prime_spectrum.basic_open_pow PrimeSpectrum.basicOpen_pow
Mathlib/AlgebraicGeometry/PrimeSpectrum/Basic.lean
833
844
theorem isTopologicalBasis_basic_opens : TopologicalSpace.IsTopologicalBasis (Set.range fun r : R => (basicOpen r : Set (PrimeSpectrum R))) := by
apply TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds · rintro _ ⟨r, rfl⟩ exact isOpen_basicOpen · rintro p U hp ⟨s, hs⟩ rw [← compl_compl U, Set.mem_compl_iff, ← hs, mem_zeroLocus, Set.not_subset] at hp obtain ⟨f, hfs, hfp⟩ := hp refine ⟨basicOpen f, ⟨f, rfl⟩, hfp, ?_⟩ rw [← Set.compl_subset_compl, ← hs, basicOpen_eq_zeroLocus_compl, compl_compl] exact zeroLocus_anti_mono (Set.singleton_subset_iff.mpr hfs)
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Data.Sym.Card /-! # Definitions for finite and locally finite graphs This file defines finite versions of `edgeSet`, `neighborSet` and `incidenceSet` and proves some of their basic properties. It also defines the notion of a locally finite graph, which is one whose vertices have finite degree. The design for finiteness is that each definition takes the smallest finiteness assumption necessary. For example, `SimpleGraph.neighborFinset v` only requires that `v` have finitely many neighbors. ## Main definitions * `SimpleGraph.edgeFinset` is the `Finset` of edges in a graph, if `edgeSet` is finite * `SimpleGraph.neighborFinset` is the `Finset` of vertices adjacent to a given vertex, if `neighborSet` is finite * `SimpleGraph.incidenceFinset` is the `Finset` of edges containing a given vertex, if `incidenceSet` is finite ## Naming conventions If the vertex type of a graph is finite, we refer to its cardinality as `CardVerts` or `card_verts`. ## Implementation notes * A locally finite graph is one with instances `Π v, Fintype (G.neighborSet v)`. * Given instances `DecidableRel G.Adj` and `Fintype V`, then the graph is locally finite, too. -/ open Finset Function namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) {e : Sym2 V} section EdgeFinset variable {G₁ G₂ : SimpleGraph V} [Fintype G.edgeSet] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] /-- The `edgeSet` of the graph as a `Finset`. -/ abbrev edgeFinset : Finset (Sym2 V) := Set.toFinset G.edgeSet #align simple_graph.edge_finset SimpleGraph.edgeFinset @[norm_cast] theorem coe_edgeFinset : (G.edgeFinset : Set (Sym2 V)) = G.edgeSet := Set.coe_toFinset _ #align simple_graph.coe_edge_finset SimpleGraph.coe_edgeFinset variable {G} theorem mem_edgeFinset : e ∈ G.edgeFinset ↔ e ∈ G.edgeSet := Set.mem_toFinset #align simple_graph.mem_edge_finset SimpleGraph.mem_edgeFinset theorem not_isDiag_of_mem_edgeFinset : e ∈ G.edgeFinset → ¬e.IsDiag := not_isDiag_of_mem_edgeSet _ ∘ mem_edgeFinset.1 #align simple_graph.not_is_diag_of_mem_edge_finset SimpleGraph.not_isDiag_of_mem_edgeFinset theorem edgeFinset_inj : G₁.edgeFinset = G₂.edgeFinset ↔ G₁ = G₂ := by simp #align simple_graph.edge_finset_inj SimpleGraph.edgeFinset_inj theorem edgeFinset_subset_edgeFinset : G₁.edgeFinset ⊆ G₂.edgeFinset ↔ G₁ ≤ G₂ := by simp #align simple_graph.edge_finset_subset_edge_finset SimpleGraph.edgeFinset_subset_edgeFinset theorem edgeFinset_ssubset_edgeFinset : G₁.edgeFinset ⊂ G₂.edgeFinset ↔ G₁ < G₂ := by simp #align simple_graph.edge_finset_ssubset_edge_finset SimpleGraph.edgeFinset_ssubset_edgeFinset @[gcongr] alias ⟨_, edgeFinset_mono⟩ := edgeFinset_subset_edgeFinset #align simple_graph.edge_finset_mono SimpleGraph.edgeFinset_mono alias ⟨_, edgeFinset_strict_mono⟩ := edgeFinset_ssubset_edgeFinset #align simple_graph.edge_finset_strict_mono SimpleGraph.edgeFinset_strict_mono attribute [mono] edgeFinset_mono edgeFinset_strict_mono @[simp] theorem edgeFinset_bot : (⊥ : SimpleGraph V).edgeFinset = ∅ := by simp [edgeFinset] #align simple_graph.edge_finset_bot SimpleGraph.edgeFinset_bot @[simp] theorem edgeFinset_sup [Fintype (edgeSet (G₁ ⊔ G₂))] [DecidableEq V] : (G₁ ⊔ G₂).edgeFinset = G₁.edgeFinset ∪ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sup SimpleGraph.edgeFinset_sup @[simp] theorem edgeFinset_inf [DecidableEq V] : (G₁ ⊓ G₂).edgeFinset = G₁.edgeFinset ∩ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_inf SimpleGraph.edgeFinset_inf @[simp] theorem edgeFinset_sdiff [DecidableEq V] : (G₁ \ G₂).edgeFinset = G₁.edgeFinset \ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sdiff SimpleGraph.edgeFinset_sdiff theorem edgeFinset_card : G.edgeFinset.card = Fintype.card G.edgeSet := Set.toFinset_card _ #align simple_graph.edge_finset_card SimpleGraph.edgeFinset_card @[simp] theorem edgeSet_univ_card : (univ : Finset G.edgeSet).card = G.edgeFinset.card := Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset #align simple_graph.edge_set_univ_card SimpleGraph.edgeSet_univ_card variable [Fintype V] @[simp] theorem edgeFinset_top [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset = univ.filter fun e => ¬e.IsDiag := by rw [← coe_inj]; simp /-- The complete graph on `n` vertices has `n.choose 2` edges. -/
Mathlib/Combinatorics/SimpleGraph/Finite.lean
125
127
theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset.card = (Fintype.card V).choose 2 := by
simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag]
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Logic.Relation import Mathlib.Data.Option.Basic import Mathlib.Data.Seq.Seq #align_import data.seq.wseq from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad" /-! # Partially defined possibly infinite lists This file provides a `WSeq α` type representing partially defined possibly infinite lists (referred here as weak sequences). -/ namespace Stream' open Function universe u v w /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ /-- Weak sequences. While the `Seq` structure allows for lists which may not be finite, a weak sequence also allows the computation of each element to involve an indeterminate amount of computation, including possibly an infinite loop. This is represented as a regular `Seq` interspersed with `none` elements to indicate that computation is ongoing. This model is appropriate for Haskell style lazy lists, and is closed under most interesting computation patterns on infinite lists, but conversely it is difficult to extract elements from it. -/ def WSeq (α) := Seq (Option α) #align stream.wseq Stream'.WSeq /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ namespace WSeq variable {α : Type u} {β : Type v} {γ : Type w} /-- Turn a sequence into a weak sequence -/ @[coe] def ofSeq : Seq α → WSeq α := (· <$> ·) some #align stream.wseq.of_seq Stream'.WSeq.ofSeq /-- Turn a list into a weak sequence -/ @[coe] def ofList (l : List α) : WSeq α := ofSeq l #align stream.wseq.of_list Stream'.WSeq.ofList /-- Turn a stream into a weak sequence -/ @[coe] def ofStream (l : Stream' α) : WSeq α := ofSeq l #align stream.wseq.of_stream Stream'.WSeq.ofStream instance coeSeq : Coe (Seq α) (WSeq α) := ⟨ofSeq⟩ #align stream.wseq.coe_seq Stream'.WSeq.coeSeq instance coeList : Coe (List α) (WSeq α) := ⟨ofList⟩ #align stream.wseq.coe_list Stream'.WSeq.coeList instance coeStream : Coe (Stream' α) (WSeq α) := ⟨ofStream⟩ #align stream.wseq.coe_stream Stream'.WSeq.coeStream /-- The empty weak sequence -/ def nil : WSeq α := Seq.nil #align stream.wseq.nil Stream'.WSeq.nil instance inhabited : Inhabited (WSeq α) := ⟨nil⟩ #align stream.wseq.inhabited Stream'.WSeq.inhabited /-- Prepend an element to a weak sequence -/ def cons (a : α) : WSeq α → WSeq α := Seq.cons (some a) #align stream.wseq.cons Stream'.WSeq.cons /-- Compute for one tick, without producing any elements -/ def think : WSeq α → WSeq α := Seq.cons none #align stream.wseq.think Stream'.WSeq.think /-- Destruct a weak sequence, to (eventually possibly) produce either `none` for `nil` or `some (a, s)` if an element is produced. -/ def destruct : WSeq α → Computation (Option (α × WSeq α)) := Computation.corec fun s => match Seq.destruct s with | none => Sum.inl none | some (none, s') => Sum.inr s' | some (some a, s') => Sum.inl (some (a, s')) #align stream.wseq.destruct Stream'.WSeq.destruct /-- Recursion principle for weak sequences, compare with `List.recOn`. -/ def recOn {C : WSeq α → Sort v} (s : WSeq α) (h1 : C nil) (h2 : ∀ x s, C (cons x s)) (h3 : ∀ s, C (think s)) : C s := Seq.recOn s h1 fun o => Option.recOn o h3 h2 #align stream.wseq.rec_on Stream'.WSeq.recOn /-- membership for weak sequences-/ protected def Mem (a : α) (s : WSeq α) := Seq.Mem (some a) s #align stream.wseq.mem Stream'.WSeq.Mem instance membership : Membership α (WSeq α) := ⟨WSeq.Mem⟩ #align stream.wseq.has_mem Stream'.WSeq.membership theorem not_mem_nil (a : α) : a ∉ @nil α := Seq.not_mem_nil (some a) #align stream.wseq.not_mem_nil Stream'.WSeq.not_mem_nil /-- Get the head of a weak sequence. This involves a possibly infinite computation. -/ def head (s : WSeq α) : Computation (Option α) := Computation.map (Prod.fst <$> ·) (destruct s) #align stream.wseq.head Stream'.WSeq.head /-- Encode a computation yielding a weak sequence into additional `think` constructors in a weak sequence -/ def flatten : Computation (WSeq α) → WSeq α := Seq.corec fun c => match Computation.destruct c with | Sum.inl s => Seq.omap (return ·) (Seq.destruct s) | Sum.inr c' => some (none, c') #align stream.wseq.flatten Stream'.WSeq.flatten /-- Get the tail of a weak sequence. This doesn't need a `Computation` wrapper, unlike `head`, because `flatten` allows us to hide this in the construction of the weak sequence itself. -/ def tail (s : WSeq α) : WSeq α := flatten <| (fun o => Option.recOn o nil Prod.snd) <$> destruct s #align stream.wseq.tail Stream'.WSeq.tail /-- drop the first `n` elements from `s`. -/ def drop (s : WSeq α) : ℕ → WSeq α | 0 => s | n + 1 => tail (drop s n) #align stream.wseq.drop Stream'.WSeq.drop /-- Get the nth element of `s`. -/ def get? (s : WSeq α) (n : ℕ) : Computation (Option α) := head (drop s n) #align stream.wseq.nth Stream'.WSeq.get? /-- Convert `s` to a list (if it is finite and completes in finite time). -/ def toList (s : WSeq α) : Computation (List α) := @Computation.corec (List α) (List α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => Sum.inl l.reverse | some (none, s') => Sum.inr (l, s') | some (some a, s') => Sum.inr (a::l, s')) ([], s) #align stream.wseq.to_list Stream'.WSeq.toList /-- Get the length of `s` (if it is finite and completes in finite time). -/ def length (s : WSeq α) : Computation ℕ := @Computation.corec ℕ (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s with | none => Sum.inl n | some (none, s') => Sum.inr (n, s') | some (some _, s') => Sum.inr (n + 1, s')) (0, s) #align stream.wseq.length Stream'.WSeq.length /-- A weak sequence is finite if `toList s` terminates. Equivalently, it is a finite number of `think` and `cons` applied to `nil`. -/ class IsFinite (s : WSeq α) : Prop where out : (toList s).Terminates #align stream.wseq.is_finite Stream'.WSeq.IsFinite instance toList_terminates (s : WSeq α) [h : IsFinite s] : (toList s).Terminates := h.out #align stream.wseq.to_list_terminates Stream'.WSeq.toList_terminates /-- Get the list corresponding to a finite weak sequence. -/ def get (s : WSeq α) [IsFinite s] : List α := (toList s).get #align stream.wseq.get Stream'.WSeq.get /-- A weak sequence is *productive* if it never stalls forever - there are always a finite number of `think`s between `cons` constructors. The sequence itself is allowed to be infinite though. -/ class Productive (s : WSeq α) : Prop where get?_terminates : ∀ n, (get? s n).Terminates #align stream.wseq.productive Stream'.WSeq.Productive #align stream.wseq.productive.nth_terminates Stream'.WSeq.Productive.get?_terminates theorem productive_iff (s : WSeq α) : Productive s ↔ ∀ n, (get? s n).Terminates := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align stream.wseq.productive_iff Stream'.WSeq.productive_iff instance get?_terminates (s : WSeq α) [h : Productive s] : ∀ n, (get? s n).Terminates := h.get?_terminates #align stream.wseq.nth_terminates Stream'.WSeq.get?_terminates instance head_terminates (s : WSeq α) [Productive s] : (head s).Terminates := s.get?_terminates 0 #align stream.wseq.head_terminates Stream'.WSeq.head_terminates /-- Replace the `n`th element of `s` with `a`. -/ def updateNth (s : WSeq α) (n : ℕ) (a : α) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (some a, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.update_nth Stream'.WSeq.updateNth /-- Remove the `n`th element of `s`. -/ def removeNth (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (none, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.remove_nth Stream'.WSeq.removeNth /-- Map the elements of `s` over `f`, removing any values that yield `none`. -/ def filterMap (f : α → Option β) : WSeq α → WSeq β := Seq.corec fun s => match Seq.destruct s with | none => none | some (none, s') => some (none, s') | some (some a, s') => some (f a, s') #align stream.wseq.filter_map Stream'.WSeq.filterMap /-- Select the elements of `s` that satisfy `p`. -/ def filter (p : α → Prop) [DecidablePred p] : WSeq α → WSeq α := filterMap fun a => if p a then some a else none #align stream.wseq.filter Stream'.WSeq.filter -- example of infinite list manipulations /-- Get the first element of `s` satisfying `p`. -/ def find (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation (Option α) := head <| filter p s #align stream.wseq.find Stream'.WSeq.find /-- Zip a function over two weak sequences -/ def zipWith (f : α → β → γ) (s1 : WSeq α) (s2 : WSeq β) : WSeq γ := @Seq.corec (Option γ) (WSeq α × WSeq β) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some _, _), some (none, s2') => some (none, s1, s2') | some (none, s1'), some (some _, _) => some (none, s1', s2) | some (some a1, s1'), some (some a2, s2') => some (some (f a1 a2), s1', s2') | _, _ => none) (s1, s2) #align stream.wseq.zip_with Stream'.WSeq.zipWith /-- Zip two weak sequences into a single sequence of pairs -/ def zip : WSeq α → WSeq β → WSeq (α × β) := zipWith Prod.mk #align stream.wseq.zip Stream'.WSeq.zip /-- Get the list of indexes of elements of `s` satisfying `p` -/ def findIndexes (p : α → Prop) [DecidablePred p] (s : WSeq α) : WSeq ℕ := (zip s (Stream'.nats : WSeq ℕ)).filterMap fun ⟨a, n⟩ => if p a then some n else none #align stream.wseq.find_indexes Stream'.WSeq.findIndexes /-- Get the index of the first element of `s` satisfying `p` -/ def findIndex (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation ℕ := (fun o => Option.getD o 0) <$> head (findIndexes p s) #align stream.wseq.find_index Stream'.WSeq.findIndex /-- Get the index of the first occurrence of `a` in `s` -/ def indexOf [DecidableEq α] (a : α) : WSeq α → Computation ℕ := findIndex (Eq a) #align stream.wseq.index_of Stream'.WSeq.indexOf /-- Get the indexes of occurrences of `a` in `s` -/ def indexesOf [DecidableEq α] (a : α) : WSeq α → WSeq ℕ := findIndexes (Eq a) #align stream.wseq.indexes_of Stream'.WSeq.indexesOf /-- `union s1 s2` is a weak sequence which interleaves `s1` and `s2` in some order (nondeterministically). -/ def union (s1 s2 : WSeq α) : WSeq α := @Seq.corec (Option α) (WSeq α × WSeq α) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | none, none => none | some (a1, s1'), none => some (a1, s1', nil) | none, some (a2, s2') => some (a2, nil, s2') | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some a1, s1'), some (none, s2') => some (some a1, s1', s2') | some (none, s1'), some (some a2, s2') => some (some a2, s1', s2') | some (some a1, s1'), some (some a2, s2') => some (some a1, cons a2 s1', s2')) (s1, s2) #align stream.wseq.union Stream'.WSeq.union /-- Returns `true` if `s` is `nil` and `false` if `s` has an element -/ def isEmpty (s : WSeq α) : Computation Bool := Computation.map Option.isNone <| head s #align stream.wseq.is_empty Stream'.WSeq.isEmpty /-- Calculate one step of computation -/ def compute (s : WSeq α) : WSeq α := match Seq.destruct s with | some (none, s') => s' | _ => s #align stream.wseq.compute Stream'.WSeq.compute /-- Get the first `n` elements of a weak sequence -/ def take (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match n, Seq.destruct s with | 0, _ => none | _ + 1, none => none | m + 1, some (none, s') => some (none, m + 1, s') | m + 1, some (some a, s') => some (some a, m, s')) (n, s) #align stream.wseq.take Stream'.WSeq.take /-- Split the sequence at position `n` into a finite initial segment and the weak sequence tail -/ def splitAt (s : WSeq α) (n : ℕ) : Computation (List α × WSeq α) := @Computation.corec (List α × WSeq α) (ℕ × List α × WSeq α) (fun ⟨n, l, s⟩ => match n, Seq.destruct s with | 0, _ => Sum.inl (l.reverse, s) | _ + 1, none => Sum.inl (l.reverse, s) | _ + 1, some (none, s') => Sum.inr (n, l, s') | m + 1, some (some a, s') => Sum.inr (m, a::l, s')) (n, [], s) #align stream.wseq.split_at Stream'.WSeq.splitAt /-- Returns `true` if any element of `s` satisfies `p` -/ def any (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl false | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inl true else Sum.inr s') s #align stream.wseq.any Stream'.WSeq.any /-- Returns `true` if every element of `s` satisfies `p` -/ def all (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl true | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inr s' else Sum.inl false) s #align stream.wseq.all Stream'.WSeq.all /-- Apply a function to the elements of the sequence to produce a sequence of partial results. (There is no `scanr` because this would require working from the end of the sequence, which may not exist.) -/ def scanl (f : α → β → α) (a : α) (s : WSeq β) : WSeq α := cons a <| @Seq.corec (Option α) (α × WSeq β) (fun ⟨a, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, a, s') | some (some b, s') => let a' := f a b some (some a', a', s')) (a, s) #align stream.wseq.scanl Stream'.WSeq.scanl /-- Get the weak sequence of initial segments of the input sequence -/ def inits (s : WSeq α) : WSeq (List α) := cons [] <| @Seq.corec (Option (List α)) (Batteries.DList α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, l, s') | some (some a, s') => let l' := l.push a some (some l'.toList, l', s')) (Batteries.DList.empty, s) #align stream.wseq.inits Stream'.WSeq.inits /-- Like take, but does not wait for a result. Calculates `n` steps of computation and returns the sequence computed so far -/ def collect (s : WSeq α) (n : ℕ) : List α := (Seq.take n s).filterMap id #align stream.wseq.collect Stream'.WSeq.collect /-- Append two weak sequences. As with `Seq.append`, this may not use the second sequence if the first one takes forever to compute -/ def append : WSeq α → WSeq α → WSeq α := Seq.append #align stream.wseq.append Stream'.WSeq.append /-- Map a function over a weak sequence -/ def map (f : α → β) : WSeq α → WSeq β := Seq.map (Option.map f) #align stream.wseq.map Stream'.WSeq.map /-- Flatten a sequence of weak sequences. (Note that this allows empty sequences, unlike `Seq.join`.) -/ def join (S : WSeq (WSeq α)) : WSeq α := Seq.join ((fun o : Option (WSeq α) => match o with | none => Seq1.ret none | some s => (none, s)) <$> S) #align stream.wseq.join Stream'.WSeq.join /-- Monadic bind operator for weak sequences -/ def bind (s : WSeq α) (f : α → WSeq β) : WSeq β := join (map f s) #align stream.wseq.bind Stream'.WSeq.bind /-- lift a relation to a relation over weak sequences -/ @[simp] def LiftRelO (R : α → β → Prop) (C : WSeq α → WSeq β → Prop) : Option (α × WSeq α) → Option (β × WSeq β) → Prop | none, none => True | some (a, s), some (b, t) => R a b ∧ C s t | _, _ => False #align stream.wseq.lift_rel_o Stream'.WSeq.LiftRelO theorem LiftRelO.imp {R S : α → β → Prop} {C D : WSeq α → WSeq β → Prop} (H1 : ∀ a b, R a b → S a b) (H2 : ∀ s t, C s t → D s t) : ∀ {o p}, LiftRelO R C o p → LiftRelO S D o p | none, none, _ => trivial | some (_, _), some (_, _), h => And.imp (H1 _ _) (H2 _ _) h | none, some _, h => False.elim h | some (_, _), none, h => False.elim h #align stream.wseq.lift_rel_o.imp Stream'.WSeq.LiftRelO.imp theorem LiftRelO.imp_right (R : α → β → Prop) {C D : WSeq α → WSeq β → Prop} (H : ∀ s t, C s t → D s t) {o p} : LiftRelO R C o p → LiftRelO R D o p := LiftRelO.imp (fun _ _ => id) H #align stream.wseq.lift_rel_o.imp_right Stream'.WSeq.LiftRelO.imp_right /-- Definition of bisimilarity for weak sequences-/ @[simp] def BisimO (R : WSeq α → WSeq α → Prop) : Option (α × WSeq α) → Option (α × WSeq α) → Prop := LiftRelO (· = ·) R #align stream.wseq.bisim_o Stream'.WSeq.BisimO theorem BisimO.imp {R S : WSeq α → WSeq α → Prop} (H : ∀ s t, R s t → S s t) {o p} : BisimO R o p → BisimO S o p := LiftRelO.imp_right _ H #align stream.wseq.bisim_o.imp Stream'.WSeq.BisimO.imp /-- Two weak sequences are `LiftRel R` related if they are either both empty, or they are both nonempty and the heads are `R` related and the tails are `LiftRel R` related. (This is a coinductive definition.) -/ def LiftRel (R : α → β → Prop) (s : WSeq α) (t : WSeq β) : Prop := ∃ C : WSeq α → WSeq β → Prop, C s t ∧ ∀ {s t}, C s t → Computation.LiftRel (LiftRelO R C) (destruct s) (destruct t) #align stream.wseq.lift_rel Stream'.WSeq.LiftRel /-- If two sequences are equivalent, then they have the same values and the same computational behavior (i.e. if one loops forever then so does the other), although they may differ in the number of `think`s needed to arrive at the answer. -/ def Equiv : WSeq α → WSeq α → Prop := LiftRel (· = ·) #align stream.wseq.equiv Stream'.WSeq.Equiv theorem liftRel_destruct {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t → Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) | ⟨R, h1, h2⟩ => by refine Computation.LiftRel.imp ?_ _ _ (h2 h1) apply LiftRelO.imp_right exact fun s' t' h' => ⟨R, h', @h2⟩ #align stream.wseq.lift_rel_destruct Stream'.WSeq.liftRel_destruct theorem liftRel_destruct_iff {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t ↔ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := ⟨liftRel_destruct, fun h => ⟨fun s t => LiftRel R s t ∨ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t), Or.inr h, fun {s t} h => by have h : Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := by cases' h with h h · exact liftRel_destruct h · assumption apply Computation.LiftRel.imp _ _ _ h intro a b apply LiftRelO.imp_right intro s t apply Or.inl⟩⟩ #align stream.wseq.lift_rel_destruct_iff Stream'.WSeq.liftRel_destruct_iff -- Porting note: To avoid ambiguous notation, `~` became `~ʷ`. infixl:50 " ~ʷ " => Equiv theorem destruct_congr {s t : WSeq α} : s ~ʷ t → Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct #align stream.wseq.destruct_congr Stream'.WSeq.destruct_congr theorem destruct_congr_iff {s t : WSeq α} : s ~ʷ t ↔ Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct_iff #align stream.wseq.destruct_congr_iff Stream'.WSeq.destruct_congr_iff theorem LiftRel.refl (R : α → α → Prop) (H : Reflexive R) : Reflexive (LiftRel R) := fun s => by refine ⟨(· = ·), rfl, fun {s t} (h : s = t) => ?_⟩ rw [← h] apply Computation.LiftRel.refl intro a cases' a with a · simp · cases a simp only [LiftRelO, and_true] apply H #align stream.wseq.lift_rel.refl Stream'.WSeq.LiftRel.refl theorem LiftRelO.swap (R : α → β → Prop) (C) : swap (LiftRelO R C) = LiftRelO (swap R) (swap C) := by funext x y rcases x with ⟨⟩ | ⟨hx, jx⟩ <;> rcases y with ⟨⟩ | ⟨hy, jy⟩ <;> rfl #align stream.wseq.lift_rel_o.swap Stream'.WSeq.LiftRelO.swap theorem LiftRel.swap_lem {R : α → β → Prop} {s1 s2} (h : LiftRel R s1 s2) : LiftRel (swap R) s2 s1 := by refine ⟨swap (LiftRel R), h, fun {s t} (h : LiftRel R t s) => ?_⟩ rw [← LiftRelO.swap, Computation.LiftRel.swap] apply liftRel_destruct h #align stream.wseq.lift_rel.swap_lem Stream'.WSeq.LiftRel.swap_lem theorem LiftRel.swap (R : α → β → Prop) : swap (LiftRel R) = LiftRel (swap R) := funext fun _ => funext fun _ => propext ⟨LiftRel.swap_lem, LiftRel.swap_lem⟩ #align stream.wseq.lift_rel.swap Stream'.WSeq.LiftRel.swap theorem LiftRel.symm (R : α → α → Prop) (H : Symmetric R) : Symmetric (LiftRel R) := fun s1 s2 (h : Function.swap (LiftRel R) s2 s1) => by rwa [LiftRel.swap, H.swap_eq] at h #align stream.wseq.lift_rel.symm Stream'.WSeq.LiftRel.symm theorem LiftRel.trans (R : α → α → Prop) (H : Transitive R) : Transitive (LiftRel R) := fun s t u h1 h2 => by refine ⟨fun s u => ∃ t, LiftRel R s t ∧ LiftRel R t u, ⟨t, h1, h2⟩, fun {s u} h => ?_⟩ rcases h with ⟨t, h1, h2⟩ have h1 := liftRel_destruct h1 have h2 := liftRel_destruct h2 refine Computation.liftRel_def.2 ⟨(Computation.terminates_of_liftRel h1).trans (Computation.terminates_of_liftRel h2), fun {a c} ha hc => ?_⟩ rcases h1.left ha with ⟨b, hb, t1⟩ have t2 := Computation.rel_of_liftRel h2 hb hc cases' a with a <;> cases' c with c · trivial · cases b · cases t2 · cases t1 · cases a cases' b with b · cases t1 · cases b cases t2 · cases' a with a s cases' b with b · cases t1 cases' b with b t cases' c with c u cases' t1 with ab st cases' t2 with bc tu exact ⟨H ab bc, t, st, tu⟩ #align stream.wseq.lift_rel.trans Stream'.WSeq.LiftRel.trans theorem LiftRel.equiv (R : α → α → Prop) : Equivalence R → Equivalence (LiftRel R) | ⟨refl, symm, trans⟩ => ⟨LiftRel.refl R refl, @(LiftRel.symm R @symm), @(LiftRel.trans R @trans)⟩ #align stream.wseq.lift_rel.equiv Stream'.WSeq.LiftRel.equiv @[refl] theorem Equiv.refl : ∀ s : WSeq α, s ~ʷ s := LiftRel.refl (· = ·) Eq.refl #align stream.wseq.equiv.refl Stream'.WSeq.Equiv.refl @[symm] theorem Equiv.symm : ∀ {s t : WSeq α}, s ~ʷ t → t ~ʷ s := @(LiftRel.symm (· = ·) (@Eq.symm _)) #align stream.wseq.equiv.symm Stream'.WSeq.Equiv.symm @[trans] theorem Equiv.trans : ∀ {s t u : WSeq α}, s ~ʷ t → t ~ʷ u → s ~ʷ u := @(LiftRel.trans (· = ·) (@Eq.trans _)) #align stream.wseq.equiv.trans Stream'.WSeq.Equiv.trans theorem Equiv.equivalence : Equivalence (@Equiv α) := ⟨@Equiv.refl _, @Equiv.symm _, @Equiv.trans _⟩ #align stream.wseq.equiv.equivalence Stream'.WSeq.Equiv.equivalence open Computation @[simp] theorem destruct_nil : destruct (nil : WSeq α) = Computation.pure none := Computation.destruct_eq_pure rfl #align stream.wseq.destruct_nil Stream'.WSeq.destruct_nil @[simp] theorem destruct_cons (a : α) (s) : destruct (cons a s) = Computation.pure (some (a, s)) := Computation.destruct_eq_pure <| by simp [destruct, cons, Computation.rmap] #align stream.wseq.destruct_cons Stream'.WSeq.destruct_cons @[simp] theorem destruct_think (s : WSeq α) : destruct (think s) = (destruct s).think := Computation.destruct_eq_think <| by simp [destruct, think, Computation.rmap] #align stream.wseq.destruct_think Stream'.WSeq.destruct_think @[simp] theorem seq_destruct_nil : Seq.destruct (nil : WSeq α) = none := Seq.destruct_nil #align stream.wseq.seq_destruct_nil Stream'.WSeq.seq_destruct_nil @[simp] theorem seq_destruct_cons (a : α) (s) : Seq.destruct (cons a s) = some (some a, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_cons Stream'.WSeq.seq_destruct_cons @[simp] theorem seq_destruct_think (s : WSeq α) : Seq.destruct (think s) = some (none, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_think Stream'.WSeq.seq_destruct_think @[simp] theorem head_nil : head (nil : WSeq α) = Computation.pure none := by simp [head] #align stream.wseq.head_nil Stream'.WSeq.head_nil @[simp] theorem head_cons (a : α) (s) : head (cons a s) = Computation.pure (some a) := by simp [head] #align stream.wseq.head_cons Stream'.WSeq.head_cons @[simp] theorem head_think (s : WSeq α) : head (think s) = (head s).think := by simp [head] #align stream.wseq.head_think Stream'.WSeq.head_think @[simp] theorem flatten_pure (s : WSeq α) : flatten (Computation.pure s) = s := by refine Seq.eq_of_bisim (fun s1 s2 => flatten (Computation.pure s2) = s1) ?_ rfl intro s' s h rw [← h] simp only [Seq.BisimO, flatten, Seq.omap, pure_def, Seq.corec_eq, destruct_pure] cases Seq.destruct s with | none => simp | some val => cases' val with o s' simp #align stream.wseq.flatten_ret Stream'.WSeq.flatten_pure @[simp] theorem flatten_think (c : Computation (WSeq α)) : flatten c.think = think (flatten c) := Seq.destruct_eq_cons <| by simp [flatten, think] #align stream.wseq.flatten_think Stream'.WSeq.flatten_think @[simp] theorem destruct_flatten (c : Computation (WSeq α)) : destruct (flatten c) = c >>= destruct := by refine Computation.eq_of_bisim (fun c1 c2 => c1 = c2 ∨ ∃ c, c1 = destruct (flatten c) ∧ c2 = Computation.bind c destruct) ?_ (Or.inr ⟨c, rfl, rfl⟩) intro c1 c2 h exact match c1, c2, h with | c, _, Or.inl rfl => by cases c.destruct <;> simp | _, _, Or.inr ⟨c, rfl, rfl⟩ => by induction' c using Computation.recOn with a c' <;> simp · cases (destruct a).destruct <;> simp · exact Or.inr ⟨c', rfl, rfl⟩ #align stream.wseq.destruct_flatten Stream'.WSeq.destruct_flatten theorem head_terminates_iff (s : WSeq α) : Terminates (head s) ↔ Terminates (destruct s) := terminates_map_iff _ (destruct s) #align stream.wseq.head_terminates_iff Stream'.WSeq.head_terminates_iff @[simp] theorem tail_nil : tail (nil : WSeq α) = nil := by simp [tail] #align stream.wseq.tail_nil Stream'.WSeq.tail_nil @[simp] theorem tail_cons (a : α) (s) : tail (cons a s) = s := by simp [tail] #align stream.wseq.tail_cons Stream'.WSeq.tail_cons @[simp] theorem tail_think (s : WSeq α) : tail (think s) = (tail s).think := by simp [tail] #align stream.wseq.tail_think Stream'.WSeq.tail_think @[simp] theorem dropn_nil (n) : drop (nil : WSeq α) n = nil := by induction n <;> simp [*, drop] #align stream.wseq.dropn_nil Stream'.WSeq.dropn_nil @[simp] theorem dropn_cons (a : α) (s) (n) : drop (cons a s) (n + 1) = drop s n := by induction n with | zero => simp [drop] | succ n n_ih => -- porting note (#10745): was `simp [*, drop]`. simp [drop, ← n_ih] #align stream.wseq.dropn_cons Stream'.WSeq.dropn_cons @[simp] theorem dropn_think (s : WSeq α) (n) : drop (think s) n = (drop s n).think := by induction n <;> simp [*, drop] #align stream.wseq.dropn_think Stream'.WSeq.dropn_think theorem dropn_add (s : WSeq α) (m) : ∀ n, drop s (m + n) = drop (drop s m) n | 0 => rfl | n + 1 => congr_arg tail (dropn_add s m n) #align stream.wseq.dropn_add Stream'.WSeq.dropn_add theorem dropn_tail (s : WSeq α) (n) : drop (tail s) n = drop s (n + 1) := by rw [Nat.add_comm] symm apply dropn_add #align stream.wseq.dropn_tail Stream'.WSeq.dropn_tail theorem get?_add (s : WSeq α) (m n) : get? s (m + n) = get? (drop s m) n := congr_arg head (dropn_add _ _ _) #align stream.wseq.nth_add Stream'.WSeq.get?_add theorem get?_tail (s : WSeq α) (n) : get? (tail s) n = get? s (n + 1) := congr_arg head (dropn_tail _ _) #align stream.wseq.nth_tail Stream'.WSeq.get?_tail @[simp] theorem join_nil : join nil = (nil : WSeq α) := Seq.join_nil #align stream.wseq.join_nil Stream'.WSeq.join_nil @[simp] theorem join_think (S : WSeq (WSeq α)) : join (think S) = think (join S) := by simp only [join, think] dsimp only [(· <$> ·)] simp [join, Seq1.ret] #align stream.wseq.join_think Stream'.WSeq.join_think @[simp] theorem join_cons (s : WSeq α) (S) : join (cons s S) = think (append s (join S)) := by simp only [join, think] dsimp only [(· <$> ·)] simp [join, cons, append] #align stream.wseq.join_cons Stream'.WSeq.join_cons @[simp] theorem nil_append (s : WSeq α) : append nil s = s := Seq.nil_append _ #align stream.wseq.nil_append Stream'.WSeq.nil_append @[simp] theorem cons_append (a : α) (s t) : append (cons a s) t = cons a (append s t) := Seq.cons_append _ _ _ #align stream.wseq.cons_append Stream'.WSeq.cons_append @[simp] theorem think_append (s t : WSeq α) : append (think s) t = think (append s t) := Seq.cons_append _ _ _ #align stream.wseq.think_append Stream'.WSeq.think_append @[simp] theorem append_nil (s : WSeq α) : append s nil = s := Seq.append_nil _ #align stream.wseq.append_nil Stream'.WSeq.append_nil @[simp] theorem append_assoc (s t u : WSeq α) : append (append s t) u = append s (append t u) := Seq.append_assoc _ _ _ #align stream.wseq.append_assoc Stream'.WSeq.append_assoc /-- auxiliary definition of tail over weak sequences-/ @[simp] def tail.aux : Option (α × WSeq α) → Computation (Option (α × WSeq α)) | none => Computation.pure none | some (_, s) => destruct s #align stream.wseq.tail.aux Stream'.WSeq.tail.aux theorem destruct_tail (s : WSeq α) : destruct (tail s) = destruct s >>= tail.aux := by simp only [tail, destruct_flatten, tail.aux]; rw [← bind_pure_comp, LawfulMonad.bind_assoc] apply congr_arg; ext1 (_ | ⟨a, s⟩) <;> apply (@pure_bind Computation _ _ _ _ _ _).trans _ <;> simp #align stream.wseq.destruct_tail Stream'.WSeq.destruct_tail /-- auxiliary definition of drop over weak sequences-/ @[simp] def drop.aux : ℕ → Option (α × WSeq α) → Computation (Option (α × WSeq α)) | 0 => Computation.pure | n + 1 => fun a => tail.aux a >>= drop.aux n #align stream.wseq.drop.aux Stream'.WSeq.drop.aux theorem drop.aux_none : ∀ n, @drop.aux α n none = Computation.pure none | 0 => rfl | n + 1 => show Computation.bind (Computation.pure none) (drop.aux n) = Computation.pure none by rw [ret_bind, drop.aux_none n] #align stream.wseq.drop.aux_none Stream'.WSeq.drop.aux_none theorem destruct_dropn : ∀ (s : WSeq α) (n), destruct (drop s n) = destruct s >>= drop.aux n | s, 0 => (bind_pure' _).symm | s, n + 1 => by rw [← dropn_tail, destruct_dropn _ n, destruct_tail, LawfulMonad.bind_assoc] rfl #align stream.wseq.destruct_dropn Stream'.WSeq.destruct_dropn theorem head_terminates_of_head_tail_terminates (s : WSeq α) [T : Terminates (head (tail s))] : Terminates (head s) := (head_terminates_iff _).2 <| by rcases (head_terminates_iff _).1 T with ⟨⟨a, h⟩⟩ simp? [tail] at h says simp only [tail, destruct_flatten] at h rcases exists_of_mem_bind h with ⟨s', h1, _⟩ unfold Functor.map at h1 exact let ⟨t, h3, _⟩ := Computation.exists_of_mem_map h1 Computation.terminates_of_mem h3 #align stream.wseq.head_terminates_of_head_tail_terminates Stream'.WSeq.head_terminates_of_head_tail_terminates theorem destruct_some_of_destruct_tail_some {s : WSeq α} {a} (h : some a ∈ destruct (tail s)) : ∃ a', some a' ∈ destruct s := by unfold tail Functor.map at h; simp only [destruct_flatten] at h rcases exists_of_mem_bind h with ⟨t, tm, td⟩; clear h rcases Computation.exists_of_mem_map tm with ⟨t', ht', ht2⟩; clear tm cases' t' with t' <;> rw [← ht2] at td <;> simp only [destruct_nil] at td · have := mem_unique td (ret_mem _) contradiction · exact ⟨_, ht'⟩ #align stream.wseq.destruct_some_of_destruct_tail_some Stream'.WSeq.destruct_some_of_destruct_tail_some theorem head_some_of_head_tail_some {s : WSeq α} {a} (h : some a ∈ head (tail s)) : ∃ a', some a' ∈ head s := by unfold head at h rcases Computation.exists_of_mem_map h with ⟨o, md, e⟩; clear h cases' o with o <;> [injection e; injection e with h']; clear h' cases' destruct_some_of_destruct_tail_some md with a am exact ⟨_, Computation.mem_map (@Prod.fst α (WSeq α) <$> ·) am⟩ #align stream.wseq.head_some_of_head_tail_some Stream'.WSeq.head_some_of_head_tail_some theorem head_some_of_get?_some {s : WSeq α} {a n} (h : some a ∈ get? s n) : ∃ a', some a' ∈ head s := by induction n generalizing a with | zero => exact ⟨_, h⟩ | succ n IH => let ⟨a', h'⟩ := head_some_of_head_tail_some h exact IH h' #align stream.wseq.head_some_of_nth_some Stream'.WSeq.head_some_of_get?_some instance productive_tail (s : WSeq α) [Productive s] : Productive (tail s) := ⟨fun n => by rw [get?_tail]; infer_instance⟩ #align stream.wseq.productive_tail Stream'.WSeq.productive_tail instance productive_dropn (s : WSeq α) [Productive s] (n) : Productive (drop s n) := ⟨fun m => by rw [← get?_add]; infer_instance⟩ #align stream.wseq.productive_dropn Stream'.WSeq.productive_dropn /-- Given a productive weak sequence, we can collapse all the `think`s to produce a sequence. -/ def toSeq (s : WSeq α) [Productive s] : Seq α := ⟨fun n => (get? s n).get, fun {n} h => by cases e : Computation.get (get? s (n + 1)) · assumption have := Computation.mem_of_get_eq _ e simp? [get?] at this h says simp only [get?] at this h cases' head_some_of_head_tail_some this with a' h' have := mem_unique h' (@Computation.mem_of_get_eq _ _ _ _ h) contradiction⟩ #align stream.wseq.to_seq Stream'.WSeq.toSeq
Mathlib/Data/Seq/WSeq.lean
893
896
theorem get?_terminates_le {s : WSeq α} {m n} (h : m ≤ n) : Terminates (get? s n) → Terminates (get? s m) := by
induction' h with m' _ IH exacts [id, fun T => IH (@head_terminates_of_head_tail_terminates _ _ T)]
/- Copyright (c) 2022 Tian Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tian Chen, Mantas Bakšys -/ import Mathlib.Algebra.GeomSum import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Int import Mathlib.NumberTheory.Padics.PadicVal import Mathlib.RingTheory.Ideal.Quotient #align_import number_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Multiplicity in Number Theory This file contains results in number theory relating to multiplicity. ## Main statements * `multiplicity.Int.pow_sub_pow` is the lifting the exponent lemma for odd primes. We also prove several variations of the lemma. ## References * [Wikipedia, *Lifting-the-exponent lemma*] (https://en.wikipedia.org/wiki/Lifting-the-exponent_lemma) -/ open Ideal Ideal.Quotient Finset variable {R : Type*} {n : ℕ} section CommRing variable [CommRing R] {a b x y : R} theorem dvd_geom_sum₂_iff_of_dvd_sub {x y p : R} (h : p ∣ x - y) : (p ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) ↔ p ∣ n * y ^ (n - 1) := by rw [← mem_span_singleton, ← Ideal.Quotient.eq] at h simp only [← mem_span_singleton, ← eq_zero_iff_mem, RingHom.map_geom_sum₂, h, geom_sum₂_self, _root_.map_mul, map_pow, map_natCast] #align dvd_geom_sum₂_iff_of_dvd_sub dvd_geom_sum₂_iff_of_dvd_sub theorem dvd_geom_sum₂_iff_of_dvd_sub' {x y p : R} (h : p ∣ x - y) : (p ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) ↔ p ∣ n * x ^ (n - 1) := by rw [geom_sum₂_comm, dvd_geom_sum₂_iff_of_dvd_sub]; simpa using h.neg_right #align dvd_geom_sum₂_iff_of_dvd_sub' dvd_geom_sum₂_iff_of_dvd_sub' theorem dvd_geom_sum₂_self {x y : R} (h : ↑n ∣ x - y) : ↑n ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := (dvd_geom_sum₂_iff_of_dvd_sub h).mpr (dvd_mul_right _ _) #align dvd_geom_sum₂_self dvd_geom_sum₂_self
Mathlib/NumberTheory/Multiplicity.lean
56
71
theorem sq_dvd_add_pow_sub_sub (p x : R) (n : ℕ) : p ^ 2 ∣ (x + p) ^ n - x ^ (n - 1) * p * n - x ^ n := by
cases' n with n n · simp only [pow_zero, Nat.cast_zero, sub_zero, sub_self, dvd_zero, Nat.zero_eq, mul_zero] · simp only [Nat.succ_sub_succ_eq_sub, tsub_zero, Nat.cast_succ, add_pow, Finset.sum_range_succ, Nat.choose_self, Nat.succ_sub _, tsub_self, pow_one, Nat.choose_succ_self_right, pow_zero, mul_one, Nat.cast_zero, zero_add, Nat.succ_eq_add_one, add_tsub_cancel_left] suffices p ^ 2 ∣ ∑ i ∈ range n, x ^ i * p ^ (n + 1 - i) * ↑((n + 1).choose i) by convert this; abel apply Finset.dvd_sum intro y hy calc p ^ 2 ∣ p ^ (n + 1 - y) := pow_dvd_pow p (le_tsub_of_add_le_left (by linarith [Finset.mem_range.mp hy])) _ ∣ x ^ y * p ^ (n + 1 - y) * ↑((n + 1).choose y) := dvd_mul_of_dvd_left (dvd_mul_left _ _) _
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Wrenna Robson -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.LinearAlgebra.Vandermonde import Mathlib.RingTheory.Polynomial.Basic #align_import linear_algebra.lagrange from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Lagrange interpolation ## Main definitions * In everything that follows, `s : Finset ι` is a finite set of indexes, with `v : ι → F` an indexing of the field over some type. We call the image of v on s the interpolation nodes, though strictly unique nodes are only defined when v is injective on s. * `Lagrange.basisDivisor x y`, with `x y : F`. These are the normalised irreducible factors of the Lagrange basis polynomials. They evaluate to `1` at `x` and `0` at `y` when `x` and `y` are distinct. * `Lagrange.basis v i` with `i : ι`: the Lagrange basis polynomial that evaluates to `1` at `v i` and `0` at `v j` for `i ≠ j`. * `Lagrange.interpolate v r` where `r : ι → F` is a function from the fintype to the field: the Lagrange interpolant that evaluates to `r i` at `x i` for all `i : ι`. The `r i` are the _values_ associated with the _nodes_`x i`. -/ open Polynomial section PolynomialDetermination namespace Polynomial variable {R : Type*} [CommRing R] [IsDomain R] {f g : R[X]} section Finset open Function Fintype variable (s : Finset R) theorem eq_zero_of_degree_lt_of_eval_finset_eq_zero (degree_f_lt : f.degree < s.card) (eval_f : ∀ x ∈ s, f.eval x = 0) : f = 0 := by rw [← mem_degreeLT] at degree_f_lt simp_rw [eval_eq_sum_degreeLTEquiv degree_f_lt] at eval_f rw [← degreeLTEquiv_eq_zero_iff_eq_zero degree_f_lt] exact Matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero (Injective.comp (Embedding.subtype _).inj' (equivFinOfCardEq (card_coe _)).symm.injective) fun _ => eval_f _ (Finset.coe_mem _) #align polynomial.eq_zero_of_degree_lt_of_eval_finset_eq_zero Polynomial.eq_zero_of_degree_lt_of_eval_finset_eq_zero theorem eq_of_degree_sub_lt_of_eval_finset_eq (degree_fg_lt : (f - g).degree < s.card) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg #align polynomial.eq_of_degree_sub_lt_of_eval_finset_eq Polynomial.eq_of_degree_sub_lt_of_eval_finset_eq theorem eq_of_degrees_lt_of_eval_finset_eq (degree_f_lt : f.degree < s.card) (degree_g_lt : g.degree < s.card) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← mem_degreeLT] at degree_f_lt degree_g_lt refine eq_of_degree_sub_lt_of_eval_finset_eq _ ?_ eval_fg rw [← mem_degreeLT]; exact Submodule.sub_mem _ degree_f_lt degree_g_lt #align polynomial.eq_of_degrees_lt_of_eval_finset_eq Polynomial.eq_of_degrees_lt_of_eval_finset_eq /-- Two polynomials, with the same degree and leading coefficient, which have the same evaluation on a set of distinct values with cardinality equal to the degree, are equal. -/ theorem eq_of_degree_le_of_eval_finset_eq (h_deg_le : f.degree ≤ s.card) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_finset_eq s (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Finset section Indexed open Finset variable {ι : Type*} {v : ι → R} (s : Finset ι) theorem eq_zero_of_degree_lt_of_eval_index_eq_zero (hvs : Set.InjOn v s) (degree_f_lt : f.degree < s.card) (eval_f : ∀ i ∈ s, f.eval (v i) = 0) : f = 0 := by classical rw [← card_image_of_injOn hvs] at degree_f_lt refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_f_lt ?_ intro x hx rcases mem_image.mp hx with ⟨_, hj, rfl⟩ exact eval_f _ hj #align polynomial.eq_zero_of_degree_lt_of_eval_index_eq_zero Polynomial.eq_zero_of_degree_lt_of_eval_index_eq_zero theorem eq_of_degree_sub_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_fg_lt : (f - g).degree < s.card) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_index_eq_zero _ hvs degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg #align polynomial.eq_of_degree_sub_lt_of_eval_index_eq Polynomial.eq_of_degree_sub_lt_of_eval_index_eq theorem eq_of_degrees_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_f_lt : f.degree < s.card) (degree_g_lt : g.degree < s.card) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by refine eq_of_degree_sub_lt_of_eval_index_eq _ hvs ?_ eval_fg rw [← mem_degreeLT] at degree_f_lt degree_g_lt ⊢ exact Submodule.sub_mem _ degree_f_lt degree_g_lt #align polynomial.eq_of_degrees_lt_of_eval_index_eq Polynomial.eq_of_degrees_lt_of_eval_index_eq theorem eq_of_degree_le_of_eval_index_eq (hvs : Set.InjOn v s) (h_deg_le : f.degree ≤ s.card) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_index_eq s hvs (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Indexed end Polynomial end PolynomialDetermination noncomputable section namespace Lagrange open Polynomial section BasisDivisor variable {F : Type*} [Field F] variable {x y : F} /-- `basisDivisor x y` is the unique linear or constant polynomial such that when evaluated at `x` it gives `1` and `y` it gives `0` (where when `x = y` it is identically `0`). Such polynomials are the building blocks for the Lagrange interpolants. -/ def basisDivisor (x y : F) : F[X] := C (x - y)⁻¹ * (X - C y) #align lagrange.basis_divisor Lagrange.basisDivisor theorem basisDivisor_self : basisDivisor x x = 0 := by simp only [basisDivisor, sub_self, inv_zero, map_zero, zero_mul] #align lagrange.basis_divisor_self Lagrange.basisDivisor_self theorem basisDivisor_inj (hxy : basisDivisor x y = 0) : x = y := by simp_rw [basisDivisor, mul_eq_zero, X_sub_C_ne_zero, or_false_iff, C_eq_zero, inv_eq_zero, sub_eq_zero] at hxy exact hxy #align lagrange.basis_divisor_inj Lagrange.basisDivisor_inj @[simp] theorem basisDivisor_eq_zero_iff : basisDivisor x y = 0 ↔ x = y := ⟨basisDivisor_inj, fun H => H ▸ basisDivisor_self⟩ #align lagrange.basis_divisor_eq_zero_iff Lagrange.basisDivisor_eq_zero_iff theorem basisDivisor_ne_zero_iff : basisDivisor x y ≠ 0 ↔ x ≠ y := by rw [Ne, basisDivisor_eq_zero_iff] #align lagrange.basis_divisor_ne_zero_iff Lagrange.basisDivisor_ne_zero_iff theorem degree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).degree = 1 := by rw [basisDivisor, degree_mul, degree_X_sub_C, degree_C, zero_add] exact inv_ne_zero (sub_ne_zero_of_ne hxy) #align lagrange.degree_basis_divisor_of_ne Lagrange.degree_basisDivisor_of_ne @[simp] theorem degree_basisDivisor_self : (basisDivisor x x).degree = ⊥ := by rw [basisDivisor_self, degree_zero] #align lagrange.degree_basis_divisor_self Lagrange.degree_basisDivisor_self theorem natDegree_basisDivisor_self : (basisDivisor x x).natDegree = 0 := by rw [basisDivisor_self, natDegree_zero] #align lagrange.nat_degree_basis_divisor_self Lagrange.natDegree_basisDivisor_self theorem natDegree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).natDegree = 1 := natDegree_eq_of_degree_eq_some (degree_basisDivisor_of_ne hxy) #align lagrange.nat_degree_basis_divisor_of_ne Lagrange.natDegree_basisDivisor_of_ne @[simp] theorem eval_basisDivisor_right : eval y (basisDivisor x y) = 0 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X, sub_self, mul_zero] #align lagrange.eval_basis_divisor_right Lagrange.eval_basisDivisor_right theorem eval_basisDivisor_left_of_ne (hxy : x ≠ y) : eval x (basisDivisor x y) = 1 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X] exact inv_mul_cancel (sub_ne_zero_of_ne hxy) #align lagrange.eval_basis_divisor_left_of_ne Lagrange.eval_basisDivisor_left_of_ne end BasisDivisor section Basis variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s : Finset ι} {v : ι → F} {i j : ι} open Finset /-- Lagrange basis polynomials indexed by `s : Finset ι`, defined at nodes `v i` for a map `v : ι → F`. For `i, j ∈ s`, `basis s v i` evaluates to 0 at `v j` for `i ≠ j`. When `v` is injective on `s`, `basis s v i` evaluates to 1 at `v i`. -/ protected def basis (s : Finset ι) (v : ι → F) (i : ι) : F[X] := ∏ j ∈ s.erase i, basisDivisor (v i) (v j) #align lagrange.basis Lagrange.basis @[simp] theorem basis_empty : Lagrange.basis ∅ v i = 1 := rfl #align lagrange.basis_empty Lagrange.basis_empty @[simp] theorem basis_singleton (i : ι) : Lagrange.basis {i} v i = 1 := by rw [Lagrange.basis, erase_singleton, prod_empty] #align lagrange.basis_singleton Lagrange.basis_singleton @[simp] theorem basis_pair_left (hij : i ≠ j) : Lagrange.basis {i, j} v i = basisDivisor (v i) (v j) := by simp only [Lagrange.basis, hij, erase_insert_eq_erase, erase_eq_of_not_mem, mem_singleton, not_false_iff, prod_singleton] #align lagrange.basis_pair_left Lagrange.basis_pair_left @[simp] theorem basis_pair_right (hij : i ≠ j) : Lagrange.basis {i, j} v j = basisDivisor (v j) (v i) := by rw [pair_comm] exact basis_pair_left hij.symm #align lagrange.basis_pair_right Lagrange.basis_pair_right theorem basis_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : Lagrange.basis s v i ≠ 0 := by simp_rw [Lagrange.basis, prod_ne_zero_iff, Ne, mem_erase] rintro j ⟨hij, hj⟩ rw [basisDivisor_eq_zero_iff, hvs.eq_iff hi hj] exact hij.symm #align lagrange.basis_ne_zero Lagrange.basis_ne_zero @[simp]
Mathlib/LinearAlgebra/Lagrange.lean
246
252
theorem eval_basis_self (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).eval (v i) = 1 := by
rw [Lagrange.basis, eval_prod] refine prod_eq_one fun j H => ?_ rw [eval_basisDivisor_left_of_ne] rcases mem_erase.mp H with ⟨hij, hj⟩ exact mt (hvs hi hj) hij.symm
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Nat import Mathlib.Algebra.Order.Sub.Canonical import Mathlib.Data.List.Perm import Mathlib.Data.Set.List import Mathlib.Init.Quot import Mathlib.Order.Hom.Basic #align_import data.multiset.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Multisets These are implemented as the quotient of a list by permutations. ## Notation We define the global infix notation `::ₘ` for `Multiset.cons`. -/ universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} /-- `Multiset α` is the quotient of `List α` by list permutation. The result is a type of finite sets with duplicates allowed. -/ def Multiset.{u} (α : Type u) : Type u := Quotient (List.isSetoid α) #align multiset Multiset namespace Multiset -- Porting note: new /-- The quotient map from `List α` to `Multiset α`. -/ @[coe] def ofList : List α → Multiset α := Quot.mk _ instance : Coe (List α) (Multiset α) := ⟨ofList⟩ @[simp] theorem quot_mk_to_coe (l : List α) : @Eq (Multiset α) ⟦l⟧ l := rfl #align multiset.quot_mk_to_coe Multiset.quot_mk_to_coe @[simp] theorem quot_mk_to_coe' (l : List α) : @Eq (Multiset α) (Quot.mk (· ≈ ·) l) l := rfl #align multiset.quot_mk_to_coe' Multiset.quot_mk_to_coe' @[simp] theorem quot_mk_to_coe'' (l : List α) : @Eq (Multiset α) (Quot.mk Setoid.r l) l := rfl #align multiset.quot_mk_to_coe'' Multiset.quot_mk_to_coe'' @[simp] theorem coe_eq_coe {l₁ l₂ : List α} : (l₁ : Multiset α) = l₂ ↔ l₁ ~ l₂ := Quotient.eq #align multiset.coe_eq_coe Multiset.coe_eq_coe -- Porting note: new instance; -- Porting note (#11215): TODO: move to better place instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ ≈ l₂) := inferInstanceAs (Decidable (l₁ ~ l₂)) -- Porting note: `Quotient.recOnSubsingleton₂ s₁ s₂` was in parens which broke elaboration instance decidableEq [DecidableEq α] : DecidableEq (Multiset α) | s₁, s₂ => Quotient.recOnSubsingleton₂ s₁ s₂ fun _ _ => decidable_of_iff' _ Quotient.eq #align multiset.has_decidable_eq Multiset.decidableEq /-- defines a size for a multiset by referring to the size of the underlying list -/ protected def sizeOf [SizeOf α] (s : Multiset α) : ℕ := (Quot.liftOn s SizeOf.sizeOf) fun _ _ => Perm.sizeOf_eq_sizeOf #align multiset.sizeof Multiset.sizeOf instance [SizeOf α] : SizeOf (Multiset α) := ⟨Multiset.sizeOf⟩ /-! ### Empty multiset -/ /-- `0 : Multiset α` is the empty set -/ protected def zero : Multiset α := @nil α #align multiset.zero Multiset.zero instance : Zero (Multiset α) := ⟨Multiset.zero⟩ instance : EmptyCollection (Multiset α) := ⟨0⟩ instance inhabitedMultiset : Inhabited (Multiset α) := ⟨0⟩ #align multiset.inhabited_multiset Multiset.inhabitedMultiset instance [IsEmpty α] : Unique (Multiset α) where default := 0 uniq := by rintro ⟨_ | ⟨a, l⟩⟩; exacts [rfl, isEmptyElim a] @[simp] theorem coe_nil : (@nil α : Multiset α) = 0 := rfl #align multiset.coe_nil Multiset.coe_nil @[simp] theorem empty_eq_zero : (∅ : Multiset α) = 0 := rfl #align multiset.empty_eq_zero Multiset.empty_eq_zero @[simp] theorem coe_eq_zero (l : List α) : (l : Multiset α) = 0 ↔ l = [] := Iff.trans coe_eq_coe perm_nil #align multiset.coe_eq_zero Multiset.coe_eq_zero theorem coe_eq_zero_iff_isEmpty (l : List α) : (l : Multiset α) = 0 ↔ l.isEmpty := Iff.trans (coe_eq_zero l) isEmpty_iff_eq_nil.symm #align multiset.coe_eq_zero_iff_empty Multiset.coe_eq_zero_iff_isEmpty /-! ### `Multiset.cons` -/ /-- `cons a s` is the multiset which contains `s` plus one more instance of `a`. -/ def cons (a : α) (s : Multiset α) : Multiset α := Quot.liftOn s (fun l => (a :: l : Multiset α)) fun _ _ p => Quot.sound (p.cons a) #align multiset.cons Multiset.cons @[inherit_doc Multiset.cons] infixr:67 " ::ₘ " => Multiset.cons instance : Insert α (Multiset α) := ⟨cons⟩ @[simp] theorem insert_eq_cons (a : α) (s : Multiset α) : insert a s = a ::ₘ s := rfl #align multiset.insert_eq_cons Multiset.insert_eq_cons @[simp] theorem cons_coe (a : α) (l : List α) : (a ::ₘ l : Multiset α) = (a :: l : List α) := rfl #align multiset.cons_coe Multiset.cons_coe @[simp] theorem cons_inj_left {a b : α} (s : Multiset α) : a ::ₘ s = b ::ₘ s ↔ a = b := ⟨Quot.inductionOn s fun l e => have : [a] ++ l ~ [b] ++ l := Quotient.exact e singleton_perm_singleton.1 <| (perm_append_right_iff _).1 this, congr_arg (· ::ₘ _)⟩ #align multiset.cons_inj_left Multiset.cons_inj_left @[simp] theorem cons_inj_right (a : α) : ∀ {s t : Multiset α}, a ::ₘ s = a ::ₘ t ↔ s = t := by rintro ⟨l₁⟩ ⟨l₂⟩; simp #align multiset.cons_inj_right Multiset.cons_inj_right @[elab_as_elim] protected theorem induction {p : Multiset α → Prop} (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : ∀ s, p s := by rintro ⟨l⟩; induction' l with _ _ ih <;> [exact empty; exact cons _ _ ih] #align multiset.induction Multiset.induction @[elab_as_elim] protected theorem induction_on {p : Multiset α → Prop} (s : Multiset α) (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : p s := Multiset.induction empty cons s #align multiset.induction_on Multiset.induction_on theorem cons_swap (a b : α) (s : Multiset α) : a ::ₘ b ::ₘ s = b ::ₘ a ::ₘ s := Quot.inductionOn s fun _ => Quotient.sound <| Perm.swap _ _ _ #align multiset.cons_swap Multiset.cons_swap section Rec variable {C : Multiset α → Sort*} /-- Dependent recursor on multisets. TODO: should be @[recursor 6], but then the definition of `Multiset.pi` fails with a stack overflow in `whnf`. -/ protected def rec (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) (m : Multiset α) : C m := Quotient.hrecOn m (@List.rec α (fun l => C ⟦l⟧) C_0 fun a l b => C_cons a ⟦l⟧ b) fun l l' h => h.rec_heq (fun hl _ ↦ by congr 1; exact Quot.sound hl) (C_cons_heq _ _ ⟦_⟧ _) #align multiset.rec Multiset.rec /-- Companion to `Multiset.rec` with more convenient argument order. -/ @[elab_as_elim] protected def recOn (m : Multiset α) (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) : C m := Multiset.rec C_0 C_cons C_cons_heq m #align multiset.rec_on Multiset.recOn variable {C_0 : C 0} {C_cons : ∀ a m, C m → C (a ::ₘ m)} {C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))} @[simp] theorem recOn_0 : @Multiset.recOn α C (0 : Multiset α) C_0 C_cons C_cons_heq = C_0 := rfl #align multiset.rec_on_0 Multiset.recOn_0 @[simp] theorem recOn_cons (a : α) (m : Multiset α) : (a ::ₘ m).recOn C_0 C_cons C_cons_heq = C_cons a m (m.recOn C_0 C_cons C_cons_heq) := Quotient.inductionOn m fun _ => rfl #align multiset.rec_on_cons Multiset.recOn_cons end Rec section Mem /-- `a ∈ s` means that `a` has nonzero multiplicity in `s`. -/ def Mem (a : α) (s : Multiset α) : Prop := Quot.liftOn s (fun l => a ∈ l) fun l₁ l₂ (e : l₁ ~ l₂) => propext <| e.mem_iff #align multiset.mem Multiset.Mem instance : Membership α (Multiset α) := ⟨Mem⟩ @[simp] theorem mem_coe {a : α} {l : List α} : a ∈ (l : Multiset α) ↔ a ∈ l := Iff.rfl #align multiset.mem_coe Multiset.mem_coe instance decidableMem [DecidableEq α] (a : α) (s : Multiset α) : Decidable (a ∈ s) := Quot.recOnSubsingleton' s fun l ↦ inferInstanceAs (Decidable (a ∈ l)) #align multiset.decidable_mem Multiset.decidableMem @[simp] theorem mem_cons {a b : α} {s : Multiset α} : a ∈ b ::ₘ s ↔ a = b ∨ a ∈ s := Quot.inductionOn s fun _ => List.mem_cons #align multiset.mem_cons Multiset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Multiset α} (h : a ∈ s) : a ∈ b ::ₘ s := mem_cons.2 <| Or.inr h #align multiset.mem_cons_of_mem Multiset.mem_cons_of_mem -- @[simp] -- Porting note (#10618): simp can prove this theorem mem_cons_self (a : α) (s : Multiset α) : a ∈ a ::ₘ s := mem_cons.2 (Or.inl rfl) #align multiset.mem_cons_self Multiset.mem_cons_self theorem forall_mem_cons {p : α → Prop} {a : α} {s : Multiset α} : (∀ x ∈ a ::ₘ s, p x) ↔ p a ∧ ∀ x ∈ s, p x := Quotient.inductionOn' s fun _ => List.forall_mem_cons #align multiset.forall_mem_cons Multiset.forall_mem_cons theorem exists_cons_of_mem {s : Multiset α} {a : α} : a ∈ s → ∃ t, s = a ::ₘ t := Quot.inductionOn s fun l (h : a ∈ l) => let ⟨l₁, l₂, e⟩ := append_of_mem h e.symm ▸ ⟨(l₁ ++ l₂ : List α), Quot.sound perm_middle⟩ #align multiset.exists_cons_of_mem Multiset.exists_cons_of_mem @[simp] theorem not_mem_zero (a : α) : a ∉ (0 : Multiset α) := List.not_mem_nil _ #align multiset.not_mem_zero Multiset.not_mem_zero theorem eq_zero_of_forall_not_mem {s : Multiset α} : (∀ x, x ∉ s) → s = 0 := Quot.inductionOn s fun l H => by rw [eq_nil_iff_forall_not_mem.mpr H]; rfl #align multiset.eq_zero_of_forall_not_mem Multiset.eq_zero_of_forall_not_mem theorem eq_zero_iff_forall_not_mem {s : Multiset α} : s = 0 ↔ ∀ a, a ∉ s := ⟨fun h => h.symm ▸ fun _ => not_mem_zero _, eq_zero_of_forall_not_mem⟩ #align multiset.eq_zero_iff_forall_not_mem Multiset.eq_zero_iff_forall_not_mem theorem exists_mem_of_ne_zero {s : Multiset α} : s ≠ 0 → ∃ a : α, a ∈ s := Quot.inductionOn s fun l hl => match l, hl with | [], h => False.elim <| h rfl | a :: l, _ => ⟨a, by simp⟩ #align multiset.exists_mem_of_ne_zero Multiset.exists_mem_of_ne_zero theorem empty_or_exists_mem (s : Multiset α) : s = 0 ∨ ∃ a, a ∈ s := or_iff_not_imp_left.mpr Multiset.exists_mem_of_ne_zero #align multiset.empty_or_exists_mem Multiset.empty_or_exists_mem @[simp] theorem zero_ne_cons {a : α} {m : Multiset α} : 0 ≠ a ::ₘ m := fun h => have : a ∈ (0 : Multiset α) := h.symm ▸ mem_cons_self _ _ not_mem_zero _ this #align multiset.zero_ne_cons Multiset.zero_ne_cons @[simp] theorem cons_ne_zero {a : α} {m : Multiset α} : a ::ₘ m ≠ 0 := zero_ne_cons.symm #align multiset.cons_ne_zero Multiset.cons_ne_zero theorem cons_eq_cons {a b : α} {as bs : Multiset α} : a ::ₘ as = b ::ₘ bs ↔ a = b ∧ as = bs ∨ a ≠ b ∧ ∃ cs, as = b ::ₘ cs ∧ bs = a ::ₘ cs := by haveI : DecidableEq α := Classical.decEq α constructor · intro eq by_cases h : a = b · subst h simp_all · have : a ∈ b ::ₘ bs := eq ▸ mem_cons_self _ _ have : a ∈ bs := by simpa [h] rcases exists_cons_of_mem this with ⟨cs, hcs⟩ simp only [h, hcs, false_and, ne_eq, not_false_eq_true, cons_inj_right, exists_eq_right', true_and, false_or] have : a ::ₘ as = b ::ₘ a ::ₘ cs := by simp [eq, hcs] have : a ::ₘ as = a ::ₘ b ::ₘ cs := by rwa [cons_swap] simpa using this · intro h rcases h with (⟨eq₁, eq₂⟩ | ⟨_, cs, eq₁, eq₂⟩) · simp [*] · simp [*, cons_swap a b] #align multiset.cons_eq_cons Multiset.cons_eq_cons end Mem /-! ### Singleton -/ instance : Singleton α (Multiset α) := ⟨fun a => a ::ₘ 0⟩ instance : LawfulSingleton α (Multiset α) := ⟨fun _ => rfl⟩ @[simp] theorem cons_zero (a : α) : a ::ₘ 0 = {a} := rfl #align multiset.cons_zero Multiset.cons_zero @[simp, norm_cast] theorem coe_singleton (a : α) : ([a] : Multiset α) = {a} := rfl #align multiset.coe_singleton Multiset.coe_singleton @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Multiset α) ↔ b = a := by simp only [← cons_zero, mem_cons, iff_self_iff, or_false_iff, not_mem_zero] #align multiset.mem_singleton Multiset.mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Multiset α) := by rw [← cons_zero] exact mem_cons_self _ _ #align multiset.mem_singleton_self Multiset.mem_singleton_self @[simp] theorem singleton_inj {a b : α} : ({a} : Multiset α) = {b} ↔ a = b := by simp_rw [← cons_zero] exact cons_inj_left _ #align multiset.singleton_inj Multiset.singleton_inj @[simp, norm_cast] theorem coe_eq_singleton {l : List α} {a : α} : (l : Multiset α) = {a} ↔ l = [a] := by rw [← coe_singleton, coe_eq_coe, List.perm_singleton] #align multiset.coe_eq_singleton Multiset.coe_eq_singleton @[simp] theorem singleton_eq_cons_iff {a b : α} (m : Multiset α) : {a} = b ::ₘ m ↔ a = b ∧ m = 0 := by rw [← cons_zero, cons_eq_cons] simp [eq_comm] #align multiset.singleton_eq_cons_iff Multiset.singleton_eq_cons_iff theorem pair_comm (x y : α) : ({x, y} : Multiset α) = {y, x} := cons_swap x y 0 #align multiset.pair_comm Multiset.pair_comm /-! ### `Multiset.Subset` -/ section Subset variable {s : Multiset α} {a : α} /-- `s ⊆ t` is the lift of the list subset relation. It means that any element with nonzero multiplicity in `s` has nonzero multiplicity in `t`, but it does not imply that the multiplicity of `a` in `s` is less or equal than in `t`; see `s ≤ t` for this relation. -/ protected def Subset (s t : Multiset α) : Prop := ∀ ⦃a : α⦄, a ∈ s → a ∈ t #align multiset.subset Multiset.Subset instance : HasSubset (Multiset α) := ⟨Multiset.Subset⟩ instance : HasSSubset (Multiset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance instIsNonstrictStrictOrder : IsNonstrictStrictOrder (Multiset α) (· ⊆ ·) (· ⊂ ·) where right_iff_left_not_left _ _ := Iff.rfl @[simp] theorem coe_subset {l₁ l₂ : List α} : (l₁ : Multiset α) ⊆ l₂ ↔ l₁ ⊆ l₂ := Iff.rfl #align multiset.coe_subset Multiset.coe_subset @[simp] theorem Subset.refl (s : Multiset α) : s ⊆ s := fun _ h => h #align multiset.subset.refl Multiset.Subset.refl theorem Subset.trans {s t u : Multiset α} : s ⊆ t → t ⊆ u → s ⊆ u := fun h₁ h₂ _ m => h₂ (h₁ m) #align multiset.subset.trans Multiset.Subset.trans theorem subset_iff {s t : Multiset α} : s ⊆ t ↔ ∀ ⦃x⦄, x ∈ s → x ∈ t := Iff.rfl #align multiset.subset_iff Multiset.subset_iff theorem mem_of_subset {s t : Multiset α} {a : α} (h : s ⊆ t) : a ∈ s → a ∈ t := @h _ #align multiset.mem_of_subset Multiset.mem_of_subset @[simp] theorem zero_subset (s : Multiset α) : 0 ⊆ s := fun a => (not_mem_nil a).elim #align multiset.zero_subset Multiset.zero_subset theorem subset_cons (s : Multiset α) (a : α) : s ⊆ a ::ₘ s := fun _ => mem_cons_of_mem #align multiset.subset_cons Multiset.subset_cons theorem ssubset_cons {s : Multiset α} {a : α} (ha : a ∉ s) : s ⊂ a ::ₘ s := ⟨subset_cons _ _, fun h => ha <| h <| mem_cons_self _ _⟩ #align multiset.ssubset_cons Multiset.ssubset_cons @[simp] theorem cons_subset {a : α} {s t : Multiset α} : a ::ₘ s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp [subset_iff, or_imp, forall_and] #align multiset.cons_subset Multiset.cons_subset theorem cons_subset_cons {a : α} {s t : Multiset α} : s ⊆ t → a ::ₘ s ⊆ a ::ₘ t := Quotient.inductionOn₂ s t fun _ _ => List.cons_subset_cons _ #align multiset.cons_subset_cons Multiset.cons_subset_cons theorem eq_zero_of_subset_zero {s : Multiset α} (h : s ⊆ 0) : s = 0 := eq_zero_of_forall_not_mem fun _ hx ↦ not_mem_zero _ (h hx) #align multiset.eq_zero_of_subset_zero Multiset.eq_zero_of_subset_zero @[simp] lemma subset_zero : s ⊆ 0 ↔ s = 0 := ⟨eq_zero_of_subset_zero, fun xeq => xeq.symm ▸ Subset.refl 0⟩ #align multiset.subset_zero Multiset.subset_zero @[simp] lemma zero_ssubset : 0 ⊂ s ↔ s ≠ 0 := by simp [ssubset_iff_subset_not_subset] @[simp] lemma singleton_subset : {a} ⊆ s ↔ a ∈ s := by simp [subset_iff] theorem induction_on' {p : Multiset α → Prop} (S : Multiset α) (h₁ : p 0) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → p s → p (insert a s)) : p S := @Multiset.induction_on α (fun T => T ⊆ S → p T) S (fun _ => h₁) (fun _ _ hps hs => let ⟨hS, sS⟩ := cons_subset.1 hs h₂ hS sS (hps sS)) (Subset.refl S) #align multiset.induction_on' Multiset.induction_on' end Subset /-! ### `Multiset.toList` -/ section ToList /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def toList (s : Multiset α) := s.out' #align multiset.to_list Multiset.toList @[simp, norm_cast] theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s := s.out_eq' #align multiset.coe_to_list Multiset.coe_toList @[simp] theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_toList] #align multiset.to_list_eq_nil Multiset.toList_eq_nil @[simp] theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := isEmpty_iff_eq_nil.trans toList_eq_nil #align multiset.empty_to_list Multiset.empty_toList @[simp] theorem toList_zero : (Multiset.toList 0 : List α) = [] := toList_eq_nil.mpr rfl #align multiset.to_list_zero Multiset.toList_zero @[simp] theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by rw [← mem_coe, coe_toList] #align multiset.mem_to_list Multiset.mem_toList @[simp] theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton] #align multiset.to_list_eq_singleton_iff Multiset.toList_eq_singleton_iff @[simp] theorem toList_singleton (a : α) : ({a} : Multiset α).toList = [a] := Multiset.toList_eq_singleton_iff.2 rfl #align multiset.to_list_singleton Multiset.toList_singleton end ToList /-! ### Partial order on `Multiset`s -/ /-- `s ≤ t` means that `s` is a sublist of `t` (up to permutation). Equivalently, `s ≤ t` means that `count a s ≤ count a t` for all `a`. -/ protected def Le (s t : Multiset α) : Prop := (Quotient.liftOn₂ s t (· <+~ ·)) fun _ _ _ _ p₁ p₂ => propext (p₂.subperm_left.trans p₁.subperm_right) #align multiset.le Multiset.Le instance : PartialOrder (Multiset α) where le := Multiset.Le le_refl := by rintro ⟨l⟩; exact Subperm.refl _ le_trans := by rintro ⟨l₁⟩ ⟨l₂⟩ ⟨l₃⟩; exact @Subperm.trans _ _ _ _ le_antisymm := by rintro ⟨l₁⟩ ⟨l₂⟩ h₁ h₂; exact Quot.sound (Subperm.antisymm h₁ h₂) instance decidableLE [DecidableEq α] : DecidableRel ((· ≤ ·) : Multiset α → Multiset α → Prop) := fun s t => Quotient.recOnSubsingleton₂ s t List.decidableSubperm #align multiset.decidable_le Multiset.decidableLE section variable {s t : Multiset α} {a : α} theorem subset_of_le : s ≤ t → s ⊆ t := Quotient.inductionOn₂ s t fun _ _ => Subperm.subset #align multiset.subset_of_le Multiset.subset_of_le alias Le.subset := subset_of_le #align multiset.le.subset Multiset.Le.subset theorem mem_of_le (h : s ≤ t) : a ∈ s → a ∈ t := mem_of_subset (subset_of_le h) #align multiset.mem_of_le Multiset.mem_of_le theorem not_mem_mono (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| @h _ #align multiset.not_mem_mono Multiset.not_mem_mono @[simp] theorem coe_le {l₁ l₂ : List α} : (l₁ : Multiset α) ≤ l₂ ↔ l₁ <+~ l₂ := Iff.rfl #align multiset.coe_le Multiset.coe_le @[elab_as_elim] theorem leInductionOn {C : Multiset α → Multiset α → Prop} {s t : Multiset α} (h : s ≤ t) (H : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → C l₁ l₂) : C s t := Quotient.inductionOn₂ s t (fun l₁ _ ⟨l, p, s⟩ => (show ⟦l⟧ = ⟦l₁⟧ from Quot.sound p) ▸ H s) h #align multiset.le_induction_on Multiset.leInductionOn theorem zero_le (s : Multiset α) : 0 ≤ s := Quot.inductionOn s fun l => (nil_sublist l).subperm #align multiset.zero_le Multiset.zero_le instance : OrderBot (Multiset α) where bot := 0 bot_le := zero_le /-- This is a `rfl` and `simp` version of `bot_eq_zero`. -/ @[simp] theorem bot_eq_zero : (⊥ : Multiset α) = 0 := rfl #align multiset.bot_eq_zero Multiset.bot_eq_zero theorem le_zero : s ≤ 0 ↔ s = 0 := le_bot_iff #align multiset.le_zero Multiset.le_zero theorem lt_cons_self (s : Multiset α) (a : α) : s < a ::ₘ s := Quot.inductionOn s fun l => suffices l <+~ a :: l ∧ ¬l ~ a :: l by simpa [lt_iff_le_and_ne] ⟨(sublist_cons _ _).subperm, fun p => _root_.ne_of_lt (lt_succ_self (length l)) p.length_eq⟩ #align multiset.lt_cons_self Multiset.lt_cons_self theorem le_cons_self (s : Multiset α) (a : α) : s ≤ a ::ₘ s := le_of_lt <| lt_cons_self _ _ #align multiset.le_cons_self Multiset.le_cons_self theorem cons_le_cons_iff (a : α) : a ::ₘ s ≤ a ::ₘ t ↔ s ≤ t := Quotient.inductionOn₂ s t fun _ _ => subperm_cons a #align multiset.cons_le_cons_iff Multiset.cons_le_cons_iff theorem cons_le_cons (a : α) : s ≤ t → a ::ₘ s ≤ a ::ₘ t := (cons_le_cons_iff a).2 #align multiset.cons_le_cons Multiset.cons_le_cons @[simp] lemma cons_lt_cons_iff : a ::ₘ s < a ::ₘ t ↔ s < t := lt_iff_lt_of_le_iff_le' (cons_le_cons_iff _) (cons_le_cons_iff _) lemma cons_lt_cons (a : α) (h : s < t) : a ::ₘ s < a ::ₘ t := cons_lt_cons_iff.2 h theorem le_cons_of_not_mem (m : a ∉ s) : s ≤ a ::ₘ t ↔ s ≤ t := by refine ⟨?_, fun h => le_trans h <| le_cons_self _ _⟩ suffices ∀ {t'}, s ≤ t' → a ∈ t' → a ::ₘ s ≤ t' by exact fun h => (cons_le_cons_iff a).1 (this h (mem_cons_self _ _)) introv h revert m refine leInductionOn h ?_ introv s m₁ m₂ rcases append_of_mem m₂ with ⟨r₁, r₂, rfl⟩ exact perm_middle.subperm_left.2 ((subperm_cons _).2 <| ((sublist_or_mem_of_sublist s).resolve_right m₁).subperm) #align multiset.le_cons_of_not_mem Multiset.le_cons_of_not_mem @[simp] theorem singleton_ne_zero (a : α) : ({a} : Multiset α) ≠ 0 := ne_of_gt (lt_cons_self _ _) #align multiset.singleton_ne_zero Multiset.singleton_ne_zero @[simp] theorem singleton_le {a : α} {s : Multiset α} : {a} ≤ s ↔ a ∈ s := ⟨fun h => mem_of_le h (mem_singleton_self _), fun h => let ⟨_t, e⟩ := exists_cons_of_mem h e.symm ▸ cons_le_cons _ (zero_le _)⟩ #align multiset.singleton_le Multiset.singleton_le @[simp] lemma le_singleton : s ≤ {a} ↔ s = 0 ∨ s = {a} := Quot.induction_on s fun l ↦ by simp only [cons_zero, ← coe_singleton, quot_mk_to_coe'', coe_le, coe_eq_zero, coe_eq_coe, perm_singleton, subperm_singleton_iff] @[simp] lemma lt_singleton : s < {a} ↔ s = 0 := by simp only [lt_iff_le_and_ne, le_singleton, or_and_right, Ne, and_not_self, or_false, and_iff_left_iff_imp] rintro rfl exact (singleton_ne_zero _).symm @[simp] lemma ssubset_singleton_iff : s ⊂ {a} ↔ s = 0 := by refine ⟨fun hs ↦ eq_zero_of_subset_zero fun b hb ↦ (hs.2 ?_).elim, ?_⟩ · obtain rfl := mem_singleton.1 (hs.1 hb) rwa [singleton_subset] · rintro rfl simp end /-! ### Additive monoid -/ /-- The sum of two multisets is the lift of the list append operation. This adds the multiplicities of each element, i.e. `count a (s + t) = count a s + count a t`. -/ protected def add (s₁ s₂ : Multiset α) : Multiset α := (Quotient.liftOn₂ s₁ s₂ fun l₁ l₂ => ((l₁ ++ l₂ : List α) : Multiset α)) fun _ _ _ _ p₁ p₂ => Quot.sound <| p₁.append p₂ #align multiset.add Multiset.add instance : Add (Multiset α) := ⟨Multiset.add⟩ @[simp] theorem coe_add (s t : List α) : (s + t : Multiset α) = (s ++ t : List α) := rfl #align multiset.coe_add Multiset.coe_add @[simp] theorem singleton_add (a : α) (s : Multiset α) : {a} + s = a ::ₘ s := rfl #align multiset.singleton_add Multiset.singleton_add private theorem add_le_add_iff_left' {s t u : Multiset α} : s + t ≤ s + u ↔ t ≤ u := Quotient.inductionOn₃ s t u fun _ _ _ => subperm_append_left _ instance : CovariantClass (Multiset α) (Multiset α) (· + ·) (· ≤ ·) := ⟨fun _s _t _u => add_le_add_iff_left'.2⟩ instance : ContravariantClass (Multiset α) (Multiset α) (· + ·) (· ≤ ·) := ⟨fun _s _t _u => add_le_add_iff_left'.1⟩ instance : OrderedCancelAddCommMonoid (Multiset α) where zero := 0 add := (· + ·) add_comm := fun s t => Quotient.inductionOn₂ s t fun l₁ l₂ => Quot.sound perm_append_comm add_assoc := fun s₁ s₂ s₃ => Quotient.inductionOn₃ s₁ s₂ s₃ fun l₁ l₂ l₃ => congr_arg _ <| append_assoc l₁ l₂ l₃ zero_add := fun s => Quot.inductionOn s fun l => rfl add_zero := fun s => Quotient.inductionOn s fun l => congr_arg _ <| append_nil l add_le_add_left := fun s₁ s₂ => add_le_add_left le_of_add_le_add_left := fun s₁ s₂ s₃ => le_of_add_le_add_left nsmul := nsmulRec theorem le_add_right (s t : Multiset α) : s ≤ s + t := by simpa using add_le_add_left (zero_le t) s #align multiset.le_add_right Multiset.le_add_right theorem le_add_left (s t : Multiset α) : s ≤ t + s := by simpa using add_le_add_right (zero_le t) s #align multiset.le_add_left Multiset.le_add_left theorem le_iff_exists_add {s t : Multiset α} : s ≤ t ↔ ∃ u, t = s + u := ⟨fun h => leInductionOn h fun s => let ⟨l, p⟩ := s.exists_perm_append ⟨l, Quot.sound p⟩, fun ⟨_u, e⟩ => e.symm ▸ le_add_right _ _⟩ #align multiset.le_iff_exists_add Multiset.le_iff_exists_add instance : CanonicallyOrderedAddCommMonoid (Multiset α) where __ := inferInstanceAs (OrderBot (Multiset α)) le_self_add := le_add_right exists_add_of_le h := leInductionOn h fun s => let ⟨l, p⟩ := s.exists_perm_append ⟨l, Quot.sound p⟩ @[simp] theorem cons_add (a : α) (s t : Multiset α) : a ::ₘ s + t = a ::ₘ (s + t) := by rw [← singleton_add, ← singleton_add, add_assoc] #align multiset.cons_add Multiset.cons_add @[simp] theorem add_cons (a : α) (s t : Multiset α) : s + a ::ₘ t = a ::ₘ (s + t) := by rw [add_comm, cons_add, add_comm] #align multiset.add_cons Multiset.add_cons @[simp] theorem mem_add {a : α} {s t : Multiset α} : a ∈ s + t ↔ a ∈ s ∨ a ∈ t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => mem_append #align multiset.mem_add Multiset.mem_add theorem mem_of_mem_nsmul {a : α} {s : Multiset α} {n : ℕ} (h : a ∈ n • s) : a ∈ s := by induction' n with n ih · rw [zero_nsmul] at h exact absurd h (not_mem_zero _) · rw [succ_nsmul, mem_add] at h exact h.elim ih id #align multiset.mem_of_mem_nsmul Multiset.mem_of_mem_nsmul @[simp] theorem mem_nsmul {a : α} {s : Multiset α} {n : ℕ} (h0 : n ≠ 0) : a ∈ n • s ↔ a ∈ s := by refine ⟨mem_of_mem_nsmul, fun h => ?_⟩ obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero h0 rw [succ_nsmul, mem_add] exact Or.inr h #align multiset.mem_nsmul Multiset.mem_nsmul theorem nsmul_cons {s : Multiset α} (n : ℕ) (a : α) : n • (a ::ₘ s) = n • ({a} : Multiset α) + n • s := by rw [← singleton_add, nsmul_add] #align multiset.nsmul_cons Multiset.nsmul_cons /-! ### Cardinality -/ /-- The cardinality of a multiset is the sum of the multiplicities of all its elements, or simply the length of the underlying list. -/ def card : Multiset α →+ ℕ where toFun s := (Quot.liftOn s length) fun _l₁ _l₂ => Perm.length_eq map_zero' := rfl map_add' s t := Quotient.inductionOn₂ s t length_append #align multiset.card Multiset.card @[simp] theorem coe_card (l : List α) : card (l : Multiset α) = length l := rfl #align multiset.coe_card Multiset.coe_card @[simp] theorem length_toList (s : Multiset α) : s.toList.length = card s := by rw [← coe_card, coe_toList] #align multiset.length_to_list Multiset.length_toList @[simp, nolint simpNF] -- Porting note (#10675): `dsimp` can not prove this, yet linter complains theorem card_zero : @card α 0 = 0 := rfl #align multiset.card_zero Multiset.card_zero theorem card_add (s t : Multiset α) : card (s + t) = card s + card t := card.map_add s t #align multiset.card_add Multiset.card_add theorem card_nsmul (s : Multiset α) (n : ℕ) : card (n • s) = n * card s := by rw [card.map_nsmul s n, Nat.nsmul_eq_mul] #align multiset.card_nsmul Multiset.card_nsmul @[simp] theorem card_cons (a : α) (s : Multiset α) : card (a ::ₘ s) = card s + 1 := Quot.inductionOn s fun _l => rfl #align multiset.card_cons Multiset.card_cons @[simp] theorem card_singleton (a : α) : card ({a} : Multiset α) = 1 := by simp only [← cons_zero, card_zero, eq_self_iff_true, zero_add, card_cons] #align multiset.card_singleton Multiset.card_singleton theorem card_pair (a b : α) : card {a, b} = 2 := by rw [insert_eq_cons, card_cons, card_singleton] #align multiset.card_pair Multiset.card_pair theorem card_eq_one {s : Multiset α} : card s = 1 ↔ ∃ a, s = {a} := ⟨Quot.inductionOn s fun _l h => (List.length_eq_one.1 h).imp fun _a => congr_arg _, fun ⟨_a, e⟩ => e.symm ▸ rfl⟩ #align multiset.card_eq_one Multiset.card_eq_one theorem card_le_card {s t : Multiset α} (h : s ≤ t) : card s ≤ card t := leInductionOn h Sublist.length_le #align multiset.card_le_of_le Multiset.card_le_card @[mono] theorem card_mono : Monotone (@card α) := fun _a _b => card_le_card #align multiset.card_mono Multiset.card_mono theorem eq_of_le_of_card_le {s t : Multiset α} (h : s ≤ t) : card t ≤ card s → s = t := leInductionOn h fun s h₂ => congr_arg _ <| s.eq_of_length_le h₂ #align multiset.eq_of_le_of_card_le Multiset.eq_of_le_of_card_le theorem card_lt_card {s t : Multiset α} (h : s < t) : card s < card t := lt_of_not_ge fun h₂ => _root_.ne_of_lt h <| eq_of_le_of_card_le (le_of_lt h) h₂ #align multiset.card_lt_card Multiset.card_lt_card lemma card_strictMono : StrictMono (card : Multiset α → ℕ) := fun _ _ ↦ card_lt_card theorem lt_iff_cons_le {s t : Multiset α} : s < t ↔ ∃ a, a ::ₘ s ≤ t := ⟨Quotient.inductionOn₂ s t fun _l₁ _l₂ h => Subperm.exists_of_length_lt (le_of_lt h) (card_lt_card h), fun ⟨_a, h⟩ => lt_of_lt_of_le (lt_cons_self _ _) h⟩ #align multiset.lt_iff_cons_le Multiset.lt_iff_cons_le @[simp] theorem card_eq_zero {s : Multiset α} : card s = 0 ↔ s = 0 := ⟨fun h => (eq_of_le_of_card_le (zero_le _) (le_of_eq h)).symm, fun e => by simp [e]⟩ #align multiset.card_eq_zero Multiset.card_eq_zero theorem card_pos {s : Multiset α} : 0 < card s ↔ s ≠ 0 := Nat.pos_iff_ne_zero.trans <| not_congr card_eq_zero #align multiset.card_pos Multiset.card_pos theorem card_pos_iff_exists_mem {s : Multiset α} : 0 < card s ↔ ∃ a, a ∈ s := Quot.inductionOn s fun _l => length_pos_iff_exists_mem #align multiset.card_pos_iff_exists_mem Multiset.card_pos_iff_exists_mem theorem card_eq_two {s : Multiset α} : card s = 2 ↔ ∃ x y, s = {x, y} := ⟨Quot.inductionOn s fun _l h => (List.length_eq_two.mp h).imp fun _a => Exists.imp fun _b => congr_arg _, fun ⟨_a, _b, e⟩ => e.symm ▸ rfl⟩ #align multiset.card_eq_two Multiset.card_eq_two theorem card_eq_three {s : Multiset α} : card s = 3 ↔ ∃ x y z, s = {x, y, z} := ⟨Quot.inductionOn s fun _l h => (List.length_eq_three.mp h).imp fun _a => Exists.imp fun _b => Exists.imp fun _c => congr_arg _, fun ⟨_a, _b, _c, e⟩ => e.symm ▸ rfl⟩ #align multiset.card_eq_three Multiset.card_eq_three /-! ### Induction principles -/ /-- The strong induction principle for multisets. -/ @[elab_as_elim] def strongInductionOn {p : Multiset α → Sort*} (s : Multiset α) (ih : ∀ s, (∀ t < s, p t) → p s) : p s := (ih s) fun t _h => strongInductionOn t ih termination_by card s decreasing_by exact card_lt_card _h #align multiset.strong_induction_on Multiset.strongInductionOnₓ -- Porting note: reorderd universes theorem strongInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) (H) : @strongInductionOn _ p s H = H s fun t _h => @strongInductionOn _ p t H := by rw [strongInductionOn] #align multiset.strong_induction_eq Multiset.strongInductionOn_eq @[elab_as_elim] theorem case_strongInductionOn {p : Multiset α → Prop} (s : Multiset α) (h₀ : p 0) (h₁ : ∀ a s, (∀ t ≤ s, p t) → p (a ::ₘ s)) : p s := Multiset.strongInductionOn s fun s => Multiset.induction_on s (fun _ => h₀) fun _a _s _ ih => (h₁ _ _) fun _t h => ih _ <| lt_of_le_of_lt h <| lt_cons_self _ _ #align multiset.case_strong_induction_on Multiset.case_strongInductionOn /-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than `n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of cardinality less than `n`, starting from multisets of card `n` and iterating. This can be used either to define data, or to prove properties. -/ def strongDownwardInduction {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : card s ≤ n → p s := H s fun {t} ht _h => strongDownwardInduction H t ht termination_by n - card s decreasing_by simp_wf; have := (card_lt_card _h); omega -- Porting note: reorderd universes #align multiset.strong_downward_induction Multiset.strongDownwardInductionₓ theorem strongDownwardInduction_eq {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : strongDownwardInduction H s = H s fun ht _hst => strongDownwardInduction H _ ht := by rw [strongDownwardInduction] #align multiset.strong_downward_induction_eq Multiset.strongDownwardInduction_eq /-- Analogue of `strongDownwardInduction` with order of arguments swapped. -/ @[elab_as_elim] def strongDownwardInductionOn {p : Multiset α → Sort*} {n : ℕ} : ∀ s : Multiset α, (∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) → card s ≤ n → p s := fun s H => strongDownwardInduction H s #align multiset.strong_downward_induction_on Multiset.strongDownwardInductionOn theorem strongDownwardInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) : s.strongDownwardInductionOn H = H s fun {t} ht _h => t.strongDownwardInductionOn H ht := by dsimp only [strongDownwardInductionOn] rw [strongDownwardInduction] #align multiset.strong_downward_induction_on_eq Multiset.strongDownwardInductionOn_eq #align multiset.well_founded_lt wellFounded_lt /-- Another way of expressing `strongInductionOn`: the `(<)` relation is well-founded. -/ instance instWellFoundedLT : WellFoundedLT (Multiset α) := ⟨Subrelation.wf Multiset.card_lt_card (measure Multiset.card).2⟩ #align multiset.is_well_founded_lt Multiset.instWellFoundedLT /-! ### `Multiset.replicate` -/ /-- `replicate n a` is the multiset containing only `a` with multiplicity `n`. -/ def replicate (n : ℕ) (a : α) : Multiset α := List.replicate n a #align multiset.replicate Multiset.replicate theorem coe_replicate (n : ℕ) (a : α) : (List.replicate n a : Multiset α) = replicate n a := rfl #align multiset.coe_replicate Multiset.coe_replicate @[simp] theorem replicate_zero (a : α) : replicate 0 a = 0 := rfl #align multiset.replicate_zero Multiset.replicate_zero @[simp] theorem replicate_succ (a : α) (n) : replicate (n + 1) a = a ::ₘ replicate n a := rfl #align multiset.replicate_succ Multiset.replicate_succ theorem replicate_add (m n : ℕ) (a : α) : replicate (m + n) a = replicate m a + replicate n a := congr_arg _ <| List.replicate_add .. #align multiset.replicate_add Multiset.replicate_add /-- `Multiset.replicate` as an `AddMonoidHom`. -/ @[simps] def replicateAddMonoidHom (a : α) : ℕ →+ Multiset α where toFun := fun n => replicate n a map_zero' := replicate_zero a map_add' := fun _ _ => replicate_add _ _ a #align multiset.replicate_add_monoid_hom Multiset.replicateAddMonoidHom #align multiset.replicate_add_monoid_hom_apply Multiset.replicateAddMonoidHom_apply theorem replicate_one (a : α) : replicate 1 a = {a} := rfl #align multiset.replicate_one Multiset.replicate_one @[simp] theorem card_replicate (n) (a : α) : card (replicate n a) = n := length_replicate n a #align multiset.card_replicate Multiset.card_replicate theorem mem_replicate {a b : α} {n : ℕ} : b ∈ replicate n a ↔ n ≠ 0 ∧ b = a := List.mem_replicate #align multiset.mem_replicate Multiset.mem_replicate theorem eq_of_mem_replicate {a b : α} {n} : b ∈ replicate n a → b = a := List.eq_of_mem_replicate #align multiset.eq_of_mem_replicate Multiset.eq_of_mem_replicate theorem eq_replicate_card {a : α} {s : Multiset α} : s = replicate (card s) a ↔ ∀ b ∈ s, b = a := Quot.inductionOn s fun _l => coe_eq_coe.trans <| perm_replicate.trans eq_replicate_length #align multiset.eq_replicate_card Multiset.eq_replicate_card alias ⟨_, eq_replicate_of_mem⟩ := eq_replicate_card #align multiset.eq_replicate_of_mem Multiset.eq_replicate_of_mem theorem eq_replicate {a : α} {n} {s : Multiset α} : s = replicate n a ↔ card s = n ∧ ∀ b ∈ s, b = a := ⟨fun h => h.symm ▸ ⟨card_replicate _ _, fun _b => eq_of_mem_replicate⟩, fun ⟨e, al⟩ => e ▸ eq_replicate_of_mem al⟩ #align multiset.eq_replicate Multiset.eq_replicate theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ #align multiset.replicate_right_injective Multiset.replicate_right_injective @[simp] theorem replicate_right_inj {a b : α} {n : ℕ} (h : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective h).eq_iff #align multiset.replicate_right_inj Multiset.replicate_right_inj theorem replicate_left_injective (a : α) : Injective (replicate · a) := -- Porting note: was `fun m n h => by rw [← (eq_replicate.1 h).1, card_replicate]` LeftInverse.injective (card_replicate · a) #align multiset.replicate_left_injective Multiset.replicate_left_injective theorem replicate_subset_singleton (n : ℕ) (a : α) : replicate n a ⊆ {a} := List.replicate_subset_singleton n a #align multiset.replicate_subset_singleton Multiset.replicate_subset_singleton theorem replicate_le_coe {a : α} {n} {l : List α} : replicate n a ≤ l ↔ List.replicate n a <+ l := ⟨fun ⟨_l', p, s⟩ => perm_replicate.1 p ▸ s, Sublist.subperm⟩ #align multiset.replicate_le_coe Multiset.replicate_le_coe theorem nsmul_replicate {a : α} (n m : ℕ) : n • replicate m a = replicate (n * m) a := ((replicateAddMonoidHom a).map_nsmul _ _).symm #align multiset.nsmul_replicate Multiset.nsmul_replicate theorem nsmul_singleton (a : α) (n) : n • ({a} : Multiset α) = replicate n a := by rw [← replicate_one, nsmul_replicate, mul_one] #align multiset.nsmul_singleton Multiset.nsmul_singleton theorem replicate_le_replicate (a : α) {k n : ℕ} : replicate k a ≤ replicate n a ↔ k ≤ n := _root_.trans (by rw [← replicate_le_coe, coe_replicate]) (List.replicate_sublist_replicate a) #align multiset.replicate_le_replicate Multiset.replicate_le_replicate theorem le_replicate_iff {m : Multiset α} {a : α} {n : ℕ} : m ≤ replicate n a ↔ ∃ k ≤ n, m = replicate k a := ⟨fun h => ⟨card m, (card_mono h).trans_eq (card_replicate _ _), eq_replicate_card.2 fun _ hb => eq_of_mem_replicate <| subset_of_le h hb⟩, fun ⟨_, hkn, hm⟩ => hm.symm ▸ (replicate_le_replicate _).2 hkn⟩ #align multiset.le_replicate_iff Multiset.le_replicate_iff theorem lt_replicate_succ {m : Multiset α} {x : α} {n : ℕ} : m < replicate (n + 1) x ↔ m ≤ replicate n x := by rw [lt_iff_cons_le] constructor · rintro ⟨x', hx'⟩ have := eq_of_mem_replicate (mem_of_le hx' (mem_cons_self _ _)) rwa [this, replicate_succ, cons_le_cons_iff] at hx' · intro h rw [replicate_succ] exact ⟨x, cons_le_cons _ h⟩ #align multiset.lt_replicate_succ Multiset.lt_replicate_succ /-! ### Erasing one copy of an element -/ section Erase variable [DecidableEq α] {s t : Multiset α} {a b : α} /-- `erase s a` is the multiset that subtracts 1 from the multiplicity of `a`. -/ def erase (s : Multiset α) (a : α) : Multiset α := Quot.liftOn s (fun l => (l.erase a : Multiset α)) fun _l₁ _l₂ p => Quot.sound (p.erase a) #align multiset.erase Multiset.erase @[simp] theorem coe_erase (l : List α) (a : α) : erase (l : Multiset α) a = l.erase a := rfl #align multiset.coe_erase Multiset.coe_erase @[simp, nolint simpNF] -- Porting note (#10675): `dsimp` can not prove this, yet linter complains theorem erase_zero (a : α) : (0 : Multiset α).erase a = 0 := rfl #align multiset.erase_zero Multiset.erase_zero @[simp] theorem erase_cons_head (a : α) (s : Multiset α) : (a ::ₘ s).erase a = s := Quot.inductionOn s fun l => congr_arg _ <| List.erase_cons_head a l #align multiset.erase_cons_head Multiset.erase_cons_head @[simp] theorem erase_cons_tail {a b : α} (s : Multiset α) (h : b ≠ a) : (b ::ₘ s).erase a = b ::ₘ s.erase a := Quot.inductionOn s fun l => congr_arg _ <| List.erase_cons_tail l (not_beq_of_ne h) #align multiset.erase_cons_tail Multiset.erase_cons_tail @[simp] theorem erase_singleton (a : α) : ({a} : Multiset α).erase a = 0 := erase_cons_head a 0 #align multiset.erase_singleton Multiset.erase_singleton @[simp] theorem erase_of_not_mem {a : α} {s : Multiset α} : a ∉ s → s.erase a = s := Quot.inductionOn s fun _l h => congr_arg _ <| List.erase_of_not_mem h #align multiset.erase_of_not_mem Multiset.erase_of_not_mem @[simp] theorem cons_erase {s : Multiset α} {a : α} : a ∈ s → a ::ₘ s.erase a = s := Quot.inductionOn s fun _l h => Quot.sound (perm_cons_erase h).symm #align multiset.cons_erase Multiset.cons_erase theorem erase_cons_tail_of_mem (h : a ∈ s) : (b ::ₘ s).erase a = b ::ₘ s.erase a := by rcases eq_or_ne a b with rfl | hab · simp [cons_erase h] · exact s.erase_cons_tail hab.symm theorem le_cons_erase (s : Multiset α) (a : α) : s ≤ a ::ₘ s.erase a := if h : a ∈ s then le_of_eq (cons_erase h).symm else by rw [erase_of_not_mem h]; apply le_cons_self #align multiset.le_cons_erase Multiset.le_cons_erase theorem add_singleton_eq_iff {s t : Multiset α} {a : α} : s + {a} = t ↔ a ∈ t ∧ s = t.erase a := by rw [add_comm, singleton_add]; constructor · rintro rfl exact ⟨s.mem_cons_self a, (s.erase_cons_head a).symm⟩ · rintro ⟨h, rfl⟩ exact cons_erase h #align multiset.add_singleton_eq_iff Multiset.add_singleton_eq_iff theorem erase_add_left_pos {a : α} {s : Multiset α} (t) : a ∈ s → (s + t).erase a = s.erase a + t := Quotient.inductionOn₂ s t fun _l₁ l₂ h => congr_arg _ <| erase_append_left l₂ h #align multiset.erase_add_left_pos Multiset.erase_add_left_pos theorem erase_add_right_pos {a : α} (s) {t : Multiset α} (h : a ∈ t) : (s + t).erase a = s + t.erase a := by rw [add_comm, erase_add_left_pos s h, add_comm] #align multiset.erase_add_right_pos Multiset.erase_add_right_pos theorem erase_add_right_neg {a : α} {s : Multiset α} (t) : a ∉ s → (s + t).erase a = s + t.erase a := Quotient.inductionOn₂ s t fun _l₁ l₂ h => congr_arg _ <| erase_append_right l₂ h #align multiset.erase_add_right_neg Multiset.erase_add_right_neg theorem erase_add_left_neg {a : α} (s) {t : Multiset α} (h : a ∉ t) : (s + t).erase a = s.erase a + t := by rw [add_comm, erase_add_right_neg s h, add_comm] #align multiset.erase_add_left_neg Multiset.erase_add_left_neg theorem erase_le (a : α) (s : Multiset α) : s.erase a ≤ s := Quot.inductionOn s fun l => (erase_sublist a l).subperm #align multiset.erase_le Multiset.erase_le @[simp] theorem erase_lt {a : α} {s : Multiset α} : s.erase a < s ↔ a ∈ s := ⟨fun h => not_imp_comm.1 erase_of_not_mem (ne_of_lt h), fun h => by simpa [h] using lt_cons_self (s.erase a) a⟩ #align multiset.erase_lt Multiset.erase_lt theorem erase_subset (a : α) (s : Multiset α) : s.erase a ⊆ s := subset_of_le (erase_le a s) #align multiset.erase_subset Multiset.erase_subset theorem mem_erase_of_ne {a b : α} {s : Multiset α} (ab : a ≠ b) : a ∈ s.erase b ↔ a ∈ s := Quot.inductionOn s fun _l => List.mem_erase_of_ne ab #align multiset.mem_erase_of_ne Multiset.mem_erase_of_ne theorem mem_of_mem_erase {a b : α} {s : Multiset α} : a ∈ s.erase b → a ∈ s := mem_of_subset (erase_subset _ _) #align multiset.mem_of_mem_erase Multiset.mem_of_mem_erase theorem erase_comm (s : Multiset α) (a b : α) : (s.erase a).erase b = (s.erase b).erase a := Quot.inductionOn s fun l => congr_arg _ <| l.erase_comm a b #align multiset.erase_comm Multiset.erase_comm theorem erase_le_erase {s t : Multiset α} (a : α) (h : s ≤ t) : s.erase a ≤ t.erase a := leInductionOn h fun h => (h.erase _).subperm #align multiset.erase_le_erase Multiset.erase_le_erase theorem erase_le_iff_le_cons {s t : Multiset α} {a : α} : s.erase a ≤ t ↔ s ≤ a ::ₘ t := ⟨fun h => le_trans (le_cons_erase _ _) (cons_le_cons _ h), fun h => if m : a ∈ s then by rw [← cons_erase m] at h; exact (cons_le_cons_iff _).1 h else le_trans (erase_le _ _) ((le_cons_of_not_mem m).1 h)⟩ #align multiset.erase_le_iff_le_cons Multiset.erase_le_iff_le_cons @[simp] theorem card_erase_of_mem {a : α} {s : Multiset α} : a ∈ s → card (s.erase a) = pred (card s) := Quot.inductionOn s fun _l => length_erase_of_mem #align multiset.card_erase_of_mem Multiset.card_erase_of_mem @[simp] theorem card_erase_add_one {a : α} {s : Multiset α} : a ∈ s → card (s.erase a) + 1 = card s := Quot.inductionOn s fun _l => length_erase_add_one #align multiset.card_erase_add_one Multiset.card_erase_add_one theorem card_erase_lt_of_mem {a : α} {s : Multiset α} : a ∈ s → card (s.erase a) < card s := fun h => card_lt_card (erase_lt.mpr h) #align multiset.card_erase_lt_of_mem Multiset.card_erase_lt_of_mem theorem card_erase_le {a : α} {s : Multiset α} : card (s.erase a) ≤ card s := card_le_card (erase_le a s) #align multiset.card_erase_le Multiset.card_erase_le theorem card_erase_eq_ite {a : α} {s : Multiset α} : card (s.erase a) = if a ∈ s then pred (card s) else card s := by by_cases h : a ∈ s · rwa [card_erase_of_mem h, if_pos] · rwa [erase_of_not_mem h, if_neg] #align multiset.card_erase_eq_ite Multiset.card_erase_eq_ite end Erase @[simp] theorem coe_reverse (l : List α) : (reverse l : Multiset α) = l := Quot.sound <| reverse_perm _ #align multiset.coe_reverse Multiset.coe_reverse /-! ### `Multiset.map` -/ /-- `map f s` is the lift of the list `map` operation. The multiplicity of `b` in `map f s` is the number of `a ∈ s` (counting multiplicity) such that `f a = b`. -/ def map (f : α → β) (s : Multiset α) : Multiset β := Quot.liftOn s (fun l : List α => (l.map f : Multiset β)) fun _l₁ _l₂ p => Quot.sound (p.map f) #align multiset.map Multiset.map @[congr] theorem map_congr {f g : α → β} {s t : Multiset α} : s = t → (∀ x ∈ t, f x = g x) → map f s = map g t := by rintro rfl h induction s using Quot.inductionOn exact congr_arg _ (List.map_congr h) #align multiset.map_congr Multiset.map_congr theorem map_hcongr {β' : Type v} {m : Multiset α} {f : α → β} {f' : α → β'} (h : β = β') (hf : ∀ a ∈ m, HEq (f a) (f' a)) : HEq (map f m) (map f' m) := by subst h; simp at hf simp [map_congr rfl hf] #align multiset.map_hcongr Multiset.map_hcongr theorem forall_mem_map_iff {f : α → β} {p : β → Prop} {s : Multiset α} : (∀ y ∈ s.map f, p y) ↔ ∀ x ∈ s, p (f x) := Quotient.inductionOn' s fun _L => List.forall_mem_map_iff #align multiset.forall_mem_map_iff Multiset.forall_mem_map_iff @[simp, norm_cast] lemma map_coe (f : α → β) (l : List α) : map f l = l.map f := rfl #align multiset.coe_map Multiset.map_coe @[simp] theorem map_zero (f : α → β) : map f 0 = 0 := rfl #align multiset.map_zero Multiset.map_zero @[simp] theorem map_cons (f : α → β) (a s) : map f (a ::ₘ s) = f a ::ₘ map f s := Quot.inductionOn s fun _l => rfl #align multiset.map_cons Multiset.map_cons theorem map_comp_cons (f : α → β) (t) : map f ∘ cons t = cons (f t) ∘ map f := by ext simp #align multiset.map_comp_cons Multiset.map_comp_cons @[simp] theorem map_singleton (f : α → β) (a : α) : ({a} : Multiset α).map f = {f a} := rfl #align multiset.map_singleton Multiset.map_singleton @[simp] theorem map_replicate (f : α → β) (k : ℕ) (a : α) : (replicate k a).map f = replicate k (f a) := by simp only [← coe_replicate, map_coe, List.map_replicate] #align multiset.map_replicate Multiset.map_replicate @[simp] theorem map_add (f : α → β) (s t) : map f (s + t) = map f s + map f t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => congr_arg _ <| map_append _ _ _ #align multiset.map_add Multiset.map_add /-- If each element of `s : Multiset α` can be lifted to `β`, then `s` can be lifted to `Multiset β`. -/ instance canLift (c) (p) [CanLift α β c p] : CanLift (Multiset α) (Multiset β) (map c) fun s => ∀ x ∈ s, p x where prf := by rintro ⟨l⟩ hl lift l to List β using hl exact ⟨l, map_coe _ _⟩ #align multiset.can_lift Multiset.canLift /-- `Multiset.map` as an `AddMonoidHom`. -/ def mapAddMonoidHom (f : α → β) : Multiset α →+ Multiset β where toFun := map f map_zero' := map_zero _ map_add' := map_add _ #align multiset.map_add_monoid_hom Multiset.mapAddMonoidHom @[simp] theorem coe_mapAddMonoidHom (f : α → β) : (mapAddMonoidHom f : Multiset α → Multiset β) = map f := rfl #align multiset.coe_map_add_monoid_hom Multiset.coe_mapAddMonoidHom theorem map_nsmul (f : α → β) (n : ℕ) (s) : map f (n • s) = n • map f s := (mapAddMonoidHom f).map_nsmul _ _ #align multiset.map_nsmul Multiset.map_nsmul @[simp] theorem mem_map {f : α → β} {b : β} {s : Multiset α} : b ∈ map f s ↔ ∃ a, a ∈ s ∧ f a = b := Quot.inductionOn s fun _l => List.mem_map #align multiset.mem_map Multiset.mem_map @[simp] theorem card_map (f : α → β) (s) : card (map f s) = card s := Quot.inductionOn s fun _l => length_map _ _ #align multiset.card_map Multiset.card_map @[simp] theorem map_eq_zero {s : Multiset α} {f : α → β} : s.map f = 0 ↔ s = 0 := by rw [← Multiset.card_eq_zero, Multiset.card_map, Multiset.card_eq_zero] #align multiset.map_eq_zero Multiset.map_eq_zero theorem mem_map_of_mem (f : α → β) {a : α} {s : Multiset α} (h : a ∈ s) : f a ∈ map f s := mem_map.2 ⟨_, h, rfl⟩ #align multiset.mem_map_of_mem Multiset.mem_map_of_mem theorem map_eq_singleton {f : α → β} {s : Multiset α} {b : β} : map f s = {b} ↔ ∃ a : α, s = {a} ∧ f a = b := by constructor · intro h obtain ⟨a, ha⟩ : ∃ a, s = {a} := by rw [← card_eq_one, ← card_map, h, card_singleton] refine ⟨a, ha, ?_⟩ rw [← mem_singleton, ← h, ha, map_singleton, mem_singleton] · rintro ⟨a, rfl, rfl⟩ simp #align multiset.map_eq_singleton Multiset.map_eq_singleton theorem map_eq_cons [DecidableEq α] (f : α → β) (s : Multiset α) (t : Multiset β) (b : β) : (∃ a ∈ s, f a = b ∧ (s.erase a).map f = t) ↔ s.map f = b ::ₘ t := by constructor · rintro ⟨a, ha, rfl, rfl⟩ rw [← map_cons, Multiset.cons_erase ha] · intro h have : b ∈ s.map f := by rw [h] exact mem_cons_self _ _ obtain ⟨a, h1, rfl⟩ := mem_map.mp this obtain ⟨u, rfl⟩ := exists_cons_of_mem h1 rw [map_cons, cons_inj_right] at h refine ⟨a, mem_cons_self _ _, rfl, ?_⟩ rw [Multiset.erase_cons_head, h] #align multiset.map_eq_cons Multiset.map_eq_cons -- The simpNF linter says that the LHS can be simplified via `Multiset.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Function.Injective f) {a : α} {s : Multiset α} : f a ∈ map f s ↔ a ∈ s := Quot.inductionOn s fun _l => List.mem_map_of_injective H #align multiset.mem_map_of_injective Multiset.mem_map_of_injective @[simp] theorem map_map (g : β → γ) (f : α → β) (s : Multiset α) : map g (map f s) = map (g ∘ f) s := Quot.inductionOn s fun _l => congr_arg _ <| List.map_map _ _ _ #align multiset.map_map Multiset.map_map theorem map_id (s : Multiset α) : map id s = s := Quot.inductionOn s fun _l => congr_arg _ <| List.map_id _ #align multiset.map_id Multiset.map_id @[simp] theorem map_id' (s : Multiset α) : map (fun x => x) s = s := map_id s #align multiset.map_id' Multiset.map_id' -- Porting note: was a `simp` lemma in mathlib3 theorem map_const (s : Multiset α) (b : β) : map (const α b) s = replicate (card s) b := Quot.inductionOn s fun _ => congr_arg _ <| List.map_const' _ _ #align multiset.map_const Multiset.map_const -- Porting note: was not a `simp` lemma in mathlib3 because `Function.const` was reducible @[simp] theorem map_const' (s : Multiset α) (b : β) : map (fun _ ↦ b) s = replicate (card s) b := map_const _ _ #align multiset.map_const' Multiset.map_const' theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (Function.const α b₂) l) : b₁ = b₂ := eq_of_mem_replicate <| by rwa [map_const] at h #align multiset.eq_of_mem_map_const Multiset.eq_of_mem_map_const @[simp] theorem map_le_map {f : α → β} {s t : Multiset α} (h : s ≤ t) : map f s ≤ map f t := leInductionOn h fun h => (h.map f).subperm #align multiset.map_le_map Multiset.map_le_map @[simp] theorem map_lt_map {f : α → β} {s t : Multiset α} (h : s < t) : s.map f < t.map f := by refine (map_le_map h.le).lt_of_not_le fun H => h.ne <| eq_of_le_of_card_le h.le ?_ rw [← s.card_map f, ← t.card_map f] exact card_le_card H #align multiset.map_lt_map Multiset.map_lt_map theorem map_mono (f : α → β) : Monotone (map f) := fun _ _ => map_le_map #align multiset.map_mono Multiset.map_mono theorem map_strictMono (f : α → β) : StrictMono (map f) := fun _ _ => map_lt_map #align multiset.map_strict_mono Multiset.map_strictMono @[simp] theorem map_subset_map {f : α → β} {s t : Multiset α} (H : s ⊆ t) : map f s ⊆ map f t := fun _b m => let ⟨a, h, e⟩ := mem_map.1 m mem_map.2 ⟨a, H h, e⟩ #align multiset.map_subset_map Multiset.map_subset_map theorem map_erase [DecidableEq α] [DecidableEq β] (f : α → β) (hf : Function.Injective f) (x : α) (s : Multiset α) : (s.erase x).map f = (s.map f).erase (f x) := by induction' s using Multiset.induction_on with y s ih · simp by_cases hxy : y = x · cases hxy simp · rw [s.erase_cons_tail hxy, map_cons, map_cons, (s.map f).erase_cons_tail (hf.ne hxy), ih] #align multiset.map_erase Multiset.map_erase theorem map_erase_of_mem [DecidableEq α] [DecidableEq β] (f : α → β) (s : Multiset α) {x : α} (h : x ∈ s) : (s.erase x).map f = (s.map f).erase (f x) := by induction' s using Multiset.induction_on with y s ih · simp rcases eq_or_ne y x with rfl | hxy · simp replace h : x ∈ s := by simpa [hxy.symm] using h rw [s.erase_cons_tail hxy, map_cons, map_cons, ih h, erase_cons_tail_of_mem (mem_map_of_mem f h)] theorem map_surjective_of_surjective {f : α → β} (hf : Function.Surjective f) : Function.Surjective (map f) := by intro s induction' s using Multiset.induction_on with x s ih · exact ⟨0, map_zero _⟩ · obtain ⟨y, rfl⟩ := hf x obtain ⟨t, rfl⟩ := ih exact ⟨y ::ₘ t, map_cons _ _ _⟩ #align multiset.map_surjective_of_surjective Multiset.map_surjective_of_surjective /-! ### `Multiset.fold` -/ /-- `foldl f H b s` is the lift of the list operation `foldl f b l`, which folds `f` over the multiset. It is well defined when `f` is right-commutative, that is, `f (f b a₁) a₂ = f (f b a₂) a₁`. -/ def foldl (f : β → α → β) (H : RightCommutative f) (b : β) (s : Multiset α) : β := Quot.liftOn s (fun l => List.foldl f b l) fun _l₁ _l₂ p => p.foldl_eq H b #align multiset.foldl Multiset.foldl @[simp] theorem foldl_zero (f : β → α → β) (H b) : foldl f H b 0 = b := rfl #align multiset.foldl_zero Multiset.foldl_zero @[simp] theorem foldl_cons (f : β → α → β) (H b a s) : foldl f H b (a ::ₘ s) = foldl f H (f b a) s := Quot.inductionOn s fun _l => rfl #align multiset.foldl_cons Multiset.foldl_cons @[simp] theorem foldl_add (f : β → α → β) (H b s t) : foldl f H b (s + t) = foldl f H (foldl f H b s) t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => foldl_append _ _ _ _ #align multiset.foldl_add Multiset.foldl_add /-- `foldr f H b s` is the lift of the list operation `foldr f b l`, which folds `f` over the multiset. It is well defined when `f` is left-commutative, that is, `f a₁ (f a₂ b) = f a₂ (f a₁ b)`. -/ def foldr (f : α → β → β) (H : LeftCommutative f) (b : β) (s : Multiset α) : β := Quot.liftOn s (fun l => List.foldr f b l) fun _l₁ _l₂ p => p.foldr_eq H b #align multiset.foldr Multiset.foldr @[simp] theorem foldr_zero (f : α → β → β) (H b) : foldr f H b 0 = b := rfl #align multiset.foldr_zero Multiset.foldr_zero @[simp] theorem foldr_cons (f : α → β → β) (H b a s) : foldr f H b (a ::ₘ s) = f a (foldr f H b s) := Quot.inductionOn s fun _l => rfl #align multiset.foldr_cons Multiset.foldr_cons @[simp] theorem foldr_singleton (f : α → β → β) (H b a) : foldr f H b ({a} : Multiset α) = f a b := rfl #align multiset.foldr_singleton Multiset.foldr_singleton @[simp] theorem foldr_add (f : α → β → β) (H b s t) : foldr f H b (s + t) = foldr f H (foldr f H b t) s := Quotient.inductionOn₂ s t fun _l₁ _l₂ => foldr_append _ _ _ _ #align multiset.foldr_add Multiset.foldr_add @[simp] theorem coe_foldr (f : α → β → β) (H : LeftCommutative f) (b : β) (l : List α) : foldr f H b l = l.foldr f b := rfl #align multiset.coe_foldr Multiset.coe_foldr @[simp] theorem coe_foldl (f : β → α → β) (H : RightCommutative f) (b : β) (l : List α) : foldl f H b l = l.foldl f b := rfl #align multiset.coe_foldl Multiset.coe_foldl theorem coe_foldr_swap (f : α → β → β) (H : LeftCommutative f) (b : β) (l : List α) : foldr f H b l = l.foldl (fun x y => f y x) b := (congr_arg (foldr f H b) (coe_reverse l)).symm.trans <| foldr_reverse _ _ _ #align multiset.coe_foldr_swap Multiset.coe_foldr_swap theorem foldr_swap (f : α → β → β) (H : LeftCommutative f) (b : β) (s : Multiset α) : foldr f H b s = foldl (fun x y => f y x) (fun _x _y _z => (H _ _ _).symm) b s := Quot.inductionOn s fun _l => coe_foldr_swap _ _ _ _ #align multiset.foldr_swap Multiset.foldr_swap theorem foldl_swap (f : β → α → β) (H : RightCommutative f) (b : β) (s : Multiset α) : foldl f H b s = foldr (fun x y => f y x) (fun _x _y _z => (H _ _ _).symm) b s := (foldr_swap _ _ _ _).symm #align multiset.foldl_swap Multiset.foldl_swap theorem foldr_induction' (f : α → β → β) (H : LeftCommutative f) (x : β) (q : α → Prop) (p : β → Prop) (s : Multiset α) (hpqf : ∀ a b, q a → p b → p (f a b)) (px : p x) (q_s : ∀ a ∈ s, q a) : p (foldr f H x s) := by induction s using Multiset.induction with | empty => simpa | cons a s ihs => simp only [forall_mem_cons, foldr_cons] at q_s ⊢ exact hpqf _ _ q_s.1 (ihs q_s.2) #align multiset.foldr_induction' Multiset.foldr_induction' theorem foldr_induction (f : α → α → α) (H : LeftCommutative f) (x : α) (p : α → Prop) (s : Multiset α) (p_f : ∀ a b, p a → p b → p (f a b)) (px : p x) (p_s : ∀ a ∈ s, p a) : p (foldr f H x s) := foldr_induction' f H x p p s p_f px p_s #align multiset.foldr_induction Multiset.foldr_induction theorem foldl_induction' (f : β → α → β) (H : RightCommutative f) (x : β) (q : α → Prop) (p : β → Prop) (s : Multiset α) (hpqf : ∀ a b, q a → p b → p (f b a)) (px : p x) (q_s : ∀ a ∈ s, q a) : p (foldl f H x s) := by rw [foldl_swap] exact foldr_induction' (fun x y => f y x) (fun x y z => (H _ _ _).symm) x q p s hpqf px q_s #align multiset.foldl_induction' Multiset.foldl_induction' theorem foldl_induction (f : α → α → α) (H : RightCommutative f) (x : α) (p : α → Prop) (s : Multiset α) (p_f : ∀ a b, p a → p b → p (f b a)) (px : p x) (p_s : ∀ a ∈ s, p a) : p (foldl f H x s) := foldl_induction' f H x p p s p_f px p_s #align multiset.foldl_induction Multiset.foldl_induction /-! ### Map for partial functions -/ /-- Lift of the list `pmap` operation. Map a partial function `f` over a multiset `s` whose elements are all in the domain of `f`. -/ nonrec def pmap {p : α → Prop} (f : ∀ a, p a → β) (s : Multiset α) : (∀ a ∈ s, p a) → Multiset β := Quot.recOn' s (fun l H => ↑(pmap f l H)) fun l₁ l₂ (pp : l₁ ~ l₂) => funext fun H₂ : ∀ a ∈ l₂, p a => have H₁ : ∀ a ∈ l₁, p a := fun a h => H₂ a (pp.subset h) have : ∀ {s₂ e H}, @Eq.ndrec (Multiset α) l₁ (fun s => (∀ a ∈ s, p a) → Multiset β) (fun _ => ↑(pmap f l₁ H₁)) s₂ e H = ↑(pmap f l₁ H₁) := by intro s₂ e _; subst e; rfl this.trans <| Quot.sound <| pp.pmap f #align multiset.pmap Multiset.pmap @[simp] theorem coe_pmap {p : α → Prop} (f : ∀ a, p a → β) (l : List α) (H : ∀ a ∈ l, p a) : pmap f l H = l.pmap f H := rfl #align multiset.coe_pmap Multiset.coe_pmap @[simp] theorem pmap_zero {p : α → Prop} (f : ∀ a, p a → β) (h : ∀ a ∈ (0 : Multiset α), p a) : pmap f 0 h = 0 := rfl #align multiset.pmap_zero Multiset.pmap_zero @[simp] theorem pmap_cons {p : α → Prop} (f : ∀ a, p a → β) (a : α) (m : Multiset α) : ∀ h : ∀ b ∈ a ::ₘ m, p b, pmap f (a ::ₘ m) h = f a (h a (mem_cons_self a m)) ::ₘ pmap f m fun a ha => h a <| mem_cons_of_mem ha := Quotient.inductionOn m fun _l _h => rfl #align multiset.pmap_cons Multiset.pmap_cons /-- "Attach" a proof that `a ∈ s` to each element `a` in `s` to produce a multiset on `{x // x ∈ s}`. -/ def attach (s : Multiset α) : Multiset { x // x ∈ s } := pmap Subtype.mk s fun _a => id #align multiset.attach Multiset.attach @[simp] theorem coe_attach (l : List α) : @Eq (Multiset { x // x ∈ l }) (@attach α l) l.attach := rfl #align multiset.coe_attach Multiset.coe_attach theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Multiset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by induction' s using Quot.inductionOn with l a b exact List.sizeOf_lt_sizeOf_of_mem hx #align multiset.sizeof_lt_sizeof_of_mem Multiset.sizeOf_lt_sizeOf_of_mem theorem pmap_eq_map (p : α → Prop) (f : α → β) (s : Multiset α) : ∀ H, @pmap _ _ p (fun a _ => f a) s H = map f s := Quot.inductionOn s fun l H => congr_arg _ <| List.pmap_eq_map p f l H #align multiset.pmap_eq_map Multiset.pmap_eq_map theorem pmap_congr {p q : α → Prop} {f : ∀ a, p a → β} {g : ∀ a, q a → β} (s : Multiset α) : ∀ {H₁ H₂}, (∀ a ∈ s, ∀ (h₁ h₂), f a h₁ = g a h₂) → pmap f s H₁ = pmap g s H₂ := @(Quot.inductionOn s (fun l _H₁ _H₂ h => congr_arg _ <| List.pmap_congr l h)) #align multiset.pmap_congr Multiset.pmap_congr theorem map_pmap {p : α → Prop} (g : β → γ) (f : ∀ a, p a → β) (s) : ∀ H, map g (pmap f s H) = pmap (fun a h => g (f a h)) s H := Quot.inductionOn s fun l H => congr_arg _ <| List.map_pmap g f l H #align multiset.map_pmap Multiset.map_pmap theorem pmap_eq_map_attach {p : α → Prop} (f : ∀ a, p a → β) (s) : ∀ H, pmap f s H = s.attach.map fun x => f x.1 (H _ x.2) := Quot.inductionOn s fun l H => congr_arg _ <| List.pmap_eq_map_attach f l H #align multiset.pmap_eq_map_attach Multiset.pmap_eq_map_attach -- @[simp] -- Porting note: Left hand does not simplify theorem attach_map_val' (s : Multiset α) (f : α → β) : (s.attach.map fun i => f i.val) = s.map f := Quot.inductionOn s fun l => congr_arg _ <| List.attach_map_coe' l f #align multiset.attach_map_coe' Multiset.attach_map_val' #align multiset.attach_map_val' Multiset.attach_map_val' @[simp] theorem attach_map_val (s : Multiset α) : s.attach.map Subtype.val = s := (attach_map_val' _ _).trans s.map_id #align multiset.attach_map_coe Multiset.attach_map_val #align multiset.attach_map_val Multiset.attach_map_val @[simp] theorem mem_attach (s : Multiset α) : ∀ x, x ∈ s.attach := Quot.inductionOn s fun _l => List.mem_attach _ #align multiset.mem_attach Multiset.mem_attach @[simp] theorem mem_pmap {p : α → Prop} {f : ∀ a, p a → β} {s H b} : b ∈ pmap f s H ↔ ∃ (a : _) (h : a ∈ s), f a (H a h) = b := Quot.inductionOn s (fun _l _H => List.mem_pmap) H #align multiset.mem_pmap Multiset.mem_pmap @[simp] theorem card_pmap {p : α → Prop} (f : ∀ a, p a → β) (s H) : card (pmap f s H) = card s := Quot.inductionOn s (fun _l _H => length_pmap) H #align multiset.card_pmap Multiset.card_pmap @[simp] theorem card_attach {m : Multiset α} : card (attach m) = card m := card_pmap _ _ _ #align multiset.card_attach Multiset.card_attach @[simp] theorem attach_zero : (0 : Multiset α).attach = 0 := rfl #align multiset.attach_zero Multiset.attach_zero theorem attach_cons (a : α) (m : Multiset α) : (a ::ₘ m).attach = ⟨a, mem_cons_self a m⟩ ::ₘ m.attach.map fun p => ⟨p.1, mem_cons_of_mem p.2⟩ := Quotient.inductionOn m fun l => congr_arg _ <| congr_arg (List.cons _) <| by rw [List.map_pmap]; exact List.pmap_congr _ fun _ _ _ _ => Subtype.eq rfl #align multiset.attach_cons Multiset.attach_cons section DecidablePiExists variable {m : Multiset α} /-- If `p` is a decidable predicate, so is the predicate that all elements of a multiset satisfy `p`. -/ protected def decidableForallMultiset {p : α → Prop} [hp : ∀ a, Decidable (p a)] : Decidable (∀ a ∈ m, p a) := Quotient.recOnSubsingleton m fun l => decidable_of_iff (∀ a ∈ l, p a) <| by simp #align multiset.decidable_forall_multiset Multiset.decidableForallMultiset instance decidableDforallMultiset {p : ∀ a ∈ m, Prop} [_hp : ∀ (a) (h : a ∈ m), Decidable (p a h)] : Decidable (∀ (a) (h : a ∈ m), p a h) := @decidable_of_iff _ _ (Iff.intro (fun h a ha => h ⟨a, ha⟩ (mem_attach _ _)) fun h ⟨_a, _ha⟩ _ => h _ _) (@Multiset.decidableForallMultiset _ m.attach (fun a => p a.1 a.2) _) #align multiset.decidable_dforall_multiset Multiset.decidableDforallMultiset /-- decidable equality for functions whose domain is bounded by multisets -/ instance decidableEqPiMultiset {β : α → Type*} [h : ∀ a, DecidableEq (β a)] : DecidableEq (∀ a ∈ m, β a) := fun f g => decidable_of_iff (∀ (a) (h : a ∈ m), f a h = g a h) (by simp [Function.funext_iff]) #align multiset.decidable_eq_pi_multiset Multiset.decidableEqPiMultiset /-- If `p` is a decidable predicate, so is the existence of an element in a multiset satisfying `p`. -/ protected def decidableExistsMultiset {p : α → Prop} [DecidablePred p] : Decidable (∃ x ∈ m, p x) := Quotient.recOnSubsingleton m fun l => decidable_of_iff (∃ a ∈ l, p a) <| by simp #align multiset.decidable_exists_multiset Multiset.decidableExistsMultiset instance decidableDexistsMultiset {p : ∀ a ∈ m, Prop} [_hp : ∀ (a) (h : a ∈ m), Decidable (p a h)] : Decidable (∃ (a : _) (h : a ∈ m), p a h) := @decidable_of_iff _ _ (Iff.intro (fun ⟨⟨a, ha₁⟩, _, ha₂⟩ => ⟨a, ha₁, ha₂⟩) fun ⟨a, ha₁, ha₂⟩ => ⟨⟨a, ha₁⟩, mem_attach _ _, ha₂⟩) (@Multiset.decidableExistsMultiset { a // a ∈ m } m.attach (fun a => p a.1 a.2) _) #align multiset.decidable_dexists_multiset Multiset.decidableDexistsMultiset end DecidablePiExists /-! ### Subtraction -/ section variable [DecidableEq α] {s t u : Multiset α} {a b : α} /-- `s - t` is the multiset such that `count a (s - t) = count a s - count a t` for all `a` (note that it is truncated subtraction, so it is `0` if `count a t ≥ count a s`). -/ protected def sub (s t : Multiset α) : Multiset α := (Quotient.liftOn₂ s t fun l₁ l₂ => (l₁.diff l₂ : Multiset α)) fun _v₁ _v₂ _w₁ _w₂ p₁ p₂ => Quot.sound <| p₁.diff p₂ #align multiset.sub Multiset.sub instance : Sub (Multiset α) := ⟨Multiset.sub⟩ @[simp] theorem coe_sub (s t : List α) : (s - t : Multiset α) = (s.diff t : List α) := rfl #align multiset.coe_sub Multiset.coe_sub /-- This is a special case of `tsub_zero`, which should be used instead of this. This is needed to prove `OrderedSub (Multiset α)`. -/ protected theorem sub_zero (s : Multiset α) : s - 0 = s := Quot.inductionOn s fun _l => rfl #align multiset.sub_zero Multiset.sub_zero @[simp] theorem sub_cons (a : α) (s t : Multiset α) : s - a ::ₘ t = s.erase a - t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => congr_arg _ <| diff_cons _ _ _ #align multiset.sub_cons Multiset.sub_cons /-- This is a special case of `tsub_le_iff_right`, which should be used instead of this. This is needed to prove `OrderedSub (Multiset α)`. -/ protected theorem sub_le_iff_le_add : s - t ≤ u ↔ s ≤ u + t := by revert s exact @(Multiset.induction_on t (by simp [Multiset.sub_zero]) fun a t IH s => by simp [IH, erase_le_iff_le_cons]) #align multiset.sub_le_iff_le_add Multiset.sub_le_iff_le_add instance : OrderedSub (Multiset α) := ⟨fun _n _m _k => Multiset.sub_le_iff_le_add⟩ theorem cons_sub_of_le (a : α) {s t : Multiset α} (h : t ≤ s) : a ::ₘ s - t = a ::ₘ (s - t) := by rw [← singleton_add, ← singleton_add, add_tsub_assoc_of_le h] #align multiset.cons_sub_of_le Multiset.cons_sub_of_le theorem sub_eq_fold_erase (s t : Multiset α) : s - t = foldl erase erase_comm s t := Quotient.inductionOn₂ s t fun l₁ l₂ => by show ofList (l₁.diff l₂) = foldl erase erase_comm l₁ l₂ rw [diff_eq_foldl l₁ l₂] symm exact foldl_hom _ _ _ _ _ fun x y => rfl #align multiset.sub_eq_fold_erase Multiset.sub_eq_fold_erase @[simp] theorem card_sub {s t : Multiset α} (h : t ≤ s) : card (s - t) = card s - card t := Nat.eq_sub_of_add_eq $ by rw [← card_add, tsub_add_cancel_of_le h] #align multiset.card_sub Multiset.card_sub /-! ### Union -/ /-- `s ∪ t` is the lattice join operation with respect to the multiset `≤`. The multiplicity of `a` in `s ∪ t` is the maximum of the multiplicities in `s` and `t`. -/ def union (s t : Multiset α) : Multiset α := s - t + t #align multiset.union Multiset.union instance : Union (Multiset α) := ⟨union⟩ theorem union_def (s t : Multiset α) : s ∪ t = s - t + t := rfl #align multiset.union_def Multiset.union_def theorem le_union_left (s t : Multiset α) : s ≤ s ∪ t := le_tsub_add #align multiset.le_union_left Multiset.le_union_left theorem le_union_right (s t : Multiset α) : t ≤ s ∪ t := le_add_left _ _ #align multiset.le_union_right Multiset.le_union_right theorem eq_union_left : t ≤ s → s ∪ t = s := tsub_add_cancel_of_le #align multiset.eq_union_left Multiset.eq_union_left theorem union_le_union_right (h : s ≤ t) (u) : s ∪ u ≤ t ∪ u := add_le_add_right (tsub_le_tsub_right h _) u #align multiset.union_le_union_right Multiset.union_le_union_right theorem union_le (h₁ : s ≤ u) (h₂ : t ≤ u) : s ∪ t ≤ u := by rw [← eq_union_left h₂]; exact union_le_union_right h₁ t #align multiset.union_le Multiset.union_le @[simp] theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t := ⟨fun h => (mem_add.1 h).imp_left (mem_of_le tsub_le_self), (Or.elim · (mem_of_le <| le_union_left _ _) (mem_of_le <| le_union_right _ _))⟩ #align multiset.mem_union Multiset.mem_union @[simp] theorem map_union [DecidableEq β] {f : α → β} (finj : Function.Injective f) {s t : Multiset α} : map f (s ∪ t) = map f s ∪ map f t := Quotient.inductionOn₂ s t fun l₁ l₂ => congr_arg ofList (by rw [List.map_append f, List.map_diff finj]) #align multiset.map_union Multiset.map_union -- Porting note (#10756): new theorem @[simp] theorem zero_union : 0 ∪ s = s := by simp [union_def] -- Porting note (#10756): new theorem @[simp] theorem union_zero : s ∪ 0 = s := by simp [union_def] /-! ### Intersection -/ /-- `s ∩ t` is the lattice meet operation with respect to the multiset `≤`. The multiplicity of `a` in `s ∩ t` is the minimum of the multiplicities in `s` and `t`. -/ def inter (s t : Multiset α) : Multiset α := Quotient.liftOn₂ s t (fun l₁ l₂ => (l₁.bagInter l₂ : Multiset α)) fun _v₁ _v₂ _w₁ _w₂ p₁ p₂ => Quot.sound <| p₁.bagInter p₂ #align multiset.inter Multiset.inter instance : Inter (Multiset α) := ⟨inter⟩ @[simp] theorem inter_zero (s : Multiset α) : s ∩ 0 = 0 := Quot.inductionOn s fun l => congr_arg ofList l.bagInter_nil #align multiset.inter_zero Multiset.inter_zero @[simp] theorem zero_inter (s : Multiset α) : 0 ∩ s = 0 := Quot.inductionOn s fun l => congr_arg ofList l.nil_bagInter #align multiset.zero_inter Multiset.zero_inter @[simp] theorem cons_inter_of_pos {a} (s : Multiset α) {t} : a ∈ t → (a ::ₘ s) ∩ t = a ::ₘ s ∩ t.erase a := Quotient.inductionOn₂ s t fun _l₁ _l₂ h => congr_arg ofList <| cons_bagInter_of_pos _ h #align multiset.cons_inter_of_pos Multiset.cons_inter_of_pos @[simp] theorem cons_inter_of_neg {a} (s : Multiset α) {t} : a ∉ t → (a ::ₘ s) ∩ t = s ∩ t := Quotient.inductionOn₂ s t fun _l₁ _l₂ h => congr_arg ofList <| cons_bagInter_of_neg _ h #align multiset.cons_inter_of_neg Multiset.cons_inter_of_neg theorem inter_le_left (s t : Multiset α) : s ∩ t ≤ s := Quotient.inductionOn₂ s t fun _l₁ _l₂ => (bagInter_sublist_left _ _).subperm #align multiset.inter_le_left Multiset.inter_le_left theorem inter_le_right (s : Multiset α) : ∀ t, s ∩ t ≤ t := Multiset.induction_on s (fun t => (zero_inter t).symm ▸ zero_le _) fun a s IH t => if h : a ∈ t then by simpa [h] using cons_le_cons a (IH (t.erase a)) else by simp [h, IH] #align multiset.inter_le_right Multiset.inter_le_right theorem le_inter (h₁ : s ≤ t) (h₂ : s ≤ u) : s ≤ t ∩ u := by revert s u; refine @(Multiset.induction_on t ?_ fun a t IH => ?_) <;> intros s u h₁ h₂ · simpa only [zero_inter, nonpos_iff_eq_zero] using h₁ by_cases h : a ∈ u · rw [cons_inter_of_pos _ h, ← erase_le_iff_le_cons] exact IH (erase_le_iff_le_cons.2 h₁) (erase_le_erase _ h₂) · rw [cons_inter_of_neg _ h] exact IH ((le_cons_of_not_mem <| mt (mem_of_le h₂) h).1 h₁) h₂ #align multiset.le_inter Multiset.le_inter @[simp] theorem mem_inter : a ∈ s ∩ t ↔ a ∈ s ∧ a ∈ t := ⟨fun h => ⟨mem_of_le (inter_le_left _ _) h, mem_of_le (inter_le_right _ _) h⟩, fun ⟨h₁, h₂⟩ => by rw [← cons_erase h₁, cons_inter_of_pos _ h₂]; apply mem_cons_self⟩ #align multiset.mem_inter Multiset.mem_inter instance : Lattice (Multiset α) := { sup := (· ∪ ·) sup_le := @union_le _ _ le_sup_left := le_union_left le_sup_right := le_union_right inf := (· ∩ ·) le_inf := @le_inter _ _ inf_le_left := inter_le_left inf_le_right := inter_le_right } @[simp] theorem sup_eq_union (s t : Multiset α) : s ⊔ t = s ∪ t := rfl #align multiset.sup_eq_union Multiset.sup_eq_union @[simp] theorem inf_eq_inter (s t : Multiset α) : s ⊓ t = s ∩ t := rfl #align multiset.inf_eq_inter Multiset.inf_eq_inter @[simp] theorem le_inter_iff : s ≤ t ∩ u ↔ s ≤ t ∧ s ≤ u := le_inf_iff #align multiset.le_inter_iff Multiset.le_inter_iff @[simp] theorem union_le_iff : s ∪ t ≤ u ↔ s ≤ u ∧ t ≤ u := sup_le_iff #align multiset.union_le_iff Multiset.union_le_iff theorem union_comm (s t : Multiset α) : s ∪ t = t ∪ s := sup_comm _ _ #align multiset.union_comm Multiset.union_comm theorem inter_comm (s t : Multiset α) : s ∩ t = t ∩ s := inf_comm _ _ #align multiset.inter_comm Multiset.inter_comm theorem eq_union_right (h : s ≤ t) : s ∪ t = t := by rw [union_comm, eq_union_left h] #align multiset.eq_union_right Multiset.eq_union_right theorem union_le_union_left (h : s ≤ t) (u) : u ∪ s ≤ u ∪ t := sup_le_sup_left h _ #align multiset.union_le_union_left Multiset.union_le_union_left theorem union_le_add (s t : Multiset α) : s ∪ t ≤ s + t := union_le (le_add_right _ _) (le_add_left _ _) #align multiset.union_le_add Multiset.union_le_add theorem union_add_distrib (s t u : Multiset α) : s ∪ t + u = s + u ∪ (t + u) := by simpa [(· ∪ ·), union, eq_comm, add_assoc] using show s + u - (t + u) = s - t by rw [add_comm t, tsub_add_eq_tsub_tsub, add_tsub_cancel_right] #align multiset.union_add_distrib Multiset.union_add_distrib theorem add_union_distrib (s t u : Multiset α) : s + (t ∪ u) = s + t ∪ (s + u) := by rw [add_comm, union_add_distrib, add_comm s, add_comm s] #align multiset.add_union_distrib Multiset.add_union_distrib theorem cons_union_distrib (a : α) (s t : Multiset α) : a ::ₘ (s ∪ t) = a ::ₘ s ∪ a ::ₘ t := by simpa using add_union_distrib (a ::ₘ 0) s t #align multiset.cons_union_distrib Multiset.cons_union_distrib theorem inter_add_distrib (s t u : Multiset α) : s ∩ t + u = (s + u) ∩ (t + u) := by by_contra h cases' lt_iff_cons_le.1 (lt_of_le_of_ne (le_inter (add_le_add_right (inter_le_left s t) u) (add_le_add_right (inter_le_right s t) u)) h) with a hl rw [← cons_add] at hl exact not_le_of_lt (lt_cons_self (s ∩ t) a) (le_inter (le_of_add_le_add_right (le_trans hl (inter_le_left _ _))) (le_of_add_le_add_right (le_trans hl (inter_le_right _ _)))) #align multiset.inter_add_distrib Multiset.inter_add_distrib theorem add_inter_distrib (s t u : Multiset α) : s + t ∩ u = (s + t) ∩ (s + u) := by rw [add_comm, inter_add_distrib, add_comm s, add_comm s] #align multiset.add_inter_distrib Multiset.add_inter_distrib theorem cons_inter_distrib (a : α) (s t : Multiset α) : a ::ₘ s ∩ t = (a ::ₘ s) ∩ (a ::ₘ t) := by simp #align multiset.cons_inter_distrib Multiset.cons_inter_distrib theorem union_add_inter (s t : Multiset α) : s ∪ t + s ∩ t = s + t := by apply _root_.le_antisymm · rw [union_add_distrib] refine union_le (add_le_add_left (inter_le_right _ _) _) ?_ rw [add_comm] exact add_le_add_right (inter_le_left _ _) _ · rw [add_comm, add_inter_distrib] refine le_inter (add_le_add_right (le_union_right _ _) _) ?_ rw [add_comm] exact add_le_add_right (le_union_left _ _) _ #align multiset.union_add_inter Multiset.union_add_inter theorem sub_add_inter (s t : Multiset α) : s - t + s ∩ t = s := by rw [inter_comm] revert s; refine Multiset.induction_on t (by simp) fun a t IH s => ?_ by_cases h : a ∈ s · rw [cons_inter_of_pos _ h, sub_cons, add_cons, IH, cons_erase h] · rw [cons_inter_of_neg _ h, sub_cons, erase_of_not_mem h, IH] #align multiset.sub_add_inter Multiset.sub_add_inter theorem sub_inter (s t : Multiset α) : s - s ∩ t = s - t := add_right_cancel <| by rw [sub_add_inter s t, tsub_add_cancel_of_le (inter_le_left s t)] #align multiset.sub_inter Multiset.sub_inter end /-! ### `Multiset.filter` -/ section variable (p : α → Prop) [DecidablePred p] /-- `Filter p s` returns the elements in `s` (with the same multiplicities) which satisfy `p`, and removes the rest. -/ def filter (s : Multiset α) : Multiset α := Quot.liftOn s (fun l => (List.filter p l : Multiset α)) fun _l₁ _l₂ h => Quot.sound <| h.filter p #align multiset.filter Multiset.filter @[simp, norm_cast] lemma filter_coe (l : List α) : filter p l = l.filter p := rfl #align multiset.coe_filter Multiset.filter_coe @[simp] theorem filter_zero : filter p 0 = 0 := rfl #align multiset.filter_zero Multiset.filter_zero theorem filter_congr {p q : α → Prop} [DecidablePred p] [DecidablePred q] {s : Multiset α} : (∀ x ∈ s, p x ↔ q x) → filter p s = filter q s := Quot.inductionOn s fun _l h => congr_arg ofList <| filter_congr' <| by simpa using h #align multiset.filter_congr Multiset.filter_congr @[simp] theorem filter_add (s t : Multiset α) : filter p (s + t) = filter p s + filter p t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => congr_arg ofList <| filter_append _ _ #align multiset.filter_add Multiset.filter_add @[simp] theorem filter_le (s : Multiset α) : filter p s ≤ s := Quot.inductionOn s fun _l => (filter_sublist _).subperm #align multiset.filter_le Multiset.filter_le @[simp] theorem filter_subset (s : Multiset α) : filter p s ⊆ s := subset_of_le <| filter_le _ _ #align multiset.filter_subset Multiset.filter_subset theorem filter_le_filter {s t} (h : s ≤ t) : filter p s ≤ filter p t := leInductionOn h fun h => (h.filter (p ·)).subperm #align multiset.filter_le_filter Multiset.filter_le_filter theorem monotone_filter_left : Monotone (filter p) := fun _s _t => filter_le_filter p #align multiset.monotone_filter_left Multiset.monotone_filter_left theorem monotone_filter_right (s : Multiset α) ⦃p q : α → Prop⦄ [DecidablePred p] [DecidablePred q] (h : ∀ b, p b → q b) : s.filter p ≤ s.filter q := Quotient.inductionOn s fun l => (l.monotone_filter_right <| by simpa using h).subperm #align multiset.monotone_filter_right Multiset.monotone_filter_right variable {p} @[simp] theorem filter_cons_of_pos {a : α} (s) : p a → filter p (a ::ₘ s) = a ::ₘ filter p s := Quot.inductionOn s fun l h => congr_arg ofList <| List.filter_cons_of_pos l <| by simpa using h #align multiset.filter_cons_of_pos Multiset.filter_cons_of_pos @[simp] theorem filter_cons_of_neg {a : α} (s) : ¬p a → filter p (a ::ₘ s) = filter p s := Quot.inductionOn s fun l h => congr_arg ofList <| List.filter_cons_of_neg l <| by simpa using h #align multiset.filter_cons_of_neg Multiset.filter_cons_of_neg @[simp] theorem mem_filter {a : α} {s} : a ∈ filter p s ↔ a ∈ s ∧ p a := Quot.inductionOn s fun _l => by simpa using List.mem_filter (p := (p ·)) #align multiset.mem_filter Multiset.mem_filter theorem of_mem_filter {a : α} {s} (h : a ∈ filter p s) : p a := (mem_filter.1 h).2 #align multiset.of_mem_filter Multiset.of_mem_filter theorem mem_of_mem_filter {a : α} {s} (h : a ∈ filter p s) : a ∈ s := (mem_filter.1 h).1 #align multiset.mem_of_mem_filter Multiset.mem_of_mem_filter theorem mem_filter_of_mem {a : α} {l} (m : a ∈ l) (h : p a) : a ∈ filter p l := mem_filter.2 ⟨m, h⟩ #align multiset.mem_filter_of_mem Multiset.mem_filter_of_mem theorem filter_eq_self {s} : filter p s = s ↔ ∀ a ∈ s, p a := Quot.inductionOn s fun _l => Iff.trans ⟨fun h => (filter_sublist _).eq_of_length (@congr_arg _ _ _ _ card h), congr_arg ofList⟩ <| by simp #align multiset.filter_eq_self Multiset.filter_eq_self theorem filter_eq_nil {s} : filter p s = 0 ↔ ∀ a ∈ s, ¬p a := Quot.inductionOn s fun _l => Iff.trans ⟨fun h => eq_nil_of_length_eq_zero (@congr_arg _ _ _ _ card h), congr_arg ofList⟩ <| by simpa using List.filter_eq_nil (p := (p ·)) #align multiset.filter_eq_nil Multiset.filter_eq_nil theorem le_filter {s t} : s ≤ filter p t ↔ s ≤ t ∧ ∀ a ∈ s, p a := ⟨fun h => ⟨le_trans h (filter_le _ _), fun _a m => of_mem_filter (mem_of_le h m)⟩, fun ⟨h, al⟩ => filter_eq_self.2 al ▸ filter_le_filter p h⟩ #align multiset.le_filter Multiset.le_filter theorem filter_cons {a : α} (s : Multiset α) : filter p (a ::ₘ s) = (if p a then {a} else 0) + filter p s := by split_ifs with h · rw [filter_cons_of_pos _ h, singleton_add] · rw [filter_cons_of_neg _ h, zero_add] #align multiset.filter_cons Multiset.filter_cons theorem filter_singleton {a : α} (p : α → Prop) [DecidablePred p] : filter p {a} = if p a then {a} else ∅ := by simp only [singleton, filter_cons, filter_zero, add_zero, empty_eq_zero] #align multiset.filter_singleton Multiset.filter_singleton theorem filter_nsmul (s : Multiset α) (n : ℕ) : filter p (n • s) = n • filter p s := by refine s.induction_on ?_ ?_ · simp only [filter_zero, nsmul_zero] · intro a ha ih rw [nsmul_cons, filter_add, ih, filter_cons, nsmul_add] congr split_ifs with hp <;> · simp only [filter_eq_self, nsmul_zero, filter_eq_nil] intro b hb rwa [mem_singleton.mp (mem_of_mem_nsmul hb)] #align multiset.filter_nsmul Multiset.filter_nsmul variable (p) @[simp] theorem filter_sub [DecidableEq α] (s t : Multiset α) : filter p (s - t) = filter p s - filter p t := by revert s; refine Multiset.induction_on t (by simp) fun a t IH s => ?_ rw [sub_cons, IH] by_cases h : p a · rw [filter_cons_of_pos _ h, sub_cons] congr by_cases m : a ∈ s · rw [← cons_inj_right a, ← filter_cons_of_pos _ h, cons_erase (mem_filter_of_mem m h), cons_erase m] · rw [erase_of_not_mem m, erase_of_not_mem (mt mem_of_mem_filter m)] · rw [filter_cons_of_neg _ h] by_cases m : a ∈ s · rw [(by rw [filter_cons_of_neg _ h] : filter p (erase s a) = filter p (a ::ₘ erase s a)), cons_erase m] · rw [erase_of_not_mem m] #align multiset.filter_sub Multiset.filter_sub @[simp] theorem filter_union [DecidableEq α] (s t : Multiset α) : filter p (s ∪ t) = filter p s ∪ filter p t := by simp [(· ∪ ·), union] #align multiset.filter_union Multiset.filter_union @[simp] theorem filter_inter [DecidableEq α] (s t : Multiset α) : filter p (s ∩ t) = filter p s ∩ filter p t := le_antisymm (le_inter (filter_le_filter _ <| inter_le_left _ _) (filter_le_filter _ <| inter_le_right _ _)) <| le_filter.2 ⟨inf_le_inf (filter_le _ _) (filter_le _ _), fun _a h => of_mem_filter (mem_of_le (inter_le_left _ _) h)⟩ #align multiset.filter_inter Multiset.filter_inter @[simp] theorem filter_filter (q) [DecidablePred q] (s : Multiset α) : filter p (filter q s) = filter (fun a => p a ∧ q a) s := Quot.inductionOn s fun l => by simp #align multiset.filter_filter Multiset.filter_filter lemma filter_comm (q) [DecidablePred q] (s : Multiset α) : filter p (filter q s) = filter q (filter p s) := by simp [and_comm] #align multiset.filter_comm Multiset.filter_comm theorem filter_add_filter (q) [DecidablePred q] (s : Multiset α) : filter p s + filter q s = filter (fun a => p a ∨ q a) s + filter (fun a => p a ∧ q a) s := Multiset.induction_on s rfl fun a s IH => by by_cases p a <;> by_cases q a <;> simp [*] #align multiset.filter_add_filter Multiset.filter_add_filter theorem filter_add_not (s : Multiset α) : filter p s + filter (fun a => ¬p a) s = s := by rw [filter_add_filter, filter_eq_self.2, filter_eq_nil.2] · simp only [add_zero] · simp [Decidable.em, -Bool.not_eq_true, -not_and, not_and_or, or_comm] · simp only [Bool.not_eq_true, decide_eq_true_eq, Bool.eq_false_or_eq_true, decide_True, implies_true, Decidable.em] #align multiset.filter_add_not Multiset.filter_add_not theorem map_filter (f : β → α) (s : Multiset β) : filter p (map f s) = map f (filter (p ∘ f) s) := Quot.inductionOn s fun l => by simp [List.map_filter]; rfl #align multiset.map_filter Multiset.map_filter lemma map_filter' {f : α → β} (hf : Injective f) (s : Multiset α) [DecidablePred fun b => ∃ a, p a ∧ f a = b] : (s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [(· ∘ ·), map_filter, hf.eq_iff] #align multiset.map_filter' Multiset.map_filter' lemma card_filter_le_iff (s : Multiset α) (P : α → Prop) [DecidablePred P] (n : ℕ) : card (s.filter P) ≤ n ↔ ∀ s' ≤ s, n < card s' → ∃ a ∈ s', ¬ P a := by fconstructor · intro H s' hs' s'_card by_contra! rid have card := card_le_card (monotone_filter_left P hs') |>.trans H exact s'_card.not_le (filter_eq_self.mpr rid ▸ card) · contrapose! exact fun H ↦ ⟨s.filter P, filter_le _ _, H, fun a ha ↦ (mem_filter.mp ha).2⟩ /-! ### Simultaneously filter and map elements of a multiset -/ /-- `filterMap f s` is a combination filter/map operation on `s`. The function `f : α → Option β` is applied to each element of `s`; if `f a` is `some b` then `b` is added to the result, otherwise `a` is removed from the resulting multiset. -/ def filterMap (f : α → Option β) (s : Multiset α) : Multiset β := Quot.liftOn s (fun l => (List.filterMap f l : Multiset β)) fun _l₁ _l₂ h => Quot.sound <| h.filterMap f #align multiset.filter_map Multiset.filterMap @[simp, norm_cast] lemma filterMap_coe (f : α → Option β) (l : List α) : filterMap f l = l.filterMap f := rfl #align multiset.coe_filter_map Multiset.filterMap_coe @[simp] theorem filterMap_zero (f : α → Option β) : filterMap f 0 = 0 := rfl #align multiset.filter_map_zero Multiset.filterMap_zero @[simp] theorem filterMap_cons_none {f : α → Option β} (a : α) (s : Multiset α) (h : f a = none) : filterMap f (a ::ₘ s) = filterMap f s := Quot.inductionOn s fun l => congr_arg ofList <| List.filterMap_cons_none a l h #align multiset.filter_map_cons_none Multiset.filterMap_cons_none @[simp] theorem filterMap_cons_some (f : α → Option β) (a : α) (s : Multiset α) {b : β} (h : f a = some b) : filterMap f (a ::ₘ s) = b ::ₘ filterMap f s := Quot.inductionOn s fun l => congr_arg ofList <| List.filterMap_cons_some f a l h #align multiset.filter_map_cons_some Multiset.filterMap_cons_some theorem filterMap_eq_map (f : α → β) : filterMap (some ∘ f) = map f := funext fun s => Quot.inductionOn s fun l => congr_arg ofList <| congr_fun (List.filterMap_eq_map f) l #align multiset.filter_map_eq_map Multiset.filterMap_eq_map theorem filterMap_eq_filter : filterMap (Option.guard p) = filter p := funext fun s => Quot.inductionOn s fun l => congr_arg ofList <| by rw [← List.filterMap_eq_filter] congr; funext a; simp #align multiset.filter_map_eq_filter Multiset.filterMap_eq_filter theorem filterMap_filterMap (f : α → Option β) (g : β → Option γ) (s : Multiset α) : filterMap g (filterMap f s) = filterMap (fun x => (f x).bind g) s := Quot.inductionOn s fun l => congr_arg ofList <| List.filterMap_filterMap f g l #align multiset.filter_map_filter_map Multiset.filterMap_filterMap theorem map_filterMap (f : α → Option β) (g : β → γ) (s : Multiset α) : map g (filterMap f s) = filterMap (fun x => (f x).map g) s := Quot.inductionOn s fun l => congr_arg ofList <| List.map_filterMap f g l #align multiset.map_filter_map Multiset.map_filterMap theorem filterMap_map (f : α → β) (g : β → Option γ) (s : Multiset α) : filterMap g (map f s) = filterMap (g ∘ f) s := Quot.inductionOn s fun l => congr_arg ofList <| List.filterMap_map f g l #align multiset.filter_map_map Multiset.filterMap_map theorem filter_filterMap (f : α → Option β) (p : β → Prop) [DecidablePred p] (s : Multiset α) : filter p (filterMap f s) = filterMap (fun x => (f x).filter p) s := Quot.inductionOn s fun l => congr_arg ofList <| List.filter_filterMap f p l #align multiset.filter_filter_map Multiset.filter_filterMap theorem filterMap_filter (f : α → Option β) (s : Multiset α) : filterMap f (filter p s) = filterMap (fun x => if p x then f x else none) s := Quot.inductionOn s fun l => congr_arg ofList <| by simpa using List.filterMap_filter p f l #align multiset.filter_map_filter Multiset.filterMap_filter @[simp] theorem filterMap_some (s : Multiset α) : filterMap some s = s := Quot.inductionOn s fun l => congr_arg ofList <| List.filterMap_some l #align multiset.filter_map_some Multiset.filterMap_some @[simp] theorem mem_filterMap (f : α → Option β) (s : Multiset α) {b : β} : b ∈ filterMap f s ↔ ∃ a, a ∈ s ∧ f a = some b := Quot.inductionOn s fun l => List.mem_filterMap f l #align multiset.mem_filter_map Multiset.mem_filterMap theorem map_filterMap_of_inv (f : α → Option β) (g : β → α) (H : ∀ x : α, (f x).map g = some x) (s : Multiset α) : map g (filterMap f s) = s := Quot.inductionOn s fun l => congr_arg ofList <| List.map_filterMap_of_inv f g H l #align multiset.map_filter_map_of_inv Multiset.map_filterMap_of_inv theorem filterMap_le_filterMap (f : α → Option β) {s t : Multiset α} (h : s ≤ t) : filterMap f s ≤ filterMap f t := leInductionOn h fun h => (h.filterMap _).subperm #align multiset.filter_map_le_filter_map Multiset.filterMap_le_filterMap /-! ### countP -/ /-- `countP p s` counts the number of elements of `s` (with multiplicity) that satisfy `p`. -/ def countP (s : Multiset α) : ℕ := Quot.liftOn s (List.countP p) fun _l₁ _l₂ => Perm.countP_eq (p ·) #align multiset.countp Multiset.countP @[simp] theorem coe_countP (l : List α) : countP p l = l.countP p := rfl #align multiset.coe_countp Multiset.coe_countP @[simp] theorem countP_zero : countP p 0 = 0 := rfl #align multiset.countp_zero Multiset.countP_zero variable {p} @[simp] theorem countP_cons_of_pos {a : α} (s) : p a → countP p (a ::ₘ s) = countP p s + 1 := Quot.inductionOn s <| by simpa using List.countP_cons_of_pos (p ·) #align multiset.countp_cons_of_pos Multiset.countP_cons_of_pos @[simp] theorem countP_cons_of_neg {a : α} (s) : ¬p a → countP p (a ::ₘ s) = countP p s := Quot.inductionOn s <| by simpa using List.countP_cons_of_neg (p ·) #align multiset.countp_cons_of_neg Multiset.countP_cons_of_neg variable (p) theorem countP_cons (b : α) (s) : countP p (b ::ₘ s) = countP p s + if p b then 1 else 0 := Quot.inductionOn s <| by simp [List.countP_cons] #align multiset.countp_cons Multiset.countP_cons theorem countP_eq_card_filter (s) : countP p s = card (filter p s) := Quot.inductionOn s fun l => l.countP_eq_length_filter (p ·) #align multiset.countp_eq_card_filter Multiset.countP_eq_card_filter theorem countP_le_card (s) : countP p s ≤ card s := Quot.inductionOn s fun _l => countP_le_length (p ·) #align multiset.countp_le_card Multiset.countP_le_card @[simp] theorem countP_add (s t) : countP p (s + t) = countP p s + countP p t := by simp [countP_eq_card_filter] #align multiset.countp_add Multiset.countP_add @[simp] theorem countP_nsmul (s) (n : ℕ) : countP p (n • s) = n * countP p s := by induction n <;> simp [*, succ_nsmul, succ_mul, zero_nsmul] #align multiset.countp_nsmul Multiset.countP_nsmul theorem card_eq_countP_add_countP (s) : card s = countP p s + countP (fun x => ¬p x) s := Quot.inductionOn s fun l => by simp [l.length_eq_countP_add_countP p] #align multiset.card_eq_countp_add_countp Multiset.card_eq_countP_add_countP /-- `countP p`, the number of elements of a multiset satisfying `p`, promoted to an `AddMonoidHom`. -/ def countPAddMonoidHom : Multiset α →+ ℕ where toFun := countP p map_zero' := countP_zero _ map_add' := countP_add _ #align multiset.countp_add_monoid_hom Multiset.countPAddMonoidHom @[simp] theorem coe_countPAddMonoidHom : (countPAddMonoidHom p : Multiset α → ℕ) = countP p := rfl #align multiset.coe_countp_add_monoid_hom Multiset.coe_countPAddMonoidHom @[simp] theorem countP_sub [DecidableEq α] {s t : Multiset α} (h : t ≤ s) : countP p (s - t) = countP p s - countP p t := by simp [countP_eq_card_filter, h, filter_le_filter] #align multiset.countp_sub Multiset.countP_sub theorem countP_le_of_le {s t} (h : s ≤ t) : countP p s ≤ countP p t := by simpa [countP_eq_card_filter] using card_le_card (filter_le_filter p h) #align multiset.countp_le_of_le Multiset.countP_le_of_le @[simp] theorem countP_filter (q) [DecidablePred q] (s : Multiset α) : countP p (filter q s) = countP (fun a => p a ∧ q a) s := by simp [countP_eq_card_filter] #align multiset.countp_filter Multiset.countP_filter theorem countP_eq_countP_filter_add (s) (p q : α → Prop) [DecidablePred p] [DecidablePred q] : countP p s = (filter q s).countP p + (filter (fun a => ¬q a) s).countP p := Quot.inductionOn s fun l => by convert l.countP_eq_countP_filter_add (p ·) (q ·) simp [countP_filter] #align multiset.countp_eq_countp_filter_add Multiset.countP_eq_countP_filter_add @[simp] theorem countP_True {s : Multiset α} : countP (fun _ => True) s = card s := Quot.inductionOn s fun _l => List.countP_true #align multiset.countp_true Multiset.countP_True @[simp] theorem countP_False {s : Multiset α} : countP (fun _ => False) s = 0 := Quot.inductionOn s fun _l => List.countP_false #align multiset.countp_false Multiset.countP_False theorem countP_map (f : α → β) (s : Multiset α) (p : β → Prop) [DecidablePred p] : countP p (map f s) = card (s.filter fun a => p (f a)) := by refine Multiset.induction_on s ?_ fun a t IH => ?_ · rw [map_zero, countP_zero, filter_zero, card_zero] · rw [map_cons, countP_cons, IH, filter_cons, card_add, apply_ite card, card_zero, card_singleton, add_comm] #align multiset.countp_map Multiset.countP_map -- Porting note: `Lean.Internal.coeM` forces us to type-ascript `{a // a ∈ s}` lemma countP_attach (s : Multiset α) : s.attach.countP (fun a : {a // a ∈ s} ↦ p a) = s.countP p := Quotient.inductionOn s fun l => by simp only [quot_mk_to_coe, coe_countP] -- Porting note: was -- rw [quot_mk_to_coe, coe_attach, coe_countP] -- exact List.countP_attach _ _ rw [coe_attach] refine (coe_countP _ _).trans ?_ convert List.countP_attach _ _ rfl #align multiset.countp_attach Multiset.countP_attach lemma filter_attach (s : Multiset α) (p : α → Prop) [DecidablePred p] : (s.attach.filter fun a : {a // a ∈ s} ↦ p ↑a) = (s.filter p).attach.map (Subtype.map id fun _ ↦ Multiset.mem_of_mem_filter) := Quotient.inductionOn s fun l ↦ congr_arg _ (List.filter_attach l p) #align multiset.filter_attach Multiset.filter_attach variable {p} theorem countP_pos {s} : 0 < countP p s ↔ ∃ a ∈ s, p a := Quot.inductionOn s fun _l => by simpa using List.countP_pos (p ·) #align multiset.countp_pos Multiset.countP_pos theorem countP_eq_zero {s} : countP p s = 0 ↔ ∀ a ∈ s, ¬p a := Quot.inductionOn s fun _l => by simp [List.countP_eq_zero] #align multiset.countp_eq_zero Multiset.countP_eq_zero theorem countP_eq_card {s} : countP p s = card s ↔ ∀ a ∈ s, p a := Quot.inductionOn s fun _l => by simp [List.countP_eq_length] #align multiset.countp_eq_card Multiset.countP_eq_card theorem countP_pos_of_mem {s a} (h : a ∈ s) (pa : p a) : 0 < countP p s := countP_pos.2 ⟨_, h, pa⟩ #align multiset.countp_pos_of_mem Multiset.countP_pos_of_mem theorem countP_congr {s s' : Multiset α} (hs : s = s') {p p' : α → Prop} [DecidablePred p] [DecidablePred p'] (hp : ∀ x ∈ s, p x = p' x) : s.countP p = s'.countP p' := by revert hs hp exact Quot.induction_on₂ s s' (fun l l' hs hp => by simp only [quot_mk_to_coe'', coe_eq_coe] at hs apply hs.countP_congr simpa using hp) #align multiset.countp_congr Multiset.countP_congr end /-! ### Multiplicity of an element -/ section variable [DecidableEq α] {s : Multiset α} /-- `count a s` is the multiplicity of `a` in `s`. -/ def count (a : α) : Multiset α → ℕ := countP (a = ·) #align multiset.count Multiset.count @[simp] theorem coe_count (a : α) (l : List α) : count a (ofList l) = l.count a := by simp_rw [count, List.count, coe_countP (a = ·) l, @eq_comm _ a] rfl #align multiset.coe_count Multiset.coe_count @[simp, nolint simpNF] -- Porting note (#10618): simp can prove this at EOF, but not right now theorem count_zero (a : α) : count a 0 = 0 := rfl #align multiset.count_zero Multiset.count_zero @[simp] theorem count_cons_self (a : α) (s : Multiset α) : count a (a ::ₘ s) = count a s + 1 := countP_cons_of_pos _ <| rfl #align multiset.count_cons_self Multiset.count_cons_self @[simp] theorem count_cons_of_ne {a b : α} (h : a ≠ b) (s : Multiset α) : count a (b ::ₘ s) = count a s := countP_cons_of_neg _ <| h #align multiset.count_cons_of_ne Multiset.count_cons_of_ne theorem count_le_card (a : α) (s) : count a s ≤ card s := countP_le_card _ _ #align multiset.count_le_card Multiset.count_le_card theorem count_le_of_le (a : α) {s t} : s ≤ t → count a s ≤ count a t := countP_le_of_le _ #align multiset.count_le_of_le Multiset.count_le_of_le theorem count_le_count_cons (a b : α) (s : Multiset α) : count a s ≤ count a (b ::ₘ s) := count_le_of_le _ (le_cons_self _ _) #align multiset.count_le_count_cons Multiset.count_le_count_cons theorem count_cons (a b : α) (s : Multiset α) : count a (b ::ₘ s) = count a s + if a = b then 1 else 0 := countP_cons (a = ·) _ _ #align multiset.count_cons Multiset.count_cons theorem count_singleton_self (a : α) : count a ({a} : Multiset α) = 1 := count_eq_one_of_mem (nodup_singleton a) <| mem_singleton_self a #align multiset.count_singleton_self Multiset.count_singleton_self theorem count_singleton (a b : α) : count a ({b} : Multiset α) = if a = b then 1 else 0 := by simp only [count_cons, ← cons_zero, count_zero, zero_add] #align multiset.count_singleton Multiset.count_singleton @[simp] theorem count_add (a : α) : ∀ s t, count a (s + t) = count a s + count a t := countP_add _ #align multiset.count_add Multiset.count_add /-- `count a`, the multiplicity of `a` in a multiset, promoted to an `AddMonoidHom`. -/ def countAddMonoidHom (a : α) : Multiset α →+ ℕ := countPAddMonoidHom (a = ·) #align multiset.count_add_monoid_hom Multiset.countAddMonoidHom @[simp] theorem coe_countAddMonoidHom {a : α} : (countAddMonoidHom a : Multiset α → ℕ) = count a := rfl #align multiset.coe_count_add_monoid_hom Multiset.coe_countAddMonoidHom @[simp] theorem count_nsmul (a : α) (n s) : count a (n • s) = n * count a s := by induction n <;> simp [*, succ_nsmul, succ_mul, zero_nsmul] #align multiset.count_nsmul Multiset.count_nsmul @[simp] lemma count_attach (a : {x // x ∈ s}) : s.attach.count a = s.count ↑a := Eq.trans (countP_congr rfl fun _ _ => by simp [Subtype.ext_iff]) <| countP_attach _ _ #align multiset.count_attach Multiset.count_attach theorem count_pos {a : α} {s : Multiset α} : 0 < count a s ↔ a ∈ s := by simp [count, countP_pos] #align multiset.count_pos Multiset.count_pos theorem one_le_count_iff_mem {a : α} {s : Multiset α} : 1 ≤ count a s ↔ a ∈ s := by rw [succ_le_iff, count_pos] #align multiset.one_le_count_iff_mem Multiset.one_le_count_iff_mem @[simp] theorem count_eq_zero_of_not_mem {a : α} {s : Multiset α} (h : a ∉ s) : count a s = 0 := by_contradiction fun h' => h <| count_pos.1 (Nat.pos_of_ne_zero h') #align multiset.count_eq_zero_of_not_mem Multiset.count_eq_zero_of_not_mem lemma count_ne_zero {a : α} : count a s ≠ 0 ↔ a ∈ s := Nat.pos_iff_ne_zero.symm.trans count_pos #align multiset.count_ne_zero Multiset.count_ne_zero @[simp] lemma count_eq_zero {a : α} : count a s = 0 ↔ a ∉ s := count_ne_zero.not_right #align multiset.count_eq_zero Multiset.count_eq_zero theorem count_eq_card {a : α} {s} : count a s = card s ↔ ∀ x ∈ s, a = x := by simp [countP_eq_card, count, @eq_comm _ a] #align multiset.count_eq_card Multiset.count_eq_card @[simp] theorem count_replicate_self (a : α) (n : ℕ) : count a (replicate n a) = n := by convert List.count_replicate_self a n rw [← coe_count, coe_replicate] #align multiset.count_replicate_self Multiset.count_replicate_self theorem count_replicate (a b : α) (n : ℕ) : count a (replicate n b) = if a = b then n else 0 := by convert List.count_replicate a b n rw [← coe_count, coe_replicate] #align multiset.count_replicate Multiset.count_replicate @[simp] theorem count_erase_self (a : α) (s : Multiset α) : count a (erase s a) = count a s - 1 := Quotient.inductionOn s fun l => by convert List.count_erase_self a l <;> rw [← coe_count] <;> simp #align multiset.count_erase_self Multiset.count_erase_self @[simp] theorem count_erase_of_ne {a b : α} (ab : a ≠ b) (s : Multiset α) : count a (erase s b) = count a s := Quotient.inductionOn s fun l => by convert List.count_erase_of_ne ab l <;> rw [← coe_count] <;> simp #align multiset.count_erase_of_ne Multiset.count_erase_of_ne @[simp] theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by revert s; refine Multiset.induction_on t (by simp) fun b t IH s => ?_ rw [sub_cons, IH] rcases Decidable.eq_or_ne a b with rfl | ab · rw [count_erase_self, count_cons_self, Nat.sub_sub, add_comm] · rw [count_erase_of_ne ab, count_cons_of_ne ab] #align multiset.count_sub Multiset.count_sub @[simp] theorem count_union (a : α) (s t : Multiset α) : count a (s ∪ t) = max (count a s) (count a t) := by simp [(· ∪ ·), union, Nat.sub_add_eq_max] #align multiset.count_union Multiset.count_union @[simp] theorem count_inter (a : α) (s t : Multiset α) : count a (s ∩ t) = min (count a s) (count a t) := by apply @Nat.add_left_cancel (count a (s - t)) rw [← count_add, sub_add_inter, count_sub, Nat.sub_add_min_cancel] #align multiset.count_inter Multiset.count_inter theorem le_count_iff_replicate_le {a : α} {s : Multiset α} {n : ℕ} : n ≤ count a s ↔ replicate n a ≤ s := Quot.inductionOn s fun _l => by simp only [quot_mk_to_coe'', mem_coe, coe_count] exact le_count_iff_replicate_sublist.trans replicate_le_coe.symm #align multiset.le_count_iff_replicate_le Multiset.le_count_iff_replicate_le @[simp] theorem count_filter_of_pos {p} [DecidablePred p] {a} {s : Multiset α} (h : p a) : count a (filter p s) = count a s := Quot.inductionOn s fun _l => by simp only [quot_mk_to_coe'', filter_coe, mem_coe, coe_count, decide_eq_true_eq] apply count_filter simpa using h #align multiset.count_filter_of_pos Multiset.count_filter_of_pos @[simp] theorem count_filter_of_neg {p} [DecidablePred p] {a} {s : Multiset α} (h : ¬p a) : count a (filter p s) = 0 := Multiset.count_eq_zero_of_not_mem fun t => h (of_mem_filter t) #align multiset.count_filter_of_neg Multiset.count_filter_of_neg theorem count_filter {p} [DecidablePred p] {a} {s : Multiset α} : count a (filter p s) = if p a then count a s else 0 := by split_ifs with h · exact count_filter_of_pos h · exact count_filter_of_neg h #align multiset.count_filter Multiset.count_filter theorem ext {s t : Multiset α} : s = t ↔ ∀ a, count a s = count a t := Quotient.inductionOn₂ s t fun _l₁ _l₂ => Quotient.eq.trans <| by simp only [quot_mk_to_coe, filter_coe, mem_coe, coe_count, decide_eq_true_eq] apply perm_iff_count #align multiset.ext Multiset.ext @[ext] theorem ext' {s t : Multiset α} : (∀ a, count a s = count a t) → s = t := ext.2 #align multiset.ext' Multiset.ext' @[simp] theorem coe_inter (s t : List α) : (s ∩ t : Multiset α) = (s.bagInter t : List α) := by ext; simp #align multiset.coe_inter Multiset.coe_inter theorem le_iff_count {s t : Multiset α} : s ≤ t ↔ ∀ a, count a s ≤ count a t := ⟨fun h a => count_le_of_le a h, fun al => by rw [← (ext.2 fun a => by simp [max_eq_right (al a)] : s ∪ t = t)]; apply le_union_left⟩ #align multiset.le_iff_count Multiset.le_iff_count instance : DistribLattice (Multiset α) := { le_sup_inf := fun s t u => le_of_eq <| Eq.symm <| ext.2 fun a => by simp only [max_min_distrib_left, Multiset.count_inter, Multiset.sup_eq_union, Multiset.count_union, Multiset.inf_eq_inter] } theorem count_map {α β : Type*} (f : α → β) (s : Multiset α) [DecidableEq β] (b : β) : count b (map f s) = card (s.filter fun a => b = f a) := by simp [Bool.beq_eq_decide_eq, eq_comm, count, countP_map] #align multiset.count_map Multiset.count_map /-- `Multiset.map f` preserves `count` if `f` is injective on the set of elements contained in the multiset -/ theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x := by suffices (filter (fun a : α => f x = f a) s).count x = card (filter (fun a : α => f x = f a) s) by rw [count, countP_map, ← this] exact count_filter_of_pos <| rfl · rw [eq_replicate_card.2 fun b hb => (hf H (mem_filter.1 hb).left _).symm] · simp only [count_replicate, eq_self_iff_true, if_true, card_replicate] · simp only [mem_filter, beq_iff_eq, and_imp, @eq_comm _ (f x), imp_self, implies_true] #align multiset.count_map_eq_count Multiset.count_map_eq_count /-- `Multiset.map f` preserves `count` if `f` is injective -/ theorem count_map_eq_count' [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Function.Injective f) (x : α) : (s.map f).count (f x) = s.count x := by by_cases H : x ∈ s · exact count_map_eq_count f _ hf.injOn _ H · rw [count_eq_zero_of_not_mem H, count_eq_zero, mem_map] rintro ⟨k, hks, hkx⟩ rw [hf hkx] at hks contradiction #align multiset.count_map_eq_count' Multiset.count_map_eq_count' @[simp] theorem sub_filter_eq_filter_not [DecidableEq α] (p) [DecidablePred p] (s : Multiset α) : s - s.filter p = s.filter (fun a ↦ ¬ p a) := by ext a; by_cases h : p a <;> simp [h] theorem filter_eq' (s : Multiset α) (b : α) : s.filter (· = b) = replicate (count b s) b := Quotient.inductionOn s fun l => by simp only [quot_mk_to_coe, filter_coe, mem_coe, coe_count] rw [List.filter_eq l b, coe_replicate] #align multiset.filter_eq' Multiset.filter_eq' theorem filter_eq (s : Multiset α) (b : α) : s.filter (Eq b) = replicate (count b s) b := by simp_rw [← filter_eq', eq_comm] #align multiset.filter_eq Multiset.filter_eq @[simp] theorem replicate_inter (n : ℕ) (x : α) (s : Multiset α) : replicate n x ∩ s = replicate (min n (s.count x)) x := by ext y rw [count_inter, count_replicate, count_replicate] by_cases h : y = x · simp only [h, if_true] · simp only [h, if_false, Nat.zero_min] #align multiset.replicate_inter Multiset.replicate_inter @[simp] theorem inter_replicate (s : Multiset α) (n : ℕ) (x : α) : s ∩ replicate n x = replicate (min (s.count x) n) x := by rw [inter_comm, replicate_inter, min_comm] #align multiset.inter_replicate Multiset.inter_replicate theorem erase_attach_map_val (s : Multiset α) (x : {x // x ∈ s}) : (s.attach.erase x).map (↑) = s.erase x := by rw [Multiset.map_erase _ val_injective, attach_map_val] theorem erase_attach_map (s : Multiset α) (f : α → β) (x : {x // x ∈ s}) : (s.attach.erase x).map (fun j : {x // x ∈ s} ↦ f j) = (s.erase x).map f := by simp only [← Function.comp_apply (f := f)] rw [← map_map, erase_attach_map_val] end @[ext] theorem addHom_ext [AddZeroClass β] ⦃f g : Multiset α →+ β⦄ (h : ∀ x, f {x} = g {x}) : f = g := by ext s induction' s using Multiset.induction_on with a s ih · simp only [_root_.map_zero] · simp only [← singleton_add, _root_.map_add, ih, h] #align multiset.add_hom_ext Multiset.addHom_ext section Embedding @[simp] theorem map_le_map_iff {f : α → β} (hf : Function.Injective f) {s t : Multiset α} : s.map f ≤ t.map f ↔ s ≤ t := by classical refine ⟨fun h => le_iff_count.mpr fun a => ?_, map_le_map⟩ simpa [count_map_eq_count' f _ hf] using le_iff_count.mp h (f a) #align multiset.map_le_map_iff Multiset.map_le_map_iff /-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a multiset to its image under `f`. -/ @[simps!] def mapEmbedding (f : α ↪ β) : Multiset α ↪o Multiset β := OrderEmbedding.ofMapLEIff (map f) fun _ _ => map_le_map_iff f.inj' #align multiset.map_embedding Multiset.mapEmbedding #align multiset.map_embedding_apply Multiset.mapEmbedding_apply end Embedding
Mathlib/Data/Multiset/Basic.lean
2,723
2,724
theorem count_eq_card_filter_eq [DecidableEq α] (s : Multiset α) (a : α) : s.count a = card (s.filter (a = ·)) := by
rw [count, countP_eq_card_filter]
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Polynomial.Nilpotent /-! # Polynomials over an irreducible ring This file contains results about the polynomials over an irreducible ring (i.e. a ring with only one minimal prime ideal, equivalently, whose spectrum is an irreducible topological space). ## Main results - `Polynomial.Monic.irreducible_of_irreducible_map_of_isPrime_nilradical`: a monic polynomial over an irreducible ring is irreducible if it is irreducible after mapping into an integral domain. A generalization to `Polynomial.Monic.irreducible_of_irreducible_map`. ## Tags polynomial, irreducible ring, nilradical, prime ideal -/ open scoped Classical Polynomial open Polynomial noncomputable section /-- A polynomial over an irreducible ring `R` is irreducible if it is monic and irreducible after mapping into an integral domain `S` (https://math.stackexchange.com/a/4843432/235999). A generalization to `Polynomial.Monic.irreducible_of_irreducible_map`. -/
Mathlib/RingTheory/Polynomial/IrreducibleRing.lean
37
61
theorem Polynomial.Monic.irreducible_of_irreducible_map_of_isPrime_nilradical {R S : Type*} [CommRing R] [(nilradical R).IsPrime] [CommRing S] [IsDomain S] (φ : R →+* S) (f : R[X]) (hm : f.Monic) (hi : Irreducible (f.map φ)) : Irreducible f := by
let R' := R ⧸ nilradical R let ψ : R' →+* S := Ideal.Quotient.lift (nilradical R) φ (haveI := RingHom.ker_isPrime φ; nilradical_le_prime (RingHom.ker φ)) let ι := algebraMap R R' rw [show φ = ψ.comp ι from rfl, ← map_map] at hi replace hi := hm.map ι |>.irreducible_of_irreducible_map _ _ hi refine ⟨fun h ↦ hi.1 <| (mapRingHom ι).isUnit_map h, fun a b h ↦ ?_⟩ wlog hb : IsUnit (b.map ι) generalizing a b · exact (this b a (mul_comm a b ▸ h) (hi.2 _ _ (by rw [h, Polynomial.map_mul]) |>.resolve_right hb)).symm have hn (i : ℕ) (hi : i ≠ 0) : IsNilpotent (b.coeff i) := by obtain ⟨_, _, h⟩ := Polynomial.isUnit_iff.1 hb simpa only [coeff_map, coeff_C, hi, ite_false, ← RingHom.mem_ker, show RingHom.ker ι = nilradical R from Ideal.mk_ker] using congr(coeff $(h.symm) i) refine .inr <| isUnit_of_coeff_isUnit_isNilpotent (isUnit_of_mul_isUnit_right (x := a.coeff f.natDegree) <| (IsUnit.neg_iff _).1 ?_) hn have hc : f.leadingCoeff = _ := congr(coeff $h f.natDegree) rw [hm, coeff_mul, Finset.Nat.sum_antidiagonal_eq_sum_range_succ fun i j ↦ a.coeff i * b.coeff j, Finset.sum_range_succ, ← sub_eq_iff_eq_add, Nat.sub_self] at hc rw [← add_sub_cancel_left 1 (-(_ * _)), ← sub_eq_add_neg, hc] exact IsNilpotent.isUnit_sub_one <| show _ ∈ nilradical R from sum_mem fun i hi ↦ Ideal.mul_mem_left _ _ <| hn _ <| Nat.sub_ne_zero_of_lt (List.mem_range.1 hi)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import measure_theory.measure.measure_space from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace open scoped Classical symmDiff open Topology Filter ENNReal NNReal Interval MeasureTheory variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ #align measure_theory.ae_is_measurably_generated MeasureTheory.ae_isMeasurablyGenerated /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] #align measure_theory.ae_uIoc_iff MeasureTheory.ae_uIoc_iff theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union MeasureTheory.measure_union theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union' MeasureTheory.measure_union' theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet #align measure_theory.measure_inter_add_diff MeasureTheory.measure_inter_add_diff theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) #align measure_theory.measure_diff_add_inter MeasureTheory.measure_diff_add_inter theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl #align measure_theory.measure_union_add_inter MeasureTheory.measure_union_add_inter theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] #align measure_theory.measure_union_add_inter' MeasureTheory.measure_union_add_inter' lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs) lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet #align measure_theory.measure_add_measure_compl MeasureTheory.measure_add_measure_compl theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 #align measure_theory.measure_bUnion₀ MeasureTheory.measure_biUnion₀ theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet #align measure_theory.measure_bUnion MeasureTheory.measure_biUnion theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] #align measure_theory.measure_sUnion₀ MeasureTheory.measure_sUnion₀ theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] #align measure_theory.measure_sUnion MeasureTheory.measure_sUnion theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm #align measure_theory.measure_bUnion_finset₀ MeasureTheory.measure_biUnion_finset₀ theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet #align measure_theory.measure_bUnion_finset MeasureTheory.measure_biUnion_finset /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) #align measure_theory.tsum_meas_le_meas_Union_of_disjoint MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] #align measure_theory.tsum_measure_preimage_singleton MeasureTheory.tsum_measure_preimage_singleton lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] #align measure_theory.sum_measure_preimage_singleton MeasureTheory.sum_measure_preimage_singleton theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h #align measure_theory.measure_diff_null' MeasureTheory.measure_diff_null' theorem measure_add_diff (hs : MeasurableSet s) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union' disjoint_sdiff_right hs, union_diff_self] #align measure_theory.measure_add_diff MeasureTheory.measure_add_diff theorem measure_diff' (s : Set α) (hm : MeasurableSet t) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := Eq.symm <| ENNReal.sub_eq_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] #align measure_theory.measure_diff' MeasureTheory.measure_diff' theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : MeasurableSet s₂) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] #align measure_theory.measure_diff MeasureTheory.measure_diff theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right #align measure_theory.le_measure_diff MeasureTheory.le_measure_diff /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := (WithTop.sub_eq_top_iff.2 ⟨hμu, hμv⟩).symm _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h #align measure_theory.measure_diff_lt_of_lt_add MeasureTheory.measure_diff_lt_of_lt_add theorem measure_diff_le_iff_le_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] #align measure_theory.measure_diff_le_iff_le_add MeasureTheory.measure_diff_le_iff_le_add theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) #align measure_theory.measure_eq_measure_of_null_diff MeasureTheory.measure_eq_measure_of_null_diff theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ #align measure_theory.measure_eq_measure_of_between_null_diff MeasureTheory.measure_eq_measure_of_between_null_diff theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 #align measure_theory.measure_eq_measure_smaller_of_between_null_diff MeasureTheory.measure_eq_measure_smaller_of_between_null_diff theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 #align measure_theory.measure_eq_measure_larger_of_between_null_diff MeasureTheory.measure_eq_measure_larger_of_between_null_diff lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin #align measure_theory.measure_compl MeasureTheory.measure_compl lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ #align measure_theory.union_ae_eq_left_iff_ae_subset MeasureTheory.union_ae_eq_left_iff_ae_subset @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] #align measure_theory.union_ae_eq_right_iff_ae_subset MeasureTheory.union_ae_eq_right_iff_ae_subset theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] #align measure_theory.ae_eq_of_ae_subset_of_measure_ge MeasureTheory.ae_eq_of_ae_subset_of_measure_ge /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht #align measure_theory.ae_eq_of_subset_of_measure_ge MeasureTheory.ae_eq_of_subset_of_measure_ge theorem measure_iUnion_congr_of_subset [Countable β] {s : β → Set α} {t : β → Set α} (hsub : ∀ b, s b ⊆ t b) (h_le : ∀ b, μ (t b) ≤ μ (s b)) : μ (⋃ b, s b) = μ (⋃ b, t b) := by rcases Classical.em (∃ b, μ (t b) = ∞) with (⟨b, hb⟩ | htop) · calc μ (⋃ b, s b) = ∞ := top_unique (hb ▸ (h_le b).trans <| measure_mono <| subset_iUnion _ _) _ = μ (⋃ b, t b) := Eq.symm <| top_unique <| hb ▸ measure_mono (subset_iUnion _ _) push_neg at htop refine le_antisymm (measure_mono (iUnion_mono hsub)) ?_ set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _) · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ #align measure_theory.measure_Union_congr_of_subset MeasureTheory.measure_iUnion_congr_of_subset theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) #align measure_theory.measure_union_congr_of_subset MeasureTheory.measure_union_congr_of_subset @[simp] theorem measure_iUnion_toMeasurable [Countable β] (s : β → Set α) : μ (⋃ b, toMeasurable μ (s b)) = μ (⋃ b, s b) := Eq.symm <| measure_iUnion_congr_of_subset (fun _b => subset_toMeasurable _ _) fun _b => (measure_toMeasurable _).le #align measure_theory.measure_Union_to_measurable MeasureTheory.measure_iUnion_toMeasurable theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] #align measure_theory.measure_bUnion_to_measurable MeasureTheory.measure_biUnion_toMeasurable @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl #align measure_theory.measure_to_measurable_union MeasureTheory.measure_toMeasurable_union @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le #align measure_theory.measure_union_to_measurable MeasureTheory.measure_union_toMeasurable theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : Set.PairwiseDisjoint (↑s) t) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset H h] exact measure_mono (subset_univ _) #align measure_theory.sum_measure_le_measure_univ MeasureTheory.sum_measure_le_measure_univ theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : Pairwise (Disjoint on s)) : (∑' i, μ (s i)) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij #align measure_theory.tsum_measure_le_measure_univ MeasureTheory.tsum_measure_le_measure_univ /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact disjoint_iff_inter_eq_empty.mpr (H i j hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_sum_measure /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `t` is measurable. -/ theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [← Set.not_disjoint_iff_nonempty_inter] contrapose! h calc μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm _ ≤ μ u := measure_mono (union_subset h's h't) #align measure_theory.nonempty_inter_of_measure_lt_add MeasureTheory.nonempty_inter_of_measure_lt_add /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `s` is measurable. -/ theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [add_comm] at h rw [inter_comm] exact nonempty_inter_of_measure_lt_add μ hs h't h's h #align measure_theory.nonempty_inter_of_measure_lt_add' MeasureTheory.nonempty_inter_of_measure_lt_add' /-- Continuity from below: the measure of the union of a directed sequence of (not necessarily -measurable) sets is the supremum of the measures. -/ theorem measure_iUnion_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by cases nonempty_encodable ι -- WLOG, `ι = ℕ` generalize ht : Function.extend Encodable.encode s ⊥ = t replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot Encodable.encode_injective suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot Encodable.encode_injective, (· ∘ ·), Pi.bot_apply, bot_eq_empty, measure_empty] at this exact this.trans (iSup_extend_bot Encodable.encode_injective _) clear! ι -- The `≥` inequality is trivial refine le_antisymm ?_ (iSup_le fun i => measure_mono <| subset_iUnion _ _) -- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T` set T : ℕ → Set α := fun n => toMeasurable μ (t n) set Td : ℕ → Set α := disjointed T have hm : ∀ n, MeasurableSet (Td n) := MeasurableSet.disjointed fun n => measurableSet_toMeasurable _ _ calc μ (⋃ n, t n) ≤ μ (⋃ n, T n) := measure_mono (iUnion_mono fun i => subset_toMeasurable _ _) _ = μ (⋃ n, Td n) := by rw [iUnion_disjointed] _ ≤ ∑' n, μ (Td n) := measure_iUnion_le _ _ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum _ ≤ ⨆ n, μ (t n) := iSup_le fun I => by rcases hd.finset_le I with ⟨N, hN⟩ calc (∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) := (measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm _ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _) _ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _ _ ≤ μ (t N) := measure_mono (iUnion₂_subset hN) _ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N #align measure_theory.measure_Union_eq_supr MeasureTheory.measure_iUnion_eq_iSup /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the supremum of the measures of the partial unions. -/ theorem measure_iUnion_eq_iSup' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by have hd : Directed (· ⊆ ·) (Accumulate f) := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biUnion_subset_biUnion_left fun l rli ↦ le_trans rli rik, biUnion_subset_biUnion_left fun l rlj ↦ le_trans rlj rjk⟩ rw [← iUnion_accumulate] exact measure_iUnion_eq_iSup hd theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable) (hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, measure_iUnion_eq_iSup hd.directed_val, ← iSup_subtype''] #align measure_theory.measure_bUnion_eq_supr MeasureTheory.measure_biUnion_eq_iSup /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the infimum of the measures. -/ theorem measure_iInter_eq_iInf [Countable ι] {s : ι → Set α} (h : ∀ i, MeasurableSet (s i)) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by rcases hfin with ⟨k, hk⟩ have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht) rw [← ENNReal.sub_sub_cancel hk (iInf_le _ k), ENNReal.sub_iInf, ← ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ← measure_diff (iInter_subset _ k) (MeasurableSet.iInter h) (this _ (iInter_subset _ k)), diff_iInter, measure_iUnion_eq_iSup] · congr 1 refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => ?_) · rcases hd i k with ⟨j, hji, hjk⟩ use j rw [← measure_diff hjk (h _) (this _ hjk)] gcongr · rw [tsub_le_iff_right, ← measure_union, Set.union_comm] · exact measure_mono (diff_subset_iff.1 Subset.rfl) · apply disjoint_sdiff_left · apply h i · exact hd.mono_comp _ fun _ _ => diff_subset_diff_right #align measure_theory.measure_Inter_eq_infi MeasureTheory.measure_iInter_eq_iInf /-- Continuity from above: the measure of the intersection of a sequence of measurable sets is the infimum of the measures of the partial intersections. -/ theorem measure_iInter_eq_iInf' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (h : ∀ i, MeasurableSet (f i)) (hfin : ∃ i, μ (f i) ≠ ∞) : μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by let s := fun i ↦ ⋂ j ≤ i, f j have iInter_eq : ⋂ i, f i = ⋂ i, s i := by ext x; simp [s]; constructor · exact fun h _ j _ ↦ h j · intro h i rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact h j i rij have ms : ∀ i, MeasurableSet (s i) := fun i ↦ MeasurableSet.biInter (countable_univ.mono <| subset_univ _) fun i _ ↦ h i have hd : Directed (· ⊇ ·) s := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biInter_subset_biInter_left fun j rji ↦ le_trans rji rik, biInter_subset_biInter_left fun i rij ↦ le_trans rij rjk⟩ have hfin' : ∃ i, μ (s i) ≠ ∞ := by rcases hfin with ⟨i, hi⟩ rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact ⟨j, ne_top_of_le_ne_top hi <| measure_mono <| biInter_subset_of_mem rij⟩ exact iInter_eq ▸ measure_iInter_eq_iInf ms hd hfin' /-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily measurable) sets is the limit of the measures. -/ theorem tendsto_measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)] [Countable ι] {s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by rw [measure_iUnion_eq_iSup hm.directed_le] exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Union MeasureTheory.tendsto_measure_iUnion /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ theorem tendsto_measure_iUnion' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by rw [measure_iUnion_eq_iSup'] exact tendsto_atTop_iSup fun i j hij ↦ by gcongr /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {s : ι → Set α} (hs : ∀ n, MeasurableSet (s n)) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by rw [measure_iInter_eq_iInf hs hm.directed_ge hf] exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Inter MeasureTheory.tendsto_measure_iInter /-- Continuity from above: the measure of the intersection of a sequence of measurable sets such that one has finite measure is the limit of the measures of the partial intersections. -/ theorem tendsto_measure_iInter' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (hm : ∀ i, MeasurableSet (f i)) (hf : ∃ i, μ (f i) ≠ ∞) : Tendsto (fun i ↦ μ (⋂ j ∈ {j | j ≤ i}, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by rw [measure_iInter_eq_iInf' hm hf] exact tendsto_atTop_iInf fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij /-- The measure of the intersection of a decreasing sequence of measurable sets indexed by a linear order with first countable topology is the limit of the measures. -/ theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α} {a : ι} (hs : ∀ r > a, MeasurableSet (s r)) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j) (hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by refine tendsto_order.2 ⟨fun l hl => ?_, fun L hL => ?_⟩ · filter_upwards [self_mem_nhdsWithin (s := Ioi a)] with r hr using hl.trans_le (measure_mono (biInter_subset_of_mem hr)) obtain ⟨u, u_anti, u_pos, u_lim⟩ : ∃ u : ℕ → ι, StrictAnti u ∧ (∀ n : ℕ, a < u n) ∧ Tendsto u atTop (𝓝 a) := by rcases hf with ⟨r, ar, _⟩ rcases exists_seq_strictAnti_tendsto' ar with ⟨w, w_anti, w_mem, w_lim⟩ exact ⟨w, w_anti, fun n => (w_mem n).1, w_lim⟩ have A : Tendsto (μ ∘ s ∘ u) atTop (𝓝 (μ (⋂ n, s (u n)))) := by refine tendsto_measure_iInter (fun n => hs _ (u_pos n)) ?_ ?_ · intro m n hmn exact hm _ _ (u_pos n) (u_anti.antitone hmn) · rcases hf with ⟨r, rpos, hr⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, u n < r := ((tendsto_order.1 u_lim).2 r rpos).exists refine ⟨n, ne_of_lt (lt_of_le_of_lt ?_ hr.lt_top)⟩ exact measure_mono (hm _ _ (u_pos n) hn.le) have B : ⋂ n, s (u n) = ⋂ r > a, s r := by apply Subset.antisymm · simp only [subset_iInter_iff, gt_iff_lt] intro r rpos obtain ⟨n, hn⟩ : ∃ n, u n < r := ((tendsto_order.1 u_lim).2 _ rpos).exists exact Subset.trans (iInter_subset _ n) (hm (u n) r (u_pos n) hn.le) · simp only [subset_iInter_iff, gt_iff_lt] intro n apply biInter_subset_of_mem exact u_pos n rw [B] at A obtain ⟨n, hn⟩ : ∃ n, μ (s (u n)) < L := ((tendsto_order.1 A).2 _ hL).exists have : Ioc a (u n) ∈ 𝓝[>] a := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, u_pos n⟩ filter_upwards [this] with r hr using lt_of_le_of_lt (measure_mono (hm _ _ hr.1 hr.2)) hn #align measure_theory.tendsto_measure_bInter_gt MeasureTheory.tendsto_measure_biInter_gt /-- One direction of the **Borel-Cantelli lemma** (sometimes called the "*first* Borel-Cantelli lemma"): if (sᵢ) is a sequence of sets such that `∑ μ sᵢ` is finite, then the limit superior of the `sᵢ` is a null set. Note: for the *second* Borel-Cantelli lemma (applying to independent sets in a probability space), see `ProbabilityTheory.measure_limsup_eq_one`. -/ theorem measure_limsup_eq_zero {s : ℕ → Set α} (hs : (∑' i, μ (s i)) ≠ ∞) : μ (limsup s atTop) = 0 := by -- First we replace the sequence `sₙ` with a sequence of measurable sets `tₙ ⊇ sₙ` of the same -- measure. set t : ℕ → Set α := fun n => toMeasurable μ (s n) have ht : (∑' i, μ (t i)) ≠ ∞ := by simpa only [t, measure_toMeasurable] using hs suffices μ (limsup t atTop) = 0 by have A : s ≤ t := fun n => subset_toMeasurable μ (s n) -- TODO default args fail exact measure_mono_null (limsup_le_limsup (eventually_of_forall (Pi.le_def.mp A))) this -- Next we unfold `limsup` for sets and replace equality with an inequality simp only [limsup_eq_iInf_iSup_of_nat', Set.iInf_eq_iInter, Set.iSup_eq_iUnion, ← nonpos_iff_eq_zero] -- Finally, we estimate `μ (⋃ i, t (i + n))` by `∑ i', μ (t (i + n))` refine le_of_tendsto_of_tendsto' (tendsto_measure_iInter (fun i => MeasurableSet.iUnion fun b => measurableSet_toMeasurable _ _) ?_ ⟨0, ne_top_of_le_ne_top ht (measure_iUnion_le t)⟩) (ENNReal.tendsto_sum_nat_add (μ ∘ t) ht) fun n => measure_iUnion_le _ intro n m hnm x simp only [Set.mem_iUnion] exact fun ⟨i, hi⟩ => ⟨i + (m - n), by simpa only [add_assoc, tsub_add_cancel_of_le hnm] using hi⟩ #align measure_theory.measure_limsup_eq_zero MeasureTheory.measure_limsup_eq_zero theorem measure_liminf_eq_zero {s : ℕ → Set α} (h : (∑' i, μ (s i)) ≠ ∞) : μ (liminf s atTop) = 0 := by rw [← le_zero_iff] have : liminf s atTop ≤ limsup s atTop := liminf_le_limsup exact (μ.mono this).trans (by simp [measure_limsup_eq_zero h]) #align measure_theory.measure_liminf_eq_zero MeasureTheory.measure_liminf_eq_zero -- Need to specify `α := Set α` below because of diamond; see #19041 theorem limsup_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : limsup (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.limsup_sdiff s t] apply measure_limsup_eq_zero simp [h] · rw [atTop.sdiff_limsup s t] apply measure_liminf_eq_zero simp [h] #align measure_theory.limsup_ae_eq_of_forall_ae_eq MeasureTheory.limsup_ae_eq_of_forall_ae_eq -- Need to specify `α := Set α` above because of diamond; see #19041 theorem liminf_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : liminf (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.liminf_sdiff s t] apply measure_liminf_eq_zero simp [h] · rw [atTop.sdiff_liminf s t] apply measure_limsup_eq_zero simp [h] #align measure_theory.liminf_ae_eq_of_forall_ae_eq MeasureTheory.liminf_ae_eq_of_forall_ae_eq theorem measure_if {x : β} {t : Set β} {s : Set α} : μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h] #align measure_theory.measure_if MeasureTheory.measure_if end section OuterMeasure variable [ms : MeasurableSpace α] {s t : Set α} /-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are Carathéodory measurable. -/ def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α := Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd => m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd #align measure_theory.outer_measure.to_measure MeasureTheory.OuterMeasure.toMeasure theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory := fun _s hs _t => (measure_inter_add_diff _ hs).symm #align measure_theory.le_to_outer_measure_caratheodory MeasureTheory.le_toOuterMeasure_caratheodory @[simp] theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : (m.toMeasure h).toOuterMeasure = m.trim := rfl #align measure_theory.to_measure_to_outer_measure MeasureTheory.toMeasure_toOuterMeasure @[simp] theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : MeasurableSet s) : m.toMeasure h s = m s := m.trim_eq hs #align measure_theory.to_measure_apply MeasureTheory.toMeasure_apply theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) : m s ≤ m.toMeasure h s := m.le_trim s #align measure_theory.le_to_measure_apply MeasureTheory.le_toMeasure_apply theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by refine le_antisymm ?_ (le_toMeasure_apply _ _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩ calc m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm _ = m t := toMeasure_apply m h htm _ ≤ m s := m.mono hts #align measure_theory.to_measure_apply₀ MeasureTheory.toMeasure_apply₀ @[simp] theorem toOuterMeasure_toMeasure {μ : Measure α} : μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ := Measure.ext fun _s => μ.toOuterMeasure.trim_eq #align measure_theory.to_outer_measure_to_measure MeasureTheory.toOuterMeasure_toMeasure @[simp] theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure := μ.toOuterMeasure.boundedBy_eq_self #align measure_theory.bounded_by_measure MeasureTheory.boundedBy_measure end OuterMeasure section /- Porting note: These variables are wrapped by an anonymous section because they interrupt synthesizing instances in `MeasureSpace` section. -/ variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable), then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/ theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u) (htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by rw [h] at ht_ne_top refine le_antisymm (by gcongr) ?_ have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) := calc μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs _ = μ t := h.symm _ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm _ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne exact ENNReal.le_of_add_le_add_right B A #align measure_theory.measure.measure_inter_eq_of_measure_eq MeasureTheory.Measure.measure_inter_eq_of_measure_eq /-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`. Here, we require that the measure of `t` is finite. The conclusion holds without this assumption when the measure is s-finite (for example when it is σ-finite), see `measure_toMeasurable_inter_of_sFinite`. -/ theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := (measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t) ht).symm #align measure_theory.measure.measure_to_measurable_inter MeasureTheory.Measure.measure_toMeasurable_inter /-! ### The `ℝ≥0∞`-module of measures -/ instance instZero [MeasurableSpace α] : Zero (Measure α) := ⟨{ toOuterMeasure := 0 m_iUnion := fun _f _hf _hd => tsum_zero.symm trim_le := OuterMeasure.trim_zero.le }⟩ #align measure_theory.measure.has_zero MeasureTheory.Measure.instZero @[simp] theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 := rfl #align measure_theory.measure.zero_to_outer_measure MeasureTheory.Measure.zero_toOuterMeasure @[simp, norm_cast] theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 := rfl #align measure_theory.measure.coe_zero MeasureTheory.Measure.coe_zero @[nontriviality] lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : μ s = 0 := by rw [eq_empty_of_isEmpty s, measure_empty] instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) := ⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩ #align measure_theory.measure.subsingleton MeasureTheory.Measure.instSubsingleton theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 := Subsingleton.elim μ 0 #align measure_theory.measure.eq_zero_of_is_empty MeasureTheory.Measure.eq_zero_of_isEmpty instance instInhabited [MeasurableSpace α] : Inhabited (Measure α) := ⟨0⟩ #align measure_theory.measure.inhabited MeasureTheory.Measure.instInhabited instance instAdd [MeasurableSpace α] : Add (Measure α) := ⟨fun μ₁ μ₂ => { toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure m_iUnion := fun s hs hd => show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩ #align measure_theory.measure.has_add MeasureTheory.Measure.instAdd @[simp] theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : (μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure := rfl #align measure_theory.measure.add_to_outer_measure MeasureTheory.Measure.add_toOuterMeasure @[simp, norm_cast] theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl #align measure_theory.measure.coe_add MeasureTheory.Measure.coe_add theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl #align measure_theory.measure.add_apply MeasureTheory.Measure.add_apply section SMul variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞] instance instSMul [MeasurableSpace α] : SMul R (Measure α) := ⟨fun c μ => { toOuterMeasure := c • μ.toOuterMeasure m_iUnion := fun s hs hd => by simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩ #align measure_theory.measure.has_smul MeasureTheory.Measure.instSMul @[simp] theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) : (c • μ).toOuterMeasure = c • μ.toOuterMeasure := rfl #align measure_theory.measure.smul_to_outer_measure MeasureTheory.Measure.smul_toOuterMeasure @[simp, norm_cast] theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ := rfl #align measure_theory.measure.coe_smul MeasureTheory.Measure.coe_smul @[simp] theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) : (c • μ) s = c • μ s := rfl #align measure_theory.measure.smul_apply MeasureTheory.Measure.smul_apply instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] [MeasurableSpace α] : SMulCommClass R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩ #align measure_theory.measure.smul_comm_class MeasureTheory.Measure.instSMulCommClass instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] [MeasurableSpace α] : IsScalarTower R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩ #align measure_theory.measure.is_scalar_tower MeasureTheory.Measure.instIsScalarTower instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] [MeasurableSpace α] : IsCentralScalar R (Measure α) := ⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩ #align measure_theory.measure.is_central_scalar MeasureTheory.Measure.instIsCentralScalar end SMul instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : MulAction R (Measure α) := Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.mul_action MeasureTheory.Measure.instMulAction instance instAddCommMonoid [MeasurableSpace α] : AddCommMonoid (Measure α) := toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure fun _ _ => smul_toOuterMeasure _ _ #align measure_theory.measure.add_comm_monoid MeasureTheory.Measure.instAddCommMonoid /-- Coercion to function as an additive monoid homomorphism. -/ def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align measure_theory.measure.coe_add_hom MeasureTheory.Measure.coeAddHom @[simp] theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) : ⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I #align measure_theory.measure.coe_finset_sum MeasureTheory.Measure.coe_finset_sum theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) : (∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply] #align measure_theory.measure.finset_sum_apply MeasureTheory.Measure.finset_sum_apply instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : DistribMulAction R (Measure α) := Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.distrib_mul_action MeasureTheory.Measure.instDistribMulAction instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : Module R (Measure α) := Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.module MeasureTheory.Measure.instModule @[simp] theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : (c • μ) s = c * μ s := rfl #align measure_theory.measure.coe_nnreal_smul_apply MeasureTheory.Measure.coe_nnreal_smul_apply @[simp] theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : c • μ s = c * μ s := by rfl theorem ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by simp only [ae_iff, Algebra.id.smul_eq_mul, smul_apply, or_iff_right_iff_imp, mul_eq_zero] simp only [IsEmpty.forall_iff, hc] #align measure_theory.measure.ae_smul_measure_iff MeasureTheory.Measure.ae_smul_measure_iff theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by refine le_antisymm (measure_mono h') ?_ have : μ t + ν t ≤ μ s + ν t := calc μ t + ν t = μ s + ν s := h''.symm _ ≤ μ s + ν t := by gcongr apply ENNReal.le_of_add_le_add_right _ this exact ne_top_of_le_ne_top h (le_add_left le_rfl) #align measure_theory.measure.measure_eq_left_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_left_of_subset_of_measure_add_eq theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by rw [add_comm] at h'' h exact measure_eq_left_of_subset_of_measure_add_eq h h' h'' #align measure_theory.measure.measure_eq_right_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_right_of_subset_of_measure_add_eq theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm · refine measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _) (measure_toMeasurable t).symm rwa [measure_toMeasurable t] · simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht exact ht.1 #align measure_theory.measure.measure_to_measurable_add_inter_left MeasureTheory.Measure.measure_toMeasurable_add_inter_left theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by rw [add_comm] at ht ⊢ exact measure_toMeasurable_add_inter_left hs ht #align measure_theory.measure.measure_to_measurable_add_inter_right MeasureTheory.Measure.measure_toMeasurable_add_inter_right /-! ### The complete lattice of measures -/ /-- Measures are partially ordered. -/ instance instPartialOrder [MeasurableSpace α] : PartialOrder (Measure α) where le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s le_refl m s := le_rfl le_trans m₁ m₂ m₃ h₁ h₂ s := le_trans (h₁ s) (h₂ s) le_antisymm m₁ m₂ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s) #align measure_theory.measure.partial_order MeasureTheory.Measure.instPartialOrder theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl #align measure_theory.measure.to_outer_measure_le MeasureTheory.Measure.toOuterMeasure_le theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff #align measure_theory.measure.le_iff MeasureTheory.Measure.le_iff theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ := le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs) theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl #align measure_theory.measure.le_iff' MeasureTheory.Measure.le_iff' theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop] #align measure_theory.measure.lt_iff MeasureTheory.Measure.lt_iff theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le] #align measure_theory.measure.lt_iff' MeasureTheory.Measure.lt_iff' instance covariantAddLE [MeasurableSpace α] : CovariantClass (Measure α) (Measure α) (· + ·) (· ≤ ·) := ⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩ #align measure_theory.measure.covariant_add_le MeasureTheory.Measure.covariantAddLE protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s) #align measure_theory.measure.le_add_left MeasureTheory.Measure.le_add_left protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s) #align measure_theory.measure.le_add_right MeasureTheory.Measure.le_add_right section sInf variable {m : Set (Measure α)} theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) : MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by rw [OuterMeasure.sInf_eq_boundedBy_sInfGen] refine OuterMeasure.boundedBy_caratheodory fun t => ?_ simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t, coe_toOuterMeasure] intro μ hμ u htu _hu have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by intro s t hst rw [OuterMeasure.sInfGen_def, iInf_image] exact iInf₂_le_of_le μ hμ <| measure_mono hst rw [← measure_inter_add_diff u hs] exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu) #align measure_theory.measure.Inf_caratheodory MeasureTheory.Measure.sInf_caratheodory instance [MeasurableSpace α] : InfSet (Measure α) := ⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩ theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s := toMeasure_apply _ _ hs #align measure_theory.measure.Inf_apply MeasureTheory.Measure.sInf_apply private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ := have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h) le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m := have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) := le_sInf <| forall_mem_image.2 fun μ hμ ↦ toOuterMeasure_le.2 <| h _ hμ le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s instance instCompleteSemilatticeInf [MeasurableSpace α] : CompleteSemilatticeInf (Measure α) := { (by infer_instance : PartialOrder (Measure α)), (by infer_instance : InfSet (Measure α)) with sInf_le := fun _s _a => measure_sInf_le le_sInf := fun _s _a => measure_le_sInf } #align measure_theory.measure.complete_semilattice_Inf MeasureTheory.Measure.instCompleteSemilatticeInf instance instCompleteLattice [MeasurableSpace α] : CompleteLattice (Measure α) := { completeLatticeOfCompleteSemilatticeInf (Measure α) with top := { toOuterMeasure := ⊤, m_iUnion := by intro f _ _ refine (measure_iUnion_le _).antisymm ?_ if hne : (⋃ i, f i).Nonempty then rw [OuterMeasure.top_apply hne] exact le_top else simp_all [Set.not_nonempty_iff_eq_empty] trim_le := le_top }, le_top := fun μ => toOuterMeasure_le.mp le_top bot := 0 bot_le := fun _a _s => bot_le } #align measure_theory.measure.complete_lattice MeasureTheory.Measure.instCompleteLattice end sInf @[simp] theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top : (⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) = (⊤ : Measure α) := toOuterMeasure_toMeasure (μ := ⊤) #align measure_theory.outer_measure.to_measure_top MeasureTheory.OuterMeasure.toMeasure_top @[simp] theorem toOuterMeasure_top [MeasurableSpace α] : (⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) := rfl #align measure_theory.measure.to_outer_measure_top MeasureTheory.Measure.toOuterMeasure_top @[simp] theorem top_add : ⊤ + μ = ⊤ := top_unique <| Measure.le_add_right le_rfl #align measure_theory.measure.top_add MeasureTheory.Measure.top_add @[simp] theorem add_top : μ + ⊤ = ⊤ := top_unique <| Measure.le_add_left le_rfl #align measure_theory.measure.add_top MeasureTheory.Measure.add_top protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ := bot_le #align measure_theory.measure.zero_le MeasureTheory.Measure.zero_le theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 := μ.zero_le.le_iff_eq #align measure_theory.measure.nonpos_iff_eq_zero' MeasureTheory.Measure.nonpos_iff_eq_zero' @[simp] theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 := ⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h => h.symm ▸ rfl⟩ #align measure_theory.measure.measure_univ_eq_zero MeasureTheory.Measure.measure_univ_eq_zero theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 := measure_univ_eq_zero.not #align measure_theory.measure.measure_univ_ne_zero MeasureTheory.Measure.measure_univ_ne_zero instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩ @[simp] theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 := pos_iff_ne_zero.trans measure_univ_ne_zero #align measure_theory.measure.measure_univ_pos MeasureTheory.Measure.measure_univ_pos /-! ### Pushforward and pullback -/ /-- Lift a linear map between `OuterMeasure` spaces such that for each measure `μ` every measurable set is caratheodory-measurable w.r.t. `f μ` to a linear map between `Measure` spaces. -/ def liftLinear {m0 : MeasurableSpace α} (f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β) (hf : ∀ μ : Measure α, ‹_› ≤ (f μ.toOuterMeasure).caratheodory) : Measure α →ₗ[ℝ≥0∞] Measure β where toFun μ := (f μ.toOuterMeasure).toMeasure (hf μ) map_add' μ₁ μ₂ := ext fun s hs => by simp only [map_add, coe_add, Pi.add_apply, toMeasure_apply, add_toOuterMeasure, OuterMeasure.coe_add, hs] map_smul' c μ := ext fun s hs => by simp only [LinearMap.map_smulₛₗ, coe_smul, Pi.smul_apply, toMeasure_apply, smul_toOuterMeasure (R := ℝ≥0∞), OuterMeasure.coe_smul (R := ℝ≥0∞), smul_apply, hs] #align measure_theory.measure.lift_linear MeasureTheory.Measure.liftLinear lemma liftLinear_apply₀ {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : NullMeasurableSet s (liftLinear f hf μ)) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply₀ _ (hf μ) hs @[simp] theorem liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : MeasurableSet s) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply _ (hf μ) hs #align measure_theory.measure.lift_linear_apply MeasureTheory.Measure.liftLinear_apply theorem le_liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) (s : Set β) : f μ.toOuterMeasure s ≤ liftLinear f hf μ s := le_toMeasure_apply _ (hf μ) s #align measure_theory.measure.le_lift_linear_apply MeasureTheory.Measure.le_liftLinear_apply /-- The pushforward of a measure as a linear map. It is defined to be `0` if `f` is not a measurable function. -/ def mapₗ [MeasurableSpace α] (f : α → β) : Measure α →ₗ[ℝ≥0∞] Measure β := if hf : Measurable f then liftLinear (OuterMeasure.map f) fun μ _s hs t => le_toOuterMeasure_caratheodory μ _ (hf hs) (f ⁻¹' t) else 0 #align measure_theory.measure.mapₗ MeasureTheory.Measure.mapₗ theorem mapₗ_congr {f g : α → β} (hf : Measurable f) (hg : Measurable g) (h : f =ᵐ[μ] g) : mapₗ f μ = mapₗ g μ := by ext1 s hs simpa only [mapₗ, hf, hg, hs, dif_pos, liftLinear_apply, OuterMeasure.map_apply] using measure_congr (h.preimage s) #align measure_theory.measure.mapₗ_congr MeasureTheory.Measure.mapₗ_congr /-- The pushforward of a measure. It is defined to be `0` if `f` is not an almost everywhere measurable function. -/ irreducible_def map [MeasurableSpace α] (f : α → β) (μ : Measure α) : Measure β := if hf : AEMeasurable f μ then mapₗ (hf.mk f) μ else 0 #align measure_theory.measure.map MeasureTheory.Measure.map theorem mapₗ_mk_apply_of_aemeasurable {f : α → β} (hf : AEMeasurable f μ) : mapₗ (hf.mk f) μ = map f μ := by simp [map, hf] #align measure_theory.measure.mapₗ_mk_apply_of_ae_measurable MeasureTheory.Measure.mapₗ_mk_apply_of_aemeasurable theorem mapₗ_apply_of_measurable {f : α → β} (hf : Measurable f) (μ : Measure α) : mapₗ f μ = map f μ := by simp only [← mapₗ_mk_apply_of_aemeasurable hf.aemeasurable] exact mapₗ_congr hf hf.aemeasurable.measurable_mk hf.aemeasurable.ae_eq_mk #align measure_theory.measure.mapₗ_apply_of_measurable MeasureTheory.Measure.mapₗ_apply_of_measurable @[simp] theorem map_add (μ ν : Measure α) {f : α → β} (hf : Measurable f) : (μ + ν).map f = μ.map f + ν.map f := by simp [← mapₗ_apply_of_measurable hf] #align measure_theory.measure.map_add MeasureTheory.Measure.map_add @[simp] theorem map_zero (f : α → β) : (0 : Measure α).map f = 0 := by by_cases hf : AEMeasurable f (0 : Measure α) <;> simp [map, hf] #align measure_theory.measure.map_zero MeasureTheory.Measure.map_zero @[simp] theorem map_of_not_aemeasurable {f : α → β} {μ : Measure α} (hf : ¬AEMeasurable f μ) : μ.map f = 0 := by simp [map, hf] #align measure_theory.measure.map_of_not_ae_measurable MeasureTheory.Measure.map_of_not_aemeasurable theorem map_congr {f g : α → β} (h : f =ᵐ[μ] g) : Measure.map f μ = Measure.map g μ := by by_cases hf : AEMeasurable f μ · have hg : AEMeasurable g μ := hf.congr h simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hg] exact mapₗ_congr hf.measurable_mk hg.measurable_mk (hf.ae_eq_mk.symm.trans (h.trans hg.ae_eq_mk)) · have hg : ¬AEMeasurable g μ := by simpa [← aemeasurable_congr h] using hf simp [map_of_not_aemeasurable, hf, hg] #align measure_theory.measure.map_congr MeasureTheory.Measure.map_congr @[simp] protected theorem map_smul (c : ℝ≥0∞) (μ : Measure α) (f : α → β) : (c • μ).map f = c • μ.map f := by rcases eq_or_ne c 0 with (rfl | hc); · simp by_cases hf : AEMeasurable f μ · have hfc : AEMeasurable f (c • μ) := ⟨hf.mk f, hf.measurable_mk, (ae_smul_measure_iff hc).2 hf.ae_eq_mk⟩ simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hfc, LinearMap.map_smulₛₗ, RingHom.id_apply] congr 1 apply mapₗ_congr hfc.measurable_mk hf.measurable_mk exact EventuallyEq.trans ((ae_smul_measure_iff hc).1 hfc.ae_eq_mk.symm) hf.ae_eq_mk · have hfc : ¬AEMeasurable f (c • μ) := by intro hfc exact hf ⟨hfc.mk f, hfc.measurable_mk, (ae_smul_measure_iff hc).1 hfc.ae_eq_mk⟩ simp [map_of_not_aemeasurable hf, map_of_not_aemeasurable hfc] #align measure_theory.measure.map_smul MeasureTheory.Measure.map_smul @[simp] protected theorem map_smul_nnreal (c : ℝ≥0) (μ : Measure α) (f : α → β) : (c • μ).map f = c • μ.map f := μ.map_smul (c : ℝ≥0∞) f #align measure_theory.measure.map_smul_nnreal MeasureTheory.Measure.map_smul_nnreal variable {f : α → β} lemma map_apply₀ {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : NullMeasurableSet s (map f μ)) : μ.map f s = μ (f ⁻¹' s) := by rw [map, dif_pos hf, mapₗ, dif_pos hf.measurable_mk] at hs ⊢ rw [liftLinear_apply₀ _ hs, measure_congr (hf.ae_eq_mk.preimage s)] rfl /-- We can evaluate the pushforward on measurable sets. For non-measurable sets, see `MeasureTheory.Measure.le_map_apply` and `MeasurableEquiv.map_apply`. -/ @[simp] theorem map_apply_of_aemeasurable (hf : AEMeasurable f μ) {s : Set β} (hs : MeasurableSet s) : μ.map f s = μ (f ⁻¹' s) := map_apply₀ hf hs.nullMeasurableSet #align measure_theory.measure.map_apply_of_ae_measurable MeasureTheory.Measure.map_apply_of_aemeasurable @[simp] theorem map_apply (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : μ.map f s = μ (f ⁻¹' s) := map_apply_of_aemeasurable hf.aemeasurable hs #align measure_theory.measure.map_apply MeasureTheory.Measure.map_apply theorem map_toOuterMeasure (hf : AEMeasurable f μ) : (μ.map f).toOuterMeasure = (OuterMeasure.map f μ.toOuterMeasure).trim := by rw [← trimmed, OuterMeasure.trim_eq_trim_iff] intro s hs simp [hf, hs] #align measure_theory.measure.map_to_outer_measure MeasureTheory.Measure.map_toOuterMeasure @[simp] lemma map_eq_zero_iff (hf : AEMeasurable f μ) : μ.map f = 0 ↔ μ = 0 := by simp_rw [← measure_univ_eq_zero, map_apply_of_aemeasurable hf .univ, preimage_univ] @[simp] lemma mapₗ_eq_zero_iff (hf : Measurable f) : Measure.mapₗ f μ = 0 ↔ μ = 0 := by rw [mapₗ_apply_of_measurable hf, map_eq_zero_iff hf.aemeasurable] lemma map_ne_zero_iff (hf : AEMeasurable f μ) : μ.map f ≠ 0 ↔ μ ≠ 0 := (map_eq_zero_iff hf).not lemma mapₗ_ne_zero_iff (hf : Measurable f) : Measure.mapₗ f μ ≠ 0 ↔ μ ≠ 0 := (mapₗ_eq_zero_iff hf).not @[simp] theorem map_id : map id μ = μ := ext fun _ => map_apply measurable_id #align measure_theory.measure.map_id MeasureTheory.Measure.map_id @[simp] theorem map_id' : map (fun x => x) μ = μ := map_id #align measure_theory.measure.map_id' MeasureTheory.Measure.map_id' theorem map_map {g : β → γ} {f : α → β} (hg : Measurable g) (hf : Measurable f) : (μ.map f).map g = μ.map (g ∘ f) := ext fun s hs => by simp [hf, hg, hs, hg hs, hg.comp hf, ← preimage_comp] #align measure_theory.measure.map_map MeasureTheory.Measure.map_map @[mono] theorem map_mono {f : α → β} (h : μ ≤ ν) (hf : Measurable f) : μ.map f ≤ ν.map f := le_iff.2 fun s hs ↦ by simp [hf.aemeasurable, hs, h _] #align measure_theory.measure.map_mono MeasureTheory.Measure.map_mono /-- Even if `s` is not measurable, we can bound `map f μ s` from below. See also `MeasurableEquiv.map_apply`. -/ theorem le_map_apply {f : α → β} (hf : AEMeasurable f μ) (s : Set β) : μ (f ⁻¹' s) ≤ μ.map f s := calc μ (f ⁻¹' s) ≤ μ (f ⁻¹' toMeasurable (μ.map f) s) := by gcongr; apply subset_toMeasurable _ = μ.map f (toMeasurable (μ.map f) s) := (map_apply_of_aemeasurable hf <| measurableSet_toMeasurable _ _).symm _ = μ.map f s := measure_toMeasurable _ #align measure_theory.measure.le_map_apply MeasureTheory.Measure.le_map_apply theorem le_map_apply_image {f : α → β} (hf : AEMeasurable f μ) (s : Set α) : μ s ≤ μ.map f (f '' s) := (measure_mono (subset_preimage_image f s)).trans (le_map_apply hf _) /-- Even if `s` is not measurable, `map f μ s = 0` implies that `μ (f ⁻¹' s) = 0`. -/ theorem preimage_null_of_map_null {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : μ.map f s = 0) : μ (f ⁻¹' s) = 0 := nonpos_iff_eq_zero.mp <| (le_map_apply hf s).trans_eq hs #align measure_theory.measure.preimage_null_of_map_null MeasureTheory.Measure.preimage_null_of_map_null theorem tendsto_ae_map {f : α → β} (hf : AEMeasurable f μ) : Tendsto f (ae μ) (ae (μ.map f)) := fun _ hs => preimage_null_of_map_null hf hs #align measure_theory.measure.tendsto_ae_map MeasureTheory.Measure.tendsto_ae_map /-- Pullback of a `Measure` as a linear map. If `f` sends each measurable set to a measurable set, then for each measurable set `s` we have `comapₗ f μ s = μ (f '' s)`. If the linearity is not needed, please use `comap` instead, which works for a larger class of functions. -/ def comapₗ [MeasurableSpace α] (f : α → β) : Measure β →ₗ[ℝ≥0∞] Measure α := if hf : Injective f ∧ ∀ s, MeasurableSet s → MeasurableSet (f '' s) then liftLinear (OuterMeasure.comap f) fun μ s hs t => by simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1] apply le_toOuterMeasure_caratheodory exact hf.2 s hs else 0 #align measure_theory.measure.comapₗ MeasureTheory.Measure.comapₗ theorem comapₗ_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comapₗ f μ s = μ (f '' s) := by rw [comapₗ, dif_pos, liftLinear_apply _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure] exact ⟨hfi, hf⟩ #align measure_theory.measure.comapₗ_apply MeasureTheory.Measure.comapₗ_apply /-- Pullback of a `Measure`. If `f` sends each measurable set to a null-measurable set, then for each measurable set `s` we have `comap f μ s = μ (f '' s)`. -/ def comap [MeasurableSpace α] (f : α → β) (μ : Measure β) : Measure α := if hf : Injective f ∧ ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ then (OuterMeasure.comap f μ.toOuterMeasure).toMeasure fun s hs t => by simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1] exact (measure_inter_add_diff₀ _ (hf.2 s hs)).symm else 0 #align measure_theory.measure.comap MeasureTheory.Measure.comap theorem comap_apply₀ [MeasurableSpace α] (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) (hs : NullMeasurableSet s (comap f μ)) : comap f μ s = μ (f '' s) := by rw [comap, dif_pos (And.intro hfi hf)] at hs ⊢ rw [toMeasure_apply₀ _ _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure] #align measure_theory.measure.comap_apply₀ MeasureTheory.Measure.comap_apply₀ theorem le_comap_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) (s : Set α) : μ (f '' s) ≤ comap f μ s := by rw [comap, dif_pos (And.intro hfi hf)] exact le_toMeasure_apply _ _ _ #align measure_theory.measure.le_comap_apply MeasureTheory.Measure.le_comap_apply theorem comap_apply {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comap f μ s = μ (f '' s) := comap_apply₀ f μ hfi (fun s hs => (hf s hs).nullMeasurableSet) hs.nullMeasurableSet #align measure_theory.measure.comap_apply MeasureTheory.Measure.comap_apply theorem comapₗ_eq_comap {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comapₗ f μ s = comap f μ s := (comapₗ_apply f hfi hf μ hs).trans (comap_apply f hfi hf μ hs).symm #align measure_theory.measure.comapₗ_eq_comap MeasureTheory.Measure.comapₗ_eq_comap theorem measure_image_eq_zero_of_comap_eq_zero {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s : Set α} (hs : comap f μ s = 0) : μ (f '' s) = 0 := le_antisymm ((le_comap_apply f μ hfi hf s).trans hs.le) (zero_le _) #align measure_theory.measure.measure_image_eq_zero_of_comap_eq_zero MeasureTheory.Measure.measure_image_eq_zero_of_comap_eq_zero theorem ae_eq_image_of_ae_eq_comap {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s t : Set α} (hst : s =ᵐ[comap f μ] t) : f '' s =ᵐ[μ] f '' t := by rw [EventuallyEq, ae_iff] at hst ⊢ have h_eq_α : { a : α | ¬s a = t a } = s \ t ∪ t \ s := by ext1 x simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff] tauto have h_eq_β : { a : β | ¬(f '' s) a = (f '' t) a } = f '' s \ f '' t ∪ f '' t \ f '' s := by ext1 x simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff] tauto rw [← Set.image_diff hfi, ← Set.image_diff hfi, ← Set.image_union] at h_eq_β rw [h_eq_β] rw [h_eq_α] at hst exact measure_image_eq_zero_of_comap_eq_zero f μ hfi hf hst #align measure_theory.measure.ae_eq_image_of_ae_eq_comap MeasureTheory.Measure.ae_eq_image_of_ae_eq_comap theorem NullMeasurableSet.image {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s : Set α} (hs : NullMeasurableSet s (μ.comap f)) : NullMeasurableSet (f '' s) μ := by refine ⟨toMeasurable μ (f '' toMeasurable (μ.comap f) s), measurableSet_toMeasurable _ _, ?_⟩ refine EventuallyEq.trans ?_ (NullMeasurableSet.toMeasurable_ae_eq ?_).symm swap · exact hf _ (measurableSet_toMeasurable _ _) have h : toMeasurable (comap f μ) s =ᵐ[comap f μ] s := NullMeasurableSet.toMeasurable_ae_eq hs exact ae_eq_image_of_ae_eq_comap f μ hfi hf h.symm #align measure_theory.measure.null_measurable_set.image MeasureTheory.Measure.NullMeasurableSet.image theorem comap_preimage {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) {s : Set β} (hf : Injective f) (hf' : Measurable f) (h : ∀ t, MeasurableSet t → NullMeasurableSet (f '' t) μ) (hs : MeasurableSet s) : μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by rw [comap_apply₀ _ _ hf h (hf' hs).nullMeasurableSet, image_preimage_eq_inter_range] #align measure_theory.measure.comap_preimage MeasureTheory.Measure.comap_preimage section Sum /-- Sum of an indexed family of measures. -/ noncomputable def sum (f : ι → Measure α) : Measure α := (OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <| le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _) (OuterMeasure.le_sum_caratheodory _) #align measure_theory.measure.sum MeasureTheory.Measure.sum theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s := le_toMeasure_apply _ _ _ #align measure_theory.measure.le_sum_apply MeasureTheory.Measure.le_sum_apply @[simp] theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : sum f s = ∑' i, f i s := toMeasure_apply _ _ hs #align measure_theory.measure.sum_apply MeasureTheory.Measure.sum_apply theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩ calc sum f s = sum f t := measure_congr ht.symm _ = ∑' i, f i t := sum_apply _ t_meas _ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts /-! For the next theorem, the countability assumption is necessary. For a counterexample, consider an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets not containing `x₀`, and their complements. All points but `x₀` are measurable. Consider the sum of the Dirac masses at points different from `x₀`, and `s = x₀`. For any Dirac mass `δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure `sum δ_x` gives mass one to each point different from `x₀`, so it gives infinite mass to any measurable set containing `x₀` (as such a set is uncountable), and by outer regularity one get `sum δ_x {x₀} = ∞`. -/ theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩ calc sum f s ≤ sum f t := measure_mono hst _ = ∑' i, f i t := sum_apply _ htm _ = ∑' i, f i s := by simp [ht] theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ := le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i #align measure_theory.measure.le_sum MeasureTheory.Measure.le_sum @[simp] theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [sum_apply_of_countable] #align measure_theory.measure.sum_apply_eq_zero MeasureTheory.Measure.sum_apply_eq_zero theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs] #align measure_theory.measure.sum_apply_eq_zero' MeasureTheory.Measure.sum_apply_eq_zero' @[simp] lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by ext s hs simp [Measure.sum_apply _ hs] theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by ext1 s hs simp [sum_apply _ hs, ENNReal.tsum_prod'] theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by ext1 s hs simp_rw [sum_apply _ hs] rw [ENNReal.tsum_comm] #align measure_theory.measure.sum_comm MeasureTheory.Measure.sum_comm theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero #align measure_theory.measure.ae_sum_iff MeasureTheory.Measure.ae_sum_iff theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero' h.compl #align measure_theory.measure.ae_sum_iff' MeasureTheory.Measure.ae_sum_iff' @[simp] theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by ext1 s hs simp only [sum_apply, finset_sum_apply, hs, tsum_fintype] #align measure_theory.measure.sum_fintype MeasureTheory.Measure.sum_fintype theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) : (sum fun i : s => μ i) = ∑ i ∈ s, μ i := by rw [sum_fintype, Finset.sum_coe_sort s μ] #align measure_theory.measure.sum_coe_finset MeasureTheory.Measure.sum_coe_finset @[simp] theorem ae_sum_eq [Countable ι] (μ : ι → Measure α) : ae (sum μ) = ⨆ i, ae (μ i) := Filter.ext fun _ => ae_sum_iff.trans mem_iSup.symm #align measure_theory.measure.ae_sum_eq MeasureTheory.Measure.ae_sum_eq theorem sum_bool (f : Bool → Measure α) : sum f = f true + f false := by rw [sum_fintype, Fintype.sum_bool] #align measure_theory.measure.sum_bool MeasureTheory.Measure.sum_bool theorem sum_cond (μ ν : Measure α) : (sum fun b => cond b μ ν) = μ + ν := sum_bool _ #align measure_theory.measure.sum_cond MeasureTheory.Measure.sum_cond @[simp] theorem sum_of_empty [IsEmpty ι] (μ : ι → Measure α) : sum μ = 0 := by rw [← measure_univ_eq_zero, sum_apply _ MeasurableSet.univ, tsum_empty] #align measure_theory.measure.sum_of_empty MeasureTheory.Measure.sum_of_empty theorem sum_add_sum_compl (s : Set ι) (μ : ι → Measure α) : ((sum fun i : s => μ i) + sum fun i : ↥sᶜ => μ i) = sum μ := by ext1 t ht simp only [add_apply, sum_apply _ ht] exact tsum_add_tsum_compl (f := fun i => μ i t) ENNReal.summable ENNReal.summable #align measure_theory.measure.sum_add_sum_compl MeasureTheory.Measure.sum_add_sum_compl theorem sum_congr {μ ν : ℕ → Measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν := congr_arg sum (funext h) #align measure_theory.measure.sum_congr MeasureTheory.Measure.sum_congr theorem sum_add_sum {ι : Type*} (μ ν : ι → Measure α) : sum μ + sum ν = sum fun n => μ n + ν n := by ext1 s hs simp only [add_apply, sum_apply _ hs, Pi.add_apply, coe_add, tsum_add ENNReal.summable ENNReal.summable] #align measure_theory.measure.sum_add_sum MeasureTheory.Measure.sum_add_sum @[simp] lemma sum_comp_equiv {ι ι' : Type*} (e : ι' ≃ ι) (m : ι → Measure α) : sum (m ∘ e) = sum m := by ext s hs simpa [hs, sum_apply] using e.tsum_eq (fun n ↦ m n s) @[simp] lemma sum_extend_zero {ι ι' : Type*} {f : ι → ι'} (hf : Injective f) (m : ι → Measure α) : sum (Function.extend f m 0) = sum m := by ext s hs simp [*, Function.apply_extend (fun μ : Measure α ↦ μ s)] end Sum /-! ### Absolute continuity -/ /-- We say that `μ` is absolutely continuous with respect to `ν`, or that `μ` is dominated by `ν`, if `ν(A) = 0` implies that `μ(A) = 0`. -/ def AbsolutelyContinuous {_m0 : MeasurableSpace α} (μ ν : Measure α) : Prop := ∀ ⦃s : Set α⦄, ν s = 0 → μ s = 0 #align measure_theory.measure.absolutely_continuous MeasureTheory.Measure.AbsolutelyContinuous @[inherit_doc MeasureTheory.Measure.AbsolutelyContinuous] scoped[MeasureTheory] infixl:50 " ≪ " => MeasureTheory.Measure.AbsolutelyContinuous theorem absolutelyContinuous_of_le (h : μ ≤ ν) : μ ≪ ν := fun s hs => nonpos_iff_eq_zero.1 <| hs ▸ le_iff'.1 h s #align measure_theory.measure.absolutely_continuous_of_le MeasureTheory.Measure.absolutelyContinuous_of_le alias _root_.LE.le.absolutelyContinuous := absolutelyContinuous_of_le #align has_le.le.absolutely_continuous LE.le.absolutelyContinuous theorem absolutelyContinuous_of_eq (h : μ = ν) : μ ≪ ν := h.le.absolutelyContinuous #align measure_theory.measure.absolutely_continuous_of_eq MeasureTheory.Measure.absolutelyContinuous_of_eq alias _root_.Eq.absolutelyContinuous := absolutelyContinuous_of_eq #align eq.absolutely_continuous Eq.absolutelyContinuous namespace AbsolutelyContinuous theorem mk (h : ∀ ⦃s : Set α⦄, MeasurableSet s → ν s = 0 → μ s = 0) : μ ≪ ν := by intro s hs rcases exists_measurable_superset_of_null hs with ⟨t, h1t, h2t, h3t⟩ exact measure_mono_null h1t (h h2t h3t) #align measure_theory.measure.absolutely_continuous.mk MeasureTheory.Measure.AbsolutelyContinuous.mk @[refl] protected theorem refl {_m0 : MeasurableSpace α} (μ : Measure α) : μ ≪ μ := rfl.absolutelyContinuous #align measure_theory.measure.absolutely_continuous.refl MeasureTheory.Measure.AbsolutelyContinuous.refl protected theorem rfl : μ ≪ μ := fun _s hs => hs #align measure_theory.measure.absolutely_continuous.rfl MeasureTheory.Measure.AbsolutelyContinuous.rfl instance instIsRefl [MeasurableSpace α] : IsRefl (Measure α) (· ≪ ·) := ⟨fun _ => AbsolutelyContinuous.rfl⟩ #align measure_theory.measure.absolutely_continuous.is_refl MeasureTheory.Measure.AbsolutelyContinuous.instIsRefl @[simp] protected lemma zero (μ : Measure α) : 0 ≪ μ := fun s _ ↦ by simp @[trans] protected theorem trans (h1 : μ₁ ≪ μ₂) (h2 : μ₂ ≪ μ₃) : μ₁ ≪ μ₃ := fun _s hs => h1 <| h2 hs #align measure_theory.measure.absolutely_continuous.trans MeasureTheory.Measure.AbsolutelyContinuous.trans @[mono] protected theorem map (h : μ ≪ ν) {f : α → β} (hf : Measurable f) : μ.map f ≪ ν.map f := AbsolutelyContinuous.mk fun s hs => by simpa [hf, hs] using @h _ #align measure_theory.measure.absolutely_continuous.map MeasureTheory.Measure.AbsolutelyContinuous.map protected theorem smul [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (h : μ ≪ ν) (c : R) : c • μ ≪ ν := fun s hνs => by simp only [h hνs, smul_eq_mul, smul_apply, smul_zero] #align measure_theory.measure.absolutely_continuous.smul MeasureTheory.Measure.AbsolutelyContinuous.smul protected lemma add (h1 : μ₁ ≪ ν) (h2 : μ₂ ≪ ν') : μ₁ + μ₂ ≪ ν + ν' := by intro s hs simp only [coe_add, Pi.add_apply, add_eq_zero] at hs ⊢ exact ⟨h1 hs.1, h2 hs.2⟩ lemma add_left_iff {μ₁ μ₂ ν : Measure α} : μ₁ + μ₂ ≪ ν ↔ μ₁ ≪ ν ∧ μ₂ ≪ ν := by refine ⟨fun h ↦ ?_, fun h ↦ (h.1.add h.2).trans ?_⟩ · have : ∀ s, ν s = 0 → μ₁ s = 0 ∧ μ₂ s = 0 := by intro s hs0; simpa using h hs0 exact ⟨fun s hs0 ↦ (this s hs0).1, fun s hs0 ↦ (this s hs0).2⟩ · have : ν + ν = 2 • ν := by ext; simp [two_mul] rw [this] exact AbsolutelyContinuous.rfl.smul 2 lemma add_right (h1 : μ ≪ ν) (ν' : Measure α) : μ ≪ ν + ν' := by intro s hs simp only [coe_add, Pi.add_apply, add_eq_zero] at hs ⊢ exact h1 hs.1 end AbsolutelyContinuous @[simp] lemma absolutelyContinuous_zero_iff : μ ≪ 0 ↔ μ = 0 := ⟨fun h ↦ measure_univ_eq_zero.mp (h rfl), fun h ↦ h.symm ▸ AbsolutelyContinuous.zero _⟩ alias absolutelyContinuous_refl := AbsolutelyContinuous.refl alias absolutelyContinuous_rfl := AbsolutelyContinuous.rfl lemma absolutelyContinuous_sum_left {μs : ι → Measure α} (hμs : ∀ i, μs i ≪ ν) : Measure.sum μs ≪ ν := AbsolutelyContinuous.mk fun s hs hs0 ↦ by simp [sum_apply _ hs, fun i ↦ hμs i hs0] lemma absolutelyContinuous_sum_right {μs : ι → Measure α} (i : ι) (hνμ : ν ≪ μs i) : ν ≪ Measure.sum μs := by refine AbsolutelyContinuous.mk fun s hs hs0 ↦ ?_ simp only [sum_apply _ hs, ENNReal.tsum_eq_zero] at hs0 exact hνμ (hs0 i) theorem absolutelyContinuous_of_le_smul {μ' : Measure α} {c : ℝ≥0∞} (hμ'_le : μ' ≤ c • μ) : μ' ≪ μ := (Measure.absolutelyContinuous_of_le hμ'_le).trans (Measure.AbsolutelyContinuous.rfl.smul c) #align measure_theory.measure.absolutely_continuous_of_le_smul MeasureTheory.Measure.absolutelyContinuous_of_le_smul lemma smul_absolutelyContinuous {c : ℝ≥0∞} : c • μ ≪ μ := absolutelyContinuous_of_le_smul le_rfl lemma absolutelyContinuous_smul {c : ℝ≥0∞} (hc : c ≠ 0) : μ ≪ c • μ := by simp [AbsolutelyContinuous, hc] theorem ae_le_iff_absolutelyContinuous : ae μ ≤ ae ν ↔ μ ≪ ν := ⟨fun h s => by rw [measure_zero_iff_ae_nmem, measure_zero_iff_ae_nmem] exact fun hs => h hs, fun h s hs => h hs⟩ #align measure_theory.measure.ae_le_iff_absolutely_continuous MeasureTheory.Measure.ae_le_iff_absolutelyContinuous alias ⟨_root_.LE.le.absolutelyContinuous_of_ae, AbsolutelyContinuous.ae_le⟩ := ae_le_iff_absolutelyContinuous #align has_le.le.absolutely_continuous_of_ae LE.le.absolutelyContinuous_of_ae #align measure_theory.measure.absolutely_continuous.ae_le MeasureTheory.Measure.AbsolutelyContinuous.ae_le alias ae_mono' := AbsolutelyContinuous.ae_le #align measure_theory.measure.ae_mono' MeasureTheory.Measure.ae_mono' theorem AbsolutelyContinuous.ae_eq (h : μ ≪ ν) {f g : α → δ} (h' : f =ᵐ[ν] g) : f =ᵐ[μ] g := h.ae_le h' #align measure_theory.measure.absolutely_continuous.ae_eq MeasureTheory.Measure.AbsolutelyContinuous.ae_eq protected theorem _root_.MeasureTheory.AEDisjoint.of_absolutelyContinuous (h : AEDisjoint μ s t) {ν : Measure α} (h' : ν ≪ μ) : AEDisjoint ν s t := h' h protected theorem _root_.MeasureTheory.AEDisjoint.of_le (h : AEDisjoint μ s t) {ν : Measure α} (h' : ν ≤ μ) : AEDisjoint ν s t := h.of_absolutelyContinuous (Measure.absolutelyContinuous_of_le h') /-! ### Quasi measure preserving maps (a.k.a. non-singular maps) -/ /-- A map `f : α → β` is said to be *quasi measure preserving* (a.k.a. non-singular) w.r.t. measures `μa` and `μb` if it is measurable and `μb s = 0` implies `μa (f ⁻¹' s) = 0`. -/ structure QuasiMeasurePreserving {m0 : MeasurableSpace α} (f : α → β) (μa : Measure α := by volume_tac) (μb : Measure β := by volume_tac) : Prop where protected measurable : Measurable f protected absolutelyContinuous : μa.map f ≪ μb #align measure_theory.measure.quasi_measure_preserving MeasureTheory.Measure.QuasiMeasurePreserving #align measure_theory.measure.quasi_measure_preserving.measurable MeasureTheory.Measure.QuasiMeasurePreserving.measurable #align measure_theory.measure.quasi_measure_preserving.absolutely_continuous MeasureTheory.Measure.QuasiMeasurePreserving.absolutelyContinuous namespace QuasiMeasurePreserving protected theorem id {_m0 : MeasurableSpace α} (μ : Measure α) : QuasiMeasurePreserving id μ μ := ⟨measurable_id, map_id.absolutelyContinuous⟩ #align measure_theory.measure.quasi_measure_preserving.id MeasureTheory.Measure.QuasiMeasurePreserving.id variable {μa μa' : Measure α} {μb μb' : Measure β} {μc : Measure γ} {f : α → β} protected theorem _root_.Measurable.quasiMeasurePreserving {_m0 : MeasurableSpace α} (hf : Measurable f) (μ : Measure α) : QuasiMeasurePreserving f μ (μ.map f) := ⟨hf, AbsolutelyContinuous.rfl⟩ #align measurable.quasi_measure_preserving Measurable.quasiMeasurePreserving theorem mono_left (h : QuasiMeasurePreserving f μa μb) (ha : μa' ≪ μa) : QuasiMeasurePreserving f μa' μb := ⟨h.1, (ha.map h.1).trans h.2⟩ #align measure_theory.measure.quasi_measure_preserving.mono_left MeasureTheory.Measure.QuasiMeasurePreserving.mono_left theorem mono_right (h : QuasiMeasurePreserving f μa μb) (ha : μb ≪ μb') : QuasiMeasurePreserving f μa μb' := ⟨h.1, h.2.trans ha⟩ #align measure_theory.measure.quasi_measure_preserving.mono_right MeasureTheory.Measure.QuasiMeasurePreserving.mono_right @[mono] theorem mono (ha : μa' ≪ μa) (hb : μb ≪ μb') (h : QuasiMeasurePreserving f μa μb) : QuasiMeasurePreserving f μa' μb' := (h.mono_left ha).mono_right hb #align measure_theory.measure.quasi_measure_preserving.mono MeasureTheory.Measure.QuasiMeasurePreserving.mono protected theorem comp {g : β → γ} {f : α → β} (hg : QuasiMeasurePreserving g μb μc) (hf : QuasiMeasurePreserving f μa μb) : QuasiMeasurePreserving (g ∘ f) μa μc := ⟨hg.measurable.comp hf.measurable, by rw [← map_map hg.1 hf.1] exact (hf.2.map hg.1).trans hg.2⟩ #align measure_theory.measure.quasi_measure_preserving.comp MeasureTheory.Measure.QuasiMeasurePreserving.comp protected theorem iterate {f : α → α} (hf : QuasiMeasurePreserving f μa μa) : ∀ n, QuasiMeasurePreserving f^[n] μa μa | 0 => QuasiMeasurePreserving.id μa | n + 1 => (hf.iterate n).comp hf #align measure_theory.measure.quasi_measure_preserving.iterate MeasureTheory.Measure.QuasiMeasurePreserving.iterate protected theorem aemeasurable (hf : QuasiMeasurePreserving f μa μb) : AEMeasurable f μa := hf.1.aemeasurable #align measure_theory.measure.quasi_measure_preserving.ae_measurable MeasureTheory.Measure.QuasiMeasurePreserving.aemeasurable theorem ae_map_le (h : QuasiMeasurePreserving f μa μb) : ae (μa.map f) ≤ ae μb := h.2.ae_le #align measure_theory.measure.quasi_measure_preserving.ae_map_le MeasureTheory.Measure.QuasiMeasurePreserving.ae_map_le theorem tendsto_ae (h : QuasiMeasurePreserving f μa μb) : Tendsto f (ae μa) (ae μb) := (tendsto_ae_map h.aemeasurable).mono_right h.ae_map_le #align measure_theory.measure.quasi_measure_preserving.tendsto_ae MeasureTheory.Measure.QuasiMeasurePreserving.tendsto_ae theorem ae (h : QuasiMeasurePreserving f μa μb) {p : β → Prop} (hg : ∀ᵐ x ∂μb, p x) : ∀ᵐ x ∂μa, p (f x) := h.tendsto_ae hg #align measure_theory.measure.quasi_measure_preserving.ae MeasureTheory.Measure.QuasiMeasurePreserving.ae theorem ae_eq (h : QuasiMeasurePreserving f μa μb) {g₁ g₂ : β → δ} (hg : g₁ =ᵐ[μb] g₂) : g₁ ∘ f =ᵐ[μa] g₂ ∘ f := h.ae hg #align measure_theory.measure.quasi_measure_preserving.ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.ae_eq theorem preimage_null (h : QuasiMeasurePreserving f μa μb) {s : Set β} (hs : μb s = 0) : μa (f ⁻¹' s) = 0 := preimage_null_of_map_null h.aemeasurable (h.2 hs) #align measure_theory.measure.quasi_measure_preserving.preimage_null MeasureTheory.Measure.QuasiMeasurePreserving.preimage_null theorem preimage_mono_ae {s t : Set β} (hf : QuasiMeasurePreserving f μa μb) (h : s ≤ᵐ[μb] t) : f ⁻¹' s ≤ᵐ[μa] f ⁻¹' t := eventually_map.mp <| Eventually.filter_mono (tendsto_ae_map hf.aemeasurable) (Eventually.filter_mono hf.ae_map_le h) #align measure_theory.measure.quasi_measure_preserving.preimage_mono_ae MeasureTheory.Measure.QuasiMeasurePreserving.preimage_mono_ae theorem preimage_ae_eq {s t : Set β} (hf : QuasiMeasurePreserving f μa μb) (h : s =ᵐ[μb] t) : f ⁻¹' s =ᵐ[μa] f ⁻¹' t := EventuallyLE.antisymm (hf.preimage_mono_ae h.le) (hf.preimage_mono_ae h.symm.le) #align measure_theory.measure.quasi_measure_preserving.preimage_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.preimage_ae_eq theorem preimage_iterate_ae_eq {s : Set α} {f : α → α} (hf : QuasiMeasurePreserving f μ μ) (k : ℕ) (hs : f ⁻¹' s =ᵐ[μ] s) : f^[k] ⁻¹' s =ᵐ[μ] s := by induction' k with k ih; · rfl rw [iterate_succ, preimage_comp] exact EventuallyEq.trans (hf.preimage_ae_eq ih) hs #align measure_theory.measure.quasi_measure_preserving.preimage_iterate_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.preimage_iterate_ae_eq theorem image_zpow_ae_eq {s : Set α} {e : α ≃ α} (he : QuasiMeasurePreserving e μ μ) (he' : QuasiMeasurePreserving e.symm μ μ) (k : ℤ) (hs : e '' s =ᵐ[μ] s) : (⇑(e ^ k)) '' s =ᵐ[μ] s := by rw [Equiv.image_eq_preimage] obtain ⟨k, rfl | rfl⟩ := k.eq_nat_or_neg · replace hs : (⇑e⁻¹) ⁻¹' s =ᵐ[μ] s := by rwa [Equiv.image_eq_preimage] at hs replace he' : (⇑e⁻¹)^[k] ⁻¹' s =ᵐ[μ] s := he'.preimage_iterate_ae_eq k hs rwa [Equiv.Perm.iterate_eq_pow e⁻¹ k, inv_pow e k] at he' · rw [zpow_neg, zpow_natCast] replace hs : e ⁻¹' s =ᵐ[μ] s := by convert he.preimage_ae_eq hs.symm rw [Equiv.preimage_image] replace he : (⇑e)^[k] ⁻¹' s =ᵐ[μ] s := he.preimage_iterate_ae_eq k hs rwa [Equiv.Perm.iterate_eq_pow e k] at he #align measure_theory.measure.quasi_measure_preserving.image_zpow_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.image_zpow_ae_eq -- Need to specify `α := Set α` below because of diamond; see #19041 theorem limsup_preimage_iterate_ae_eq {f : α → α} (hf : QuasiMeasurePreserving f μ μ) (hs : f ⁻¹' s =ᵐ[μ] s) : limsup (α := Set α) (fun n => (preimage f)^[n] s) atTop =ᵐ[μ] s := haveI : ∀ n, (preimage f)^[n] s =ᵐ[μ] s := by intro n induction' n with n ih · rfl simpa only [iterate_succ', comp_apply] using ae_eq_trans (hf.ae_eq ih) hs (limsup_ae_eq_of_forall_ae_eq (fun n => (preimage f)^[n] s) this).trans (ae_eq_refl _) #align measure_theory.measure.quasi_measure_preserving.limsup_preimage_iterate_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.limsup_preimage_iterate_ae_eq -- Need to specify `α := Set α` below because of diamond; see #19041 theorem liminf_preimage_iterate_ae_eq {f : α → α} (hf : QuasiMeasurePreserving f μ μ) (hs : f ⁻¹' s =ᵐ[μ] s) : liminf (α := Set α) (fun n => (preimage f)^[n] s) atTop =ᵐ[μ] s := by rw [← ae_eq_set_compl_compl, @Filter.liminf_compl (Set α)] rw [← ae_eq_set_compl_compl, ← preimage_compl] at hs convert hf.limsup_preimage_iterate_ae_eq hs ext1 n simp only [← Set.preimage_iterate_eq, comp_apply, preimage_compl] #align measure_theory.measure.quasi_measure_preserving.liminf_preimage_iterate_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.liminf_preimage_iterate_ae_eq /-- By replacing a measurable set that is almost invariant with the `limsup` of its preimages, we obtain a measurable set that is almost equal and strictly invariant. (The `liminf` would work just as well.) -/ theorem exists_preimage_eq_of_preimage_ae {f : α → α} (h : QuasiMeasurePreserving f μ μ) (hs : MeasurableSet s) (hs' : f ⁻¹' s =ᵐ[μ] s) : ∃ t : Set α, MeasurableSet t ∧ t =ᵐ[μ] s ∧ f ⁻¹' t = t := ⟨limsup (fun n => (preimage f)^[n] s) atTop, MeasurableSet.measurableSet_limsup fun n => preimage_iterate_eq ▸ h.measurable.iterate n hs, h.limsup_preimage_iterate_ae_eq hs', Filter.CompleteLatticeHom.apply_limsup_iterate (CompleteLatticeHom.setPreimage f) s⟩ #align measure_theory.measure.quasi_measure_preserving.exists_preimage_eq_of_preimage_ae MeasureTheory.Measure.QuasiMeasurePreserving.exists_preimage_eq_of_preimage_ae open Pointwise @[to_additive] theorem smul_ae_eq_of_ae_eq {G α : Type*} [Group G] [MulAction G α] [MeasurableSpace α] {s t : Set α} {μ : Measure α} (g : G) (h_qmp : QuasiMeasurePreserving (g⁻¹ • · : α → α) μ μ) (h_ae_eq : s =ᵐ[μ] t) : (g • s : Set α) =ᵐ[μ] (g • t : Set α) := by simpa only [← preimage_smul_inv] using h_qmp.ae_eq h_ae_eq #align measure_theory.measure.quasi_measure_preserving.smul_ae_eq_of_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.smul_ae_eq_of_ae_eq #align measure_theory.measure.quasi_measure_preserving.vadd_ae_eq_of_ae_eq MeasureTheory.Measure.QuasiMeasurePreserving.vadd_ae_eq_of_ae_eq end QuasiMeasurePreserving section Pointwise open Pointwise @[to_additive] theorem pairwise_aedisjoint_of_aedisjoint_forall_ne_one {G α : Type*} [Group G] [MulAction G α] [MeasurableSpace α] {μ : Measure α} {s : Set α} (h_ae_disjoint : ∀ g ≠ (1 : G), AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving (g • ·) μ μ) : Pairwise (AEDisjoint μ on fun g : G => g • s) := by intro g₁ g₂ hg let g := g₂⁻¹ * g₁ replace hg : g ≠ 1 := by rw [Ne, inv_mul_eq_one] exact hg.symm have : (g₂⁻¹ • ·) ⁻¹' (g • s ∩ s) = g₁ • s ∩ g₂ • s := by rw [preimage_eq_iff_eq_image (MulAction.bijective g₂⁻¹), image_smul, smul_set_inter, smul_smul, smul_smul, inv_mul_self, one_smul] change μ (g₁ • s ∩ g₂ • s) = 0 exact this ▸ (h_qmp g₂⁻¹).preimage_null (h_ae_disjoint g hg) #align measure_theory.measure.pairwise_ae_disjoint_of_ae_disjoint_forall_ne_one MeasureTheory.Measure.pairwise_aedisjoint_of_aedisjoint_forall_ne_one #align measure_theory.measure.pairwise_ae_disjoint_of_ae_disjoint_forall_ne_zero MeasureTheory.Measure.pairwise_aedisjoint_of_aedisjoint_forall_ne_zero end Pointwise /-! ### The `cofinite` filter -/ /-- The filter of sets `s` such that `sᶜ` has finite measure. -/ def cofinite {m0 : MeasurableSpace α} (μ : Measure α) : Filter α := comk (μ · < ∞) (by simp) (fun t ht s hs ↦ (measure_mono hs).trans_lt ht) fun s hs t ht ↦ (measure_union_le s t).trans_lt <| ENNReal.add_lt_top.2 ⟨hs, ht⟩ #align measure_theory.measure.cofinite MeasureTheory.Measure.cofinite theorem mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ := Iff.rfl #align measure_theory.measure.mem_cofinite MeasureTheory.Measure.mem_cofinite theorem compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ := by rw [mem_cofinite, compl_compl] #align measure_theory.measure.compl_mem_cofinite MeasureTheory.Measure.compl_mem_cofinite theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ { x | ¬p x } < ∞ := Iff.rfl #align measure_theory.measure.eventually_cofinite MeasureTheory.Measure.eventually_cofinite end Measure open Measure open MeasureTheory protected theorem _root_.AEMeasurable.nullMeasurable {f : α → β} (h : AEMeasurable f μ) : NullMeasurable f μ := let ⟨_g, hgm, hg⟩ := h; hgm.nullMeasurable.congr hg.symm #align ae_measurable.null_measurable AEMeasurable.nullMeasurable lemma _root_.AEMeasurable.nullMeasurableSet_preimage {f : α → β} {s : Set β} (hf : AEMeasurable f μ) (hs : MeasurableSet s) : NullMeasurableSet (f ⁻¹' s) μ := hf.nullMeasurable hs /-- The preimage of a null measurable set under a (quasi) measure preserving map is a null measurable set. -/ theorem NullMeasurableSet.preimage {ν : Measure β} {f : α → β} {t : Set β} (ht : NullMeasurableSet t ν) (hf : QuasiMeasurePreserving f μ ν) : NullMeasurableSet (f ⁻¹' t) μ := ⟨f ⁻¹' toMeasurable ν t, hf.measurable (measurableSet_toMeasurable _ _), hf.ae_eq ht.toMeasurable_ae_eq.symm⟩ #align measure_theory.null_measurable_set.preimage MeasureTheory.NullMeasurableSet.preimage theorem NullMeasurableSet.mono_ac (h : NullMeasurableSet s μ) (hle : ν ≪ μ) : NullMeasurableSet s ν := h.preimage <| (QuasiMeasurePreserving.id μ).mono_left hle #align measure_theory.null_measurable_set.mono_ac MeasureTheory.NullMeasurableSet.mono_ac theorem NullMeasurableSet.mono (h : NullMeasurableSet s μ) (hle : ν ≤ μ) : NullMeasurableSet s ν := h.mono_ac hle.absolutelyContinuous #align measure_theory.null_measurable_set.mono MeasureTheory.NullMeasurableSet.mono theorem AEDisjoint.preimage {ν : Measure β} {f : α → β} {s t : Set β} (ht : AEDisjoint ν s t) (hf : QuasiMeasurePreserving f μ ν) : AEDisjoint μ (f ⁻¹' s) (f ⁻¹' t) := hf.preimage_null ht #align measure_theory.ae_disjoint.preimage MeasureTheory.AEDisjoint.preimage @[simp]
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
1,986
1,987
theorem ae_eq_bot : ae μ = ⊥ ↔ μ = 0 := by
rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Shing Tak Lam, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Log import Mathlib.Data.List.Indexes import Mathlib.Data.List.Palindrome import Mathlib.Tactic.IntervalCases import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring #align_import data.nat.digits from "leanprover-community/mathlib"@"369525b73f229ccd76a6ec0e0e0bf2be57599768" /-! # Digits of a natural number This provides a basic API for extracting the digits of a natural number in a given base, and reconstructing numbers from their digits. We also prove some divisibility tests based on digits, in particular completing Theorem #85 from https://www.cs.ru.nl/~freek/100/. Also included is a bound on the length of `Nat.toDigits` from core. ## TODO A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b` are numerals is not yet ported. -/ namespace Nat variable {n : ℕ} /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux0 : ℕ → List ℕ | 0 => [] | n + 1 => [n + 1] #align nat.digits_aux_0 Nat.digitsAux0 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux1 (n : ℕ) : List ℕ := List.replicate n 1 #align nat.digits_aux_1 Nat.digitsAux1 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ | 0 => [] | n + 1 => ((n + 1) % b) :: digitsAux b h ((n + 1) / b) decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h #align nat.digits_aux Nat.digitsAux @[simp] theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux] #align nat.digits_aux_zero Nat.digitsAux_zero theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) : digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by cases n · cases w · rw [digitsAux] #align nat.digits_aux_def Nat.digitsAux_def /-- `digits b n` gives the digits, in little-endian order, of a natural number `n` in a specified base `b`. In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`. * For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`, and the last digit is not zero. This uniquely specifies the behaviour of `digits b`. * For `b = 1`, we define `digits 1 n = List.replicate n 1`. * For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`. Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals. In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`. -/ def digits : ℕ → ℕ → List ℕ | 0 => digitsAux0 | 1 => digitsAux1 | b + 2 => digitsAux (b + 2) (by norm_num) #align nat.digits Nat.digits @[simp] theorem digits_zero (b : ℕ) : digits b 0 = [] := by rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1] #align nat.digits_zero Nat.digits_zero -- @[simp] -- Porting note (#10618): simp can prove this theorem digits_zero_zero : digits 0 0 = [] := rfl #align nat.digits_zero_zero Nat.digits_zero_zero @[simp] theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] := rfl #align nat.digits_zero_succ Nat.digits_zero_succ theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n] | 0, h => (h rfl).elim | _ + 1, _ => rfl #align nat.digits_zero_succ' Nat.digits_zero_succ' @[simp] theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 := rfl #align nat.digits_one Nat.digits_one -- @[simp] -- Porting note (#10685): dsimp can prove this theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n := rfl #align nat.digits_one_succ Nat.digits_one_succ theorem digits_add_two_add_one (b n : ℕ) : digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by simp [digits, digitsAux_def] #align nat.digits_add_two_add_one Nat.digits_add_two_add_one @[simp] lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) : Nat.digits b n = n % b :: Nat.digits b (n / b) := by rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one] theorem digits_def' : ∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b) | 0, h => absurd h (by decide) | 1, h => absurd h (by decide) | b + 2, _ => digitsAux_def _ (by simp) _ #align nat.digits_def' Nat.digits_def' @[simp] theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩ rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩ rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb] #align nat.digits_of_lt Nat.digits_of_lt theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) : digits b (x + b * y) = x :: digits b y := by rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩ cases y · simp [hxb, hxy.resolve_right (absurd rfl)] dsimp [digits] rw [digitsAux_def] · congr · simp [Nat.add_mod, mod_eq_of_lt hxb] · simp [add_mul_div_left, div_eq_of_lt hxb] · apply Nat.succ_pos #align nat.digits_add Nat.digits_add -- If we had a function converting a list into a polynomial, -- and appropriate lemmas about that function, -- we could rewrite this in terms of that. /-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them as a number in semiring, as the little-endian digits in base `b`. -/ def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α | [] => 0 | h :: t => h + b * ofDigits b t #align nat.of_digits Nat.ofDigits theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) : ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by induction' L with d L ih · rfl · dsimp [ofDigits] rw [ih] #align nat.of_digits_eq_foldr Nat.ofDigits_eq_foldr theorem ofDigits_eq_sum_map_with_index_aux (b : ℕ) (l : List ℕ) : ((List.range l.length).zipWith ((fun i a : ℕ => a * b ^ (i + 1))) l).sum = b * ((List.range l.length).zipWith (fun i a => a * b ^ i) l).sum := by suffices (List.range l.length).zipWith (fun i a : ℕ => a * b ^ (i + 1)) l = (List.range l.length).zipWith (fun i a => b * (a * b ^ i)) l by simp [this] congr; ext; simp [pow_succ]; ring #align nat.of_digits_eq_sum_map_with_index_aux Nat.ofDigits_eq_sum_map_with_index_aux theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) : ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by rw [List.mapIdx_eq_enum_map, List.enum_eq_zip_range, List.map_uncurry_zip_eq_zipWith, ofDigits_eq_foldr] induction' L with hd tl hl · simp · simpa [List.range_succ_eq_map, List.zipWith_map_left, ofDigits_eq_sum_map_with_index_aux] using Or.inl hl #align nat.of_digits_eq_sum_map_with_index Nat.ofDigits_eq_sum_mapIdx @[simp] theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl @[simp] theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits] #align nat.of_digits_singleton Nat.ofDigits_singleton @[simp] theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) : ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits] #align nat.of_digits_one_cons Nat.ofDigits_one_cons theorem ofDigits_cons {b hd} {tl : List ℕ} : ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} : ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by induction' l1 with hd tl IH · simp [ofDigits] · rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ'] ring #align nat.of_digits_append Nat.ofDigits_append @[norm_cast] theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by induction' L with d L ih · simp [ofDigits] · dsimp [ofDigits]; push_cast; rw [ih] #align nat.coe_of_digits Nat.coe_ofDigits @[norm_cast] theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by induction' L with d L _ · rfl · dsimp [ofDigits]; push_cast; simp only #align nat.coe_int_of_digits Nat.coe_int_ofDigits theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) : ∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0 | _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0 | _ :: _, h0, _, List.Mem.tail _ hL => digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL #align nat.digits_zero_of_eq_zero Nat.digits_zero_of_eq_zero theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b) (w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by induction' L with d L ih · dsimp [ofDigits] simp · dsimp [ofDigits] replace w₂ := w₂ (by simp) rw [digits_add b h] · rw [ih] · intro l m apply w₁ exact List.mem_cons_of_mem _ m · intro h rw [List.getLast_cons h] at w₂ convert w₂ · exact w₁ d (List.mem_cons_self _ _) · by_cases h' : L = [] · rcases h' with rfl left simpa using w₂ · right contrapose! w₂ refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_ rw [List.getLast_cons h'] exact List.getLast_mem h' #align nat.digits_of_digits Nat.digits_ofDigits theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by cases' b with b · cases' n with n · rfl · change ofDigits 0 [n + 1] = n + 1 dsimp [ofDigits] · cases' b with b · induction' n with n ih · rfl · rw [Nat.zero_add] at ih ⊢ simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ] · apply Nat.strongInductionOn n _ clear n intro n h cases n · rw [digits_zero] rfl · simp only [Nat.succ_eq_add_one, digits_add_two_add_one] dsimp [ofDigits] rw [h _ (Nat.div_lt_self' _ b)] rw [Nat.mod_add_div] #align nat.of_digits_digits Nat.ofDigits_digits theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by induction' L with _ _ ih · rfl · simp [ofDigits, List.sum_cons, ih] #align nat.of_digits_one Nat.ofDigits_one /-! ### Properties This section contains various lemmas of properties relating to `digits` and `ofDigits`. -/ theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by constructor · intro h have : ofDigits b (digits b n) = ofDigits b [] := by rw [h] convert this rw [ofDigits_digits] · rintro rfl simp #align nat.digits_eq_nil_iff_eq_zero Nat.digits_eq_nil_iff_eq_zero theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 := not_congr digits_eq_nil_iff_eq_zero #align nat.digits_ne_nil_iff_ne_zero Nat.digits_ne_nil_iff_ne_zero theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) : digits b n = (n % b) :: digits b (n / b) := by rcases b with (_ | _ | b) · rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero] · norm_num at h rcases n with (_ | n) · norm_num at w · simp only [digits_add_two_add_one, ne_eq] #align nat.digits_eq_cons_digits_div Nat.digits_eq_cons_digits_div theorem digits_getLast {b : ℕ} (m : ℕ) (h : 1 < b) (p q) : (digits b m).getLast p = (digits b (m / b)).getLast q := by by_cases hm : m = 0 · simp [hm] simp only [digits_eq_cons_digits_div h hm] rw [List.getLast_cons] #align nat.digits_last Nat.digits_getLast theorem digits.injective (b : ℕ) : Function.Injective b.digits := Function.LeftInverse.injective (ofDigits_digits b) #align nat.digits.injective Nat.digits.injective @[simp] theorem digits_inj_iff {b n m : ℕ} : b.digits n = b.digits m ↔ n = m := (digits.injective b).eq_iff #align nat.digits_inj_iff Nat.digits_inj_iff theorem digits_len (b n : ℕ) (hb : 1 < b) (hn : n ≠ 0) : (b.digits n).length = b.log n + 1 := by induction' n using Nat.strong_induction_on with n IH rw [digits_eq_cons_digits_div hb hn, List.length] by_cases h : n / b = 0 · have hb0 : b ≠ 0 := (Nat.succ_le_iff.1 hb).ne_bot simp [h, log_eq_zero_iff, ← Nat.div_eq_zero_iff hb0.bot_lt] · have : n / b < n := div_lt_self (Nat.pos_of_ne_zero hn) hb rw [IH _ this h, log_div_base, tsub_add_cancel_of_le] refine Nat.succ_le_of_lt (log_pos hb ?_) contrapose! h exact div_eq_of_lt h #align nat.digits_len Nat.digits_len theorem getLast_digit_ne_zero (b : ℕ) {m : ℕ} (hm : m ≠ 0) : (digits b m).getLast (digits_ne_nil_iff_ne_zero.mpr hm) ≠ 0 := by rcases b with (_ | _ | b) · cases m · cases hm rfl · simp · cases m · cases hm rfl rename ℕ => m simp only [zero_add, digits_one, List.getLast_replicate_succ m 1] exact Nat.one_ne_zero revert hm apply Nat.strongInductionOn m intro n IH hn by_cases hnb : n < b + 2 · simpa only [digits_of_lt (b + 2) n hn hnb] · rw [digits_getLast n (le_add_left 2 b)] refine IH _ (Nat.div_lt_self hn.bot_lt (one_lt_succ_succ b)) ?_ rw [← pos_iff_ne_zero] exact Nat.div_pos (le_of_not_lt hnb) (zero_lt_succ (succ b)) #align nat.last_digit_ne_zero Nat.getLast_digit_ne_zero theorem mul_ofDigits (n : ℕ) {b : ℕ} {l : List ℕ} : n * ofDigits b l = ofDigits b (l.map (n * ·)) := by induction l with | nil => rfl | cons hd tl ih => rw [List.map_cons, ofDigits_cons, ofDigits_cons, ← ih] ring /-- The addition of ofDigits of two lists is equal to ofDigits of digit-wise addition of them-/ theorem ofDigits_add_ofDigits_eq_ofDigits_zipWith_of_length_eq {b : ℕ} {l1 l2 : List ℕ} (h : l1.length = l2.length) : ofDigits b l1 + ofDigits b l2 = ofDigits b (l1.zipWith (· + ·) l2) := by induction l1 generalizing l2 with | nil => simp_all [eq_comm, List.length_eq_zero, ofDigits] | cons hd₁ tl₁ ih₁ => induction l2 generalizing tl₁ with | nil => simp_all | cons hd₂ tl₂ ih₂ => simp_all only [List.length_cons, succ_eq_add_one, ofDigits_cons, add_left_inj, eq_comm, List.zipWith_cons_cons, add_eq] rw [← ih₁ h.symm, mul_add] ac_rfl /-- The digits in the base b+2 expansion of n are all less than b+2 -/ theorem digits_lt_base' {b m : ℕ} : ∀ {d}, d ∈ digits (b + 2) m → d < b + 2 := by apply Nat.strongInductionOn m intro n IH d hd cases' n with n · rw [digits_zero] at hd cases hd -- base b+2 expansion of 0 has no digits rw [digits_add_two_add_one] at hd cases hd · exact n.succ.mod_lt (by simp) -- Porting note: Previous code (single line) contained linarith. -- . exact IH _ (Nat.div_lt_self (Nat.succ_pos _) (by linarith)) hd · apply IH ((n + 1) / (b + 2)) · apply Nat.div_lt_self <;> omega · assumption #align nat.digits_lt_base' Nat.digits_lt_base' /-- The digits in the base b expansion of n are all less than b, if b ≥ 2 -/ theorem digits_lt_base {b m d : ℕ} (hb : 1 < b) (hd : d ∈ digits b m) : d < b := by rcases b with (_ | _ | b) <;> try simp_all exact digits_lt_base' hd #align nat.digits_lt_base Nat.digits_lt_base /-- an n-digit number in base b + 2 is less than (b + 2)^n -/ theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) : ofDigits (b + 2) l < (b + 2) ^ l.length := by induction' l with hd tl IH · simp [ofDigits] · rw [ofDigits, List.length_cons, pow_succ] have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) := mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le]) (Nat.zero_le _) suffices ↑hd < b + 2 by linarith exact hl hd (List.mem_cons_self _ _) #align nat.of_digits_lt_base_pow_length' Nat.ofDigits_lt_base_pow_length' /-- an n-digit number in base b is less than b^n if b > 1 -/ theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) : ofDigits b l < b ^ l.length := by rcases b with (_ | _ | b) <;> try simp_all exact ofDigits_lt_base_pow_length' hl #align nat.of_digits_lt_base_pow_length Nat.ofDigits_lt_base_pow_length /-- Any number m is less than (b+2)^(number of digits in the base b + 2 representation of m) -/ theorem lt_base_pow_length_digits' {b m : ℕ} : m < (b + 2) ^ (digits (b + 2) m).length := by convert @ofDigits_lt_base_pow_length' b (digits (b + 2) m) fun _ => digits_lt_base' rw [ofDigits_digits (b + 2) m] #align nat.lt_base_pow_length_digits' Nat.lt_base_pow_length_digits' /-- Any number m is less than b^(number of digits in the base b representation of m) -/ theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by rcases b with (_ | _ | b) <;> try simp_all exact lt_base_pow_length_digits' #align nat.lt_base_pow_length_digits Nat.lt_base_pow_length_digits theorem ofDigits_digits_append_digits {b m n : ℕ} : ofDigits b (digits b n ++ digits b m) = n + b ^ (digits b n).length * m := by rw [ofDigits_append, ofDigits_digits, ofDigits_digits] #align nat.of_digits_digits_append_digits Nat.ofDigits_digits_append_digits theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) : digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb) · simp [List.replicate_add] rw [← ofDigits_digits_append_digits] refine (digits_ofDigits b hb _ (fun l hl => ?_) (fun h_append => ?_)).symm · rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h · by_cases h : digits b m = [] · simp only [h, List.append_nil] at h_append ⊢ exact getLast_digit_ne_zero b <| digits_ne_nil_iff_ne_zero.mp h_append · exact (List.getLast_append' _ _ h) ▸ (getLast_digit_ne_zero _ <| digits_ne_nil_iff_ne_zero.mp h) theorem digits_len_le_digits_len_succ (b n : ℕ) : (digits b n).length ≤ (digits b (n + 1)).length := by rcases Decidable.eq_or_ne n 0 with (rfl | hn) · simp rcases le_or_lt b 1 with hb | hb · interval_cases b <;> simp_arith [digits_zero_succ', hn] simpa [digits_len, hb, hn] using log_mono_right (le_succ _) #align nat.digits_len_le_digits_len_succ Nat.digits_len_le_digits_len_succ theorem le_digits_len_le (b n m : ℕ) (h : n ≤ m) : (digits b n).length ≤ (digits b m).length := monotone_nat_of_le_succ (digits_len_le_digits_len_succ b) h #align nat.le_digits_len_le Nat.le_digits_len_le @[mono] theorem ofDigits_monotone {p q : ℕ} (L : List ℕ) (h : p ≤ q) : ofDigits p L ≤ ofDigits q L := by induction' L with _ _ hi · rfl · simp only [ofDigits, cast_id, add_le_add_iff_left] exact Nat.mul_le_mul h hi theorem sum_le_ofDigits {p : ℕ} (L : List ℕ) (h : 1 ≤ p) : L.sum ≤ ofDigits p L := (ofDigits_one L).symm ▸ ofDigits_monotone L h theorem digit_sum_le (p n : ℕ) : List.sum (digits p n) ≤ n := by induction' n with n · exact digits_zero _ ▸ Nat.le_refl (List.sum []) · induction' p with p · rw [digits_zero_succ, List.sum_cons, List.sum_nil, add_zero] · nth_rw 2 [← ofDigits_digits p.succ (n + 1)] rw [← ofDigits_one <| digits p.succ n.succ] exact ofDigits_monotone (digits p.succ n.succ) <| Nat.succ_pos p theorem pow_length_le_mul_ofDigits {b : ℕ} {l : List ℕ} (hl : l ≠ []) (hl2 : l.getLast hl ≠ 0) : (b + 2) ^ l.length ≤ (b + 2) * ofDigits (b + 2) l := by rw [← List.dropLast_append_getLast hl] simp only [List.length_append, List.length, zero_add, List.length_dropLast, ofDigits_append, List.length_dropLast, ofDigits_singleton, add_comm (l.length - 1), pow_add, pow_one] apply Nat.mul_le_mul_left refine le_trans ?_ (Nat.le_add_left _ _) have : 0 < l.getLast hl := by rwa [pos_iff_ne_zero] convert Nat.mul_le_mul_left ((b + 2) ^ (l.length - 1)) this using 1 rw [Nat.mul_one] #align nat.pow_length_le_mul_of_digits Nat.pow_length_le_mul_ofDigits /-- Any non-zero natural number `m` is greater than (b+2)^((number of digits in the base (b+2) representation of m) - 1) -/ theorem base_pow_length_digits_le' (b m : ℕ) (hm : m ≠ 0) : (b + 2) ^ (digits (b + 2) m).length ≤ (b + 2) * m := by have : digits (b + 2) m ≠ [] := digits_ne_nil_iff_ne_zero.mpr hm convert @pow_length_le_mul_ofDigits b (digits (b+2) m) this (getLast_digit_ne_zero _ hm) rw [ofDigits_digits] #align nat.base_pow_length_digits_le' Nat.base_pow_length_digits_le' /-- Any non-zero natural number `m` is greater than b^((number of digits in the base b representation of m) - 1) -/ theorem base_pow_length_digits_le (b m : ℕ) (hb : 1 < b) : m ≠ 0 → b ^ (digits b m).length ≤ b * m := by rcases b with (_ | _ | b) <;> try simp_all exact base_pow_length_digits_le' b m #align nat.base_pow_length_digits_le Nat.base_pow_length_digits_le /-- Interpreting as a base `p` number and dividing by `p` is the same as interpreting the tail. -/ lemma ofDigits_div_eq_ofDigits_tail {p : ℕ} (hpos : 0 < p) (digits : List ℕ) (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p = ofDigits p digits.tail := by induction' digits with hd tl · simp [ofDigits] · refine Eq.trans (add_mul_div_left hd _ hpos) ?_ rw [Nat.div_eq_of_lt <| w₁ _ <| List.mem_cons_self _ _, zero_add] rfl /-- Interpreting as a base `p` number and dividing by `p^i` is the same as dropping `i`. -/ lemma ofDigits_div_pow_eq_ofDigits_drop {p : ℕ} (i : ℕ) (hpos : 0 < p) (digits : List ℕ) (w₁ : ∀ l ∈ digits, l < p) : ofDigits p digits / p ^ i = ofDigits p (digits.drop i) := by induction' i with i hi · simp · rw [Nat.pow_succ, ← Nat.div_div_eq_div_mul, hi, ofDigits_div_eq_ofDigits_tail hpos (List.drop i digits) fun x hx ↦ w₁ x <| List.mem_of_mem_drop hx, ← List.drop_one, List.drop_drop, add_comm] /-- Dividing `n` by `p^i` is like truncating the first `i` digits of `n` in base `p`. -/ lemma self_div_pow_eq_ofDigits_drop {p : ℕ} (i n : ℕ) (h : 2 ≤ p): n / p ^ i = ofDigits p ((p.digits n).drop i) := by convert ofDigits_div_pow_eq_ofDigits_drop i (zero_lt_of_lt h) (p.digits n) (fun l hl ↦ digits_lt_base h hl) exact (ofDigits_digits p n).symm open Finset theorem sub_one_mul_sum_div_pow_eq_sub_sum_digits {p : ℕ} (L : List ℕ) {h_nonempty} (h_ne_zero : L.getLast h_nonempty ≠ 0) (h_lt : ∀ l ∈ L, l < p) : (p - 1) * ∑ i ∈ range L.length, (ofDigits p L) / p ^ i.succ = (ofDigits p L) - L.sum := by obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p · induction' L with hd tl ih · simp [ofDigits] · simp only [List.length_cons, List.sum_cons, self_div_pow_eq_ofDigits_drop _ _ h, digits_ofDigits p h (hd :: tl) h_lt (fun _ => h_ne_zero)] simp only [ofDigits] rw [sum_range_succ, Nat.cast_id] simp only [List.drop, List.drop_length] obtain rfl | h' := em <| tl = [] · simp [ofDigits] · have w₁' := fun l hl ↦ h_lt l <| List.mem_cons_of_mem hd hl have w₂' := fun (h : tl ≠ []) ↦ (List.getLast_cons h) ▸ h_ne_zero have ih := ih (w₂' h') w₁' simp only [self_div_pow_eq_ofDigits_drop _ _ h, digits_ofDigits p h tl w₁' w₂', ← Nat.one_add] at ih have := sum_singleton (fun x ↦ ofDigits p <| tl.drop x) tl.length rw [← Ico_succ_singleton, List.drop_length, ofDigits] at this have h₁ : 1 ≤ tl.length := List.length_pos.mpr h' rw [← sum_range_add_sum_Ico _ <| h₁, ← add_zero (∑ x ∈ Ico _ _, ofDigits p (tl.drop x)), ← this, sum_Ico_consecutive _ h₁ <| (le_add_right tl.length 1), ← sum_Ico_add _ 0 tl.length 1, Ico_zero_eq_range, mul_add, mul_add, ih, range_one, sum_singleton, List.drop, ofDigits, mul_zero, add_zero, ← Nat.add_sub_assoc <| sum_le_ofDigits _ <| Nat.le_of_lt h] nth_rw 2 [← one_mul <| ofDigits p tl] rw [← add_mul, one_eq_succ_zero, Nat.sub_add_cancel <| zero_lt_of_lt h, Nat.add_sub_add_left] · simp [ofDigits_one] · simp [lt_one_iff.mp h] cases L · rfl · simp [ofDigits] theorem sub_one_mul_sum_log_div_pow_eq_sub_sum_digits {p : ℕ} (n : ℕ) : (p - 1) * ∑ i ∈ range (log p n).succ, n / p ^ i.succ = n - (p.digits n).sum := by obtain h | rfl | h : 1 < p ∨ 1 = p ∨ p < 1 := trichotomous 1 p · rcases eq_or_ne n 0 with rfl | hn · simp · convert sub_one_mul_sum_div_pow_eq_sub_sum_digits (p.digits n) (getLast_digit_ne_zero p hn) <| (fun l a ↦ digits_lt_base h a) · refine (digits_len p n h hn).symm all_goals exact (ofDigits_digits p n).symm · simp · simp [lt_one_iff.mp h] cases n all_goals simp /-! ### Binary -/ theorem digits_two_eq_bits (n : ℕ) : digits 2 n = n.bits.map fun b => cond b 1 0 := by induction' n using Nat.binaryRecFromOne with b n h ih · simp · rfl rw [bits_append_bit _ _ fun hn => absurd hn h] cases b · rw [digits_def' one_lt_two] · simpa [Nat.bit, Nat.bit0_val n] · simpa [pos_iff_ne_zero, Nat.bit0_eq_zero] · simpa [Nat.bit, Nat.bit1_val n, add_comm, digits_add 2 one_lt_two 1 n, Nat.add_mul_div_left] #align nat.digits_two_eq_bits Nat.digits_two_eq_bits /-! ### Modular Arithmetic -/ -- This is really a theorem about polynomials. theorem dvd_ofDigits_sub_ofDigits {α : Type*} [CommRing α] {a b k : α} (h : k ∣ a - b) (L : List ℕ) : k ∣ ofDigits a L - ofDigits b L := by induction' L with d L ih · change k ∣ 0 - 0 simp · simp only [ofDigits, add_sub_add_left_eq_sub] exact dvd_mul_sub_mul h ih #align nat.dvd_of_digits_sub_of_digits Nat.dvd_ofDigits_sub_ofDigits theorem ofDigits_modEq' (b b' : ℕ) (k : ℕ) (h : b ≡ b' [MOD k]) (L : List ℕ) : ofDigits b L ≡ ofDigits b' L [MOD k] := by induction' L with d L ih · rfl · dsimp [ofDigits] dsimp [Nat.ModEq] at * conv_lhs => rw [Nat.add_mod, Nat.mul_mod, h, ih] conv_rhs => rw [Nat.add_mod, Nat.mul_mod] #align nat.of_digits_modeq' Nat.ofDigits_modEq' theorem ofDigits_modEq (b k : ℕ) (L : List ℕ) : ofDigits b L ≡ ofDigits (b % k) L [MOD k] := ofDigits_modEq' b (b % k) k (b.mod_modEq k).symm L #align nat.of_digits_modeq Nat.ofDigits_modEq theorem ofDigits_mod (b k : ℕ) (L : List ℕ) : ofDigits b L % k = ofDigits (b % k) L % k := ofDigits_modEq b k L #align nat.of_digits_mod Nat.ofDigits_mod
Mathlib/Data/Nat/Digits.lean
666
667
theorem ofDigits_mod_eq_head! (b : ℕ) (l : List ℕ) : ofDigits b l % b = l.head! % b := by
induction l <;> simp [Nat.ofDigits, Int.ModEq]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Logic.Pairwise import Mathlib.Order.CompleteBooleanAlgebra import Mathlib.Order.Directed import Mathlib.Order.GaloisConnection #align_import data.set.lattice from "leanprover-community/mathlib"@"b86832321b586c6ac23ef8cdef6a7a27e42b13bd" /-! # The set lattice This file provides usual set notation for unions and intersections, a `CompleteLattice` instance for `Set α`, and some more set constructions. ## Main declarations * `Set.iUnion`: **i**ndexed **union**. Union of an indexed family of sets. * `Set.iInter`: **i**ndexed **inter**section. Intersection of an indexed family of sets. * `Set.sInter`: **s**et **inter**section. Intersection of sets belonging to a set of sets. * `Set.sUnion`: **s**et **union**. Union of sets belonging to a set of sets. * `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and `⋃₀ s = ⋃ x ∈ s, x`. * `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`, `< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference. See `Set.BooleanAlgebra`. * `Set.kernImage`: For a function `f : α → β`, `s.kernImage f` is the set of `y` such that `f ⁻¹ y ⊆ s`. * `Set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union of `f '' t` over all `f ∈ s`, where `t : Set α` and `s : Set (α → β)`. * `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an indexed family of disjoint sets. ## Naming convention In lemma names, * `⋃ i, s i` is called `iUnion` * `⋂ i, s i` is called `iInter` * `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`. * `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`. * `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂` where `j : i ∈ s`. * `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂` where `j : i ∈ s`. ## Notation * `⋃`: `Set.iUnion` * `⋂`: `Set.iInter` * `⋃₀`: `Set.sUnion` * `⋂₀`: `Set.sInter` -/ open Function Set universe u variable {α β γ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*} namespace Set /-! ### Complete lattice and complete Boolean algebra instances -/ theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by simp_rw [mem_iUnion] #align set.mem_Union₂ Set.mem_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by simp_rw [mem_iInter] #align set.mem_Inter₂ Set.mem_iInter₂ theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ #align set.mem_Union_of_mem Set.mem_iUnion_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) : a ∈ ⋃ (i) (j), s i j := mem_iUnion₂.2 ⟨i, j, ha⟩ #align set.mem_Union₂_of_mem Set.mem_iUnion₂_of_mem theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i := mem_iInter.2 h #align set.mem_Inter_of_mem Set.mem_iInter_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) : a ∈ ⋂ (i) (j), s i j := mem_iInter₂.2 h #align set.mem_Inter₂_of_mem Set.mem_iInter₂_of_mem instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Set α) := { instBooleanAlgebraSet with le_sSup := fun s t t_in a a_in => ⟨t, t_in, a_in⟩ sSup_le := fun s t h a ⟨t', ⟨t'_in, a_in⟩⟩ => h t' t'_in a_in le_sInf := fun s t h a a_in t' t'_in => h t' t'_in a_in sInf_le := fun s t t_in a h => h _ t_in iInf_iSup_eq := by intros; ext; simp [Classical.skolem] } section GaloisConnection variable {f : α → β} protected theorem image_preimage : GaloisConnection (image f) (preimage f) := fun _ _ => image_subset_iff #align set.image_preimage Set.image_preimage protected theorem preimage_kernImage : GaloisConnection (preimage f) (kernImage f) := fun _ _ => subset_kernImage_iff.symm #align set.preimage_kern_image Set.preimage_kernImage end GaloisConnection section kernImage variable {f : α → β} lemma kernImage_mono : Monotone (kernImage f) := Set.preimage_kernImage.monotone_u lemma kernImage_eq_compl {s : Set α} : kernImage f s = (f '' sᶜ)ᶜ := Set.preimage_kernImage.u_unique (Set.image_preimage.compl) (fun t ↦ compl_compl (f ⁻¹' t) ▸ Set.preimage_compl) lemma kernImage_compl {s : Set α} : kernImage f (sᶜ) = (f '' s)ᶜ := by rw [kernImage_eq_compl, compl_compl] lemma kernImage_empty : kernImage f ∅ = (range f)ᶜ := by rw [kernImage_eq_compl, compl_empty, image_univ] lemma kernImage_preimage_eq_iff {s : Set β} : kernImage f (f ⁻¹' s) = s ↔ (range f)ᶜ ⊆ s := by rw [kernImage_eq_compl, ← preimage_compl, compl_eq_comm, eq_comm, image_preimage_eq_iff, compl_subset_comm] lemma compl_range_subset_kernImage {s : Set α} : (range f)ᶜ ⊆ kernImage f s := by rw [← kernImage_empty] exact kernImage_mono (empty_subset _) lemma kernImage_union_preimage {s : Set α} {t : Set β} : kernImage f (s ∪ f ⁻¹' t) = kernImage f s ∪ t := by rw [kernImage_eq_compl, kernImage_eq_compl, compl_union, ← preimage_compl, image_inter_preimage, compl_inter, compl_compl] lemma kernImage_preimage_union {s : Set α} {t : Set β} : kernImage f (f ⁻¹' t ∪ s) = t ∪ kernImage f s := by rw [union_comm, kernImage_union_preimage, union_comm] end kernImage /-! ### Union and intersection over an indexed family of sets -/ instance : OrderTop (Set α) where top := univ le_top := by simp @[congr] theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ := iSup_congr_Prop pq f #align set.Union_congr_Prop Set.iUnion_congr_Prop @[congr] theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ := iInf_congr_Prop pq f #align set.Inter_congr_Prop Set.iInter_congr_Prop theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ #align set.Union_plift_up Set.iUnion_plift_up theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ #align set.Union_plift_down Set.iUnion_plift_down theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i := iInf_plift_up _ #align set.Inter_plift_up Set.iInter_plift_up theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i := iInf_plift_down _ #align set.Inter_plift_down Set.iInter_plift_down theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ := iSup_eq_if _ #align set.Union_eq_if Set.iUnion_eq_if theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋃ h : p, s h = if h : p then s h else ∅ := iSup_eq_dif _ #align set.Union_eq_dif Set.iUnion_eq_dif theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ := iInf_eq_if _ #align set.Inter_eq_if Set.iInter_eq_if theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋂ h : p, s h = if h : p then s h else univ := _root_.iInf_eq_dif _ #align set.Infi_eq_dif Set.iInf_eq_dif theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β) (w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by have p : x ∈ ⊤ := Set.mem_univ x rw [← w, Set.mem_iUnion] at p simpa using p #align set.exists_set_mem_of_union_eq_top Set.exists_set_mem_of_union_eq_top theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α) (H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some exact ⟨x, m⟩ #align set.nonempty_of_union_eq_top_of_nonempty Set.nonempty_of_union_eq_top_of_nonempty theorem nonempty_of_nonempty_iUnion {s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by obtain ⟨x, hx⟩ := h_Union exact ⟨Classical.choose <| mem_iUnion.mp hx⟩ theorem nonempty_of_nonempty_iUnion_eq_univ {s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι := nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty) theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } := ext fun _ => mem_iUnion.symm #align set.set_of_exists Set.setOf_exists theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } := ext fun _ => mem_iInter.symm #align set.set_of_forall Set.setOf_forall theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t := iSup_le h #align set.Union_subset Set.iUnion_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) : ⋃ (i) (j), s i j ⊆ t := iUnion_subset fun x => iUnion_subset (h x) #align set.Union₂_subset Set.iUnion₂_subset theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := le_iInf h #align set.subset_Inter Set.subset_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) : s ⊆ ⋂ (i) (j), t i j := subset_iInter fun x => subset_iInter <| h x #align set.subset_Inter₂ Set.subset_iInter₂ @[simp] theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t := ⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩ #align set.Union_subset_iff Set.iUnion_subset_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} : ⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff] #align set.Union₂_subset_iff Set.iUnion₂_subset_iff @[simp] theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i := le_iInf_iff #align set.subset_Inter_iff Set.subset_iInter_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note (#10618): removing `simp`. `simp` can prove it theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} : (s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff] #align set.subset_Inter₂_iff Set.subset_iInter₂_iff theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i := le_iSup #align set.subset_Union Set.subset_iUnion theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i := iInf_le #align set.Inter_subset Set.iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' := le_iSup₂ i j #align set.subset_Union₂ Set.subset_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j := iInf₂_le i j #align set.Inter₂_subset Set.iInter₂_subset /-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i := le_iSup_of_le i h #align set.subset_Union_of_subset Set.subset_iUnion_of_subset /-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) : ⋂ i, s i ⊆ t := iInf_le_of_le i h #align set.Inter_subset_of_subset Set.iInter_subset_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i) (h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j := le_iSup₂_of_le i j h #align set.subset_Union₂_of_subset Set.subset_iUnion₂_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i) (h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t := iInf₂_le_of_le i j h #align set.Inter₂_subset_of_subset Set.iInter₂_subset_of_subset theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono h #align set.Union_mono Set.iUnion_mono @[gcongr] theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t := iSup_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j := iSup₂_mono h #align set.Union₂_mono Set.iUnion₂_mono theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i := iInf_mono h #align set.Inter_mono Set.iInter_mono @[gcongr] theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t := iInf_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j := iInf₂_mono h #align set.Inter₂_mono Set.iInter₂_mono theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono' h #align set.Union_mono' Set.iUnion_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' := iSup₂_mono' h #align set.Union₂_mono' Set.iUnion₂_mono' theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) : ⋂ i, s i ⊆ ⋂ j, t j := Set.subset_iInter fun j => let ⟨i, hi⟩ := h j iInter_subset_of_subset i hi #align set.Inter_mono' Set.iInter_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' := subset_iInter₂_iff.2 fun i' j' => let ⟨_, _, hst⟩ := h i' j' (iInter₂_subset _ _).trans hst #align set.Inter₂_mono' Set.iInter₂_mono' theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) : ⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl #align set.Union₂_subset_Union Set.iUnion₂_subset_iUnion theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) : ⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl #align set.Inter_subset_Inter₂ Set.iInter_subset_iInter₂ theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by ext exact mem_iUnion #align set.Union_set_of Set.iUnion_setOf theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by ext exact mem_iInter #align set.Inter_set_of Set.iInter_setOf theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y := h1.iSup_congr h h2 #align set.Union_congr_of_surjective Set.iUnion_congr_of_surjective theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y := h1.iInf_congr h h2 #align set.Inter_congr_of_surjective Set.iInter_congr_of_surjective lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h #align set.Union_congr Set.iUnion_congr lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h #align set.Inter_congr Set.iInter_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋃ (i) (j), s i j = ⋃ (i) (j), t i j := iUnion_congr fun i => iUnion_congr <| h i #align set.Union₂_congr Set.iUnion₂_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋂ (i) (j), s i j = ⋂ (i) (j), t i j := iInter_congr fun i => iInter_congr <| h i #align set.Inter₂_congr Set.iInter₂_congr section Nonempty variable [Nonempty ι] {f : ι → Set α} {s : Set α} lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const #align set.Union_const Set.iUnion_const lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const #align set.Inter_const Set.iInter_const lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s := (iUnion_congr hf).trans <| iUnion_const _ #align set.Union_eq_const Set.iUnion_eq_const lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s := (iInter_congr hf).trans <| iInter_const _ #align set.Inter_eq_const Set.iInter_eq_const end Nonempty @[simp] theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ := compl_iSup #align set.compl_Union Set.compl_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by simp_rw [compl_iUnion] #align set.compl_Union₂ Set.compl_iUnion₂ @[simp] theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ := compl_iInf #align set.compl_Inter Set.compl_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by simp_rw [compl_iInter] #align set.compl_Inter₂ Set.compl_iInter₂ -- classical -- complete_boolean_algebra theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by simp only [compl_iInter, compl_compl] #align set.Union_eq_compl_Inter_compl Set.iUnion_eq_compl_iInter_compl -- classical -- complete_boolean_algebra theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by simp only [compl_iUnion, compl_compl] #align set.Inter_eq_compl_Union_compl Set.iInter_eq_compl_iUnion_compl theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i := inf_iSup_eq _ _ #align set.inter_Union Set.inter_iUnion theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := iSup_inf_eq _ _ #align set.Union_inter Set.iUnion_inter theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) : ⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i := iSup_sup_eq #align set.Union_union_distrib Set.iUnion_union_distrib theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) : ⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i := iInf_inf_eq #align set.Inter_inter_distrib Set.iInter_inter_distrib theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i := sup_iSup #align set.union_Union Set.union_iUnion theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s := iSup_sup #align set.Union_union Set.iUnion_union theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i := inf_iInf #align set.inter_Inter Set.inter_iInter theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s := iInf_inf #align set.Inter_inter Set.iInter_inter -- classical theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i := sup_iInf_eq _ _ #align set.union_Inter Set.union_iInter theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ #align set.Inter_union Set.iInter_union theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s := iUnion_inter _ _ #align set.Union_diff Set.iUnion_diff theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by rw [diff_eq, compl_iUnion, inter_iInter]; rfl #align set.diff_Union Set.diff_iUnion theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_iInter, inter_iUnion]; rfl #align set.diff_Inter Set.diff_iInter theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i := le_iSup_inf_iSup s t #align set.Union_inter_subset Set.iUnion_inter_subset theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_monotone hs ht #align set.Union_inter_of_monotone Set.iUnion_inter_of_monotone theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_antitone hs ht #align set.Union_inter_of_antitone Set.iUnion_inter_of_antitone theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_monotone hs ht #align set.Inter_union_of_monotone Set.iInter_union_of_monotone theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_antitone hs ht #align set.Inter_union_of_antitone Set.iInter_union_of_antitone /-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/ theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j := iSup_iInf_le_iInf_iSup (flip s) #align set.Union_Inter_subset Set.iUnion_iInter_subset theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) := iSup_option s #align set.Union_option Set.iUnion_option theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) := iInf_option s #align set.Inter_option Set.iInter_option section variable (p : ι → Prop) [DecidablePred p] theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h := iSup_dite _ _ _ #align set.Union_dite Set.iUnion_dite theorem iUnion_ite (f g : ι → Set α) : ⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i := iUnion_dite _ _ _ #align set.Union_ite Set.iUnion_ite theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h := iInf_dite _ _ _ #align set.Inter_dite Set.iInter_dite theorem iInter_ite (f g : ι → Set α) : ⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i := iInter_dite _ _ _ #align set.Inter_ite Set.iInter_ite end theorem image_projection_prod {ι : Type*} {α : ι → Type*} {v : ∀ i : ι, Set (α i)} (hv : (pi univ v).Nonempty) (i : ι) : ((fun x : ∀ i : ι, α i => x i) '' ⋂ k, (fun x : ∀ j : ι, α j => x k) ⁻¹' v k) = v i := by classical apply Subset.antisymm · simp [iInter_subset] · intro y y_in simp only [mem_image, mem_iInter, mem_preimage] rcases hv with ⟨z, hz⟩ refine ⟨Function.update z i y, ?_, update_same i y z⟩ rw [@forall_update_iff ι α _ z i y fun i t => t ∈ v i] exact ⟨y_in, fun j _ => by simpa using hz j⟩ #align set.image_projection_prod Set.image_projection_prod /-! ### Unions and intersections indexed by `Prop` -/ theorem iInter_false {s : False → Set α} : iInter s = univ := iInf_false #align set.Inter_false Set.iInter_false theorem iUnion_false {s : False → Set α} : iUnion s = ∅ := iSup_false #align set.Union_false Set.iUnion_false @[simp] theorem iInter_true {s : True → Set α} : iInter s = s trivial := iInf_true #align set.Inter_true Set.iInter_true @[simp] theorem iUnion_true {s : True → Set α} : iUnion s = s trivial := iSup_true #align set.Union_true Set.iUnion_true @[simp] theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} : ⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ := iInf_exists #align set.Inter_exists Set.iInter_exists @[simp] theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} : ⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ := iSup_exists #align set.Union_exists Set.iUnion_exists @[simp] theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ := iSup_bot #align set.Union_empty Set.iUnion_empty @[simp] theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ := iInf_top #align set.Inter_univ Set.iInter_univ section variable {s : ι → Set α} @[simp] theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ := iSup_eq_bot #align set.Union_eq_empty Set.iUnion_eq_empty @[simp] theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ := iInf_eq_top #align set.Inter_eq_univ Set.iInter_eq_univ @[simp] theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by simp [nonempty_iff_ne_empty] #align set.nonempty_Union Set.nonempty_iUnion -- Porting note (#10618): removing `simp`. `simp` can prove it theorem nonempty_biUnion {t : Set α} {s : α → Set β} : (⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp #align set.nonempty_bUnion Set.nonempty_biUnion theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) : ⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ := iSup_exists #align set.Union_nonempty_index Set.iUnion_nonempty_index end @[simp] theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋂ (x) (h : x = b), s x h = s b rfl := iInf_iInf_eq_left #align set.Inter_Inter_eq_left Set.iInter_iInter_eq_left @[simp] theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋂ (x) (h : b = x), s x h = s b rfl := iInf_iInf_eq_right #align set.Inter_Inter_eq_right Set.iInter_iInter_eq_right @[simp] theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋃ (x) (h : x = b), s x h = s b rfl := iSup_iSup_eq_left #align set.Union_Union_eq_left Set.iUnion_iUnion_eq_left @[simp] theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋃ (x) (h : b = x), s x h = s b rfl := iSup_iSup_eq_right #align set.Union_Union_eq_right Set.iUnion_iUnion_eq_right theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) : ⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) := iInf_or #align set.Inter_or Set.iInter_or theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) : ⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) := iSup_or #align set.Union_or Set.iUnion_or /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ := iSup_and #align set.Union_and Set.iUnion_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ := iInf_and #align set.Inter_and Set.iInter_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' := iSup_comm #align set.Union_comm Set.iUnion_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' := iInf_comm #align set.Inter_comm Set.iInter_comm theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_sigma theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 := iSup_sigma' _ theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ := iInf_sigma theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 := iInf_sigma' _ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iSup₂_comm _ #align set.Union₂_comm Set.iUnion₂_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iInf₂_comm _ #align set.Inter₂_comm Set.iInter₂_comm @[simp] theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iUnion_and, @iUnion_comm _ ι'] #align set.bUnion_and Set.biUnion_and @[simp] theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iUnion_and, @iUnion_comm _ ι] #align set.bUnion_and' Set.biUnion_and' @[simp] theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iInter_and, @iInter_comm _ ι'] #align set.bInter_and Set.biInter_and @[simp] theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iInter_and, @iInter_comm _ ι] #align set.bInter_and' Set.biInter_and' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[simp] theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left] #align set.Union_Union_eq_or_left Set.iUnion_iUnion_eq_or_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[simp] theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left] #align set.Inter_Inter_eq_or_left Set.iInter_iInter_eq_or_left /-! ### Bounded unions and intersections -/ /-- A specialization of `mem_iUnion₂`. -/ theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := mem_iUnion₂_of_mem xs ytx #align set.mem_bUnion Set.mem_biUnion /-- A specialization of `mem_iInter₂`. -/ theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) : y ∈ ⋂ x ∈ s, t x := mem_iInter₂_of_mem h #align set.mem_bInter Set.mem_biInter /-- A specialization of `subset_iUnion₂`. -/ theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) : u x ⊆ ⋃ x ∈ s, u x := -- Porting note: Why is this not just `subset_iUnion₂ x xs`? @subset_iUnion₂ β α (· ∈ s) (fun i _ => u i) x xs #align set.subset_bUnion_of_mem Set.subset_biUnion_of_mem /-- A specialization of `iInter₂_subset`. -/ theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) : ⋂ x ∈ s, t x ⊆ t x := iInter₂_subset x xs #align set.bInter_subset_of_mem Set.biInter_subset_of_mem theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') : ⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x := iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx #align set.bUnion_subset_bUnion_left Set.biUnion_subset_biUnion_left theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) : ⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x := subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx #align set.bInter_subset_bInter_left Set.biInter_subset_biInter_left theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) : ⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x := (biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h #align set.bUnion_mono Set.biUnion_mono theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) : ⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x := (biInter_subset_biInter_left hs).trans <| iInter₂_mono h #align set.bInter_mono Set.biInter_mono theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) : ⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 := iSup_subtype' #align set.bUnion_eq_Union Set.biUnion_eq_iUnion theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) : ⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 := iInf_subtype' #align set.bInter_eq_Inter Set.biInter_eq_iInter theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ := iSup_subtype #align set.Union_subtype Set.iUnion_subtype theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ := iInf_subtype #align set.Inter_subtype Set.iInter_subtype theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ := iInf_emptyset #align set.bInter_empty Set.biInter_empty theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x := iInf_univ #align set.bInter_univ Set.biInter_univ @[simp] theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s := Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx #align set.bUnion_self Set.biUnion_self @[simp] theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by rw [iUnion_nonempty_index, biUnion_self] #align set.Union_nonempty_self Set.iUnion_nonempty_self theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a := iInf_singleton #align set.bInter_singleton Set.biInter_singleton theorem biInter_union (s t : Set α) (u : α → Set β) : ⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x := iInf_union #align set.bInter_union Set.biInter_union theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) : ⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp #align set.bInter_insert Set.biInter_insert theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by rw [biInter_insert, biInter_singleton] #align set.bInter_pair Set.biInter_pair theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by haveI : Nonempty s := hs.to_subtype simp [biInter_eq_iInter, ← iInter_inter] #align set.bInter_inter Set.biInter_inter theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by rw [inter_comm, ← biInter_inter hs] simp [inter_comm] #align set.inter_bInter Set.inter_biInter theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ := iSup_emptyset #align set.bUnion_empty Set.biUnion_empty theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x := iSup_univ #align set.bUnion_univ Set.biUnion_univ theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a := iSup_singleton #align set.bUnion_singleton Set.biUnion_singleton @[simp] theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s := ext <| by simp #align set.bUnion_of_singleton Set.biUnion_of_singleton theorem biUnion_union (s t : Set α) (u : α → Set β) : ⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x := iSup_union #align set.bUnion_union Set.biUnion_union @[simp] theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iUnion_subtype _ _ #align set.Union_coe_set Set.iUnion_coe_set @[simp] theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iInter_subtype _ _ #align set.Inter_coe_set Set.iInter_coe_set theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) : ⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp #align set.bUnion_insert Set.biUnion_insert theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by simp #align set.bUnion_pair Set.biUnion_pair /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion] #align set.inter_Union₂ Set.inter_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter] #align set.Union₂_inter Set.iUnion₂_inter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter] #align set.union_Inter₂ Set.union_iInter₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union] #align set.Inter₂_union Set.iInter₂_union theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀S := ⟨t, ht, hx⟩ #align set.mem_sUnion_of_mem Set.mem_sUnion_of_mem -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀S) (ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩ #align set.not_mem_of_not_mem_sUnion Set.not_mem_of_not_mem_sUnion theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t := sInf_le tS #align set.sInter_subset_of_mem Set.sInter_subset_of_mem theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀S := le_sSup tS #align set.subset_sUnion_of_mem Set.subset_sUnion_of_mem theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u) (h₂ : u ∈ t) : s ⊆ ⋃₀t := Subset.trans h₁ (subset_sUnion_of_mem h₂) #align set.subset_sUnion_of_subset Set.subset_sUnion_of_subset theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀S ⊆ t := sSup_le h #align set.sUnion_subset Set.sUnion_subset @[simp] theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t := sSup_le_iff #align set.sUnion_subset_iff Set.sUnion_subset_iff /-- `sUnion` is monotone under taking a subset of each set. -/ lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) : ⋃₀ s ⊆ ⋃₀ (f '' s) := fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩ /-- `sUnion` is monotone under taking a superset of each set. -/ lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) : ⋃₀ (f '' s) ⊆ ⋃₀ s := -- If t ∈ f '' s is arbitrary; t = f u for some u : Set α. fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩ theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S := le_sInf h #align set.subset_sInter Set.subset_sInter @[simp] theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' := le_sInf_iff #align set.subset_sInter_iff Set.subset_sInter_iff @[gcongr] theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀S ⊆ ⋃₀T := sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs) #align set.sUnion_subset_sUnion Set.sUnion_subset_sUnion @[gcongr] theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S := subset_sInter fun _ hs => sInter_subset_of_mem (h hs) #align set.sInter_subset_sInter Set.sInter_subset_sInter @[simp] theorem sUnion_empty : ⋃₀∅ = (∅ : Set α) := sSup_empty #align set.sUnion_empty Set.sUnion_empty @[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) := sInf_empty #align set.sInter_empty Set.sInter_empty @[simp] theorem sUnion_singleton (s : Set α) : ⋃₀{s} = s := sSup_singleton #align set.sUnion_singleton Set.sUnion_singleton @[simp] theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s := sInf_singleton #align set.sInter_singleton Set.sInter_singleton @[simp] theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀S = ∅ ↔ ∀ s ∈ S, s = ∅ := sSup_eq_bot #align set.sUnion_eq_empty Set.sUnion_eq_empty @[simp] theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ := sInf_eq_top #align set.sInter_eq_univ Set.sInter_eq_univ theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t := sUnion_subset_iff.symm /-- `⋃₀` and `𝒫` form a Galois connection. -/ theorem sUnion_powerset_gc : GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gc_sSup_Iic /-- `⋃₀` and `𝒫` form a Galois insertion. -/ def sUnion_powerset_gi : GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gi_sSup_Iic /-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/ theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) : ⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall] rintro ⟨s, hs, hne⟩ obtain rfl : s = univ := (h hs).resolve_left hne exact univ_subset_iff.1 <| subset_sUnion_of_mem hs @[simp] theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by simp [nonempty_iff_ne_empty] #align set.nonempty_sUnion Set.nonempty_sUnion theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀s).Nonempty) : s.Nonempty := let ⟨s, hs, _⟩ := nonempty_sUnion.1 h ⟨s, hs⟩ #align set.nonempty.of_sUnion Set.Nonempty.of_sUnion theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀s = univ) : s.Nonempty := Nonempty.of_sUnion <| h.symm ▸ univ_nonempty #align set.nonempty.of_sUnion_eq_univ Set.Nonempty.of_sUnion_eq_univ theorem sUnion_union (S T : Set (Set α)) : ⋃₀(S ∪ T) = ⋃₀S ∪ ⋃₀T := sSup_union #align set.sUnion_union Set.sUnion_union theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := sInf_union #align set.sInter_union Set.sInter_union @[simp] theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀insert s T = s ∪ ⋃₀T := sSup_insert #align set.sUnion_insert Set.sUnion_insert @[simp] theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T := sInf_insert #align set.sInter_insert Set.sInter_insert @[simp] theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀(s \ {∅}) = ⋃₀s := sSup_diff_singleton_bot s #align set.sUnion_diff_singleton_empty Set.sUnion_diff_singleton_empty @[simp] theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s := sInf_diff_singleton_top s #align set.sInter_diff_singleton_univ Set.sInter_diff_singleton_univ theorem sUnion_pair (s t : Set α) : ⋃₀{s, t} = s ∪ t := sSup_pair #align set.sUnion_pair Set.sUnion_pair theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t := sInf_pair #align set.sInter_pair Set.sInter_pair @[simp] theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀(f '' s) = ⋃ x ∈ s, f x := sSup_image #align set.sUnion_image Set.sUnion_image @[simp] theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := sInf_image #align set.sInter_image Set.sInter_image @[simp] theorem sUnion_range (f : ι → Set β) : ⋃₀range f = ⋃ x, f x := rfl #align set.sUnion_range Set.sUnion_range @[simp] theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x := rfl #align set.sInter_range Set.sInter_range theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by simp only [eq_univ_iff_forall, mem_iUnion] #align set.Union_eq_univ_iff Set.iUnion_eq_univ_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} : ⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by simp only [iUnion_eq_univ_iff, mem_iUnion] #align set.Union₂_eq_univ_iff Set.iUnion₂_eq_univ_iff theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by simp only [eq_univ_iff_forall, mem_sUnion] #align set.sUnion_eq_univ_iff Set.sUnion_eq_univ_iff -- classical theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by simp [Set.eq_empty_iff_forall_not_mem] #align set.Inter_eq_empty_iff Set.iInter_eq_empty_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- classical theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} : ⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall] #align set.Inter₂_eq_empty_iff Set.iInter₂_eq_empty_iff -- classical theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by simp [Set.eq_empty_iff_forall_not_mem] #align set.sInter_eq_empty_iff Set.sInter_eq_empty_iff -- classical @[simp] theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by simp [nonempty_iff_ne_empty, iInter_eq_empty_iff] #align set.nonempty_Inter Set.nonempty_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- classical -- Porting note (#10618): removing `simp`. `simp` can prove it theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} : (⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by simp #align set.nonempty_Inter₂ Set.nonempty_iInter₂ -- classical @[simp] theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by simp [nonempty_iff_ne_empty, sInter_eq_empty_iff] #align set.nonempty_sInter Set.nonempty_sInter -- classical theorem compl_sUnion (S : Set (Set α)) : (⋃₀S)ᶜ = ⋂₀ (compl '' S) := ext fun x => by simp #align set.compl_sUnion Set.compl_sUnion -- classical theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀S = (⋂₀ (compl '' S))ᶜ := by rw [← compl_compl (⋃₀S), compl_sUnion] #align set.sUnion_eq_compl_sInter_compl Set.sUnion_eq_compl_sInter_compl -- classical theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀(compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] #align set.compl_sInter Set.compl_sInter -- classical theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀(compl '' S))ᶜ := by rw [← compl_compl (⋂₀ S), compl_sInter] #align set.sInter_eq_compl_sUnion_compl Set.sInter_eq_compl_sUnion_compl theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S) (h : s ∩ ⋃₀S = ∅) : s ∩ t = ∅ := eq_empty_of_subset_empty <| by rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs) #align set.inter_empty_of_inter_sUnion_empty Set.inter_empty_of_inter_sUnion_empty theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) : range f = ⋃ a, range fun b => f ⟨a, b⟩ := Set.ext <| by simp #align set.range_sigma_eq_Union_range Set.range_sigma_eq_iUnion_range theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by simp [Set.ext_iff] #align set.Union_eq_range_sigma Set.iUnion_eq_range_sigma theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by simp [Set.ext_iff] #align set.Union_eq_range_psigma Set.iUnion_eq_range_psigma theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) : ⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by ext x simp only [mem_iUnion, mem_image, mem_preimage] constructor · rintro ⟨i, a, h, rfl⟩ exact h · intro h cases' x with i a exact ⟨i, a, h, rfl⟩ #align set.Union_image_preimage_sigma_mk_eq_self Set.iUnion_image_preimage_sigma_mk_eq_self theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) := Set.ext fun x => iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩ #align set.sigma.univ Set.Sigma.univ alias sUnion_mono := sUnion_subset_sUnion #align set.sUnion_mono Set.sUnion_mono theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s := iSup_const_mono (α := Set α) h #align set.Union_subset_Union_const Set.iUnion_subset_iUnion_const @[simp] theorem iUnion_singleton_eq_range {α β : Type*} (f : α → β) : ⋃ x : α, {f x} = range f := by ext x simp [@eq_comm _ x] #align set.Union_singleton_eq_range Set.iUnion_singleton_eq_range theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff] #align set.Union_of_singleton Set.iUnion_of_singleton theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp #align set.Union_of_singleton_coe Set.iUnion_of_singleton_coe theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀s = ⋃ (i : Set α) (_ : i ∈ s), i := by rw [← sUnion_image, image_id'] #align set.sUnion_eq_bUnion Set.sUnion_eq_biUnion theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by rw [← sInter_image, image_id'] #align set.sInter_eq_bInter Set.sInter_eq_biInter theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀s = ⋃ i : s, i := by simp only [← sUnion_range, Subtype.range_coe] #align set.sUnion_eq_Union Set.sUnion_eq_iUnion theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by simp only [← sInter_range, Subtype.range_coe] #align set.sInter_eq_Inter Set.sInter_eq_iInter @[simp] theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ := iSup_of_empty _ #align set.Union_of_empty Set.iUnion_of_empty @[simp] theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ := iInf_of_empty _ #align set.Inter_of_empty Set.iInter_of_empty theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ := sup_eq_iSup s₁ s₂ #align set.union_eq_Union Set.union_eq_iUnion theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ := inf_eq_iInf s₁ s₂ #align set.inter_eq_Inter Set.inter_eq_iInter theorem sInter_union_sInter {S T : Set (Set α)} : ⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 := sInf_sup_sInf #align set.sInter_union_sInter Set.sInter_union_sInter theorem sUnion_inter_sUnion {s t : Set (Set α)} : ⋃₀s ∩ ⋃₀t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 := sSup_inf_sSup #align set.sUnion_inter_sUnion Set.sUnion_inter_sUnion theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) : ⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι] #align set.bUnion_Union Set.biUnion_iUnion theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) : ⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι] #align set.bInter_Union Set.biInter_iUnion theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀⋃ i, s i = ⋃ i, ⋃₀s i := by simp only [sUnion_eq_biUnion, biUnion_iUnion] #align set.sUnion_Union Set.sUnion_iUnion theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by simp only [sInter_eq_biInter, biInter_iUnion] #align set.sInter_Union Set.sInter_iUnion theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)} (hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀C := by ext x; constructor · rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩ refine ⟨_, hs, ?_⟩ exact (f ⟨s, hs⟩ y).2 · rintro ⟨s, hs, hx⟩ cases' hf ⟨s, hs⟩ ⟨x, hx⟩ with y hy refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩ exact congr_arg Subtype.val hy #align set.Union_range_eq_sUnion Set.iUnion_range_eq_sUnion theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x} (hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by ext x; rw [mem_iUnion, mem_iUnion]; constructor · rintro ⟨y, i, rfl⟩ exact ⟨i, (f i y).2⟩ · rintro ⟨i, hx⟩ cases' hf i ⟨x, hx⟩ with y hy exact ⟨y, i, congr_arg Subtype.val hy⟩ #align set.Union_range_eq_Union Set.iUnion_range_eq_iUnion theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i := sup_iInf_eq _ _ #align set.union_distrib_Inter_left Set.union_distrib_iInter_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) : (s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left] #align set.union_distrib_Inter₂_left Set.union_distrib_iInter₂_left theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ #align set.union_distrib_Inter_right Set.union_distrib_iInter_right /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right] #align set.union_distrib_Inter₂_right Set.union_distrib_iInter₂_right section Function /-! ### Lemmas about `Set.MapsTo` Porting note: some lemmas in this section were upgraded from implications to `iff`s. -/ @[simp] theorem mapsTo_sUnion {S : Set (Set α)} {t : Set β} {f : α → β} : MapsTo f (⋃₀ S) t ↔ ∀ s ∈ S, MapsTo f s t := sUnion_subset_iff #align set.maps_to_sUnion Set.mapsTo_sUnion @[simp] theorem mapsTo_iUnion {s : ι → Set α} {t : Set β} {f : α → β} : MapsTo f (⋃ i, s i) t ↔ ∀ i, MapsTo f (s i) t := iUnion_subset_iff #align set.maps_to_Union Set.mapsTo_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iUnion₂ {s : ∀ i, κ i → Set α} {t : Set β} {f : α → β} : MapsTo f (⋃ (i) (j), s i j) t ↔ ∀ i j, MapsTo f (s i j) t := iUnion₂_subset_iff #align set.maps_to_Union₂ Set.mapsTo_iUnion₂ theorem mapsTo_iUnion_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋃ i, s i) (⋃ i, t i) := mapsTo_iUnion.2 fun i ↦ (H i).mono_right (subset_iUnion t i) #align set.maps_to_Union_Union Set.mapsTo_iUnion_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iUnion₂_iUnion₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋃ (i) (j), s i j) (⋃ (i) (j), t i j) := mapsTo_iUnion_iUnion fun i => mapsTo_iUnion_iUnion (H i) #align set.maps_to_Union₂_Union₂ Set.mapsTo_iUnion₂_iUnion₂ @[simp] theorem mapsTo_sInter {s : Set α} {T : Set (Set β)} {f : α → β} : MapsTo f s (⋂₀ T) ↔ ∀ t ∈ T, MapsTo f s t := forall₂_swap #align set.maps_to_sInter Set.mapsTo_sInter @[simp] theorem mapsTo_iInter {s : Set α} {t : ι → Set β} {f : α → β} : MapsTo f s (⋂ i, t i) ↔ ∀ i, MapsTo f s (t i) := mapsTo_sInter.trans forall_mem_range #align set.maps_to_Inter Set.mapsTo_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iInter₂ {s : Set α} {t : ∀ i, κ i → Set β} {f : α → β} : MapsTo f s (⋂ (i) (j), t i j) ↔ ∀ i j, MapsTo f s (t i j) := by simp only [mapsTo_iInter] #align set.maps_to_Inter₂ Set.mapsTo_iInter₂ theorem mapsTo_iInter_iInter {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋂ i, s i) (⋂ i, t i) := mapsTo_iInter.2 fun i => (H i).mono_left (iInter_subset s i) #align set.maps_to_Inter_Inter Set.mapsTo_iInter_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iInter₂_iInter₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋂ (i) (j), s i j) (⋂ (i) (j), t i j) := mapsTo_iInter_iInter fun i => mapsTo_iInter_iInter (H i) #align set.maps_to_Inter₂_Inter₂ Set.mapsTo_iInter₂_iInter₂ theorem image_iInter_subset (s : ι → Set α) (f : α → β) : (f '' ⋂ i, s i) ⊆ ⋂ i, f '' s i := (mapsTo_iInter_iInter fun i => mapsTo_image f (s i)).image_subset #align set.image_Inter_subset Set.image_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image_iInter₂_subset (s : ∀ i, κ i → Set α) (f : α → β) : (f '' ⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), f '' s i j := (mapsTo_iInter₂_iInter₂ fun i hi => mapsTo_image f (s i hi)).image_subset #align set.image_Inter₂_subset Set.image_iInter₂_subset theorem image_sInter_subset (S : Set (Set α)) (f : α → β) : f '' ⋂₀ S ⊆ ⋂ s ∈ S, f '' s := by rw [sInter_eq_biInter] apply image_iInter₂_subset #align set.image_sInter_subset Set.image_sInter_subset /-! ### `restrictPreimage` -/ section open Function variable (s : Set β) {f : α → β} {U : ι → Set β} (hU : iUnion U = univ) theorem injective_iff_injective_of_iUnion_eq_univ : Injective f ↔ ∀ i, Injective ((U i).restrictPreimage f) := by refine ⟨fun H i => (U i).restrictPreimage_injective H, fun H x y e => ?_⟩ obtain ⟨i, hi⟩ := Set.mem_iUnion.mp (show f x ∈ Set.iUnion U by rw [hU]; trivial) injection @H i ⟨x, hi⟩ ⟨y, show f y ∈ U i from e ▸ hi⟩ (Subtype.ext e) #align set.injective_iff_injective_of_Union_eq_univ Set.injective_iff_injective_of_iUnion_eq_univ theorem surjective_iff_surjective_of_iUnion_eq_univ : Surjective f ↔ ∀ i, Surjective ((U i).restrictPreimage f) := by refine ⟨fun H i => (U i).restrictPreimage_surjective H, fun H x => ?_⟩ obtain ⟨i, hi⟩ := Set.mem_iUnion.mp (show x ∈ Set.iUnion U by rw [hU]; trivial) exact ⟨_, congr_arg Subtype.val (H i ⟨x, hi⟩).choose_spec⟩ #align set.surjective_iff_surjective_of_Union_eq_univ Set.surjective_iff_surjective_of_iUnion_eq_univ theorem bijective_iff_bijective_of_iUnion_eq_univ : Bijective f ↔ ∀ i, Bijective ((U i).restrictPreimage f) := by rw [Bijective, injective_iff_injective_of_iUnion_eq_univ hU, surjective_iff_surjective_of_iUnion_eq_univ hU] simp [Bijective, forall_and] #align set.bijective_iff_bijective_of_Union_eq_univ Set.bijective_iff_bijective_of_iUnion_eq_univ end /-! ### `InjOn` -/ theorem InjOn.image_iInter_eq [Nonempty ι] {s : ι → Set α} {f : α → β} (h : InjOn f (⋃ i, s i)) : (f '' ⋂ i, s i) = ⋂ i, f '' s i := by inhabit ι refine Subset.antisymm (image_iInter_subset s f) fun y hy => ?_ simp only [mem_iInter, mem_image] at hy choose x hx hy using hy refine ⟨x default, mem_iInter.2 fun i => ?_, hy _⟩ suffices x default = x i by rw [this] apply hx replace hx : ∀ i, x i ∈ ⋃ j, s j := fun i => (subset_iUnion _ _) (hx i) apply h (hx _) (hx _) simp only [hy] #align set.inj_on.image_Inter_eq Set.InjOn.image_iInter_eq /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/ theorem InjOn.image_biInter_eq {p : ι → Prop} {s : ∀ i, p i → Set α} (hp : ∃ i, p i) {f : α → β} (h : InjOn f (⋃ (i) (hi), s i hi)) : (f '' ⋂ (i) (hi), s i hi) = ⋂ (i) (hi), f '' s i hi := by simp only [iInter, iInf_subtype'] haveI : Nonempty { i // p i } := nonempty_subtype.2 hp apply InjOn.image_iInter_eq simpa only [iUnion, iSup_subtype'] using h #align set.inj_on.image_bInter_eq Set.InjOn.image_biInter_eq theorem image_iInter {f : α → β} (hf : Bijective f) (s : ι → Set α) : (f '' ⋂ i, s i) = ⋂ i, f '' s i := by cases isEmpty_or_nonempty ι · simp_rw [iInter_of_empty, image_univ_of_surjective hf.surjective] · exact hf.injective.injOn.image_iInter_eq #align set.image_Inter Set.image_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image_iInter₂ {f : α → β} (hf : Bijective f) (s : ∀ i, κ i → Set α) : (f '' ⋂ (i) (j), s i j) = ⋂ (i) (j), f '' s i j := by simp_rw [image_iInter hf] #align set.image_Inter₂ Set.image_iInter₂ theorem inj_on_iUnion_of_directed {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {f : α → β} (hf : ∀ i, InjOn f (s i)) : InjOn f (⋃ i, s i) := by intro x hx y hy hxy rcases mem_iUnion.1 hx with ⟨i, hx⟩ rcases mem_iUnion.1 hy with ⟨j, hy⟩ rcases hs i j with ⟨k, hi, hj⟩ exact hf k (hi hx) (hj hy) hxy #align set.inj_on_Union_of_directed Set.inj_on_iUnion_of_directed /-! ### `SurjOn` -/ theorem surjOn_sUnion {s : Set α} {T : Set (Set β)} {f : α → β} (H : ∀ t ∈ T, SurjOn f s t) : SurjOn f s (⋃₀T) := fun _ ⟨t, ht, hx⟩ => H t ht hx #align set.surj_on_sUnion Set.surjOn_sUnion theorem surjOn_iUnion {s : Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, SurjOn f s (t i)) : SurjOn f s (⋃ i, t i) := surjOn_sUnion <| forall_mem_range.2 H #align set.surj_on_Union Set.surjOn_iUnion theorem surjOn_iUnion_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, SurjOn f (s i) (t i)) : SurjOn f (⋃ i, s i) (⋃ i, t i) := surjOn_iUnion fun i => (H i).mono (subset_iUnion _ _) (Subset.refl _) #align set.surj_on_Union_Union Set.surjOn_iUnion_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem surjOn_iUnion₂ {s : Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, SurjOn f s (t i j)) : SurjOn f s (⋃ (i) (j), t i j) := surjOn_iUnion fun i => surjOn_iUnion (H i) #align set.surj_on_Union₂ Set.surjOn_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem surjOn_iUnion₂_iUnion₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, SurjOn f (s i j) (t i j)) : SurjOn f (⋃ (i) (j), s i j) (⋃ (i) (j), t i j) := surjOn_iUnion_iUnion fun i => surjOn_iUnion_iUnion (H i) #align set.surj_on_Union₂_Union₂ Set.surjOn_iUnion₂_iUnion₂ theorem surjOn_iInter [Nonempty ι] {s : ι → Set α} {t : Set β} {f : α → β} (H : ∀ i, SurjOn f (s i) t) (Hinj : InjOn f (⋃ i, s i)) : SurjOn f (⋂ i, s i) t := by intro y hy rw [Hinj.image_iInter_eq, mem_iInter] exact fun i => H i hy #align set.surj_on_Inter Set.surjOn_iInter theorem surjOn_iInter_iInter [Nonempty ι] {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, SurjOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : SurjOn f (⋂ i, s i) (⋂ i, t i) := surjOn_iInter (fun i => (H i).mono (Subset.refl _) (iInter_subset _ _)) Hinj #align set.surj_on_Inter_Inter Set.surjOn_iInter_iInter /-! ### `BijOn` -/ theorem bijOn_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : BijOn f (⋃ i, s i) (⋃ i, t i) := ⟨mapsTo_iUnion_iUnion fun i => (H i).mapsTo, Hinj, surjOn_iUnion_iUnion fun i => (H i).surjOn⟩ #align set.bij_on_Union Set.bijOn_iUnion theorem bijOn_iInter [hi : Nonempty ι] {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : BijOn f (⋂ i, s i) (⋂ i, t i) := ⟨mapsTo_iInter_iInter fun i => (H i).mapsTo, hi.elim fun i => (H i).injOn.mono (iInter_subset _ _), surjOn_iInter_iInter (fun i => (H i).surjOn) Hinj⟩ #align set.bij_on_Inter Set.bijOn_iInter theorem bijOn_iUnion_of_directed {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) : BijOn f (⋃ i, s i) (⋃ i, t i) := bijOn_iUnion H <| inj_on_iUnion_of_directed hs fun i => (H i).injOn #align set.bij_on_Union_of_directed Set.bijOn_iUnion_of_directed theorem bijOn_iInter_of_directed [Nonempty ι] {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) : BijOn f (⋂ i, s i) (⋂ i, t i) := bijOn_iInter H <| inj_on_iUnion_of_directed hs fun i => (H i).injOn #align set.bij_on_Inter_of_directed Set.bijOn_iInter_of_directed end Function /-! ### `image`, `preimage` -/ section Image theorem image_iUnion {f : α → β} {s : ι → Set α} : (f '' ⋃ i, s i) = ⋃ i, f '' s i := by ext1 x simp only [mem_image, mem_iUnion, ← exists_and_right, ← exists_and_left] -- Porting note: `exists_swap` causes a `simp` loop in Lean4 so we use `rw` instead. rw [exists_swap] #align set.image_Union Set.image_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image_iUnion₂ (f : α → β) (s : ∀ i, κ i → Set α) : (f '' ⋃ (i) (j), s i j) = ⋃ (i) (j), f '' s i j := by simp_rw [image_iUnion] #align set.image_Union₂ Set.image_iUnion₂ theorem univ_subtype {p : α → Prop} : (univ : Set (Subtype p)) = ⋃ (x) (h : p x), {⟨x, h⟩} := Set.ext fun ⟨x, h⟩ => by simp [h] #align set.univ_subtype Set.univ_subtype theorem range_eq_iUnion {ι} (f : ι → α) : range f = ⋃ i, {f i} := Set.ext fun a => by simp [@eq_comm α a] #align set.range_eq_Union Set.range_eq_iUnion theorem image_eq_iUnion (f : α → β) (s : Set α) : f '' s = ⋃ i ∈ s, {f i} := Set.ext fun b => by simp [@eq_comm β b] #align set.image_eq_Union Set.image_eq_iUnion theorem biUnion_range {f : ι → α} {g : α → Set β} : ⋃ x ∈ range f, g x = ⋃ y, g (f y) := iSup_range #align set.bUnion_range Set.biUnion_range /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x y) -/ @[simp] theorem iUnion_iUnion_eq' {f : ι → α} {g : α → Set β} : ⋃ (x) (y) (_ : f y = x), g x = ⋃ y, g (f y) := by simpa using biUnion_range #align set.Union_Union_eq' Set.iUnion_iUnion_eq' theorem biInter_range {f : ι → α} {g : α → Set β} : ⋂ x ∈ range f, g x = ⋂ y, g (f y) := iInf_range #align set.bInter_range Set.biInter_range /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x y) -/ @[simp] theorem iInter_iInter_eq' {f : ι → α} {g : α → Set β} : ⋂ (x) (y) (_ : f y = x), g x = ⋂ y, g (f y) := by simpa using biInter_range #align set.Inter_Inter_eq' Set.iInter_iInter_eq' variable {s : Set γ} {f : γ → α} {g : α → Set β} theorem biUnion_image : ⋃ x ∈ f '' s, g x = ⋃ y ∈ s, g (f y) := iSup_image #align set.bUnion_image Set.biUnion_image theorem biInter_image : ⋂ x ∈ f '' s, g x = ⋂ y ∈ s, g (f y) := iInf_image #align set.bInter_image Set.biInter_image end Image section Preimage theorem monotone_preimage {f : α → β} : Monotone (preimage f) := fun _ _ h => preimage_mono h #align set.monotone_preimage Set.monotone_preimage @[simp] theorem preimage_iUnion {f : α → β} {s : ι → Set β} : (f ⁻¹' ⋃ i, s i) = ⋃ i, f ⁻¹' s i := Set.ext <| by simp [preimage] #align set.preimage_Union Set.preimage_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem preimage_iUnion₂ {f : α → β} {s : ∀ i, κ i → Set β} : (f ⁻¹' ⋃ (i) (j), s i j) = ⋃ (i) (j), f ⁻¹' s i j := by simp_rw [preimage_iUnion] #align set.preimage_Union₂ Set.preimage_iUnion₂ theorem image_sUnion {f : α → β} {s : Set (Set α)} : (f '' ⋃₀ s) = ⋃₀ (image f '' s) := by ext b simp only [mem_image, mem_sUnion, exists_prop, sUnion_image, mem_iUnion] constructor · rintro ⟨a, ⟨t, ht₁, ht₂⟩, rfl⟩ exact ⟨t, ht₁, a, ht₂, rfl⟩ · rintro ⟨t, ht₁, a, ht₂, rfl⟩ exact ⟨a, ⟨t, ht₁, ht₂⟩, rfl⟩ @[simp] theorem preimage_sUnion {f : α → β} {s : Set (Set β)} : f ⁻¹' ⋃₀s = ⋃ t ∈ s, f ⁻¹' t := by rw [sUnion_eq_biUnion, preimage_iUnion₂] #align set.preimage_sUnion Set.preimage_sUnion theorem preimage_iInter {f : α → β} {s : ι → Set β} : (f ⁻¹' ⋂ i, s i) = ⋂ i, f ⁻¹' s i := by ext; simp #align set.preimage_Inter Set.preimage_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem preimage_iInter₂ {f : α → β} {s : ∀ i, κ i → Set β} : (f ⁻¹' ⋂ (i) (j), s i j) = ⋂ (i) (j), f ⁻¹' s i j := by simp_rw [preimage_iInter] #align set.preimage_Inter₂ Set.preimage_iInter₂ @[simp] theorem preimage_sInter {f : α → β} {s : Set (Set β)} : f ⁻¹' ⋂₀ s = ⋂ t ∈ s, f ⁻¹' t := by rw [sInter_eq_biInter, preimage_iInter₂] #align set.preimage_sInter Set.preimage_sInter @[simp] theorem biUnion_preimage_singleton (f : α → β) (s : Set β) : ⋃ y ∈ s, f ⁻¹' {y} = f ⁻¹' s := by rw [← preimage_iUnion₂, biUnion_of_singleton] #align set.bUnion_preimage_singleton Set.biUnion_preimage_singleton theorem biUnion_range_preimage_singleton (f : α → β) : ⋃ y ∈ range f, f ⁻¹' {y} = univ := by rw [biUnion_preimage_singleton, preimage_range] #align set.bUnion_range_preimage_singleton Set.biUnion_range_preimage_singleton end Preimage section Prod theorem prod_iUnion {s : Set α} {t : ι → Set β} : (s ×ˢ ⋃ i, t i) = ⋃ i, s ×ˢ t i := by ext simp #align set.prod_Union Set.prod_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem prod_iUnion₂ {s : Set α} {t : ∀ i, κ i → Set β} : (s ×ˢ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ×ˢ t i j := by simp_rw [prod_iUnion] #align set.prod_Union₂ Set.prod_iUnion₂ theorem prod_sUnion {s : Set α} {C : Set (Set β)} : s ×ˢ ⋃₀C = ⋃₀((fun t => s ×ˢ t) '' C) := by simp_rw [sUnion_eq_biUnion, biUnion_image, prod_iUnion₂] #align set.prod_sUnion Set.prod_sUnion theorem iUnion_prod_const {s : ι → Set α} {t : Set β} : (⋃ i, s i) ×ˢ t = ⋃ i, s i ×ˢ t := by ext simp #align set.Union_prod_const Set.iUnion_prod_const /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_prod_const {s : ∀ i, κ i → Set α} {t : Set β} : (⋃ (i) (j), s i j) ×ˢ t = ⋃ (i) (j), s i j ×ˢ t := by simp_rw [iUnion_prod_const] #align set.Union₂_prod_const Set.iUnion₂_prod_const theorem sUnion_prod_const {C : Set (Set α)} {t : Set β} : ⋃₀C ×ˢ t = ⋃₀((fun s : Set α => s ×ˢ t) '' C) := by simp only [sUnion_eq_biUnion, iUnion₂_prod_const, biUnion_image] #align set.sUnion_prod_const Set.sUnion_prod_const theorem iUnion_prod {ι ι' α β} (s : ι → Set α) (t : ι' → Set β) : ⋃ x : ι × ι', s x.1 ×ˢ t x.2 = (⋃ i : ι, s i) ×ˢ ⋃ i : ι', t i := by ext simp #align set.Union_prod Set.iUnion_prod /-- Analogue of `iSup_prod` for sets. -/ lemma iUnion_prod' (f : β × γ → Set α) : ⋃ x : β × γ, f x = ⋃ (i : β) (j : γ), f (i, j) := iSup_prod theorem iUnion_prod_of_monotone [SemilatticeSup α] {s : α → Set β} {t : α → Set γ} (hs : Monotone s) (ht : Monotone t) : ⋃ x, s x ×ˢ t x = (⋃ x, s x) ×ˢ ⋃ x, t x := by ext ⟨z, w⟩; simp only [mem_prod, mem_iUnion, exists_imp, and_imp, iff_def]; constructor · intro x hz hw exact ⟨⟨x, hz⟩, x, hw⟩ · intro x hz x' hw exact ⟨x ⊔ x', hs le_sup_left hz, ht le_sup_right hw⟩ #align set.Union_prod_of_monotone Set.iUnion_prod_of_monotone theorem sInter_prod_sInter_subset (S : Set (Set α)) (T : Set (Set β)) : ⋂₀ S ×ˢ ⋂₀ T ⊆ ⋂ r ∈ S ×ˢ T, r.1 ×ˢ r.2 := subset_iInter₂ fun x hx _ hy => ⟨hy.1 x.1 hx.1, hy.2 x.2 hx.2⟩ #align set.sInter_prod_sInter_subset Set.sInter_prod_sInter_subset theorem sInter_prod_sInter {S : Set (Set α)} {T : Set (Set β)} (hS : S.Nonempty) (hT : T.Nonempty) : ⋂₀ S ×ˢ ⋂₀ T = ⋂ r ∈ S ×ˢ T, r.1 ×ˢ r.2 := by obtain ⟨s₁, h₁⟩ := hS obtain ⟨s₂, h₂⟩ := hT refine Set.Subset.antisymm (sInter_prod_sInter_subset S T) fun x hx => ?_ rw [mem_iInter₂] at hx exact ⟨fun s₀ h₀ => (hx (s₀, s₂) ⟨h₀, h₂⟩).1, fun s₀ h₀ => (hx (s₁, s₀) ⟨h₁, h₀⟩).2⟩ #align set.sInter_prod_sInter Set.sInter_prod_sInter theorem sInter_prod {S : Set (Set α)} (hS : S.Nonempty) (t : Set β) : ⋂₀ S ×ˢ t = ⋂ s ∈ S, s ×ˢ t := by rw [← sInter_singleton t, sInter_prod_sInter hS (singleton_nonempty t), sInter_singleton] simp_rw [prod_singleton, mem_image, iInter_exists, biInter_and', iInter_iInter_eq_right] #align set.sInter_prod Set.sInter_prod theorem prod_sInter {T : Set (Set β)} (hT : T.Nonempty) (s : Set α) : s ×ˢ ⋂₀ T = ⋂ t ∈ T, s ×ˢ t := by rw [← sInter_singleton s, sInter_prod_sInter (singleton_nonempty s) hT, sInter_singleton] simp_rw [singleton_prod, mem_image, iInter_exists, biInter_and', iInter_iInter_eq_right] #align set.prod_sInter Set.prod_sInter theorem prod_iInter {s : Set α} {t : ι → Set β} [hι : Nonempty ι] : (s ×ˢ ⋂ i, t i) = ⋂ i, s ×ˢ t i := by ext x simp only [mem_prod, mem_iInter] exact ⟨fun h i => ⟨h.1, h.2 i⟩, fun h => ⟨(h hι.some).1, fun i => (h i).2⟩⟩ #align prod_Inter Set.prod_iInter end Prod section Image2 variable (f : α → β → γ) {s : Set α} {t : Set β} /-- The `Set.image2` version of `Set.image_eq_iUnion` -/ theorem image2_eq_iUnion (s : Set α) (t : Set β) : image2 f s t = ⋃ (i ∈ s) (j ∈ t), {f i j} := by ext; simp [eq_comm] #align set.image2_eq_Union Set.image2_eq_iUnion theorem iUnion_image_left : ⋃ a ∈ s, f a '' t = image2 f s t := by simp only [image2_eq_iUnion, image_eq_iUnion] #align set.Union_image_left Set.iUnion_image_left theorem iUnion_image_right : ⋃ b ∈ t, (f · b) '' s = image2 f s t := by rw [image2_swap, iUnion_image_left] #align set.Union_image_right Set.iUnion_image_right theorem image2_iUnion_left (s : ι → Set α) (t : Set β) : image2 f (⋃ i, s i) t = ⋃ i, image2 f (s i) t := by simp only [← image_prod, iUnion_prod_const, image_iUnion] #align set.image2_Union_left Set.image2_iUnion_left theorem image2_iUnion_right (s : Set α) (t : ι → Set β) : image2 f s (⋃ i, t i) = ⋃ i, image2 f s (t i) := by simp only [← image_prod, prod_iUnion, image_iUnion] #align set.image2_Union_right Set.image2_iUnion_right /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image2_iUnion₂_left (s : ∀ i, κ i → Set α) (t : Set β) : image2 f (⋃ (i) (j), s i j) t = ⋃ (i) (j), image2 f (s i j) t := by simp_rw [image2_iUnion_left] #align set.image2_Union₂_left Set.image2_iUnion₂_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image2_iUnion₂_right (s : Set α) (t : ∀ i, κ i → Set β) : image2 f s (⋃ (i) (j), t i j) = ⋃ (i) (j), image2 f s (t i j) := by simp_rw [image2_iUnion_right] #align set.image2_Union₂_right Set.image2_iUnion₂_right theorem image2_iInter_subset_left (s : ι → Set α) (t : Set β) : image2 f (⋂ i, s i) t ⊆ ⋂ i, image2 f (s i) t := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i => mem_image2_of_mem (hx _) hy #align set.image2_Inter_subset_left Set.image2_iInter_subset_left theorem image2_iInter_subset_right (s : Set α) (t : ι → Set β) : image2 f s (⋂ i, t i) ⊆ ⋂ i, image2 f s (t i) := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i => mem_image2_of_mem hx (hy _) #align set.image2_Inter_subset_right Set.image2_iInter_subset_right /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image2_iInter₂_subset_left (s : ∀ i, κ i → Set α) (t : Set β) : image2 f (⋂ (i) (j), s i j) t ⊆ ⋂ (i) (j), image2 f (s i j) t := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i j => mem_image2_of_mem (hx _ _) hy #align set.image2_Inter₂_subset_left Set.image2_iInter₂_subset_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image2_iInter₂_subset_right (s : Set α) (t : ∀ i, κ i → Set β) : image2 f s (⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), image2 f s (t i j) := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i j => mem_image2_of_mem hx (hy _ _) #align set.image2_Inter₂_subset_right Set.image2_iInter₂_subset_right theorem prod_eq_biUnion_left : s ×ˢ t = ⋃ a ∈ s, (fun b => (a, b)) '' t := by rw [iUnion_image_left, image2_mk_eq_prod] #align set.prod_eq_bUnion_left Set.prod_eq_biUnion_left theorem prod_eq_biUnion_right : s ×ˢ t = ⋃ b ∈ t, (fun a => (a, b)) '' s := by rw [iUnion_image_right, image2_mk_eq_prod] #align set.prod_eq_bUnion_right Set.prod_eq_biUnion_right end Image2 section Seq theorem seq_def {s : Set (α → β)} {t : Set α} : seq s t = ⋃ f ∈ s, f '' t := by rw [seq_eq_image2, iUnion_image_left] #align set.seq_def Set.seq_def theorem seq_subset {s : Set (α → β)} {t : Set α} {u : Set β} : seq s t ⊆ u ↔ ∀ f ∈ s, ∀ a ∈ t, (f : α → β) a ∈ u := image2_subset_iff #align set.seq_subset Set.seq_subset @[gcongr] theorem seq_mono {s₀ s₁ : Set (α → β)} {t₀ t₁ : Set α} (hs : s₀ ⊆ s₁) (ht : t₀ ⊆ t₁) : seq s₀ t₀ ⊆ seq s₁ t₁ := image2_subset hs ht #align set.seq_mono Set.seq_mono theorem singleton_seq {f : α → β} {t : Set α} : Set.seq ({f} : Set (α → β)) t = f '' t := image2_singleton_left #align set.singleton_seq Set.singleton_seq theorem seq_singleton {s : Set (α → β)} {a : α} : Set.seq s {a} = (fun f : α → β => f a) '' s := image2_singleton_right #align set.seq_singleton Set.seq_singleton theorem seq_seq {s : Set (β → γ)} {t : Set (α → β)} {u : Set α} : seq s (seq t u) = seq (seq ((· ∘ ·) '' s) t) u := by simp only [seq_eq_image2, image2_image_left] exact .symm <| image2_assoc fun _ _ _ ↦ rfl #align set.seq_seq Set.seq_seq theorem image_seq {f : β → γ} {s : Set (α → β)} {t : Set α} : f '' seq s t = seq ((f ∘ ·) '' s) t := by simp only [seq, image_image2, image2_image_left, comp_apply] #align set.image_seq Set.image_seq
Mathlib/Data/Set/Lattice.lean
1,963
1,964
theorem prod_eq_seq {s : Set α} {t : Set β} : s ×ˢ t = (Prod.mk '' s).seq t := by
rw [seq_eq_image2, image2_image_left, image2_mk_eq_prod]
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Analytic.Composition import Mathlib.Analysis.Analytic.Linear import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Geometry.Manifold.ChartedSpace import Mathlib.Analysis.NormedSpace.FiniteDimension import Mathlib.Analysis.Calculus.ContDiff.Basic #align_import geometry.manifold.smooth_manifold_with_corners from "leanprover-community/mathlib"@"ddec54a71a0dd025c05445d467f1a2b7d586a3ba" /-! # Smooth manifolds (possibly with boundary or corners) A smooth manifold is a manifold modelled on a normed vector space, or a subset like a half-space (to get manifolds with boundaries) for which the changes of coordinates are smooth maps. We define a model with corners as a map `I : H → E` embedding nicely the topological space `H` in the vector space `E` (or more precisely as a structure containing all the relevant properties). Given such a model with corners `I` on `(E, H)`, we define the groupoid of local homeomorphisms of `H` which are smooth when read in `E` (for any regularity `n : ℕ∞`). With this groupoid at hand and the general machinery of charted spaces, we thus get the notion of `C^n` manifold with respect to any model with corners `I` on `(E, H)`. We also introduce a specific type class for `C^∞` manifolds as these are the most commonly used. Some texts assume manifolds to be Hausdorff and secound countable. We (in mathlib) assume neither, but add these assumptions later as needed. (Quite a few results still do not require them.) ## Main definitions * `ModelWithCorners 𝕜 E H` : a structure containing informations on the way a space `H` embeds in a model vector space E over the field `𝕜`. This is all that is needed to define a smooth manifold with model space `H`, and model vector space `E`. * `modelWithCornersSelf 𝕜 E` : trivial model with corners structure on the space `E` embedded in itself by the identity. * `contDiffGroupoid n I` : when `I` is a model with corners on `(𝕜, E, H)`, this is the groupoid of partial homeos of `H` which are of class `C^n` over the normed field `𝕜`, when read in `E`. * `SmoothManifoldWithCorners I M` : a type class saying that the charted space `M`, modelled on the space `H`, has `C^∞` changes of coordinates with respect to the model with corners `I` on `(𝕜, E, H)`. This type class is just a shortcut for `HasGroupoid M (contDiffGroupoid ∞ I)`. * `extChartAt I x`: in a smooth manifold with corners with the model `I` on `(E, H)`, the charts take values in `H`, but often we may want to use their `E`-valued version, obtained by composing the charts with `I`. Since the target is in general not open, we can not register them as partial homeomorphisms, but we register them as `PartialEquiv`s. `extChartAt I x` is the canonical such partial equiv around `x`. As specific examples of models with corners, we define (in `Geometry.Manifold.Instances.Real`) * `modelWithCornersSelf ℝ (EuclideanSpace (Fin n))` for the model space used to define `n`-dimensional real manifolds without boundary (with notation `𝓡 n` in the locale `Manifold`) * `ModelWithCorners ℝ (EuclideanSpace (Fin n)) (EuclideanHalfSpace n)` for the model space used to define `n`-dimensional real manifolds with boundary (with notation `𝓡∂ n` in the locale `Manifold`) * `ModelWithCorners ℝ (EuclideanSpace (Fin n)) (EuclideanQuadrant n)` for the model space used to define `n`-dimensional real manifolds with corners With these definitions at hand, to invoke an `n`-dimensional real manifold without boundary, one could use `variable {n : ℕ} {M : Type*} [TopologicalSpace M] [ChartedSpace (EuclideanSpace (Fin n)) M] [SmoothManifoldWithCorners (𝓡 n) M]`. However, this is not the recommended way: a theorem proved using this assumption would not apply for instance to the tangent space of such a manifold, which is modelled on `(EuclideanSpace (Fin n)) × (EuclideanSpace (Fin n))` and not on `EuclideanSpace (Fin (2 * n))`! In the same way, it would not apply to product manifolds, modelled on `(EuclideanSpace (Fin n)) × (EuclideanSpace (Fin m))`. The right invocation does not focus on one specific construction, but on all constructions sharing the right properties, like `variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {I : ModelWithCorners ℝ E E} [I.Boundaryless] {M : Type*} [TopologicalSpace M] [ChartedSpace E M] [SmoothManifoldWithCorners I M]` Here, `I.Boundaryless` is a typeclass property ensuring that there is no boundary (this is for instance the case for `modelWithCornersSelf`, or products of these). Note that one could consider as a natural assumption to only use the trivial model with corners `modelWithCornersSelf ℝ E`, but again in product manifolds the natural model with corners will not be this one but the product one (and they are not defeq as `(fun p : E × F ↦ (p.1, p.2))` is not defeq to the identity). So, it is important to use the above incantation to maximize the applicability of theorems. ## Implementation notes We want to talk about manifolds modelled on a vector space, but also on manifolds with boundary, modelled on a half space (or even manifolds with corners). For the latter examples, we still want to define smooth functions, tangent bundles, and so on. As smooth functions are well defined on vector spaces or subsets of these, one could take for model space a subtype of a vector space. With the drawback that the whole vector space itself (which is the most basic example) is not directly a subtype of itself: the inclusion of `univ : Set E` in `Set E` would show up in the definition, instead of `id`. A good abstraction covering both cases it to have a vector space `E` (with basic example the Euclidean space), a model space `H` (with basic example the upper half space), and an embedding of `H` into `E` (which can be the identity for `H = E`, or `Subtype.val` for manifolds with corners). We say that the pair `(E, H)` with their embedding is a model with corners, and we encompass all the relevant properties (in particular the fact that the image of `H` in `E` should have unique differentials) in the definition of `ModelWithCorners`. We concentrate on `C^∞` manifolds: all the definitions work equally well for `C^n` manifolds, but later on it is a pain to carry all over the smoothness parameter, especially when one wants to deal with `C^k` functions as there would be additional conditions `k ≤ n` everywhere. Since one deals almost all the time with `C^∞` (or analytic) manifolds, this seems to be a reasonable choice that one could revisit later if needed. `C^k` manifolds are still available, but they should be called using `HasGroupoid M (contDiffGroupoid k I)` where `I` is the model with corners. I have considered using the model with corners `I` as a typeclass argument, possibly `outParam`, to get lighter notations later on, but it did not turn out right, as on `E × F` there are two natural model with corners, the trivial (identity) one, and the product one, and they are not defeq and one needs to indicate to Lean which one we want to use. This means that when talking on objects on manifolds one will most often need to specify the model with corners one is using. For instance, the tangent bundle will be `TangentBundle I M` and the derivative will be `mfderiv I I' f`, instead of the more natural notations `TangentBundle 𝕜 M` and `mfderiv 𝕜 f` (the field has to be explicit anyway, as some manifolds could be considered both as real and complex manifolds). -/ noncomputable section universe u v w u' v' w' open Set Filter Function open scoped Manifold Filter Topology /-- The extended natural number `∞` -/ scoped[Manifold] notation "∞" => (⊤ : ℕ∞) /-! ### Models with corners. -/ /-- A structure containing informations on the way a space `H` embeds in a model vector space `E` over the field `𝕜`. This is all what is needed to define a smooth manifold with model space `H`, and model vector space `E`. -/ @[ext] -- Porting note(#5171): was nolint has_nonempty_instance structure ModelWithCorners (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] (H : Type*) [TopologicalSpace H] extends PartialEquiv H E where source_eq : source = univ unique_diff' : UniqueDiffOn 𝕜 toPartialEquiv.target continuous_toFun : Continuous toFun := by continuity continuous_invFun : Continuous invFun := by continuity #align model_with_corners ModelWithCorners attribute [simp, mfld_simps] ModelWithCorners.source_eq /-- A vector space is a model with corners. -/ def modelWithCornersSelf (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] : ModelWithCorners 𝕜 E E where toPartialEquiv := PartialEquiv.refl E source_eq := rfl unique_diff' := uniqueDiffOn_univ continuous_toFun := continuous_id continuous_invFun := continuous_id #align model_with_corners_self modelWithCornersSelf @[inherit_doc] scoped[Manifold] notation "𝓘(" 𝕜 ", " E ")" => modelWithCornersSelf 𝕜 E /-- A normed field is a model with corners. -/ scoped[Manifold] notation "𝓘(" 𝕜 ")" => modelWithCornersSelf 𝕜 𝕜 section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) namespace ModelWithCorners /-- Coercion of a model with corners to a function. We don't use `e.toFun` because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/ @[coe] def toFun' (e : ModelWithCorners 𝕜 E H) : H → E := e.toFun instance : CoeFun (ModelWithCorners 𝕜 E H) fun _ => H → E := ⟨toFun'⟩ /-- The inverse to a model with corners, only registered as a `PartialEquiv`. -/ protected def symm : PartialEquiv E H := I.toPartialEquiv.symm #align model_with_corners.symm ModelWithCorners.symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] (H : Type*) [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) : H → E := I #align model_with_corners.simps.apply ModelWithCorners.Simps.apply /-- See Note [custom simps projection] -/ def Simps.symm_apply (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] (H : Type*) [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) : E → H := I.symm #align model_with_corners.simps.symm_apply ModelWithCorners.Simps.symm_apply initialize_simps_projections ModelWithCorners (toFun → apply, invFun → symm_apply) -- Register a few lemmas to make sure that `simp` puts expressions in normal form @[simp, mfld_simps] theorem toPartialEquiv_coe : (I.toPartialEquiv : H → E) = I := rfl #align model_with_corners.to_local_equiv_coe ModelWithCorners.toPartialEquiv_coe @[simp, mfld_simps] theorem mk_coe (e : PartialEquiv H E) (a b c d) : ((ModelWithCorners.mk e a b c d : ModelWithCorners 𝕜 E H) : H → E) = (e : H → E) := rfl #align model_with_corners.mk_coe ModelWithCorners.mk_coe @[simp, mfld_simps] theorem toPartialEquiv_coe_symm : (I.toPartialEquiv.symm : E → H) = I.symm := rfl #align model_with_corners.to_local_equiv_coe_symm ModelWithCorners.toPartialEquiv_coe_symm @[simp, mfld_simps] theorem mk_symm (e : PartialEquiv H E) (a b c d) : (ModelWithCorners.mk e a b c d : ModelWithCorners 𝕜 E H).symm = e.symm := rfl #align model_with_corners.mk_symm ModelWithCorners.mk_symm @[continuity] protected theorem continuous : Continuous I := I.continuous_toFun #align model_with_corners.continuous ModelWithCorners.continuous protected theorem continuousAt {x} : ContinuousAt I x := I.continuous.continuousAt #align model_with_corners.continuous_at ModelWithCorners.continuousAt protected theorem continuousWithinAt {s x} : ContinuousWithinAt I s x := I.continuousAt.continuousWithinAt #align model_with_corners.continuous_within_at ModelWithCorners.continuousWithinAt @[continuity] theorem continuous_symm : Continuous I.symm := I.continuous_invFun #align model_with_corners.continuous_symm ModelWithCorners.continuous_symm theorem continuousAt_symm {x} : ContinuousAt I.symm x := I.continuous_symm.continuousAt #align model_with_corners.continuous_at_symm ModelWithCorners.continuousAt_symm theorem continuousWithinAt_symm {s x} : ContinuousWithinAt I.symm s x := I.continuous_symm.continuousWithinAt #align model_with_corners.continuous_within_at_symm ModelWithCorners.continuousWithinAt_symm theorem continuousOn_symm {s} : ContinuousOn I.symm s := I.continuous_symm.continuousOn #align model_with_corners.continuous_on_symm ModelWithCorners.continuousOn_symm @[simp, mfld_simps] theorem target_eq : I.target = range (I : H → E) := by rw [← image_univ, ← I.source_eq] exact I.image_source_eq_target.symm #align model_with_corners.target_eq ModelWithCorners.target_eq protected theorem unique_diff : UniqueDiffOn 𝕜 (range I) := I.target_eq ▸ I.unique_diff' #align model_with_corners.unique_diff ModelWithCorners.unique_diff @[simp, mfld_simps] protected theorem left_inv (x : H) : I.symm (I x) = x := by refine I.left_inv' ?_; simp #align model_with_corners.left_inv ModelWithCorners.left_inv protected theorem leftInverse : LeftInverse I.symm I := I.left_inv #align model_with_corners.left_inverse ModelWithCorners.leftInverse theorem injective : Injective I := I.leftInverse.injective #align model_with_corners.injective ModelWithCorners.injective @[simp, mfld_simps] theorem symm_comp_self : I.symm ∘ I = id := I.leftInverse.comp_eq_id #align model_with_corners.symm_comp_self ModelWithCorners.symm_comp_self protected theorem rightInvOn : RightInvOn I.symm I (range I) := I.leftInverse.rightInvOn_range #align model_with_corners.right_inv_on ModelWithCorners.rightInvOn @[simp, mfld_simps] protected theorem right_inv {x : E} (hx : x ∈ range I) : I (I.symm x) = x := I.rightInvOn hx #align model_with_corners.right_inv ModelWithCorners.right_inv theorem preimage_image (s : Set H) : I ⁻¹' (I '' s) = s := I.injective.preimage_image s #align model_with_corners.preimage_image ModelWithCorners.preimage_image protected theorem image_eq (s : Set H) : I '' s = I.symm ⁻¹' s ∩ range I := by refine (I.toPartialEquiv.image_eq_target_inter_inv_preimage ?_).trans ?_ · rw [I.source_eq]; exact subset_univ _ · rw [inter_comm, I.target_eq, I.toPartialEquiv_coe_symm] #align model_with_corners.image_eq ModelWithCorners.image_eq protected theorem closedEmbedding : ClosedEmbedding I := I.leftInverse.closedEmbedding I.continuous_symm I.continuous #align model_with_corners.closed_embedding ModelWithCorners.closedEmbedding theorem isClosed_range : IsClosed (range I) := I.closedEmbedding.isClosed_range #align model_with_corners.closed_range ModelWithCorners.isClosed_range @[deprecated (since := "2024-03-17")] alias closed_range := isClosed_range theorem map_nhds_eq (x : H) : map I (𝓝 x) = 𝓝[range I] I x := I.closedEmbedding.toEmbedding.map_nhds_eq x #align model_with_corners.map_nhds_eq ModelWithCorners.map_nhds_eq theorem map_nhdsWithin_eq (s : Set H) (x : H) : map I (𝓝[s] x) = 𝓝[I '' s] I x := I.closedEmbedding.toEmbedding.map_nhdsWithin_eq s x #align model_with_corners.map_nhds_within_eq ModelWithCorners.map_nhdsWithin_eq theorem image_mem_nhdsWithin {x : H} {s : Set H} (hs : s ∈ 𝓝 x) : I '' s ∈ 𝓝[range I] I x := I.map_nhds_eq x ▸ image_mem_map hs #align model_with_corners.image_mem_nhds_within ModelWithCorners.image_mem_nhdsWithin theorem symm_map_nhdsWithin_image {x : H} {s : Set H} : map I.symm (𝓝[I '' s] I x) = 𝓝[s] x := by rw [← I.map_nhdsWithin_eq, map_map, I.symm_comp_self, map_id] #align model_with_corners.symm_map_nhds_within_image ModelWithCorners.symm_map_nhdsWithin_image theorem symm_map_nhdsWithin_range (x : H) : map I.symm (𝓝[range I] I x) = 𝓝 x := by rw [← I.map_nhds_eq, map_map, I.symm_comp_self, map_id] #align model_with_corners.symm_map_nhds_within_range ModelWithCorners.symm_map_nhdsWithin_range theorem unique_diff_preimage {s : Set H} (hs : IsOpen s) : UniqueDiffOn 𝕜 (I.symm ⁻¹' s ∩ range I) := by rw [inter_comm] exact I.unique_diff.inter (hs.preimage I.continuous_invFun) #align model_with_corners.unique_diff_preimage ModelWithCorners.unique_diff_preimage theorem unique_diff_preimage_source {β : Type*} [TopologicalSpace β] {e : PartialHomeomorph H β} : UniqueDiffOn 𝕜 (I.symm ⁻¹' e.source ∩ range I) := I.unique_diff_preimage e.open_source #align model_with_corners.unique_diff_preimage_source ModelWithCorners.unique_diff_preimage_source theorem unique_diff_at_image {x : H} : UniqueDiffWithinAt 𝕜 (range I) (I x) := I.unique_diff _ (mem_range_self _) #align model_with_corners.unique_diff_at_image ModelWithCorners.unique_diff_at_image theorem symm_continuousWithinAt_comp_right_iff {X} [TopologicalSpace X] {f : H → X} {s : Set H} {x : H} : ContinuousWithinAt (f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) ↔ ContinuousWithinAt f s x := by refine ⟨fun h => ?_, fun h => ?_⟩ · have := h.comp I.continuousWithinAt (mapsTo_preimage _ _) simp_rw [preimage_inter, preimage_preimage, I.left_inv, preimage_id', preimage_range, inter_univ] at this rwa [Function.comp.assoc, I.symm_comp_self] at this · rw [← I.left_inv x] at h; exact h.comp I.continuousWithinAt_symm inter_subset_left #align model_with_corners.symm_continuous_within_at_comp_right_iff ModelWithCorners.symm_continuousWithinAt_comp_right_iff protected theorem locallyCompactSpace [LocallyCompactSpace E] (I : ModelWithCorners 𝕜 E H) : LocallyCompactSpace H := by have : ∀ x : H, (𝓝 x).HasBasis (fun s => s ∈ 𝓝 (I x) ∧ IsCompact s) fun s => I.symm '' (s ∩ range I) := fun x ↦ by rw [← I.symm_map_nhdsWithin_range] exact ((compact_basis_nhds (I x)).inf_principal _).map _ refine .of_hasBasis this ?_ rintro x s ⟨-, hsc⟩ exact (hsc.inter_right I.isClosed_range).image I.continuous_symm #align model_with_corners.locally_compact ModelWithCorners.locallyCompactSpace open TopologicalSpace protected theorem secondCountableTopology [SecondCountableTopology E] (I : ModelWithCorners 𝕜 E H) : SecondCountableTopology H := I.closedEmbedding.toEmbedding.secondCountableTopology #align model_with_corners.second_countable_topology ModelWithCorners.secondCountableTopology end ModelWithCorners section variable (𝕜 E) /-- In the trivial model with corners, the associated `PartialEquiv` is the identity. -/ @[simp, mfld_simps] theorem modelWithCornersSelf_partialEquiv : 𝓘(𝕜, E).toPartialEquiv = PartialEquiv.refl E := rfl #align model_with_corners_self_local_equiv modelWithCornersSelf_partialEquiv @[simp, mfld_simps] theorem modelWithCornersSelf_coe : (𝓘(𝕜, E) : E → E) = id := rfl #align model_with_corners_self_coe modelWithCornersSelf_coe @[simp, mfld_simps] theorem modelWithCornersSelf_coe_symm : (𝓘(𝕜, E).symm : E → E) = id := rfl #align model_with_corners_self_coe_symm modelWithCornersSelf_coe_symm end end section ModelWithCornersProd /-- Given two model_with_corners `I` on `(E, H)` and `I'` on `(E', H')`, we define the model with corners `I.prod I'` on `(E × E', ModelProd H H')`. This appears in particular for the manifold structure on the tangent bundle to a manifold modelled on `(E, H)`: it will be modelled on `(E × E, H × E)`. See note [Manifold type tags] for explanation about `ModelProd H H'` vs `H × H'`. -/ @[simps (config := .lemmasOnly)] def ModelWithCorners.prod {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type w} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {E' : Type v'} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type w'} [TopologicalSpace H'] (I' : ModelWithCorners 𝕜 E' H') : ModelWithCorners 𝕜 (E × E') (ModelProd H H') := { I.toPartialEquiv.prod I'.toPartialEquiv with toFun := fun x => (I x.1, I' x.2) invFun := fun x => (I.symm x.1, I'.symm x.2) source := { x | x.1 ∈ I.source ∧ x.2 ∈ I'.source } source_eq := by simp only [setOf_true, mfld_simps] unique_diff' := I.unique_diff'.prod I'.unique_diff' continuous_toFun := I.continuous_toFun.prod_map I'.continuous_toFun continuous_invFun := I.continuous_invFun.prod_map I'.continuous_invFun } #align model_with_corners.prod ModelWithCorners.prod /-- Given a finite family of `ModelWithCorners` `I i` on `(E i, H i)`, we define the model with corners `pi I` on `(Π i, E i, ModelPi H)`. See note [Manifold type tags] for explanation about `ModelPi H`. -/ def ModelWithCorners.pi {𝕜 : Type u} [NontriviallyNormedField 𝕜] {ι : Type v} [Fintype ι] {E : ι → Type w} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] {H : ι → Type u'} [∀ i, TopologicalSpace (H i)] (I : ∀ i, ModelWithCorners 𝕜 (E i) (H i)) : ModelWithCorners 𝕜 (∀ i, E i) (ModelPi H) where toPartialEquiv := PartialEquiv.pi fun i => (I i).toPartialEquiv source_eq := by simp only [pi_univ, mfld_simps] unique_diff' := UniqueDiffOn.pi ι E _ _ fun i _ => (I i).unique_diff' continuous_toFun := continuous_pi fun i => (I i).continuous.comp (continuous_apply i) continuous_invFun := continuous_pi fun i => (I i).continuous_symm.comp (continuous_apply i) #align model_with_corners.pi ModelWithCorners.pi /-- Special case of product model with corners, which is trivial on the second factor. This shows up as the model to tangent bundles. -/ abbrev ModelWithCorners.tangent {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type w} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) : ModelWithCorners 𝕜 (E × E) (ModelProd H E) := I.prod 𝓘(𝕜, E) #align model_with_corners.tangent ModelWithCorners.tangent variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {H : Type*} [TopologicalSpace H] {H' : Type*} [TopologicalSpace H'] {G : Type*} [TopologicalSpace G] {G' : Type*} [TopologicalSpace G'] {I : ModelWithCorners 𝕜 E H} {J : ModelWithCorners 𝕜 F G} @[simp, mfld_simps] theorem modelWithCorners_prod_toPartialEquiv : (I.prod J).toPartialEquiv = I.toPartialEquiv.prod J.toPartialEquiv := rfl #align model_with_corners_prod_to_local_equiv modelWithCorners_prod_toPartialEquiv @[simp, mfld_simps] theorem modelWithCorners_prod_coe (I : ModelWithCorners 𝕜 E H) (I' : ModelWithCorners 𝕜 E' H') : (I.prod I' : _ × _ → _ × _) = Prod.map I I' := rfl #align model_with_corners_prod_coe modelWithCorners_prod_coe @[simp, mfld_simps] theorem modelWithCorners_prod_coe_symm (I : ModelWithCorners 𝕜 E H) (I' : ModelWithCorners 𝕜 E' H') : ((I.prod I').symm : _ × _ → _ × _) = Prod.map I.symm I'.symm := rfl #align model_with_corners_prod_coe_symm modelWithCorners_prod_coe_symm theorem modelWithCornersSelf_prod : 𝓘(𝕜, E × F) = 𝓘(𝕜, E).prod 𝓘(𝕜, F) := by ext1 <;> simp #align model_with_corners_self_prod modelWithCornersSelf_prod theorem ModelWithCorners.range_prod : range (I.prod J) = range I ×ˢ range J := by simp_rw [← ModelWithCorners.target_eq]; rfl #align model_with_corners.range_prod ModelWithCorners.range_prod end ModelWithCornersProd section Boundaryless /-- Property ensuring that the model with corners `I` defines manifolds without boundary. This differs from the more general `BoundarylessManifold`, which requires every point on the manifold to be an interior point. -/ class ModelWithCorners.Boundaryless {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) : Prop where range_eq_univ : range I = univ #align model_with_corners.boundaryless ModelWithCorners.Boundaryless theorem ModelWithCorners.range_eq_univ {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) [I.Boundaryless] : range I = univ := ModelWithCorners.Boundaryless.range_eq_univ /-- If `I` is a `ModelWithCorners.Boundaryless` model, then it is a homeomorphism. -/ @[simps (config := {simpRhs := true})] def ModelWithCorners.toHomeomorph {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) [I.Boundaryless] : H ≃ₜ E where __ := I left_inv := I.left_inv right_inv _ := I.right_inv <| I.range_eq_univ.symm ▸ mem_univ _ /-- The trivial model with corners has no boundary -/ instance modelWithCornersSelf_boundaryless (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] : (modelWithCornersSelf 𝕜 E).Boundaryless := ⟨by simp⟩ #align model_with_corners_self_boundaryless modelWithCornersSelf_boundaryless /-- If two model with corners are boundaryless, their product also is -/ instance ModelWithCorners.range_eq_univ_prod {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type w} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) [I.Boundaryless] {E' : Type v'} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type w'} [TopologicalSpace H'] (I' : ModelWithCorners 𝕜 E' H') [I'.Boundaryless] : (I.prod I').Boundaryless := by constructor dsimp [ModelWithCorners.prod, ModelProd] rw [← prod_range_range_eq, ModelWithCorners.Boundaryless.range_eq_univ, ModelWithCorners.Boundaryless.range_eq_univ, univ_prod_univ] #align model_with_corners.range_eq_univ_prod ModelWithCorners.range_eq_univ_prod end Boundaryless section contDiffGroupoid /-! ### Smooth functions on models with corners -/ variable {m n : ℕ∞} {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] variable (n) /-- Given a model with corners `(E, H)`, we define the pregroupoid of `C^n` transformations of `H` as the maps that are `C^n` when read in `E` through `I`. -/ def contDiffPregroupoid : Pregroupoid H where property f s := ContDiffOn 𝕜 n (I ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) comp {f g u v} hf hg _ _ _ := by have : I ∘ (g ∘ f) ∘ I.symm = (I ∘ g ∘ I.symm) ∘ I ∘ f ∘ I.symm := by ext x; simp simp only [this] refine hg.comp (hf.mono fun x ⟨hx1, hx2⟩ ↦ ⟨hx1.1, hx2⟩) ?_ rintro x ⟨hx1, _⟩ simp only [mfld_simps] at hx1 ⊢ exact hx1.2 id_mem := by apply ContDiffOn.congr contDiff_id.contDiffOn rintro x ⟨_, hx2⟩ rcases mem_range.1 hx2 with ⟨y, hy⟩ rw [← hy] simp only [mfld_simps] locality {f u} _ H := by apply contDiffOn_of_locally_contDiffOn rintro y ⟨hy1, hy2⟩ rcases mem_range.1 hy2 with ⟨x, hx⟩ rw [← hx] at hy1 ⊢ simp only [mfld_simps] at hy1 ⊢ rcases H x hy1 with ⟨v, v_open, xv, hv⟩ have : I.symm ⁻¹' (u ∩ v) ∩ range I = I.symm ⁻¹' u ∩ range I ∩ I.symm ⁻¹' v := by rw [preimage_inter, inter_assoc, inter_assoc] congr 1 rw [inter_comm] rw [this] at hv exact ⟨I.symm ⁻¹' v, v_open.preimage I.continuous_symm, by simpa, hv⟩ congr {f g u} _ fg hf := by apply hf.congr rintro y ⟨hy1, hy2⟩ rcases mem_range.1 hy2 with ⟨x, hx⟩ rw [← hx] at hy1 ⊢ simp only [mfld_simps] at hy1 ⊢ rw [fg _ hy1] /-- Given a model with corners `(E, H)`, we define the groupoid of invertible `C^n` transformations of `H` as the invertible maps that are `C^n` when read in `E` through `I`. -/ def contDiffGroupoid : StructureGroupoid H := Pregroupoid.groupoid (contDiffPregroupoid n I) #align cont_diff_groupoid contDiffGroupoid variable {n} /-- Inclusion of the groupoid of `C^n` local diffeos in the groupoid of `C^m` local diffeos when `m ≤ n` -/ theorem contDiffGroupoid_le (h : m ≤ n) : contDiffGroupoid n I ≤ contDiffGroupoid m I := by rw [contDiffGroupoid, contDiffGroupoid] apply groupoid_of_pregroupoid_le intro f s hfs exact ContDiffOn.of_le hfs h #align cont_diff_groupoid_le contDiffGroupoid_le /-- The groupoid of `0`-times continuously differentiable maps is just the groupoid of all partial homeomorphisms -/ theorem contDiffGroupoid_zero_eq : contDiffGroupoid 0 I = continuousGroupoid H := by apply le_antisymm le_top intro u _ -- we have to check that every partial homeomorphism belongs to `contDiffGroupoid 0 I`, -- by unfolding its definition change u ∈ contDiffGroupoid 0 I rw [contDiffGroupoid, mem_groupoid_of_pregroupoid, contDiffPregroupoid] simp only [contDiffOn_zero] constructor · refine I.continuous.comp_continuousOn (u.continuousOn.comp I.continuousOn_symm ?_) exact (mapsTo_preimage _ _).mono_left inter_subset_left · refine I.continuous.comp_continuousOn (u.symm.continuousOn.comp I.continuousOn_symm ?_) exact (mapsTo_preimage _ _).mono_left inter_subset_left #align cont_diff_groupoid_zero_eq contDiffGroupoid_zero_eq variable (n) /-- An identity partial homeomorphism belongs to the `C^n` groupoid. -/ theorem ofSet_mem_contDiffGroupoid {s : Set H} (hs : IsOpen s) : PartialHomeomorph.ofSet s hs ∈ contDiffGroupoid n I := by rw [contDiffGroupoid, mem_groupoid_of_pregroupoid] suffices h : ContDiffOn 𝕜 n (I ∘ I.symm) (I.symm ⁻¹' s ∩ range I) by simp [h, contDiffPregroupoid] have : ContDiffOn 𝕜 n id (univ : Set E) := contDiff_id.contDiffOn exact this.congr_mono (fun x hx => I.right_inv hx.2) (subset_univ _) #align of_set_mem_cont_diff_groupoid ofSet_mem_contDiffGroupoid /-- The composition of a partial homeomorphism from `H` to `M` and its inverse belongs to the `C^n` groupoid. -/ theorem symm_trans_mem_contDiffGroupoid (e : PartialHomeomorph M H) : e.symm.trans e ∈ contDiffGroupoid n I := haveI : e.symm.trans e ≈ PartialHomeomorph.ofSet e.target e.open_target := PartialHomeomorph.symm_trans_self _ StructureGroupoid.mem_of_eqOnSource _ (ofSet_mem_contDiffGroupoid n I e.open_target) this #align symm_trans_mem_cont_diff_groupoid symm_trans_mem_contDiffGroupoid variable {E' H' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] [TopologicalSpace H'] /-- The product of two smooth partial homeomorphisms is smooth. -/ theorem contDiffGroupoid_prod {I : ModelWithCorners 𝕜 E H} {I' : ModelWithCorners 𝕜 E' H'} {e : PartialHomeomorph H H} {e' : PartialHomeomorph H' H'} (he : e ∈ contDiffGroupoid ⊤ I) (he' : e' ∈ contDiffGroupoid ⊤ I') : e.prod e' ∈ contDiffGroupoid ⊤ (I.prod I') := by cases' he with he he_symm cases' he' with he' he'_symm simp only at he he_symm he' he'_symm constructor <;> simp only [PartialEquiv.prod_source, PartialHomeomorph.prod_toPartialEquiv, contDiffPregroupoid] · have h3 := ContDiffOn.prod_map he he' rw [← I.image_eq, ← I'.image_eq, prod_image_image_eq] at h3 rw [← (I.prod I').image_eq] exact h3 · have h3 := ContDiffOn.prod_map he_symm he'_symm rw [← I.image_eq, ← I'.image_eq, prod_image_image_eq] at h3 rw [← (I.prod I').image_eq] exact h3 #align cont_diff_groupoid_prod contDiffGroupoid_prod /-- The `C^n` groupoid is closed under restriction. -/ instance : ClosedUnderRestriction (contDiffGroupoid n I) := (closedUnderRestriction_iff_id_le _).mpr (by rw [StructureGroupoid.le_iff] rintro e ⟨s, hs, hes⟩ apply (contDiffGroupoid n I).mem_of_eqOnSource' _ _ _ hes exact ofSet_mem_contDiffGroupoid n I hs) end contDiffGroupoid section analyticGroupoid variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] /-- Given a model with corners `(E, H)`, we define the groupoid of analytic transformations of `H` as the maps that are analytic and map interior to interior when read in `E` through `I`. We also explicitly define that they are `C^∞` on the whole domain, since we are only requiring analyticity on the interior of the domain. -/ def analyticGroupoid : StructureGroupoid H := (contDiffGroupoid ∞ I) ⊓ Pregroupoid.groupoid { property := fun f s => AnalyticOn 𝕜 (I ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ interior (range I)) ∧ (I.symm ⁻¹' s ∩ interior (range I)).image (I ∘ f ∘ I.symm) ⊆ interior (range I) comp := fun {f g u v} hf hg _ _ _ => by simp only [] at hf hg ⊢ have comp : I ∘ (g ∘ f) ∘ I.symm = (I ∘ g ∘ I.symm) ∘ I ∘ f ∘ I.symm := by ext x; simp apply And.intro · simp only [comp, preimage_inter] refine hg.left.comp (hf.left.mono ?_) ?_ · simp only [subset_inter_iff, inter_subset_right] rw [inter_assoc] simp · intro x hx apply And.intro · rw [mem_preimage, comp_apply, I.left_inv] exact hx.left.right · apply hf.right rw [mem_image] exact ⟨x, ⟨⟨hx.left.left, hx.right⟩, rfl⟩⟩ · simp only [comp] rw [image_comp] intro x hx rw [mem_image] at hx rcases hx with ⟨x', hx'⟩ refine hg.right ⟨x', And.intro ?_ hx'.right⟩ apply And.intro · have hx'1 : x' ∈ ((v.preimage f).preimage (I.symm)).image (I ∘ f ∘ I.symm) := by refine image_subset (I ∘ f ∘ I.symm) ?_ hx'.left rw [preimage_inter] refine Subset.trans ?_ (u.preimage I.symm).inter_subset_right apply inter_subset_left rcases hx'1 with ⟨x'', hx''⟩ rw [hx''.right.symm] simp only [comp_apply, mem_preimage, I.left_inv] exact hx''.left · rw [mem_image] at hx' rcases hx'.left with ⟨x'', hx''⟩ exact hf.right ⟨x'', ⟨⟨hx''.left.left.left, hx''.left.right⟩, hx''.right⟩⟩ id_mem := by apply And.intro · simp only [preimage_univ, univ_inter] exact AnalyticOn.congr isOpen_interior (f := (1 : E →L[𝕜] E)) (fun x _ => (1 : E →L[𝕜] E).analyticAt x) (fun z hz => (I.right_inv (interior_subset hz)).symm) · intro x hx simp only [id_comp, comp_apply, preimage_univ, univ_inter, mem_image] at hx rcases hx with ⟨y, hy⟩ rw [← hy.right, I.right_inv (interior_subset hy.left)] exact hy.left locality := fun {f u} _ h => by simp only [] at h simp only [AnalyticOn] apply And.intro · intro x hx rcases h (I.symm x) (mem_preimage.mp hx.left) with ⟨v, hv⟩ exact hv.right.right.left x ⟨mem_preimage.mpr ⟨hx.left, hv.right.left⟩, hx.right⟩ · apply mapsTo'.mp simp only [MapsTo] intro x hx rcases h (I.symm x) hx.left with ⟨v, hv⟩ apply hv.right.right.right rw [mem_image] have hx' := And.intro hx (mem_preimage.mpr hv.right.left) rw [← mem_inter_iff, inter_comm, ← inter_assoc, ← preimage_inter, inter_comm v u] at hx' exact ⟨x, ⟨hx', rfl⟩⟩ congr := fun {f g u} hu fg hf => by simp only [] at hf ⊢ apply And.intro · refine AnalyticOn.congr (IsOpen.inter (hu.preimage I.continuous_symm) isOpen_interior) hf.left ?_ intro z hz simp only [comp_apply] rw [fg (I.symm z) hz.left] · intro x hx apply hf.right rw [mem_image] at hx ⊢ rcases hx with ⟨y, hy⟩ refine ⟨y, ⟨hy.left, ?_⟩⟩ rw [comp_apply, comp_apply, fg (I.symm y) hy.left.left] at hy exact hy.right } /-- An identity partial homeomorphism belongs to the analytic groupoid. -/ theorem ofSet_mem_analyticGroupoid {s : Set H} (hs : IsOpen s) : PartialHomeomorph.ofSet s hs ∈ analyticGroupoid I := by rw [analyticGroupoid] refine And.intro (ofSet_mem_contDiffGroupoid ∞ I hs) ?_ apply mem_groupoid_of_pregroupoid.mpr suffices h : AnalyticOn 𝕜 (I ∘ I.symm) (I.symm ⁻¹' s ∩ interior (range I)) ∧ (I.symm ⁻¹' s ∩ interior (range I)).image (I ∘ I.symm) ⊆ interior (range I) by simp only [PartialHomeomorph.ofSet_apply, id_comp, PartialHomeomorph.ofSet_toPartialEquiv, PartialEquiv.ofSet_source, h, comp_apply, mem_range, image_subset_iff, true_and, PartialHomeomorph.ofSet_symm, PartialEquiv.ofSet_target, and_self] intro x hx refine mem_preimage.mpr ?_ rw [← I.right_inv (interior_subset hx.right)] at hx exact hx.right apply And.intro · have : AnalyticOn 𝕜 (1 : E →L[𝕜] E) (univ : Set E) := (fun x _ => (1 : E →L[𝕜] E).analyticAt x) exact (this.mono (subset_univ (s.preimage (I.symm) ∩ interior (range I)))).congr ((hs.preimage I.continuous_symm).inter isOpen_interior) fun z hz => (I.right_inv (interior_subset hz.right)).symm · intro x hx simp only [comp_apply, mem_image] at hx rcases hx with ⟨y, hy⟩ rw [← hy.right, I.right_inv (interior_subset hy.left.right)] exact hy.left.right /-- The composition of a partial homeomorphism from `H` to `M` and its inverse belongs to the analytic groupoid. -/ theorem symm_trans_mem_analyticGroupoid (e : PartialHomeomorph M H) : e.symm.trans e ∈ analyticGroupoid I := haveI : e.symm.trans e ≈ PartialHomeomorph.ofSet e.target e.open_target := PartialHomeomorph.symm_trans_self _ StructureGroupoid.mem_of_eqOnSource _ (ofSet_mem_analyticGroupoid I e.open_target) this /-- The analytic groupoid is closed under restriction. -/ instance : ClosedUnderRestriction (analyticGroupoid I) := (closedUnderRestriction_iff_id_le _).mpr (by rw [StructureGroupoid.le_iff] rintro e ⟨s, hs, hes⟩ apply (analyticGroupoid I).mem_of_eqOnSource' _ _ _ hes exact ofSet_mem_analyticGroupoid I hs) /-- The analytic groupoid on a boundaryless charted space modeled on a complete vector space consists of the partial homeomorphisms which are analytic and have analytic inverse. -/ theorem mem_analyticGroupoid_of_boundaryless [CompleteSpace E] [I.Boundaryless] (e : PartialHomeomorph H H) : e ∈ analyticGroupoid I ↔ AnalyticOn 𝕜 (I ∘ e ∘ I.symm) (I '' e.source) ∧ AnalyticOn 𝕜 (I ∘ e.symm ∘ I.symm) (I '' e.target) := by apply Iff.intro · intro he have := mem_groupoid_of_pregroupoid.mp he.right simp only [I.image_eq, I.range_eq_univ, interior_univ, subset_univ, and_true] at this ⊢ exact this · intro he apply And.intro all_goals apply mem_groupoid_of_pregroupoid.mpr; simp only [I.image_eq, I.range_eq_univ, interior_univ, subset_univ, and_true, contDiffPregroupoid] at he ⊢ · exact ⟨he.left.contDiffOn, he.right.contDiffOn⟩ · exact he end analyticGroupoid section SmoothManifoldWithCorners /-! ### Smooth manifolds with corners -/ /-- Typeclass defining smooth manifolds with corners with respect to a model with corners, over a field `𝕜` and with infinite smoothness to simplify typeclass search and statements later on. -/ class SmoothManifoldWithCorners {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) (M : Type*) [TopologicalSpace M] [ChartedSpace H M] extends HasGroupoid M (contDiffGroupoid ∞ I) : Prop #align smooth_manifold_with_corners SmoothManifoldWithCorners theorem SmoothManifoldWithCorners.mk' {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) (M : Type*) [TopologicalSpace M] [ChartedSpace H M] [gr : HasGroupoid M (contDiffGroupoid ∞ I)] : SmoothManifoldWithCorners I M := { gr with } #align smooth_manifold_with_corners.mk' SmoothManifoldWithCorners.mk' theorem smoothManifoldWithCorners_of_contDiffOn {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (h : ∀ e e' : PartialHomeomorph M H, e ∈ atlas H M → e' ∈ atlas H M → ContDiffOn 𝕜 ⊤ (I ∘ e.symm ≫ₕ e' ∘ I.symm) (I.symm ⁻¹' (e.symm ≫ₕ e').source ∩ range I)) : SmoothManifoldWithCorners I M where compatible := by haveI : HasGroupoid M (contDiffGroupoid ∞ I) := hasGroupoid_of_pregroupoid _ (h _ _) apply StructureGroupoid.compatible #align smooth_manifold_with_corners_of_cont_diff_on smoothManifoldWithCorners_of_contDiffOn /-- For any model with corners, the model space is a smooth manifold -/ instance model_space_smooth {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} : SmoothManifoldWithCorners I H := { hasGroupoid_model_space _ _ with } #align model_space_smooth model_space_smooth end SmoothManifoldWithCorners namespace SmoothManifoldWithCorners /- We restate in the namespace `SmoothManifoldWithCorners` some lemmas that hold for general charted space with a structure groupoid, avoiding the need to specify the groupoid `contDiffGroupoid ∞ I` explicitly. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) (M : Type*) [TopologicalSpace M] [ChartedSpace H M] /-- The maximal atlas of `M` for the smooth manifold with corners structure corresponding to the model with corners `I`. -/ def maximalAtlas := (contDiffGroupoid ∞ I).maximalAtlas M #align smooth_manifold_with_corners.maximal_atlas SmoothManifoldWithCorners.maximalAtlas variable {M} theorem subset_maximalAtlas [SmoothManifoldWithCorners I M] : atlas H M ⊆ maximalAtlas I M := StructureGroupoid.subset_maximalAtlas _ #align smooth_manifold_with_corners.subset_maximal_atlas SmoothManifoldWithCorners.subset_maximalAtlas theorem chart_mem_maximalAtlas [SmoothManifoldWithCorners I M] (x : M) : chartAt H x ∈ maximalAtlas I M := StructureGroupoid.chart_mem_maximalAtlas _ x #align smooth_manifold_with_corners.chart_mem_maximal_atlas SmoothManifoldWithCorners.chart_mem_maximalAtlas variable {I} theorem compatible_of_mem_maximalAtlas {e e' : PartialHomeomorph M H} (he : e ∈ maximalAtlas I M) (he' : e' ∈ maximalAtlas I M) : e.symm.trans e' ∈ contDiffGroupoid ∞ I := StructureGroupoid.compatible_of_mem_maximalAtlas he he' #align smooth_manifold_with_corners.compatible_of_mem_maximal_atlas SmoothManifoldWithCorners.compatible_of_mem_maximalAtlas /-- The product of two smooth manifolds with corners is naturally a smooth manifold with corners. -/ instance prod {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} (M : Type*) [TopologicalSpace M] [ChartedSpace H M] [SmoothManifoldWithCorners I M] (M' : Type*) [TopologicalSpace M'] [ChartedSpace H' M'] [SmoothManifoldWithCorners I' M'] : SmoothManifoldWithCorners (I.prod I') (M × M') where compatible := by rintro f g ⟨f1, hf1, f2, hf2, rfl⟩ ⟨g1, hg1, g2, hg2, rfl⟩ rw [PartialHomeomorph.prod_symm, PartialHomeomorph.prod_trans] have h1 := (contDiffGroupoid ⊤ I).compatible hf1 hg1 have h2 := (contDiffGroupoid ⊤ I').compatible hf2 hg2 exact contDiffGroupoid_prod h1 h2 #align smooth_manifold_with_corners.prod SmoothManifoldWithCorners.prod end SmoothManifoldWithCorners theorem PartialHomeomorph.singleton_smoothManifoldWithCorners {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] (e : PartialHomeomorph M H) (h : e.source = Set.univ) : @SmoothManifoldWithCorners 𝕜 _ E _ _ H _ I M _ (e.singletonChartedSpace h) := @SmoothManifoldWithCorners.mk' _ _ _ _ _ _ _ _ _ _ (id _) <| e.singleton_hasGroupoid h (contDiffGroupoid ∞ I) #align local_homeomorph.singleton_smooth_manifold_with_corners PartialHomeomorph.singleton_smoothManifoldWithCorners theorem OpenEmbedding.singleton_smoothManifoldWithCorners {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [Nonempty M] {f : M → H} (h : OpenEmbedding f) : @SmoothManifoldWithCorners 𝕜 _ E _ _ H _ I M _ h.singletonChartedSpace := (h.toPartialHomeomorph f).singleton_smoothManifoldWithCorners I (by simp) #align open_embedding.singleton_smooth_manifold_with_corners OpenEmbedding.singleton_smoothManifoldWithCorners namespace TopologicalSpace.Opens open TopologicalSpace variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [SmoothManifoldWithCorners I M] (s : Opens M) instance : SmoothManifoldWithCorners I s := { s.instHasGroupoid (contDiffGroupoid ∞ I) with } end TopologicalSpace.Opens section ExtendedCharts open scoped Topology variable {𝕜 E M H E' M' H' : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [TopologicalSpace H] [TopologicalSpace M] (f f' : PartialHomeomorph M H) (I : ModelWithCorners 𝕜 E H) [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] [TopologicalSpace H'] [TopologicalSpace M'] (I' : ModelWithCorners 𝕜 E' H') {s t : Set M} /-! ### Extended charts In a smooth manifold with corners, the model space is the space `H`. However, we will also need to use extended charts taking values in the model vector space `E`. These extended charts are not `PartialHomeomorph` as the target is not open in `E` in general, but we can still register them as `PartialEquiv`. -/ namespace PartialHomeomorph /-- Given a chart `f` on a manifold with corners, `f.extend I` is the extended chart to the model vector space. -/ @[simp, mfld_simps] def extend : PartialEquiv M E := f.toPartialEquiv ≫ I.toPartialEquiv #align local_homeomorph.extend PartialHomeomorph.extend theorem extend_coe : ⇑(f.extend I) = I ∘ f := rfl #align local_homeomorph.extend_coe PartialHomeomorph.extend_coe theorem extend_coe_symm : ⇑(f.extend I).symm = f.symm ∘ I.symm := rfl #align local_homeomorph.extend_coe_symm PartialHomeomorph.extend_coe_symm theorem extend_source : (f.extend I).source = f.source := by rw [extend, PartialEquiv.trans_source, I.source_eq, preimage_univ, inter_univ] #align local_homeomorph.extend_source PartialHomeomorph.extend_source theorem isOpen_extend_source : IsOpen (f.extend I).source := by rw [extend_source] exact f.open_source #align local_homeomorph.is_open_extend_source PartialHomeomorph.isOpen_extend_source theorem extend_target : (f.extend I).target = I.symm ⁻¹' f.target ∩ range I := by simp_rw [extend, PartialEquiv.trans_target, I.target_eq, I.toPartialEquiv_coe_symm, inter_comm] #align local_homeomorph.extend_target PartialHomeomorph.extend_target theorem extend_target' : (f.extend I).target = I '' f.target := by rw [extend, PartialEquiv.trans_target'', I.source_eq, univ_inter, I.toPartialEquiv_coe] lemma isOpen_extend_target [I.Boundaryless] : IsOpen (f.extend I).target := by rw [extend_target, I.range_eq_univ, inter_univ] exact I.continuous_symm.isOpen_preimage _ f.open_target theorem mapsTo_extend (hs : s ⊆ f.source) : MapsTo (f.extend I) s ((f.extend I).symm ⁻¹' s ∩ range I) := by rw [mapsTo', extend_coe, extend_coe_symm, preimage_comp, ← I.image_eq, image_comp, f.image_eq_target_inter_inv_preimage hs] exact image_subset _ inter_subset_right #align local_homeomorph.maps_to_extend PartialHomeomorph.mapsTo_extend theorem extend_left_inv {x : M} (hxf : x ∈ f.source) : (f.extend I).symm (f.extend I x) = x := (f.extend I).left_inv <| by rwa [f.extend_source] #align local_homeomorph.extend_left_inv PartialHomeomorph.extend_left_inv /-- Variant of `f.extend_left_inv I`, stated in terms of images. -/ lemma extend_left_inv' (ht: t ⊆ f.source) : ((f.extend I).symm ∘ (f.extend I)) '' t = t := EqOn.image_eq_self (fun _ hx ↦ f.extend_left_inv I (ht hx)) theorem extend_source_mem_nhds {x : M} (h : x ∈ f.source) : (f.extend I).source ∈ 𝓝 x := (isOpen_extend_source f I).mem_nhds <| by rwa [f.extend_source I] #align local_homeomorph.extend_source_mem_nhds PartialHomeomorph.extend_source_mem_nhds theorem extend_source_mem_nhdsWithin {x : M} (h : x ∈ f.source) : (f.extend I).source ∈ 𝓝[s] x := mem_nhdsWithin_of_mem_nhds <| extend_source_mem_nhds f I h #align local_homeomorph.extend_source_mem_nhds_within PartialHomeomorph.extend_source_mem_nhdsWithin theorem continuousOn_extend : ContinuousOn (f.extend I) (f.extend I).source := by refine I.continuous.comp_continuousOn ?_ rw [extend_source] exact f.continuousOn #align local_homeomorph.continuous_on_extend PartialHomeomorph.continuousOn_extend theorem continuousAt_extend {x : M} (h : x ∈ f.source) : ContinuousAt (f.extend I) x := (continuousOn_extend f I).continuousAt <| extend_source_mem_nhds f I h #align local_homeomorph.continuous_at_extend PartialHomeomorph.continuousAt_extend theorem map_extend_nhds {x : M} (hy : x ∈ f.source) : map (f.extend I) (𝓝 x) = 𝓝[range I] f.extend I x := by rwa [extend_coe, comp_apply, ← I.map_nhds_eq, ← f.map_nhds_eq, map_map] #align local_homeomorph.map_extend_nhds PartialHomeomorph.map_extend_nhds theorem map_extend_nhds_of_boundaryless [I.Boundaryless] {x : M} (hx : x ∈ f.source) : map (f.extend I) (𝓝 x) = 𝓝 (f.extend I x) := by rw [f.map_extend_nhds _ hx, I.range_eq_univ, nhdsWithin_univ] theorem extend_target_mem_nhdsWithin {y : M} (hy : y ∈ f.source) : (f.extend I).target ∈ 𝓝[range I] f.extend I y := by rw [← PartialEquiv.image_source_eq_target, ← map_extend_nhds f I hy] exact image_mem_map (extend_source_mem_nhds _ _ hy) #align local_homeomorph.extend_target_mem_nhds_within PartialHomeomorph.extend_target_mem_nhdsWithin
Mathlib/Geometry/Manifold/SmoothManifoldWithCorners.lean
1,041
1,044
theorem extend_image_nhd_mem_nhds_of_boundaryless [I.Boundaryless] {x} (hx : x ∈ f.source) {s : Set M} (h : s ∈ 𝓝 x) : (f.extend I) '' s ∈ 𝓝 ((f.extend I) x) := by
rw [← f.map_extend_nhds_of_boundaryless _ hx, Filter.mem_map] filter_upwards [h] using subset_preimage_image (f.extend I) s
/- 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] 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] #align fractional_ideal.map_symm_map FractionalIdeal.map_symm_map theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} : f x ∈ map f I ↔ x ∈ I := mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ #align fractional_ideal.map_mem_map FractionalIdeal.map_mem_map theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) : Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ => ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h) #align fractional_ideal.map_injective FractionalIdeal.map_injective /-- If `g` is an equivalence, `map g` is an isomorphism -/ def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where toFun := map g invFun := map g.symm map_add' I J := map_add I J _ map_mul' I J := map_mul I J _ left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id] right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id] #align fractional_ideal.map_equiv FractionalIdeal.mapEquiv @[simp] theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') : (mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g := rfl #align fractional_ideal.coe_fun_map_equiv FractionalIdeal.coeFun_mapEquiv @[simp] theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I := rfl #align fractional_ideal.map_equiv_apply FractionalIdeal.mapEquiv_apply @[simp] theorem mapEquiv_symm (g : P ≃ₐ[R] P') : ((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm := rfl #align fractional_ideal.map_equiv_symm FractionalIdeal.mapEquiv_symm @[simp] theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) := RingEquiv.ext fun x => by simp #align fractional_ideal.map_equiv_refl FractionalIdeal.mapEquiv_refl theorem isFractional_span_iff {s : Set P} : IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) := ⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => span_induction hb h (by rw [smul_zero] exact isInteger_zero) (fun x y hx hy => by rw [smul_add] exact isInteger_add hx hy) fun s x hx => by rw [smul_comm] exact isInteger_smul hx⟩⟩ #align fractional_ideal.is_fractional_span_iff FractionalIdeal.isFractional_span_iff theorem isFractional_of_fg {I : Submodule R P} (hI : I.FG) : IsFractional S I := by rcases hI with ⟨I, rfl⟩ rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩ rw [isFractional_span_iff] exact ⟨s, hs1, hs⟩ #align fractional_ideal.is_fractional_of_fg FractionalIdeal.isFractional_of_fg theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) : ∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) := Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx) #align fractional_ideal.mem_span_mul_finite_of_mem_mul FractionalIdeal.mem_span_mul_finite_of_mem_mul variable (S) theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) : FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG := coeSubmodule_fg _ inj _ #align fractional_ideal.coe_ideal_fg FractionalIdeal.coeIdeal_fg variable {S} theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) := Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I #align fractional_ideal.fg_unit FractionalIdeal.fg_unit theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) := fg_unit h.unit #align fractional_ideal.fg_of_is_unit FractionalIdeal.fg_of_isUnit theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R) (h : IsUnit (I : FractionalIdeal S P)) : I.FG := by rw [← coeIdeal_fg S inj I] exact FractionalIdeal.fg_of_isUnit I h #align ideal.fg_of_is_unit Ideal.fg_of_isUnit variable (S P P') /-- `canonicalEquiv f f'` is the canonical equivalence between the fractional ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/ noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' := mapEquiv { ringEquivOfRingEquiv P P' (RingEquiv.refl R) (show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with commutes' := fun r => ringEquivOfRingEquiv_eq _ _ } #align fractional_ideal.canonical_equiv FractionalIdeal.canonicalEquiv @[simp] theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} : x ∈ canonicalEquiv S P P' I ↔ ∃ y ∈ I, IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) (y : P) = x := by rw [canonicalEquiv, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ #align fractional_ideal.mem_canonical_equiv_apply FractionalIdeal.mem_canonicalEquiv_apply @[simp] theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P := RingEquiv.ext fun I => SetLike.ext_iff.mpr fun x => by rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ #align fractional_ideal.canonical_equiv_symm FractionalIdeal.canonicalEquiv_symm theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by rw [← canonicalEquiv_symm]; erw [RingEquiv.apply_symm_apply] #align fractional_ideal.canonical_equiv_flip FractionalIdeal.canonicalEquiv_flip @[simp] theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] (I : FractionalIdeal S P) : canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by ext simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply, exists_prop, exists_exists_and_eq_and] #align fractional_ideal.canonical_equiv_canonical_equiv FractionalIdeal.canonicalEquiv_canonicalEquiv theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] : (canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' := RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'') #align fractional_ideal.canonical_equiv_trans_canonical_equiv FractionalIdeal.canonicalEquiv_trans_canonicalEquiv @[simp] theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by ext simp [IsLocalization.map_eq] #align fractional_ideal.canonical_equiv_coe_ideal FractionalIdeal.canonicalEquiv_coeIdeal @[simp] theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by rw [← canonicalEquiv_trans_canonicalEquiv S P P] convert (canonicalEquiv S P P).symm_trans_self exact (canonicalEquiv_symm S P P).symm #align fractional_ideal.canonical_equiv_self FractionalIdeal.canonicalEquiv_self end section IsFractionRing /-! ### `IsFractionRing` section This section concerns fractional ideals in the field of fractions, i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`. -/ variable {K K' : Type*} [Field K] [Field K'] variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K'] variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K') /-- Nonzero fractional ideals contain a nonzero integer. -/ theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) : ∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by obtain ⟨y : K, y_mem, y_not_mem⟩ := SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI) have y_ne_zero : y ≠ 0 := by simpa using y_not_mem obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y refine ⟨x, ?_, ?_⟩ · rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def] exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero · rw [hx] exact smul_mem _ _ y_mem #align fractional_ideal.exists_ne_zero_mem_is_integer FractionalIdeal.exists_ne_zero_mem_isInteger theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI contrapose! x_ne_zero with map_eq_zero refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_)) exact ⟨algebraMap R K x, hx, h.commutes x⟩ #align fractional_ideal.map_ne_zero FractionalIdeal.map_ne_zero @[simp] theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 := ⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ map_zero h⟩ #align fractional_ideal.map_eq_zero_iff FractionalIdeal.map_eq_zero_iff theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) := coeIdeal_injective' le_rfl #align fractional_ideal.coe_ideal_injective FractionalIdeal.coeIdeal_injective theorem coeIdeal_inj {I J : Ideal R} : (I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J := coeIdeal_inj' le_rfl #align fractional_ideal.coe_ideal_inj FractionalIdeal.coeIdeal_inj @[simp] theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ := coeIdeal_eq_zero' le_rfl #align fractional_ideal.coe_ideal_eq_zero FractionalIdeal.coeIdeal_eq_zero theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ := coeIdeal_ne_zero' le_rfl #align fractional_ideal.coe_ideal_ne_zero FractionalIdeal.coeIdeal_ne_zero @[simp] theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by simpa only [Ideal.one_eq_top] using coeIdeal_inj #align fractional_ideal.coe_ideal_eq_one FractionalIdeal.coeIdeal_eq_one theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 := not_iff_not.mpr coeIdeal_eq_one #align fractional_ideal.coe_ideal_ne_one FractionalIdeal.coeIdeal_ne_one theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 := ⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h, fun h ↦ h ▸ num_zero_eq (IsFractionRing.injective R K)⟩ end IsFractionRing section Quotient /-! ### `quotient` section This section defines the ideal quotient of fractional ideals. In this section we need that each non-zero `y : R` has an inverse in the localization, i.e. that the localization is a field. We satisfy this assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which is a field because `R` is a domain. -/ open scoped Classical variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [frac : IsFractionRing R₁ K] instance : Nontrivial (FractionalIdeal R₁⁰ K) := ⟨⟨0, 1, fun h => have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by rw [← (algebraMap R₁ K).map_one] simpa only [h] using coe_mem_one R₁⁰ 1 one_ne_zero ((mem_zero_iff _).mp this)⟩⟩ theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI => zero_ne_one' (FractionalIdeal R₁⁰ K) (by convert h simp [hI]) #align fractional_ideal.ne_zero_of_mul_eq_one FractionalIdeal.ne_zero_of_mul_eq_one variable [IsDomain R₁] theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} : IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by obtain ⟨y, mem_J, not_mem_zero⟩ := SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h) obtain ⟨y', hy'⟩ := hJ y mem_J use aI * y' constructor · apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _) intro y'_eq_zero have : algebraMap R₁ K aJ * y = 0 := by rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero] have y_zero := (mul_eq_zero.mp this).resolve_left (mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _) (mem_nonZeroDivisors_iff_ne_zero.mp haJ)) apply not_mem_zero simpa intro b hb convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1 rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul] #align is_fractional.div_of_nonzero IsFractional.div_of_nonzero theorem fractional_div_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : IsFractional R₁⁰ (I / J : Submodule R₁ K) := I.isFractional.div_of_nonzero J.isFractional fun H => h <| coeToSubmodule_injective <| H.trans coe_zero.symm #align fractional_ideal.fractional_div_of_nonzero FractionalIdeal.fractional_div_of_nonzero noncomputable instance : Div (FractionalIdeal R₁⁰ K) := ⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩ variable {I J : FractionalIdeal R₁⁰ K} @[simp] theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 := dif_pos rfl #align fractional_ideal.div_zero FractionalIdeal.div_zero theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : I / J = ⟨I / J, fractional_div_of_nonzero h⟩ := dif_neg h #align fractional_ideal.div_nonzero FractionalIdeal.div_nonzero @[simp] theorem coe_div {I J : FractionalIdeal R₁⁰ K} (hJ : J ≠ 0) : (↑(I / J) : Submodule R₁ K) = ↑I / (↑J : Submodule R₁ K) := congr_arg _ (dif_neg hJ) #align fractional_ideal.coe_div FractionalIdeal.coe_div theorem mem_div_iff_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} : x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by rw [div_nonzero h] exact Submodule.mem_div_iff_forall_mul_mem #align fractional_ideal.mem_div_iff_of_nonzero FractionalIdeal.mem_div_iff_of_nonzero theorem mul_one_div_le_one {I : FractionalIdeal R₁⁰ K} : I * (1 / I) ≤ 1 := by by_cases hI : I = 0 · rw [hI, div_zero, mul_zero] exact zero_le 1 · rw [← coe_le_coe, coe_mul, coe_div hI, coe_one] apply Submodule.mul_one_div_le_one #align fractional_ideal.mul_one_div_le_one FractionalIdeal.mul_one_div_le_one theorem le_self_mul_one_div {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * (1 / I) := by by_cases hI_nz : I = 0 · rw [hI_nz, div_zero, mul_zero] · rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one] rw [← coe_le_coe, coe_one] at hI exact Submodule.le_self_mul_one_div hI #align fractional_ideal.le_self_mul_one_div FractionalIdeal.le_self_mul_one_div theorem le_div_iff_of_nonzero {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ ∀ x ∈ I, ∀ y ∈ J', x * y ∈ J := ⟨fun h _ hx => (mem_div_iff_of_nonzero hJ').mp (h hx), fun h x hx => (mem_div_iff_of_nonzero hJ').mpr (h x hx)⟩ #align fractional_ideal.le_div_iff_of_nonzero FractionalIdeal.le_div_iff_of_nonzero theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ I * J' ≤ J := by rw [div_nonzero hJ'] -- Porting note: this used to be { convert; rw }, flipped the order. rw [← coe_le_coe (I := I * J') (J := J), coe_mul] exact Submodule.le_div_iff_mul_le #align fractional_ideal.le_div_iff_mul_le FractionalIdeal.le_div_iff_mul_le @[simp] theorem div_one {I : FractionalIdeal R₁⁰ K} : I / 1 = I := by rw [div_nonzero (one_ne_zero' (FractionalIdeal R₁⁰ K))] ext constructor <;> intro h · simpa using mem_div_iff_forall_mul_mem.mp h 1 ((algebraMap R₁ K).map_one ▸ coe_mem_one R₁⁰ 1) · apply mem_div_iff_forall_mul_mem.mpr rintro y ⟨y', _, rfl⟩ -- Porting note: this used to be { convert; rw }, flipped the order. rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def] exact Submodule.smul_mem _ y' h #align fractional_ideal.div_one FractionalIdeal.div_one theorem eq_one_div_of_mul_eq_one_right (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = 1 / I := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hx hy #align fractional_ideal.eq_one_div_of_mul_eq_one_right FractionalIdeal.eq_one_div_of_mul_eq_one_right theorem mul_div_self_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * (1 / I) = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨1 / I, h⟩, fun ⟨J, hJ⟩ => by rwa [← eq_one_div_of_mul_eq_one_right I J hJ]⟩ #align fractional_ideal.mul_div_self_cancel_iff FractionalIdeal.mul_div_self_cancel_iff variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] theorem map_div (I J : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h := by by_cases H : J = 0 · rw [H, div_zero, map_zero, div_zero] · -- Porting note: `simp` wouldn't apply these lemmas so do them manually using `rw` rw [← coeToSubmodule_inj, div_nonzero H, div_nonzero (map_ne_zero _ H)] simp [Submodule.map_div] #align fractional_ideal.map_div FractionalIdeal.map_div -- Porting note: doesn't need to be @[simp] because this follows from `map_one` and `map_div` theorem map_one_div (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h := by rw [map_div, map_one] #align fractional_ideal.map_one_div FractionalIdeal.map_one_div end Quotient section Field variable {R₁ K L : Type*} [CommRing R₁] [Field K] [Field L] variable [Algebra R₁ K] [IsFractionRing R₁ K] [Algebra K L] [IsFractionRing K L] theorem eq_zero_or_one (I : FractionalIdeal K⁰ L) : I = 0 ∨ I = 1 := by rw [or_iff_not_imp_left] intro hI simp_rw [@SetLike.ext_iff _ _ _ I 1, mem_one_iff] intro x constructor · intro x_mem obtain ⟨n, d, rfl⟩ := IsLocalization.mk'_surjective K⁰ x refine ⟨n / d, ?_⟩ rw [map_div₀, IsFractionRing.mk'_eq_div] · rintro ⟨x, rfl⟩ obtain ⟨y, y_ne, y_mem⟩ := exists_ne_zero_mem_isInteger hI rw [← div_mul_cancel₀ x y_ne, RingHom.map_mul, ← Algebra.smul_def] exact smul_mem (M := L) I (x / y) y_mem #align fractional_ideal.eq_zero_or_one FractionalIdeal.eq_zero_or_one theorem eq_zero_or_one_of_isField (hF : IsField R₁) (I : FractionalIdeal R₁⁰ K) : I = 0 ∨ I = 1 := letI : Field R₁ := hF.toField eq_zero_or_one I #align fractional_ideal.eq_zero_or_one_of_is_field FractionalIdeal.eq_zero_or_one_of_isField end Field section PrincipalIdeal variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [IsFractionRing R₁ K] open scoped Classical variable (R₁) /-- `FractionalIdeal.span_finset R₁ s f` is the fractional ideal of `R₁` generated by `f '' s`. -/ -- Porting note: `@[simps]` generated a `Subtype.val` coercion instead of a -- `FractionalIdeal.coeToSubmodule` coercion def spanFinset {ι : Type*} (s : Finset ι) (f : ι → K) : FractionalIdeal R₁⁰ K := ⟨Submodule.span R₁ (f '' s), by obtain ⟨a', ha'⟩ := IsLocalization.exist_integer_multiples R₁⁰ s f refine ⟨a', a'.2, fun x hx => Submodule.span_induction hx ?_ ?_ ?_ ?_⟩ · rintro _ ⟨i, hi, rfl⟩ exact ha' i hi · rw [smul_zero] exact IsLocalization.isInteger_zero · intro x y hx hy rw [smul_add] exact IsLocalization.isInteger_add hx hy · intro c x hx rw [smul_comm] exact IsLocalization.isInteger_smul hx⟩ #align fractional_ideal.span_finset FractionalIdeal.spanFinset @[simp] lemma spanFinset_coe {ι : Type*} (s : Finset ι) (f : ι → K) : (spanFinset R₁ s f : Submodule R₁ K) = Submodule.span R₁ (f '' s) := rfl variable {R₁} @[simp] theorem spanFinset_eq_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f = 0 ↔ ∀ j ∈ s, f j = 0 := by simp only [← coeToSubmodule_inj, spanFinset_coe, coe_zero, Submodule.span_eq_bot, Set.mem_image, Finset.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] #align fractional_ideal.span_finset_eq_zero FractionalIdeal.spanFinset_eq_zero theorem spanFinset_ne_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f ≠ 0 ↔ ∃ j ∈ s, f j ≠ 0 := by simp #align fractional_ideal.span_finset_ne_zero FractionalIdeal.spanFinset_ne_zero open Submodule.IsPrincipal theorem isFractional_span_singleton (x : P) : IsFractional S (span R {x} : Submodule R P) := let ⟨a, ha⟩ := exists_integer_multiple S x isFractional_span_iff.mpr ⟨a, a.2, fun _ hx' => (Set.mem_singleton_iff.mp hx').symm ▸ ha⟩ #align fractional_ideal.is_fractional_span_singleton FractionalIdeal.isFractional_span_singleton variable (S) /-- `spanSingleton x` is the fractional ideal generated by `x` if `0 ∉ S` -/ irreducible_def spanSingleton (x : P) : FractionalIdeal S P := ⟨span R {x}, isFractional_span_singleton x⟩ #align fractional_ideal.span_singleton FractionalIdeal.spanSingleton -- local attribute [semireducible] span_singleton @[simp] theorem coe_spanSingleton (x : P) : (spanSingleton S x : Submodule R P) = span R {x} := by rw [spanSingleton] rfl #align fractional_ideal.coe_span_singleton FractionalIdeal.coe_spanSingleton @[simp] theorem mem_spanSingleton {x y : P} : x ∈ spanSingleton S y ↔ ∃ z : R, z • y = x := by rw [spanSingleton] exact Submodule.mem_span_singleton #align fractional_ideal.mem_span_singleton FractionalIdeal.mem_spanSingleton theorem mem_spanSingleton_self (x : P) : x ∈ spanSingleton S x := (mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩ #align fractional_ideal.mem_span_singleton_self FractionalIdeal.mem_spanSingleton_self variable (P) in /-- A version of `FractionalIdeal.den_mul_self_eq_num` in terms of fractional ideals. -/ theorem den_mul_self_eq_num' (I : FractionalIdeal S P) : spanSingleton S (algebraMap R P I.den) * I = I.num := by apply coeToSubmodule_injective dsimp only rw [coe_mul, ← smul_eq_mul, coe_spanSingleton, smul_eq_mul, Submodule.span_singleton_mul] convert I.den_mul_self_eq_num using 1 ext erw [Set.mem_smul_set, Set.mem_smul_set] simp [Algebra.smul_def] variable {S} @[simp] theorem spanSingleton_le_iff_mem {x : P} {I : FractionalIdeal S P} : spanSingleton S x ≤ I ↔ x ∈ I := by rw [← coe_le_coe, coe_spanSingleton, Submodule.span_singleton_le_iff_mem, mem_coe] #align fractional_ideal.span_singleton_le_iff_mem FractionalIdeal.spanSingleton_le_iff_mem theorem spanSingleton_eq_spanSingleton [NoZeroSMulDivisors R P] {x y : P} : spanSingleton S x = spanSingleton S y ↔ ∃ z : Rˣ, z • x = y := by rw [← Submodule.span_singleton_eq_span_singleton, spanSingleton, spanSingleton] exact Subtype.mk_eq_mk #align fractional_ideal.span_singleton_eq_span_singleton FractionalIdeal.spanSingleton_eq_spanSingleton
Mathlib/RingTheory/FractionalIdeal/Operations.lean
670
674
theorem eq_spanSingleton_of_principal (I : FractionalIdeal S P) [IsPrincipal (I : Submodule R P)] : I = spanSingleton S (generator (I : Submodule R P)) := by
-- Porting note: this used to be `coeToSubmodule_injective (span_singleton_generator ↑I).symm` -- but Lean 4 struggled to unify everything. Turned it into an explicit `rw`. rw [spanSingleton, ← coeToSubmodule_inj, coe_mk, span_singleton_generator]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Analytic.CPolynomial import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add #align_import analysis.calculus.fderiv_analytic from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Frechet derivatives of analytic functions. A function expressible as a power series at a point has a Frechet derivative there. Also the special case in terms of `deriv` when the domain is 1-dimensional. As an application, we show that continuous multilinear maps are smooth. We also compute their iterated derivatives, in `ContinuousMultilinearMap.iteratedFDeriv_eq`. -/ open Filter Asymptotics open scoped ENNReal universe u v variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type u} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section fderiv variable {p : FormalMultilinearSeries 𝕜 E F} {r : ℝ≥0∞} variable {f : E → F} {x : E} {s : Set E} theorem HasFPowerSeriesAt.hasStrictFDerivAt (h : HasFPowerSeriesAt f p x) : HasStrictFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := by refine h.isBigO_image_sub_norm_mul_norm_sub.trans_isLittleO (IsLittleO.of_norm_right ?_) refine isLittleO_iff_exists_eq_mul.2 ⟨fun y => ‖y - (x, x)‖, ?_, EventuallyEq.rfl⟩ refine (continuous_id.sub continuous_const).norm.tendsto' _ _ ?_ rw [_root_.id, sub_self, norm_zero] #align has_fpower_series_at.has_strict_fderiv_at HasFPowerSeriesAt.hasStrictFDerivAt theorem HasFPowerSeriesAt.hasFDerivAt (h : HasFPowerSeriesAt f p x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := h.hasStrictFDerivAt.hasFDerivAt #align has_fpower_series_at.has_fderiv_at HasFPowerSeriesAt.hasFDerivAt theorem HasFPowerSeriesAt.differentiableAt (h : HasFPowerSeriesAt f p x) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt #align has_fpower_series_at.differentiable_at HasFPowerSeriesAt.differentiableAt theorem AnalyticAt.differentiableAt : AnalyticAt 𝕜 f x → DifferentiableAt 𝕜 f x | ⟨_, hp⟩ => hp.differentiableAt #align analytic_at.differentiable_at AnalyticAt.differentiableAt theorem AnalyticAt.differentiableWithinAt (h : AnalyticAt 𝕜 f x) : DifferentiableWithinAt 𝕜 f s x := h.differentiableAt.differentiableWithinAt #align analytic_at.differentiable_within_at AnalyticAt.differentiableWithinAt theorem HasFPowerSeriesAt.fderiv_eq (h : HasFPowerSeriesAt f p x) : fderiv 𝕜 f x = continuousMultilinearCurryFin1 𝕜 E F (p 1) := h.hasFDerivAt.fderiv #align has_fpower_series_at.fderiv_eq HasFPowerSeriesAt.fderiv_eq theorem HasFPowerSeriesOnBall.differentiableOn [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : DifferentiableOn 𝕜 f (EMetric.ball x r) := fun _ hy => (h.analyticAt_of_mem hy).differentiableWithinAt #align has_fpower_series_on_ball.differentiable_on HasFPowerSeriesOnBall.differentiableOn theorem AnalyticOn.differentiableOn (h : AnalyticOn 𝕜 f s) : DifferentiableOn 𝕜 f s := fun y hy => (h y hy).differentiableWithinAt #align analytic_on.differentiable_on AnalyticOn.differentiableOn theorem HasFPowerSeriesOnBall.hasFDerivAt [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1)) (x + y) := (h.changeOrigin hy).hasFPowerSeriesAt.hasFDerivAt #align has_fpower_series_on_ball.has_fderiv_at HasFPowerSeriesOnBall.hasFDerivAt theorem HasFPowerSeriesOnBall.fderiv_eq [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : fderiv 𝕜 f (x + y) = continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1) := (h.hasFDerivAt hy).fderiv #align has_fpower_series_on_ball.fderiv_eq HasFPowerSeriesOnBall.fderiv_eq /-- If a function has a power series on a ball, then so does its derivative. -/ theorem HasFPowerSeriesOnBall.fderiv [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x r := by refine .congr (f := fun z ↦ continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin (z - x) 1)) ?_ fun z hz ↦ ?_ · refine continuousMultilinearCurryFin1 𝕜 E F |>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFPowerSeriesOnBall ?_ simpa using ((p.hasFPowerSeriesOnBall_changeOrigin 1 (h.r_pos.trans_le h.r_le)).mono h.r_pos h.r_le).comp_sub x dsimp only rw [← h.fderiv_eq, add_sub_cancel] simpa only [edist_eq_coe_nnnorm_sub, EMetric.mem_ball] using hz #align has_fpower_series_on_ball.fderiv HasFPowerSeriesOnBall.fderiv /-- If a function is analytic on a set `s`, so is its Fréchet derivative. -/ theorem AnalyticOn.fderiv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (fderiv 𝕜 f) s := by intro y hy rcases h y hy with ⟨p, r, hp⟩ exact hp.fderiv.analyticAt #align analytic_on.fderiv AnalyticOn.fderiv /-- If a function is analytic on a set `s`, so are its successive Fréchet derivative. -/ theorem AnalyticOn.iteratedFDeriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) (n : ℕ) : AnalyticOn 𝕜 (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact ((continuousMultilinearCurryFin0 𝕜 E F).symm : F →L[𝕜] E[×0]→L[𝕜] F).comp_analyticOn h · rw [iteratedFDeriv_succ_eq_comp_left] -- Porting note: for reasons that I do not understand at all, `?g` cannot be inlined. convert ContinuousLinearMap.comp_analyticOn ?g IH.fderiv case g => exact ↑(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) ↦ E) F) simp #align analytic_on.iterated_fderiv AnalyticOn.iteratedFDeriv /-- An analytic function is infinitely differentiable. -/ theorem AnalyticOn.contDiffOn [CompleteSpace F] (h : AnalyticOn 𝕜 f s) {n : ℕ∞} : ContDiffOn 𝕜 n f s := let t := { x | AnalyticAt 𝕜 f x } suffices ContDiffOn 𝕜 n f t from this.mono h have H : AnalyticOn 𝕜 f t := fun _x hx ↦ hx have t_open : IsOpen t := isOpen_analyticAt 𝕜 f contDiffOn_of_continuousOn_differentiableOn (fun m _ ↦ (H.iteratedFDeriv m).continuousOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) (fun m _ ↦ (H.iteratedFDeriv m).differentiableOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) #align analytic_on.cont_diff_on AnalyticOn.contDiffOn theorem AnalyticAt.contDiffAt [CompleteSpace F] (h : AnalyticAt 𝕜 f x) {n : ℕ∞} : ContDiffAt 𝕜 n f x := by obtain ⟨s, hs, hf⟩ := h.exists_mem_nhds_analyticOn exact hf.contDiffOn.contDiffAt hs end fderiv section deriv variable {p : FormalMultilinearSeries 𝕜 𝕜 F} {r : ℝ≥0∞} variable {f : 𝕜 → F} {x : 𝕜} {s : Set 𝕜} protected theorem HasFPowerSeriesAt.hasStrictDerivAt (h : HasFPowerSeriesAt f p x) : HasStrictDerivAt f (p 1 fun _ => 1) x := h.hasStrictFDerivAt.hasStrictDerivAt #align has_fpower_series_at.has_strict_deriv_at HasFPowerSeriesAt.hasStrictDerivAt protected theorem HasFPowerSeriesAt.hasDerivAt (h : HasFPowerSeriesAt f p x) : HasDerivAt f (p 1 fun _ => 1) x := h.hasStrictDerivAt.hasDerivAt #align has_fpower_series_at.has_deriv_at HasFPowerSeriesAt.hasDerivAt protected theorem HasFPowerSeriesAt.deriv (h : HasFPowerSeriesAt f p x) : deriv f x = p 1 fun _ => 1 := h.hasDerivAt.deriv #align has_fpower_series_at.deriv HasFPowerSeriesAt.deriv /-- If a function is analytic on a set `s`, so is its derivative. -/ theorem AnalyticOn.deriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (deriv f) s := (ContinuousLinearMap.apply 𝕜 F (1 : 𝕜)).comp_analyticOn h.fderiv #align analytic_on.deriv AnalyticOn.deriv /-- If a function is analytic on a set `s`, so are its successive derivatives. -/ theorem AnalyticOn.iterated_deriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) (n : ℕ) : AnalyticOn 𝕜 (_root_.deriv^[n] f) s := by induction' n with n IH · exact h · simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv #align analytic_on.iterated_deriv AnalyticOn.iterated_deriv end deriv section fderiv variable {p : FormalMultilinearSeries 𝕜 E F} {r : ℝ≥0∞} {n : ℕ} variable {f : E → F} {x : E} {s : Set E} /-! The case of continuously polynomial functions. We get the same differentiability results as for analytic functions, but without the assumptions that `F` is complete. -/ theorem HasFiniteFPowerSeriesOnBall.differentiableOn (h : HasFiniteFPowerSeriesOnBall f p x n r) : DifferentiableOn 𝕜 f (EMetric.ball x r) := fun _ hy ↦ (h.cPolynomialAt_of_mem hy).analyticAt.differentiableWithinAt theorem HasFiniteFPowerSeriesOnBall.hasFDerivAt (h : HasFiniteFPowerSeriesOnBall f p x n r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1)) (x + y) := (h.changeOrigin hy).toHasFPowerSeriesOnBall.hasFPowerSeriesAt.hasFDerivAt theorem HasFiniteFPowerSeriesOnBall.fderiv_eq (h : HasFiniteFPowerSeriesOnBall f p x n r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : fderiv 𝕜 f (x + y) = continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1) := (h.hasFDerivAt hy).fderiv /-- If a function has a finite power series on a ball, then so does its derivative. -/ protected theorem HasFiniteFPowerSeriesOnBall.fderiv (h : HasFiniteFPowerSeriesOnBall f p x (n + 1) r) : HasFiniteFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x n r := by refine .congr (f := fun z ↦ continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin (z - x) 1)) ?_ fun z hz ↦ ?_ · refine continuousMultilinearCurryFin1 𝕜 E F |>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFiniteFPowerSeriesOnBall ?_ simpa using ((p.hasFiniteFPowerSeriesOnBall_changeOrigin 1 h.finite).mono h.r_pos le_top).comp_sub x dsimp only rw [← h.fderiv_eq, add_sub_cancel] simpa only [edist_eq_coe_nnnorm_sub, EMetric.mem_ball] using hz /-- If a function has a finite power series on a ball, then so does its derivative. This is a variant of `HasFiniteFPowerSeriesOnBall.fderiv` where the degree of `f` is `< n` and not `< n + 1`. -/ theorem HasFiniteFPowerSeriesOnBall.fderiv' (h : HasFiniteFPowerSeriesOnBall f p x n r) : HasFiniteFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x (n - 1) r := by obtain rfl | hn := eq_or_ne n 0 · rw [zero_tsub] refine HasFiniteFPowerSeriesOnBall.bound_zero_of_eq_zero (fun y hy ↦ ?_) h.r_pos fun n ↦ ?_ · rw [Filter.EventuallyEq.fderiv_eq (f := fun _ ↦ 0)] · rw [fderiv_const, Pi.zero_apply] · exact Filter.eventuallyEq_iff_exists_mem.mpr ⟨EMetric.ball x r, EMetric.isOpen_ball.mem_nhds hy, fun z hz ↦ by rw [h.eq_zero_of_bound_zero z hz]⟩ · apply ContinuousMultilinearMap.ext; intro a change (continuousMultilinearCurryFin1 𝕜 E F) (p.changeOriginSeries 1 n a) = 0 rw [p.changeOriginSeries_finite_of_finite h.finite 1 (Nat.zero_le _)] exact map_zero _ · rw [← Nat.succ_pred hn] at h exact h.fderiv /-- If a function is polynomial on a set `s`, so is its Fréchet derivative. -/ theorem CPolynomialOn.fderiv (h : CPolynomialOn 𝕜 f s) : CPolynomialOn 𝕜 (fderiv 𝕜 f) s := by intro y hy rcases h y hy with ⟨p, r, n, hp⟩ exact hp.fderiv'.cPolynomialAt /-- If a function is polynomial on a set `s`, so are its successive Fréchet derivative. -/ theorem CPolynomialOn.iteratedFDeriv (h : CPolynomialOn 𝕜 f s) (n : ℕ) : CPolynomialOn 𝕜 (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact ((continuousMultilinearCurryFin0 𝕜 E F).symm : F →L[𝕜] E[×0]→L[𝕜] F).comp_cPolynomialOn h · rw [iteratedFDeriv_succ_eq_comp_left] convert ContinuousLinearMap.comp_cPolynomialOn ?g IH.fderiv case g => exact ↑(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) ↦ E) F) simp /-- A polynomial function is infinitely differentiable. -/ theorem CPolynomialOn.contDiffOn (h : CPolynomialOn 𝕜 f s) {n : ℕ∞} : ContDiffOn 𝕜 n f s := let t := { x | CPolynomialAt 𝕜 f x } suffices ContDiffOn 𝕜 n f t from this.mono h have H : CPolynomialOn 𝕜 f t := fun _x hx ↦ hx have t_open : IsOpen t := isOpen_cPolynomialAt 𝕜 f contDiffOn_of_continuousOn_differentiableOn (fun m _ ↦ (H.iteratedFDeriv m).continuousOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) (fun m _ ↦ (H.iteratedFDeriv m).analyticOn.differentiableOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) theorem CPolynomialAt.contDiffAt (h : CPolynomialAt 𝕜 f x) {n : ℕ∞} : ContDiffAt 𝕜 n f x := let ⟨_, hs, hf⟩ := h.exists_mem_nhds_cPolynomialOn hf.contDiffOn.contDiffAt hs end fderiv section deriv variable {p : FormalMultilinearSeries 𝕜 𝕜 F} {r : ℝ≥0∞} variable {f : 𝕜 → F} {x : 𝕜} {s : Set 𝕜} /-- If a function is polynomial on a set `s`, so is its derivative. -/ protected theorem CPolynomialOn.deriv (h : CPolynomialOn 𝕜 f s) : CPolynomialOn 𝕜 (deriv f) s := (ContinuousLinearMap.apply 𝕜 F (1 : 𝕜)).comp_cPolynomialOn h.fderiv /-- If a function is polynomial on a set `s`, so are its successive derivatives. -/ theorem CPolynomialOn.iterated_deriv (h : CPolynomialOn 𝕜 f s) (n : ℕ) : CPolynomialOn 𝕜 (deriv^[n] f) s := by induction' n with n IH · exact h · simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv end deriv namespace ContinuousMultilinearMap variable {ι : Type*} {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] [Fintype ι] (f : ContinuousMultilinearMap 𝕜 E F) open FormalMultilinearSeries protected theorem hasFiniteFPowerSeriesOnBall : HasFiniteFPowerSeriesOnBall f f.toFormalMultilinearSeries 0 (Fintype.card ι + 1) ⊤ := .mk' (fun m hm ↦ dif_neg (Nat.succ_le_iff.mp hm).ne) ENNReal.zero_lt_top fun y _ ↦ by rw [Finset.sum_eq_single_of_mem _ (Finset.self_mem_range_succ _), zero_add] · rw [toFormalMultilinearSeries, dif_pos rfl]; rfl · intro m _ ne; rw [toFormalMultilinearSeries, dif_neg ne.symm]; rfl theorem changeOriginSeries_support {k l : ℕ} (h : k + l ≠ Fintype.card ι) : f.toFormalMultilinearSeries.changeOriginSeries k l = 0 := Finset.sum_eq_zero fun _ _ ↦ by simp_rw [FormalMultilinearSeries.changeOriginSeriesTerm, toFormalMultilinearSeries, dif_neg h.symm, LinearIsometryEquiv.map_zero] variable {n : ℕ∞} (x : ∀ i, E i) open Finset in theorem changeOrigin_toFormalMultilinearSeries [DecidableEq ι] : continuousMultilinearCurryFin1 𝕜 (∀ i, E i) F (f.toFormalMultilinearSeries.changeOrigin x 1) = f.linearDeriv x := by ext y rw [continuousMultilinearCurryFin1_apply, linearDeriv_apply, changeOrigin, FormalMultilinearSeries.sum] cases isEmpty_or_nonempty ι · have (l) : 1 + l ≠ Fintype.card ι := by rw [add_comm, Fintype.card_eq_zero]; exact Nat.succ_ne_zero _ simp_rw [Fintype.sum_empty, changeOriginSeries_support _ (this _), zero_apply _, tsum_zero]; rfl rw [tsum_eq_single (Fintype.card ι - 1), changeOriginSeries]; swap · intro m hm rw [Ne, eq_tsub_iff_add_eq_of_le (by exact Fintype.card_pos), add_comm] at hm rw [f.changeOriginSeries_support hm, zero_apply] rw [sum_apply, ContinuousMultilinearMap.sum_apply, Fin.snoc_zero] simp_rw [changeOriginSeriesTerm_apply] refine (Fintype.sum_bijective (?_ ∘ Fintype.equivFinOfCardEq (Nat.add_sub_of_le Fintype.card_pos).symm) (.comp ?_ <| Equiv.bijective _) _ _ fun i ↦ ?_).symm · exact (⟨{·}ᶜ, by rw [card_compl, Fintype.card_fin, card_singleton, Nat.add_sub_cancel_left]⟩) · use fun _ _ ↦ (singleton_injective <| compl_injective <| Subtype.ext_iff.mp ·) intro ⟨s, hs⟩ have h : sᶜ.card = 1 := by rw [card_compl, hs, Fintype.card_fin, Nat.add_sub_cancel] obtain ⟨a, ha⟩ := card_eq_one.mp h exact ⟨a, Subtype.ext (compl_eq_comm.mp ha)⟩ rw [Function.comp_apply, Subtype.coe_mk, compl_singleton, piecewise_erase_univ, toFormalMultilinearSeries, dif_pos (Nat.add_sub_of_le Fintype.card_pos).symm] simp_rw [domDomCongr_apply, compContinuousLinearMap_apply, ContinuousLinearMap.proj_apply, Function.update_apply, (Equiv.injective _).eq_iff, ite_apply] congr; ext j obtain rfl | hj := eq_or_ne j i · rw [Function.update_same, if_pos rfl] · rw [Function.update_noteq hj, if_neg hj] protected theorem hasFDerivAt [DecidableEq ι] : HasFDerivAt f (f.linearDeriv x) x := by rw [← changeOrigin_toFormalMultilinearSeries] convert f.hasFiniteFPowerSeriesOnBall.hasFDerivAt (y := x) ENNReal.coe_lt_top rw [zero_add] /-- Technical lemma used in the proof of `hasFTaylorSeriesUpTo_iteratedFDeriv`, to compare sums over embedding of `Fin k` and `Fin (k + 1)`. -/ private lemma _root_.Equiv.succ_embeddingFinSucc_fst_symm_apply {ι : Type*} [DecidableEq ι] {n : ℕ} (e : Fin (n+1) ↪ ι) {k : ι} (h'k : k ∈ Set.range (Equiv.embeddingFinSucc n ι e).1) (hk : k ∈ Set.range e) : Fin.succ ((Equiv.embeddingFinSucc n ι e).1.toEquivRange.symm ⟨k, h'k⟩) = e.toEquivRange.symm ⟨k, hk⟩ := by rcases hk with ⟨j, rfl⟩ have hj : j ≠ 0 := by rintro rfl simp at h'k simp only [Function.Embedding.toEquivRange_symm_apply_self] have : e j = (Equiv.embeddingFinSucc n ι e).1 (Fin.pred j hj) := by simp simp_rw [this] simp [-Equiv.embeddingFinSucc_fst] /-- A continuous multilinear function `f` admits a Taylor series, whose successive terms are given by `f.iteratedFDeriv n`. This is the point of the definition of `f.iteratedFDeriv`. -/ theorem hasFTaylorSeriesUpTo_iteratedFDeriv : HasFTaylorSeriesUpTo ⊤ f (fun v n ↦ f.iteratedFDeriv n v) := by classical constructor · simp [ContinuousMultilinearMap.iteratedFDeriv] · rintro n - x suffices H : curryLeft (f.iteratedFDeriv (Nat.succ n) x) = (∑ e : Fin n ↪ ι, ((iteratedFDerivComponent f e.toEquivRange).linearDeriv (Pi.compRightL 𝕜 _ Subtype.val x)) ∘L (Pi.compRightL 𝕜 _ Subtype.val)) by have A : HasFDerivAt (f.iteratedFDeriv n) (∑ e : Fin n ↪ ι, ((iteratedFDerivComponent f e.toEquivRange).linearDeriv (Pi.compRightL 𝕜 _ Subtype.val x)) ∘L (Pi.compRightL 𝕜 _ Subtype.val)) x := by apply HasFDerivAt.sum (fun s _hs ↦ ?_) exact (ContinuousMultilinearMap.hasFDerivAt _ _).comp x (ContinuousLinearMap.hasFDerivAt _) rwa [← H] at A ext v m simp only [ContinuousMultilinearMap.iteratedFDeriv, curryLeft_apply, sum_apply, iteratedFDerivComponent_apply, Finset.univ_sigma_univ, Pi.compRightL_apply, ContinuousLinearMap.coe_sum', ContinuousLinearMap.coe_comp', Finset.sum_apply, Function.comp_apply, linearDeriv_apply, Finset.sum_sigma'] rw [← (Equiv.embeddingFinSucc n ι).sum_comp] congr with e congr with k by_cases hke : k ∈ Set.range e · simp only [hke, ↓reduceDite] split_ifs with hkf · simp only [← Equiv.succ_embeddingFinSucc_fst_symm_apply e hkf hke, Fin.cons_succ] · obtain rfl : k = e 0 := by rcases hke with ⟨j, rfl⟩ simpa using hkf simp only [Function.Embedding.toEquivRange_symm_apply_self, Fin.cons_zero, Function.update, Pi.compRightL_apply] split_ifs with h · congr! · exfalso apply h simp_rw [← Equiv.embeddingFinSucc_snd e] · have hkf : k ∉ Set.range (Equiv.embeddingFinSucc n ι e).1 := by contrapose! hke rw [Equiv.embeddingFinSucc_fst] at hke exact Set.range_comp_subset_range _ _ hke simp only [hke, hkf, ↓reduceDite, Pi.compRightL, ContinuousLinearMap.coe_mk', LinearMap.coe_mk, AddHom.coe_mk] rw [Function.update_noteq] contrapose! hke rw [show k = _ from Subtype.ext_iff_val.1 hke, Equiv.embeddingFinSucc_snd e] exact Set.mem_range_self _ · rintro n - apply continuous_finset_sum _ (fun e _ ↦ ?_) exact (ContinuousMultilinearMap.coe_continuous _).comp (ContinuousLinearMap.continuous _) theorem iteratedFDeriv_eq (n : ℕ) : iteratedFDeriv 𝕜 n f = f.iteratedFDeriv n := funext fun x ↦ (f.hasFTaylorSeriesUpTo_iteratedFDeriv.eq_iteratedFDeriv (m := n) le_top x).symm
Mathlib/Analysis/Calculus/FDeriv/Analytic.lean
426
430
theorem norm_iteratedFDeriv_le (n : ℕ) (x : (i : ι) → E i) : ‖iteratedFDeriv 𝕜 n f x‖ ≤ Nat.descFactorial (Fintype.card ι) n * ‖f‖ * ‖x‖ ^ (Fintype.card ι - n) := by
rw [f.iteratedFDeriv_eq] exact f.norm_iteratedFDeriv_le' n x
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Topology.Order.MonotoneContinuity import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.Instances.NNReal import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Order.T5 #align_import topology.instances.ennreal from "leanprover-community/mathlib"@"ec4b2eeb50364487f80421c0b4c41328a611f30d" /-! # Topology on extended non-negative reals -/ noncomputable section open Set Filter Metric Function open scoped Classical Topology ENNReal NNReal Filter variable {α : Type*} {β : Type*} {γ : Type*} namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞} section TopologicalSpace open TopologicalSpace /-- Topology on `ℝ≥0∞`. Note: this is different from the `EMetricSpace` topology. The `EMetricSpace` topology has `IsOpen {∞}`, while this topology doesn't have singleton elements. -/ instance : TopologicalSpace ℝ≥0∞ := Preorder.topology ℝ≥0∞ instance : OrderTopology ℝ≥0∞ := ⟨rfl⟩ -- short-circuit type class inference instance : T2Space ℝ≥0∞ := inferInstance instance : T5Space ℝ≥0∞ := inferInstance instance : T4Space ℝ≥0∞ := inferInstance instance : SecondCountableTopology ℝ≥0∞ := orderIsoUnitIntervalBirational.toHomeomorph.embedding.secondCountableTopology instance : MetrizableSpace ENNReal := orderIsoUnitIntervalBirational.toHomeomorph.embedding.metrizableSpace theorem embedding_coe : Embedding ((↑) : ℝ≥0 → ℝ≥0∞) := coe_strictMono.embedding_of_ordConnected <| by rw [range_coe']; exact ordConnected_Iio #align ennreal.embedding_coe ENNReal.embedding_coe theorem isOpen_ne_top : IsOpen { a : ℝ≥0∞ | a ≠ ∞ } := isOpen_ne #align ennreal.is_open_ne_top ENNReal.isOpen_ne_top theorem isOpen_Ico_zero : IsOpen (Ico 0 b) := by rw [ENNReal.Ico_eq_Iio] exact isOpen_Iio #align ennreal.is_open_Ico_zero ENNReal.isOpen_Ico_zero theorem openEmbedding_coe : OpenEmbedding ((↑) : ℝ≥0 → ℝ≥0∞) := ⟨embedding_coe, by rw [range_coe']; exact isOpen_Iio⟩ #align ennreal.open_embedding_coe ENNReal.openEmbedding_coe theorem coe_range_mem_nhds : range ((↑) : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) := IsOpen.mem_nhds openEmbedding_coe.isOpen_range <| mem_range_self _ #align ennreal.coe_range_mem_nhds ENNReal.coe_range_mem_nhds @[norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {a : ℝ≥0} : Tendsto (fun a => (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm #align ennreal.tendsto_coe ENNReal.tendsto_coe theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ≥0∞) := embedding_coe.continuous #align ennreal.continuous_coe ENNReal.continuous_coe theorem continuous_coe_iff {α} [TopologicalSpace α] {f : α → ℝ≥0} : (Continuous fun a => (f a : ℝ≥0∞)) ↔ Continuous f := embedding_coe.continuous_iff.symm #align ennreal.continuous_coe_iff ENNReal.continuous_coe_iff theorem nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map (↑) := (openEmbedding_coe.map_nhds_eq r).symm #align ennreal.nhds_coe ENNReal.nhds_coe theorem tendsto_nhds_coe_iff {α : Type*} {l : Filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} : Tendsto f (𝓝 ↑x) l ↔ Tendsto (f ∘ (↑) : ℝ≥0 → α) (𝓝 x) l := by rw [nhds_coe, tendsto_map'_iff] #align ennreal.tendsto_nhds_coe_iff ENNReal.tendsto_nhds_coe_iff theorem continuousAt_coe_iff {α : Type*} [TopologicalSpace α] {x : ℝ≥0} {f : ℝ≥0∞ → α} : ContinuousAt f ↑x ↔ ContinuousAt (f ∘ (↑) : ℝ≥0 → α) x := tendsto_nhds_coe_iff #align ennreal.continuous_at_coe_iff ENNReal.continuousAt_coe_iff theorem nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map fun p : ℝ≥0 × ℝ≥0 => (↑p.1, ↑p.2) := ((openEmbedding_coe.prod openEmbedding_coe).map_nhds_eq (r, p)).symm #align ennreal.nhds_coe_coe ENNReal.nhds_coe_coe theorem continuous_ofReal : Continuous ENNReal.ofReal := (continuous_coe_iff.2 continuous_id).comp continuous_real_toNNReal #align ennreal.continuous_of_real ENNReal.continuous_ofReal theorem tendsto_ofReal {f : Filter α} {m : α → ℝ} {a : ℝ} (h : Tendsto m f (𝓝 a)) : Tendsto (fun a => ENNReal.ofReal (m a)) f (𝓝 (ENNReal.ofReal a)) := (continuous_ofReal.tendsto a).comp h #align ennreal.tendsto_of_real ENNReal.tendsto_ofReal theorem tendsto_toNNReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toNNReal (𝓝 a) (𝓝 a.toNNReal) := by lift a to ℝ≥0 using ha rw [nhds_coe, tendsto_map'_iff] exact tendsto_id #align ennreal.tendsto_to_nnreal ENNReal.tendsto_toNNReal theorem eventuallyEq_of_toReal_eventuallyEq {l : Filter α} {f g : α → ℝ≥0∞} (hfi : ∀ᶠ x in l, f x ≠ ∞) (hgi : ∀ᶠ x in l, g x ≠ ∞) (hfg : (fun x => (f x).toReal) =ᶠ[l] fun x => (g x).toReal) : f =ᶠ[l] g := by filter_upwards [hfi, hgi, hfg] with _ hfx hgx _ rwa [← ENNReal.toReal_eq_toReal hfx hgx] #align ennreal.eventually_eq_of_to_real_eventually_eq ENNReal.eventuallyEq_of_toReal_eventuallyEq theorem continuousOn_toNNReal : ContinuousOn ENNReal.toNNReal { a | a ≠ ∞ } := fun _a ha => ContinuousAt.continuousWithinAt (tendsto_toNNReal ha) #align ennreal.continuous_on_to_nnreal ENNReal.continuousOn_toNNReal theorem tendsto_toReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toReal (𝓝 a) (𝓝 a.toReal) := NNReal.tendsto_coe.2 <| tendsto_toNNReal ha #align ennreal.tendsto_to_real ENNReal.tendsto_toReal lemma continuousOn_toReal : ContinuousOn ENNReal.toReal { a | a ≠ ∞ } := NNReal.continuous_coe.comp_continuousOn continuousOn_toNNReal lemma continuousAt_toReal (hx : x ≠ ∞) : ContinuousAt ENNReal.toReal x := continuousOn_toReal.continuousAt (isOpen_ne_top.mem_nhds_iff.mpr hx) /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def neTopHomeomorphNNReal : { a | a ≠ ∞ } ≃ₜ ℝ≥0 where toEquiv := neTopEquivNNReal continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toNNReal continuous_invFun := continuous_coe.subtype_mk _ #align ennreal.ne_top_homeomorph_nnreal ENNReal.neTopHomeomorphNNReal /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def ltTopHomeomorphNNReal : { a | a < ∞ } ≃ₜ ℝ≥0 := by refine (Homeomorph.setCongr ?_).trans neTopHomeomorphNNReal simp only [mem_setOf_eq, lt_top_iff_ne_top] #align ennreal.lt_top_homeomorph_nnreal ENNReal.ltTopHomeomorphNNReal theorem nhds_top : 𝓝 ∞ = ⨅ (a) (_ : a ≠ ∞), 𝓟 (Ioi a) := nhds_top_order.trans <| by simp [lt_top_iff_ne_top, Ioi] #align ennreal.nhds_top ENNReal.nhds_top theorem nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi ↑r) := nhds_top.trans <| iInf_ne_top _ #align ennreal.nhds_top' ENNReal.nhds_top' theorem nhds_top_basis : (𝓝 ∞).HasBasis (fun a => a < ∞) fun a => Ioi a := _root_.nhds_top_basis #align ennreal.nhds_top_basis ENNReal.nhds_top_basis theorem tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a := by simp only [nhds_top', tendsto_iInf, tendsto_principal, mem_Ioi] #align ennreal.tendsto_nhds_top_iff_nnreal ENNReal.tendsto_nhds_top_iff_nnreal theorem tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a := tendsto_nhds_top_iff_nnreal.trans ⟨fun h n => by simpa only [ENNReal.coe_natCast] using h n, fun h x => let ⟨n, hn⟩ := exists_nat_gt x (h n).mono fun y => lt_trans <| by rwa [← ENNReal.coe_natCast, coe_lt_coe]⟩ #align ennreal.tendsto_nhds_top_iff_nat ENNReal.tendsto_nhds_top_iff_nat theorem tendsto_nhds_top {m : α → ℝ≥0∞} {f : Filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : Tendsto m f (𝓝 ∞) := tendsto_nhds_top_iff_nat.2 h #align ennreal.tendsto_nhds_top ENNReal.tendsto_nhds_top theorem tendsto_nat_nhds_top : Tendsto (fun n : ℕ => ↑n) atTop (𝓝 ∞) := tendsto_nhds_top fun n => mem_atTop_sets.2 ⟨n + 1, fun _m hm => mem_setOf.2 <| Nat.cast_lt.2 <| Nat.lt_of_succ_le hm⟩ #align ennreal.tendsto_nat_nhds_top ENNReal.tendsto_nat_nhds_top @[simp, norm_cast] theorem tendsto_coe_nhds_top {f : α → ℝ≥0} {l : Filter α} : Tendsto (fun x => (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ Tendsto f l atTop := by rw [tendsto_nhds_top_iff_nnreal, atTop_basis_Ioi.tendsto_right_iff]; simp #align ennreal.tendsto_coe_nhds_top ENNReal.tendsto_coe_nhds_top theorem tendsto_ofReal_atTop : Tendsto ENNReal.ofReal atTop (𝓝 ∞) := tendsto_coe_nhds_top.2 tendsto_real_toNNReal_atTop #align ennreal.tendsto_of_real_at_top ENNReal.tendsto_ofReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅ (a) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp [pos_iff_ne_zero, Iio] #align ennreal.nhds_zero ENNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) fun a => Iio a := nhds_bot_basis #align ennreal.nhds_zero_basis ENNReal.nhds_zero_basis theorem nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) Iic := nhds_bot_basis_Iic #align ennreal.nhds_zero_basis_Iic ENNReal.nhds_zero_basis_Iic -- Porting note (#11215): TODO: add a TC for `≠ ∞`? @[instance] theorem nhdsWithin_Ioi_coe_neBot {r : ℝ≥0} : (𝓝[>] (r : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_self_neBot' ⟨∞, ENNReal.coe_lt_top⟩ #align ennreal.nhds_within_Ioi_coe_ne_bot ENNReal.nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_zero_neBot : (𝓝[>] (0 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot #align ennreal.nhds_within_Ioi_zero_ne_bot ENNReal.nhdsWithin_Ioi_zero_neBot @[instance] theorem nhdsWithin_Ioi_one_neBot : (𝓝[>] (1 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_nat_neBot (n : ℕ) : (𝓝[>] (n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_ofNat_nebot (n : ℕ) [n.AtLeastTwo] : (𝓝[>] (OfNat.ofNat n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Iio_neBot [NeZero x] : (𝓝[<] x).NeBot := nhdsWithin_Iio_self_neBot' ⟨0, NeZero.pos x⟩ /-- Closed intervals `Set.Icc (x - ε) (x + ε)`, `ε ≠ 0`, form a basis of neighborhoods of an extended nonnegative real number `x ≠ ∞`. We use `Set.Icc` instead of `Set.Ioo` because this way the statement works for `x = 0`. -/ theorem hasBasis_nhds_of_ne_top' (xt : x ≠ ∞) : (𝓝 x).HasBasis (· ≠ 0) (fun ε => Icc (x - ε) (x + ε)) := by rcases (zero_le x).eq_or_gt with rfl | x0 · simp_rw [zero_tsub, zero_add, ← bot_eq_zero, Icc_bot, ← bot_lt_iff_ne_bot] exact nhds_bot_basis_Iic · refine (nhds_basis_Ioo' ⟨_, x0⟩ ⟨_, xt.lt_top⟩).to_hasBasis ?_ fun ε ε0 => ?_ · rintro ⟨a, b⟩ ⟨ha, hb⟩ rcases exists_between (tsub_pos_of_lt ha) with ⟨ε, ε0, hε⟩ rcases lt_iff_exists_add_pos_lt.1 hb with ⟨δ, δ0, hδ⟩ refine ⟨min ε δ, (lt_min ε0 (coe_pos.2 δ0)).ne', Icc_subset_Ioo ?_ ?_⟩ · exact lt_tsub_comm.2 ((min_le_left _ _).trans_lt hε) · exact (add_le_add_left (min_le_right _ _) _).trans_lt hδ · exact ⟨(x - ε, x + ε), ⟨ENNReal.sub_lt_self xt x0.ne' ε0, lt_add_right xt ε0⟩, Ioo_subset_Icc_self⟩ theorem hasBasis_nhds_of_ne_top (xt : x ≠ ∞) : (𝓝 x).HasBasis (0 < ·) (fun ε => Icc (x - ε) (x + ε)) := by simpa only [pos_iff_ne_zero] using hasBasis_nhds_of_ne_top' xt theorem Icc_mem_nhds (xt : x ≠ ∞) (ε0 : ε ≠ 0) : Icc (x - ε) (x + ε) ∈ 𝓝 x := (hasBasis_nhds_of_ne_top' xt).mem_of_mem ε0 #align ennreal.Icc_mem_nhds ENNReal.Icc_mem_nhds theorem nhds_of_ne_top (xt : x ≠ ∞) : 𝓝 x = ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) := (hasBasis_nhds_of_ne_top xt).eq_biInf #align ennreal.nhds_of_ne_top ENNReal.nhds_of_ne_top theorem biInf_le_nhds : ∀ x : ℝ≥0∞, ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) ≤ 𝓝 x | ∞ => iInf₂_le_of_le 1 one_pos <| by simpa only [← coe_one, top_sub_coe, top_add, Icc_self, principal_singleton] using pure_le_nhds _ | (x : ℝ≥0) => (nhds_of_ne_top coe_ne_top).ge -- Porting note (#10756): new lemma protected theorem tendsto_nhds_of_Icc {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε)) : Tendsto u f (𝓝 a) := by refine Tendsto.mono_right ?_ (biInf_le_nhds _) simpa only [tendsto_iInf, tendsto_principal] /-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_iInf, tendsto_principal] #align ennreal.tendsto_nhds ENNReal.tendsto_nhds protected theorem tendsto_nhds_zero {f : Filter α} {u : α → ℝ≥0∞} : Tendsto u f (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ≤ ε := nhds_zero_basis_Iic.tendsto_right_iff #align ennreal.tendsto_nhds_zero ENNReal.tendsto_nhds_zero protected theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto f atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ∈ Icc (a - ε) (a + ε) := .trans (atTop_basis.tendsto_iff (hasBasis_nhds_of_ne_top ha)) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top ENNReal.tendsto_atTop instance : ContinuousAdd ℝ≥0∞ := by refine ⟨continuous_iff_continuousAt.2 ?_⟩ rintro ⟨_ | a, b⟩ · exact tendsto_nhds_top_mono' continuousAt_fst fun p => le_add_right le_rfl rcases b with (_ | b) · exact tendsto_nhds_top_mono' continuousAt_snd fun p => le_add_left le_rfl simp only [ContinuousAt, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (· ∘ ·), tendsto_coe, tendsto_add] protected theorem tendsto_atTop_zero [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} : Tendsto f atTop (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε := .trans (atTop_basis.tendsto_iff nhds_zero_basis_Iic) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top_zero ENNReal.tendsto_atTop_zero theorem tendsto_sub : ∀ {a b : ℝ≥0∞}, (a ≠ ∞ ∨ b ≠ ∞) → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) (𝓝 (a, b)) (𝓝 (a - b)) | ∞, ∞, h => by simp only [ne_eq, not_true_eq_false, or_self] at h | ∞, (b : ℝ≥0), _ => by rw [top_sub_coe, tendsto_nhds_top_iff_nnreal] refine fun x => ((lt_mem_nhds <| @coe_lt_top (b + 1 + x)).prod_nhds (ge_mem_nhds <| coe_lt_coe.2 <| lt_add_one b)).mono fun y hy => ?_ rw [lt_tsub_iff_left] calc y.2 + x ≤ ↑(b + 1) + x := add_le_add_right hy.2 _ _ < y.1 := hy.1 | (a : ℝ≥0), ∞, _ => by rw [sub_top] refine (tendsto_pure.2 ?_).mono_right (pure_le_nhds _) exact ((gt_mem_nhds <| coe_lt_coe.2 <| lt_add_one a).prod_nhds (lt_mem_nhds <| @coe_lt_top (a + 1))).mono fun x hx => tsub_eq_zero_iff_le.2 (hx.1.trans hx.2).le | (a : ℝ≥0), (b : ℝ≥0), _ => by simp only [nhds_coe_coe, tendsto_map'_iff, ← ENNReal.coe_sub, (· ∘ ·), tendsto_coe] exact continuous_sub.tendsto (a, b) #align ennreal.tendsto_sub ENNReal.tendsto_sub protected theorem Tendsto.sub {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (hmb : Tendsto mb f (𝓝 b)) (h : a ≠ ∞ ∨ b ≠ ∞) : Tendsto (fun a => ma a - mb a) f (𝓝 (a - b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a - b)) from Tendsto.comp (ENNReal.tendsto_sub h) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.sub ENNReal.Tendsto.sub protected theorem tendsto_mul (ha : a ≠ 0 ∨ b ≠ ∞) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := by have ht : ∀ b : ℝ≥0∞, b ≠ 0 → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (∞, b)) (𝓝 ∞) := fun b hb => by refine tendsto_nhds_top_iff_nnreal.2 fun n => ?_ rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩ have : ∀ᶠ c : ℝ≥0∞ × ℝ≥0∞ in 𝓝 (∞, b), ↑n / ↑ε < c.1 ∧ ↑ε < c.2 := (lt_mem_nhds <| div_lt_top coe_ne_top hε.ne').prod_nhds (lt_mem_nhds hεb) refine this.mono fun c hc => ?_ exact (ENNReal.div_mul_cancel hε.ne' coe_ne_top).symm.trans_lt (mul_lt_mul hc.1 hc.2) induction a with | top => simp only [ne_eq, or_false, not_true_eq_false] at hb; simp [ht b hb, top_mul hb] | coe a => induction b with | top => simp only [ne_eq, or_false, not_true_eq_false] at ha simpa [(· ∘ ·), mul_comm, mul_top ha] using (ht a ha).comp (continuous_swap.tendsto (ofNNReal a, ∞)) | coe b => simp only [nhds_coe_coe, ← coe_mul, tendsto_coe, tendsto_map'_iff, (· ∘ ·), tendsto_mul] #align ennreal.tendsto_mul ENNReal.tendsto_mul protected theorem Tendsto.mul {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun a => ma a * mb a) f (𝓝 (a * b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a * b)) from Tendsto.comp (ENNReal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.mul ENNReal.Tendsto.mul theorem _root_.ContinuousOn.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₁ : ∀ x ∈ s, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x ∈ s, g x ≠ 0 ∨ f x ≠ ∞) : ContinuousOn (fun x => f x * g x) s := fun x hx => ENNReal.Tendsto.mul (hf x hx) (h₁ x hx) (hg x hx) (h₂ x hx) #align continuous_on.ennreal_mul ContinuousOn.ennreal_mul theorem _root_.Continuous.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} (hf : Continuous f) (hg : Continuous g) (h₁ : ∀ x, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x, g x ≠ 0 ∨ f x ≠ ∞) : Continuous fun x => f x * g x := continuous_iff_continuousAt.2 fun x => ENNReal.Tendsto.mul hf.continuousAt (h₁ x) hg.continuousAt (h₂ x) #align continuous.ennreal_mul Continuous.ennreal_mul protected theorem Tendsto.const_mul {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun b => a * m b) f (𝓝 (a * b)) := by_cases (fun (this : a = 0) => by simp [this, tendsto_const_nhds]) fun ha : a ≠ 0 => ENNReal.Tendsto.mul tendsto_const_nhds (Or.inl ha) hm hb #align ennreal.tendsto.const_mul ENNReal.Tendsto.const_mul protected theorem Tendsto.mul_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) : Tendsto (fun x => m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ENNReal.Tendsto.const_mul hm ha #align ennreal.tendsto.mul_const ENNReal.Tendsto.mul_const theorem tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : Filter α} {a : ι → ℝ≥0∞} (s : Finset ι) (h : ∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞) : Tendsto (fun b => ∏ c ∈ s, f c b) x (𝓝 (∏ c ∈ s, a c)) := by induction' s using Finset.induction with a s has IH · simp [tendsto_const_nhds] simp only [Finset.prod_insert has] apply Tendsto.mul (h _ (Finset.mem_insert_self _ _)) · right exact (prod_lt_top fun i hi => h' _ (Finset.mem_insert_of_mem hi)).ne · exact IH (fun i hi => h _ (Finset.mem_insert_of_mem hi)) fun i hi => h' _ (Finset.mem_insert_of_mem hi) · exact Or.inr (h' _ (Finset.mem_insert_self _ _)) #align ennreal.tendsto_finset_prod_of_ne_top ENNReal.tendsto_finset_prod_of_ne_top protected theorem continuousAt_const_mul {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (a * ·) b := Tendsto.const_mul tendsto_id h.symm #align ennreal.continuous_at_const_mul ENNReal.continuousAt_const_mul protected theorem continuousAt_mul_const {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (fun x => x * a) b := Tendsto.mul_const tendsto_id h.symm #align ennreal.continuous_at_mul_const ENNReal.continuousAt_mul_const protected theorem continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous (a * ·) := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_const_mul (Or.inl ha) #align ennreal.continuous_const_mul ENNReal.continuous_const_mul protected theorem continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous fun x => x * a := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_mul_const (Or.inl ha) #align ennreal.continuous_mul_const ENNReal.continuous_mul_const protected theorem continuous_div_const (c : ℝ≥0∞) (c_ne_zero : c ≠ 0) : Continuous fun x : ℝ≥0∞ => x / c := by simp_rw [div_eq_mul_inv, continuous_iff_continuousAt] intro x exact ENNReal.continuousAt_mul_const (Or.intro_left _ (inv_ne_top.mpr c_ne_zero)) #align ennreal.continuous_div_const ENNReal.continuous_div_const @[continuity] theorem continuous_pow (n : ℕ) : Continuous fun a : ℝ≥0∞ => a ^ n := by induction' n with n IH · simp [continuous_const] simp_rw [pow_add, pow_one, continuous_iff_continuousAt] intro x refine ENNReal.Tendsto.mul (IH.tendsto _) ?_ tendsto_id ?_ <;> by_cases H : x = 0 · simp only [H, zero_ne_top, Ne, or_true_iff, not_false_iff] · exact Or.inl fun h => H (pow_eq_zero h) · simp only [H, pow_eq_top_iff, zero_ne_top, false_or_iff, eq_self_iff_true, not_true, Ne, not_false_iff, false_and_iff] · simp only [H, true_or_iff, Ne, not_false_iff] #align ennreal.continuous_pow ENNReal.continuous_pow theorem continuousOn_sub : ContinuousOn (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) { p : ℝ≥0∞ × ℝ≥0∞ | p ≠ ⟨∞, ∞⟩ } := by rw [ContinuousOn] rintro ⟨x, y⟩ hp simp only [Ne, Set.mem_setOf_eq, Prod.mk.inj_iff] at hp exact tendsto_nhdsWithin_of_tendsto_nhds (tendsto_sub (not_and_or.mp hp)) #align ennreal.continuous_on_sub ENNReal.continuousOn_sub theorem continuous_sub_left {a : ℝ≥0∞} (a_ne_top : a ≠ ∞) : Continuous (a - ·) := by change Continuous (Function.uncurry Sub.sub ∘ (a, ·)) refine continuousOn_sub.comp_continuous (Continuous.Prod.mk a) fun x => ?_ simp only [a_ne_top, Ne, mem_setOf_eq, Prod.mk.inj_iff, false_and_iff, not_false_iff] #align ennreal.continuous_sub_left ENNReal.continuous_sub_left theorem continuous_nnreal_sub {a : ℝ≥0} : Continuous fun x : ℝ≥0∞ => (a : ℝ≥0∞) - x := continuous_sub_left coe_ne_top #align ennreal.continuous_nnreal_sub ENNReal.continuous_nnreal_sub theorem continuousOn_sub_left (a : ℝ≥0∞) : ContinuousOn (a - ·) { x : ℝ≥0∞ | x ≠ ∞ } := by rw [show (fun x => a - x) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨a, x⟩ by rfl] apply ContinuousOn.comp continuousOn_sub (Continuous.continuousOn (Continuous.Prod.mk a)) rintro _ h (_ | _) exact h none_eq_top #align ennreal.continuous_on_sub_left ENNReal.continuousOn_sub_left theorem continuous_sub_right (a : ℝ≥0∞) : Continuous fun x : ℝ≥0∞ => x - a := by by_cases a_infty : a = ∞ · simp [a_infty, continuous_const] · rw [show (fun x => x - a) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨x, a⟩ by rfl] apply ContinuousOn.comp_continuous continuousOn_sub (continuous_id'.prod_mk continuous_const) intro x simp only [a_infty, Ne, mem_setOf_eq, Prod.mk.inj_iff, and_false_iff, not_false_iff] #align ennreal.continuous_sub_right ENNReal.continuous_sub_right protected theorem Tendsto.pow {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} {n : ℕ} (hm : Tendsto m f (𝓝 a)) : Tendsto (fun x => m x ^ n) f (𝓝 (a ^ n)) := ((continuous_pow n).tendsto a).comp hm #align ennreal.tendsto.pow ENNReal.Tendsto.pow theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := by have : Tendsto (· * x) (𝓝[<] 1) (𝓝 (1 * x)) := (ENNReal.continuousAt_mul_const (Or.inr one_ne_zero)).mono_left inf_le_left rw [one_mul] at this exact le_of_tendsto this (eventually_nhdsWithin_iff.2 <| eventually_of_forall h) #align ennreal.le_of_forall_lt_one_mul_le ENNReal.le_of_forall_lt_one_mul_le theorem iInf_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, a * f i = a * ⨅ i, f i := by by_cases H : a = ∞ ∧ ⨅ i, f i = 0 · rcases h H.1 H.2 with ⟨i, hi⟩ rw [H.2, mul_zero, ← bot_eq_zero, iInf_eq_bot] exact fun b hb => ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ · rw [not_and_or] at H cases isEmpty_or_nonempty ι · rw [iInf_of_empty, iInf_of_empty, mul_top] exact mt h0 (not_nonempty_iff.2 ‹_›) · exact (ENNReal.mul_left_mono.map_iInf_of_continuousAt' (ENNReal.continuousAt_const_mul H)).symm #align ennreal.infi_mul_left' ENNReal.iInf_mul_left' theorem iInf_mul_left {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, a * f i = a * ⨅ i, f i := iInf_mul_left' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_left ENNReal.iInf_mul_left theorem iInf_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, f i * a = (⨅ i, f i) * a := by simpa only [mul_comm a] using iInf_mul_left' h h0 #align ennreal.infi_mul_right' ENNReal.iInf_mul_right' theorem iInf_mul_right {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, f i * a = (⨅ i, f i) * a := iInf_mul_right' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_right ENNReal.iInf_mul_right theorem inv_map_iInf {ι : Sort*} {x : ι → ℝ≥0∞} : (iInf x)⁻¹ = ⨆ i, (x i)⁻¹ := OrderIso.invENNReal.map_iInf x #align ennreal.inv_map_infi ENNReal.inv_map_iInf theorem inv_map_iSup {ι : Sort*} {x : ι → ℝ≥0∞} : (iSup x)⁻¹ = ⨅ i, (x i)⁻¹ := OrderIso.invENNReal.map_iSup x #align ennreal.inv_map_supr ENNReal.inv_map_iSup theorem inv_limsup {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (limsup x l)⁻¹ = liminf (fun i => (x i)⁻¹) l := OrderIso.invENNReal.limsup_apply #align ennreal.inv_limsup ENNReal.inv_limsup theorem inv_liminf {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (liminf x l)⁻¹ = limsup (fun i => (x i)⁻¹) l := OrderIso.invENNReal.liminf_apply #align ennreal.inv_liminf ENNReal.inv_liminf instance : ContinuousInv ℝ≥0∞ := ⟨OrderIso.invENNReal.continuous⟩ @[simp] -- Porting note (#11215): TODO: generalize to `[InvolutiveInv _] [ContinuousInv _]` protected theorem tendsto_inv_iff {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} : Tendsto (fun x => (m x)⁻¹) f (𝓝 a⁻¹) ↔ Tendsto m f (𝓝 a) := ⟨fun h => by simpa only [inv_inv] using Tendsto.inv h, Tendsto.inv⟩ #align ennreal.tendsto_inv_iff ENNReal.tendsto_inv_iff protected theorem Tendsto.div {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun a => ma a / mb a) f (𝓝 (a / b)) := by apply Tendsto.mul hma _ (ENNReal.tendsto_inv_iff.2 hmb) _ <;> simp [ha, hb] #align ennreal.tendsto.div ENNReal.Tendsto.div protected theorem Tendsto.const_div {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun b => a / m b) f (𝓝 (a / b)) := by apply Tendsto.const_mul (ENNReal.tendsto_inv_iff.2 hm) simp [hb] #align ennreal.tendsto.const_div ENNReal.Tendsto.const_div protected theorem Tendsto.div_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : Tendsto (fun x => m x / b) f (𝓝 (a / b)) := by apply Tendsto.mul_const hm simp [ha] #align ennreal.tendsto.div_const ENNReal.Tendsto.div_const protected theorem tendsto_inv_nat_nhds_zero : Tendsto (fun n : ℕ => (n : ℝ≥0∞)⁻¹) atTop (𝓝 0) := ENNReal.inv_top ▸ ENNReal.tendsto_inv_iff.2 tendsto_nat_nhds_top #align ennreal.tendsto_inv_nat_nhds_zero ENNReal.tendsto_inv_nat_nhds_zero theorem iSup_add {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : iSup s + a = ⨆ b, s b + a := Monotone.map_iSup_of_continuousAt' (continuousAt_id.add continuousAt_const) <| monotone_id.add monotone_const #align ennreal.supr_add ENNReal.iSup_add theorem biSup_add' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (⨆ (i) (_ : p i), f i) + a = ⨆ (i) (_ : p i), f i + a := by haveI : Nonempty { i // p i } := nonempty_subtype.2 h simp only [iSup_subtype', iSup_add] #align ennreal.bsupr_add' ENNReal.biSup_add' theorem add_biSup' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (a + ⨆ (i) (_ : p i), f i) = ⨆ (i) (_ : p i), a + f i := by simp only [add_comm a, biSup_add' h] #align ennreal.add_bsupr' ENNReal.add_biSup' theorem biSup_add {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a := biSup_add' hs #align ennreal.bsupr_add ENNReal.biSup_add theorem add_biSup {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (a + ⨆ i ∈ s, f i) = ⨆ i ∈ s, a + f i := add_biSup' hs #align ennreal.add_bsupr ENNReal.add_biSup theorem sSup_add {s : Set ℝ≥0∞} (hs : s.Nonempty) : sSup s + a = ⨆ b ∈ s, b + a := by rw [sSup_eq_iSup, biSup_add hs] #align ennreal.Sup_add ENNReal.sSup_add theorem add_iSup {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : a + iSup s = ⨆ b, a + s b := by rw [add_comm, iSup_add]; simp [add_comm] #align ennreal.add_supr ENNReal.add_iSup theorem iSup_add_iSup_le {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i j, f i + g j ≤ a) : iSup f + iSup g ≤ a := by simp_rw [iSup_add, add_iSup]; exact iSup₂_le h #align ennreal.supr_add_supr_le ENNReal.iSup_add_iSup_le theorem biSup_add_biSup_le' {ι ι'} {p : ι → Prop} {q : ι' → Prop} (hp : ∃ i, p i) (hq : ∃ j, q j) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i, p i → ∀ j, q j → f i + g j ≤ a) : ((⨆ (i) (_ : p i), f i) + ⨆ (j) (_ : q j), g j) ≤ a := by simp_rw [biSup_add' hp, add_biSup' hq] exact iSup₂_le fun i hi => iSup₂_le (h i hi) #align ennreal.bsupr_add_bsupr_le' ENNReal.biSup_add_biSup_le' theorem biSup_add_biSup_le {ι ι'} {s : Set ι} {t : Set ι'} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i ∈ s, ∀ j ∈ t, f i + g j ≤ a) : ((⨆ i ∈ s, f i) + ⨆ j ∈ t, g j) ≤ a := biSup_add_biSup_le' hs ht h #align ennreal.bsupr_add_bsupr_le ENNReal.biSup_add_biSup_le theorem iSup_add_iSup {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀ i j, ∃ k, f i + g j ≤ f k + g k) : iSup f + iSup g = ⨆ a, f a + g a := by cases isEmpty_or_nonempty ι · simp only [iSup_of_empty, bot_eq_zero, zero_add] · refine le_antisymm ?_ (iSup_le fun a => add_le_add (le_iSup _ _) (le_iSup _ _)) refine iSup_add_iSup_le fun i j => ?_ rcases h i j with ⟨k, hk⟩ exact le_iSup_of_le k hk #align ennreal.supr_add_supr ENNReal.iSup_add_iSup theorem iSup_add_iSup_of_monotone {ι : Type*} [SemilatticeSup ι] {f g : ι → ℝ≥0∞} (hf : Monotone f) (hg : Monotone g) : iSup f + iSup g = ⨆ a, f a + g a := iSup_add_iSup fun i j => ⟨i ⊔ j, add_le_add (hf <| le_sup_left) (hg <| le_sup_right)⟩ #align ennreal.supr_add_supr_of_monotone ENNReal.iSup_add_iSup_of_monotone theorem finset_sum_iSup_nat {α} {ι} [SemilatticeSup ι] {s : Finset α} {f : α → ι → ℝ≥0∞} (hf : ∀ a, Monotone (f a)) : (∑ a ∈ s, iSup (f a)) = ⨆ n, ∑ a ∈ s, f a n := by refine Finset.induction_on s ?_ ?_ · simp · intro a s has ih simp only [Finset.sum_insert has] rw [ih, iSup_add_iSup_of_monotone (hf a)] intro i j h exact Finset.sum_le_sum fun a _ => hf a h #align ennreal.finset_sum_supr_nat ENNReal.finset_sum_iSup_nat theorem mul_iSup {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : a * iSup f = ⨆ i, a * f i := by by_cases hf : ∀ i, f i = 0 · obtain rfl : f = fun _ => 0 := funext hf simp only [iSup_zero_eq_zero, mul_zero] · refine (monotone_id.const_mul' _).map_iSup_of_continuousAt ?_ (mul_zero a) refine ENNReal.Tendsto.const_mul tendsto_id (Or.inl ?_) exact mt iSup_eq_zero.1 hf #align ennreal.mul_supr ENNReal.mul_iSup theorem mul_sSup {s : Set ℝ≥0∞} {a : ℝ≥0∞} : a * sSup s = ⨆ i ∈ s, a * i := by simp only [sSup_eq_iSup, mul_iSup] #align ennreal.mul_Sup ENNReal.mul_sSup theorem iSup_mul {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f * a = ⨆ i, f i * a := by rw [mul_comm, mul_iSup]; congr; funext; rw [mul_comm] #align ennreal.supr_mul ENNReal.iSup_mul theorem smul_iSup {ι : Sort*} {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (f : ι → ℝ≥0∞) (c : R) : (c • ⨆ i, f i) = ⨆ i, c • f i := by -- Porting note: replaced `iSup _` with `iSup f` simp only [← smul_one_mul c (f _), ← smul_one_mul c (iSup f), ENNReal.mul_iSup] #align ennreal.smul_supr ENNReal.smul_iSup theorem smul_sSup {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (s : Set ℝ≥0∞) (c : R) : c • sSup s = ⨆ i ∈ s, c • i := by -- Porting note: replaced `_` with `s` simp_rw [← smul_one_mul c (sSup s), ENNReal.mul_sSup, smul_one_mul] #align ennreal.smul_Sup ENNReal.smul_sSup theorem iSup_div {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f / a = ⨆ i, f i / a := iSup_mul #align ennreal.supr_div ENNReal.iSup_div protected theorem tendsto_coe_sub {b : ℝ≥0∞} : Tendsto (fun b : ℝ≥0∞ => ↑r - b) (𝓝 b) (𝓝 (↑r - b)) := continuous_nnreal_sub.tendsto _ #align ennreal.tendsto_coe_sub ENNReal.tendsto_coe_sub theorem sub_iSup {ι : Sort*} [Nonempty ι] {b : ι → ℝ≥0∞} (hr : a < ∞) : (a - ⨆ i, b i) = ⨅ i, a - b i := antitone_const_tsub.map_iSup_of_continuousAt' (continuous_sub_left hr.ne).continuousAt #align ennreal.sub_supr ENNReal.sub_iSup theorem exists_countable_dense_no_zero_top : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ 0 ∉ s ∧ ∞ ∉ s := by obtain ⟨s, s_count, s_dense, hs⟩ : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ (∀ x, IsBot x → x ∉ s) ∧ ∀ x, IsTop x → x ∉ s := exists_countable_dense_no_bot_top ℝ≥0∞ exact ⟨s, s_count, s_dense, fun h => hs.1 0 (by simp) h, fun h => hs.2 ∞ (by simp) h⟩ #align ennreal.exists_countable_dense_no_zero_top ENNReal.exists_countable_dense_no_zero_top theorem exists_lt_add_of_lt_add {x y z : ℝ≥0∞} (h : x < y + z) (hy : y ≠ 0) (hz : z ≠ 0) : ∃ y' z', y' < y ∧ z' < z ∧ x < y' + z' := by have : NeZero y := ⟨hy⟩ have : NeZero z := ⟨hz⟩ have A : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 + p.2) (𝓝[<] y ×ˢ 𝓝[<] z) (𝓝 (y + z)) := by apply Tendsto.mono_left _ (Filter.prod_mono nhdsWithin_le_nhds nhdsWithin_le_nhds) rw [← nhds_prod_eq] exact tendsto_add rcases ((A.eventually (lt_mem_nhds h)).and (Filter.prod_mem_prod self_mem_nhdsWithin self_mem_nhdsWithin)).exists with ⟨⟨y', z'⟩, hx, hy', hz'⟩ exact ⟨y', z', hy', hz', hx⟩ #align ennreal.exists_lt_add_of_lt_add ENNReal.exists_lt_add_of_lt_add theorem ofReal_cinfi (f : α → ℝ) [Nonempty α] : ENNReal.ofReal (⨅ i, f i) = ⨅ i, ENNReal.ofReal (f i) := by by_cases hf : BddBelow (range f) · exact Monotone.map_ciInf_of_continuousAt ENNReal.continuous_ofReal.continuousAt (fun i j hij => ENNReal.ofReal_le_ofReal hij) hf · symm rw [Real.iInf_of_not_bddBelow hf, ENNReal.ofReal_zero, ← ENNReal.bot_eq_zero, iInf_eq_bot] obtain ⟨y, hy_mem, hy_neg⟩ := not_bddBelow_iff.mp hf 0 obtain ⟨i, rfl⟩ := mem_range.mpr hy_mem refine fun x hx => ⟨i, ?_⟩ rwa [ENNReal.ofReal_of_nonpos hy_neg.le] #align ennreal.of_real_cinfi ENNReal.ofReal_cinfi end TopologicalSpace section Liminf theorem exists_frequently_lt_of_liminf_ne_top {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, x n < R := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h r] with i hi using hi.trans (le_abs_self (x i)) #align ennreal.exists_frequently_lt_of_liminf_ne_top ENNReal.exists_frequently_lt_of_liminf_ne_top theorem exists_frequently_lt_of_liminf_ne_top' {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, R < x n := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h (-r)] with i hi using(le_neg.1 hi).trans (neg_le_abs _) #align ennreal.exists_frequently_lt_of_liminf_ne_top' ENNReal.exists_frequently_lt_of_liminf_ne_top' theorem exists_upcrossings_of_not_bounded_under {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hf : liminf (fun i => (Real.nnabs (x i) : ℝ≥0∞)) l ≠ ∞) (hbdd : ¬IsBoundedUnder (· ≤ ·) l fun i => |x i|) : ∃ a b : ℚ, a < b ∧ (∃ᶠ i in l, x i < a) ∧ ∃ᶠ i in l, ↑b < x i := by rw [isBoundedUnder_le_abs, not_and_or] at hbdd obtain hbdd | hbdd := hbdd · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top hf obtain ⟨q, hq⟩ := exists_rat_gt R refine ⟨q, q + 1, (lt_add_iff_pos_right _).2 zero_lt_one, ?_, ?_⟩ · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 (lt_of_lt_of_le hq (not_lt.1 hx)).le · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q + 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top' hf obtain ⟨q, hq⟩ := exists_rat_lt R refine ⟨q - 1, q, (sub_lt_self_iff _).2 zero_lt_one, ?_, ?_⟩ · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q - 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 ((not_lt.1 hx).trans hq.le) #align ennreal.exists_upcrossings_of_not_bounded_under ENNReal.exists_upcrossings_of_not_bounded_under end Liminf section tsum variable {f g : α → ℝ≥0∞} @[norm_cast] protected theorem hasSum_coe {f : α → ℝ≥0} {r : ℝ≥0} : HasSum (fun a => (f a : ℝ≥0∞)) ↑r ↔ HasSum f r := by simp only [HasSum, ← coe_finset_sum, tendsto_coe] #align ennreal.has_sum_coe ENNReal.hasSum_coe protected theorem tsum_coe_eq {f : α → ℝ≥0} (h : HasSum f r) : (∑' a, (f a : ℝ≥0∞)) = r := (ENNReal.hasSum_coe.2 h).tsum_eq #align ennreal.tsum_coe_eq ENNReal.tsum_coe_eq protected theorem coe_tsum {f : α → ℝ≥0} : Summable f → ↑(tsum f) = ∑' a, (f a : ℝ≥0∞) | ⟨r, hr⟩ => by rw [hr.tsum_eq, ENNReal.tsum_coe_eq hr] #align ennreal.coe_tsum ENNReal.coe_tsum protected theorem hasSum : HasSum f (⨆ s : Finset α, ∑ a ∈ s, f a) := tendsto_atTop_iSup fun _ _ => Finset.sum_le_sum_of_subset #align ennreal.has_sum ENNReal.hasSum @[simp] protected theorem summable : Summable f := ⟨_, ENNReal.hasSum⟩ #align ennreal.summable ENNReal.summable theorem tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} : (∑' b, (f b : ℝ≥0∞)) ≠ ∞ ↔ Summable f := by refine ⟨fun h => ?_, fun h => ENNReal.coe_tsum h ▸ ENNReal.coe_ne_top⟩ lift ∑' b, (f b : ℝ≥0∞) to ℝ≥0 using h with a ha refine ⟨a, ENNReal.hasSum_coe.1 ?_⟩ rw [ha] exact ENNReal.summable.hasSum #align ennreal.tsum_coe_ne_top_iff_summable ENNReal.tsum_coe_ne_top_iff_summable protected theorem tsum_eq_iSup_sum : ∑' a, f a = ⨆ s : Finset α, ∑ a ∈ s, f a := ENNReal.hasSum.tsum_eq #align ennreal.tsum_eq_supr_sum ENNReal.tsum_eq_iSup_sum protected theorem tsum_eq_iSup_sum' {ι : Type*} (s : ι → Finset α) (hs : ∀ t, ∃ i, t ⊆ s i) : ∑' a, f a = ⨆ i, ∑ a ∈ s i, f a := by rw [ENNReal.tsum_eq_iSup_sum] symm change ⨆ i : ι, (fun t : Finset α => ∑ a ∈ t, f a) (s i) = ⨆ s : Finset α, ∑ a ∈ s, f a exact (Finset.sum_mono_set f).iSup_comp_eq hs #align ennreal.tsum_eq_supr_sum' ENNReal.tsum_eq_iSup_sum' protected theorem tsum_sigma {β : α → Type*} (f : ∀ a, β a → ℝ≥0∞) : ∑' p : Σa, β a, f p.1 p.2 = ∑' (a) (b), f a b := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma ENNReal.tsum_sigma protected theorem tsum_sigma' {β : α → Type*} (f : (Σa, β a) → ℝ≥0∞) : ∑' p : Σa, β a, f p = ∑' (a) (b), f ⟨a, b⟩ := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma' ENNReal.tsum_sigma' protected theorem tsum_prod {f : α → β → ℝ≥0∞} : ∑' p : α × β, f p.1 p.2 = ∑' (a) (b), f a b := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod ENNReal.tsum_prod protected theorem tsum_prod' {f : α × β → ℝ≥0∞} : ∑' p : α × β, f p = ∑' (a) (b), f (a, b) := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod' ENNReal.tsum_prod' protected theorem tsum_comm {f : α → β → ℝ≥0∞} : ∑' a, ∑' b, f a b = ∑' b, ∑' a, f a b := tsum_comm' ENNReal.summable (fun _ => ENNReal.summable) fun _ => ENNReal.summable #align ennreal.tsum_comm ENNReal.tsum_comm protected theorem tsum_add : ∑' a, (f a + g a) = ∑' a, f a + ∑' a, g a := tsum_add ENNReal.summable ENNReal.summable #align ennreal.tsum_add ENNReal.tsum_add protected theorem tsum_le_tsum (h : ∀ a, f a ≤ g a) : ∑' a, f a ≤ ∑' a, g a := tsum_le_tsum h ENNReal.summable ENNReal.summable #align ennreal.tsum_le_tsum ENNReal.tsum_le_tsum @[gcongr] protected theorem _root_.GCongr.ennreal_tsum_le_tsum (h : ∀ a, f a ≤ g a) : tsum f ≤ tsum g := ENNReal.tsum_le_tsum h protected theorem sum_le_tsum {f : α → ℝ≥0∞} (s : Finset α) : ∑ x ∈ s, f x ≤ ∑' x, f x := sum_le_tsum s (fun _ _ => zero_le _) ENNReal.summable #align ennreal.sum_le_tsum ENNReal.sum_le_tsum protected theorem tsum_eq_iSup_nat' {f : ℕ → ℝ≥0∞} {N : ℕ → ℕ} (hN : Tendsto N atTop atTop) : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range (N i), f a := ENNReal.tsum_eq_iSup_sum' _ fun t => let ⟨n, hn⟩ := t.exists_nat_subset_range let ⟨k, _, hk⟩ := exists_le_of_tendsto_atTop hN 0 n ⟨k, Finset.Subset.trans hn (Finset.range_mono hk)⟩ #align ennreal.tsum_eq_supr_nat' ENNReal.tsum_eq_iSup_nat' protected theorem tsum_eq_iSup_nat {f : ℕ → ℝ≥0∞} : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range i, f a := ENNReal.tsum_eq_iSup_sum' _ Finset.exists_nat_subset_range #align ennreal.tsum_eq_supr_nat ENNReal.tsum_eq_iSup_nat protected theorem tsum_eq_liminf_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = liminf (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.liminf_eq.symm #align ennreal.tsum_eq_liminf_sum_nat ENNReal.tsum_eq_liminf_sum_nat protected theorem tsum_eq_limsup_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = limsup (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.limsup_eq.symm protected theorem le_tsum (a : α) : f a ≤ ∑' a, f a := le_tsum' ENNReal.summable a #align ennreal.le_tsum ENNReal.le_tsum @[simp] protected theorem tsum_eq_zero : ∑' i, f i = 0 ↔ ∀ i, f i = 0 := tsum_eq_zero_iff ENNReal.summable #align ennreal.tsum_eq_zero ENNReal.tsum_eq_zero protected theorem tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → ∑' a, f a = ∞ | ⟨a, ha⟩ => top_unique <| ha ▸ ENNReal.le_tsum a #align ennreal.tsum_eq_top_of_eq_top ENNReal.tsum_eq_top_of_eq_top protected theorem lt_top_of_tsum_ne_top {a : α → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) (j : α) : a j < ∞ := by contrapose! tsum_ne_top with h exact ENNReal.tsum_eq_top_of_eq_top ⟨j, top_unique h⟩ #align ennreal.lt_top_of_tsum_ne_top ENNReal.lt_top_of_tsum_ne_top @[simp] protected theorem tsum_top [Nonempty α] : ∑' _ : α, ∞ = ∞ := let ⟨a⟩ := ‹Nonempty α› ENNReal.tsum_eq_top_of_eq_top ⟨a, rfl⟩ #align ennreal.tsum_top ENNReal.tsum_top theorem tsum_const_eq_top_of_ne_zero {α : Type*} [Infinite α] {c : ℝ≥0∞} (hc : c ≠ 0) : ∑' _ : α, c = ∞ := by have A : Tendsto (fun n : ℕ => (n : ℝ≥0∞) * c) atTop (𝓝 (∞ * c)) := by apply ENNReal.Tendsto.mul_const tendsto_nat_nhds_top simp only [true_or_iff, top_ne_zero, Ne, not_false_iff] have B : ∀ n : ℕ, (n : ℝ≥0∞) * c ≤ ∑' _ : α, c := fun n => by rcases Infinite.exists_subset_card_eq α n with ⟨s, hs⟩ simpa [hs] using @ENNReal.sum_le_tsum α (fun _ => c) s simpa [hc] using le_of_tendsto' A B #align ennreal.tsum_const_eq_top_of_ne_zero ENNReal.tsum_const_eq_top_of_ne_zero protected theorem ne_top_of_tsum_ne_top (h : ∑' a, f a ≠ ∞) (a : α) : f a ≠ ∞ := fun ha => h <| ENNReal.tsum_eq_top_of_eq_top ⟨a, ha⟩ #align ennreal.ne_top_of_tsum_ne_top ENNReal.ne_top_of_tsum_ne_top protected theorem tsum_mul_left : ∑' i, a * f i = a * ∑' i, f i := by by_cases hf : ∀ i, f i = 0 · simp [hf] · rw [← ENNReal.tsum_eq_zero] at hf have : Tendsto (fun s : Finset α => ∑ j ∈ s, a * f j) atTop (𝓝 (a * ∑' i, f i)) := by simp only [← Finset.mul_sum] exact ENNReal.Tendsto.const_mul ENNReal.summable.hasSum (Or.inl hf) exact HasSum.tsum_eq this #align ennreal.tsum_mul_left ENNReal.tsum_mul_left protected theorem tsum_mul_right : ∑' i, f i * a = (∑' i, f i) * a := by simp [mul_comm, ENNReal.tsum_mul_left] #align ennreal.tsum_mul_right ENNReal.tsum_mul_right protected theorem tsum_const_smul {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (a : R) : ∑' i, a • f i = a • ∑' i, f i := by simpa only [smul_one_mul] using @ENNReal.tsum_mul_left _ (a • (1 : ℝ≥0∞)) _ #align ennreal.tsum_const_smul ENNReal.tsum_const_smul @[simp] theorem tsum_iSup_eq {α : Type*} (a : α) {f : α → ℝ≥0∞} : (∑' b : α, ⨆ _ : a = b, f b) = f a := (tsum_eq_single a fun _ h => by simp [h.symm]).trans <| by simp #align ennreal.tsum_supr_eq ENNReal.tsum_iSup_eq theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0∞} (r : ℝ≥0∞) : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by refine ⟨HasSum.tendsto_sum_nat, fun h => ?_⟩ rw [← iSup_eq_of_tendsto _ h, ← ENNReal.tsum_eq_iSup_nat] · exact ENNReal.summable.hasSum · exact fun s t hst => Finset.sum_le_sum_of_subset (Finset.range_subset.2 hst) #align ennreal.has_sum_iff_tendsto_nat ENNReal.hasSum_iff_tendsto_nat theorem tendsto_nat_tsum (f : ℕ → ℝ≥0∞) : Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 (∑' n, f n)) := by rw [← hasSum_iff_tendsto_nat] exact ENNReal.summable.hasSum #align ennreal.tendsto_nat_tsum ENNReal.tendsto_nat_tsum theorem toNNReal_apply_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) (x : α) : (((ENNReal.toNNReal ∘ f) x : ℝ≥0) : ℝ≥0∞) = f x := coe_toNNReal <| ENNReal.ne_top_of_tsum_ne_top hf _ #align ennreal.to_nnreal_apply_of_tsum_ne_top ENNReal.toNNReal_apply_of_tsum_ne_top theorem summable_toNNReal_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) : Summable (ENNReal.toNNReal ∘ f) := by simpa only [← tsum_coe_ne_top_iff_summable, toNNReal_apply_of_tsum_ne_top hf] using hf #align ennreal.summable_to_nnreal_of_tsum_ne_top ENNReal.summable_toNNReal_of_tsum_ne_top theorem tendsto_cofinite_zero_of_tsum_ne_top {α} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f cofinite (𝓝 0) := by have f_ne_top : ∀ n, f n ≠ ∞ := ENNReal.ne_top_of_tsum_ne_top hf have h_f_coe : f = fun n => ((f n).toNNReal : ENNReal) := funext fun n => (coe_toNNReal (f_ne_top n)).symm rw [h_f_coe, ← @coe_zero, tendsto_coe] exact NNReal.tendsto_cofinite_zero_of_summable (summable_toNNReal_of_tsum_ne_top hf) #align ennreal.tendsto_cofinite_zero_of_tsum_ne_top ENNReal.tendsto_cofinite_zero_of_tsum_ne_top theorem tendsto_atTop_zero_of_tsum_ne_top {f : ℕ → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f atTop (𝓝 0) := by rw [← Nat.cofinite_eq_atTop] exact tendsto_cofinite_zero_of_tsum_ne_top hf #align ennreal.tendsto_at_top_zero_of_tsum_ne_top ENNReal.tendsto_atTop_zero_of_tsum_ne_top /-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole space. This does not need a summability assumption, as otherwise all sums are zero. -/ theorem tendsto_tsum_compl_atTop_zero {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto (fun s : Finset α => ∑' b : { x // x ∉ s }, f b) atTop (𝓝 0) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hf convert ENNReal.tendsto_coe.2 (NNReal.tendsto_tsum_compl_atTop_zero f) rw [ENNReal.coe_tsum] exact NNReal.summable_comp_injective (tsum_coe_ne_top_iff_summable.1 hf) Subtype.coe_injective #align ennreal.tendsto_tsum_compl_at_top_zero ENNReal.tendsto_tsum_compl_atTop_zero protected theorem tsum_apply {ι α : Type*} {f : ι → α → ℝ≥0∞} {x : α} : (∑' i, f i) x = ∑' i, f i x := tsum_apply <| Pi.summable.mpr fun _ => ENNReal.summable #align ennreal.tsum_apply ENNReal.tsum_apply theorem tsum_sub {f : ℕ → ℝ≥0∞} {g : ℕ → ℝ≥0∞} (h₁ : ∑' i, g i ≠ ∞) (h₂ : g ≤ f) : ∑' i, (f i - g i) = ∑' i, f i - ∑' i, g i := have : ∀ i, f i - g i + g i = f i := fun i => tsub_add_cancel_of_le (h₂ i) ENNReal.eq_sub_of_add_eq h₁ <| by simp only [← ENNReal.tsum_add, this] #align ennreal.tsum_sub ENNReal.tsum_sub theorem tsum_comp_le_tsum_of_injective {f : α → β} (hf : Injective f) (g : β → ℝ≥0∞) : ∑' x, g (f x) ≤ ∑' y, g y := tsum_le_tsum_of_inj f hf (fun _ _ => zero_le _) (fun _ => le_rfl) ENNReal.summable ENNReal.summable theorem tsum_le_tsum_comp_of_surjective {f : α → β} (hf : Surjective f) (g : β → ℝ≥0∞) : ∑' y, g y ≤ ∑' x, g (f x) := calc ∑' y, g y = ∑' y, g (f (surjInv hf y)) := by simp only [surjInv_eq hf] _ ≤ ∑' x, g (f x) := tsum_comp_le_tsum_of_injective (injective_surjInv hf) _ theorem tsum_mono_subtype (f : α → ℝ≥0∞) {s t : Set α} (h : s ⊆ t) : ∑' x : s, f x ≤ ∑' x : t, f x := tsum_comp_le_tsum_of_injective (inclusion_injective h) _ #align ennreal.tsum_mono_subtype ENNReal.tsum_mono_subtype theorem tsum_iUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑' i, ∑' x : t i, f x := calc ∑' x : ⋃ i, t i, f x ≤ ∑' x : Σ i, t i, f x.2 := tsum_le_tsum_comp_of_surjective (sigmaToiUnion_surjective t) _ _ = ∑' i, ∑' x : t i, f x := ENNReal.tsum_sigma' _ theorem tsum_biUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (s : Set ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s , t i, f x ≤ ∑' i : s, ∑' x : t i, f x := calc ∑' x : ⋃ i ∈ s, t i, f x = ∑' x : ⋃ i : s, t i, f x := tsum_congr_set_coe _ <| by simp _ ≤ ∑' i : s, ∑' x : t i, f x := tsum_iUnion_le_tsum _ _ theorem tsum_biUnion_le {ι : Type*} (f : α → ℝ≥0∞) (s : Finset ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s, t i, f x ≤ ∑ i ∈ s, ∑' x : t i, f x := (tsum_biUnion_le_tsum f s.toSet t).trans_eq (Finset.tsum_subtype s fun i => ∑' x : t i, f x) #align ennreal.tsum_bUnion_le ENNReal.tsum_biUnion_le theorem tsum_iUnion_le {ι : Type*} [Fintype ι] (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑ i, ∑' x : t i, f x := by rw [← tsum_fintype] exact tsum_iUnion_le_tsum f t #align ennreal.tsum_Union_le ENNReal.tsum_iUnion_le theorem tsum_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∑' x : ↑(s ∪ t), f x ≤ ∑' x : s, f x + ∑' x : t, f x := calc ∑' x : ↑(s ∪ t), f x = ∑' x : ⋃ b, cond b s t, f x := tsum_congr_set_coe _ union_eq_iUnion _ ≤ _ := by simpa using tsum_iUnion_le f (cond · s t) #align ennreal.tsum_union_le ENNReal.tsum_union_le theorem tsum_eq_add_tsum_ite {f : β → ℝ≥0∞} (b : β) : ∑' x, f x = f b + ∑' x, ite (x = b) 0 (f x) := tsum_eq_add_tsum_ite' b ENNReal.summable #align ennreal.tsum_eq_add_tsum_ite ENNReal.tsum_eq_add_tsum_ite theorem tsum_add_one_eq_top {f : ℕ → ℝ≥0∞} (hf : ∑' n, f n = ∞) (hf0 : f 0 ≠ ∞) : ∑' n, f (n + 1) = ∞ := by rw [tsum_eq_zero_add' ENNReal.summable, add_eq_top] at hf exact hf.resolve_left hf0 #align ennreal.tsum_add_one_eq_top ENNReal.tsum_add_one_eq_top /-- A sum of extended nonnegative reals which is finite can have only finitely many terms above any positive threshold. -/ theorem finite_const_le_of_tsum_ne_top {ι : Type*} {a : ι → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : { i : ι | ε ≤ a i }.Finite := by by_contra h have := Infinite.to_subtype h refine tsum_ne_top (top_unique ?_) calc ∞ = ∑' _ : { i | ε ≤ a i }, ε := (tsum_const_eq_top_of_ne_zero ε_ne_zero).symm _ ≤ ∑' i, a i := tsum_le_tsum_of_inj (↑) Subtype.val_injective (fun _ _ => zero_le _) (fun i => i.2) ENNReal.summable ENNReal.summable #align ennreal.finite_const_le_of_tsum_ne_top ENNReal.finite_const_le_of_tsum_ne_top /-- Markov's inequality for `Finset.card` and `tsum` in `ℝ≥0∞`. -/ theorem finset_card_const_le_le_of_tsum_le {ι : Type*} {a : ι → ℝ≥0∞} {c : ℝ≥0∞} (c_ne_top : c ≠ ∞) (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : ∃ hf : { i : ι | ε ≤ a i }.Finite, ↑hf.toFinset.card ≤ c / ε := by have hf : { i : ι | ε ≤ a i }.Finite := finite_const_le_of_tsum_ne_top (ne_top_of_le_ne_top c_ne_top tsum_le_c) ε_ne_zero refine ⟨hf, (ENNReal.le_div_iff_mul_le (.inl ε_ne_zero) (.inr c_ne_top)).2 ?_⟩ calc ↑hf.toFinset.card * ε = ∑ _i ∈ hf.toFinset, ε := by rw [Finset.sum_const, nsmul_eq_mul] _ ≤ ∑ i ∈ hf.toFinset, a i := Finset.sum_le_sum fun i => hf.mem_toFinset.1 _ ≤ ∑' i, a i := ENNReal.sum_le_tsum _ _ ≤ c := tsum_le_c #align ennreal.finset_card_const_le_le_of_tsum_le ENNReal.finset_card_const_le_le_of_tsum_le theorem tsum_fiberwise (f : β → ℝ≥0∞) (g : β → γ) : ∑' x, ∑' b : g ⁻¹' {x}, f b = ∑' i, f i := by apply HasSum.tsum_eq let equiv := Equiv.sigmaFiberEquiv g apply (equiv.hasSum_iff.mpr ENNReal.summable.hasSum).sigma exact fun _ ↦ ENNReal.summable.hasSum_iff.mpr rfl end tsum theorem tendsto_toReal_iff {ι} {fi : Filter ι} {f : ι → ℝ≥0∞} (hf : ∀ i, f i ≠ ∞) {x : ℝ≥0∞} (hx : x ≠ ∞) : Tendsto (fun n => (f n).toReal) fi (𝓝 x.toReal) ↔ Tendsto f fi (𝓝 x) := by lift f to ι → ℝ≥0 using hf lift x to ℝ≥0 using hx simp [tendsto_coe] #align ennreal.tendsto_to_real_iff ENNReal.tendsto_toReal_iff theorem tsum_coe_ne_top_iff_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) ≠ ∞ ↔ Summable fun a => (f a : ℝ) := by rw [NNReal.summable_coe] exact tsum_coe_ne_top_iff_summable #align ennreal.tsum_coe_ne_top_iff_summable_coe ENNReal.tsum_coe_ne_top_iff_summable_coe theorem tsum_coe_eq_top_iff_not_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) = ∞ ↔ ¬Summable fun a => (f a : ℝ) := tsum_coe_ne_top_iff_summable_coe.not_right #align ennreal.tsum_coe_eq_top_iff_not_summable_coe ENNReal.tsum_coe_eq_top_iff_not_summable_coe theorem hasSum_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : HasSum (fun x => (f x).toReal) (∑' x, (f x).toReal) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hsum simp only [coe_toReal, ← NNReal.coe_tsum, NNReal.hasSum_coe] exact (tsum_coe_ne_top_iff_summable.1 hsum).hasSum #align ennreal.has_sum_to_real ENNReal.hasSum_toReal theorem summable_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : Summable fun x => (f x).toReal := (hasSum_toReal hsum).summable #align ennreal.summable_to_real ENNReal.summable_toReal end ENNReal namespace NNReal theorem tsum_eq_toNNReal_tsum {f : β → ℝ≥0} : ∑' b, f b = (∑' b, (f b : ℝ≥0∞)).toNNReal := by by_cases h : Summable f · rw [← ENNReal.coe_tsum h, ENNReal.toNNReal_coe] · have A := tsum_eq_zero_of_not_summable h simp only [← ENNReal.tsum_coe_ne_top_iff_summable, Classical.not_not] at h simp only [h, ENNReal.top_toNNReal, A] #align nnreal.tsum_eq_to_nnreal_tsum NNReal.tsum_eq_toNNReal_tsum /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem exists_le_hasSum_of_le {f g : β → ℝ≥0} {r : ℝ≥0} (hgf : ∀ b, g b ≤ f b) (hfr : HasSum f r) : ∃ p ≤ r, HasSum g p := have : (∑' b, (g b : ℝ≥0∞)) ≤ r := by refine hasSum_le (fun b => ?_) ENNReal.summable.hasSum (ENNReal.hasSum_coe.2 hfr) exact ENNReal.coe_le_coe.2 (hgf _) let ⟨p, Eq, hpr⟩ := ENNReal.le_coe_iff.1 this ⟨p, hpr, ENNReal.hasSum_coe.1 <| Eq ▸ ENNReal.summable.hasSum⟩ #align nnreal.exists_le_has_sum_of_le NNReal.exists_le_hasSum_of_le /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem summable_of_le {f g : β → ℝ≥0} (hgf : ∀ b, g b ≤ f b) : Summable f → Summable g | ⟨_r, hfr⟩ => let ⟨_p, _, hp⟩ := exists_le_hasSum_of_le hgf hfr hp.summable #align nnreal.summable_of_le NNReal.summable_of_le /-- Summable non-negative functions have countable support -/ theorem _root_.Summable.countable_support_nnreal (f : α → ℝ≥0) (h : Summable f) : f.support.Countable := by rw [← NNReal.summable_coe] at h simpa [support] using h.countable_support /-- A series of non-negative real numbers converges to `r` in the sense of `HasSum` if and only if the sequence of partial sum converges to `r`. -/ theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by rw [← ENNReal.hasSum_coe, ENNReal.hasSum_iff_tendsto_nat] simp only [← ENNReal.coe_finset_sum] exact ENNReal.tendsto_coe #align nnreal.has_sum_iff_tendsto_nat NNReal.hasSum_iff_tendsto_nat theorem not_summable_iff_tendsto_nat_atTop {f : ℕ → ℝ≥0} : ¬Summable f ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by constructor · intro h refine ((tendsto_of_monotone ?_).resolve_right h).comp ?_ exacts [Finset.sum_mono_set _, tendsto_finset_range] · rintro hnat ⟨r, hr⟩ exact not_tendsto_nhds_of_tendsto_atTop hnat _ (hasSum_iff_tendsto_nat.1 hr) #align nnreal.not_summable_iff_tendsto_nat_at_top NNReal.not_summable_iff_tendsto_nat_atTop theorem summable_iff_not_tendsto_nat_atTop {f : ℕ → ℝ≥0} : Summable f ↔ ¬Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by rw [← not_iff_not, Classical.not_not, not_summable_iff_tendsto_nat_atTop] #align nnreal.summable_iff_not_tendsto_nat_at_top NNReal.summable_iff_not_tendsto_nat_atTop theorem summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : Summable f := by refine summable_iff_not_tendsto_nat_atTop.2 fun H => ?_ rcases exists_lt_of_tendsto_atTop H 0 c with ⟨n, -, hn⟩ exact lt_irrefl _ (hn.trans_le (h n)) #align nnreal.summable_of_sum_range_le NNReal.summable_of_sum_range_le theorem tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : ∑' n, f n ≤ c := _root_.tsum_le_of_sum_range_le (summable_of_sum_range_le h) h #align nnreal.tsum_le_of_sum_range_le NNReal.tsum_le_of_sum_range_le theorem tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : Summable f) {i : β → α} (hi : Function.Injective i) : (∑' x, f (i x)) ≤ ∑' x, f x := tsum_le_tsum_of_inj i hi (fun _ _ => zero_le _) (fun _ => le_rfl) (summable_comp_injective hf hi) hf #align nnreal.tsum_comp_le_tsum_of_inj NNReal.tsum_comp_le_tsum_of_inj theorem summable_sigma {β : α → Type*} {f : (Σ x, β x) → ℝ≥0} : Summable f ↔ (∀ x, Summable fun y => f ⟨x, y⟩) ∧ Summable fun x => ∑' y, f ⟨x, y⟩ := by constructor · simp only [← NNReal.summable_coe, NNReal.coe_tsum] exact fun h => ⟨h.sigma_factor, h.sigma⟩ · rintro ⟨h₁, h₂⟩ simpa only [← ENNReal.tsum_coe_ne_top_iff_summable, ENNReal.tsum_sigma', ENNReal.coe_tsum (h₁ _)] using h₂ #align nnreal.summable_sigma NNReal.summable_sigma theorem indicator_summable {f : α → ℝ≥0} (hf : Summable f) (s : Set α) : Summable (s.indicator f) := by refine NNReal.summable_of_le (fun a => le_trans (le_of_eq (s.indicator_apply f a)) ?_) hf split_ifs · exact le_refl (f a) · exact zero_le_coe #align nnreal.indicator_summable NNReal.indicator_summable theorem tsum_indicator_ne_zero {f : α → ℝ≥0} (hf : Summable f) {s : Set α} (h : ∃ a ∈ s, f a ≠ 0) : (∑' x, (s.indicator f) x) ≠ 0 := fun h' => let ⟨a, ha, hap⟩ := h hap ((Set.indicator_apply_eq_self.mpr (absurd ha)).symm.trans ((tsum_eq_zero_iff (indicator_summable hf s)).1 h' a)) #align nnreal.tsum_indicator_ne_zero NNReal.tsum_indicator_ne_zero open Finset /-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability assumption on `f`, as otherwise all sums are zero. -/ theorem tendsto_sum_nat_add (f : ℕ → ℝ≥0) : Tendsto (fun i => ∑' k, f (k + i)) atTop (𝓝 0) := by rw [← tendsto_coe] convert _root_.tendsto_sum_nat_add fun i => (f i : ℝ) norm_cast #align nnreal.tendsto_sum_nat_add NNReal.tendsto_sum_nat_add nonrec theorem hasSum_lt {f g : α → ℝ≥0} {sf sg : ℝ≥0} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hf : HasSum f sf) (hg : HasSum g sg) : sf < sg := by have A : ∀ a : α, (f a : ℝ) ≤ g a := fun a => NNReal.coe_le_coe.2 (h a) have : (sf : ℝ) < sg := hasSum_lt A (NNReal.coe_lt_coe.2 hi) (hasSum_coe.2 hf) (hasSum_coe.2 hg) exact NNReal.coe_lt_coe.1 this #align nnreal.has_sum_lt NNReal.hasSum_lt @[mono] theorem hasSum_strict_mono {f g : α → ℝ≥0} {sf sg : ℝ≥0} (hf : HasSum f sf) (hg : HasSum g sg) (h : f < g) : sf < sg := let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h hasSum_lt hle hi hf hg #align nnreal.has_sum_strict_mono NNReal.hasSum_strict_mono theorem tsum_lt_tsum {f g : α → ℝ≥0} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hg : Summable g) : ∑' n, f n < ∑' n, g n := hasSum_lt h hi (summable_of_le h hg).hasSum hg.hasSum #align nnreal.tsum_lt_tsum NNReal.tsum_lt_tsum @[mono] theorem tsum_strict_mono {f g : α → ℝ≥0} (hg : Summable g) (h : f < g) : ∑' n, f n < ∑' n, g n := let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h tsum_lt_tsum hle hi hg #align nnreal.tsum_strict_mono NNReal.tsum_strict_mono theorem tsum_pos {g : α → ℝ≥0} (hg : Summable g) (i : α) (hi : 0 < g i) : 0 < ∑' b, g b := by rw [← tsum_zero] exact tsum_lt_tsum (fun a => zero_le _) hi hg #align nnreal.tsum_pos NNReal.tsum_pos
Mathlib/Topology/Instances/ENNReal.lean
1,266
1,270
theorem tsum_eq_add_tsum_ite {f : α → ℝ≥0} (hf : Summable f) (i : α) : ∑' x, f x = f i + ∑' x, ite (x = i) 0 (f x) := by
refine tsum_eq_add_tsum_ite' i (NNReal.summable_of_le (fun i' => ?_) hf) rw [Function.update_apply] split_ifs <;> simp only [zero_le', le_rfl]
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Preserves.Basic #align_import category_theory.limits.preserves.shapes.pullbacks from "leanprover-community/mathlib"@"f11e306adb9f2a393539d2bb4293bf1b42caa7ac" /-! # Preserving pullbacks Constructions to relate the notions of preserving pullbacks and reflecting pullbacks to concrete pullback cones. In particular, we show that `pullbackComparison G f g` is an isomorphism iff `G` preserves the pullback of `f` and `g`. The dual is also given. ## TODO * Generalise to wide pullbacks -/ noncomputable section universe v₁ v₂ u₁ u₂ -- Porting note: need Functor namespace for mapCone open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Functor namespace CategoryTheory.Limits section Pullback variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} {h : W ⟶ X} {k : W ⟶ Y} (comm : h ≫ f = k ≫ g) /-- The map of a pullback cone is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `PullbackCone.mk` with `Functor.mapCone`. -/ def isLimitMapConePullbackConeEquiv : IsLimit (mapCone G (PullbackCone.mk h k comm)) ≃ IsLimit (PullbackCone.mk (G.map h) (G.map k) (by simp only [← G.map_comp, comm]) : PullbackCone (G.map f) (G.map g)) := (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₂} _) _).symm.trans <| IsLimit.equivIsoLimit <| Cones.ext (Iso.refl _) <| by rintro (_ | _ | _) <;> dsimp <;> simp only [comp_id, id_comp, G.map_comp] #align category_theory.limits.is_limit_map_cone_pullback_cone_equiv CategoryTheory.Limits.isLimitMapConePullbackConeEquiv /-- The property of preserving pullbacks expressed in terms of binary fans. -/ def isLimitPullbackConeMapOfIsLimit [PreservesLimit (cospan f g) G] (l : IsLimit (PullbackCone.mk h k comm)) : have : G.map h ≫ G.map f = G.map k ≫ G.map g := by rw [← G.map_comp, ← G.map_comp,comm] IsLimit (PullbackCone.mk (G.map h) (G.map k) this) := isLimitMapConePullbackConeEquiv G comm (PreservesLimit.preserves l) #align category_theory.limits.is_limit_pullback_cone_map_of_is_limit CategoryTheory.Limits.isLimitPullbackConeMapOfIsLimit /-- The property of reflecting pullbacks expressed in terms of binary fans. -/ def isLimitOfIsLimitPullbackConeMap [ReflectsLimit (cospan f g) G] (l : IsLimit (PullbackCone.mk (G.map h) (G.map k) (show G.map h ≫ G.map f = G.map k ≫ G.map g from by simp only [← G.map_comp,comm]))) : IsLimit (PullbackCone.mk h k comm) := ReflectsLimit.reflects ((isLimitMapConePullbackConeEquiv G comm).symm l) #align category_theory.limits.is_limit_of_is_limit_pullback_cone_map CategoryTheory.Limits.isLimitOfIsLimitPullbackConeMap variable (f g) [PreservesLimit (cospan f g) G] /-- If `G` preserves pullbacks and `C` has them, then the pullback cone constructed of the mapped morphisms of the pullback cone is a limit. -/ def isLimitOfHasPullbackOfPreservesLimit [i : HasPullback f g] : have : G.map pullback.fst ≫ G.map f = G.map pullback.snd ≫ G.map g := by simp only [← G.map_comp, pullback.condition]; IsLimit (PullbackCone.mk (G.map (@pullback.fst _ _ _ _ _ f g i)) (G.map pullback.snd) this) := isLimitPullbackConeMapOfIsLimit G _ (pullbackIsPullback f g) #align category_theory.limits.is_limit_of_has_pullback_of_preserves_limit CategoryTheory.Limits.isLimitOfHasPullbackOfPreservesLimit /-- If `F` preserves the pullback of `f, g`, it also preserves the pullback of `g, f`. -/ def preservesPullbackSymmetry : PreservesLimit (cospan g f) G where preserves {c} hc := by apply (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₂} _) _).toFun apply IsLimit.ofIsoLimit _ (PullbackCone.isoMk _).symm apply PullbackCone.isLimitOfFlip apply (isLimitMapConePullbackConeEquiv _ _).toFun · refine @PreservesLimit.preserves _ _ _ _ _ _ _ _ ?_ _ ?_ · dsimp infer_instance apply PullbackCone.isLimitOfFlip apply IsLimit.ofIsoLimit _ (PullbackCone.isoMk _) exact (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₁} _) _).invFun hc · exact (c.π.naturality WalkingCospan.Hom.inr).symm.trans (c.π.naturality WalkingCospan.Hom.inl : _) #align category_theory.limits.preserves_pullback_symmetry CategoryTheory.Limits.preservesPullbackSymmetry theorem hasPullback_of_preservesPullback [HasPullback f g] : HasPullback (G.map f) (G.map g) := ⟨⟨⟨_, isLimitPullbackConeMapOfIsLimit G _ (pullbackIsPullback _ _)⟩⟩⟩ #align category_theory.limits.has_pullback_of_preserves_pullback CategoryTheory.Limits.hasPullback_of_preservesPullback variable [HasPullback f g] [HasPullback (G.map f) (G.map g)] /-- If `G` preserves the pullback of `(f,g)`, then the pullback comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesPullback.iso : G.obj (pullback f g) ≅ pullback (G.map f) (G.map g) := IsLimit.conePointUniqueUpToIso (isLimitOfHasPullbackOfPreservesLimit G f g) (limit.isLimit _) #align category_theory.limits.preserves_pullback.iso CategoryTheory.Limits.PreservesPullback.iso @[simp] theorem PreservesPullback.iso_hom : (PreservesPullback.iso G f g).hom = pullbackComparison G f g := rfl #align category_theory.limits.preserves_pullback.iso_hom CategoryTheory.Limits.PreservesPullback.iso_hom @[reassoc] theorem PreservesPullback.iso_hom_fst : (PreservesPullback.iso G f g).hom ≫ pullback.fst = G.map pullback.fst := by simp [PreservesPullback.iso] #align category_theory.limits.preserves_pullback.iso_hom_fst CategoryTheory.Limits.PreservesPullback.iso_hom_fst @[reassoc] theorem PreservesPullback.iso_hom_snd : (PreservesPullback.iso G f g).hom ≫ pullback.snd = G.map pullback.snd := by simp [PreservesPullback.iso] #align category_theory.limits.preserves_pullback.iso_hom_snd CategoryTheory.Limits.PreservesPullback.iso_hom_snd @[reassoc (attr := simp)] theorem PreservesPullback.iso_inv_fst : (PreservesPullback.iso G f g).inv ≫ G.map pullback.fst = pullback.fst := by simp [PreservesPullback.iso, Iso.inv_comp_eq] #align category_theory.limits.preserves_pullback.iso_inv_fst CategoryTheory.Limits.PreservesPullback.iso_inv_fst @[reassoc (attr := simp)] theorem PreservesPullback.iso_inv_snd : (PreservesPullback.iso G f g).inv ≫ G.map pullback.snd = pullback.snd := by simp [PreservesPullback.iso, Iso.inv_comp_eq] #align category_theory.limits.preserves_pullback.iso_inv_snd CategoryTheory.Limits.PreservesPullback.iso_inv_snd end Pullback section Pushout variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {W X Y Z : C} {h : X ⟶ Z} {k : Y ⟶ Z} {f : W ⟶ X} {g : W ⟶ Y} (comm : f ≫ h = g ≫ k) /-- The map of a pushout cocone is a colimit iff the cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `PushoutCocone.mk` with `Functor.mapCocone`. -/ def isColimitMapCoconePushoutCoconeEquiv : IsColimit (mapCocone G (PushoutCocone.mk h k comm)) ≃ IsColimit (PushoutCocone.mk (G.map h) (G.map k) (by simp only [← G.map_comp, comm]) : PushoutCocone (G.map f) (G.map g)) := (IsColimit.precomposeHomEquiv (diagramIsoSpan.{v₂} _).symm _).symm.trans <| IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) <| by rintro (_ | _ | _) <;> dsimp <;> simp only [Category.comp_id, Category.id_comp, ← G.map_comp] #align category_theory.limits.is_colimit_map_cocone_pushout_cocone_equiv CategoryTheory.Limits.isColimitMapCoconePushoutCoconeEquiv /-- The property of preserving pushouts expressed in terms of binary cofans. -/ def isColimitPushoutCoconeMapOfIsColimit [PreservesColimit (span f g) G] (l : IsColimit (PushoutCocone.mk h k comm)) : IsColimit (PushoutCocone.mk (G.map h) (G.map k) (show G.map f ≫ G.map h = G.map g ≫ G.map k from by simp only [← G.map_comp,comm] )) := isColimitMapCoconePushoutCoconeEquiv G comm (PreservesColimit.preserves l) #align category_theory.limits.is_colimit_pushout_cocone_map_of_is_colimit CategoryTheory.Limits.isColimitPushoutCoconeMapOfIsColimit /-- The property of reflecting pushouts expressed in terms of binary cofans. -/ def isColimitOfIsColimitPushoutCoconeMap [ReflectsColimit (span f g) G] (l : IsColimit (PushoutCocone.mk (G.map h) (G.map k) (show G.map f ≫ G.map h = G.map g ≫ G.map k from by simp only [← G.map_comp,comm]))) : IsColimit (PushoutCocone.mk h k comm) := ReflectsColimit.reflects ((isColimitMapCoconePushoutCoconeEquiv G comm).symm l) #align category_theory.limits.is_colimit_of_is_colimit_pushout_cocone_map CategoryTheory.Limits.isColimitOfIsColimitPushoutCoconeMap variable (f g) [PreservesColimit (span f g) G] /-- If `G` preserves pushouts and `C` has them, then the pushout cocone constructed of the mapped morphisms of the pushout cocone is a colimit. -/ def isColimitOfHasPushoutOfPreservesColimit [i : HasPushout f g] : IsColimit (PushoutCocone.mk (G.map pushout.inl) (G.map (@pushout.inr _ _ _ _ _ f g i)) (show G.map f ≫ G.map pushout.inl = G.map g ≫ G.map pushout.inr from by simp only [← G.map_comp, pushout.condition])) := isColimitPushoutCoconeMapOfIsColimit G _ (pushoutIsPushout f g) #align category_theory.limits.is_colimit_of_has_pushout_of_preserves_colimit CategoryTheory.Limits.isColimitOfHasPushoutOfPreservesColimit /-- If `F` preserves the pushout of `f, g`, it also preserves the pushout of `g, f`. -/ def preservesPushoutSymmetry : PreservesColimit (span g f) G where preserves {c} hc := by apply (IsColimit.precomposeHomEquiv (diagramIsoSpan.{v₂} _).symm _).toFun apply IsColimit.ofIsoColimit _ (PushoutCocone.isoMk _).symm apply PushoutCocone.isColimitOfFlip apply (isColimitMapCoconePushoutCoconeEquiv _ _).toFun · refine @PreservesColimit.preserves _ _ _ _ _ _ _ _ ?_ _ ?_ -- Porting note: more TC coddling · dsimp infer_instance · exact PushoutCocone.flipIsColimit hc #align category_theory.limits.preserves_pushout_symmetry CategoryTheory.Limits.preservesPushoutSymmetry theorem hasPushout_of_preservesPushout [HasPushout f g] : HasPushout (G.map f) (G.map g) := ⟨⟨⟨_, isColimitPushoutCoconeMapOfIsColimit G _ (pushoutIsPushout _ _)⟩⟩⟩ #align category_theory.limits.has_pushout_of_preserves_pushout CategoryTheory.Limits.hasPushout_of_preservesPushout variable [HasPushout f g] [HasPushout (G.map f) (G.map g)] /-- If `G` preserves the pushout of `(f,g)`, then the pushout comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesPushout.iso : pushout (G.map f) (G.map g) ≅ G.obj (pushout f g) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitOfHasPushoutOfPreservesColimit G f g) #align category_theory.limits.preserves_pushout.iso CategoryTheory.Limits.PreservesPushout.iso @[simp] theorem PreservesPushout.iso_hom : (PreservesPushout.iso G f g).hom = pushoutComparison G f g := rfl #align category_theory.limits.preserves_pushout.iso_hom CategoryTheory.Limits.PreservesPushout.iso_hom @[reassoc]
Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean
225
228
theorem PreservesPushout.inl_iso_hom : pushout.inl ≫ (PreservesPushout.iso G f g).hom = G.map pushout.inl := by
delta PreservesPushout.iso simp
/- Copyright (c) 2021 Alex J. Best. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best, Yaël Dillies -/ import Mathlib.Algebra.Bounds import Mathlib.Algebra.Order.Field.Basic -- Porting note: `LinearOrderedField`, etc import Mathlib.Data.Set.Pointwise.SMul #align_import algebra.order.pointwise from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Pointwise operations on ordered algebraic objects This file contains lemmas about the effect of pointwise operations on sets with an order structure. ## TODO `sSup (s • t) = sSup s • sSup t` and `sInf (s • t) = sInf s • sInf t` hold as well but `CovariantClass` is currently not polymorphic enough to state it. -/ open Function Set open Pointwise variable {α : Type*} -- Porting note: Swapped the place of `CompleteLattice` and `ConditionallyCompleteLattice` -- due to simpNF problem between `sSup_xx` `csSup_xx`. section CompleteLattice variable [CompleteLattice α] section One variable [One α] @[to_additive (attr := simp)] theorem sSup_one : sSup (1 : Set α) = 1 := sSup_singleton #align Sup_zero sSup_zero #align Sup_one sSup_one @[to_additive (attr := simp)] theorem sInf_one : sInf (1 : Set α) = 1 := sInf_singleton #align Inf_zero sInf_zero #align Inf_one sInf_one end One section Group variable [Group α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (s t : Set α) @[to_additive] theorem sSup_inv (s : Set α) : sSup s⁻¹ = (sInf s)⁻¹ := by rw [← image_inv, sSup_image] exact ((OrderIso.inv α).map_sInf _).symm #align Sup_inv sSup_inv #align Sup_neg sSup_neg @[to_additive] theorem sInf_inv (s : Set α) : sInf s⁻¹ = (sSup s)⁻¹ := by rw [← image_inv, sInf_image] exact ((OrderIso.inv α).map_sSup _).symm #align Inf_inv sInf_inv #align Inf_neg sInf_neg @[to_additive] theorem sSup_mul : sSup (s * t) = sSup s * sSup t := (sSup_image2_eq_sSup_sSup fun _ => (OrderIso.mulRight _).to_galoisConnection) fun _ => (OrderIso.mulLeft _).to_galoisConnection #align Sup_mul sSup_mul #align Sup_add sSup_add @[to_additive] theorem sInf_mul : sInf (s * t) = sInf s * sInf t := (sInf_image2_eq_sInf_sInf fun _ => (OrderIso.mulRight _).symm.to_galoisConnection) fun _ => (OrderIso.mulLeft _).symm.to_galoisConnection #align Inf_mul sInf_mul #align Inf_add sInf_add @[to_additive] theorem sSup_div : sSup (s / t) = sSup s / sInf t := by simp_rw [div_eq_mul_inv, sSup_mul, sSup_inv] #align Sup_div sSup_div #align Sup_sub sSup_sub @[to_additive] theorem sInf_div : sInf (s / t) = sInf s / sSup t := by simp_rw [div_eq_mul_inv, sInf_mul, sInf_inv] #align Inf_div sInf_div #align Inf_sub sInf_sub end Group end CompleteLattice section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] section One variable [One α] @[to_additive (attr := simp)] theorem csSup_one : sSup (1 : Set α) = 1 := csSup_singleton _ #align cSup_zero csSup_zero #align cSup_one csSup_one @[to_additive (attr := simp)] theorem csInf_one : sInf (1 : Set α) = 1 := csInf_singleton _ #align cInf_zero csInf_zero #align cInf_one csInf_one end One section Group variable [Group α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {s t : Set α} @[to_additive] theorem csSup_inv (hs₀ : s.Nonempty) (hs₁ : BddBelow s) : sSup s⁻¹ = (sInf s)⁻¹ := by rw [← image_inv] exact ((OrderIso.inv α).map_csInf' hs₀ hs₁).symm #align cSup_inv csSup_inv #align cSup_neg csSup_neg @[to_additive] theorem csInf_inv (hs₀ : s.Nonempty) (hs₁ : BddAbove s) : sInf s⁻¹ = (sSup s)⁻¹ := by rw [← image_inv] exact ((OrderIso.inv α).map_csSup' hs₀ hs₁).symm #align cInf_inv csInf_inv #align cInf_neg csInf_neg @[to_additive] theorem csSup_mul (hs₀ : s.Nonempty) (hs₁ : BddAbove s) (ht₀ : t.Nonempty) (ht₁ : BddAbove t) : sSup (s * t) = sSup s * sSup t := csSup_image2_eq_csSup_csSup (fun _ => (OrderIso.mulRight _).to_galoisConnection) (fun _ => (OrderIso.mulLeft _).to_galoisConnection) hs₀ hs₁ ht₀ ht₁ #align cSup_mul csSup_mul #align cSup_add csSup_add @[to_additive] theorem csInf_mul (hs₀ : s.Nonempty) (hs₁ : BddBelow s) (ht₀ : t.Nonempty) (ht₁ : BddBelow t) : sInf (s * t) = sInf s * sInf t := csInf_image2_eq_csInf_csInf (fun _ => (OrderIso.mulRight _).symm.to_galoisConnection) (fun _ => (OrderIso.mulLeft _).symm.to_galoisConnection) hs₀ hs₁ ht₀ ht₁ #align cInf_mul csInf_mul #align cInf_add csInf_add @[to_additive]
Mathlib/Algebra/Order/Pointwise.lean
160
162
theorem csSup_div (hs₀ : s.Nonempty) (hs₁ : BddAbove s) (ht₀ : t.Nonempty) (ht₁ : BddBelow t) : sSup (s / t) = sSup s / sInf t := by
rw [div_eq_mul_inv, csSup_mul hs₀ hs₁ ht₀.inv ht₁.inv, csSup_inv ht₀ ht₁, div_eq_mul_inv]
/- 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]
Mathlib/NumberTheory/Padics/PadicIntegers.lean
303
303
theorem padic_norm_e_of_padicInt (z : ℤ_[p]) : ‖(z : ℚ_[p])‖ = ‖z‖ := by
simp [norm_def]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Algebra.Group.Int import Mathlib.Data.Int.Lemmas import Mathlib.Data.Set.Subsingleton import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Order.GaloisConnection import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity #align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c" /-! # Floor and ceil ## Summary We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. ## Main Definitions * `FloorSemiring`: An ordered semiring with natural-valued floor and ceil. * `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`. * `Nat.ceil a`: Least natural `n` such that `a ≤ n`. * `FloorRing`: A linearly ordered ring with integer-valued floor and ceil. * `Int.floor a`: Greatest integer `z` such that `z ≤ a`. * `Int.ceil a`: Least integer `z` such that `a ≤ z`. * `Int.fract a`: Fractional part of `a`, defined as `a - floor a`. * `round a`: Nearest integer to `a`. It rounds halves towards infinity. ## Notations * `⌊a⌋₊` is `Nat.floor a`. * `⌈a⌉₊` is `Nat.ceil a`. * `⌊a⌋` is `Int.floor a`. * `⌈a⌉` is `Int.ceil a`. The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation for `nnnorm`. ## TODO `LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in many lemmas. ## Tags rounding, floor, ceil -/ open Set variable {F α β : Type*} /-! ### Floor semiring -/ /-- A `FloorSemiring` is an ordered semiring over `α` with a function `floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`. Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/ class FloorSemiring (α) [OrderedSemiring α] where /-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/ floor : α → ℕ /-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/ ceil : α → ℕ /-- `FloorSemiring.floor` of a negative element is zero. -/ floor_of_neg {a : α} (ha : a < 0) : floor a = 0 /-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is smaller than `a`. -/ gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a /-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/ gc_ceil : GaloisConnection ceil (↑) #align floor_semiring FloorSemiring instance : FloorSemiring ℕ where floor := id ceil := id floor_of_neg ha := (Nat.not_lt_zero _ ha).elim gc_floor _ := by rw [Nat.cast_id] rfl gc_ceil n a := by rw [Nat.cast_id] rfl namespace Nat section OrderedSemiring variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} /-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/ def floor : α → ℕ := FloorSemiring.floor #align nat.floor Nat.floor /-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/ def ceil : α → ℕ := FloorSemiring.ceil #align nat.ceil Nat.ceil @[simp] theorem floor_nat : (Nat.floor : ℕ → ℕ) = id := rfl #align nat.floor_nat Nat.floor_nat @[simp] theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id := rfl #align nat.ceil_nat Nat.ceil_nat @[inherit_doc] notation "⌊" a "⌋₊" => Nat.floor a @[inherit_doc] notation "⌈" a "⌉₊" => Nat.ceil a end OrderedSemiring section LinearOrderedSemiring variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := FloorSemiring.gc_floor ha #align nat.le_floor_iff Nat.le_floor_iff theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ := (le_floor_iff <| n.cast_nonneg.trans h).2 h #align nat.le_floor Nat.le_floor theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff ha #align nat.floor_lt Nat.floor_lt theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 := (floor_lt ha).trans <| by rw [Nat.cast_one] #align nat.floor_lt_one Nat.floor_lt_one theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n := lt_of_not_le fun h' => (le_floor h').not_lt h #align nat.lt_of_floor_lt Nat.lt_of_floor_lt theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h #align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a := (le_floor_iff ha).1 le_rfl #align nat.floor_le Nat.floor_le theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ := lt_of_floor_lt <| Nat.lt_succ_self _ #align nat.lt_succ_floor Nat.lt_succ_floor theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a #align nat.lt_floor_add_one Nat.lt_floor_add_one @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n := eq_of_forall_le_iff fun a => by rw [le_floor_iff, Nat.cast_le] exact n.cast_nonneg #align nat.floor_coe Nat.floor_natCast @[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast] #align nat.floor_zero Nat.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast] #align nat.floor_one Nat.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n := Nat.floor_natCast _ theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 := ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by rintro rfl exact floor_zero #align nat.floor_of_nonpos Nat.floor_of_nonpos theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact le_floor ((floor_le ha).trans h) #align nat.floor_mono Nat.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact iff_of_false (Nat.pos_of_ne_zero hn).not_le (not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn) · exact le_floor_iff ha #align nat.le_floor_iff' Nat.le_floor_iff' @[simp] theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x := mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero #align nat.one_le_floor_iff Nat.one_le_floor_iff theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff' hn #align nat.floor_lt' Nat.floor_lt'
Mathlib/Algebra/Order/Floor.lean
221
223
theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by
-- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero` rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one]
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Group.Units import Mathlib.Algebra.Regular.Basic import Mathlib.GroupTheory.Congruence.Basic import Mathlib.Init.Data.Prod import Mathlib.RingTheory.OreLocalization.Basic #align_import group_theory.monoid_localization from "leanprover-community/mathlib"@"10ee941346c27bdb5e87bb3535100c0b1f08ac41" /-! # Localizations of commutative monoids Localizing a commutative ring at one of its submonoids does not rely on the ring's addition, so we can generalize localizations to commutative monoids. We characterize the localization of a commutative monoid `M` at a submonoid `S` up to isomorphism; that is, a commutative monoid `N` is the localization of `M` at `S` iff we can find a monoid homomorphism `f : M →* N` satisfying 3 properties: 1. For all `y ∈ S`, `f y` is a unit; 2. For all `z : N`, there exists `(x, y) : M × S` such that `z * f y = f x`; 3. For all `x, y : M` such that `f x = f y`, there exists `c ∈ S` such that `x * c = y * c`. (The converse is a consequence of 1.) Given such a localization map `f : M →* N`, we can define the surjection `Submonoid.LocalizationMap.mk'` sending `(x, y) : M × S` to `f x * (f y)⁻¹`, and `Submonoid.LocalizationMap.lift`, the homomorphism from `N` induced by a homomorphism from `M` which maps elements of `S` to invertible elements of the codomain. Similarly, given commutative monoids `P, Q`, a submonoid `T` of `P` and a localization map for `T` from `P` to `Q`, then a homomorphism `g : M →* P` such that `g(S) ⊆ T` induces a homomorphism of localizations, `LocalizationMap.map`, from `N` to `Q`. We treat the special case of localizing away from an element in the sections `AwayMap` and `Away`. We also define the quotient of `M × S` by the unique congruence relation (equivalence relation preserving a binary operation) `r` such that for any other congruence relation `s` on `M × S` satisfying '`∀ y ∈ S`, `(1, 1) ∼ (y, y)` under `s`', we have that `(x₁, y₁) ∼ (x₂, y₂)` by `s` whenever `(x₁, y₁) ∼ (x₂, y₂)` by `r`. We show this relation is equivalent to the standard localization relation. This defines the localization as a quotient type, `Localization`, but the majority of subsequent lemmas in the file are given in terms of localizations up to isomorphism, using maps which satisfy the characteristic predicate. The Grothendieck group construction corresponds to localizing at the top submonoid, namely making every element invertible. ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. The infimum form of the localization congruence relation is chosen as 'canonical' here, since it shortens some proofs. To apply a localization map `f` as a function, we use `f.toMap`, as coercions don't work well for this structure. To reason about the localization as a quotient type, use `mk_eq_monoidOf_mk'` and associated lemmas. These show the quotient map `mk : M → S → Localization S` equals the surjection `LocalizationMap.mk'` induced by the map `Localization.monoidOf : Submonoid.LocalizationMap S (Localization S)` (where `of` establishes the localization as a quotient type satisfies the characteristic predicate). The lemma `mk_eq_monoidOf_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. ## TODO * Show that the localization at the top monoid is a group. * Generalise to (nonempty) subsemigroups. * If we acquire more bundlings, we can make `Localization.mkOrderEmbedding` be an ordered monoid embedding. ## Tags localization, monoid localization, quotient monoid, congruence relation, characteristic predicate, commutative monoid, grothendieck group -/ open Function namespace AddSubmonoid variable {M : Type*} [AddCommMonoid M] (S : AddSubmonoid M) (N : Type*) [AddCommMonoid N] /-- The type of AddMonoid homomorphisms satisfying the characteristic predicate: if `f : M →+ N` satisfies this predicate, then `N` is isomorphic to the localization of `M` at `S`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure LocalizationMap extends AddMonoidHom M N where map_add_units' : ∀ y : S, IsAddUnit (toFun y) surj' : ∀ z : N, ∃ x : M × S, z + toFun x.2 = toFun x.1 exists_of_eq : ∀ x y, toFun x = toFun y → ∃ c : S, ↑c + x = ↑c + y #align add_submonoid.localization_map AddSubmonoid.LocalizationMap -- Porting note: no docstrings for AddSubmonoid.LocalizationMap attribute [nolint docBlame] AddSubmonoid.LocalizationMap.map_add_units' AddSubmonoid.LocalizationMap.surj' AddSubmonoid.LocalizationMap.exists_of_eq /-- The AddMonoidHom underlying a `LocalizationMap` of `AddCommMonoid`s. -/ add_decl_doc LocalizationMap.toAddMonoidHom end AddSubmonoid section CommMonoid variable {M : Type*} [CommMonoid M] (S : Submonoid M) (N : Type*) [CommMonoid N] {P : Type*} [CommMonoid P] namespace Submonoid /-- The type of monoid homomorphisms satisfying the characteristic predicate: if `f : M →* N` satisfies this predicate, then `N` is isomorphic to the localization of `M` at `S`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure LocalizationMap extends MonoidHom M N where map_units' : ∀ y : S, IsUnit (toFun y) surj' : ∀ z : N, ∃ x : M × S, z * toFun x.2 = toFun x.1 exists_of_eq : ∀ x y, toFun x = toFun y → ∃ c : S, ↑c * x = c * y #align submonoid.localization_map Submonoid.LocalizationMap -- Porting note: no docstrings for Submonoid.LocalizationMap attribute [nolint docBlame] Submonoid.LocalizationMap.map_units' Submonoid.LocalizationMap.surj' Submonoid.LocalizationMap.exists_of_eq attribute [to_additive] Submonoid.LocalizationMap -- Porting note: this translation already exists -- attribute [to_additive] Submonoid.LocalizationMap.toMonoidHom /-- The monoid hom underlying a `LocalizationMap`. -/ add_decl_doc LocalizationMap.toMonoidHom end Submonoid namespace Localization -- Porting note: this does not work so it is done explicitly instead -- run_cmd to_additive.map_namespace `Localization `AddLocalization -- run_cmd Elab.Command.liftCoreM <| ToAdditive.insertTranslation `Localization `AddLocalization /-- The congruence relation on `M × S`, `M` a `CommMonoid` and `S` a submonoid of `M`, whose quotient is the localization of `M` at `S`, defined as the unique congruence relation on `M × S` such that for any other congruence relation `s` on `M × S` where for all `y ∈ S`, `(1, 1) ∼ (y, y)` under `s`, we have that `(x₁, y₁) ∼ (x₂, y₂)` by `r` implies `(x₁, y₁) ∼ (x₂, y₂)` by `s`. -/ @[to_additive AddLocalization.r "The congruence relation on `M × S`, `M` an `AddCommMonoid` and `S` an `AddSubmonoid` of `M`, whose quotient is the localization of `M` at `S`, defined as the unique congruence relation on `M × S` such that for any other congruence relation `s` on `M × S` where for all `y ∈ S`, `(0, 0) ∼ (y, y)` under `s`, we have that `(x₁, y₁) ∼ (x₂, y₂)` by `r` implies `(x₁, y₁) ∼ (x₂, y₂)` by `s`."] def r (S : Submonoid M) : Con (M × S) := sInf { c | ∀ y : S, c 1 (y, y) } #align localization.r Localization.r #align add_localization.r AddLocalization.r /-- An alternate form of the congruence relation on `M × S`, `M` a `CommMonoid` and `S` a submonoid of `M`, whose quotient is the localization of `M` at `S`. -/ @[to_additive AddLocalization.r' "An alternate form of the congruence relation on `M × S`, `M` a `CommMonoid` and `S` a submonoid of `M`, whose quotient is the localization of `M` at `S`."] def r' : Con (M × S) := by -- note we multiply by `c` on the left so that we can later generalize to `•` refine { r := fun a b : M × S ↦ ∃ c : S, ↑c * (↑b.2 * a.1) = c * (a.2 * b.1) iseqv := ⟨fun a ↦ ⟨1, rfl⟩, fun ⟨c, hc⟩ ↦ ⟨c, hc.symm⟩, ?_⟩ mul' := ?_ } · rintro a b c ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ use t₂ * t₁ * b.2 simp only [Submonoid.coe_mul] calc (t₂ * t₁ * b.2 : M) * (c.2 * a.1) = t₂ * c.2 * (t₁ * (b.2 * a.1)) := by ac_rfl _ = t₁ * a.2 * (t₂ * (c.2 * b.1)) := by rw [ht₁]; ac_rfl _ = t₂ * t₁ * b.2 * (a.2 * c.1) := by rw [ht₂]; ac_rfl · rintro a b c d ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ use t₂ * t₁ calc (t₂ * t₁ : M) * (b.2 * d.2 * (a.1 * c.1)) = t₂ * (d.2 * c.1) * (t₁ * (b.2 * a.1)) := by ac_rfl _ = (t₂ * t₁ : M) * (a.2 * c.2 * (b.1 * d.1)) := by rw [ht₁, ht₂]; ac_rfl #align localization.r' Localization.r' #align add_localization.r' AddLocalization.r' /-- The congruence relation used to localize a `CommMonoid` at a submonoid can be expressed equivalently as an infimum (see `Localization.r`) or explicitly (see `Localization.r'`). -/ @[to_additive AddLocalization.r_eq_r' "The additive congruence relation used to localize an `AddCommMonoid` at a submonoid can be expressed equivalently as an infimum (see `AddLocalization.r`) or explicitly (see `AddLocalization.r'`)."] theorem r_eq_r' : r S = r' S := le_antisymm (sInf_le fun _ ↦ ⟨1, by simp⟩) <| le_sInf fun b H ⟨p, q⟩ ⟨x, y⟩ ⟨t, ht⟩ ↦ by rw [← one_mul (p, q), ← one_mul (x, y)] refine b.trans (b.mul (H (t * y)) (b.refl _)) ?_ convert b.symm (b.mul (H (t * q)) (b.refl (x, y))) using 1 dsimp only [Prod.mk_mul_mk, Submonoid.coe_mul] at ht ⊢ simp_rw [mul_assoc, ht, mul_comm y q] #align localization.r_eq_r' Localization.r_eq_r' #align add_localization.r_eq_r' AddLocalization.r_eq_r' variable {S} @[to_additive AddLocalization.r_iff_exists] theorem r_iff_exists {x y : M × S} : r S x y ↔ ∃ c : S, ↑c * (↑y.2 * x.1) = c * (x.2 * y.1) := by rw [r_eq_r' S]; rfl #align localization.r_iff_exists Localization.r_iff_exists #align add_localization.r_iff_exists AddLocalization.r_iff_exists end Localization /-- The localization of a `CommMonoid` at one of its submonoids (as a quotient type). -/ @[to_additive AddLocalization "The localization of an `AddCommMonoid` at one of its submonoids (as a quotient type)."] def Localization := (Localization.r S).Quotient #align localization Localization #align add_localization AddLocalization namespace Localization @[to_additive] instance inhabited : Inhabited (Localization S) := Con.Quotient.inhabited #align localization.inhabited Localization.inhabited #align add_localization.inhabited AddLocalization.inhabited /-- Multiplication in a `Localization` is defined as `⟨a, b⟩ * ⟨c, d⟩ = ⟨a * c, b * d⟩`. -/ @[to_additive "Addition in an `AddLocalization` is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨a + c, b + d⟩`. Should not be confused with the ring localization counterpart `Localization.add`, which maps `⟨a, b⟩ + ⟨c, d⟩` to `⟨d * a + b * c, b * d⟩`."] protected irreducible_def mul : Localization S → Localization S → Localization S := (r S).commMonoid.mul #align localization.mul Localization.mul #align add_localization.add AddLocalization.add @[to_additive] instance : Mul (Localization S) := ⟨Localization.mul S⟩ /-- The identity element of a `Localization` is defined as `⟨1, 1⟩`. -/ @[to_additive "The identity element of an `AddLocalization` is defined as `⟨0, 0⟩`. Should not be confused with the ring localization counterpart `Localization.zero`, which is defined as `⟨0, 1⟩`."] protected irreducible_def one : Localization S := (r S).commMonoid.one #align localization.one Localization.one #align add_localization.zero AddLocalization.zero @[to_additive] instance : One (Localization S) := ⟨Localization.one S⟩ /-- Exponentiation in a `Localization` is defined as `⟨a, b⟩ ^ n = ⟨a ^ n, b ^ n⟩`. This is a separate `irreducible` def to ensure the elaborator doesn't waste its time trying to unify some huge recursive definition with itself, but unfolded one step less. -/ @[to_additive "Multiplication with a natural in an `AddLocalization` is defined as `n • ⟨a, b⟩ = ⟨n • a, n • b⟩`. This is a separate `irreducible` def to ensure the elaborator doesn't waste its time trying to unify some huge recursive definition with itself, but unfolded one step less."] protected irreducible_def npow : ℕ → Localization S → Localization S := (r S).commMonoid.npow #align localization.npow Localization.npow #align add_localization.nsmul AddLocalization.nsmul @[to_additive] instance commMonoid : CommMonoid (Localization S) where mul := (· * ·) one := 1 mul_assoc x y z := show (x.mul S y).mul S z = x.mul S (y.mul S z) by rw [Localization.mul]; apply (r S).commMonoid.mul_assoc mul_comm x y := show x.mul S y = y.mul S x by rw [Localization.mul]; apply (r S).commMonoid.mul_comm mul_one x := show x.mul S (.one S) = x by rw [Localization.mul, Localization.one]; apply (r S).commMonoid.mul_one one_mul x := show (Localization.one S).mul S x = x by rw [Localization.mul, Localization.one]; apply (r S).commMonoid.one_mul npow := Localization.npow S npow_zero x := show Localization.npow S 0 x = .one S by rw [Localization.npow, Localization.one]; apply (r S).commMonoid.npow_zero npow_succ n x := show Localization.npow S n.succ x = (Localization.npow S n x).mul S x by rw [Localization.npow, Localization.mul]; apply (r S).commMonoid.npow_succ variable {S} /-- Given a `CommMonoid` `M` and submonoid `S`, `mk` sends `x : M`, `y ∈ S` to the equivalence class of `(x, y)` in the localization of `M` at `S`. -/ @[to_additive "Given an `AddCommMonoid` `M` and submonoid `S`, `mk` sends `x : M`, `y ∈ S` to the equivalence class of `(x, y)` in the localization of `M` at `S`."] def mk (x : M) (y : S) : Localization S := (r S).mk' (x, y) #align localization.mk Localization.mk #align add_localization.mk AddLocalization.mk @[to_additive] theorem mk_eq_mk_iff {a c : M} {b d : S} : mk a b = mk c d ↔ r S ⟨a, b⟩ ⟨c, d⟩ := (r S).eq #align localization.mk_eq_mk_iff Localization.mk_eq_mk_iff #align add_localization.mk_eq_mk_iff AddLocalization.mk_eq_mk_iff universe u /-- Dependent recursion principle for `Localizations`: given elements `f a b : p (mk a b)` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d` (with the correct coercions), then `f` is defined on the whole `Localization S`. -/ @[to_additive (attr := elab_as_elim) "Dependent recursion principle for `AddLocalizations`: given elements `f a b : p (mk a b)` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d` (with the correct coercions), then `f` is defined on the whole `AddLocalization S`."] def rec {p : Localization S → Sort u} (f : ∀ (a : M) (b : S), p (mk a b)) (H : ∀ {a c : M} {b d : S} (h : r S (a, b) (c, d)), (Eq.ndrec (f a b) (mk_eq_mk_iff.mpr h) : p (mk c d)) = f c d) (x) : p x := Quot.rec (fun y ↦ Eq.ndrec (f y.1 y.2) (by rfl)) (fun y z h ↦ by cases y; cases z; exact H h) x #align localization.rec Localization.rec #align add_localization.rec AddLocalization.rec /-- Copy of `Quotient.recOnSubsingleton₂` for `Localization` -/ @[to_additive (attr := elab_as_elim) "Copy of `Quotient.recOnSubsingleton₂` for `AddLocalization`"] def recOnSubsingleton₂ {r : Localization S → Localization S → Sort u} [h : ∀ (a c : M) (b d : S), Subsingleton (r (mk a b) (mk c d))] (x y : Localization S) (f : ∀ (a c : M) (b d : S), r (mk a b) (mk c d)) : r x y := @Quotient.recOnSubsingleton₂' _ _ _ _ r (Prod.rec fun _ _ => Prod.rec fun _ _ => h _ _ _ _) x y (Prod.rec fun _ _ => Prod.rec fun _ _ => f _ _ _ _) #align localization.rec_on_subsingleton₂ Localization.recOnSubsingleton₂ #align add_localization.rec_on_subsingleton₂ AddLocalization.recOnSubsingleton₂ @[to_additive] theorem mk_mul (a c : M) (b d : S) : mk a b * mk c d = mk (a * c) (b * d) := show Localization.mul S _ _ = _ by rw [Localization.mul]; rfl #align localization.mk_mul Localization.mk_mul #align add_localization.mk_add AddLocalization.mk_add @[to_additive] theorem mk_one : mk 1 (1 : S) = 1 := show mk _ _ = .one S by rw [Localization.one]; rfl #align localization.mk_one Localization.mk_one #align add_localization.mk_zero AddLocalization.mk_zero @[to_additive] theorem mk_pow (n : ℕ) (a : M) (b : S) : mk a b ^ n = mk (a ^ n) (b ^ n) := show Localization.npow S _ _ = _ by rw [Localization.npow]; rfl #align localization.mk_pow Localization.mk_pow #align add_localization.mk_nsmul AddLocalization.mk_nsmul -- Porting note: mathport translated `rec` to `ndrec` in the name of this lemma @[to_additive (attr := simp)] theorem ndrec_mk {p : Localization S → Sort u} (f : ∀ (a : M) (b : S), p (mk a b)) (H) (a : M) (b : S) : (rec f H (mk a b) : p (mk a b)) = f a b := rfl #align localization.rec_mk Localization.ndrec_mk #align add_localization.rec_mk AddLocalization.ndrec_mk /-- Non-dependent recursion principle for localizations: given elements `f a b : p` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d`, then `f` is defined on the whole `Localization S`. -/ -- Porting note: the attribute `elab_as_elim` fails with `unexpected eliminator resulting type p` -- @[to_additive (attr := elab_as_elim) @[to_additive "Non-dependent recursion principle for `AddLocalization`s: given elements `f a b : p` for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d`, then `f` is defined on the whole `Localization S`."] def liftOn {p : Sort u} (x : Localization S) (f : M → S → p) (H : ∀ {a c : M} {b d : S}, r S (a, b) (c, d) → f a b = f c d) : p := rec f (fun h ↦ (by simpa only [eq_rec_constant] using H h)) x #align localization.lift_on Localization.liftOn #align add_localization.lift_on AddLocalization.liftOn @[to_additive] theorem liftOn_mk {p : Sort u} (f : M → S → p) (H) (a : M) (b : S) : liftOn (mk a b) f H = f a b := rfl #align localization.lift_on_mk Localization.liftOn_mk #align add_localization.lift_on_mk AddLocalization.liftOn_mk @[to_additive (attr := elab_as_elim)] theorem ind {p : Localization S → Prop} (H : ∀ y : M × S, p (mk y.1 y.2)) (x) : p x := rec (fun a b ↦ H (a, b)) (fun _ ↦ rfl) x #align localization.ind Localization.ind #align add_localization.ind AddLocalization.ind @[to_additive (attr := elab_as_elim)] theorem induction_on {p : Localization S → Prop} (x) (H : ∀ y : M × S, p (mk y.1 y.2)) : p x := ind H x #align localization.induction_on Localization.induction_on #align add_localization.induction_on AddLocalization.induction_on /-- Non-dependent recursion principle for localizations: given elements `f x y : p` for all `x` and `y`, such that `r S x x'` and `r S y y'` implies `f x y = f x' y'`, then `f` is defined on the whole `Localization S`. -/ -- Porting note: the attribute `elab_as_elim` fails with `unexpected eliminator resulting type p` -- @[to_additive (attr := elab_as_elim) @[to_additive "Non-dependent recursion principle for localizations: given elements `f x y : p` for all `x` and `y`, such that `r S x x'` and `r S y y'` implies `f x y = f x' y'`, then `f` is defined on the whole `Localization S`."] def liftOn₂ {p : Sort u} (x y : Localization S) (f : M → S → M → S → p) (H : ∀ {a a' b b' c c' d d'}, r S (a, b) (a', b') → r S (c, d) (c', d') → f a b c d = f a' b' c' d') : p := liftOn x (fun a b ↦ liftOn y (f a b) fun hy ↦ H ((r S).refl _) hy) fun hx ↦ induction_on y fun ⟨_, _⟩ ↦ H hx ((r S).refl _) #align localization.lift_on₂ Localization.liftOn₂ #align add_localization.lift_on₂ AddLocalization.liftOn₂ @[to_additive] theorem liftOn₂_mk {p : Sort*} (f : M → S → M → S → p) (H) (a c : M) (b d : S) : liftOn₂ (mk a b) (mk c d) f H = f a b c d := rfl #align localization.lift_on₂_mk Localization.liftOn₂_mk #align add_localization.lift_on₂_mk AddLocalization.liftOn₂_mk @[to_additive (attr := elab_as_elim)] theorem induction_on₂ {p : Localization S → Localization S → Prop} (x y) (H : ∀ x y : M × S, p (mk x.1 x.2) (mk y.1 y.2)) : p x y := induction_on x fun x ↦ induction_on y <| H x #align localization.induction_on₂ Localization.induction_on₂ #align add_localization.induction_on₂ AddLocalization.induction_on₂ @[to_additive (attr := elab_as_elim)] theorem induction_on₃ {p : Localization S → Localization S → Localization S → Prop} (x y z) (H : ∀ x y z : M × S, p (mk x.1 x.2) (mk y.1 y.2) (mk z.1 z.2)) : p x y z := induction_on₂ x y fun x y ↦ induction_on z <| H x y #align localization.induction_on₃ Localization.induction_on₃ #align add_localization.induction_on₃ AddLocalization.induction_on₃ @[to_additive] theorem one_rel (y : S) : r S 1 (y, y) := fun _ hb ↦ hb y #align localization.one_rel Localization.one_rel #align add_localization.zero_rel AddLocalization.zero_rel @[to_additive] theorem r_of_eq {x y : M × S} (h : ↑y.2 * x.1 = ↑x.2 * y.1) : r S x y := r_iff_exists.2 ⟨1, by rw [h]⟩ #align localization.r_of_eq Localization.r_of_eq #align add_localization.r_of_eq AddLocalization.r_of_eq @[to_additive] theorem mk_self (a : S) : mk (a : M) a = 1 := by symm rw [← mk_one, mk_eq_mk_iff] exact one_rel a #align localization.mk_self Localization.mk_self #align add_localization.mk_self AddLocalization.mk_self section Scalar variable {R R₁ R₂ : Type*} /-- Scalar multiplication in a monoid localization is defined as `c • ⟨a, b⟩ = ⟨c • a, b⟩`. -/ protected irreducible_def smul [SMul R M] [IsScalarTower R M M] (c : R) (z : Localization S) : Localization S := Localization.liftOn z (fun a b ↦ mk (c • a) b) (fun {a a' b b'} h ↦ mk_eq_mk_iff.2 (by let ⟨b, hb⟩ := b let ⟨b', hb'⟩ := b' rw [r_eq_r'] at h ⊢ let ⟨t, ht⟩ := h use t dsimp only [Subtype.coe_mk] at ht ⊢ -- TODO: this definition should take `SMulCommClass R M M` instead of `IsScalarTower R M M` if -- we ever want to generalize to the non-commutative case. haveI : SMulCommClass R M M := ⟨fun r m₁ m₂ ↦ by simp_rw [smul_eq_mul, mul_comm m₁, smul_mul_assoc]⟩ simp only [mul_smul_comm, ht])) #align localization.smul Localization.smul instance instSMulLocalization [SMul R M] [IsScalarTower R M M] : SMul R (Localization S) where smul := Localization.smul theorem smul_mk [SMul R M] [IsScalarTower R M M] (c : R) (a b) : c • (mk a b : Localization S) = mk (c • a) b := by simp only [HSMul.hSMul, instHSMul, SMul.smul, instSMulLocalization, Localization.smul] show liftOn (mk a b) (fun a b => mk (c • a) b) _ = _ exact liftOn_mk (fun a b => mk (c • a) b) _ a b #align localization.smul_mk Localization.smul_mk instance [SMul R₁ M] [SMul R₂ M] [IsScalarTower R₁ M M] [IsScalarTower R₂ M M] [SMulCommClass R₁ R₂ M] : SMulCommClass R₁ R₂ (Localization S) where smul_comm s t := Localization.ind <| Prod.rec fun r x ↦ by simp only [smul_mk, smul_comm s t r] instance [SMul R₁ M] [SMul R₂ M] [IsScalarTower R₁ M M] [IsScalarTower R₂ M M] [SMul R₁ R₂] [IsScalarTower R₁ R₂ M] : IsScalarTower R₁ R₂ (Localization S) where smul_assoc s t := Localization.ind <| Prod.rec fun r x ↦ by simp only [smul_mk, smul_assoc s t r] instance smulCommClass_right {R : Type*} [SMul R M] [IsScalarTower R M M] : SMulCommClass R (Localization S) (Localization S) where smul_comm s := Localization.ind <| Prod.rec fun r₁ x₁ ↦ Localization.ind <| Prod.rec fun r₂ x₂ ↦ by simp only [smul_mk, smul_eq_mul, mk_mul, mul_comm r₁, smul_mul_assoc] #align localization.smul_comm_class_right Localization.smulCommClass_right instance isScalarTower_right {R : Type*} [SMul R M] [IsScalarTower R M M] : IsScalarTower R (Localization S) (Localization S) where smul_assoc s := Localization.ind <| Prod.rec fun r₁ x₁ ↦ Localization.ind <| Prod.rec fun r₂ x₂ ↦ by simp only [smul_mk, smul_eq_mul, mk_mul, smul_mul_assoc] #align localization.is_scalar_tower_right Localization.isScalarTower_right instance [SMul R M] [SMul Rᵐᵒᵖ M] [IsScalarTower R M M] [IsScalarTower Rᵐᵒᵖ M M] [IsCentralScalar R M] : IsCentralScalar R (Localization S) where op_smul_eq_smul s := Localization.ind <| Prod.rec fun r x ↦ by simp only [smul_mk, op_smul_eq_smul] instance [Monoid R] [MulAction R M] [IsScalarTower R M M] : MulAction R (Localization S) where one_smul := Localization.ind <| Prod.rec <| by intros simp only [Localization.smul_mk, one_smul] mul_smul s₁ s₂ := Localization.ind <| Prod.rec <| by intros simp only [Localization.smul_mk, mul_smul] instance [Monoid R] [MulDistribMulAction R M] [IsScalarTower R M M] : MulDistribMulAction R (Localization S) where smul_one s := by simp only [← Localization.mk_one, Localization.smul_mk, smul_one] smul_mul s x y := Localization.induction_on₂ x y <| Prod.rec fun r₁ x₁ ↦ Prod.rec fun r₂ x₂ ↦ by simp only [Localization.smul_mk, Localization.mk_mul, smul_mul'] end Scalar end Localization variable {S N} namespace MonoidHom /-- Makes a localization map from a `CommMonoid` hom satisfying the characteristic predicate. -/ @[to_additive "Makes a localization map from an `AddCommMonoid` hom satisfying the characteristic predicate."] def toLocalizationMap (f : M →* N) (H1 : ∀ y : S, IsUnit (f y)) (H2 : ∀ z, ∃ x : M × S, z * f x.2 = f x.1) (H3 : ∀ x y, f x = f y → ∃ c : S, ↑c * x = ↑c * y) : Submonoid.LocalizationMap S N := { f with map_units' := H1 surj' := H2 exists_of_eq := H3 } #align monoid_hom.to_localization_map MonoidHom.toLocalizationMap #align add_monoid_hom.to_localization_map AddMonoidHom.toLocalizationMap end MonoidHom namespace Submonoid namespace LocalizationMap /-- Short for `toMonoidHom`; used to apply a localization map as a function. -/ @[to_additive "Short for `toAddMonoidHom`; used to apply a localization map as a function."] abbrev toMap (f : LocalizationMap S N) := f.toMonoidHom #align submonoid.localization_map.to_map Submonoid.LocalizationMap.toMap #align add_submonoid.localization_map.to_map AddSubmonoid.LocalizationMap.toMap @[to_additive (attr := ext)] theorem ext {f g : LocalizationMap S N} (h : ∀ x, f.toMap x = g.toMap x) : f = g := by rcases f with ⟨⟨⟩⟩ rcases g with ⟨⟨⟩⟩ simp only [mk.injEq, MonoidHom.mk.injEq] exact OneHom.ext h #align submonoid.localization_map.ext Submonoid.LocalizationMap.ext #align add_submonoid.localization_map.ext AddSubmonoid.LocalizationMap.ext @[to_additive] theorem ext_iff {f g : LocalizationMap S N} : f = g ↔ ∀ x, f.toMap x = g.toMap x := ⟨fun h _ ↦ h ▸ rfl, ext⟩ #align submonoid.localization_map.ext_iff Submonoid.LocalizationMap.ext_iff #align add_submonoid.localization_map.ext_iff AddSubmonoid.LocalizationMap.ext_iff @[to_additive] theorem toMap_injective : Function.Injective (@LocalizationMap.toMap _ _ S N _) := fun _ _ h ↦ ext <| DFunLike.ext_iff.1 h #align submonoid.localization_map.to_map_injective Submonoid.LocalizationMap.toMap_injective #align add_submonoid.localization_map.to_map_injective AddSubmonoid.LocalizationMap.toMap_injective @[to_additive] theorem map_units (f : LocalizationMap S N) (y : S) : IsUnit (f.toMap y) := f.2 y #align submonoid.localization_map.map_units Submonoid.LocalizationMap.map_units #align add_submonoid.localization_map.map_add_units AddSubmonoid.LocalizationMap.map_addUnits @[to_additive] theorem surj (f : LocalizationMap S N) (z : N) : ∃ x : M × S, z * f.toMap x.2 = f.toMap x.1 := f.3 z #align submonoid.localization_map.surj Submonoid.LocalizationMap.surj #align add_submonoid.localization_map.surj AddSubmonoid.LocalizationMap.surj /-- Given a localization map `f : M →* N`, and `z w : N`, there exist `z' w' : M` and `d : S` such that `f z' / f d = z` and `f w' / f d = w`. -/ @[to_additive "Given a localization map `f : M →+ N`, and `z w : N`, there exist `z' w' : M` and `d : S` such that `f z' - f d = z` and `f w' - f d = w`."] theorem surj₂ (f : LocalizationMap S N) (z w : N) : ∃ z' w' : M, ∃ d : S, (z * f.toMap d = f.toMap z') ∧ (w * f.toMap d = f.toMap w') := by let ⟨a, ha⟩ := surj f z let ⟨b, hb⟩ := surj f w refine ⟨a.1 * b.2, a.2 * b.1, a.2 * b.2, ?_, ?_⟩ · simp_rw [mul_def, map_mul, ← ha] exact (mul_assoc z _ _).symm · simp_rw [mul_def, map_mul, ← hb] exact mul_left_comm w _ _ @[to_additive] theorem eq_iff_exists (f : LocalizationMap S N) {x y} : f.toMap x = f.toMap y ↔ ∃ c : S, ↑c * x = c * y := Iff.intro (f.4 x y) fun ⟨c, h⟩ ↦ by replace h := congr_arg f.toMap h rw [map_mul, map_mul] at h exact (f.map_units c).mul_right_inj.mp h #align submonoid.localization_map.eq_iff_exists Submonoid.LocalizationMap.eq_iff_exists #align add_submonoid.localization_map.eq_iff_exists AddSubmonoid.LocalizationMap.eq_iff_exists /-- Given a localization map `f : M →* N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/ @[to_additive "Given a localization map `f : M →+ N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x - f y = z`."] noncomputable def sec (f : LocalizationMap S N) (z : N) : M × S := Classical.choose <| f.surj z #align submonoid.localization_map.sec Submonoid.LocalizationMap.sec #align add_submonoid.localization_map.sec AddSubmonoid.LocalizationMap.sec @[to_additive] theorem sec_spec {f : LocalizationMap S N} (z : N) : z * f.toMap (f.sec z).2 = f.toMap (f.sec z).1 := Classical.choose_spec <| f.surj z #align submonoid.localization_map.sec_spec Submonoid.LocalizationMap.sec_spec #align add_submonoid.localization_map.sec_spec AddSubmonoid.LocalizationMap.sec_spec @[to_additive] theorem sec_spec' {f : LocalizationMap S N} (z : N) : f.toMap (f.sec z).1 = f.toMap (f.sec z).2 * z := by rw [mul_comm, sec_spec] #align submonoid.localization_map.sec_spec' Submonoid.LocalizationMap.sec_spec' #align add_submonoid.localization_map.sec_spec' AddSubmonoid.LocalizationMap.sec_spec' /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `w, z : N` and `y ∈ S`, we have `w * (f y)⁻¹ = z ↔ w = f y * z`. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `w, z : N` and `y ∈ S`, we have `w - f y = z ↔ w = f y + z`."] theorem mul_inv_left {f : M →* N} (h : ∀ y : S, IsUnit (f y)) (y : S) (w z : N) : w * (IsUnit.liftRight (f.restrict S) h y)⁻¹ = z ↔ w = f y * z := by rw [mul_comm] exact Units.inv_mul_eq_iff_eq_mul (IsUnit.liftRight (f.restrict S) h y) #align submonoid.localization_map.mul_inv_left Submonoid.LocalizationMap.mul_inv_left #align add_submonoid.localization_map.add_neg_left AddSubmonoid.LocalizationMap.add_neg_left /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `w, z : N` and `y ∈ S`, we have `z = w * (f y)⁻¹ ↔ z * f y = w`. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `w, z : N` and `y ∈ S`, we have `z = w - f y ↔ z + f y = w`."] theorem mul_inv_right {f : M →* N} (h : ∀ y : S, IsUnit (f y)) (y : S) (w z : N) : z = w * (IsUnit.liftRight (f.restrict S) h y)⁻¹ ↔ z * f y = w := by rw [eq_comm, mul_inv_left h, mul_comm, eq_comm] #align submonoid.localization_map.mul_inv_right Submonoid.LocalizationMap.mul_inv_right #align add_submonoid.localization_map.add_neg_right AddSubmonoid.LocalizationMap.add_neg_right /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `x₁ x₂ : M` and `y₁, y₂ ∈ S`, we have `f x₁ * (f y₁)⁻¹ = f x₂ * (f y₂)⁻¹ ↔ f (x₁ * y₂) = f (x₂ * y₁)`. -/ @[to_additive (attr := simp) "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `x₁ x₂ : M` and `y₁, y₂ ∈ S`, we have `f x₁ - f y₁ = f x₂ - f y₂ ↔ f (x₁ + y₂) = f (x₂ + y₁)`."] theorem mul_inv {f : M →* N} (h : ∀ y : S, IsUnit (f y)) {x₁ x₂} {y₁ y₂ : S} : f x₁ * (IsUnit.liftRight (f.restrict S) h y₁)⁻¹ = f x₂ * (IsUnit.liftRight (f.restrict S) h y₂)⁻¹ ↔ f (x₁ * y₂) = f (x₂ * y₁) := by rw [mul_inv_right h, mul_assoc, mul_comm _ (f y₂), ← mul_assoc, mul_inv_left h, mul_comm x₂, f.map_mul, f.map_mul] #align submonoid.localization_map.mul_inv Submonoid.LocalizationMap.mul_inv #align add_submonoid.localization_map.add_neg AddSubmonoid.LocalizationMap.add_neg /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `y, z ∈ S`, we have `(f y)⁻¹ = (f z)⁻¹ → f y = f z`. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `y, z ∈ S`, we have `- (f y) = - (f z) → f y = f z`."] theorem inv_inj {f : M →* N} (hf : ∀ y : S, IsUnit (f y)) {y z : S} (h : (IsUnit.liftRight (f.restrict S) hf y)⁻¹ = (IsUnit.liftRight (f.restrict S) hf z)⁻¹) : f y = f z := by rw [← mul_one (f y), eq_comm, ← mul_inv_left hf y (f z) 1, h] exact Units.inv_mul (IsUnit.liftRight (f.restrict S) hf z)⁻¹ #align submonoid.localization_map.inv_inj Submonoid.LocalizationMap.inv_inj #align add_submonoid.localization_map.neg_inj AddSubmonoid.LocalizationMap.neg_inj /-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all `y ∈ S`, `(f y)⁻¹` is unique. -/ @[to_additive "Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that `f(S) ⊆ AddUnits N`, for all `y ∈ S`, `- (f y)` is unique."] theorem inv_unique {f : M →* N} (h : ∀ y : S, IsUnit (f y)) {y : S} {z : N} (H : f y * z = 1) : (IsUnit.liftRight (f.restrict S) h y)⁻¹ = z := by rw [← one_mul _⁻¹, Units.val_mul, mul_inv_left] exact H.symm #align submonoid.localization_map.inv_unique Submonoid.LocalizationMap.inv_unique #align add_submonoid.localization_map.neg_unique AddSubmonoid.LocalizationMap.neg_unique variable (f : LocalizationMap S N) @[to_additive] theorem map_right_cancel {x y} {c : S} (h : f.toMap (c * x) = f.toMap (c * y)) : f.toMap x = f.toMap y := by rw [f.toMap.map_mul, f.toMap.map_mul] at h let ⟨u, hu⟩ := f.map_units c rw [← hu] at h exact (Units.mul_right_inj u).1 h #align submonoid.localization_map.map_right_cancel Submonoid.LocalizationMap.map_right_cancel #align add_submonoid.localization_map.map_right_cancel AddSubmonoid.LocalizationMap.map_right_cancel @[to_additive] theorem map_left_cancel {x y} {c : S} (h : f.toMap (x * c) = f.toMap (y * c)) : f.toMap x = f.toMap y := f.map_right_cancel <| by rw [mul_comm _ x, mul_comm _ y, h] #align submonoid.localization_map.map_left_cancel Submonoid.LocalizationMap.map_left_cancel #align add_submonoid.localization_map.map_left_cancel AddSubmonoid.LocalizationMap.map_left_cancel /-- Given a localization map `f : M →* N`, the surjection sending `(x, y) : M × S` to `f x * (f y)⁻¹`. -/ @[to_additive "Given a localization map `f : M →+ N`, the surjection sending `(x, y) : M × S` to `f x - f y`."] noncomputable def mk' (f : LocalizationMap S N) (x : M) (y : S) : N := f.toMap x * ↑(IsUnit.liftRight (f.toMap.restrict S) f.map_units y)⁻¹ #align submonoid.localization_map.mk' Submonoid.LocalizationMap.mk' #align add_submonoid.localization_map.mk' AddSubmonoid.LocalizationMap.mk' @[to_additive] theorem mk'_mul (x₁ x₂ : M) (y₁ y₂ : S) : f.mk' (x₁ * x₂) (y₁ * y₂) = f.mk' x₁ y₁ * f.mk' x₂ y₂ := (mul_inv_left f.map_units _ _ _).2 <| show _ = _ * (_ * _ * (_ * _)) by rw [← mul_assoc, ← mul_assoc, mul_inv_right f.map_units, mul_assoc, mul_assoc, mul_comm _ (f.toMap x₂), ← mul_assoc, ← mul_assoc, mul_inv_right f.map_units, Submonoid.coe_mul, f.toMap.map_mul, f.toMap.map_mul] ac_rfl #align submonoid.localization_map.mk'_mul Submonoid.LocalizationMap.mk'_mul #align add_submonoid.localization_map.mk'_add AddSubmonoid.LocalizationMap.mk'_add @[to_additive] theorem mk'_one (x) : f.mk' x (1 : S) = f.toMap x := by rw [mk', MonoidHom.map_one] exact mul_one _ #align submonoid.localization_map.mk'_one Submonoid.LocalizationMap.mk'_one #align add_submonoid.localization_map.mk'_zero AddSubmonoid.LocalizationMap.mk'_zero /-- Given a localization map `f : M →* N` for a submonoid `S ⊆ M`, for all `z : N` we have that if `x : M, y ∈ S` are such that `z * f y = f x`, then `f x * (f y)⁻¹ = z`. -/ @[to_additive (attr := simp) "Given a localization map `f : M →+ N` for a Submonoid `S ⊆ M`, for all `z : N` we have that if `x : M, y ∈ S` are such that `z + f y = f x`, then `f x - f y = z`."] theorem mk'_sec (z : N) : f.mk' (f.sec z).1 (f.sec z).2 = z := show _ * _ = _ by rw [← sec_spec, mul_inv_left, mul_comm] #align submonoid.localization_map.mk'_sec Submonoid.LocalizationMap.mk'_sec #align add_submonoid.localization_map.mk'_sec AddSubmonoid.LocalizationMap.mk'_sec @[to_additive] theorem mk'_surjective (z : N) : ∃ (x : _) (y : S), f.mk' x y = z := ⟨(f.sec z).1, (f.sec z).2, f.mk'_sec z⟩ #align submonoid.localization_map.mk'_surjective Submonoid.LocalizationMap.mk'_surjective #align add_submonoid.localization_map.mk'_surjective AddSubmonoid.LocalizationMap.mk'_surjective @[to_additive] theorem mk'_spec (x) (y : S) : f.mk' x y * f.toMap y = f.toMap x := show _ * _ * _ = _ by rw [mul_assoc, mul_comm _ (f.toMap y), ← mul_assoc, mul_inv_left, mul_comm] #align submonoid.localization_map.mk'_spec Submonoid.LocalizationMap.mk'_spec #align add_submonoid.localization_map.mk'_spec AddSubmonoid.LocalizationMap.mk'_spec @[to_additive] theorem mk'_spec' (x) (y : S) : f.toMap y * f.mk' x y = f.toMap x := by rw [mul_comm, mk'_spec] #align submonoid.localization_map.mk'_spec' Submonoid.LocalizationMap.mk'_spec' #align add_submonoid.localization_map.mk'_spec' AddSubmonoid.LocalizationMap.mk'_spec' @[to_additive] theorem eq_mk'_iff_mul_eq {x} {y : S} {z} : z = f.mk' x y ↔ z * f.toMap y = f.toMap x := ⟨fun H ↦ by rw [H, mk'_spec], fun H ↦ by erw [mul_inv_right, H]⟩ #align submonoid.localization_map.eq_mk'_iff_mul_eq Submonoid.LocalizationMap.eq_mk'_iff_mul_eq #align add_submonoid.localization_map.eq_mk'_iff_add_eq AddSubmonoid.LocalizationMap.eq_mk'_iff_add_eq @[to_additive] theorem mk'_eq_iff_eq_mul {x} {y : S} {z} : f.mk' x y = z ↔ f.toMap x = z * f.toMap y := by rw [eq_comm, eq_mk'_iff_mul_eq, eq_comm] #align submonoid.localization_map.mk'_eq_iff_eq_mul Submonoid.LocalizationMap.mk'_eq_iff_eq_mul #align add_submonoid.localization_map.mk'_eq_iff_eq_add AddSubmonoid.LocalizationMap.mk'_eq_iff_eq_add @[to_additive] theorem mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : S} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ f.toMap (y₂ * x₁) = f.toMap (y₁ * x₂) := ⟨fun H ↦ by rw [f.toMap.map_mul, f.toMap.map_mul, f.mk'_eq_iff_eq_mul.1 H,← mul_assoc, mk'_spec', mul_comm ((toMap f) x₂) _], fun H ↦ by rw [mk'_eq_iff_eq_mul, mk', mul_assoc, mul_comm _ (f.toMap y₁), ← mul_assoc, ← f.toMap.map_mul, mul_comm x₂, ← H, ← mul_comm x₁, f.toMap.map_mul, mul_inv_right f.map_units]⟩ #align submonoid.localization_map.mk'_eq_iff_eq Submonoid.LocalizationMap.mk'_eq_iff_eq #align add_submonoid.localization_map.mk'_eq_iff_eq AddSubmonoid.LocalizationMap.mk'_eq_iff_eq @[to_additive] theorem mk'_eq_iff_eq' {x₁ x₂} {y₁ y₂ : S} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ f.toMap (x₁ * y₂) = f.toMap (x₂ * y₁) := by simp only [f.mk'_eq_iff_eq, mul_comm] #align submonoid.localization_map.mk'_eq_iff_eq' Submonoid.LocalizationMap.mk'_eq_iff_eq' #align add_submonoid.localization_map.mk'_eq_iff_eq' AddSubmonoid.LocalizationMap.mk'_eq_iff_eq' @[to_additive] protected theorem eq {a₁ b₁} {a₂ b₂ : S} : f.mk' a₁ a₂ = f.mk' b₁ b₂ ↔ ∃ c : S, ↑c * (↑b₂ * a₁) = c * (a₂ * b₁) := f.mk'_eq_iff_eq.trans <| f.eq_iff_exists #align submonoid.localization_map.eq Submonoid.LocalizationMap.eq #align add_submonoid.localization_map.eq AddSubmonoid.LocalizationMap.eq @[to_additive] protected theorem eq' {a₁ b₁} {a₂ b₂ : S} : f.mk' a₁ a₂ = f.mk' b₁ b₂ ↔ Localization.r S (a₁, a₂) (b₁, b₂) := by rw [f.eq, Localization.r_iff_exists] #align submonoid.localization_map.eq' Submonoid.LocalizationMap.eq' #align add_submonoid.localization_map.eq' AddSubmonoid.LocalizationMap.eq' @[to_additive] theorem eq_iff_eq (g : LocalizationMap S P) {x y} : f.toMap x = f.toMap y ↔ g.toMap x = g.toMap y := f.eq_iff_exists.trans g.eq_iff_exists.symm #align submonoid.localization_map.eq_iff_eq Submonoid.LocalizationMap.eq_iff_eq #align add_submonoid.localization_map.eq_iff_eq AddSubmonoid.LocalizationMap.eq_iff_eq @[to_additive] theorem mk'_eq_iff_mk'_eq (g : LocalizationMap S P) {x₁ x₂} {y₁ y₂ : S} : f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ g.mk' x₁ y₁ = g.mk' x₂ y₂ := f.eq'.trans g.eq'.symm #align submonoid.localization_map.mk'_eq_iff_mk'_eq Submonoid.LocalizationMap.mk'_eq_iff_mk'_eq #align add_submonoid.localization_map.mk'_eq_iff_mk'_eq AddSubmonoid.LocalizationMap.mk'_eq_iff_mk'_eq /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, for all `x₁ : M` and `y₁ ∈ S`, if `x₂ : M, y₂ ∈ S` are such that `f x₁ * (f y₁)⁻¹ * f y₂ = f x₂`, then there exists `c ∈ S` such that `x₁ * y₂ * c = x₂ * y₁ * c`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, for all `x₁ : M` and `y₁ ∈ S`, if `x₂ : M, y₂ ∈ S` are such that `(f x₁ - f y₁) + f y₂ = f x₂`, then there exists `c ∈ S` such that `x₁ + y₂ + c = x₂ + y₁ + c`."] theorem exists_of_sec_mk' (x) (y : S) : ∃ c : S, ↑c * (↑(f.sec <| f.mk' x y).2 * x) = c * (y * (f.sec <| f.mk' x y).1) := f.eq_iff_exists.1 <| f.mk'_eq_iff_eq.1 <| (mk'_sec _ _).symm #align submonoid.localization_map.exists_of_sec_mk' Submonoid.LocalizationMap.exists_of_sec_mk' #align add_submonoid.localization_map.exists_of_sec_mk' AddSubmonoid.LocalizationMap.exists_of_sec_mk' @[to_additive] theorem mk'_eq_of_eq {a₁ b₁ : M} {a₂ b₂ : S} (H : ↑a₂ * b₁ = ↑b₂ * a₁) : f.mk' a₁ a₂ = f.mk' b₁ b₂ := f.mk'_eq_iff_eq.2 <| H ▸ rfl #align submonoid.localization_map.mk'_eq_of_eq Submonoid.LocalizationMap.mk'_eq_of_eq #align add_submonoid.localization_map.mk'_eq_of_eq AddSubmonoid.LocalizationMap.mk'_eq_of_eq @[to_additive] theorem mk'_eq_of_eq' {a₁ b₁ : M} {a₂ b₂ : S} (H : b₁ * ↑a₂ = a₁ * ↑b₂) : f.mk' a₁ a₂ = f.mk' b₁ b₂ := f.mk'_eq_of_eq <| by simpa only [mul_comm] using H #align submonoid.localization_map.mk'_eq_of_eq' Submonoid.LocalizationMap.mk'_eq_of_eq' #align add_submonoid.localization_map.mk'_eq_of_eq' AddSubmonoid.LocalizationMap.mk'_eq_of_eq' @[to_additive] theorem mk'_cancel (a : M) (b c : S) : f.mk' (a * c) (b * c) = f.mk' a b := mk'_eq_of_eq' f (by rw [Submonoid.coe_mul, mul_comm (b:M), mul_assoc]) @[to_additive] theorem mk'_eq_of_same {a b} {d : S} : f.mk' a d = f.mk' b d ↔ ∃ c : S, c * a = c * b := by rw [mk'_eq_iff_eq', map_mul, map_mul, ← eq_iff_exists f] exact (map_units f d).mul_left_inj @[to_additive (attr := simp)] theorem mk'_self' (y : S) : f.mk' (y : M) y = 1 := show _ * _ = _ by rw [mul_inv_left, mul_one] #align submonoid.localization_map.mk'_self' Submonoid.LocalizationMap.mk'_self' #align add_submonoid.localization_map.mk'_self' AddSubmonoid.LocalizationMap.mk'_self' @[to_additive (attr := simp)] theorem mk'_self (x) (H : x ∈ S) : f.mk' x ⟨x, H⟩ = 1 := mk'_self' f ⟨x, H⟩ #align submonoid.localization_map.mk'_self Submonoid.LocalizationMap.mk'_self #align add_submonoid.localization_map.mk'_self AddSubmonoid.LocalizationMap.mk'_self @[to_additive] theorem mul_mk'_eq_mk'_of_mul (x₁ x₂) (y : S) : f.toMap x₁ * f.mk' x₂ y = f.mk' (x₁ * x₂) y := by rw [← mk'_one, ← mk'_mul, one_mul] #align submonoid.localization_map.mul_mk'_eq_mk'_of_mul Submonoid.LocalizationMap.mul_mk'_eq_mk'_of_mul #align add_submonoid.localization_map.add_mk'_eq_mk'_of_add AddSubmonoid.LocalizationMap.add_mk'_eq_mk'_of_add @[to_additive] theorem mk'_mul_eq_mk'_of_mul (x₁ x₂) (y : S) : f.mk' x₂ y * f.toMap x₁ = f.mk' (x₁ * x₂) y := by rw [mul_comm, mul_mk'_eq_mk'_of_mul] #align submonoid.localization_map.mk'_mul_eq_mk'_of_mul Submonoid.LocalizationMap.mk'_mul_eq_mk'_of_mul #align add_submonoid.localization_map.mk'_add_eq_mk'_of_add AddSubmonoid.LocalizationMap.mk'_add_eq_mk'_of_add @[to_additive] theorem mul_mk'_one_eq_mk' (x) (y : S) : f.toMap x * f.mk' 1 y = f.mk' x y := by rw [mul_mk'_eq_mk'_of_mul, mul_one] #align submonoid.localization_map.mul_mk'_one_eq_mk' Submonoid.LocalizationMap.mul_mk'_one_eq_mk' #align add_submonoid.localization_map.add_mk'_zero_eq_mk' AddSubmonoid.LocalizationMap.add_mk'_zero_eq_mk' @[to_additive (attr := simp)] theorem mk'_mul_cancel_right (x : M) (y : S) : f.mk' (x * y) y = f.toMap x := by rw [← mul_mk'_one_eq_mk', f.toMap.map_mul, mul_assoc, mul_mk'_one_eq_mk', mk'_self', mul_one] #align submonoid.localization_map.mk'_mul_cancel_right Submonoid.LocalizationMap.mk'_mul_cancel_right #align add_submonoid.localization_map.mk'_add_cancel_right AddSubmonoid.LocalizationMap.mk'_add_cancel_right @[to_additive] theorem mk'_mul_cancel_left (x) (y : S) : f.mk' ((y : M) * x) y = f.toMap x := by rw [mul_comm, mk'_mul_cancel_right] #align submonoid.localization_map.mk'_mul_cancel_left Submonoid.LocalizationMap.mk'_mul_cancel_left #align add_submonoid.localization_map.mk'_add_cancel_left AddSubmonoid.LocalizationMap.mk'_add_cancel_left @[to_additive] theorem isUnit_comp (j : N →* P) (y : S) : IsUnit (j.comp f.toMap y) := ⟨Units.map j <| IsUnit.liftRight (f.toMap.restrict S) f.map_units y, show j _ = j _ from congr_arg j <| IsUnit.coe_liftRight (f.toMap.restrict S) f.map_units _⟩ #align submonoid.localization_map.is_unit_comp Submonoid.LocalizationMap.isUnit_comp #align add_submonoid.localization_map.is_add_unit_comp AddSubmonoid.LocalizationMap.isAddUnit_comp variable {g : M →* P} /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s `g : M →* P` such that `g(S) ⊆ Units P`, `f x = f y → g x = g y` for all `x y : M`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M` and a map of `AddCommMonoid`s `g : M →+ P` such that `g(S) ⊆ AddUnits P`, `f x = f y → g x = g y` for all `x y : M`."] theorem eq_of_eq (hg : ∀ y : S, IsUnit (g y)) {x y} (h : f.toMap x = f.toMap y) : g x = g y := by obtain ⟨c, hc⟩ := f.eq_iff_exists.1 h rw [← one_mul (g x), ← IsUnit.liftRight_inv_mul (g.restrict S) hg c] show _ * g c * _ = _ rw [mul_assoc, ← g.map_mul, hc, mul_comm, mul_inv_left hg, g.map_mul] #align submonoid.localization_map.eq_of_eq Submonoid.LocalizationMap.eq_of_eq #align add_submonoid.localization_map.eq_of_eq AddSubmonoid.LocalizationMap.eq_of_eq /-- Given `CommMonoid`s `M, P`, Localization maps `f : M →* N, k : P →* Q` for Submonoids `S, T` respectively, and `g : M →* P` such that `g(S) ⊆ T`, `f x = f y` implies `k (g x) = k (g y)`. -/ @[to_additive "Given `AddCommMonoid`s `M, P`, Localization maps `f : M →+ N, k : P →+ Q` for Submonoids `S, T` respectively, and `g : M →+ P` such that `g(S) ⊆ T`, `f x = f y` implies `k (g x) = k (g y)`."] theorem comp_eq_of_eq {T : Submonoid P} {Q : Type*} [CommMonoid Q] (hg : ∀ y : S, g y ∈ T) (k : LocalizationMap T Q) {x y} (h : f.toMap x = f.toMap y) : k.toMap (g x) = k.toMap (g y) := f.eq_of_eq (fun y : S ↦ show IsUnit (k.toMap.comp g y) from k.map_units ⟨g y, hg y⟩) h #align submonoid.localization_map.comp_eq_of_eq Submonoid.LocalizationMap.comp_eq_of_eq #align add_submonoid.localization_map.comp_eq_of_eq AddSubmonoid.LocalizationMap.comp_eq_of_eq variable (hg : ∀ y : S, IsUnit (g y)) /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s `g : M →* P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` sending `z : N` to `g x * (g y)⁻¹`, where `(x, y) : M × S` are such that `z = f x * (f y)⁻¹`. -/ @[to_additive "Given a localization map `f : M →+ N` for a submonoid `S ⊆ M` and a map of `AddCommMonoid`s `g : M →+ P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` sending `z : N` to `g x - g y`, where `(x, y) : M × S` are such that `z = f x - f y`."] noncomputable def lift : N →* P where toFun z := g (f.sec z).1 * (IsUnit.liftRight (g.restrict S) hg (f.sec z).2)⁻¹ map_one' := by rw [mul_inv_left, mul_one]; exact f.eq_of_eq hg (by rw [← sec_spec, one_mul]) map_mul' x y := by dsimp only rw [mul_inv_left hg, ← mul_assoc, ← mul_assoc, mul_inv_right hg, mul_comm _ (g (f.sec y).1), ← mul_assoc, ← mul_assoc, mul_inv_right hg] repeat rw [← g.map_mul] exact f.eq_of_eq hg (by simp_rw [f.toMap.map_mul, sec_spec']; ac_rfl) #align submonoid.localization_map.lift Submonoid.LocalizationMap.lift #align add_submonoid.localization_map.lift AddSubmonoid.LocalizationMap.lift /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s `g : M →* P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : M, y ∈ S`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M` and a map of `AddCommMonoid`s `g : M →+ P` such that `g y` is invertible for all `y : S`, the homomorphism induced from `N` to `P` maps `f x - f y` to `g x - g y` for all `x : M, y ∈ S`."] theorem lift_mk' (x y) : f.lift hg (f.mk' x y) = g x * (IsUnit.liftRight (g.restrict S) hg y)⁻¹ := (mul_inv hg).2 <| f.eq_of_eq hg <| by simp_rw [f.toMap.map_mul, sec_spec', mul_assoc, f.mk'_spec, mul_comm] #align submonoid.localization_map.lift_mk' Submonoid.LocalizationMap.lift_mk' #align add_submonoid.localization_map.lift_mk' AddSubmonoid.LocalizationMap.lift_mk' /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N, v : P`, we have `f.lift hg z = v ↔ g x = g y * v`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N, v : P`, we have `f.lift hg z = v ↔ g x = g y + v`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_spec (z v) : f.lift hg z = v ↔ g (f.sec z).1 = g (f.sec z).2 * v := mul_inv_left hg _ _ v #align submonoid.localization_map.lift_spec Submonoid.LocalizationMap.lift_spec #align add_submonoid.localization_map.lift_spec AddSubmonoid.LocalizationMap.lift_spec /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N, v w : P`, we have `f.lift hg z * w = v ↔ g x * w = g y * v`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N, v w : P`, we have `f.lift hg z + w = v ↔ g x + w = g y + v`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_spec_mul (z w v) : f.lift hg z * w = v ↔ g (f.sec z).1 * w = g (f.sec z).2 * v := by erw [mul_comm, ← mul_assoc, mul_inv_left hg, mul_comm] #align submonoid.localization_map.lift_spec_mul Submonoid.LocalizationMap.lift_spec_mul #align add_submonoid.localization_map.lift_spec_add AddSubmonoid.LocalizationMap.lift_spec_add @[to_additive] theorem lift_mk'_spec (x v) (y : S) : f.lift hg (f.mk' x y) = v ↔ g x = g y * v := by rw [f.lift_mk' hg]; exact mul_inv_left hg _ _ _ #align submonoid.localization_map.lift_mk'_spec Submonoid.LocalizationMap.lift_mk'_spec #align add_submonoid.localization_map.lift_mk'_spec AddSubmonoid.LocalizationMap.lift_mk'_spec /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N`, we have `f.lift hg z * g y = g x`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N`, we have `f.lift hg z + g y = g x`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_mul_right (z) : f.lift hg z * g (f.sec z).2 = g (f.sec z).1 := by erw [mul_assoc, IsUnit.liftRight_inv_mul, mul_one] #align submonoid.localization_map.lift_mul_right Submonoid.LocalizationMap.lift_mul_right #align add_submonoid.localization_map.lift_add_right AddSubmonoid.LocalizationMap.lift_add_right /-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map `g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N`, we have `g y * f.lift hg z = g x`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/ @[to_additive "Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all `z : N`, we have `g y + f.lift hg z = g x`, where `x : M, y ∈ S` are such that `z + f y = f x`."] theorem lift_mul_left (z) : g (f.sec z).2 * f.lift hg z = g (f.sec z).1 := by rw [mul_comm, lift_mul_right] #align submonoid.localization_map.lift_mul_left Submonoid.LocalizationMap.lift_mul_left #align add_submonoid.localization_map.lift_add_left AddSubmonoid.LocalizationMap.lift_add_left @[to_additive (attr := simp)] theorem lift_eq (x : M) : f.lift hg (f.toMap x) = g x := by rw [lift_spec, ← g.map_mul]; exact f.eq_of_eq hg (by rw [sec_spec', f.toMap.map_mul]) #align submonoid.localization_map.lift_eq Submonoid.LocalizationMap.lift_eq #align add_submonoid.localization_map.lift_eq AddSubmonoid.LocalizationMap.lift_eq @[to_additive] theorem lift_eq_iff {x y : M × S} : f.lift hg (f.mk' x.1 x.2) = f.lift hg (f.mk' y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) := by rw [lift_mk', lift_mk', mul_inv hg] #align submonoid.localization_map.lift_eq_iff Submonoid.LocalizationMap.lift_eq_iff #align add_submonoid.localization_map.lift_eq_iff AddSubmonoid.LocalizationMap.lift_eq_iff @[to_additive (attr := simp)] theorem lift_comp : (f.lift hg).comp f.toMap = g := by ext; exact f.lift_eq hg _ #align submonoid.localization_map.lift_comp Submonoid.LocalizationMap.lift_comp #align add_submonoid.localization_map.lift_comp AddSubmonoid.LocalizationMap.lift_comp @[to_additive (attr := simp)] theorem lift_of_comp (j : N →* P) : f.lift (f.isUnit_comp j) = j := by ext rw [lift_spec] show j _ = j _ * _ erw [← j.map_mul, sec_spec'] #align submonoid.localization_map.lift_of_comp Submonoid.LocalizationMap.lift_of_comp #align add_submonoid.localization_map.lift_of_comp AddSubmonoid.LocalizationMap.lift_of_comp @[to_additive] theorem epic_of_localizationMap {j k : N →* P} (h : ∀ a, j.comp f.toMap a = k.comp f.toMap a) : j = k := by rw [← f.lift_of_comp j, ← f.lift_of_comp k] congr 1 with x; exact h x #align submonoid.localization_map.epic_of_localization_map Submonoid.LocalizationMap.epic_of_localizationMap #align add_submonoid.localization_map.epic_of_localization_map AddSubmonoid.LocalizationMap.epic_of_localizationMap @[to_additive]
Mathlib/GroupTheory/MonoidLocalization.lean
1,077
1,081
theorem lift_unique {j : N →* P} (hj : ∀ x, j (f.toMap x) = g x) : f.lift hg = j := by
ext rw [lift_spec, ← hj, ← hj, ← j.map_mul] apply congr_arg rw [← sec_spec']
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Nat import Mathlib.Algebra.Order.Sub.Canonical import Mathlib.Data.List.Perm import Mathlib.Data.Set.List import Mathlib.Init.Quot import Mathlib.Order.Hom.Basic #align_import data.multiset.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Multisets These are implemented as the quotient of a list by permutations. ## Notation We define the global infix notation `::ₘ` for `Multiset.cons`. -/ universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} /-- `Multiset α` is the quotient of `List α` by list permutation. The result is a type of finite sets with duplicates allowed. -/ def Multiset.{u} (α : Type u) : Type u := Quotient (List.isSetoid α) #align multiset Multiset namespace Multiset -- Porting note: new /-- The quotient map from `List α` to `Multiset α`. -/ @[coe] def ofList : List α → Multiset α := Quot.mk _ instance : Coe (List α) (Multiset α) := ⟨ofList⟩ @[simp] theorem quot_mk_to_coe (l : List α) : @Eq (Multiset α) ⟦l⟧ l := rfl #align multiset.quot_mk_to_coe Multiset.quot_mk_to_coe @[simp] theorem quot_mk_to_coe' (l : List α) : @Eq (Multiset α) (Quot.mk (· ≈ ·) l) l := rfl #align multiset.quot_mk_to_coe' Multiset.quot_mk_to_coe' @[simp] theorem quot_mk_to_coe'' (l : List α) : @Eq (Multiset α) (Quot.mk Setoid.r l) l := rfl #align multiset.quot_mk_to_coe'' Multiset.quot_mk_to_coe'' @[simp] theorem coe_eq_coe {l₁ l₂ : List α} : (l₁ : Multiset α) = l₂ ↔ l₁ ~ l₂ := Quotient.eq #align multiset.coe_eq_coe Multiset.coe_eq_coe -- Porting note: new instance; -- Porting note (#11215): TODO: move to better place instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ ≈ l₂) := inferInstanceAs (Decidable (l₁ ~ l₂)) -- Porting note: `Quotient.recOnSubsingleton₂ s₁ s₂` was in parens which broke elaboration instance decidableEq [DecidableEq α] : DecidableEq (Multiset α) | s₁, s₂ => Quotient.recOnSubsingleton₂ s₁ s₂ fun _ _ => decidable_of_iff' _ Quotient.eq #align multiset.has_decidable_eq Multiset.decidableEq /-- defines a size for a multiset by referring to the size of the underlying list -/ protected def sizeOf [SizeOf α] (s : Multiset α) : ℕ := (Quot.liftOn s SizeOf.sizeOf) fun _ _ => Perm.sizeOf_eq_sizeOf #align multiset.sizeof Multiset.sizeOf instance [SizeOf α] : SizeOf (Multiset α) := ⟨Multiset.sizeOf⟩ /-! ### Empty multiset -/ /-- `0 : Multiset α` is the empty set -/ protected def zero : Multiset α := @nil α #align multiset.zero Multiset.zero instance : Zero (Multiset α) := ⟨Multiset.zero⟩ instance : EmptyCollection (Multiset α) := ⟨0⟩ instance inhabitedMultiset : Inhabited (Multiset α) := ⟨0⟩ #align multiset.inhabited_multiset Multiset.inhabitedMultiset instance [IsEmpty α] : Unique (Multiset α) where default := 0 uniq := by rintro ⟨_ | ⟨a, l⟩⟩; exacts [rfl, isEmptyElim a] @[simp] theorem coe_nil : (@nil α : Multiset α) = 0 := rfl #align multiset.coe_nil Multiset.coe_nil @[simp] theorem empty_eq_zero : (∅ : Multiset α) = 0 := rfl #align multiset.empty_eq_zero Multiset.empty_eq_zero @[simp] theorem coe_eq_zero (l : List α) : (l : Multiset α) = 0 ↔ l = [] := Iff.trans coe_eq_coe perm_nil #align multiset.coe_eq_zero Multiset.coe_eq_zero theorem coe_eq_zero_iff_isEmpty (l : List α) : (l : Multiset α) = 0 ↔ l.isEmpty := Iff.trans (coe_eq_zero l) isEmpty_iff_eq_nil.symm #align multiset.coe_eq_zero_iff_empty Multiset.coe_eq_zero_iff_isEmpty /-! ### `Multiset.cons` -/ /-- `cons a s` is the multiset which contains `s` plus one more instance of `a`. -/ def cons (a : α) (s : Multiset α) : Multiset α := Quot.liftOn s (fun l => (a :: l : Multiset α)) fun _ _ p => Quot.sound (p.cons a) #align multiset.cons Multiset.cons @[inherit_doc Multiset.cons] infixr:67 " ::ₘ " => Multiset.cons instance : Insert α (Multiset α) := ⟨cons⟩ @[simp] theorem insert_eq_cons (a : α) (s : Multiset α) : insert a s = a ::ₘ s := rfl #align multiset.insert_eq_cons Multiset.insert_eq_cons @[simp] theorem cons_coe (a : α) (l : List α) : (a ::ₘ l : Multiset α) = (a :: l : List α) := rfl #align multiset.cons_coe Multiset.cons_coe @[simp] theorem cons_inj_left {a b : α} (s : Multiset α) : a ::ₘ s = b ::ₘ s ↔ a = b := ⟨Quot.inductionOn s fun l e => have : [a] ++ l ~ [b] ++ l := Quotient.exact e singleton_perm_singleton.1 <| (perm_append_right_iff _).1 this, congr_arg (· ::ₘ _)⟩ #align multiset.cons_inj_left Multiset.cons_inj_left @[simp] theorem cons_inj_right (a : α) : ∀ {s t : Multiset α}, a ::ₘ s = a ::ₘ t ↔ s = t := by rintro ⟨l₁⟩ ⟨l₂⟩; simp #align multiset.cons_inj_right Multiset.cons_inj_right @[elab_as_elim] protected theorem induction {p : Multiset α → Prop} (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : ∀ s, p s := by rintro ⟨l⟩; induction' l with _ _ ih <;> [exact empty; exact cons _ _ ih] #align multiset.induction Multiset.induction @[elab_as_elim] protected theorem induction_on {p : Multiset α → Prop} (s : Multiset α) (empty : p 0) (cons : ∀ (a : α) (s : Multiset α), p s → p (a ::ₘ s)) : p s := Multiset.induction empty cons s #align multiset.induction_on Multiset.induction_on theorem cons_swap (a b : α) (s : Multiset α) : a ::ₘ b ::ₘ s = b ::ₘ a ::ₘ s := Quot.inductionOn s fun _ => Quotient.sound <| Perm.swap _ _ _ #align multiset.cons_swap Multiset.cons_swap section Rec variable {C : Multiset α → Sort*} /-- Dependent recursor on multisets. TODO: should be @[recursor 6], but then the definition of `Multiset.pi` fails with a stack overflow in `whnf`. -/ protected def rec (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) (m : Multiset α) : C m := Quotient.hrecOn m (@List.rec α (fun l => C ⟦l⟧) C_0 fun a l b => C_cons a ⟦l⟧ b) fun l l' h => h.rec_heq (fun hl _ ↦ by congr 1; exact Quot.sound hl) (C_cons_heq _ _ ⟦_⟧ _) #align multiset.rec Multiset.rec /-- Companion to `Multiset.rec` with more convenient argument order. -/ @[elab_as_elim] protected def recOn (m : Multiset α) (C_0 : C 0) (C_cons : ∀ a m, C m → C (a ::ₘ m)) (C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))) : C m := Multiset.rec C_0 C_cons C_cons_heq m #align multiset.rec_on Multiset.recOn variable {C_0 : C 0} {C_cons : ∀ a m, C m → C (a ::ₘ m)} {C_cons_heq : ∀ a a' m b, HEq (C_cons a (a' ::ₘ m) (C_cons a' m b)) (C_cons a' (a ::ₘ m) (C_cons a m b))} @[simp] theorem recOn_0 : @Multiset.recOn α C (0 : Multiset α) C_0 C_cons C_cons_heq = C_0 := rfl #align multiset.rec_on_0 Multiset.recOn_0 @[simp] theorem recOn_cons (a : α) (m : Multiset α) : (a ::ₘ m).recOn C_0 C_cons C_cons_heq = C_cons a m (m.recOn C_0 C_cons C_cons_heq) := Quotient.inductionOn m fun _ => rfl #align multiset.rec_on_cons Multiset.recOn_cons end Rec section Mem /-- `a ∈ s` means that `a` has nonzero multiplicity in `s`. -/ def Mem (a : α) (s : Multiset α) : Prop := Quot.liftOn s (fun l => a ∈ l) fun l₁ l₂ (e : l₁ ~ l₂) => propext <| e.mem_iff #align multiset.mem Multiset.Mem instance : Membership α (Multiset α) := ⟨Mem⟩ @[simp] theorem mem_coe {a : α} {l : List α} : a ∈ (l : Multiset α) ↔ a ∈ l := Iff.rfl #align multiset.mem_coe Multiset.mem_coe instance decidableMem [DecidableEq α] (a : α) (s : Multiset α) : Decidable (a ∈ s) := Quot.recOnSubsingleton' s fun l ↦ inferInstanceAs (Decidable (a ∈ l)) #align multiset.decidable_mem Multiset.decidableMem @[simp] theorem mem_cons {a b : α} {s : Multiset α} : a ∈ b ::ₘ s ↔ a = b ∨ a ∈ s := Quot.inductionOn s fun _ => List.mem_cons #align multiset.mem_cons Multiset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Multiset α} (h : a ∈ s) : a ∈ b ::ₘ s := mem_cons.2 <| Or.inr h #align multiset.mem_cons_of_mem Multiset.mem_cons_of_mem -- @[simp] -- Porting note (#10618): simp can prove this theorem mem_cons_self (a : α) (s : Multiset α) : a ∈ a ::ₘ s := mem_cons.2 (Or.inl rfl) #align multiset.mem_cons_self Multiset.mem_cons_self theorem forall_mem_cons {p : α → Prop} {a : α} {s : Multiset α} : (∀ x ∈ a ::ₘ s, p x) ↔ p a ∧ ∀ x ∈ s, p x := Quotient.inductionOn' s fun _ => List.forall_mem_cons #align multiset.forall_mem_cons Multiset.forall_mem_cons theorem exists_cons_of_mem {s : Multiset α} {a : α} : a ∈ s → ∃ t, s = a ::ₘ t := Quot.inductionOn s fun l (h : a ∈ l) => let ⟨l₁, l₂, e⟩ := append_of_mem h e.symm ▸ ⟨(l₁ ++ l₂ : List α), Quot.sound perm_middle⟩ #align multiset.exists_cons_of_mem Multiset.exists_cons_of_mem @[simp] theorem not_mem_zero (a : α) : a ∉ (0 : Multiset α) := List.not_mem_nil _ #align multiset.not_mem_zero Multiset.not_mem_zero theorem eq_zero_of_forall_not_mem {s : Multiset α} : (∀ x, x ∉ s) → s = 0 := Quot.inductionOn s fun l H => by rw [eq_nil_iff_forall_not_mem.mpr H]; rfl #align multiset.eq_zero_of_forall_not_mem Multiset.eq_zero_of_forall_not_mem theorem eq_zero_iff_forall_not_mem {s : Multiset α} : s = 0 ↔ ∀ a, a ∉ s := ⟨fun h => h.symm ▸ fun _ => not_mem_zero _, eq_zero_of_forall_not_mem⟩ #align multiset.eq_zero_iff_forall_not_mem Multiset.eq_zero_iff_forall_not_mem theorem exists_mem_of_ne_zero {s : Multiset α} : s ≠ 0 → ∃ a : α, a ∈ s := Quot.inductionOn s fun l hl => match l, hl with | [], h => False.elim <| h rfl | a :: l, _ => ⟨a, by simp⟩ #align multiset.exists_mem_of_ne_zero Multiset.exists_mem_of_ne_zero theorem empty_or_exists_mem (s : Multiset α) : s = 0 ∨ ∃ a, a ∈ s := or_iff_not_imp_left.mpr Multiset.exists_mem_of_ne_zero #align multiset.empty_or_exists_mem Multiset.empty_or_exists_mem @[simp] theorem zero_ne_cons {a : α} {m : Multiset α} : 0 ≠ a ::ₘ m := fun h => have : a ∈ (0 : Multiset α) := h.symm ▸ mem_cons_self _ _ not_mem_zero _ this #align multiset.zero_ne_cons Multiset.zero_ne_cons @[simp] theorem cons_ne_zero {a : α} {m : Multiset α} : a ::ₘ m ≠ 0 := zero_ne_cons.symm #align multiset.cons_ne_zero Multiset.cons_ne_zero theorem cons_eq_cons {a b : α} {as bs : Multiset α} : a ::ₘ as = b ::ₘ bs ↔ a = b ∧ as = bs ∨ a ≠ b ∧ ∃ cs, as = b ::ₘ cs ∧ bs = a ::ₘ cs := by haveI : DecidableEq α := Classical.decEq α constructor · intro eq by_cases h : a = b · subst h simp_all · have : a ∈ b ::ₘ bs := eq ▸ mem_cons_self _ _ have : a ∈ bs := by simpa [h] rcases exists_cons_of_mem this with ⟨cs, hcs⟩ simp only [h, hcs, false_and, ne_eq, not_false_eq_true, cons_inj_right, exists_eq_right', true_and, false_or] have : a ::ₘ as = b ::ₘ a ::ₘ cs := by simp [eq, hcs] have : a ::ₘ as = a ::ₘ b ::ₘ cs := by rwa [cons_swap] simpa using this · intro h rcases h with (⟨eq₁, eq₂⟩ | ⟨_, cs, eq₁, eq₂⟩) · simp [*] · simp [*, cons_swap a b] #align multiset.cons_eq_cons Multiset.cons_eq_cons end Mem /-! ### Singleton -/ instance : Singleton α (Multiset α) := ⟨fun a => a ::ₘ 0⟩ instance : LawfulSingleton α (Multiset α) := ⟨fun _ => rfl⟩ @[simp] theorem cons_zero (a : α) : a ::ₘ 0 = {a} := rfl #align multiset.cons_zero Multiset.cons_zero @[simp, norm_cast] theorem coe_singleton (a : α) : ([a] : Multiset α) = {a} := rfl #align multiset.coe_singleton Multiset.coe_singleton @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Multiset α) ↔ b = a := by simp only [← cons_zero, mem_cons, iff_self_iff, or_false_iff, not_mem_zero] #align multiset.mem_singleton Multiset.mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Multiset α) := by rw [← cons_zero] exact mem_cons_self _ _ #align multiset.mem_singleton_self Multiset.mem_singleton_self @[simp] theorem singleton_inj {a b : α} : ({a} : Multiset α) = {b} ↔ a = b := by simp_rw [← cons_zero] exact cons_inj_left _ #align multiset.singleton_inj Multiset.singleton_inj @[simp, norm_cast] theorem coe_eq_singleton {l : List α} {a : α} : (l : Multiset α) = {a} ↔ l = [a] := by rw [← coe_singleton, coe_eq_coe, List.perm_singleton] #align multiset.coe_eq_singleton Multiset.coe_eq_singleton @[simp] theorem singleton_eq_cons_iff {a b : α} (m : Multiset α) : {a} = b ::ₘ m ↔ a = b ∧ m = 0 := by rw [← cons_zero, cons_eq_cons] simp [eq_comm] #align multiset.singleton_eq_cons_iff Multiset.singleton_eq_cons_iff theorem pair_comm (x y : α) : ({x, y} : Multiset α) = {y, x} := cons_swap x y 0 #align multiset.pair_comm Multiset.pair_comm /-! ### `Multiset.Subset` -/ section Subset variable {s : Multiset α} {a : α} /-- `s ⊆ t` is the lift of the list subset relation. It means that any element with nonzero multiplicity in `s` has nonzero multiplicity in `t`, but it does not imply that the multiplicity of `a` in `s` is less or equal than in `t`; see `s ≤ t` for this relation. -/ protected def Subset (s t : Multiset α) : Prop := ∀ ⦃a : α⦄, a ∈ s → a ∈ t #align multiset.subset Multiset.Subset instance : HasSubset (Multiset α) := ⟨Multiset.Subset⟩ instance : HasSSubset (Multiset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance instIsNonstrictStrictOrder : IsNonstrictStrictOrder (Multiset α) (· ⊆ ·) (· ⊂ ·) where right_iff_left_not_left _ _ := Iff.rfl @[simp] theorem coe_subset {l₁ l₂ : List α} : (l₁ : Multiset α) ⊆ l₂ ↔ l₁ ⊆ l₂ := Iff.rfl #align multiset.coe_subset Multiset.coe_subset @[simp] theorem Subset.refl (s : Multiset α) : s ⊆ s := fun _ h => h #align multiset.subset.refl Multiset.Subset.refl theorem Subset.trans {s t u : Multiset α} : s ⊆ t → t ⊆ u → s ⊆ u := fun h₁ h₂ _ m => h₂ (h₁ m) #align multiset.subset.trans Multiset.Subset.trans theorem subset_iff {s t : Multiset α} : s ⊆ t ↔ ∀ ⦃x⦄, x ∈ s → x ∈ t := Iff.rfl #align multiset.subset_iff Multiset.subset_iff theorem mem_of_subset {s t : Multiset α} {a : α} (h : s ⊆ t) : a ∈ s → a ∈ t := @h _ #align multiset.mem_of_subset Multiset.mem_of_subset @[simp] theorem zero_subset (s : Multiset α) : 0 ⊆ s := fun a => (not_mem_nil a).elim #align multiset.zero_subset Multiset.zero_subset theorem subset_cons (s : Multiset α) (a : α) : s ⊆ a ::ₘ s := fun _ => mem_cons_of_mem #align multiset.subset_cons Multiset.subset_cons theorem ssubset_cons {s : Multiset α} {a : α} (ha : a ∉ s) : s ⊂ a ::ₘ s := ⟨subset_cons _ _, fun h => ha <| h <| mem_cons_self _ _⟩ #align multiset.ssubset_cons Multiset.ssubset_cons @[simp] theorem cons_subset {a : α} {s t : Multiset α} : a ::ₘ s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp [subset_iff, or_imp, forall_and] #align multiset.cons_subset Multiset.cons_subset theorem cons_subset_cons {a : α} {s t : Multiset α} : s ⊆ t → a ::ₘ s ⊆ a ::ₘ t := Quotient.inductionOn₂ s t fun _ _ => List.cons_subset_cons _ #align multiset.cons_subset_cons Multiset.cons_subset_cons theorem eq_zero_of_subset_zero {s : Multiset α} (h : s ⊆ 0) : s = 0 := eq_zero_of_forall_not_mem fun _ hx ↦ not_mem_zero _ (h hx) #align multiset.eq_zero_of_subset_zero Multiset.eq_zero_of_subset_zero @[simp] lemma subset_zero : s ⊆ 0 ↔ s = 0 := ⟨eq_zero_of_subset_zero, fun xeq => xeq.symm ▸ Subset.refl 0⟩ #align multiset.subset_zero Multiset.subset_zero @[simp] lemma zero_ssubset : 0 ⊂ s ↔ s ≠ 0 := by simp [ssubset_iff_subset_not_subset] @[simp] lemma singleton_subset : {a} ⊆ s ↔ a ∈ s := by simp [subset_iff] theorem induction_on' {p : Multiset α → Prop} (S : Multiset α) (h₁ : p 0) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → p s → p (insert a s)) : p S := @Multiset.induction_on α (fun T => T ⊆ S → p T) S (fun _ => h₁) (fun _ _ hps hs => let ⟨hS, sS⟩ := cons_subset.1 hs h₂ hS sS (hps sS)) (Subset.refl S) #align multiset.induction_on' Multiset.induction_on' end Subset /-! ### `Multiset.toList` -/ section ToList /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def toList (s : Multiset α) := s.out' #align multiset.to_list Multiset.toList @[simp, norm_cast] theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s := s.out_eq' #align multiset.coe_to_list Multiset.coe_toList @[simp] theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_toList] #align multiset.to_list_eq_nil Multiset.toList_eq_nil @[simp] theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := isEmpty_iff_eq_nil.trans toList_eq_nil #align multiset.empty_to_list Multiset.empty_toList @[simp] theorem toList_zero : (Multiset.toList 0 : List α) = [] := toList_eq_nil.mpr rfl #align multiset.to_list_zero Multiset.toList_zero @[simp]
Mathlib/Data/Multiset/Basic.lean
493
494
theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by
rw [← mem_coe, coe_toList]
/- 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.Restrict /-! # Classes of measures We introduce the following typeclasses for measures: * `IsProbabilityMeasure μ`: `μ univ = 1`; * `IsFiniteMeasure μ`: `μ univ < ∞`; * `SigmaFinite μ`: there exists a countable collection of sets that cover `univ` where `μ` is finite; * `SFinite μ`: the measure `μ` can be written as a countable sum of finite measures; * `IsLocallyFiniteMeasure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`; * `NoAtoms μ` : `∀ x, μ {x} = 0`; possibly should be redefined as `∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter Function MeasurableSpace ENNReal variable {α β δ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] {μ ν ν₁ ν₂: Measure α} {s t : Set α} section IsFiniteMeasure /-- A measure `μ` is called finite if `μ univ < ∞`. -/ class IsFiniteMeasure (μ : Measure α) : Prop where measure_univ_lt_top : μ univ < ∞ #align measure_theory.is_finite_measure MeasureTheory.IsFiniteMeasure #align measure_theory.is_finite_measure.measure_univ_lt_top MeasureTheory.IsFiniteMeasure.measure_univ_lt_top
Mathlib/MeasureTheory/Measure/Typeclasses.lean
41
44
theorem not_isFiniteMeasure_iff : ¬IsFiniteMeasure μ ↔ μ Set.univ = ∞ := by
refine ⟨fun h => ?_, fun h => fun h' => h'.measure_univ_lt_top.ne h⟩ by_contra h' exact h ⟨lt_top_iff_ne_top.mpr h'⟩
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.Group.WithOne.Defs import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.Algebra.Order.Group.Units import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Monoid.Basic import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Algebra.Order.Monoid.TypeTags import Mathlib.Algebra.Order.ZeroLEOne #align_import algebra.order.monoid.with_zero.defs from "leanprover-community/mathlib"@"4dc134b97a3de65ef2ed881f3513d56260971562" #align_import algebra.order.monoid.with_zero.basic from "leanprover-community/mathlib"@"dad7ecf9a1feae63e6e49f07619b7087403fb8d4" #align_import algebra.order.with_zero from "leanprover-community/mathlib"@"655994e298904d7e5bbd1e18c95defd7b543eb94" /-! # Linearly ordered commutative groups and monoids with a zero element adjoined This file sets up a special class of linearly ordered commutative monoids that show up as the target of so-called “valuations” in algebraic number theory. Usually, in the informal literature, these objects are constructed by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}. The disadvantage is that a type such as `NNReal` is not of that form, whereas it is a very common target for valuations. The solutions is to use a typeclass, and that is exactly what we do in this file. -/ variable {α : Type*} /-- A linearly ordered commutative monoid with a zero element. -/ class LinearOrderedCommMonoidWithZero (α : Type*) extends LinearOrderedCommMonoid α, CommMonoidWithZero α where /-- `0 ≤ 1` in any linearly ordered commutative monoid. -/ zero_le_one : (0 : α) ≤ 1 #align linear_ordered_comm_monoid_with_zero LinearOrderedCommMonoidWithZero /-- A linearly ordered commutative group with a zero element. -/ class LinearOrderedCommGroupWithZero (α : Type*) extends LinearOrderedCommMonoidWithZero α, CommGroupWithZero α #align linear_ordered_comm_group_with_zero LinearOrderedCommGroupWithZero instance (priority := 100) LinearOrderedCommMonoidWithZero.toZeroLeOneClass [LinearOrderedCommMonoidWithZero α] : ZeroLEOneClass α := { ‹LinearOrderedCommMonoidWithZero α› with } #align linear_ordered_comm_monoid_with_zero.to_zero_le_one_class LinearOrderedCommMonoidWithZero.toZeroLeOneClass instance (priority := 100) canonicallyOrderedAddCommMonoid.toZeroLeOneClass [CanonicallyOrderedAddCommMonoid α] [One α] : ZeroLEOneClass α := ⟨zero_le 1⟩ #align canonically_ordered_add_monoid.to_zero_le_one_class canonicallyOrderedAddCommMonoid.toZeroLeOneClass section LinearOrderedCommMonoidWithZero variable [LinearOrderedCommMonoidWithZero α] {a b c d x y z : α} {n : ℕ} /- The following facts are true more generally in a (linearly) ordered commutative monoid. -/ /-- Pullback a `LinearOrderedCommMonoidWithZero` under an injective map. See note [reducible non-instances]. -/ abbrev Function.Injective.linearOrderedCommMonoidWithZero {β : Type*} [Zero β] [One β] [Mul β] [Pow β ℕ] [Sup β] [Inf β] (f : β → α) (hf : Function.Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) : LinearOrderedCommMonoidWithZero β := { LinearOrder.lift f hf hsup hinf, hf.orderedCommMonoid f one mul npow, hf.commMonoidWithZero f zero one mul npow with zero_le_one := show f 0 ≤ f 1 by simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one] } #align function.injective.linear_ordered_comm_monoid_with_zero Function.Injective.linearOrderedCommMonoidWithZero @[simp] lemma zero_le' : 0 ≤ a := by simpa only [mul_zero, mul_one] using mul_le_mul_left' (zero_le_one' α) a #align zero_le' zero_le' @[simp] theorem not_lt_zero' : ¬a < 0 := not_lt_of_le zero_le' #align not_lt_zero' not_lt_zero' @[simp] theorem le_zero_iff : a ≤ 0 ↔ a = 0 := ⟨fun h ↦ le_antisymm h zero_le', fun h ↦ h ▸ le_rfl⟩ #align le_zero_iff le_zero_iff theorem zero_lt_iff : 0 < a ↔ a ≠ 0 := ⟨ne_of_gt, fun h ↦ lt_of_le_of_ne zero_le' h.symm⟩ #align zero_lt_iff zero_lt_iff theorem ne_zero_of_lt (h : b < a) : a ≠ 0 := fun h1 ↦ not_lt_zero' <| show b < 0 from h1 ▸ h #align ne_zero_of_lt ne_zero_of_lt instance instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual : LinearOrderedAddCommMonoidWithTop (Additive αᵒᵈ) := { Additive.orderedAddCommMonoid, Additive.linearOrder with top := (0 : α) top_add' := fun a ↦ zero_mul (Additive.toMul a) le_top := fun _ ↦ zero_le' } #align additive.linear_ordered_add_comm_monoid_with_top instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual variable [NoZeroDivisors α] lemma pow_pos_iff (hn : n ≠ 0) : 0 < a ^ n ↔ 0 < a := by simp_rw [zero_lt_iff, pow_ne_zero_iff hn] #align pow_pos_iff pow_pos_iff end LinearOrderedCommMonoidWithZero section LinearOrderedCommGroupWithZero variable [LinearOrderedCommGroupWithZero α] {a b c d : α} {m n : ℕ} -- TODO: Do we really need the following two? /-- Alias of `mul_le_one'` for unification. -/ theorem mul_le_one₀ (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 := mul_le_one' ha hb #align mul_le_one₀ mul_le_one₀ /-- Alias of `one_le_mul'` for unification. -/ theorem one_le_mul₀ (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b := one_le_mul ha hb #align one_le_mul₀ one_le_mul₀ theorem le_of_le_mul_right (h : c ≠ 0) (hab : a * c ≤ b * c) : a ≤ b := by simpa only [mul_inv_cancel_right₀ h] using mul_le_mul_right' hab c⁻¹ #align le_of_le_mul_right le_of_le_mul_right theorem le_mul_inv_of_mul_le (h : c ≠ 0) (hab : a * c ≤ b) : a ≤ b * c⁻¹ := le_of_le_mul_right h (by simpa [h] using hab) #align le_mul_inv_of_mul_le le_mul_inv_of_mul_le theorem mul_inv_le_of_le_mul (hab : a ≤ b * c) : a * c⁻¹ ≤ b := by by_cases h : c = 0 · simp [h] · exact le_of_le_mul_right h (by simpa [h] using hab) #align mul_inv_le_of_le_mul mul_inv_le_of_le_mul theorem inv_le_one₀ (ha : a ≠ 0) : a⁻¹ ≤ 1 ↔ 1 ≤ a := @inv_le_one' _ _ _ _ <| Units.mk0 a ha #align inv_le_one₀ inv_le_one₀ theorem one_le_inv₀ (ha : a ≠ 0) : 1 ≤ a⁻¹ ↔ a ≤ 1 := @one_le_inv' _ _ _ _ <| Units.mk0 a ha #align one_le_inv₀ one_le_inv₀ theorem le_mul_inv_iff₀ (hc : c ≠ 0) : a ≤ b * c⁻¹ ↔ a * c ≤ b := ⟨fun h ↦ inv_inv c ▸ mul_inv_le_of_le_mul h, le_mul_inv_of_mul_le hc⟩ #align le_mul_inv_iff₀ le_mul_inv_iff₀ theorem mul_inv_le_iff₀ (hc : c ≠ 0) : a * c⁻¹ ≤ b ↔ a ≤ b * c := ⟨fun h ↦ inv_inv c ▸ le_mul_inv_of_mul_le (inv_ne_zero hc) h, mul_inv_le_of_le_mul⟩ #align mul_inv_le_iff₀ mul_inv_le_iff₀ theorem div_le_div₀ (a b c d : α) (hb : b ≠ 0) (hd : d ≠ 0) : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by rw [mul_inv_le_iff₀ hb, mul_right_comm, le_mul_inv_iff₀ hd] #align div_le_div₀ div_le_div₀ @[simp] theorem Units.zero_lt (u : αˣ) : (0 : α) < u := zero_lt_iff.2 <| u.ne_zero #align units.zero_lt Units.zero_lt theorem mul_lt_mul_of_lt_of_le₀ (hab : a ≤ b) (hb : b ≠ 0) (hcd : c < d) : a * c < b * d := have hd : d ≠ 0 := ne_zero_of_lt hcd if ha : a = 0 then by rw [ha, zero_mul, zero_lt_iff] exact mul_ne_zero hb hd else if hc : c = 0 then by rw [hc, mul_zero, zero_lt_iff] exact mul_ne_zero hb hd else show Units.mk0 a ha * Units.mk0 c hc < Units.mk0 b hb * Units.mk0 d hd from mul_lt_mul_of_le_of_lt hab hcd #align mul_lt_mul_of_lt_of_le₀ mul_lt_mul_of_lt_of_le₀ theorem mul_lt_mul₀ (hab : a < b) (hcd : c < d) : a * c < b * d := mul_lt_mul_of_lt_of_le₀ hab.le (ne_zero_of_lt hab) hcd #align mul_lt_mul₀ mul_lt_mul₀ theorem mul_inv_lt_of_lt_mul₀ (h : a < b * c) : a * c⁻¹ < b := by contrapose! h simpa only [inv_inv] using mul_inv_le_of_le_mul h #align mul_inv_lt_of_lt_mul₀ mul_inv_lt_of_lt_mul₀ theorem inv_mul_lt_of_lt_mul₀ (h : a < b * c) : b⁻¹ * a < c := by rw [mul_comm] at * exact mul_inv_lt_of_lt_mul₀ h #align inv_mul_lt_of_lt_mul₀ inv_mul_lt_of_lt_mul₀ theorem mul_lt_right₀ (c : α) (h : a < b) (hc : c ≠ 0) : a * c < b * c := by contrapose! h exact le_of_le_mul_right hc h #align mul_lt_right₀ mul_lt_right₀ theorem inv_lt_one₀ (ha : a ≠ 0) : a⁻¹ < 1 ↔ 1 < a := @inv_lt_one' _ _ _ _ <| Units.mk0 a ha theorem one_lt_inv₀ (ha : a ≠ 0) : 1 < a⁻¹ ↔ a < 1 := @one_lt_inv' _ _ _ _ <| Units.mk0 a ha theorem inv_lt_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ < b⁻¹ ↔ b < a := show (Units.mk0 a ha)⁻¹ < (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb < Units.mk0 a ha from have : CovariantClass αˣ αˣ (· * ·) (· < ·) := IsLeftCancelMul.covariant_mul_lt_of_covariant_mul_le αˣ inv_lt_inv_iff #align inv_lt_inv₀ inv_lt_inv₀ theorem inv_le_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := show (Units.mk0 a ha)⁻¹ ≤ (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb ≤ Units.mk0 a ha from inv_le_inv_iff #align inv_le_inv₀ inv_le_inv₀ theorem lt_of_mul_lt_mul_of_le₀ (h : a * b < c * d) (hc : 0 < c) (hh : c ≤ a) : b < d := by have ha : a ≠ 0 := ne_of_gt (lt_of_lt_of_le hc hh) simp_rw [← inv_le_inv₀ ha (ne_of_gt hc)] at hh have := mul_lt_mul_of_lt_of_le₀ hh (inv_ne_zero (ne_of_gt hc)) h simpa [inv_mul_cancel_left₀ ha, inv_mul_cancel_left₀ (ne_of_gt hc)] using this #align lt_of_mul_lt_mul_of_le₀ lt_of_mul_lt_mul_of_le₀ theorem mul_le_mul_right₀ (hc : c ≠ 0) : a * c ≤ b * c ↔ a ≤ b := ⟨le_of_le_mul_right hc, fun hab ↦ mul_le_mul_right' hab _⟩ #align mul_le_mul_right₀ mul_le_mul_right₀ theorem mul_le_mul_left₀ (ha : a ≠ 0) : a * b ≤ a * c ↔ b ≤ c := by simp only [mul_comm a] exact mul_le_mul_right₀ ha #align mul_le_mul_left₀ mul_le_mul_left₀ theorem div_le_div_right₀ (hc : c ≠ 0) : a / c ≤ b / c ↔ a ≤ b := by rw [div_eq_mul_inv, div_eq_mul_inv, mul_le_mul_right₀ (inv_ne_zero hc)] #align div_le_div_right₀ div_le_div_right₀ theorem div_le_div_left₀ (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0) : a / b ≤ a / c ↔ c ≤ b := by simp only [div_eq_mul_inv, mul_le_mul_left₀ ha, inv_le_inv₀ hb hc] #align div_le_div_left₀ div_le_div_left₀
Mathlib/Algebra/Order/GroupWithZero/Canonical.lean
243
244
theorem le_div_iff₀ (hc : c ≠ 0) : a ≤ b / c ↔ a * c ≤ b := by
rw [div_eq_mul_inv, le_mul_inv_iff₀ hc]
/- Copyright (c) 2021 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.CategoryTheory.NatIso #align_import category_theory.bicategory.basic from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Bicategories In this file we define typeclass for bicategories. A bicategory `B` consists of * objects `a : B`, * 1-morphisms `f : a ⟶ b` between objects `a b : B`, and * 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`. We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms, respectively. A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that we have * a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and * an identity `𝟙 a : a ⟶ a` for each object `a : B`. For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The 2-morphisms in the bicategory are implemented as the morphisms in this family of categories. The composition of 1-morphisms is in fact an object part of a functor `(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism `f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a 2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism `whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law `whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`, which is required as an axiom in the definition here. -/ namespace CategoryTheory universe w v u open Category Iso -- intended to be used with explicit universe parameters /-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative, but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`. There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`. These associators and unitors satisfy the pentagon and triangle equations. See https://ncatlab.org/nlab/show/bicategory. -/ @[nolint checkUnivs] class Bicategory (B : Type u) extends CategoryStruct.{v} B where -- category structure on the collection of 1-morphisms: homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance -- left whiskering: whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h -- right whiskering: whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h -- associator: associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h -- left unitor: leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f -- right unitor: rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f -- axioms for left whiskering: whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by aesop_cat whiskerLeft_comp : ∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i), whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by aesop_cat id_whiskerLeft : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by aesop_cat comp_whiskerLeft : ∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'), whiskerLeft (f ≫ g) η = (associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by aesop_cat -- axioms for right whiskering: id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by aesop_cat comp_whiskerRight : ∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c), whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by aesop_cat whiskerRight_id : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by aesop_cat whiskerRight_comp : ∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d), whiskerRight η (g ≫ h) = (associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by aesop_cat -- associativity of whiskerings: whisker_assoc : ∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d), whiskerRight (whiskerLeft f η) h = (associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by aesop_cat -- exchange law of left and right whiskerings: whisker_exchange : ∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i), whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by aesop_cat -- pentagon identity: pentagon : ∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e), whiskerRight (associator f g h).hom i ≫ (associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom = (associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by aesop_cat -- triangle identity: triangle : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), (associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom = whiskerRight (rightUnitor f).hom g := by aesop_cat #align category_theory.bicategory CategoryTheory.Bicategory #align category_theory.bicategory.hom_category CategoryTheory.Bicategory.homCategory #align category_theory.bicategory.whisker_left CategoryTheory.Bicategory.whiskerLeft #align category_theory.bicategory.whisker_right CategoryTheory.Bicategory.whiskerRight #align category_theory.bicategory.left_unitor CategoryTheory.Bicategory.leftUnitor #align category_theory.bicategory.right_unitor CategoryTheory.Bicategory.rightUnitor #align category_theory.bicategory.whisker_left_id' CategoryTheory.Bicategory.whiskerLeft_id #align category_theory.bicategory.whisker_left_comp' CategoryTheory.Bicategory.whiskerLeft_comp #align category_theory.bicategory.id_whisker_left' CategoryTheory.Bicategory.id_whiskerLeft #align category_theory.bicategory.comp_whisker_left' CategoryTheory.Bicategory.comp_whiskerLeft #align category_theory.bicategory.id_whisker_right' CategoryTheory.Bicategory.id_whiskerRight #align category_theory.bicategory.comp_whisker_right' CategoryTheory.Bicategory.comp_whiskerRight #align category_theory.bicategory.whisker_right_id' CategoryTheory.Bicategory.whiskerRight_id #align category_theory.bicategory.whisker_right_comp' CategoryTheory.Bicategory.whiskerRight_comp #align category_theory.bicategory.whisker_assoc' CategoryTheory.Bicategory.whisker_assoc #align category_theory.bicategory.whisker_exchange' CategoryTheory.Bicategory.whisker_exchange #align category_theory.bicategory.pentagon' CategoryTheory.Bicategory.pentagon #align category_theory.bicategory.triangle' CategoryTheory.Bicategory.triangle namespace Bicategory scoped infixr:81 " ◁ " => Bicategory.whiskerLeft scoped infixl:81 " ▷ " => Bicategory.whiskerRight scoped notation "α_" => Bicategory.associator scoped notation "λ_" => Bicategory.leftUnitor scoped notation "ρ_" => Bicategory.rightUnitor /-! ### Simp-normal form for 2-morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any 2-morphisms into simp-normal form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming) `coherence` tactic. The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors) or non-structural 2-morphisms, and 2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`, where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a non-structural 2-morphisms that is also not the identity or a composite. Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`. -/ attribute [instance] homCategory attribute [reassoc] whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc whisker_exchange attribute [reassoc (attr := simp)] pentagon triangle /- The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`), which at first glance look more complicated than the LHS, but they will be eventually reduced by the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic. -/ attribute [simp] whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B} @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] #align category_theory.bicategory.hom_inv_whisker_left CategoryTheory.Bicategory.whiskerLeft_hom_inv @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] #align category_theory.bicategory.hom_inv_whisker_right CategoryTheory.Bicategory.hom_inv_whiskerRight @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] #align category_theory.bicategory.inv_hom_whisker_left CategoryTheory.Bicategory.whiskerLeft_inv_hom @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] #align category_theory.bicategory.inv_hom_whisker_right CategoryTheory.Bicategory.inv_hom_whiskerRight /-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps] def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where hom := f ◁ η.hom inv := f ◁ η.inv #align category_theory.bicategory.whisker_left_iso CategoryTheory.Bicategory.whiskerLeftIso instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) := (whiskerLeftIso f (asIso η)).isIso_hom #align category_theory.bicategory.whisker_left_is_iso CategoryTheory.Bicategory.whiskerLeft_isIso @[simp] theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : inv (f ◁ η) = f ◁ inv η := by apply IsIso.inv_eq_of_hom_inv_id simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id] #align category_theory.bicategory.inv_whisker_left CategoryTheory.Bicategory.inv_whiskerLeft /-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps!] def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where hom := η.hom ▷ h inv := η.inv ▷ h #align category_theory.bicategory.whisker_right_iso CategoryTheory.Bicategory.whiskerRightIso instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) := (whiskerRightIso (asIso η) h).isIso_hom #align category_theory.bicategory.whisker_right_is_iso CategoryTheory.Bicategory.whiskerRight_isIso @[simp] theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : inv (η ▷ h) = inv η ▷ h := by apply IsIso.inv_eq_of_hom_inv_id simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id] #align category_theory.bicategory.inv_whisker_right CategoryTheory.Bicategory.inv_whiskerRight @[reassoc (attr := simp)] theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i = (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_inv CategoryTheory.Bicategory.pentagon_inv @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom = f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv] simp #align category_theory.bicategory.pentagon_inv_inv_hom_hom_inv CategoryTheory.Bicategory.pentagon_inv_inv_hom_hom_inv @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom = (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_inv_hom_hom_hom_inv CategoryTheory.Bicategory.pentagon_inv_hom_hom_hom_inv @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv = (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by simp [← cancel_epi (f ◁ (α_ g h i).inv)] #align category_theory.bicategory.pentagon_hom_inv_inv_inv_inv CategoryTheory.Bicategory.pentagon_hom_inv_inv_inv_inv @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv = (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_hom_hom_inv_hom_hom CategoryTheory.Bicategory.pentagon_hom_hom_inv_hom_hom @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv = (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)] simp #align category_theory.bicategory.pentagon_hom_inv_inv_inv_hom CategoryTheory.Bicategory.pentagon_hom_inv_inv_inv_hom @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv = (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_hom_hom_inv_inv_hom CategoryTheory.Bicategory.pentagon_hom_hom_inv_inv_hom @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom = (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by simp [← cancel_epi ((α_ f g h).hom ▷ i)] #align category_theory.bicategory.pentagon_inv_hom_hom_hom_hom CategoryTheory.Bicategory.pentagon_inv_hom_hom_hom_hom @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i = f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_inv_inv_hom_inv_inv CategoryTheory.Bicategory.pentagon_inv_inv_hom_inv_inv theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g := triangle f g #align category_theory.bicategory.triangle_assoc_comp_left CategoryTheory.Bicategory.triangle_assoc_comp_left @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc] #align category_theory.bicategory.triangle_assoc_comp_right CategoryTheory.Bicategory.triangle_assoc_comp_right @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) : (ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by simp [← cancel_mono (f ◁ (λ_ g).hom)] #align category_theory.bicategory.triangle_assoc_comp_right_inv CategoryTheory.Bicategory.triangle_assoc_comp_right_inv @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by simp [← cancel_mono ((ρ_ f).hom ▷ g)] #align category_theory.bicategory.triangle_assoc_comp_left_inv CategoryTheory.Bicategory.triangle_assoc_comp_left_inv @[reassoc] theorem associator_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h ≫ (α_ f' g h).hom = (α_ f g h).hom ≫ η ▷ (g ≫ h) := by simp #align category_theory.bicategory.associator_naturality_left CategoryTheory.Bicategory.associator_naturality_left @[reassoc] theorem associator_inv_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ (g ≫ h) ≫ (α_ f' g h).inv = (α_ f g h).inv ≫ η ▷ g ▷ h := by simp #align category_theory.bicategory.associator_inv_naturality_left CategoryTheory.Bicategory.associator_inv_naturality_left @[reassoc] theorem whiskerRight_comp_symm {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h = (α_ f g h).hom ≫ η ▷ (g ≫ h) ≫ (α_ f' g h).inv := by simp #align category_theory.bicategory.whisker_right_comp_symm CategoryTheory.Bicategory.whiskerRight_comp_symm @[reassoc] theorem associator_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : (f ◁ η) ▷ h ≫ (α_ f g' h).hom = (α_ f g h).hom ≫ f ◁ η ▷ h := by simp #align category_theory.bicategory.associator_naturality_middle CategoryTheory.Bicategory.associator_naturality_middle @[reassoc] theorem associator_inv_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h ≫ (α_ f g' h).inv = (α_ f g h).inv ≫ (f ◁ η) ▷ h := by simp #align category_theory.bicategory.associator_inv_naturality_middle CategoryTheory.Bicategory.associator_inv_naturality_middle @[reassoc] theorem whisker_assoc_symm (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h = (α_ f g h).inv ≫ (f ◁ η) ▷ h ≫ (α_ f g' h).hom := by simp #align category_theory.bicategory.whisker_assoc_symm CategoryTheory.Bicategory.whisker_assoc_symm @[reassoc] theorem associator_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : (f ≫ g) ◁ η ≫ (α_ f g h').hom = (α_ f g h).hom ≫ f ◁ g ◁ η := by simp #align category_theory.bicategory.associator_naturality_right CategoryTheory.Bicategory.associator_naturality_right @[reassoc] theorem associator_inv_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η ≫ (α_ f g h').inv = (α_ f g h).inv ≫ (f ≫ g) ◁ η := by simp #align category_theory.bicategory.associator_inv_naturality_right CategoryTheory.Bicategory.associator_inv_naturality_right @[reassoc] theorem comp_whiskerLeft_symm (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η = (α_ f g h).inv ≫ (f ≫ g) ◁ η ≫ (α_ f g h').hom := by simp #align category_theory.bicategory.comp_whisker_left_symm CategoryTheory.Bicategory.comp_whiskerLeft_symm @[reassoc] theorem leftUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : 𝟙 a ◁ η ≫ (λ_ g).hom = (λ_ f).hom ≫ η := by simp #align category_theory.bicategory.left_unitor_naturality CategoryTheory.Bicategory.leftUnitor_naturality @[reassoc] theorem leftUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (λ_ g).inv = (λ_ f).inv ≫ 𝟙 a ◁ η := by simp #align category_theory.bicategory.left_unitor_inv_naturality CategoryTheory.Bicategory.leftUnitor_inv_naturality theorem id_whiskerLeft_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (λ_ f).inv ≫ 𝟙 a ◁ η ≫ (λ_ g).hom := by simp #align category_theory.bicategory.id_whisker_left_symm CategoryTheory.Bicategory.id_whiskerLeft_symm @[reassoc] theorem rightUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ▷ 𝟙 b ≫ (ρ_ g).hom = (ρ_ f).hom ≫ η := by simp #align category_theory.bicategory.right_unitor_naturality CategoryTheory.Bicategory.rightUnitor_naturality @[reassoc] theorem rightUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (ρ_ g).inv = (ρ_ f).inv ≫ η ▷ 𝟙 b := by simp #align category_theory.bicategory.right_unitor_inv_naturality CategoryTheory.Bicategory.rightUnitor_inv_naturality theorem whiskerRight_id_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (ρ_ f).inv ≫ η ▷ 𝟙 b ≫ (ρ_ g).hom := by simp #align category_theory.bicategory.whisker_right_id_symm CategoryTheory.Bicategory.whiskerRight_id_symm theorem whiskerLeft_iff {f g : a ⟶ b} (η θ : f ⟶ g) : 𝟙 a ◁ η = 𝟙 a ◁ θ ↔ η = θ := by simp #align category_theory.bicategory.whisker_left_iff CategoryTheory.Bicategory.whiskerLeft_iff
Mathlib/CategoryTheory/Bicategory/Basic.lean
415
415
theorem whiskerRight_iff {f g : a ⟶ b} (η θ : f ⟶ g) : η ▷ 𝟙 b = θ ▷ 𝟙 b ↔ η = θ := by
simp
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation #align_import linear_algebra.clifford_algebra.fold from "leanprover-community/mathlib"@"446eb51ce0a90f8385f260d2b52e760e2004246b" /-! # Recursive computation rules for the Clifford algebra This file provides API for a special case `CliffordAlgebra.foldr` of the universal property `CliffordAlgebra.lift` with `A = Module.End R N` for some arbitrary module `N`. This specialization resembles the `list.foldr` operation, allowing a bilinear map to be "folded" along the generators. For convenience, this file also provides `CliffordAlgebra.foldl`, implemented via `CliffordAlgebra.reverse` ## Main definitions * `CliffordAlgebra.foldr`: a computation rule for building linear maps out of the clifford algebra starting on the right, analogous to using `list.foldr` on the generators. * `CliffordAlgebra.foldl`: a computation rule for building linear maps out of the clifford algebra starting on the left, analogous to using `list.foldl` on the generators. ## Main statements * `CliffordAlgebra.right_induction`: an induction rule that adds generators from the right. * `CliffordAlgebra.left_induction`: an induction rule that adds generators from the left. -/ universe u1 u2 u3 variable {R M N : Type*} variable [CommRing R] [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] variable (Q : QuadraticForm R M) namespace CliffordAlgebra section Foldr /-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule given by `foldr Q f hf n (ι Q m * x) = f m (foldr Q f hf n x)`. For example, `foldr f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/ def foldr (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) : N →ₗ[R] CliffordAlgebra Q →ₗ[R] N := (CliffordAlgebra.lift Q ⟨f, fun v => LinearMap.ext <| hf v⟩).toLinearMap.flip #align clifford_algebra.foldr CliffordAlgebra.foldr @[simp] theorem foldr_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldr Q f hf n (ι Q m) = f m n := LinearMap.congr_fun (lift_ι_apply _ _ _) n #align clifford_algebra.foldr_ι CliffordAlgebra.foldr_ι @[simp] theorem foldr_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) : foldr Q f hf n (algebraMap R _ r) = r • n := LinearMap.congr_fun (AlgHom.commutes _ r) n #align clifford_algebra.foldr_algebra_map CliffordAlgebra.foldr_algebraMap @[simp] theorem foldr_one (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldr Q f hf n 1 = n := LinearMap.congr_fun (AlgHom.map_one _) n #align clifford_algebra.foldr_one CliffordAlgebra.foldr_one @[simp] theorem foldr_mul (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) : foldr Q f hf n (a * b) = foldr Q f hf (foldr Q f hf n b) a := LinearMap.congr_fun (AlgHom.map_mul _ _ _) n #align clifford_algebra.foldr_mul CliffordAlgebra.foldr_mul /-- This lemma demonstrates the origin of the `foldr` name. -/ theorem foldr_prod_map_ι (l : List M) (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldr Q f hf n (l.map <| ι Q).prod = List.foldr (fun m n => f m n) n l := by induction' l with hd tl ih · rw [List.map_nil, List.prod_nil, List.foldr_nil, foldr_one] · rw [List.map_cons, List.prod_cons, List.foldr_cons, foldr_mul, foldr_ι, ih] #align clifford_algebra.foldr_prod_map_ι CliffordAlgebra.foldr_prod_map_ι end Foldr section Foldl /-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule given by `foldl Q f hf n (ι Q m * x) = f m (foldl Q f hf n x)`. For example, `foldl f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/ def foldl (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) : N →ₗ[R] CliffordAlgebra Q →ₗ[R] N := LinearMap.compl₂ (foldr Q f hf) reverse #align clifford_algebra.foldl CliffordAlgebra.foldl @[simp] theorem foldl_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) : foldl Q f hf n (reverse x) = foldr Q f hf n x := DFunLike.congr_arg (foldr Q f hf n) <| reverse_reverse _ #align clifford_algebra.foldl_reverse CliffordAlgebra.foldl_reverse @[simp] theorem foldr_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) : foldr Q f hf n (reverse x) = foldl Q f hf n x := rfl #align clifford_algebra.foldr_reverse CliffordAlgebra.foldr_reverse @[simp] theorem foldl_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldl Q f hf n (ι Q m) = f m n := by rw [← foldr_reverse, reverse_ι, foldr_ι] #align clifford_algebra.foldl_ι CliffordAlgebra.foldl_ι @[simp]
Mathlib/LinearAlgebra/CliffordAlgebra/Fold.lean
115
117
theorem foldl_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) : foldl Q f hf n (algebraMap R _ r) = r • n := by
rw [← foldr_reverse, reverse.commutes, foldr_algebraMap]
/- Copyright (c) 2022 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Heather Macbeth -/ import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.RingTheory.WittVector.Truncated #align_import ring_theory.witt_vector.mul_coeff from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Leading terms of Witt vector multiplication The goal of this file is to study the leading terms of the formula for the `n+1`st coefficient of a product of Witt vectors `x` and `y` over a ring of characteristic `p`. We aim to isolate the `n+1`st coefficients of `x` and `y`, and express the rest of the product in terms of a function of the lower coefficients. For most of this file we work with terms of type `MvPolynomial (Fin 2 × ℕ) ℤ`. We will eventually evaluate them in `k`, but first we must take care of a calculation that needs to happen in characteristic 0. ## Main declarations * `WittVector.nth_mul_coeff`: expresses the coefficient of a product of Witt vectors in terms of the previous coefficients of the multiplicands. -/ noncomputable section namespace WittVector variable (p : ℕ) [hp : Fact p.Prime] variable {k : Type*} [CommRing k] local notation "𝕎" => WittVector p -- Porting note: new notation local notation "𝕄" => MvPolynomial (Fin 2 × ℕ) ℤ open Finset MvPolynomial /-- ``` (∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) * (∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) ``` -/ def wittPolyProd (n : ℕ) : 𝕄 := rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ n) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ n) #align witt_vector.witt_poly_prod WittVector.wittPolyProd theorem wittPolyProd_vars (n : ℕ) : (wittPolyProd p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [wittPolyProd] apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ <;> · refine Subset.trans (vars_rename _ _) ?_ simp [wittPolynomial_vars, image_subset_iff] #align witt_vector.witt_poly_prod_vars WittVector.wittPolyProd_vars /-- The "remainder term" of `WittVector.wittPolyProd`. See `mul_polyOfInterest_aux2`. -/ def wittPolyProdRemainder (n : ℕ) : 𝕄 := ∑ i ∈ range n, (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i) #align witt_vector.witt_poly_prod_remainder WittVector.wittPolyProdRemainder theorem wittPolyProdRemainder_vars (n : ℕ) : (wittPolyProdRemainder p n).vars ⊆ univ ×ˢ range n := by rw [wittPolyProdRemainder] refine Subset.trans (vars_sum_subset _ _) ?_ rw [biUnion_subset] intro x hx apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ · apply Subset.trans (vars_pow _ _) have : (p : 𝕄) = C (p : ℤ) := by simp only [Int.cast_natCast, eq_intCast] rw [this, vars_C] apply empty_subset · apply Subset.trans (vars_pow _ _) apply Subset.trans (wittMul_vars _ _) apply product_subset_product (Subset.refl _) simp only [mem_range, range_subset] at hx ⊢ exact hx #align witt_vector.witt_poly_prod_remainder_vars WittVector.wittPolyProdRemainder_vars /-- `remainder p n` represents the remainder term from `mul_polyOfInterest_aux3`. `wittPolyProd p (n+1)` will have variables up to `n+1`, but `remainder` will only have variables up to `n`. -/ def remainder (n : ℕ) : 𝕄 := (∑ x ∈ range (n + 1), (rename (Prod.mk 0)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x))) * ∑ x ∈ range (n + 1), (rename (Prod.mk 1)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x)) #align witt_vector.remainder WittVector.remainder theorem remainder_vars (n : ℕ) : (remainder p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [remainder] apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ <;> · refine Subset.trans (vars_sum_subset _ _) ?_ rw [biUnion_subset] intro x hx rw [rename_monomial, vars_monomial, Finsupp.mapDomain_single] · apply Subset.trans Finsupp.support_single_subset simpa using mem_range.mp hx · apply pow_ne_zero exact mod_cast hp.out.ne_zero #align witt_vector.remainder_vars WittVector.remainder_vars /-- This is the polynomial whose degree we want to get a handle on. -/ def polyOfInterest (n : ℕ) : 𝕄 := wittMul p (n + 1) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * X (1, n + 1) - X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) - X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) #align witt_vector.poly_of_interest WittVector.polyOfInterest theorem mul_polyOfInterest_aux1 (n : ℕ) : ∑ i ∈ range (n + 1), (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i) = wittPolyProd p n := by simp only [wittPolyProd] convert wittStructureInt_prop p (X (0 : Fin 2) * X 1) n using 1 · simp only [wittPolynomial, wittMul] rw [AlgHom.map_sum] congr 1 with i congr 1 have hsupp : (Finsupp.single i (p ^ (n - i))).support = {i} := by rw [Finsupp.support_eq_singleton] simp only [and_true_iff, Finsupp.single_eq_same, eq_self_iff_true, Ne] exact pow_ne_zero _ hp.out.ne_zero simp only [bind₁_monomial, hsupp, Int.cast_natCast, prod_singleton, eq_intCast, Finsupp.single_eq_same, C_pow, mul_eq_mul_left_iff, true_or_iff, eq_self_iff_true, Int.cast_pow] · simp only [map_mul, bind₁_X_right] #align witt_vector.mul_poly_of_interest_aux1 WittVector.mul_polyOfInterest_aux1 theorem mul_polyOfInterest_aux2 (n : ℕ) : (p : 𝕄) ^ n * wittMul p n + wittPolyProdRemainder p n = wittPolyProd p n := by convert mul_polyOfInterest_aux1 p n rw [sum_range_succ, add_comm, Nat.sub_self, pow_zero, pow_one] rfl #align witt_vector.mul_poly_of_interest_aux2 WittVector.mul_polyOfInterest_aux2 theorem mul_polyOfInterest_aux3 (n : ℕ) : wittPolyProd p (n + 1) = -((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + (p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + remainder p n := by -- a useful auxiliary fact have mvpz : (p : 𝕄) ^ (n + 1) = MvPolynomial.C ((p : ℤ) ^ (n + 1)) := by norm_cast -- Porting note: the original proof applies `sum_range_succ` through a non-`conv` rewrite, -- but this does not work in Lean 4; the whole proof also times out very badly. The proof has been -- nearly totally rewritten here and now finishes quite fast. rw [wittPolyProd, wittPolynomial, AlgHom.map_sum, AlgHom.map_sum] conv_lhs => arg 1 rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] conv_lhs => arg 2 rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] conv_rhs => enter [1, 1, 2, 2] rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] conv_rhs => enter [1, 2, 2] rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] simp only [add_mul, mul_add] rw [add_comm _ (remainder p n)] simp only [add_assoc] apply congrArg (Add.add _) ring #align witt_vector.mul_poly_of_interest_aux3 WittVector.mul_polyOfInterest_aux3 theorem mul_polyOfInterest_aux4 (n : ℕ) : (p : 𝕄) ^ (n + 1) * wittMul p (n + 1) = -((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + (p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + (remainder p n - wittPolyProdRemainder p (n + 1)) := by rw [← add_sub_assoc, eq_sub_iff_add_eq, mul_polyOfInterest_aux2] exact mul_polyOfInterest_aux3 _ _ #align witt_vector.mul_poly_of_interest_aux4 WittVector.mul_polyOfInterest_aux4 theorem mul_polyOfInterest_aux5 (n : ℕ) : (p : 𝕄) ^ (n + 1) * polyOfInterest p n = remainder p n - wittPolyProdRemainder p (n + 1) := by simp only [polyOfInterest, mul_sub, mul_add, sub_eq_iff_eq_add'] rw [mul_polyOfInterest_aux4 p n] ring #align witt_vector.mul_poly_of_interest_aux5 WittVector.mul_polyOfInterest_aux5 theorem mul_polyOfInterest_vars (n : ℕ) : ((p : 𝕄) ^ (n + 1) * polyOfInterest p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [mul_polyOfInterest_aux5] apply Subset.trans (vars_sub_subset _) refine union_subset ?_ ?_ · apply remainder_vars · apply wittPolyProdRemainder_vars #align witt_vector.mul_poly_of_interest_vars WittVector.mul_polyOfInterest_vars
Mathlib/RingTheory/WittVector/MulCoeff.lean
205
212
theorem polyOfInterest_vars_eq (n : ℕ) : (polyOfInterest p n).vars = ((p : 𝕄) ^ (n + 1) * (wittMul p (n + 1) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * X (1, n + 1) - X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) - X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)))).vars := by
have : (p : 𝕄) ^ (n + 1) = C ((p : ℤ) ^ (n + 1)) := by norm_cast rw [polyOfInterest, this, vars_C_mul] apply pow_ne_zero exact mod_cast hp.out.ne_zero
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign #align_import analysis.special_functions.trigonometric.angle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real -- Porting note: can't derive `NormedAddCommGroup, Inhabited` /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) #align real.angle Real.Angle namespace Angle -- Porting note (#10754): added due to missing instances due to no deriving instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving -- also, without this, a plain `QuotientAddGroup.mk` -- causes coerced terms to be of type `ℝ ⧸ AddSubgroup.zmultiples (2 * π)` /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' #align real.angle.continuous_coe Real.Angle.continuous_coe /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ #align real.angle.coe_hom Real.Angle.coeHom @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl #align real.angle.coe_coe_hom Real.Angle.coe_coeHom /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h #align real.angle.induction_on Real.Angle.induction_on @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl #align real.angle.coe_zero Real.Angle.coe_zero @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl #align real.angle.coe_add Real.Angle.coe_add @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl #align real.angle.coe_neg Real.Angle.coe_neg @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl #align real.angle.coe_sub Real.Angle.coe_sub theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl #align real.angle.coe_nsmul Real.Angle.coe_nsmul theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl #align real.angle.coe_zsmul Real.Angle.coe_zsmul @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n #align real.angle.coe_nat_mul_eq_nsmul Real.Angle.natCast_mul_eq_nsmul @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n #align real.angle.coe_int_mul_eq_zsmul Real.Angle.intCast_mul_eq_zsmul @[deprecated (since := "2024-05-25")] alias coe_nat_mul_eq_nsmul := natCast_mul_eq_nsmul @[deprecated (since := "2024-05-25")] alias coe_int_mul_eq_zsmul := intCast_mul_eq_zsmul theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] -- Porting note: added `rw`, `simp [Angle.coe, QuotientAddGroup.eq]` doesn't fire otherwise rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] #align real.angle.angle_eq_iff_two_pi_dvd_sub Real.Angle.angle_eq_iff_two_pi_dvd_sub @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ #align real.angle.coe_two_pi Real.Angle.coe_two_pi @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] #align real.angle.neg_coe_pi Real.Angle.neg_coe_pi @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] #align real.angle.two_nsmul_coe_div_two Real.Angle.two_nsmul_coe_div_two @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] #align real.angle.two_zsmul_coe_div_two Real.Angle.two_zsmul_coe_div_two -- Porting note (#10618): @[simp] can prove it theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] #align real.angle.two_nsmul_neg_pi_div_two Real.Angle.two_nsmul_neg_pi_div_two -- Porting note (#10618): @[simp] can prove it theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] #align real.angle.two_zsmul_neg_pi_div_two Real.Angle.two_zsmul_neg_pi_div_two theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] #align real.angle.sub_coe_pi_eq_add_coe_pi Real.Angle.sub_coe_pi_eq_add_coe_pi @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] #align real.angle.two_nsmul_coe_pi Real.Angle.two_nsmul_coe_pi @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] #align real.angle.two_zsmul_coe_pi Real.Angle.two_zsmul_coe_pi @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] #align real.angle.coe_pi_add_coe_pi Real.Angle.coe_pi_add_coe_pi theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz #align real.angle.zsmul_eq_iff Real.Angle.zsmul_eq_iff theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz #align real.angle.nsmul_eq_iff Real.Angle.nsmul_eq_iff theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by -- Porting note: no `Int.natAbs_bit0` anymore have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] #align real.angle.two_zsmul_eq_iff Real.Angle.two_zsmul_eq_iff theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] #align real.angle.two_nsmul_eq_iff Real.Angle.two_nsmul_eq_iff theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp #align real.angle.two_nsmul_eq_zero_iff Real.Angle.two_nsmul_eq_zero_iff theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] #align real.angle.two_nsmul_ne_zero_iff Real.Angle.two_nsmul_ne_zero_iff theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.two_zsmul_eq_zero_iff Real.Angle.two_zsmul_eq_zero_iff theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] #align real.angle.two_zsmul_ne_zero_iff Real.Angle.two_zsmul_ne_zero_iff theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.eq_neg_self_iff Real.Angle.eq_neg_self_iff theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] #align real.angle.ne_neg_self_iff Real.Angle.ne_neg_self_iff theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] #align real.angle.neg_eq_self_iff Real.Angle.neg_eq_self_iff theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] #align real.angle.neg_ne_self_iff Real.Angle.neg_ne_self_iff theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ) :) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] #align real.angle.two_nsmul_eq_pi_iff Real.Angle.two_nsmul_eq_pi_iff theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] #align real.angle.two_zsmul_eq_pi_iff Real.Angle.two_zsmul_eq_pi_iff theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or_iff, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] #align real.angle.cos_eq_iff_coe_eq_or_eq_neg Real.Angle.cos_eq_iff_coe_eq_or_eq_neg theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] #align real.angle.sin_eq_iff_coe_eq_or_add_eq_pi Real.Angle.sin_eq_iff_coe_eq_or_add_eq_pi theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc hc; · exact hc cases' sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false_iff, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self] at this exact absurd this one_ne_zero #align real.angle.cos_sin_inj Real.Angle.cos_sin_inj /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ #align real.angle.sin Real.Angle.sin @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl #align real.angle.sin_coe Real.Angle.sin_coe @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ #align real.angle.continuous_sin Real.Angle.continuous_sin /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ #align real.angle.cos Real.Angle.cos @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl #align real.angle.cos_coe Real.Angle.cos_coe @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ #align real.angle.continuous_cos Real.Angle.continuous_cos theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg #align real.angle.cos_eq_real_cos_iff_eq_or_eq_neg Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg #align real.angle.cos_eq_iff_eq_or_eq_neg Real.Angle.cos_eq_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi #align real.angle.sin_eq_real_sin_iff_eq_or_add_eq_pi Real.Angle.sin_eq_real_sin_iff_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi #align real.angle.sin_eq_iff_eq_or_add_eq_pi Real.Angle.sin_eq_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] #align real.angle.sin_zero Real.Angle.sin_zero -- Porting note (#10618): @[simp] can prove it theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] #align real.angle.sin_coe_pi Real.Angle.sin_coe_pi theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp #align real.angle.sin_eq_zero_iff Real.Angle.sin_eq_zero_iff theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] #align real.angle.sin_ne_zero_iff Real.Angle.sin_ne_zero_iff @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ #align real.angle.sin_neg Real.Angle.sin_neg theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _ #align real.angle.sin_antiperiodic Real.Angle.sin_antiperiodic @[simp] theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ := sin_antiperiodic θ #align real.angle.sin_add_pi Real.Angle.sin_add_pi @[simp] theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ := sin_antiperiodic.sub_eq θ #align real.angle.sin_sub_pi Real.Angle.sin_sub_pi @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] #align real.angle.cos_zero Real.Angle.cos_zero -- Porting note (#10618): @[simp] can prove it theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi] #align real.angle.cos_coe_pi Real.Angle.cos_coe_pi @[simp] theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.cos_neg _ #align real.angle.cos_neg Real.Angle.cos_neg theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.cos_antiperiodic _ #align real.angle.cos_antiperiodic Real.Angle.cos_antiperiodic @[simp] theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ := cos_antiperiodic θ #align real.angle.cos_add_pi Real.Angle.cos_add_pi @[simp] theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ := cos_antiperiodic.sub_eq θ #align real.angle.cos_sub_pi Real.Angle.cos_sub_pi theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] #align real.angle.cos_eq_zero_iff Real.Angle.cos_eq_zero_iff theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact Real.sin_add _ _ #align real.angle.sin_add Real.Angle.sin_add theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by induction θ₂ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ #align real.angle.cos_add Real.Angle.cos_add @[simp] theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by induction θ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ #align real.angle.cos_sq_add_sin_sq Real.Angle.cos_sq_add_sin_sq theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ #align real.angle.sin_add_pi_div_two Real.Angle.sin_add_pi_div_two theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ #align real.angle.sin_sub_pi_div_two Real.Angle.sin_sub_pi_div_two theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ #align real.angle.sin_pi_div_two_sub Real.Angle.sin_pi_div_two_sub theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ #align real.angle.cos_add_pi_div_two Real.Angle.cos_add_pi_div_two theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ #align real.angle.cos_sub_pi_div_two Real.Angle.cos_sub_pi_div_two theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ #align real.angle.cos_pi_div_two_sub Real.Angle.cos_pi_div_two_sub theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |sin θ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [sin_add_pi, abs_neg] #align real.angle.abs_sin_eq_of_two_nsmul_eq Real.Angle.abs_sin_eq_of_two_nsmul_eq theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |sin θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h #align real.angle.abs_sin_eq_of_two_zsmul_eq Real.Angle.abs_sin_eq_of_two_zsmul_eq theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |cos θ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [cos_add_pi, abs_neg] #align real.angle.abs_cos_eq_of_two_nsmul_eq Real.Angle.abs_cos_eq_of_two_nsmul_eq theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |cos θ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h #align real.angle.abs_cos_eq_of_two_zsmul_eq Real.Angle.abs_cos_eq_of_two_zsmul_eq @[simp]
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
508
511
theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by
rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm]
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.RepresentationTheory.FdRep import Mathlib.LinearAlgebra.Trace import Mathlib.RepresentationTheory.Invariants #align_import representation_theory.character from "leanprover-community/mathlib"@"55b3f8206b8596db8bb1804d8a92814a0b6670c9" /-! # Characters of representations This file introduces characters of representation and proves basic lemmas about how characters behave under various operations on representations. A key result is the orthogonality of characters for irreducible representations of finite group over an algebraically closed field whose characteristic doesn't divide the order of the group. It is the theorem `char_orthonormal` # Implementation notes Irreducible representations are implemented categorically, using the `Simple` class defined in `Mathlib.CategoryTheory.Simple` # TODO * Once we have the monoidal closed structure on `FdRep k G` and a better API for the rigid structure, `char_dual` and `char_linHom` should probably be stated in terms of `Vᘁ` and `ihom V W`. -/ noncomputable section universe u open CategoryTheory LinearMap CategoryTheory.MonoidalCategory Representation FiniteDimensional variable {k : Type u} [Field k] namespace FdRep set_option linter.uppercaseLean3 false -- `FdRep` section Monoid variable {G : Type u} [Monoid G] /-- The character of a representation `V : FdRep k G` is the function associating to `g : G` the trace of the linear map `V.ρ g`. -/ def character (V : FdRep k G) (g : G) := LinearMap.trace k V (V.ρ g) #align fdRep.character FdRep.character theorem char_mul_comm (V : FdRep k G) (g : G) (h : G) : V.character (h * g) = V.character (g * h) := by simp only [trace_mul_comm, character, map_mul] #align fdRep.char_mul_comm FdRep.char_mul_comm @[simp] theorem char_one (V : FdRep k G) : V.character 1 = FiniteDimensional.finrank k V := by simp only [character, map_one, trace_one] #align fdRep.char_one FdRep.char_one /-- The character is multiplicative under the tensor product. -/ theorem char_tensor (V W : FdRep k G) : (V ⊗ W).character = V.character * W.character := by ext g; convert trace_tensorProduct' (V.ρ g) (W.ρ g) #align fdRep.char_tensor FdRep.char_tensor -- Porting note: adding variant of `char_tensor` to make the simp-set confluent @[simp] theorem char_tensor' (V W : FdRep k G) : character (Action.FunctorCategoryEquivalence.inverse.obj (Action.FunctorCategoryEquivalence.functor.obj V ⊗ Action.FunctorCategoryEquivalence.functor.obj W)) = V.character * W.character := by simp [← char_tensor] /-- The character of isomorphic representations is the same. -/ theorem char_iso {V W : FdRep k G} (i : V ≅ W) : V.character = W.character := by ext g; simp only [character, FdRep.Iso.conj_ρ i]; exact (trace_conj' (V.ρ g) _).symm #align fdRep.char_iso FdRep.char_iso end Monoid section Group variable {G : Type u} [Group G] /-- The character of a representation is constant on conjugacy classes. -/ @[simp] theorem char_conj (V : FdRep k G) (g : G) (h : G) : V.character (h * g * h⁻¹) = V.character g := by rw [char_mul_comm, inv_mul_cancel_left] #align fdRep.char_conj FdRep.char_conj @[simp] theorem char_dual (V : FdRep k G) (g : G) : (of (dual V.ρ)).character g = V.character g⁻¹ := trace_transpose' (V.ρ g⁻¹) #align fdRep.char_dual FdRep.char_dual @[simp] theorem char_linHom (V W : FdRep k G) (g : G) : (of (linHom V.ρ W.ρ)).character g = V.character g⁻¹ * W.character g := by rw [← char_iso (dualTensorIsoLinHom _ _), char_tensor, Pi.mul_apply, char_dual] #align fdRep.char_lin_hom FdRep.char_linHom variable [Fintype G] [Invertible (Fintype.card G : k)]
Mathlib/RepresentationTheory/Character.lean
106
109
theorem average_char_eq_finrank_invariants (V : FdRep k G) : ⅟ (Fintype.card G : k) • ∑ g : G, V.character g = finrank k (invariants V.ρ) := by
erw [← (isProj_averageMap V.ρ).trace] -- Porting note: Changed `rw` to `erw` simp [character, GroupAlgebra.average, _root_.map_sum]
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Oleksandr Manzyuk -/ import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.Monoidal.Mon_ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers #align_import category_theory.monoidal.Bimod from "leanprover-community/mathlib"@"4698e35ca56a0d4fa53aa5639c3364e0a77f4eba" /-! # The category of bimodule objects over a pair of monoid objects. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory open CategoryTheory.MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] section open CategoryTheory.Limits variable [HasCoequalizers C] section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] theorem id_tensor_π_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Z ⊗ Y ⟶ W) (wh : (Z ◁ f) ≫ h = (Z ◁ g) ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorLeft Z) f g h wh #align id_tensor_π_preserves_coequalizer_inv_desc id_tensor_π_preserves_coequalizer_inv_desc theorem id_tensor_π_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : Z ⊗ X ⟶ X') (q : Z ⊗ Y ⟶ Y') (wf : (Z ◁ f) ≫ q = p ≫ f') (wg : (Z ◁ g) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ colimMap (parallelPairHom (Z ◁ f) (Z ◁ g) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorLeft Z) f g f' g' p q wf wg h wh #align id_tensor_π_preserves_coequalizer_inv_colim_map_desc id_tensor_π_preserves_coequalizer_inv_colimMap_desc end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem π_tensor_id_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Y ⊗ Z ⟶ W) (wh : (f ▷ Z) ≫ h = (g ▷ Z) ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorRight Z) f g h wh #align π_tensor_id_preserves_coequalizer_inv_desc π_tensor_id_preserves_coequalizer_inv_desc theorem π_tensor_id_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⊗ Z ⟶ X') (q : Y ⊗ Z ⟶ Y') (wf : (f ▷ Z) ≫ q = p ≫ f') (wg : (g ▷ Z) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ colimMap (parallelPairHom (f ▷ Z) (g ▷ Z) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorRight Z) f g f' g' p q wf wg h wh #align π_tensor_id_preserves_coequalizer_inv_colim_map_desc π_tensor_id_preserves_coequalizer_inv_colimMap_desc end end /-- A bimodule object for a pair of monoid objects, all internal to some monoidal category. -/ structure Bimod (A B : Mon_ C) where X : C actLeft : A.X ⊗ X ⟶ X one_actLeft : (A.one ▷ X) ≫ actLeft = (λ_ X).hom := by aesop_cat left_assoc : (A.mul ▷ X) ≫ actLeft = (α_ A.X A.X X).hom ≫ (A.X ◁ actLeft) ≫ actLeft := by aesop_cat actRight : X ⊗ B.X ⟶ X actRight_one : (X ◁ B.one) ≫ actRight = (ρ_ X).hom := by aesop_cat right_assoc : (X ◁ B.mul) ≫ actRight = (α_ X B.X B.X).inv ≫ (actRight ▷ B.X) ≫ actRight := by aesop_cat middle_assoc : (actLeft ▷ B.X) ≫ actRight = (α_ A.X X B.X).hom ≫ (A.X ◁ actRight) ≫ actLeft := by aesop_cat set_option linter.uppercaseLean3 false in #align Bimod Bimod attribute [reassoc (attr := simp)] Bimod.one_actLeft Bimod.actRight_one Bimod.left_assoc Bimod.right_assoc Bimod.middle_assoc namespace Bimod variable {A B : Mon_ C} (M : Bimod A B) /-- A morphism of bimodule objects. -/ @[ext] structure Hom (M N : Bimod A B) where hom : M.X ⟶ N.X left_act_hom : M.actLeft ≫ hom = (A.X ◁ hom) ≫ N.actLeft := by aesop_cat right_act_hom : M.actRight ≫ hom = (hom ▷ B.X) ≫ N.actRight := by aesop_cat set_option linter.uppercaseLean3 false in #align Bimod.hom Bimod.Hom attribute [reassoc (attr := simp)] Hom.left_act_hom Hom.right_act_hom /-- The identity morphism on a bimodule object. -/ @[simps] def id' (M : Bimod A B) : Hom M M where hom := 𝟙 M.X set_option linter.uppercaseLean3 false in #align Bimod.id' Bimod.id' instance homInhabited (M : Bimod A B) : Inhabited (Hom M M) := ⟨id' M⟩ set_option linter.uppercaseLean3 false in #align Bimod.hom_inhabited Bimod.homInhabited /-- Composition of bimodule object morphisms. -/ @[simps] def comp {M N O : Bimod A B} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom set_option linter.uppercaseLean3 false in #align Bimod.comp Bimod.comp instance : Category (Bimod A B) where Hom M N := Hom M N id := id' comp f g := comp f g -- Porting note: added because `Hom.ext` is not triggered automatically @[ext] lemma hom_ext {M N : Bimod A B} (f g : M ⟶ N) (h : f.hom = g.hom) : f = g := Hom.ext _ _ h @[simp] theorem id_hom' (M : Bimod A B) : (𝟙 M : Hom M M).hom = 𝟙 M.X := rfl set_option linter.uppercaseLean3 false in #align Bimod.id_hom' Bimod.id_hom' @[simp] theorem comp_hom' {M N K : Bimod A B} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : Hom M K).hom = f.hom ≫ g.hom := rfl set_option linter.uppercaseLean3 false in #align Bimod.comp_hom' Bimod.comp_hom' /-- Construct an isomorphism of bimodules by giving an isomorphism between the underlying objects and checking compatibility with left and right actions only in the forward direction. -/ @[simps] def isoOfIso {X Y : Mon_ C} {P Q : Bimod X Y} (f : P.X ≅ Q.X) (f_left_act_hom : P.actLeft ≫ f.hom = (X.X ◁ f.hom) ≫ Q.actLeft) (f_right_act_hom : P.actRight ≫ f.hom = (f.hom ▷ Y.X) ≫ Q.actRight) : P ≅ Q where hom := { hom := f.hom } inv := { hom := f.inv left_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_left_act_hom, ← Category.assoc, ← MonoidalCategory.whiskerLeft_comp, Iso.inv_hom_id, MonoidalCategory.whiskerLeft_id, Category.id_comp] right_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_right_act_hom, ← Category.assoc, ← comp_whiskerRight, Iso.inv_hom_id, MonoidalCategory.id_whiskerRight, Category.id_comp] } hom_inv_id := by ext; dsimp; rw [Iso.hom_inv_id] inv_hom_id := by ext; dsimp; rw [Iso.inv_hom_id] set_option linter.uppercaseLean3 false in #align Bimod.iso_of_iso Bimod.isoOfIso variable (A) /-- A monoid object as a bimodule over itself. -/ @[simps] def regular : Bimod A A where X := A.X actLeft := A.mul actRight := A.mul set_option linter.uppercaseLean3 false in #align Bimod.regular Bimod.regular instance : Inhabited (Bimod A A) := ⟨regular A⟩ /-- The forgetful functor from bimodule objects to the ambient category. -/ def forget : Bimod A B ⥤ C where obj A := A.X map f := f.hom set_option linter.uppercaseLean3 false in #align Bimod.forget Bimod.forget open CategoryTheory.Limits variable [HasCoequalizers C] namespace TensorBimod variable {R S T : Mon_ C} (P : Bimod R S) (Q : Bimod S T) /-- The underlying object of the tensor product of two bimodules. -/ noncomputable def X : C := coequalizer (P.actRight ▷ Q.X) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actLeft)) set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.X Bimod.TensorBimod.X section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] /-- Left action for the tensor product of two bimodules. -/ noncomputable def actLeft : R.X ⊗ X P Q ⟶ X P Q := (PreservesCoequalizer.iso (tensorLeft R.X) _ _).inv ≫ colimMap (parallelPairHom _ _ _ _ ((α_ _ _ _).inv ≫ ((α_ _ _ _).inv ▷ _) ≫ (P.actLeft ▷ S.X ▷ Q.X)) ((α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X)) (by dsimp simp only [Category.assoc] slice_lhs 1 2 => rw [associator_inv_naturality_middle] slice_rhs 3 4 => rw [← comp_whiskerRight, middle_assoc, comp_whiskerRight] coherence) (by dsimp slice_lhs 1 1 => rw [MonoidalCategory.whiskerLeft_comp] slice_lhs 2 3 => rw [associator_inv_naturality_right] slice_lhs 3 4 => rw [whisker_exchange] coherence)) set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.act_left Bimod.TensorBimod.actLeft theorem whiskerLeft_π_actLeft : (R.X ◁ coequalizer.π _ _) ≫ actLeft P Q = (α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X) ≫ coequalizer.π _ _ := by erw [map_π_preserves_coequalizer_inv_colimMap (tensorLeft _)] simp only [Category.assoc] set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.id_tensor_π_act_left Bimod.TensorBimod.whiskerLeft_π_actLeft
Mathlib/CategoryTheory/Monoidal/Bimod.lean
250
259
theorem one_act_left' : (R.one ▷ _) ≫ actLeft P Q = (λ_ _).hom := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace `rw` by `erw` slice_lhs 1 2 => erw [whisker_exchange] slice_lhs 2 3 => rw [whiskerLeft_π_actLeft] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, one_actLeft] slice_rhs 1 2 => rw [leftUnitor_naturality] coherence
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.OuterMeasure.Caratheodory /-! # Induced Outer Measure We can extend a function defined on a subset of `Set α` to an outer measure. The underlying function is called `extend`, and the measure it induces is called `inducedOuterMeasure`. Some lemmas below are proven twice, once in the general case, and one where the function `m` is only defined on measurable sets (i.e. when `P = MeasurableSet`). In the latter cases, we can remove some hypotheses in the statement. The general version has the same name, but with a prime at the end. ## Tags outer measure -/ #align_import measure_theory.measure.outer_measure from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" noncomputable section open Set Function Filter open scoped Classical NNReal Topology ENNReal namespace MeasureTheory open OuterMeasure section Extend variable {α : Type*} {P : α → Prop} variable (m : ∀ s : α, P s → ℝ≥0∞) /-- We can trivially extend a function defined on a subclass of objects (with codomain `ℝ≥0∞`) to all objects by defining it to be `∞` on the objects not in the class. -/ def extend (s : α) : ℝ≥0∞ := ⨅ h : P s, m s h #align measure_theory.extend MeasureTheory.extend theorem extend_eq {s : α} (h : P s) : extend m s = m s h := by simp [extend, h] #align measure_theory.extend_eq MeasureTheory.extend_eq theorem extend_eq_top {s : α} (h : ¬P s) : extend m s = ∞ := by simp [extend, h] #align measure_theory.extend_eq_top MeasureTheory.extend_eq_top theorem smul_extend {R} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] {c : R} (hc : c ≠ 0) : c • extend m = extend fun s h => c • m s h := by ext1 s dsimp [extend] by_cases h : P s · simp [h] · simp [h, ENNReal.smul_top, hc] #align measure_theory.smul_extend MeasureTheory.smul_extend theorem le_extend {s : α} (h : P s) : m s h ≤ extend m s := by simp only [extend, le_iInf_iff] intro rfl #align measure_theory.le_extend MeasureTheory.le_extend -- TODO: why this is a bad `congr` lemma? theorem extend_congr {β : Type*} {Pb : β → Prop} {mb : ∀ s : β, Pb s → ℝ≥0∞} {sa : α} {sb : β} (hP : P sa ↔ Pb sb) (hm : ∀ (ha : P sa) (hb : Pb sb), m sa ha = mb sb hb) : extend m sa = extend mb sb := iInf_congr_Prop hP fun _h => hm _ _ #align measure_theory.extend_congr MeasureTheory.extend_congr @[simp] theorem extend_top {α : Type*} {P : α → Prop} : extend (fun _ _ => ∞ : ∀ s : α, P s → ℝ≥0∞) = ⊤ := funext fun _ => iInf_eq_top.mpr fun _ => rfl #align measure_theory.extend_top MeasureTheory.extend_top end Extend section ExtendSet variable {α : Type*} {P : Set α → Prop} variable {m : ∀ s : Set α, P s → ℝ≥0∞} variable (P0 : P ∅) (m0 : m ∅ P0 = 0) variable (PU : ∀ ⦃f : ℕ → Set α⦄ (_hm : ∀ i, P (f i)), P (⋃ i, f i)) variable (mU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)), Pairwise (Disjoint on f) → m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i)) variable (msU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)), m (⋃ i, f i) (PU hm) ≤ ∑' i, m (f i) (hm i)) variable (m_mono : ∀ ⦃s₁ s₂ : Set α⦄ (hs₁ : P s₁) (hs₂ : P s₂), s₁ ⊆ s₂ → m s₁ hs₁ ≤ m s₂ hs₂) theorem extend_empty : extend m ∅ = 0 := (extend_eq _ P0).trans m0 #align measure_theory.extend_empty MeasureTheory.extend_empty theorem extend_iUnion_nat {f : ℕ → Set α} (hm : ∀ i, P (f i)) (mU : m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i)) : extend m (⋃ i, f i) = ∑' i, extend m (f i) := (extend_eq _ _).trans <| mU.trans <| by congr with i rw [extend_eq] #align measure_theory.extend_Union_nat MeasureTheory.extend_iUnion_nat section Subadditive theorem extend_iUnion_le_tsum_nat' (s : ℕ → Set α) : extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by by_cases h : ∀ i, P (s i) · rw [extend_eq _ (PU h), congr_arg tsum _] · apply msU h funext i apply extend_eq _ (h i) · cases' not_forall.1 h with i hi exact le_trans (le_iInf fun h => hi.elim h) (ENNReal.le_tsum i) #align measure_theory.extend_Union_le_tsum_nat' MeasureTheory.extend_iUnion_le_tsum_nat' end Subadditive section Mono theorem extend_mono' ⦃s₁ s₂ : Set α⦄ (h₁ : P s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := by refine le_iInf ?_ intro h₂ rw [extend_eq m h₁] exact m_mono h₁ h₂ hs #align measure_theory.extend_mono' MeasureTheory.extend_mono' end Mono section Unions theorem extend_iUnion {β} [Countable β] {f : β → Set α} (hd : Pairwise (Disjoint on f)) (hm : ∀ i, P (f i)) : extend m (⋃ i, f i) = ∑' i, extend m (f i) := by cases nonempty_encodable β rw [← Encodable.iUnion_decode₂, ← tsum_iUnion_decode₂] · exact extend_iUnion_nat PU (fun n => Encodable.iUnion_decode₂_cases P0 hm) (mU _ (Encodable.iUnion_decode₂_disjoint_on hd)) · exact extend_empty P0 m0 #align measure_theory.extend_Union MeasureTheory.extend_iUnion theorem extend_union {s₁ s₂ : Set α} (hd : Disjoint s₁ s₂) (h₁ : P s₁) (h₂ : P s₂) : extend m (s₁ ∪ s₂) = extend m s₁ + extend m s₂ := by rw [union_eq_iUnion, extend_iUnion P0 m0 PU mU (pairwise_disjoint_on_bool.2 hd) (Bool.forall_bool.2 ⟨h₂, h₁⟩), tsum_fintype] simp #align measure_theory.extend_union MeasureTheory.extend_union end Unions variable (m) /-- Given an arbitrary function on a subset of sets, we can define the outer measure corresponding to it (this is the unique maximal outer measure that is at most `m` on the domain of `m`). -/ def inducedOuterMeasure : OuterMeasure α := OuterMeasure.ofFunction (extend m) (extend_empty P0 m0) #align measure_theory.induced_outer_measure MeasureTheory.inducedOuterMeasure variable {m P0 m0} theorem le_inducedOuterMeasure {μ : OuterMeasure α} : μ ≤ inducedOuterMeasure m P0 m0 ↔ ∀ (s) (hs : P s), μ s ≤ m s hs := le_ofFunction.trans <| forall_congr' fun _s => le_iInf_iff #align measure_theory.le_induced_outer_measure MeasureTheory.le_inducedOuterMeasure /-- If `P u` is `False` for any set `u` that has nonempty intersection both with `s` and `t`, then `μ (s ∪ t) = μ s + μ t`, where `μ = inducedOuterMeasure m P0 m0`. E.g., if `α` is an (e)metric space and `P u = diam u < r`, then this lemma implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s` and `y ∈ t`. -/ theorem inducedOuterMeasure_union_of_false_of_nonempty_inter {s t : Set α} (h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → ¬P u) : inducedOuterMeasure m P0 m0 (s ∪ t) = inducedOuterMeasure m P0 m0 s + inducedOuterMeasure m P0 m0 t := ofFunction_union_of_top_of_nonempty_inter fun u hsu htu => @iInf_of_empty _ _ _ ⟨h u hsu htu⟩ _ #align measure_theory.induced_outer_measure_union_of_false_of_nonempty_inter MeasureTheory.inducedOuterMeasure_union_of_false_of_nonempty_inter theorem inducedOuterMeasure_eq_extend' {s : Set α} (hs : P s) : inducedOuterMeasure m P0 m0 s = extend m s := ofFunction_eq s (fun _t => extend_mono' m_mono hs) (extend_iUnion_le_tsum_nat' PU msU) #align measure_theory.induced_outer_measure_eq_extend' MeasureTheory.inducedOuterMeasure_eq_extend' theorem inducedOuterMeasure_eq' {s : Set α} (hs : P s) : inducedOuterMeasure m P0 m0 s = m s hs := (inducedOuterMeasure_eq_extend' PU msU m_mono hs).trans <| extend_eq _ _ #align measure_theory.induced_outer_measure_eq' MeasureTheory.inducedOuterMeasure_eq' theorem inducedOuterMeasure_eq_iInf (s : Set α) : inducedOuterMeasure m P0 m0 s = ⨅ (t : Set α) (ht : P t) (_ : s ⊆ t), m t ht := by apply le_antisymm · simp only [le_iInf_iff] intro t ht hs refine le_trans (measure_mono hs) ?_ exact le_of_eq (inducedOuterMeasure_eq' _ msU m_mono _) · refine le_iInf ?_ intro f refine le_iInf ?_ intro hf refine le_trans ?_ (extend_iUnion_le_tsum_nat' _ msU _) refine le_iInf ?_ intro h2f exact iInf_le_of_le _ (iInf_le_of_le h2f <| iInf_le _ hf) #align measure_theory.induced_outer_measure_eq_infi MeasureTheory.inducedOuterMeasure_eq_iInf theorem inducedOuterMeasure_preimage (f : α ≃ α) (Pm : ∀ s : Set α, P (f ⁻¹' s) ↔ P s) (mm : ∀ (s : Set α) (hs : P s), m (f ⁻¹' s) ((Pm _).mpr hs) = m s hs) {A : Set α} : inducedOuterMeasure m P0 m0 (f ⁻¹' A) = inducedOuterMeasure m P0 m0 A := by rw [inducedOuterMeasure_eq_iInf _ msU m_mono, inducedOuterMeasure_eq_iInf _ msU m_mono]; symm refine f.injective.preimage_surjective.iInf_congr (preimage f) fun s => ?_ refine iInf_congr_Prop (Pm s) ?_; intro hs refine iInf_congr_Prop f.surjective.preimage_subset_preimage_iff ?_ intro _; exact mm s hs #align measure_theory.induced_outer_measure_preimage MeasureTheory.inducedOuterMeasure_preimage theorem inducedOuterMeasure_exists_set {s : Set α} (hs : inducedOuterMeasure m P0 m0 s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ t : Set α, P t ∧ s ⊆ t ∧ inducedOuterMeasure m P0 m0 t ≤ inducedOuterMeasure m P0 m0 s + ε := by have h := ENNReal.lt_add_right hs hε conv at h => lhs rw [inducedOuterMeasure_eq_iInf _ msU m_mono] simp only [iInf_lt_iff] at h rcases h with ⟨t, h1t, h2t, h3t⟩ exact ⟨t, h1t, h2t, le_trans (le_of_eq <| inducedOuterMeasure_eq' _ msU m_mono h1t) (le_of_lt h3t)⟩ #align measure_theory.induced_outer_measure_exists_set MeasureTheory.inducedOuterMeasure_exists_set /-- To test whether `s` is Carathéodory-measurable we only need to check the sets `t` for which `P t` holds. See `ofFunction_caratheodory` for another way to show the Carathéodory-measurability of `s`. -/ theorem inducedOuterMeasure_caratheodory (s : Set α) : MeasurableSet[(inducedOuterMeasure m P0 m0).caratheodory] s ↔ ∀ t : Set α, P t → inducedOuterMeasure m P0 m0 (t ∩ s) + inducedOuterMeasure m P0 m0 (t \ s) ≤ inducedOuterMeasure m P0 m0 t := by rw [isCaratheodory_iff_le] constructor · intro h t _ht exact h t · intro h u conv_rhs => rw [inducedOuterMeasure_eq_iInf _ msU m_mono] refine le_iInf ?_ intro t refine le_iInf ?_ intro ht refine le_iInf ?_ intro h2t refine le_trans ?_ ((h t ht).trans_eq <| inducedOuterMeasure_eq' _ msU m_mono ht) gcongr #align measure_theory.induced_outer_measure_caratheodory MeasureTheory.inducedOuterMeasure_caratheodory end ExtendSet /-! If `P` is `MeasurableSet` for some measurable space, then we can remove some hypotheses of the above lemmas. -/ section MeasurableSpace variable {α : Type*} [MeasurableSpace α] variable {m : ∀ s : Set α, MeasurableSet s → ℝ≥0∞} variable (m0 : m ∅ MeasurableSet.empty = 0) variable (mU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, MeasurableSet (f i)), Pairwise (Disjoint on f) → m (⋃ i, f i) (MeasurableSet.iUnion hm) = ∑' i, m (f i) (hm i)) theorem extend_mono {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := by refine le_iInf ?_; intro h₂ have := extend_union MeasurableSet.empty m0 MeasurableSet.iUnion mU disjoint_sdiff_self_right h₁ (h₂.diff h₁) rw [union_diff_cancel hs] at this rw [← extend_eq m] exact le_iff_exists_add.2 ⟨_, this⟩ #align measure_theory.extend_mono MeasureTheory.extend_mono theorem extend_iUnion_le_tsum_nat : ∀ s : ℕ → Set α, extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by refine extend_iUnion_le_tsum_nat' MeasurableSet.iUnion ?_; intro f h simp (config := { singlePass := true }) only [iUnion_disjointed.symm] rw [mU (MeasurableSet.disjointed h) (disjoint_disjointed _)] refine ENNReal.tsum_le_tsum fun i => ?_ rw [← extend_eq m, ← extend_eq m] exact extend_mono m0 mU (MeasurableSet.disjointed h _) (disjointed_le f _) #align measure_theory.extend_Union_le_tsum_nat MeasureTheory.extend_iUnion_le_tsum_nat theorem inducedOuterMeasure_eq_extend {s : Set α} (hs : MeasurableSet s) : inducedOuterMeasure m MeasurableSet.empty m0 s = extend m s := ofFunction_eq s (fun _t => extend_mono m0 mU hs) (extend_iUnion_le_tsum_nat m0 mU) #align measure_theory.induced_outer_measure_eq_extend MeasureTheory.inducedOuterMeasure_eq_extend theorem inducedOuterMeasure_eq {s : Set α} (hs : MeasurableSet s) : inducedOuterMeasure m MeasurableSet.empty m0 s = m s hs := (inducedOuterMeasure_eq_extend m0 mU hs).trans <| extend_eq _ _ #align measure_theory.induced_outer_measure_eq MeasureTheory.inducedOuterMeasure_eq end MeasurableSpace namespace OuterMeasure variable {α : Type*} [MeasurableSpace α] (m : OuterMeasure α) /-- Given an outer measure `m` we can forget its value on non-measurable sets, and then consider `m.trim`, the unique maximal outer measure less than that function. -/ def trim : OuterMeasure α := inducedOuterMeasure (fun s _ => m s) MeasurableSet.empty m.empty #align measure_theory.outer_measure.trim MeasureTheory.OuterMeasure.trim theorem le_trim_iff {m₁ m₂ : OuterMeasure α} : m₁ ≤ m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s ≤ m₂ s := le_inducedOuterMeasure #align measure_theory.outer_measure.le_trim_iff MeasureTheory.OuterMeasure.le_trim_iff theorem le_trim : m ≤ m.trim := le_trim_iff.2 fun _ _ ↦ le_rfl #align measure_theory.outer_measure.le_trim MeasureTheory.OuterMeasure.le_trim @[simp] -- Porting note: added `simp` theorem trim_eq {s : Set α} (hs : MeasurableSet s) : m.trim s = m s := inducedOuterMeasure_eq' MeasurableSet.iUnion (fun f _hf => measure_iUnion_le f) (fun _ _ _ _ h => measure_mono h) hs #align measure_theory.outer_measure.trim_eq MeasureTheory.OuterMeasure.trim_eq theorem trim_congr {m₁ m₂ : OuterMeasure α} (H : ∀ {s : Set α}, MeasurableSet s → m₁ s = m₂ s) : m₁.trim = m₂.trim := by simp (config := { contextual := true }) only [trim, H] #align measure_theory.outer_measure.trim_congr MeasureTheory.OuterMeasure.trim_congr @[mono] theorem trim_mono : Monotone (trim : OuterMeasure α → OuterMeasure α) := fun _m₁ _m₂ H _s => iInf₂_mono fun _f _hs => ENNReal.tsum_le_tsum fun _b => iInf_mono fun _hf => H _ #align measure_theory.outer_measure.trim_mono MeasureTheory.OuterMeasure.trim_mono /-- `OuterMeasure.trim` is antitone in the σ-algebra. -/
Mathlib/MeasureTheory/OuterMeasure/Induced.lean
347
351
theorem trim_anti_measurableSpace (m : OuterMeasure α) {m0 m1 : MeasurableSpace α} (h : m0 ≤ m1) : @trim _ m1 m ≤ @trim _ m0 m := by
simp only [le_trim_iff] intro s hs rw [trim_eq _ (h s hs)]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Tactic.FinCases import Mathlib.Tactic.LinearCombination import Mathlib.Lean.Expr.ExtraRecognizers import Mathlib.Data.Set.Subsingleton #align_import linear_algebra.linear_independent from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Linear independence This file defines linear independence in a module or vector space. It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light. We define `LinearIndependent R v` as `ker (Finsupp.total ι M R v) = ⊥`. Here `Finsupp.total` is the linear map sending a function `f : ι →₀ R` with finite support to the linear combination of vectors from `v` with these coefficients. Then we prove that several other statements are equivalent to this one, including injectivity of `Finsupp.total ι M R v` and some versions with explicitly written linear combinations. ## Main definitions All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or vector space and `ι : Type*` is an arbitrary indexing type. * `LinearIndependent R v` states that the elements of the family `v` are linearly independent. * `LinearIndependent.repr hv x` returns the linear combination representing `x : span R (range v)` on the linearly independent vectors `v`, given `hv : LinearIndependent R v` (using classical choice). `LinearIndependent.repr hv` is provided as a linear map. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `Fintype.linearIndependent_iff`: if `ι` is a finite type, then any function `f : ι → R` has finite support, so we can reformulate the statement using `∑ i : ι, f i • v i` instead of a sum over an auxiliary `s : Finset ι`; * `linearIndependent_empty_type`: a family indexed by an empty type is linearly independent; * `linearIndependent_unique_iff`: if `ι` is a singleton, then `LinearIndependent K v` is equivalent to `v default ≠ 0`; * `linearIndependent_option`, `linearIndependent_sum`, `linearIndependent_fin_cons`, `linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector fields; * `linearIndependent_insert`, `linearIndependent_union`, `linearIndependent_pair`, `linearIndependent_singleton`: linear independence tests for set operations. In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. We also prove that, when working over a division ring, any family of vectors includes a linear independent subfamily spanning the same subspace. ## Implementation notes We use families instead of sets because it allows us to say that two identical vectors are linearly dependent. If you want to use sets, use the family `(fun x ↦ x : s → M)` given a set `s : Set M`. The lemmas `LinearIndependent.to_subtype_range` and `LinearIndependent.of_subtype_range` connect those two worlds. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ noncomputable section open Function Set Submodule open Cardinal universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*} section Module variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} variable (R) (v) /-- `LinearIndependent R v` states the family of vectors `v` is linearly independent over `R`. -/ def LinearIndependent : Prop := LinearMap.ker (Finsupp.total ι M R v) = ⊥ #align linear_independent LinearIndependent open Lean PrettyPrinter.Delaborator SubExpr in /-- Delaborator for `LinearIndependent` that suggests pretty printing with type hints in case the family of vectors is over a `Set`. Type hints look like `LinearIndependent fun (v : ↑s) => ↑v` or `LinearIndependent (ι := ↑s) f`, depending on whether the family is a lambda expression or not. -/ @[delab app.LinearIndependent] def delabLinearIndependent : Delab := whenPPOption getPPNotation <| whenNotPPOption getPPAnalysisSkip <| withOptionAtCurrPos `pp.analysis.skip true do let e ← getExpr guard <| e.isAppOfArity ``LinearIndependent 7 let some _ := (e.getArg! 0).coeTypeSet? | failure let optionsPerPos ← if (e.getArg! 3).isLambda then withNaryArg 3 do return (← read).optionsPerPos.setBool (← getPos) pp.funBinderTypes.name true else withNaryArg 0 do return (← read).optionsPerPos.setBool (← getPos) `pp.analysis.namedArg true withTheReader Context ({· with optionsPerPos}) delab variable {R} {v} theorem linearIndependent_iff : LinearIndependent R v ↔ ∀ l, Finsupp.total ι M R v l = 0 → l = 0 := by simp [LinearIndependent, LinearMap.ker_eq_bot'] #align linear_independent_iff linearIndependent_iff theorem linearIndependent_iff' : LinearIndependent R v ↔ ∀ s : Finset ι, ∀ g : ι → R, ∑ i ∈ s, g i • v i = 0 → ∀ i ∈ s, g i = 0 := linearIndependent_iff.trans ⟨fun hf s g hg i his => have h := hf (∑ i ∈ s, Finsupp.single i (g i)) <| by simpa only [map_sum, Finsupp.total_single] using hg calc g i = (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single i (g i)) := by { rw [Finsupp.lapply_apply, Finsupp.single_eq_same] } _ = ∑ j ∈ s, (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single j (g j)) := Eq.symm <| Finset.sum_eq_single i (fun j _hjs hji => by rw [Finsupp.lapply_apply, Finsupp.single_eq_of_ne hji]) fun hnis => hnis.elim his _ = (∑ j ∈ s, Finsupp.single j (g j)) i := (map_sum ..).symm _ = 0 := DFunLike.ext_iff.1 h i, fun hf l hl => Finsupp.ext fun i => _root_.by_contradiction fun hni => hni <| hf _ _ hl _ <| Finsupp.mem_support_iff.2 hni⟩ #align linear_independent_iff' linearIndependent_iff' theorem linearIndependent_iff'' : LinearIndependent R v ↔ ∀ (s : Finset ι) (g : ι → R), (∀ i ∉ s, g i = 0) → ∑ i ∈ s, g i • v i = 0 → ∀ i, g i = 0 := by classical exact linearIndependent_iff'.trans ⟨fun H s g hg hv i => if his : i ∈ s then H s g hv i his else hg i his, fun H s g hg i hi => by convert H s (fun j => if j ∈ s then g j else 0) (fun j hj => if_neg hj) (by simp_rw [ite_smul, zero_smul, Finset.sum_extend_by_zero, hg]) i exact (if_pos hi).symm⟩ #align linear_independent_iff'' linearIndependent_iff'' theorem not_linearIndependent_iff : ¬LinearIndependent R v ↔ ∃ s : Finset ι, ∃ g : ι → R, ∑ i ∈ s, g i • v i = 0 ∧ ∃ i ∈ s, g i ≠ 0 := by rw [linearIndependent_iff'] simp only [exists_prop, not_forall] #align not_linear_independent_iff not_linearIndependent_iff theorem Fintype.linearIndependent_iff [Fintype ι] : LinearIndependent R v ↔ ∀ g : ι → R, ∑ i, g i • v i = 0 → ∀ i, g i = 0 := by refine ⟨fun H g => by simpa using linearIndependent_iff'.1 H Finset.univ g, fun H => linearIndependent_iff''.2 fun s g hg hs i => H _ ?_ _⟩ rw [← hs] refine (Finset.sum_subset (Finset.subset_univ _) fun i _ hi => ?_).symm rw [hg i hi, zero_smul] #align fintype.linear_independent_iff Fintype.linearIndependent_iff /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` has the trivial kernel. -/ theorem Fintype.linearIndependent_iff' [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ LinearMap.ker (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) = ⊥ := by simp [Fintype.linearIndependent_iff, LinearMap.ker_eq_bot', funext_iff] #align fintype.linear_independent_iff' Fintype.linearIndependent_iff' theorem Fintype.not_linearIndependent_iff [Fintype ι] : ¬LinearIndependent R v ↔ ∃ g : ι → R, ∑ i, g i • v i = 0 ∧ ∃ i, g i ≠ 0 := by simpa using not_iff_not.2 Fintype.linearIndependent_iff #align fintype.not_linear_independent_iff Fintype.not_linearIndependent_iff theorem linearIndependent_empty_type [IsEmpty ι] : LinearIndependent R v := linearIndependent_iff.mpr fun v _hv => Subsingleton.elim v 0 #align linear_independent_empty_type linearIndependent_empty_type theorem LinearIndependent.ne_zero [Nontrivial R] (i : ι) (hv : LinearIndependent R v) : v i ≠ 0 := fun h => zero_ne_one' R <| Eq.symm (by suffices (Finsupp.single i 1 : ι →₀ R) i = 0 by simpa rw [linearIndependent_iff.1 hv (Finsupp.single i 1)] · simp · simp [h]) #align linear_independent.ne_zero LinearIndependent.ne_zero lemma LinearIndependent.eq_zero_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x + t • y = 0) : s = 0 ∧ t = 0 := by have := linearIndependent_iff'.1 h Finset.univ ![s, t] simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, h', Finset.mem_univ, forall_true_left] at this exact ⟨this 0, this 1⟩ /-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/ lemma LinearIndependent.pair_iff {x y : M} : LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by refine ⟨fun h s t hst ↦ h.eq_zero_of_pair hst, fun h ↦ ?_⟩ apply Fintype.linearIndependent_iff.2 intro g hg simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons] at hg intro i fin_cases i exacts [(h _ _ hg).1, (h _ _ hg).2] /-- A subfamily of a linearly independent family (i.e., a composition with an injective map) is a linearly independent family. -/ theorem LinearIndependent.comp (h : LinearIndependent R v) (f : ι' → ι) (hf : Injective f) : LinearIndependent R (v ∘ f) := by rw [linearIndependent_iff, Finsupp.total_comp] intro l hl have h_map_domain : ∀ x, (Finsupp.mapDomain f l) (f x) = 0 := by rw [linearIndependent_iff.1 h (Finsupp.mapDomain f l) hl]; simp ext x convert h_map_domain x rw [Finsupp.mapDomain_apply hf] #align linear_independent.comp LinearIndependent.comp /-- A family is linearly independent if and only if all of its finite subfamily is linearly independent. -/ theorem linearIndependent_iff_finset_linearIndependent : LinearIndependent R v ↔ ∀ (s : Finset ι), LinearIndependent R (v ∘ (Subtype.val : s → ι)) := ⟨fun H _ ↦ H.comp _ Subtype.val_injective, fun H ↦ linearIndependent_iff'.2 fun s g hg i hi ↦ Fintype.linearIndependent_iff.1 (H s) (g ∘ Subtype.val) (hg ▸ Finset.sum_attach s fun j ↦ g j • v j) ⟨i, hi⟩⟩ theorem LinearIndependent.coe_range (i : LinearIndependent R v) : LinearIndependent R ((↑) : range v → M) := by simpa using i.comp _ (rangeSplitting_injective v) #align linear_independent.coe_range LinearIndependent.coe_range /-- If `v` is a linearly independent family of vectors and the kernel of a linear map `f` is disjoint with the submodule spanned by the vectors of `v`, then `f ∘ v` is a linearly independent family of vectors. See also `LinearIndependent.map'` for a special case assuming `ker f = ⊥`. -/ theorem LinearIndependent.map (hv : LinearIndependent R v) {f : M →ₗ[R] M'} (hf_inj : Disjoint (span R (range v)) (LinearMap.ker f)) : LinearIndependent R (f ∘ v) := by rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, map_le_iff_le_comap, comap_bot, Finsupp.supported_univ, top_inf_eq] at hf_inj unfold LinearIndependent at hv ⊢ rw [hv, le_bot_iff] at hf_inj haveI : Inhabited M := ⟨0⟩ rw [Finsupp.total_comp, Finsupp.lmapDomain_total _ _ f, LinearMap.ker_comp, hf_inj] exact fun _ => rfl #align linear_independent.map LinearIndependent.map /-- If `v` is an injective family of vectors such that `f ∘ v` is linearly independent, then `v` spans a submodule disjoint from the kernel of `f` -/ theorem Submodule.range_ker_disjoint {f : M →ₗ[R] M'} (hv : LinearIndependent R (f ∘ v)) : Disjoint (span R (range v)) (LinearMap.ker f) := by rw [LinearIndependent, Finsupp.total_comp, Finsupp.lmapDomain_total R _ f (fun _ ↦ rfl), LinearMap.ker_comp] at hv rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, hv, inf_bot_eq, map_bot] /-- An injective linear map sends linearly independent families of vectors to linearly independent families of vectors. See also `LinearIndependent.map` for a more general statement. -/ theorem LinearIndependent.map' (hv : LinearIndependent R v) (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) := hv.map <| by simp [hf_inj] #align linear_independent.map' LinearIndependent.map' /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map, `j : M →+ M'` is a monoid map, such that they send non-zero elements to non-zero elements, and compatible with the scalar multiplications on `M` and `M'`, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_injective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : LinearIndependent R' (j ∘ v) := by rw [linearIndependent_iff'] at hv ⊢ intro S r' H s hs simp_rw [comp_apply, ← hc, ← map_sum] at H exact hi _ <| hv _ _ (hj _ H) s hs /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero, `j : M →+ M'` is a monoid map which sends non-zero elements to non-zero elements, such that the scalar multiplications on `M` and `M'` are compatible, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_surjective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : ZeroHom R R') (j : M →+ M') (hi : Surjective i) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : LinearIndependent R' (j ∘ v) := by obtain ⟨i', hi'⟩ := hi.hasRightInverse refine hv.map_of_injective_injective i' j (fun _ h ↦ ?_) hj fun r m ↦ ?_ · apply_fun i at h rwa [hi', i.map_zero] at h rw [hc (i' r) m, hi'] /-- If the image of a family of vectors under a linear map is linearly independent, then so is the original family. -/ theorem LinearIndependent.of_comp (f : M →ₗ[R] M') (hfv : LinearIndependent R (f ∘ v)) : LinearIndependent R v := linearIndependent_iff'.2 fun s g hg i his => have : (∑ i ∈ s, g i • f (v i)) = 0 := by simp_rw [← map_smul, ← map_sum, hg, f.map_zero] linearIndependent_iff'.1 hfv s g this i his #align linear_independent.of_comp LinearIndependent.of_comp /-- If `f` is an injective linear map, then the family `f ∘ v` is linearly independent if and only if the family `v` is linearly independent. -/ protected theorem LinearMap.linearIndependent_iff (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) ↔ LinearIndependent R v := ⟨fun h => h.of_comp f, fun h => h.map <| by simp only [hf_inj, disjoint_bot_right]⟩ #align linear_map.linear_independent_iff LinearMap.linearIndependent_iff @[nontriviality] theorem linearIndependent_of_subsingleton [Subsingleton R] : LinearIndependent R v := linearIndependent_iff.2 fun _l _hl => Subsingleton.elim _ _ #align linear_independent_of_subsingleton linearIndependent_of_subsingleton theorem linearIndependent_equiv (e : ι ≃ ι') {f : ι' → M} : LinearIndependent R (f ∘ e) ↔ LinearIndependent R f := ⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h => h.comp _ e.injective⟩ #align linear_independent_equiv linearIndependent_equiv theorem linearIndependent_equiv' (e : ι ≃ ι') {f : ι' → M} {g : ι → M} (h : f ∘ e = g) : LinearIndependent R g ↔ LinearIndependent R f := h ▸ linearIndependent_equiv e #align linear_independent_equiv' linearIndependent_equiv' theorem linearIndependent_subtype_range {ι} {f : ι → M} (hf : Injective f) : LinearIndependent R ((↑) : range f → M) ↔ LinearIndependent R f := Iff.symm <| linearIndependent_equiv' (Equiv.ofInjective f hf) rfl #align linear_independent_subtype_range linearIndependent_subtype_range alias ⟨LinearIndependent.of_subtype_range, _⟩ := linearIndependent_subtype_range #align linear_independent.of_subtype_range LinearIndependent.of_subtype_range theorem linearIndependent_image {ι} {s : Set ι} {f : ι → M} (hf : Set.InjOn f s) : (LinearIndependent R fun x : s => f x) ↔ LinearIndependent R fun x : f '' s => (x : M) := linearIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl #align linear_independent_image linearIndependent_image theorem linearIndependent_span (hs : LinearIndependent R v) : LinearIndependent R (M := span R (range v)) (fun i : ι => ⟨v i, subset_span (mem_range_self i)⟩) := LinearIndependent.of_comp (span R (range v)).subtype hs #align linear_independent_span linearIndependent_span /-- See `LinearIndependent.fin_cons` for a family of elements in a vector space. -/ theorem LinearIndependent.fin_cons' {m : ℕ} (x : M) (v : Fin m → M) (hli : LinearIndependent R v) (x_ortho : ∀ (c : R) (y : Submodule.span R (Set.range v)), c • x + y = (0 : M) → c = 0) : LinearIndependent R (Fin.cons x v : Fin m.succ → M) := by rw [Fintype.linearIndependent_iff] at hli ⊢ rintro g total_eq j simp_rw [Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ] at total_eq have : g 0 = 0 := by refine x_ortho (g 0) ⟨∑ i : Fin m, g i.succ • v i, ?_⟩ total_eq exact sum_mem fun i _ => smul_mem _ _ (subset_span ⟨i, rfl⟩) rw [this, zero_smul, zero_add] at total_eq exact Fin.cases this (hli _ total_eq) j #align linear_independent.fin_cons' LinearIndependent.fin_cons' /-- A set of linearly independent vectors in a module `M` over a semiring `K` is also linearly independent over a subring `R` of `K`. The implementation uses minimal assumptions about the relationship between `R`, `K` and `M`. The version where `K` is an `R`-algebra is `LinearIndependent.restrict_scalars_algebras`. -/ theorem LinearIndependent.restrict_scalars [Semiring K] [SMulWithZero R K] [Module K M] [IsScalarTower R K M] (hinj : Function.Injective fun r : R => r • (1 : K)) (li : LinearIndependent K v) : LinearIndependent R v := by refine linearIndependent_iff'.mpr fun s g hg i hi => hinj ?_ dsimp only; rw [zero_smul] refine (linearIndependent_iff'.mp li : _) _ (g · • (1:K)) ?_ i hi simp_rw [smul_assoc, one_smul] exact hg #align linear_independent.restrict_scalars LinearIndependent.restrict_scalars /-- Every finite subset of a linearly independent set is linearly independent. -/ theorem linearIndependent_finset_map_embedding_subtype (s : Set M) (li : LinearIndependent R ((↑) : s → M)) (t : Finset s) : LinearIndependent R ((↑) : Finset.map (Embedding.subtype s) t → M) := by let f : t.map (Embedding.subtype s) → s := fun x => ⟨x.1, by obtain ⟨x, h⟩ := x rw [Finset.mem_map] at h obtain ⟨a, _ha, rfl⟩ := h simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩ convert LinearIndependent.comp li f ?_ rintro ⟨x, hx⟩ ⟨y, hy⟩ rw [Finset.mem_map] at hx hy obtain ⟨a, _ha, rfl⟩ := hx obtain ⟨b, _hb, rfl⟩ := hy simp only [f, imp_self, Subtype.mk_eq_mk] #align linear_independent_finset_map_embedding_subtype linearIndependent_finset_map_embedding_subtype /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : ∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li #align linear_independent_bounded_of_finset_linear_independent_bounded linearIndependent_bounded_of_finset_linearIndependent_bounded section Subtype /-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/ theorem linearIndependent_comp_subtype {s : Set ι} : LinearIndependent R (v ∘ (↑) : s → M) ↔ ∀ l ∈ Finsupp.supported R R s, (Finsupp.total ι M R v) l = 0 → l = 0 := by simp only [linearIndependent_iff, (· ∘ ·), Finsupp.mem_supported, Finsupp.total_apply, Set.subset_def, Finset.mem_coe] constructor · intro h l hl₁ hl₂ have := h (l.subtypeDomain s) ((Finsupp.sum_subtypeDomain_index hl₁).trans hl₂) exact (Finsupp.subtypeDomain_eq_zero_iff hl₁).1 this · intro h l hl refine Finsupp.embDomain_eq_zero.1 (h (l.embDomain <| Function.Embedding.subtype s) ?_ ?_) · suffices ∀ i hi, ¬l ⟨i, hi⟩ = 0 → i ∈ s by simpa intros assumption · rwa [Finsupp.embDomain_eq_mapDomain, Finsupp.sum_mapDomain_index] exacts [fun _ => zero_smul _ _, fun _ _ _ => add_smul _ _ _] #align linear_independent_comp_subtype linearIndependent_comp_subtype theorem linearDependent_comp_subtype' {s : Set ι} : ¬LinearIndependent R (v ∘ (↑) : s → M) ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ Finsupp.total ι M R v f = 0 ∧ f ≠ 0 := by simp [linearIndependent_comp_subtype, and_left_comm] #align linear_dependent_comp_subtype' linearDependent_comp_subtype' /-- A version of `linearDependent_comp_subtype'` with `Finsupp.total` unfolded. -/ theorem linearDependent_comp_subtype {s : Set ι} : ¬LinearIndependent R (v ∘ (↑) : s → M) ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ ∑ i ∈ f.support, f i • v i = 0 ∧ f ≠ 0 := linearDependent_comp_subtype' #align linear_dependent_comp_subtype linearDependent_comp_subtype theorem linearIndependent_subtype {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ ∀ l ∈ Finsupp.supported R R s, (Finsupp.total M M R id) l = 0 → l = 0 := by apply linearIndependent_comp_subtype (v := id) #align linear_independent_subtype linearIndependent_subtype theorem linearIndependent_comp_subtype_disjoint {s : Set ι} : LinearIndependent R (v ∘ (↑) : s → M) ↔ Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total ι M R v) := by rw [linearIndependent_comp_subtype, LinearMap.disjoint_ker] #align linear_independent_comp_subtype_disjoint linearIndependent_comp_subtype_disjoint theorem linearIndependent_subtype_disjoint {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total M M R id) := by apply linearIndependent_comp_subtype_disjoint (v := id) #align linear_independent_subtype_disjoint linearIndependent_subtype_disjoint theorem linearIndependent_iff_totalOn {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ (LinearMap.ker <| Finsupp.totalOn M M R id s) = ⊥ := by rw [Finsupp.totalOn, LinearMap.ker, LinearMap.comap_codRestrict, Submodule.map_bot, comap_bot, LinearMap.ker_comp, linearIndependent_subtype_disjoint, disjoint_iff_inf_le, ← map_comap_subtype, map_le_iff_le_comap, comap_bot, ker_subtype, le_bot_iff] #align linear_independent_iff_total_on linearIndependent_iff_totalOn theorem LinearIndependent.restrict_of_comp_subtype {s : Set ι} (hs : LinearIndependent R (v ∘ (↑) : s → M)) : LinearIndependent R (s.restrict v) := hs #align linear_independent.restrict_of_comp_subtype LinearIndependent.restrict_of_comp_subtype variable (R M) theorem linearIndependent_empty : LinearIndependent R (fun x => x : (∅ : Set M) → M) := by simp [linearIndependent_subtype_disjoint] #align linear_independent_empty linearIndependent_empty variable {R M} theorem LinearIndependent.mono {t s : Set M} (h : t ⊆ s) : LinearIndependent R (fun x => x : s → M) → LinearIndependent R (fun x => x : t → M) := by simp only [linearIndependent_subtype_disjoint] exact Disjoint.mono_left (Finsupp.supported_mono h) #align linear_independent.mono LinearIndependent.mono theorem linearIndependent_of_finite (s : Set M) (H : ∀ t ⊆ s, Set.Finite t → LinearIndependent R (fun x => x : t → M)) : LinearIndependent R (fun x => x : s → M) := linearIndependent_subtype.2 fun l hl => linearIndependent_subtype.1 (H _ hl (Finset.finite_toSet _)) l (Subset.refl _) #align linear_independent_of_finite linearIndependent_of_finite theorem linearIndependent_iUnion_of_directed {η : Type*} {s : η → Set M} (hs : Directed (· ⊆ ·) s) (h : ∀ i, LinearIndependent R (fun x => x : s i → M)) : LinearIndependent R (fun x => x : (⋃ i, s i) → M) := by by_cases hη : Nonempty η · refine linearIndependent_of_finite (⋃ i, s i) fun t ht ft => ?_ rcases finite_subset_iUnion ft ht with ⟨I, fi, hI⟩ rcases hs.finset_le fi.toFinset with ⟨i, hi⟩ exact (h i).mono (Subset.trans hI <| iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) · refine (linearIndependent_empty R M).mono (t := iUnion (s ·)) ?_ rintro _ ⟨_, ⟨i, _⟩, _⟩ exact hη ⟨i⟩ #align linear_independent_Union_of_directed linearIndependent_iUnion_of_directed theorem linearIndependent_sUnion_of_directed {s : Set (Set M)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, LinearIndependent R ((↑) : ((a : Set M) : Type _) → M)) : LinearIndependent R (fun x => x : ⋃₀ s → M) := by rw [sUnion_eq_iUnion]; exact linearIndependent_iUnion_of_directed hs.directed_val (by simpa using h) #align linear_independent_sUnion_of_directed linearIndependent_sUnion_of_directed theorem linearIndependent_biUnion_of_directed {η} {s : Set η} {t : η → Set M} (hs : DirectedOn (t ⁻¹'o (· ⊆ ·)) s) (h : ∀ a ∈ s, LinearIndependent R (fun x => x : t a → M)) : LinearIndependent R (fun x => x : (⋃ a ∈ s, t a) → M) := by rw [biUnion_eq_iUnion] exact linearIndependent_iUnion_of_directed (directed_comp.2 <| hs.directed_val) (by simpa using h) #align linear_independent_bUnion_of_directed linearIndependent_biUnion_of_directed end Subtype end Module /-! ### Properties which require `Ring R` -/ section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} theorem linearIndependent_iff_injective_total : LinearIndependent R v ↔ Function.Injective (Finsupp.total ι M R v) := linearIndependent_iff.trans (injective_iff_map_eq_zero (Finsupp.total ι M R v).toAddMonoidHom).symm #align linear_independent_iff_injective_total linearIndependent_iff_injective_total alias ⟨LinearIndependent.injective_total, _⟩ := linearIndependent_iff_injective_total #align linear_independent.injective_total LinearIndependent.injective_total theorem LinearIndependent.injective [Nontrivial R] (hv : LinearIndependent R v) : Injective v := by intro i j hij let l : ι →₀ R := Finsupp.single i (1 : R) - Finsupp.single j 1 have h_total : Finsupp.total ι M R v l = 0 := by simp_rw [l, LinearMap.map_sub, Finsupp.total_apply] simp [hij] have h_single_eq : Finsupp.single i (1 : R) = Finsupp.single j 1 := by rw [linearIndependent_iff] at hv simp [eq_add_of_sub_eq' (hv l h_total)] simpa [Finsupp.single_eq_single_iff] using h_single_eq #align linear_independent.injective LinearIndependent.injective theorem LinearIndependent.to_subtype_range {ι} {f : ι → M} (hf : LinearIndependent R f) : LinearIndependent R ((↑) : range f → M) := by nontriviality R exact (linearIndependent_subtype_range hf.injective).2 hf #align linear_independent.to_subtype_range LinearIndependent.to_subtype_range theorem LinearIndependent.to_subtype_range' {ι} {f : ι → M} (hf : LinearIndependent R f) {t} (ht : range f = t) : LinearIndependent R ((↑) : t → M) := ht ▸ hf.to_subtype_range #align linear_independent.to_subtype_range' LinearIndependent.to_subtype_range' theorem LinearIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → M) (hs : LinearIndependent R fun x : s => g (f x)) : LinearIndependent R fun x : f '' s => g x := by nontriviality R have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp exact (linearIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs #align linear_independent.image_of_comp LinearIndependent.image_of_comp theorem LinearIndependent.image {ι} {s : Set ι} {f : ι → M} (hs : LinearIndependent R fun x : s => f x) : LinearIndependent R fun x : f '' s => (x : M) := by convert LinearIndependent.image_of_comp s f id hs #align linear_independent.image LinearIndependent.image theorem LinearIndependent.group_smul {G : Type*} [hG : Group G] [DistribMulAction G R] [DistribMulAction G M] [IsScalarTower G R M] [SMulCommClass G R M] {v : ι → M} (hv : LinearIndependent R v) (w : ι → G) : LinearIndependent R (w • v) := by rw [linearIndependent_iff''] at hv ⊢ intro s g hgs hsum i refine (smul_eq_zero_iff_eq (w i)).1 ?_ refine hv s (fun i => w i • g i) (fun i hi => ?_) ?_ i · dsimp only exact (hgs i hi).symm ▸ smul_zero _ · rw [← hsum, Finset.sum_congr rfl _] intros dsimp rw [smul_assoc, smul_comm] #align linear_independent.group_smul LinearIndependent.group_smul -- This lemma cannot be proved with `LinearIndependent.group_smul` since the action of -- `Rˣ` on `R` is not commutative. theorem LinearIndependent.units_smul {v : ι → M} (hv : LinearIndependent R v) (w : ι → Rˣ) : LinearIndependent R (w • v) := by rw [linearIndependent_iff''] at hv ⊢ intro s g hgs hsum i rw [← (w i).mul_left_eq_zero] refine hv s (fun i => g i • (w i : R)) (fun i hi => ?_) ?_ i · dsimp only exact (hgs i hi).symm ▸ zero_smul _ _ · rw [← hsum, Finset.sum_congr rfl _] intros erw [Pi.smul_apply, smul_assoc] rfl #align linear_independent.units_smul LinearIndependent.units_smul lemma LinearIndependent.eq_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t s' t' : R} (h' : s • x + t • y = s' • x + t' • y) : s = s' ∧ t = t' := by have : (s - s') • x + (t - t') • y = 0 := by rw [← sub_eq_zero_of_eq h', ← sub_eq_zero] simp only [sub_smul] abel simpa [sub_eq_zero] using h.eq_zero_of_pair this lemma LinearIndependent.eq_zero_of_pair' {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x = t • y) : s = 0 ∧ t = 0 := by suffices H : s = 0 ∧ 0 = t from ⟨H.1, H.2.symm⟩ exact h.eq_of_pair (by simpa using h') /-- If two vectors `x` and `y` are linearly independent, so are their linear combinations `a x + b y` and `c x + d y` provided the determinant `a * d - b * c` is nonzero. -/ lemma LinearIndependent.linear_combination_pair_of_det_ne_zero {R M : Type*} [CommRing R] [NoZeroDivisors R] [AddCommGroup M] [Module R M] {x y : M} (h : LinearIndependent R ![x, y]) {a b c d : R} (h' : a * d - b * c ≠ 0) : LinearIndependent R ![a • x + b • y, c • x + d • y] := by apply LinearIndependent.pair_iff.2 (fun s t hst ↦ ?_) have H : (s * a + t * c) • x + (s * b + t * d) • y = 0 := by convert hst using 1 simp only [_root_.add_smul, smul_add, smul_smul] abel have I1 : s * a + t * c = 0 := (h.eq_zero_of_pair H).1 have I2 : s * b + t * d = 0 := (h.eq_zero_of_pair H).2 have J1 : (a * d - b * c) * s = 0 := by linear_combination d * I1 - c * I2 have J2 : (a * d - b * c) * t = 0 := by linear_combination -b * I1 + a * I2 exact ⟨by simpa [h'] using mul_eq_zero.1 J1, by simpa [h'] using mul_eq_zero.1 J2⟩ section Maximal universe v w /-- A linearly independent family is maximal if there is no strictly larger linearly independent family. -/ @[nolint unusedArguments] def LinearIndependent.Maximal {ι : Type w} {R : Type u} [Semiring R] {M : Type v} [AddCommMonoid M] [Module R M] {v : ι → M} (_i : LinearIndependent R v) : Prop := ∀ (s : Set M) (_i' : LinearIndependent R ((↑) : s → M)) (_h : range v ≤ s), range v = s #align linear_independent.maximal LinearIndependent.Maximal /-- An alternative characterization of a maximal linearly independent family, quantifying over types (in the same universe as `M`) into which the indexing family injects. -/ theorem LinearIndependent.maximal_iff {ι : Type w} {R : Type u} [Ring R] [Nontrivial R] {M : Type v} [AddCommGroup M] [Module R M] {v : ι → M} (i : LinearIndependent R v) : i.Maximal ↔ ∀ (κ : Type v) (w : κ → M) (_i' : LinearIndependent R w) (j : ι → κ) (_h : w ∘ j = v), Surjective j := by constructor · rintro p κ w i' j rfl specialize p (range w) i'.coe_range (range_comp_subset_range _ _) rw [range_comp, ← image_univ (f := w)] at p exact range_iff_surjective.mp (image_injective.mpr i'.injective p) · intro p w i' h specialize p w ((↑) : w → M) i' (fun i => ⟨v i, range_subset_iff.mp h i⟩) (by ext simp) have q := congr_arg (fun s => ((↑) : w → M) '' s) p.range_eq dsimp at q rw [← image_univ, image_image] at q simpa using q #align linear_independent.maximal_iff LinearIndependent.maximal_iff end Maximal /-- Linear independent families are injective, even if you multiply either side. -/ theorem LinearIndependent.eq_of_smul_apply_eq_smul_apply {M : Type*} [AddCommGroup M] [Module R M] {v : ι → M} (li : LinearIndependent R v) (c d : R) (i j : ι) (hc : c ≠ 0) (h : c • v i = d • v j) : i = j := by let l : ι →₀ R := Finsupp.single i c - Finsupp.single j d have h_total : Finsupp.total ι M R v l = 0 := by simp_rw [l, LinearMap.map_sub, Finsupp.total_apply] simp [h] have h_single_eq : Finsupp.single i c = Finsupp.single j d := by rw [linearIndependent_iff] at li simp [eq_add_of_sub_eq' (li l h_total)] rcases (Finsupp.single_eq_single_iff ..).mp h_single_eq with (⟨H, _⟩ | ⟨hc, _⟩) · exact H · contradiction #align linear_independent.eq_of_smul_apply_eq_smul_apply LinearIndependent.eq_of_smul_apply_eq_smul_apply section Subtype /-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/ theorem LinearIndependent.disjoint_span_image (hv : LinearIndependent R v) {s t : Set ι} (hs : Disjoint s t) : Disjoint (Submodule.span R <| v '' s) (Submodule.span R <| v '' t) := by simp only [disjoint_def, Finsupp.mem_span_image_iff_total] rintro _ ⟨l₁, hl₁, rfl⟩ ⟨l₂, hl₂, H⟩ rw [hv.injective_total.eq_iff] at H; subst l₂ have : l₁ = 0 := Submodule.disjoint_def.mp (Finsupp.disjoint_supported_supported hs) _ hl₁ hl₂ simp [this] #align linear_independent.disjoint_span_image LinearIndependent.disjoint_span_image theorem LinearIndependent.not_mem_span_image [Nontrivial R] (hv : LinearIndependent R v) {s : Set ι} {x : ι} (h : x ∉ s) : v x ∉ Submodule.span R (v '' s) := by have h' : v x ∈ Submodule.span R (v '' {x}) := by rw [Set.image_singleton] exact mem_span_singleton_self (v x) intro w apply LinearIndependent.ne_zero x hv refine disjoint_def.1 (hv.disjoint_span_image ?_) (v x) h' w simpa using h #align linear_independent.not_mem_span_image LinearIndependent.not_mem_span_image theorem LinearIndependent.total_ne_of_not_mem_support [Nontrivial R] (hv : LinearIndependent R v) {x : ι} (f : ι →₀ R) (h : x ∉ f.support) : Finsupp.total ι M R v f ≠ v x := by replace h : x ∉ (f.support : Set ι) := h have p := hv.not_mem_span_image h intro w rw [← w] at p rw [Finsupp.span_image_eq_map_total] at p simp only [not_exists, not_and, mem_map] at p -- Porting note: `mem_map` isn't currently triggered exact p f (f.mem_supported_support R) rfl #align linear_independent.total_ne_of_not_mem_support LinearIndependent.total_ne_of_not_mem_support theorem linearIndependent_sum {v : Sum ι ι' → M} : LinearIndependent R v ↔ LinearIndependent R (v ∘ Sum.inl) ∧ LinearIndependent R (v ∘ Sum.inr) ∧ Disjoint (Submodule.span R (range (v ∘ Sum.inl))) (Submodule.span R (range (v ∘ Sum.inr))) := by classical rw [range_comp v, range_comp v] refine ⟨?_, ?_⟩ · intro h refine ⟨h.comp _ Sum.inl_injective, h.comp _ Sum.inr_injective, ?_⟩ refine h.disjoint_span_image ?_ -- Porting note: `isCompl_range_inl_range_inr.1` timeouts. exact IsCompl.disjoint isCompl_range_inl_range_inr rintro ⟨hl, hr, hlr⟩ rw [linearIndependent_iff'] at * intro s g hg i hi have : ((∑ i ∈ s.preimage Sum.inl Sum.inl_injective.injOn, (fun x => g x • v x) (Sum.inl i)) + ∑ i ∈ s.preimage Sum.inr Sum.inr_injective.injOn, (fun x => g x • v x) (Sum.inr i)) = 0 := by -- Porting note: `g` must be specified. rw [Finset.sum_preimage' (g := fun x => g x • v x), Finset.sum_preimage' (g := fun x => g x • v x), ← Finset.sum_union, ← Finset.filter_or] · simpa only [← mem_union, range_inl_union_range_inr, mem_univ, Finset.filter_True] · -- Porting note: Here was one `exact`, but timeouted. refine Finset.disjoint_filter.2 fun x _ hx => disjoint_left.1 ?_ hx exact IsCompl.disjoint isCompl_range_inl_range_inr rw [← eq_neg_iff_add_eq_zero] at this rw [disjoint_def'] at hlr have A := by refine hlr _ (sum_mem fun i _ => ?_) _ (neg_mem <| sum_mem fun i _ => ?_) this · exact smul_mem _ _ (subset_span ⟨Sum.inl i, mem_range_self _, rfl⟩) · exact smul_mem _ _ (subset_span ⟨Sum.inr i, mem_range_self _, rfl⟩) cases' i with i i · exact hl _ _ A i (Finset.mem_preimage.2 hi) · rw [this, neg_eq_zero] at A exact hr _ _ A i (Finset.mem_preimage.2 hi) #align linear_independent_sum linearIndependent_sum theorem LinearIndependent.sum_type {v' : ι' → M} (hv : LinearIndependent R v) (hv' : LinearIndependent R v') (h : Disjoint (Submodule.span R (range v)) (Submodule.span R (range v'))) : LinearIndependent R (Sum.elim v v') := linearIndependent_sum.2 ⟨hv, hv', h⟩ #align linear_independent.sum_type LinearIndependent.sum_type theorem LinearIndependent.union {s t : Set M} (hs : LinearIndependent R (fun x => x : s → M)) (ht : LinearIndependent R (fun x => x : t → M)) (hst : Disjoint (span R s) (span R t)) : LinearIndependent R (fun x => x : ↥(s ∪ t) → M) := (hs.sum_type ht <| by simpa).to_subtype_range' <| by simp #align linear_independent.union LinearIndependent.union theorem linearIndependent_iUnion_finite_subtype {ι : Type*} {f : ι → Set M} (hl : ∀ i, LinearIndependent R (fun x => x : f i → M)) (hd : ∀ i, ∀ t : Set ι, t.Finite → i ∉ t → Disjoint (span R (f i)) (⨆ i ∈ t, span R (f i))) : LinearIndependent R (fun x => x : (⋃ i, f i) → M) := by classical rw [iUnion_eq_iUnion_finset f] apply linearIndependent_iUnion_of_directed · apply directed_of_isDirected_le exact fun t₁ t₂ ht => iUnion_mono fun i => iUnion_subset_iUnion_const fun h => ht h intro t induction' t using Finset.induction_on with i s his ih · refine (linearIndependent_empty R M).mono ?_ simp · rw [Finset.set_biUnion_insert] refine (hl _).union ih ?_ rw [span_iUnion₂] exact hd i s s.finite_toSet his #align linear_independent_Union_finite_subtype linearIndependent_iUnion_finite_subtype theorem linearIndependent_iUnion_finite {η : Type*} {ιs : η → Type*} {f : ∀ j : η, ιs j → M} (hindep : ∀ j, LinearIndependent R (f j)) (hd : ∀ i, ∀ t : Set η, t.Finite → i ∉ t → Disjoint (span R (range (f i))) (⨆ i ∈ t, span R (range (f i)))) : LinearIndependent R fun ji : Σ j, ιs j => f ji.1 ji.2 := by nontriviality R apply LinearIndependent.of_subtype_range · rintro ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ hxy by_cases h_cases : x₁ = y₁ · subst h_cases refine Sigma.eq rfl ?_ rw [LinearIndependent.injective (hindep _) hxy] · have h0 : f x₁ x₂ = 0 := by apply disjoint_def.1 (hd x₁ {y₁} (finite_singleton y₁) fun h => h_cases (eq_of_mem_singleton h)) (f x₁ x₂) (subset_span (mem_range_self _)) rw [iSup_singleton] simp only at hxy rw [hxy] exact subset_span (mem_range_self y₂) exact False.elim ((hindep x₁).ne_zero _ h0) rw [range_sigma_eq_iUnion_range] apply linearIndependent_iUnion_finite_subtype (fun j => (hindep j).to_subtype_range) hd #align linear_independent_Union_finite linearIndependent_iUnion_finite end Subtype section repr variable (hv : LinearIndependent R v) /-- Canonical isomorphism between linear combinations and the span of linearly independent vectors. -/ @[simps (config := { rhsMd := default }) symm_apply] def LinearIndependent.totalEquiv (hv : LinearIndependent R v) : (ι →₀ R) ≃ₗ[R] span R (range v) := by apply LinearEquiv.ofBijective (LinearMap.codRestrict (span R (range v)) (Finsupp.total ι M R v) _) constructor · rw [← LinearMap.ker_eq_bot, LinearMap.ker_codRestrict] · apply hv · intro l rw [← Finsupp.range_total] rw [LinearMap.mem_range] apply mem_range_self l · rw [← LinearMap.range_eq_top, LinearMap.range_eq_map, LinearMap.map_codRestrict, ← LinearMap.range_le_iff_comap, range_subtype, Submodule.map_top] rw [Finsupp.range_total] #align linear_independent.total_equiv LinearIndependent.totalEquiv #align linear_independent.total_equiv_symm_apply LinearIndependent.totalEquiv_symm_apply -- Porting note: The original theorem generated by `simps` was -- different from the theorem on Lean 3, and not simp-normal form. @[simp] theorem LinearIndependent.totalEquiv_apply_coe (hv : LinearIndependent R v) (l : ι →₀ R) : hv.totalEquiv l = Finsupp.total ι M R v l := rfl #align linear_independent.total_equiv_apply_coe LinearIndependent.totalEquiv_apply_coe /-- Linear combination representing a vector in the span of linearly independent vectors. Given a family of linearly independent vectors, we can represent any vector in their span as a linear combination of these vectors. These are provided by this linear map. It is simply one direction of `LinearIndependent.total_equiv`. -/ def LinearIndependent.repr (hv : LinearIndependent R v) : span R (range v) →ₗ[R] ι →₀ R := hv.totalEquiv.symm #align linear_independent.repr LinearIndependent.repr @[simp] theorem LinearIndependent.total_repr (x) : Finsupp.total ι M R v (hv.repr x) = x := Subtype.ext_iff.1 (LinearEquiv.apply_symm_apply hv.totalEquiv x) #align linear_independent.total_repr LinearIndependent.total_repr theorem LinearIndependent.total_comp_repr : (Finsupp.total ι M R v).comp hv.repr = Submodule.subtype _ := LinearMap.ext <| hv.total_repr #align linear_independent.total_comp_repr LinearIndependent.total_comp_repr theorem LinearIndependent.repr_ker : LinearMap.ker hv.repr = ⊥ := by rw [LinearIndependent.repr, LinearEquiv.ker] #align linear_independent.repr_ker LinearIndependent.repr_ker theorem LinearIndependent.repr_range : LinearMap.range hv.repr = ⊤ := by rw [LinearIndependent.repr, LinearEquiv.range] #align linear_independent.repr_range LinearIndependent.repr_range theorem LinearIndependent.repr_eq {l : ι →₀ R} {x : span R (range v)} (eq : Finsupp.total ι M R v l = ↑x) : hv.repr x = l := by have : ↑((LinearIndependent.totalEquiv hv : (ι →₀ R) →ₗ[R] span R (range v)) l) = Finsupp.total ι M R v l := rfl have : (LinearIndependent.totalEquiv hv : (ι →₀ R) →ₗ[R] span R (range v)) l = x := by rw [eq] at this exact Subtype.ext_iff.2 this rw [← LinearEquiv.symm_apply_apply hv.totalEquiv l] rw [← this] rfl #align linear_independent.repr_eq LinearIndependent.repr_eq theorem LinearIndependent.repr_eq_single (i) (x : span R (range v)) (hx : ↑x = v i) : hv.repr x = Finsupp.single i 1 := by apply hv.repr_eq simp [Finsupp.total_single, hx] #align linear_independent.repr_eq_single LinearIndependent.repr_eq_single theorem LinearIndependent.span_repr_eq [Nontrivial R] (x) : Span.repr R (Set.range v) x = (hv.repr x).equivMapDomain (Equiv.ofInjective _ hv.injective) := by have p : (Span.repr R (Set.range v) x).equivMapDomain (Equiv.ofInjective _ hv.injective).symm = hv.repr x := by apply (LinearIndependent.totalEquiv hv).injective ext simp only [LinearIndependent.totalEquiv_apply_coe, Equiv.self_comp_ofInjective_symm, LinearIndependent.total_repr, Finsupp.total_equivMapDomain, Span.finsupp_total_repr] ext ⟨_, ⟨i, rfl⟩⟩ simp [← p] #align linear_independent.span_repr_eq LinearIndependent.span_repr_eq theorem linearIndependent_iff_not_smul_mem_span : LinearIndependent R v ↔ ∀ (i : ι) (a : R), a • v i ∈ span R (v '' (univ \ {i})) → a = 0 := ⟨fun hv i a ha => by rw [Finsupp.span_image_eq_map_total, mem_map] at ha rcases ha with ⟨l, hl, e⟩ rw [sub_eq_zero.1 (linearIndependent_iff.1 hv (l - Finsupp.single i a) (by simp [e]))] at hl by_contra hn exact (not_mem_of_mem_diff (hl <| by simp [hn])) (mem_singleton _), fun H => linearIndependent_iff.2 fun l hl => by ext i; simp only [Finsupp.zero_apply] by_contra hn refine hn (H i _ ?_) refine (Finsupp.mem_span_image_iff_total R).2 ⟨Finsupp.single i (l i) - l, ?_, ?_⟩ · rw [Finsupp.mem_supported'] intro j hj have hij : j = i := Classical.not_not.1 fun hij : j ≠ i => hj ((mem_diff _).2 ⟨mem_univ _, fun h => hij (eq_of_mem_singleton h)⟩) simp [hij] · simp [hl]⟩ #align linear_independent_iff_not_smul_mem_span linearIndependent_iff_not_smul_mem_span /-- See also `CompleteLattice.independent_iff_linearIndependent_of_ne_zero`. -/ theorem LinearIndependent.independent_span_singleton (hv : LinearIndependent R v) : CompleteLattice.Independent fun i => R ∙ v i := by refine CompleteLattice.independent_def.mp fun i => ?_ rw [disjoint_iff_inf_le] intro m hm simp only [mem_inf, mem_span_singleton, iSup_subtype'] at hm rw [← span_range_eq_iSup] at hm obtain ⟨⟨r, rfl⟩, hm⟩ := hm suffices r = 0 by simp [this] apply linearIndependent_iff_not_smul_mem_span.mp hv i -- Porting note: The original proof was using `convert hm`. suffices v '' (univ \ {i}) = range fun j : { j // j ≠ i } => v j by rwa [this] ext simp #align linear_independent.independent_span_singleton LinearIndependent.independent_span_singleton variable (R) theorem exists_maximal_independent' (s : ι → M) : ∃ I : Set ι, (LinearIndependent R fun x : I => s x) ∧ ∀ J : Set ι, I ⊆ J → (LinearIndependent R fun x : J => s x) → I = J := by let indep : Set ι → Prop := fun I => LinearIndependent R (s ∘ (↑) : I → M) let X := { I : Set ι // indep I } let r : X → X → Prop := fun I J => I.1 ⊆ J.1 have key : ∀ c : Set X, IsChain r c → indep (⋃ (I : X) (_ : I ∈ c), I) := by intro c hc dsimp [indep] rw [linearIndependent_comp_subtype] intro f hsupport hsum rcases eq_empty_or_nonempty c with (rfl | hn) · simpa using hsupport haveI : IsRefl X r := ⟨fun _ => Set.Subset.refl _⟩ obtain ⟨I, _I_mem, hI⟩ : ∃ I ∈ c, (f.support : Set ι) ⊆ I := hc.directedOn.exists_mem_subset_of_finset_subset_biUnion hn hsupport exact linearIndependent_comp_subtype.mp I.2 f hI hsum have trans : Transitive r := fun I J K => Set.Subset.trans obtain ⟨⟨I, hli : indep I⟩, hmax : ∀ a, r ⟨I, hli⟩ a → r a ⟨I, hli⟩⟩ := exists_maximal_of_chains_bounded (fun c hc => ⟨⟨⋃ I ∈ c, (I : Set ι), key c hc⟩, fun I => Set.subset_biUnion_of_mem⟩) @trans exact ⟨I, hli, fun J hsub hli => Set.Subset.antisymm hsub (hmax ⟨J, hli⟩ hsub)⟩ #align exists_maximal_independent' exists_maximal_independent' theorem exists_maximal_independent (s : ι → M) : ∃ I : Set ι, (LinearIndependent R fun x : I => s x) ∧ ∀ i ∉ I, ∃ a : R, a ≠ 0 ∧ a • s i ∈ span R (s '' I) := by classical rcases exists_maximal_independent' R s with ⟨I, hIlinind, hImaximal⟩ use I, hIlinind intro i hi specialize hImaximal (I ∪ {i}) (by simp) set J := I ∪ {i} with hJ have memJ : ∀ {x}, x ∈ J ↔ x = i ∨ x ∈ I := by simp [hJ] have hiJ : i ∈ J := by simp [J] have h := by refine mt hImaximal ?_ · intro h2 rw [h2] at hi exact absurd hiJ hi obtain ⟨f, supp_f, sum_f, f_ne⟩ := linearDependent_comp_subtype.mp h have hfi : f i ≠ 0 := by contrapose hIlinind refine linearDependent_comp_subtype.mpr ⟨f, ?_, sum_f, f_ne⟩ simp only [Finsupp.mem_supported, hJ] at supp_f ⊢ rintro x hx refine (memJ.mp (supp_f hx)).resolve_left ?_ rintro rfl exact hIlinind (Finsupp.mem_support_iff.mp hx) use f i, hfi have hfi' : i ∈ f.support := Finsupp.mem_support_iff.mpr hfi rw [← Finset.insert_erase hfi', Finset.sum_insert (Finset.not_mem_erase _ _), add_eq_zero_iff_eq_neg] at sum_f rw [sum_f] refine neg_mem (sum_mem fun c hc => smul_mem _ _ (subset_span ⟨c, ?_, rfl⟩)) exact (memJ.mp (supp_f (Finset.erase_subset _ _ hc))).resolve_left (Finset.ne_of_mem_erase hc) #align exists_maximal_independent exists_maximal_independent end repr theorem surjective_of_linearIndependent_of_span [Nontrivial R] (hv : LinearIndependent R v) (f : ι' ↪ ι) (hss : range v ⊆ span R (range (v ∘ f))) : Surjective f := by intro i let repr : (span R (range (v ∘ f)) : Type _) → ι' →₀ R := (hv.comp f f.injective).repr let l := (repr ⟨v i, hss (mem_range_self i)⟩).mapDomain f have h_total_l : Finsupp.total ι M R v l = v i := by dsimp only [l] rw [Finsupp.total_mapDomain] rw [(hv.comp f f.injective).total_repr] -- Porting note: `rfl` isn't necessary. have h_total_eq : (Finsupp.total ι M R v) l = (Finsupp.total ι M R v) (Finsupp.single i 1) := by rw [h_total_l, Finsupp.total_single, one_smul] have l_eq : l = _ := LinearMap.ker_eq_bot.1 hv h_total_eq dsimp only [l] at l_eq rw [← Finsupp.embDomain_eq_mapDomain] at l_eq rcases Finsupp.single_of_embDomain_single (repr ⟨v i, _⟩) f i (1 : R) zero_ne_one.symm l_eq with ⟨i', hi'⟩ use i' exact hi'.2 #align surjective_of_linear_independent_of_span surjective_of_linearIndependent_of_span theorem eq_of_linearIndependent_of_span_subtype [Nontrivial R] {s t : Set M} (hs : LinearIndependent R (fun x => x : s → M)) (h : t ⊆ s) (hst : s ⊆ span R t) : s = t := by let f : t ↪ s := ⟨fun x => ⟨x.1, h x.2⟩, fun a b hab => Subtype.coe_injective (Subtype.mk.inj hab)⟩ have h_surj : Surjective f := by apply surjective_of_linearIndependent_of_span hs f _ convert hst <;> simp [f, comp] show s = t apply Subset.antisymm _ h intro x hx rcases h_surj ⟨x, hx⟩ with ⟨y, hy⟩ convert y.mem rw [← Subtype.mk.inj hy] #align eq_of_linear_independent_of_span_subtype eq_of_linearIndependent_of_span_subtype open LinearMap theorem LinearIndependent.image_subtype {s : Set M} {f : M →ₗ[R] M'} (hs : LinearIndependent R (fun x => x : s → M)) (hf_inj : Disjoint (span R s) (LinearMap.ker f)) : LinearIndependent R (fun x => x : f '' s → M') := by rw [← Subtype.range_coe (s := s)] at hf_inj refine (hs.map hf_inj).to_subtype_range' ?_ simp [Set.range_comp f] #align linear_independent.image_subtype LinearIndependent.image_subtype
Mathlib/LinearAlgebra/LinearIndependent.lean
1,101
1,108
theorem LinearIndependent.inl_union_inr {s : Set M} {t : Set M'} (hs : LinearIndependent R (fun x => x : s → M)) (ht : LinearIndependent R (fun x => x : t → M')) : LinearIndependent R (fun x => x : ↥(inl R M M' '' s ∪ inr R M M' '' t) → M × M') := by
refine (hs.image_subtype ?_).union (ht.image_subtype ?_) ?_ <;> [simp; simp; skip] -- Note: #8386 had to change `span_image` into `span_image _` simp only [span_image _] simp [disjoint_iff, prod_inf_prod]
/- 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.RBMap.Alter import Batteries.Data.List.Lemmas /-! # Additional lemmas for Red-black trees -/ namespace Batteries namespace RBNode open RBColor attribute [simp] fold foldl foldr Any forM foldlM Ordered @[simp] theorem min?_reverse (t : RBNode α) : t.reverse.min? = t.max? := by unfold RBNode.max?; split <;> simp [RBNode.min?] unfold RBNode.min?; rw [min?.match_1.eq_3] · apply min?_reverse · simpa [reverse_eq_iff] @[simp] theorem max?_reverse (t : RBNode α) : t.reverse.max? = t.min? := by rw [← min?_reverse, reverse_reverse] @[simp] theorem mem_nil {x} : ¬x ∈ (.nil : RBNode α) := by simp [(·∈·), EMem] @[simp] theorem mem_node {y c a x b} : y ∈ (.node c a x b : RBNode α) ↔ y = x ∨ y ∈ a ∨ y ∈ b := by simp [(·∈·), EMem] theorem All_def {t : RBNode α} : t.All p ↔ ∀ x ∈ t, p x := by induction t <;> simp [or_imp, forall_and, *] theorem Any_def {t : RBNode α} : t.Any p ↔ ∃ x ∈ t, p x := by induction t <;> simp [or_and_right, exists_or, *] theorem memP_def : MemP cut t ↔ ∃ x ∈ t, cut x = .eq := Any_def theorem mem_def : Mem cmp x t ↔ ∃ y ∈ t, cmp x y = .eq := Any_def theorem mem_congr [@TransCmp α cmp] {t : RBNode α} (h : cmp x y = .eq) : Mem cmp x t ↔ Mem cmp y t := by simp [Mem, TransCmp.cmp_congr_left' h] theorem isOrdered_iff' [@TransCmp α cmp] {t : RBNode α} : isOrdered cmp t L R ↔ (∀ a ∈ L, t.All (cmpLT cmp a ·)) ∧ (∀ a ∈ R, t.All (cmpLT cmp · a)) ∧ (∀ a ∈ L, ∀ b ∈ R, cmpLT cmp a b) ∧ Ordered cmp t := by induction t generalizing L R with | nil => simp [isOrdered]; split <;> simp [cmpLT_iff] next h => intro _ ha _ hb; cases h _ _ ha hb | node _ l v r => simp [isOrdered, *] exact ⟨ fun ⟨⟨Ll, lv, Lv, ol⟩, ⟨vr, rR, vR, or⟩⟩ => ⟨ fun _ h => ⟨Lv _ h, Ll _ h, (Lv _ h).trans_l vr⟩, fun _ h => ⟨vR _ h, (vR _ h).trans_r lv, rR _ h⟩, fun _ hL _ hR => (Lv _ hL).trans (vR _ hR), lv, vr, ol, or⟩, fun ⟨hL, hR, _, lv, vr, ol, or⟩ => ⟨ ⟨fun _ h => (hL _ h).2.1, lv, fun _ h => (hL _ h).1, ol⟩, ⟨vr, fun _ h => (hR _ h).2.2, fun _ h => (hR _ h).1, or⟩⟩⟩ theorem isOrdered_iff [@TransCmp α cmp] {t : RBNode α} : isOrdered cmp t ↔ Ordered cmp t := by simp [isOrdered_iff'] instance (cmp) [@TransCmp α cmp] (t) : Decidable (Ordered cmp t) := decidable_of_iff _ isOrdered_iff /-- A cut is like a homomorphism of orderings: it is a monotonic predicate with respect to `cmp`, but it can make things that are distinguished by `cmp` equal. This is sufficient for `find?` to locate an element on which `cut` returns `.eq`, but there may be other elements, not returned by `find?`, on which `cut` also returns `.eq`. -/ class IsCut (cmp : α → α → Ordering) (cut : α → Ordering) : Prop where /-- The set `{x | cut x = .lt}` is downward-closed. -/ le_lt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut x = .lt → cut y = .lt /-- The set `{x | cut x = .gt}` is upward-closed. -/ le_gt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut y = .gt → cut x = .gt theorem IsCut.lt_trans [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .lt) : cut x = .lt → cut y = .lt := IsCut.le_lt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H theorem IsCut.gt_trans [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .lt) : cut y = .gt → cut x = .gt := IsCut.le_gt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H theorem IsCut.congr [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .eq) : cut x = cut y := by cases ey : cut y · exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h) ey · cases ex : cut x · exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans h) ex |>.symm.trans ey · rfl · refine IsCut.le_gt_trans (cmp := cmp) (fun h => ?_) ex |>.symm.trans ey cases H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h · exact IsCut.le_gt_trans (fun h => nomatch H.symm.trans h) ey instance (cmp cut) [@IsCut α cmp cut] : IsCut (flip cmp) (cut · |>.swap) where le_lt_trans h₁ h₂ := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [IsCut.le_gt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl le_gt_trans h₁ h₂ := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [IsCut.le_lt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl /-- `IsStrictCut` upgrades the `IsCut` property to ensure that at most one element of the tree can match the cut, and hence `find?` will return the unique such element if one exists. -/ class IsStrictCut (cmp : α → α → Ordering) (cut : α → Ordering) extends IsCut cmp cut : Prop where /-- If `cut = x`, then `cut` and `x` have compare the same with respect to other elements. -/ exact [TransCmp cmp] : cut x = .eq → cmp x y = cut y /-- A "representable cut" is one generated by `cmp a` for some `a`. This is always a valid cut. -/ instance (cmp) (a : α) : IsStrictCut cmp (cmp a) where le_lt_trans h₁ h₂ := TransCmp.lt_le_trans h₂ h₁ le_gt_trans h₁ := Decidable.not_imp_not.1 (TransCmp.le_trans · h₁) exact h := (TransCmp.cmp_congr_left h).symm instance (cmp cut) [@IsStrictCut α cmp cut] : IsStrictCut (flip cmp) (cut · |>.swap) where exact h := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [← IsStrictCut.exact (cmp := cmp) (Ordering.swap_inj.1 h), OrientedCmp.symm]; rfl section fold theorem foldr_cons (t : RBNode α) (l) : t.foldr (·::·) l = t.toList ++ l := by unfold toList induction t generalizing l with | nil => rfl | node _ a _ b iha ihb => rw [foldr, foldr, iha, iha (_::_), ihb]; simp @[simp] theorem toList_nil : (.nil : RBNode α).toList = [] := rfl @[simp] theorem toList_node : (.node c a x b : RBNode α).toList = a.toList ++ x :: b.toList := by rw [toList, foldr, foldr_cons]; rfl @[simp] theorem toList_reverse (t : RBNode α) : t.reverse.toList = t.toList.reverse := by induction t <;> simp [*] @[simp] theorem mem_toList {t : RBNode α} : x ∈ t.toList ↔ x ∈ t := by induction t <;> simp [*, or_left_comm] @[simp] theorem mem_reverse {t : RBNode α} : a ∈ t.reverse ↔ a ∈ t := by rw [← mem_toList]; simp theorem min?_eq_toList_head? {t : RBNode α} : t.min? = t.toList.head? := by induction t with | nil => rfl | node _ l _ _ ih => cases l <;> simp [RBNode.min?, ih] next ll _ _ => cases toList ll <;> rfl theorem max?_eq_toList_getLast? {t : RBNode α} : t.max? = t.toList.getLast? := by rw [← min?_reverse, min?_eq_toList_head?]; simp theorem foldr_eq_foldr_toList {t : RBNode α} : t.foldr f init = t.toList.foldr f init := by induction t generalizing init <;> simp [*] theorem foldl_eq_foldl_toList {t : RBNode α} : t.foldl f init = t.toList.foldl f init := by induction t generalizing init <;> simp [*] theorem foldl_reverse {α β : Type _} {t : RBNode α} {f : β → α → β} {init : β} : t.reverse.foldl f init = t.foldr (flip f) init := by simp (config := {unfoldPartialApp := true}) [foldr_eq_foldr_toList, foldl_eq_foldl_toList, flip] theorem foldr_reverse {α β : Type _} {t : RBNode α} {f : α → β → β} {init : β} : t.reverse.foldr f init = t.foldl (flip f) init := foldl_reverse.symm.trans (by simp; rfl) theorem forM_eq_forM_toList [Monad m] [LawfulMonad m] {t : RBNode α} : t.forM (m := m) f = t.toList.forM f := by induction t <;> simp [*] theorem foldlM_eq_foldlM_toList [Monad m] [LawfulMonad m] {t : RBNode α} : t.foldlM (m := m) f init = t.toList.foldlM f init := by induction t generalizing init <;> simp [*] theorem forIn_visit_eq_bindList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn.visit (m := m) f t init = (ForInStep.yield init).bindList f t.toList := by induction t generalizing init <;> simp [*, forIn.visit] theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn (m := m) t init f = forIn t.toList init f := by conv => lhs; simp only [forIn, RBNode.forIn] rw [List.forIn_eq_bindList, forIn_visit_eq_bindList] end fold namespace Stream attribute [simp] foldl foldr theorem foldr_cons (t : RBNode.Stream α) (l) : t.foldr (·::·) l = t.toList ++ l := by unfold toList; apply Eq.symm; induction t <;> simp [*, foldr, RBNode.foldr_cons] @[simp] theorem toList_nil : (.nil : RBNode.Stream α).toList = [] := rfl @[simp] theorem toList_cons : (.cons x r s : RBNode.Stream α).toList = x :: r.toList ++ s.toList := by rw [toList, toList, foldr, RBNode.foldr_cons]; rfl theorem foldr_eq_foldr_toList {s : RBNode.Stream α} : s.foldr f init = s.toList.foldr f init := by induction s <;> simp [*, RBNode.foldr_eq_foldr_toList] theorem foldl_eq_foldl_toList {t : RBNode.Stream α} : t.foldl f init = t.toList.foldl f init := by induction t generalizing init <;> simp [*, RBNode.foldl_eq_foldl_toList] theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn (m := m) t init f = forIn t.toList init f := by conv => lhs; simp only [forIn, RBNode.forIn] rw [List.forIn_eq_bindList, forIn_visit_eq_bindList] end Stream theorem toStream_toList' {t : RBNode α} {s} : (t.toStream s).toList = t.toList ++ s.toList := by induction t generalizing s <;> simp [*, toStream] @[simp] theorem toStream_toList {t : RBNode α} : t.toStream.toList = t.toList := by simp [toStream_toList'] theorem Stream.next?_toList {s : RBNode.Stream α} : (s.next?.map fun (a, b) => (a, b.toList)) = s.toList.next? := by cases s <;> simp [next?, toStream_toList'] theorem ordered_iff {t : RBNode α} : t.Ordered cmp ↔ t.toList.Pairwise (cmpLT cmp) := by induction t with | nil => simp | node c l v r ihl ihr => simp [*, List.pairwise_append, Ordered, All_def, and_assoc, and_left_comm, and_comm, imp_and, forall_and] exact fun _ _ hl hr a ha b hb => (hl _ ha).trans (hr _ hb) theorem Ordered.toList_sorted {t : RBNode α} : t.Ordered cmp → t.toList.Pairwise (cmpLT cmp) := ordered_iff.1 theorem min?_mem {t : RBNode α} (h : t.min? = some a) : a ∈ t := by rw [min?_eq_toList_head?] at h rw [← mem_toList] revert h; cases toList t <;> rintro ⟨⟩; constructor theorem Ordered.min?_le {t : RBNode α} [TransCmp cmp] (ht : t.Ordered cmp) (h : t.min? = some a) (x) (hx : x ∈ t) : cmp a x ≠ .gt := by rw [min?_eq_toList_head?] at h rw [← mem_toList] at hx have := ht.toList_sorted revert h hx this; cases toList t <;> rintro ⟨⟩ (_ | ⟨_, hx⟩) (_ | ⟨h1,h2⟩) · rw [OrientedCmp.cmp_refl (cmp := cmp)]; decide · rw [(h1 _ hx).1]; decide theorem max?_mem {t : RBNode α} (h : t.max? = some a) : a ∈ t := by simpa using min?_mem ((min?_reverse _).trans h) theorem Ordered.le_max? {t : RBNode α} [TransCmp cmp] (ht : t.Ordered cmp) (h : t.max? = some a) (x) (hx : x ∈ t) : cmp x a ≠ .gt := ht.reverse.min?_le ((min?_reverse _).trans h) _ (by simpa using hx) @[simp] theorem setBlack_toList {t : RBNode α} : t.setBlack.toList = t.toList := by cases t <;> simp [setBlack] @[simp] theorem setRed_toList {t : RBNode α} : t.setRed.toList = t.toList := by cases t <;> simp [setRed] @[simp] theorem balance1_toList {l : RBNode α} {v r} : (l.balance1 v r).toList = l.toList ++ v :: r.toList := by unfold balance1; split <;> simp @[simp] theorem balance2_toList {l : RBNode α} {v r} : (l.balance2 v r).toList = l.toList ++ v :: r.toList := by unfold balance2; split <;> simp @[simp] theorem balLeft_toList {l : RBNode α} {v r} : (l.balLeft v r).toList = l.toList ++ v :: r.toList := by unfold balLeft; split <;> (try simp); split <;> simp @[simp] theorem balRight_toList {l : RBNode α} {v r} : (l.balRight v r).toList = l.toList ++ v :: r.toList := by unfold balRight; split <;> (try simp); split <;> simp theorem size_eq {t : RBNode α} : t.size = t.toList.length := by induction t <;> simp [*, size]; rfl @[simp] theorem reverse_size (t : RBNode α) : t.reverse.size = t.size := by simp [size_eq] @[simp] theorem Any_reverse {t : RBNode α} : t.reverse.Any p ↔ t.Any p := by simp [Any_def] @[simp] theorem memP_reverse {t : RBNode α} : MemP cut t.reverse ↔ MemP (cut · |>.swap) t := by simp [MemP]; apply Iff.of_eq; congr; funext x; rw [← Ordering.swap_inj]; rfl theorem Mem_reverse [@OrientedCmp α cmp] {t : RBNode α} : Mem cmp x t.reverse ↔ Mem (flip cmp) x t := by simp [Mem]; apply Iff.of_eq; congr; funext x; rw [OrientedCmp.symm]; rfl section find? theorem find?_some_eq_eq {t : RBNode α} : x ∈ t.find? cut → cut x = .eq := by induction t <;> simp [find?]; split <;> try assumption intro | rfl => assumption theorem find?_some_mem {t : RBNode α} : x ∈ t.find? cut → x ∈ t := by induction t <;> simp [find?]; split <;> simp (config := {contextual := true}) [*] theorem find?_some_memP {t : RBNode α} (h : x ∈ t.find? cut) : MemP cut t := memP_def.2 ⟨_, find?_some_mem h, find?_some_eq_eq h⟩ theorem Ordered.memP_iff_find? [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) : MemP cut t ↔ ∃ x, t.find? cut = some x := by refine ⟨fun H => ?_, fun ⟨x, h⟩ => find?_some_memP h⟩ induction t with simp [find?] at H ⊢ | nil => cases H | node _ l _ r ihl ihr => let ⟨lx, xr, hl, hr⟩ := ht split · next ev => refine ihl hl ?_ rcases H with ev' | hx | hx · cases ev.symm.trans ev' · exact hx · have ⟨z, hz, ez⟩ := Any_def.1 hx cases ez.symm.trans <| IsCut.lt_trans (All_def.1 xr _ hz).1 ev · next ev => refine ihr hr ?_ rcases H with ev' | hx | hx · cases ev.symm.trans ev' · have ⟨z, hz, ez⟩ := Any_def.1 hx cases ez.symm.trans <| IsCut.gt_trans (All_def.1 lx _ hz).1 ev · exact hx · exact ⟨_, rfl⟩ theorem Ordered.unique [@TransCmp α cmp] (ht : Ordered cmp t) (hx : x ∈ t) (hy : y ∈ t) (e : cmp x y = .eq) : x = y := by induction t with | nil => cases hx | node _ l _ r ihl ihr => let ⟨lx, xr, hl, hr⟩ := ht rcases hx, hy with ⟨rfl | hx | hx, rfl | hy | hy⟩ · rfl · cases e.symm.trans <| OrientedCmp.cmp_eq_gt.2 (All_def.1 lx _ hy).1 · cases e.symm.trans (All_def.1 xr _ hy).1 · cases e.symm.trans (All_def.1 lx _ hx).1 · exact ihl hl hx hy · cases e.symm.trans ((All_def.1 lx _ hx).trans (All_def.1 xr _ hy)).1 · cases e.symm.trans <| OrientedCmp.cmp_eq_gt.2 (All_def.1 xr _ hx).1 · cases e.symm.trans <| OrientedCmp.cmp_eq_gt.2 ((All_def.1 lx _ hy).trans (All_def.1 xr _ hx)).1 · exact ihr hr hx hy theorem Ordered.find?_some [@TransCmp α cmp] [IsStrictCut cmp cut] (ht : Ordered cmp t) : t.find? cut = some x ↔ x ∈ t ∧ cut x = .eq := by refine ⟨fun h => ⟨find?_some_mem h, find?_some_eq_eq h⟩, fun ⟨hx, e⟩ => ?_⟩ have ⟨y, hy⟩ := ht.memP_iff_find?.1 (memP_def.2 ⟨_, hx, e⟩) exact ht.unique hx (find?_some_mem hy) ((IsStrictCut.exact e).trans (find?_some_eq_eq hy)) ▸ hy @[simp] theorem find?_reverse (t : RBNode α) (cut : α → Ordering) : t.reverse.find? cut = t.find? (cut · |>.swap) := by induction t <;> simp [*, find?] cases cut _ <;> simp [Ordering.swap] /-- Auxiliary definition for `zoom_ins`: set the root of the tree to `v`, creating a node if necessary. -/ def setRoot (v : α) : RBNode α → RBNode α | nil => node red nil v nil | node c a _ b => node c a v b /-- Auxiliary definition for `zoom_ins`: set the root of the tree to `v`, creating a node if necessary. -/ def delRoot : RBNode α → RBNode α | nil => nil | node _ a _ b => a.append b end find? section «upperBound? and lowerBound?» @[simp] theorem upperBound?_reverse (t : RBNode α) (cut ub) : t.reverse.upperBound? cut ub = t.lowerBound? (cut · |>.swap) ub := by induction t generalizing ub <;> simp [lowerBound?, upperBound?] split <;> simp [*, Ordering.swap] @[simp] theorem lowerBound?_reverse (t : RBNode α) (cut lb) : t.reverse.lowerBound? cut lb = t.upperBound? (cut · |>.swap) lb := by simpa using (upperBound?_reverse t.reverse (cut · |>.swap) lb).symm theorem upperBound?_eq_find? {t : RBNode α} {cut} (ub) (H : t.find? cut = some x) : t.upperBound? cut ub = some x := by induction t generalizing ub with simp [find?] at H | node c a y b iha ihb => simp [upperBound?]; split at H · apply iha _ H · apply ihb _ H · exact H theorem lowerBound?_eq_find? {t : RBNode α} {cut} (lb) (H : t.find? cut = some x) : t.lowerBound? cut lb = some x := by rw [← reverse_reverse t] at H ⊢; rw [lowerBound?_reverse]; rw [find?_reverse] at H exact upperBound?_eq_find? _ H /-- The value `x` returned by `upperBound?` is greater or equal to the `cut`. -/ theorem upperBound?_ge' {t : RBNode α} (H : ∀ {x}, x ∈ ub → cut x ≠ .gt) : t.upperBound? cut ub = some x → cut x ≠ .gt := by induction t generalizing ub with | nil => exact H | node _ _ _ _ ihl ihr => simp [upperBound?]; split · next hv => exact ihl fun | rfl, e => nomatch hv.symm.trans e · exact ihr H · next hv => intro | rfl, e => cases hv.symm.trans e /-- The value `x` returned by `upperBound?` is greater or equal to the `cut`. -/ theorem upperBound?_ge {t : RBNode α} : t.upperBound? cut = some x → cut x ≠ .gt := upperBound?_ge' nofun /-- The value `x` returned by `lowerBound?` is less or equal to the `cut`. -/ theorem lowerBound?_le' {t : RBNode α} (H : ∀ {x}, x ∈ lb → cut x ≠ .lt) : t.lowerBound? cut lb = some x → cut x ≠ .lt := by rw [← reverse_reverse t, lowerBound?_reverse, Ne, ← Ordering.swap_inj] exact upperBound?_ge' fun h => by specialize H h; rwa [Ne, ← Ordering.swap_inj] at H /-- The value `x` returned by `lowerBound?` is less or equal to the `cut`. -/ theorem lowerBound?_le {t : RBNode α} : t.lowerBound? cut = some x → cut x ≠ .lt := lowerBound?_le' nofun theorem All.upperBound?_ub {t : RBNode α} (hp : t.All p) (H : ∀ {x}, ub = some x → p x) : t.upperBound? cut ub = some x → p x := by induction t generalizing ub with | nil => exact H | node _ _ _ _ ihl ihr => simp [upperBound?]; split · exact ihl hp.2.1 fun | rfl => hp.1 · exact ihr hp.2.2 H · exact fun | rfl => hp.1 theorem All.upperBound? {t : RBNode α} (hp : t.All p) : t.upperBound? cut = some x → p x := hp.upperBound?_ub nofun theorem All.lowerBound?_lb {t : RBNode α} (hp : t.All p) (H : ∀ {x}, lb = some x → p x) : t.lowerBound? cut lb = some x → p x := by rw [← reverse_reverse t, lowerBound?_reverse] exact All.upperBound?_ub (All.reverse.2 hp) H theorem All.lowerBound? {t : RBNode α} (hp : t.All p) : t.lowerBound? cut = some x → p x := hp.lowerBound?_lb nofun theorem upperBound?_mem_ub {t : RBNode α} (h : t.upperBound? cut ub = some x) : x ∈ t ∨ ub = some x := All.upperBound?_ub (p := fun x => x ∈ t ∨ ub = some x) (All_def.2 fun _ => .inl) Or.inr h theorem upperBound?_mem {t : RBNode α} (h : t.upperBound? cut = some x) : x ∈ t := (upperBound?_mem_ub h).resolve_right nofun theorem lowerBound?_mem_lb {t : RBNode α} (h : t.lowerBound? cut lb = some x) : x ∈ t ∨ lb = some x := All.lowerBound?_lb (p := fun x => x ∈ t ∨ lb = some x) (All_def.2 fun _ => .inl) Or.inr h theorem lowerBound?_mem {t : RBNode α} (h : t.lowerBound? cut = some x) : x ∈ t := (lowerBound?_mem_lb h).resolve_right nofun theorem upperBound?_of_some {t : RBNode α} : ∃ x, t.upperBound? cut (some y) = some x := by induction t generalizing y <;> simp [upperBound?]; split <;> simp [*] theorem lowerBound?_of_some {t : RBNode α} : ∃ x, t.lowerBound? cut (some y) = some x := by rw [← reverse_reverse t, lowerBound?_reverse]; exact upperBound?_of_some theorem Ordered.upperBound?_exists [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) : (∃ x, t.upperBound? cut = some x) ↔ ∃ x ∈ t, cut x ≠ .gt := by refine ⟨fun ⟨x, hx⟩ => ⟨_, upperBound?_mem hx, upperBound?_ge hx⟩, fun H => ?_⟩ obtain ⟨x, hx, e⟩ := H induction t generalizing x with | nil => cases hx | node _ _ _ _ _ ihr => simp [upperBound?]; split · exact upperBound?_of_some · rcases hx with rfl | hx | hx · contradiction · next hv => cases e <| IsCut.gt_trans (All_def.1 h.1 _ hx).1 hv · exact ihr h.2.2.2 _ hx e · exact ⟨_, rfl⟩ theorem Ordered.lowerBound?_exists [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) : (∃ x, t.lowerBound? cut = some x) ↔ ∃ x ∈ t, cut x ≠ .lt := by conv => enter [2, 1, x]; rw [Ne, ← Ordering.swap_inj] rw [← reverse_reverse t, lowerBound?_reverse] simpa [-Ordering.swap_inj] using h.reverse.upperBound?_exists (cut := (cut · |>.swap)) theorem Ordered.upperBound?_least_ub [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) (hub : ∀ {x}, ub = some x → t.All (cmpLT cmp · x)) : t.upperBound? cut ub = some x → y ∈ t → cut x = .lt → cmp y x = .lt → cut y = .gt := by induction t generalizing ub with | nil => nofun | node _ _ _ _ ihl ihr => simp [upperBound?]; split <;> rename_i hv <;> rintro h₁ (rfl | hy' | hy') hx h₂ · rcases upperBound?_mem_ub h₁ with h₁ | ⟨⟨⟩⟩ · cases TransCmp.lt_asymm h₂ (All_def.1 h.1 _ h₁).1 · cases TransCmp.lt_asymm h₂ h₂ · exact ihl h.2.2.1 (by rintro _ ⟨⟨⟩⟩; exact h.1) h₁ hy' hx h₂ · refine (TransCmp.lt_asymm h₂ ?_).elim; have := (All_def.1 h.2.1 _ hy').1 rcases upperBound?_mem_ub h₁ with h₁ | ⟨⟨⟩⟩ · exact TransCmp.lt_trans (All_def.1 h.1 _ h₁).1 this · exact this · exact hv · exact IsCut.gt_trans (cut := cut) (cmp := cmp) (All_def.1 h.1 _ hy').1 hv · exact ihr h.2.2.2 (fun h => (hub h).2.2) h₁ hy' hx h₂ · cases h₁; cases TransCmp.lt_asymm h₂ h₂ · cases h₁; cases hx.symm.trans hv · cases h₁; cases hx.symm.trans hv theorem Ordered.lowerBound?_greatest_lb [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) (hlb : ∀ {x}, lb = some x → t.All (cmpLT cmp x ·)) : t.lowerBound? cut lb = some x → y ∈ t → cut x = .gt → cmp x y = .lt → cut y = .lt := by intro h1 h2 h3 h4 rw [← reverse_reverse t, lowerBound?_reverse] at h1 rw [← Ordering.swap_inj] at h3 ⊢ revert h2 h3 h4 simpa [-Ordering.swap_inj] using h.reverse.upperBound?_least_ub (fun h => All.reverse.2 <| (hlb h).imp .flip) h1 /-- A statement of the least-ness of the result of `upperBound?`. If `x` is the return value of `upperBound?` and it is strictly greater than the cut, then any other `y < x` in the tree is in fact strictly less than the cut (so there is no exact match, and nothing closer to the cut). -/ theorem Ordered.upperBound?_least [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) (H : t.upperBound? cut = some x) (hy : y ∈ t) (xy : cmp y x = .lt) (hx : cut x = .lt) : cut y = .gt := ht.upperBound?_least_ub (by nofun) H hy hx xy /-- A statement of the greatest-ness of the result of `lowerBound?`. If `x` is the return value of `lowerBound?` and it is strictly less than the cut, then any other `y > x` in the tree is in fact strictly greater than the cut (so there is no exact match, and nothing closer to the cut). -/ theorem Ordered.lowerBound?_greatest [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) (H : t.lowerBound? cut none = some x) (hy : y ∈ t) (xy : cmp x y = .lt) (hx : cut x = .gt) : cut y = .lt := ht.lowerBound?_greatest_lb (by nofun) H hy hx xy theorem Ordered.memP_iff_upperBound? [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) : t.MemP cut ↔ ∃ x, t.upperBound? cut = some x ∧ cut x = .eq := by refine memP_def.trans ⟨fun ⟨y, hy, ey⟩ => ?_, fun ⟨x, hx, e⟩ => ⟨_, upperBound?_mem hx, e⟩⟩ have ⟨x, hx⟩ := ht.upperBound?_exists.2 ⟨_, hy, fun h => nomatch ey.symm.trans h⟩ refine ⟨x, hx, ?_⟩; cases ex : cut x · cases e : cmp x y · cases ey.symm.trans <| IsCut.lt_trans e ex · cases ey.symm.trans <| IsCut.congr e |>.symm.trans ex · cases ey.symm.trans <| ht.upperBound?_least hx hy (OrientedCmp.cmp_eq_gt.1 e) ex · rfl · cases upperBound?_ge hx ex theorem Ordered.memP_iff_lowerBound? [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) : t.MemP cut ↔ ∃ x, t.lowerBound? cut = some x ∧ cut x = .eq := by refine memP_def.trans ⟨fun ⟨y, hy, ey⟩ => ?_, fun ⟨x, hx, e⟩ => ⟨_, lowerBound?_mem hx, e⟩⟩ have ⟨x, hx⟩ := ht.lowerBound?_exists.2 ⟨_, hy, fun h => nomatch ey.symm.trans h⟩ refine ⟨x, hx, ?_⟩; cases ex : cut x · cases lowerBound?_le hx ex · rfl · cases e : cmp x y · cases ey.symm.trans <| ht.lowerBound?_greatest hx hy e ex · cases ey.symm.trans <| IsCut.congr e |>.symm.trans ex · cases ey.symm.trans <| IsCut.gt_trans (OrientedCmp.cmp_eq_gt.1 e) ex /-- A stronger version of `lowerBound?_greatest` that holds when the cut is strict. -/ theorem Ordered.lowerBound?_lt [@TransCmp α cmp] [IsStrictCut cmp cut] (ht : Ordered cmp t) (H : t.lowerBound? cut = some x) (hy : y ∈ t) : cmp x y = .lt ↔ cut y = .lt := by refine ⟨fun h => ?_, fun h => OrientedCmp.cmp_eq_gt.1 ?_⟩ · cases e : cut x · cases lowerBound?_le H e · exact IsStrictCut.exact e |>.symm.trans h · exact ht.lowerBound?_greatest H hy h e · by_contra h'; exact lowerBound?_le H <| IsCut.le_lt_trans (cmp := cmp) (cut := cut) h' h /-- A stronger version of `upperBound?_least` that holds when the cut is strict. -/ theorem Ordered.lt_upperBound? [@TransCmp α cmp] [IsStrictCut cmp cut] (ht : Ordered cmp t) (H : t.upperBound? cut = some x) (hy : y ∈ t) : cmp y x = .lt ↔ cut y = .gt := by rw [← reverse_reverse t, upperBound?_reverse] at H rw [← Ordering.swap_inj (o₂ := .gt)] revert hy; simpa [-Ordering.swap_inj] using ht.reverse.lowerBound?_lt H end «upperBound? and lowerBound?» namespace Path attribute [simp] RootOrdered Ordered /-- The list of elements to the left of the hole. (This function is intended for specification purposes only.) -/ @[simp] def listL : Path α → List α | .root => [] | .left _ parent _ _ => parent.listL | .right _ l v parent => parent.listL ++ (l.toList ++ [v]) /-- The list of elements to the right of the hole. (This function is intended for specification purposes only.) -/ @[simp] def listR : Path α → List α | .root => [] | .left _ parent v r => v :: r.toList ++ parent.listR | .right _ _ _ parent => parent.listR /-- Wraps a list of elements with the left and right elements of the path. -/ abbrev withList (p : Path α) (l : List α) : List α := p.listL ++ l ++ p.listR theorem rootOrdered_iff {p : Path α} (hp : p.Ordered cmp) : p.RootOrdered cmp v ↔ (∀ a ∈ p.listL, cmpLT cmp a v) ∧ (∀ a ∈ p.listR, cmpLT cmp v a) := by induction p with (simp [All_def] at hp; simp [*, and_assoc, and_left_comm, and_comm, or_imp, forall_and]) | left _ _ x _ ih => exact fun vx _ _ _ ha => vx.trans (hp.2.1 _ ha) | right _ _ x _ ih => exact fun xv _ _ _ ha => (hp.2.1 _ ha).trans xv theorem ordered_iff {p : Path α} : p.Ordered cmp ↔ p.listL.Pairwise (cmpLT cmp) ∧ p.listR.Pairwise (cmpLT cmp) ∧ ∀ x ∈ p.listL, ∀ y ∈ p.listR, cmpLT cmp x y := by induction p with | root => simp | left _ _ x _ ih | right _ _ x _ ih => ?_ all_goals rw [Ordered, and_congr_right_eq fun h => by simp [All_def, rootOrdered_iff h]; rfl] simp [List.pairwise_append, or_imp, forall_and, ih, RBNode.ordered_iff] -- FIXME: simp [and_assoc, and_left_comm, and_comm] is really slow here · exact ⟨ fun ⟨⟨hL, hR, LR⟩, xr, ⟨Lx, xR⟩, ⟨rL, rR⟩, hr⟩ => ⟨hL, ⟨⟨xr, xR⟩, hr, hR, rR⟩, Lx, fun _ ha _ hb => rL _ hb _ ha, LR⟩, fun ⟨hL, ⟨⟨xr, xR⟩, hr, hR, rR⟩, Lx, Lr, LR⟩ => ⟨⟨hL, hR, LR⟩, xr, ⟨Lx, xR⟩, ⟨fun _ ha _ hb => Lr _ hb _ ha, rR⟩, hr⟩⟩ · exact ⟨ fun ⟨⟨hL, hR, LR⟩, lx, ⟨Lx, xR⟩, ⟨lL, lR⟩, hl⟩ => ⟨⟨hL, ⟨hl, lx⟩, fun _ ha _ hb => lL _ hb _ ha, Lx⟩, hR, LR, lR, xR⟩, fun ⟨⟨hL, ⟨hl, lx⟩, Ll, Lx⟩, hR, LR, lR, xR⟩ => ⟨⟨hL, hR, LR⟩, lx, ⟨Lx, xR⟩, ⟨fun _ ha _ hb => Ll _ hb _ ha, lR⟩, hl⟩⟩ theorem zoom_zoomed₁ (e : zoom cut t path = (t', path')) : t'.OnRoot (cut · = .eq) := match t, e with | nil, rfl => trivial | node .., e => by revert e; unfold zoom; split · exact zoom_zoomed₁ · exact zoom_zoomed₁ · next H => intro e; cases e; exact H @[simp] theorem fill_toList {p : Path α} : (p.fill t).toList = p.withList t.toList := by induction p generalizing t <;> simp [*] theorem _root_.Batteries.RBNode.zoom_toList {t : RBNode α} (eq : t.zoom cut = (t', p')) : p'.withList t'.toList = t.toList := by rw [← fill_toList, ← zoom_fill eq]; rfl @[simp] theorem ins_toList {p : Path α} : (p.ins t).toList = p.withList t.toList := by match p with | .root | .left red .. | .right red .. | .left black .. | .right black .. => simp [ins, ins_toList] @[simp] theorem insertNew_toList {p : Path α} : (p.insertNew v).toList = p.withList [v] := by simp [insertNew] theorem insert_toList {p : Path α} : (p.insert t v).toList = p.withList (t.setRoot v).toList := by simp [insert]; split <;> simp [setRoot] protected theorem Balanced.insert {path : Path α} (hp : path.Balanced c₀ n₀ c n) : t.Balanced c n → ∃ c n, (path.insert t v).Balanced c n | .nil => ⟨_, hp.insertNew⟩ | .red ha hb => ⟨_, _, hp.fill (.red ha hb)⟩ | .black ha hb => ⟨_, _, hp.fill (.black ha hb)⟩ theorem Ordered.insert : ∀ {path : Path α} {t : RBNode α}, path.Ordered cmp → t.Ordered cmp → t.All (path.RootOrdered cmp) → path.RootOrdered cmp v → t.OnRoot (cmpEq cmp v) → (path.insert t v).Ordered cmp | _, nil, hp, _, _, vp, _ => hp.insertNew vp | _, node .., hp, ⟨ax, xb, ha, hb⟩, ⟨_, ap, bp⟩, vp, xv => Ordered.fill.2 ⟨hp, ⟨ax.imp xv.lt_congr_right.2, xb.imp xv.lt_congr_left.2, ha, hb⟩, vp, ap, bp⟩ theorem Ordered.erase : ∀ {path : Path α} {t : RBNode α}, path.Ordered cmp → t.Ordered cmp → t.All (path.RootOrdered cmp) → (path.erase t).Ordered cmp | _, nil, hp, ht, tp => Ordered.fill.2 ⟨hp, ht, tp⟩ | _, node .., hp, ⟨ax, xb, ha, hb⟩, ⟨_, ap, bp⟩ => hp.del (ha.append ax xb hb) (ap.append bp) theorem zoom_ins {t : RBNode α} {cmp : α → α → Ordering} : t.zoom (cmp v) path = (t', path') → path.ins (t.ins cmp v) = path'.ins (t'.setRoot v) := by unfold RBNode.ins; split <;> simp [zoom] · intro | rfl, rfl => rfl all_goals · split · exact zoom_ins · exact zoom_ins · intro | rfl => rfl theorem insertNew_eq_insert (h : zoom (cmp v) t = (nil, path)) : path.insertNew v = (t.insert cmp v).setBlack := insert_setBlack .. ▸ (zoom_ins h).symm theorem ins_eq_fill {path : Path α} {t : RBNode α} : path.Balanced c₀ n₀ c n → t.Balanced c n → path.ins t = (path.fill t).setBlack | .root, h => rfl | .redL hb H, ha | .redR ha H, hb => by unfold ins; exact ins_eq_fill H (.red ha hb) | .blackL hb H, ha => by rw [ins, fill, ← ins_eq_fill H (.black ha hb), balance1_eq ha] | .blackR ha H, hb => by rw [ins, fill, ← ins_eq_fill H (.black ha hb), balance2_eq hb] theorem zoom_insert {path : Path α} {t : RBNode α} (ht : t.Balanced c n) (H : zoom (cmp v) t = (t', path)) : (path.insert t' v).setBlack = (t.insert cmp v).setBlack := by have ⟨_, _, ht', hp'⟩ := ht.zoom .root H cases ht' with simp [insert] | nil => simp [insertNew_eq_insert H, setBlack_idem] | red hl hr => rw [← ins_eq_fill hp' (.red hl hr), insert_setBlack]; exact (zoom_ins H).symm | black hl hr => rw [← ins_eq_fill hp' (.black hl hr), insert_setBlack]; exact (zoom_ins H).symm theorem zoom_del {t : RBNode α} : t.zoom cut path = (t', path') → path.del (t.del cut) (match t with | node c .. => c | _ => red) = path'.del t'.delRoot (match t' with | node c .. => c | _ => red) := by unfold RBNode.del; split <;> simp [zoom] · intro | rfl, rfl => rfl · next c a y b => split · have IH := @zoom_del (t := a) match a with | nil => intro | rfl => rfl | node black .. | node red .. => apply IH · have IH := @zoom_del (t := b) match b with | nil => intro | rfl => rfl | node black .. | node red .. => apply IH · intro | rfl => rfl /-- Asserts that `p` holds on all elements to the left of the hole. -/ def AllL (p : α → Prop) : Path α → Prop | .root => True | .left _ parent _ _ => parent.AllL p | .right _ a x parent => a.All p ∧ p x ∧ parent.AllL p /-- Asserts that `p` holds on all elements to the right of the hole. -/ def AllR (p : α → Prop) : Path α → Prop | .root => True | .left _ parent x b => parent.AllR p ∧ p x ∧ b.All p | .right _ _ _ parent => parent.AllR p end Path theorem insert_toList_zoom {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (t', p)) : (t.insert cmp v).toList = p.withList (t'.setRoot v).toList := by rw [← setBlack_toList, ← Path.zoom_insert ht e, setBlack_toList, Path.insert_toList] theorem insert_toList_zoom_nil {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (nil, p)) : (t.insert cmp v).toList = p.withList [v] := insert_toList_zoom ht e theorem exists_insert_toList_zoom_nil {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (nil, p)) : ∃ L R, t.toList = L ++ R ∧ (t.insert cmp v).toList = L ++ v :: R := ⟨p.listL, p.listR, by simp [← zoom_toList e, insert_toList_zoom_nil ht e]⟩ theorem insert_toList_zoom_node {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (node c' l v' r, p)) : (t.insert cmp v).toList = p.withList (node c l v r).toList := insert_toList_zoom ht e theorem exists_insert_toList_zoom_node {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (node c' l v' r, p)) : ∃ L R, t.toList = L ++ v' :: R ∧ (t.insert cmp v).toList = L ++ v :: R := by refine ⟨p.listL ++ l.toList, r.toList ++ p.listR, ?_⟩ simp [← zoom_toList e, insert_toList_zoom_node ht e] theorem mem_insert_self {t : RBNode α} (ht : Balanced t c n) : v ∈ t.insert cmp v := by rw [← mem_toList, List.mem_iff_append] exact match e : zoom (cmp v) t with | (nil, p) => let ⟨_, _, _, h⟩ := exists_insert_toList_zoom_nil ht e; ⟨_, _, h⟩ | (node .., p) => let ⟨_, _, _, h⟩ := exists_insert_toList_zoom_node ht e; ⟨_, _, h⟩ theorem mem_insert_of_mem {t : RBNode α} (ht : Balanced t c n) (h : v' ∈ t) : v' ∈ t.insert cmp v ∨ cmp v v' = .eq := by match e : zoom (cmp v) t with | (nil, p) => let ⟨_, _, h₁, h₂⟩ := exists_insert_toList_zoom_nil ht e simp [← mem_toList, h₁] at h simp [← mem_toList, h₂]; cases h <;> simp [*] | (node .., p) => let ⟨_, _, h₁, h₂⟩ := exists_insert_toList_zoom_node ht e simp [← mem_toList, h₁] at h simp [← mem_toList, h₂]; rcases h with h|h|h <;> simp [*] exact .inr (Path.zoom_zoomed₁ e) theorem exists_find?_insert_self [@TransCmp α cmp] [IsCut cmp cut] {t : RBNode α} (ht : Balanced t c n) (ht₂ : Ordered cmp t) (hv : cut v = .eq) : ∃ x, (t.insert cmp v).find? cut = some x := ht₂.insert.memP_iff_find?.1 <| memP_def.2 ⟨_, mem_insert_self ht, hv⟩ theorem find?_insert_self [@TransCmp α cmp] [IsStrictCut cmp cut] {t : RBNode α} (ht : Balanced t c n) (ht₂ : Ordered cmp t) (hv : cut v = .eq) : (t.insert cmp v).find? cut = some v := ht₂.insert.find?_some.2 ⟨mem_insert_self ht, hv⟩ theorem mem_insert [@TransCmp α cmp] {t : RBNode α} (ht : Balanced t c n) (ht₂ : Ordered cmp t) : v' ∈ t.insert cmp v ↔ (v' ∈ t ∧ t.find? (cmp v) ≠ some v') ∨ v' = v := by refine ⟨fun h => ?_, fun | .inl ⟨h₁, h₂⟩ => ?_ | .inr h => ?_⟩ · match e : zoom (cmp v) t with | (nil, p) => let ⟨_, _, h₁, h₂⟩ := exists_insert_toList_zoom_nil ht e simp [← mem_toList, h₂] at h; rw [← or_assoc, or_right_comm] at h refine h.imp_left fun h => ?_ simp [← mem_toList, h₁, h] rw [find?_eq_zoom, e]; nofun | (node .., p) => let ⟨_, _, h₁, h₂⟩ := exists_insert_toList_zoom_node ht e simp [← mem_toList, h₂] at h; simp [← mem_toList, h₁]; rw [or_left_comm] at h ⊢ rcases h with _|h <;> simp [*] refine .inl fun h => ?_ rw [find?_eq_zoom, e] at h; cases h suffices cmpLT cmp v' v' by cases OrientedCmp.cmp_refl.symm.trans this.1 have := ht₂.toList_sorted; simp [h₁, List.pairwise_append] at this exact h.elim (this.2.2 _ · |>.1) (this.2.1.1 _) · exact (mem_insert_of_mem ht h₁).resolve_right fun h' => h₂ <| ht₂.find?_some.2 ⟨h₁, h'⟩ · exact h ▸ mem_insert_self ht end RBNode open RBNode (IsCut IsStrictCut) namespace RBSet @[simp] theorem val_toList {t : RBSet α cmp} : t.1.toList = t.toList := rfl @[simp] theorem mkRBSet_eq : mkRBSet α cmp = ∅ := rfl @[simp] theorem empty_eq : @RBSet.empty α cmp = ∅ := rfl @[simp] theorem default_eq : (default : RBSet α cmp) = ∅ := rfl @[simp] theorem empty_toList : toList (∅ : RBSet α cmp) = [] := rfl @[simp] theorem single_toList : toList (single a : RBSet α cmp) = [a] := rfl theorem mem_toList {t : RBSet α cmp} : x ∈ toList t ↔ x ∈ t.1 := RBNode.mem_toList theorem mem_congr [@TransCmp α cmp] {t : RBSet α cmp} (h : cmp x y = .eq) : x ∈ t ↔ y ∈ t := RBNode.mem_congr h theorem mem_iff_mem_toList {t : RBSet α cmp} : x ∈ t ↔ ∃ y ∈ toList t, cmp x y = .eq := RBNode.mem_def.trans <| by simp [mem_toList] theorem mem_of_mem_toList [@OrientedCmp α cmp] {t : RBSet α cmp} (h : x ∈ toList t) : x ∈ t := mem_iff_mem_toList.2 ⟨_, h, OrientedCmp.cmp_refl⟩ theorem foldl_eq_foldl_toList {t : RBSet α cmp} : t.foldl f init = t.toList.foldl f init := RBNode.foldl_eq_foldl_toList theorem foldr_eq_foldr_toList {t : RBSet α cmp} : t.foldr f init = t.toList.foldr f init := RBNode.foldr_eq_foldr_toList theorem foldlM_eq_foldlM_toList [Monad m] [LawfulMonad m] {t : RBSet α cmp} : t.foldlM (m := m) f init = t.toList.foldlM f init := RBNode.foldlM_eq_foldlM_toList theorem forM_eq_forM_toList [Monad m] [LawfulMonad m] {t : RBSet α cmp} : t.forM (m := m) f = t.toList.forM f := RBNode.forM_eq_forM_toList theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBSet α cmp} : forIn (m := m) t init f = forIn t.toList init f := RBNode.forIn_eq_forIn_toList theorem toStream_eq {t : RBSet α cmp} : toStream t = t.1.toStream .nil := rfl @[simp] theorem toStream_toList {t : RBSet α cmp} : (toStream t).toList = t.toList := by simp [toStream_eq] theorem isEmpty_iff_toList_eq_nil {t : RBSet α cmp} : t.isEmpty ↔ t.toList = [] := by obtain ⟨⟨⟩, _⟩ := t <;> simp [toList, isEmpty] theorem toList_sorted {t : RBSet α cmp} : t.toList.Pairwise (RBNode.cmpLT cmp) := t.2.out.1.toList_sorted theorem findP?_some_eq_eq {t : RBSet α cmp} : t.findP? cut = some y → cut y = .eq := RBNode.find?_some_eq_eq theorem find?_some_eq_eq {t : RBSet α cmp} : t.find? x = some y → cmp x y = .eq := findP?_some_eq_eq theorem findP?_some_mem_toList {t : RBSet α cmp} (h : t.findP? cut = some y) : y ∈ toList t := mem_toList.2 <| RBNode.find?_some_mem h theorem find?_some_mem_toList {t : RBSet α cmp} (h : t.find? x = some y) : y ∈ toList t := findP?_some_mem_toList h theorem findP?_some_memP {t : RBSet α cmp} (h : t.findP? cut = some y) : t.MemP cut := RBNode.find?_some_memP h theorem find?_some_mem {t : RBSet α cmp} (h : t.find? x = some y) : x ∈ t := findP?_some_memP h theorem mem_toList_unique [@TransCmp α cmp] {t : RBSet α cmp} (hx : x ∈ toList t) (hy : y ∈ toList t) (e : cmp x y = .eq) : x = y := t.2.out.1.unique (mem_toList.1 hx) (mem_toList.1 hy) e theorem findP?_some [@TransCmp α cmp] [IsStrictCut cmp cut] {t : RBSet α cmp} : t.findP? cut = some y ↔ y ∈ toList t ∧ cut y = .eq := t.2.out.1.find?_some.trans <| by simp [mem_toList] theorem find?_some [@TransCmp α cmp] {t : RBSet α cmp} : t.find? x = some y ↔ y ∈ toList t ∧ cmp x y = .eq := findP?_some theorem memP_iff_findP? [@TransCmp α cmp] [IsCut cmp cut] {t : RBSet α cmp} : MemP cut t ↔ ∃ y, t.findP? cut = some y := t.2.out.1.memP_iff_find? theorem mem_iff_find? [@TransCmp α cmp] {t : RBSet α cmp} : x ∈ t ↔ ∃ y, t.find? x = some y := memP_iff_findP? @[simp] theorem contains_iff [@TransCmp α cmp] {t : RBSet α cmp} : t.contains x ↔ x ∈ t := Option.isSome_iff_exists.trans mem_iff_find?.symm instance [@TransCmp α cmp] {t : RBSet α cmp} : Decidable (x ∈ t) := decidable_of_iff _ contains_iff theorem size_eq (t : RBSet α cmp) : t.size = t.toList.length := RBNode.size_eq theorem mem_toList_insert_self (v) (t : RBSet α cmp) : v ∈ toList (t.insert v) := let ⟨_, _, h⟩ := t.2.out.2; mem_toList.2 (RBNode.mem_insert_self h) theorem mem_insert_self [@OrientedCmp α cmp] (v) (t : RBSet α cmp) : v ∈ t.insert v := mem_of_mem_toList <| mem_toList_insert_self v t theorem mem_insert_of_eq [@TransCmp α cmp] (t : RBSet α cmp) (h : cmp v v' = .eq) : v' ∈ t.insert v := (mem_congr h).1 (mem_insert_self ..) theorem mem_toList_insert_of_mem (v) {t : RBSet α cmp} (h : v' ∈ toList t) : v' ∈ toList (t.insert v) ∨ cmp v v' = .eq := let ⟨_, _, ht⟩ := t.2.out.2 .imp_left mem_toList.2 <| RBNode.mem_insert_of_mem ht <| mem_toList.1 h theorem mem_insert_of_mem_toList [@OrientedCmp α cmp] (v) {t : RBSet α cmp} (h : v' ∈ toList t) : v' ∈ t.insert v := match mem_toList_insert_of_mem v h with | .inl h' => mem_of_mem_toList h' | .inr h' => mem_iff_mem_toList.2 ⟨_, mem_toList_insert_self .., OrientedCmp.cmp_eq_eq_symm.1 h'⟩ theorem mem_insert_of_mem [@TransCmp α cmp] (v) {t : RBSet α cmp} (h : v' ∈ t) : v' ∈ t.insert v := let ⟨_, h₁, h₂⟩ := mem_iff_mem_toList.1 h (mem_congr h₂).2 (mem_insert_of_mem_toList v h₁) theorem mem_toList_insert [@TransCmp α cmp] {t : RBSet α cmp} : v' ∈ toList (t.insert v) ↔ (v' ∈ toList t ∧ t.find? v ≠ some v') ∨ v' = v := by let ⟨ht₁, _, _, ht₂⟩ := t.2.out simpa [mem_toList] using RBNode.mem_insert ht₂ ht₁
.lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean
940
946
theorem mem_insert [@TransCmp α cmp] {t : RBSet α cmp} : v' ∈ t.insert v ↔ v' ∈ t ∨ cmp v v' = .eq := by
refine ⟨fun h => ?_, fun | .inl h => mem_insert_of_mem _ h | .inr h => mem_insert_of_eq _ h⟩ let ⟨_, h₁, h₂⟩ := mem_iff_mem_toList.1 h match mem_toList_insert.1 h₁ with | .inl ⟨h₃, _⟩ => exact .inl <| mem_iff_mem_toList.2 ⟨_, h₃, h₂⟩ | .inr rfl => exact .inr <| OrientedCmp.cmp_eq_eq_symm.1 h₂
/- Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Patrick Lutz -/ import Mathlib.Algebra.Algebra.Subalgebra.Directed import Mathlib.FieldTheory.IntermediateField import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.SplittingField.IsSplittingField import Mathlib.RingTheory.TensorProduct.Basic #align_import field_theory.adjoin from "leanprover-community/mathlib"@"df76f43357840485b9d04ed5dee5ab115d420e87" /-! # Adjoining Elements to Fields In this file we introduce the notion of adjoining elements to fields. This isn't quite the same as adjoining elements to rings. For example, `Algebra.adjoin K {x}` might not include `x⁻¹`. ## Main results - `adjoin_adjoin_left`: adjoining S and then T is the same as adjoining `S ∪ T`. - `bot_eq_top_of_rank_adjoin_eq_one`: if `F⟮x⟯` has dimension `1` over `F` for every `x` in `E` then `F = E` ## Notation - `F⟮α⟯`: adjoin a single element `α` to `F` (in scope `IntermediateField`). -/ set_option autoImplicit true open FiniteDimensional Polynomial open scoped Classical Polynomial namespace IntermediateField section AdjoinDef variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E) -- Porting note: not adding `neg_mem'` causes an error. /-- `adjoin F S` extends a field `F` by adjoining a set `S ⊆ E`. -/ def adjoin : IntermediateField F E := { Subfield.closure (Set.range (algebraMap F E) ∪ S) with algebraMap_mem' := fun x => Subfield.subset_closure (Or.inl (Set.mem_range_self x)) } #align intermediate_field.adjoin IntermediateField.adjoin variable {S} theorem mem_adjoin_iff (x : E) : x ∈ adjoin F S ↔ ∃ r s : MvPolynomial S F, x = MvPolynomial.aeval Subtype.val r / MvPolynomial.aeval Subtype.val s := by simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring, Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring, Algebra.adjoin_eq_range, AlgHom.mem_range, exists_exists_eq_and] tauto theorem mem_adjoin_simple_iff {α : E} (x : E) : x ∈ adjoin F {α} ↔ ∃ r s : F[X], x = aeval α r / aeval α s := by simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring, Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring, Algebra.adjoin_singleton_eq_range_aeval, AlgHom.mem_range, exists_exists_eq_and] tauto end AdjoinDef section Lattice variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] @[simp] theorem adjoin_le_iff {S : Set E} {T : IntermediateField F E} : adjoin F S ≤ T ↔ S ≤ T := ⟨fun H => le_trans (le_trans Set.subset_union_right Subfield.subset_closure) H, fun H => (@Subfield.closure_le E _ (Set.range (algebraMap F E) ∪ S) T.toSubfield).mpr (Set.union_subset (IntermediateField.set_range_subset T) H)⟩ #align intermediate_field.adjoin_le_iff IntermediateField.adjoin_le_iff theorem gc : GaloisConnection (adjoin F : Set E → IntermediateField F E) (fun (x : IntermediateField F E) => (x : Set E)) := fun _ _ => adjoin_le_iff #align intermediate_field.gc IntermediateField.gc /-- Galois insertion between `adjoin` and `coe`. -/ def gi : GaloisInsertion (adjoin F : Set E → IntermediateField F E) (fun (x : IntermediateField F E) => (x : Set E)) where choice s hs := (adjoin F s).copy s <| le_antisymm (gc.le_u_l s) hs gc := IntermediateField.gc le_l_u S := (IntermediateField.gc (S : Set E) (adjoin F S)).1 <| le_rfl choice_eq _ _ := copy_eq _ _ _ #align intermediate_field.gi IntermediateField.gi instance : CompleteLattice (IntermediateField F E) where __ := GaloisInsertion.liftCompleteLattice IntermediateField.gi bot := { toSubalgebra := ⊥ inv_mem' := by rintro x ⟨r, rfl⟩; exact ⟨r⁻¹, map_inv₀ _ _⟩ } bot_le x := (bot_le : ⊥ ≤ x.toSubalgebra) instance : Inhabited (IntermediateField F E) := ⟨⊤⟩ instance : Unique (IntermediateField F F) := { inferInstanceAs (Inhabited (IntermediateField F F)) with uniq := fun _ ↦ toSubalgebra_injective <| Subsingleton.elim _ _ } theorem coe_bot : ↑(⊥ : IntermediateField F E) = Set.range (algebraMap F E) := rfl #align intermediate_field.coe_bot IntermediateField.coe_bot theorem mem_bot {x : E} : x ∈ (⊥ : IntermediateField F E) ↔ x ∈ Set.range (algebraMap F E) := Iff.rfl #align intermediate_field.mem_bot IntermediateField.mem_bot @[simp] theorem bot_toSubalgebra : (⊥ : IntermediateField F E).toSubalgebra = ⊥ := rfl #align intermediate_field.bot_to_subalgebra IntermediateField.bot_toSubalgebra @[simp] theorem coe_top : ↑(⊤ : IntermediateField F E) = (Set.univ : Set E) := rfl #align intermediate_field.coe_top IntermediateField.coe_top @[simp] theorem mem_top {x : E} : x ∈ (⊤ : IntermediateField F E) := trivial #align intermediate_field.mem_top IntermediateField.mem_top @[simp] theorem top_toSubalgebra : (⊤ : IntermediateField F E).toSubalgebra = ⊤ := rfl #align intermediate_field.top_to_subalgebra IntermediateField.top_toSubalgebra @[simp] theorem top_toSubfield : (⊤ : IntermediateField F E).toSubfield = ⊤ := rfl #align intermediate_field.top_to_subfield IntermediateField.top_toSubfield @[simp, norm_cast] theorem coe_inf (S T : IntermediateField F E) : (↑(S ⊓ T) : Set E) = (S : Set E) ∩ T := rfl #align intermediate_field.coe_inf IntermediateField.coe_inf @[simp] theorem mem_inf {S T : IntermediateField F E} {x : E} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl #align intermediate_field.mem_inf IntermediateField.mem_inf @[simp] theorem inf_toSubalgebra (S T : IntermediateField F E) : (S ⊓ T).toSubalgebra = S.toSubalgebra ⊓ T.toSubalgebra := rfl #align intermediate_field.inf_to_subalgebra IntermediateField.inf_toSubalgebra @[simp] theorem inf_toSubfield (S T : IntermediateField F E) : (S ⊓ T).toSubfield = S.toSubfield ⊓ T.toSubfield := rfl #align intermediate_field.inf_to_subfield IntermediateField.inf_toSubfield @[simp, norm_cast] theorem coe_sInf (S : Set (IntermediateField F E)) : (↑(sInf S) : Set E) = sInf ((fun (x : IntermediateField F E) => (x : Set E)) '' S) := rfl #align intermediate_field.coe_Inf IntermediateField.coe_sInf @[simp] theorem sInf_toSubalgebra (S : Set (IntermediateField F E)) : (sInf S).toSubalgebra = sInf (toSubalgebra '' S) := SetLike.coe_injective <| by simp [Set.sUnion_image] #align intermediate_field.Inf_to_subalgebra IntermediateField.sInf_toSubalgebra @[simp] theorem sInf_toSubfield (S : Set (IntermediateField F E)) : (sInf S).toSubfield = sInf (toSubfield '' S) := SetLike.coe_injective <| by simp [Set.sUnion_image] #align intermediate_field.Inf_to_subfield IntermediateField.sInf_toSubfield @[simp, norm_cast] theorem coe_iInf {ι : Sort*} (S : ι → IntermediateField F E) : (↑(iInf S) : Set E) = ⋂ i, S i := by simp [iInf] #align intermediate_field.coe_infi IntermediateField.coe_iInf @[simp] theorem iInf_toSubalgebra {ι : Sort*} (S : ι → IntermediateField F E) : (iInf S).toSubalgebra = ⨅ i, (S i).toSubalgebra := SetLike.coe_injective <| by simp [iInf] #align intermediate_field.infi_to_subalgebra IntermediateField.iInf_toSubalgebra @[simp] theorem iInf_toSubfield {ι : Sort*} (S : ι → IntermediateField F E) : (iInf S).toSubfield = ⨅ i, (S i).toSubfield := SetLike.coe_injective <| by simp [iInf] #align intermediate_field.infi_to_subfield IntermediateField.iInf_toSubfield /-- Construct an algebra isomorphism from an equality of intermediate fields -/ @[simps! apply] def equivOfEq {S T : IntermediateField F E} (h : S = T) : S ≃ₐ[F] T := Subalgebra.equivOfEq _ _ (congr_arg toSubalgebra h) #align intermediate_field.equiv_of_eq IntermediateField.equivOfEq @[simp] theorem equivOfEq_symm {S T : IntermediateField F E} (h : S = T) : (equivOfEq h).symm = equivOfEq h.symm := rfl #align intermediate_field.equiv_of_eq_symm IntermediateField.equivOfEq_symm @[simp] theorem equivOfEq_rfl (S : IntermediateField F E) : equivOfEq (rfl : S = S) = AlgEquiv.refl := by ext; rfl #align intermediate_field.equiv_of_eq_rfl IntermediateField.equivOfEq_rfl @[simp] theorem equivOfEq_trans {S T U : IntermediateField F E} (hST : S = T) (hTU : T = U) : (equivOfEq hST).trans (equivOfEq hTU) = equivOfEq (hST.trans hTU) := rfl #align intermediate_field.equiv_of_eq_trans IntermediateField.equivOfEq_trans variable (F E) /-- The bottom intermediate_field is isomorphic to the field. -/ noncomputable def botEquiv : (⊥ : IntermediateField F E) ≃ₐ[F] F := (Subalgebra.equivOfEq _ _ bot_toSubalgebra).trans (Algebra.botEquiv F E) #align intermediate_field.bot_equiv IntermediateField.botEquiv variable {F E} -- Porting note: this was tagged `simp`. theorem botEquiv_def (x : F) : botEquiv F E (algebraMap F (⊥ : IntermediateField F E) x) = x := by simp #align intermediate_field.bot_equiv_def IntermediateField.botEquiv_def @[simp] theorem botEquiv_symm (x : F) : (botEquiv F E).symm x = algebraMap F _ x := rfl #align intermediate_field.bot_equiv_symm IntermediateField.botEquiv_symm noncomputable instance algebraOverBot : Algebra (⊥ : IntermediateField F E) F := (IntermediateField.botEquiv F E).toAlgHom.toRingHom.toAlgebra #align intermediate_field.algebra_over_bot IntermediateField.algebraOverBot theorem coe_algebraMap_over_bot : (algebraMap (⊥ : IntermediateField F E) F : (⊥ : IntermediateField F E) → F) = IntermediateField.botEquiv F E := rfl #align intermediate_field.coe_algebra_map_over_bot IntermediateField.coe_algebraMap_over_bot instance isScalarTower_over_bot : IsScalarTower (⊥ : IntermediateField F E) F E := IsScalarTower.of_algebraMap_eq (by intro x obtain ⟨y, rfl⟩ := (botEquiv F E).symm.surjective x rw [coe_algebraMap_over_bot, (botEquiv F E).apply_symm_apply, botEquiv_symm, IsScalarTower.algebraMap_apply F (⊥ : IntermediateField F E) E]) #align intermediate_field.is_scalar_tower_over_bot IntermediateField.isScalarTower_over_bot /-- The top `IntermediateField` is isomorphic to the field. This is the intermediate field version of `Subalgebra.topEquiv`. -/ @[simps!] def topEquiv : (⊤ : IntermediateField F E) ≃ₐ[F] E := (Subalgebra.equivOfEq _ _ top_toSubalgebra).trans Subalgebra.topEquiv #align intermediate_field.top_equiv IntermediateField.topEquiv -- Porting note: this theorem is now generated by the `@[simps!]` above. #align intermediate_field.top_equiv_symm_apply_coe IntermediateField.topEquiv_symm_apply_coe @[simp] theorem restrictScalars_bot_eq_self (K : IntermediateField F E) : (⊥ : IntermediateField K E).restrictScalars _ = K := SetLike.coe_injective Subtype.range_coe #align intermediate_field.restrict_scalars_bot_eq_self IntermediateField.restrictScalars_bot_eq_self @[simp] theorem restrictScalars_top {K : Type*} [Field K] [Algebra K E] [Algebra K F] [IsScalarTower K F E] : (⊤ : IntermediateField F E).restrictScalars K = ⊤ := rfl #align intermediate_field.restrict_scalars_top IntermediateField.restrictScalars_top variable {K : Type*} [Field K] [Algebra F K] @[simp] theorem map_bot (f : E →ₐ[F] K) : IntermediateField.map f ⊥ = ⊥ := toSubalgebra_injective <| Algebra.map_bot _ theorem map_sup (s t : IntermediateField F E) (f : E →ₐ[F] K) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : E →ₐ[F] K) (s : ι → IntermediateField F E) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem _root_.AlgHom.fieldRange_eq_map (f : E →ₐ[F] K) : f.fieldRange = IntermediateField.map f ⊤ := SetLike.ext' Set.image_univ.symm #align alg_hom.field_range_eq_map AlgHom.fieldRange_eq_map theorem _root_.AlgHom.map_fieldRange {L : Type*} [Field L] [Algebra F L] (f : E →ₐ[F] K) (g : K →ₐ[F] L) : f.fieldRange.map g = (g.comp f).fieldRange := SetLike.ext' (Set.range_comp g f).symm #align alg_hom.map_field_range AlgHom.map_fieldRange theorem _root_.AlgHom.fieldRange_eq_top {f : E →ₐ[F] K} : f.fieldRange = ⊤ ↔ Function.Surjective f := SetLike.ext'_iff.trans Set.range_iff_surjective #align alg_hom.field_range_eq_top AlgHom.fieldRange_eq_top @[simp] theorem _root_.AlgEquiv.fieldRange_eq_top (f : E ≃ₐ[F] K) : (f : E →ₐ[F] K).fieldRange = ⊤ := AlgHom.fieldRange_eq_top.mpr f.surjective #align alg_equiv.field_range_eq_top AlgEquiv.fieldRange_eq_top end Lattice section equivMap variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] {K : Type*} [Field K] [Algebra F K] (L : IntermediateField F E) (f : E →ₐ[F] K) theorem fieldRange_comp_val : (f.comp L.val).fieldRange = L.map f := toSubalgebra_injective <| by rw [toSubalgebra_map, AlgHom.fieldRange_toSubalgebra, AlgHom.range_comp, range_val] /-- An intermediate field is isomorphic to its image under an `AlgHom` (which is automatically injective) -/ noncomputable def equivMap : L ≃ₐ[F] L.map f := (AlgEquiv.ofInjective _ (f.comp L.val).injective).trans (equivOfEq (fieldRange_comp_val L f)) @[simp] theorem coe_equivMap_apply (x : L) : ↑(equivMap L f x) = f x := rfl end equivMap section AdjoinDef variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E) theorem adjoin_eq_range_algebraMap_adjoin : (adjoin F S : Set E) = Set.range (algebraMap (adjoin F S) E) := Subtype.range_coe.symm #align intermediate_field.adjoin_eq_range_algebra_map_adjoin IntermediateField.adjoin_eq_range_algebraMap_adjoin theorem adjoin.algebraMap_mem (x : F) : algebraMap F E x ∈ adjoin F S := IntermediateField.algebraMap_mem (adjoin F S) x #align intermediate_field.adjoin.algebra_map_mem IntermediateField.adjoin.algebraMap_mem theorem adjoin.range_algebraMap_subset : Set.range (algebraMap F E) ⊆ adjoin F S := by intro x hx cases' hx with f hf rw [← hf] exact adjoin.algebraMap_mem F S f #align intermediate_field.adjoin.range_algebra_map_subset IntermediateField.adjoin.range_algebraMap_subset instance adjoin.fieldCoe : CoeTC F (adjoin F S) where coe x := ⟨algebraMap F E x, adjoin.algebraMap_mem F S x⟩ #align intermediate_field.adjoin.field_coe IntermediateField.adjoin.fieldCoe theorem subset_adjoin : S ⊆ adjoin F S := fun _ hx => Subfield.subset_closure (Or.inr hx) #align intermediate_field.subset_adjoin IntermediateField.subset_adjoin instance adjoin.setCoe : CoeTC S (adjoin F S) where coe x := ⟨x, subset_adjoin F S (Subtype.mem x)⟩ #align intermediate_field.adjoin.set_coe IntermediateField.adjoin.setCoe @[mono] theorem adjoin.mono (T : Set E) (h : S ⊆ T) : adjoin F S ≤ adjoin F T := GaloisConnection.monotone_l gc h #align intermediate_field.adjoin.mono IntermediateField.adjoin.mono theorem adjoin_contains_field_as_subfield (F : Subfield E) : (F : Set E) ⊆ adjoin F S := fun x hx => adjoin.algebraMap_mem F S ⟨x, hx⟩ #align intermediate_field.adjoin_contains_field_as_subfield IntermediateField.adjoin_contains_field_as_subfield theorem subset_adjoin_of_subset_left {F : Subfield E} {T : Set E} (HT : T ⊆ F) : T ⊆ adjoin F S := fun x hx => (adjoin F S).algebraMap_mem ⟨x, HT hx⟩ #align intermediate_field.subset_adjoin_of_subset_left IntermediateField.subset_adjoin_of_subset_left theorem subset_adjoin_of_subset_right {T : Set E} (H : T ⊆ S) : T ⊆ adjoin F S := fun _ hx => subset_adjoin F S (H hx) #align intermediate_field.subset_adjoin_of_subset_right IntermediateField.subset_adjoin_of_subset_right @[simp] theorem adjoin_empty (F E : Type*) [Field F] [Field E] [Algebra F E] : adjoin F (∅ : Set E) = ⊥ := eq_bot_iff.mpr (adjoin_le_iff.mpr (Set.empty_subset _)) #align intermediate_field.adjoin_empty IntermediateField.adjoin_empty @[simp] theorem adjoin_univ (F E : Type*) [Field F] [Field E] [Algebra F E] : adjoin F (Set.univ : Set E) = ⊤ := eq_top_iff.mpr <| subset_adjoin _ _ #align intermediate_field.adjoin_univ IntermediateField.adjoin_univ /-- If `K` is a field with `F ⊆ K` and `S ⊆ K` then `adjoin F S ≤ K`. -/ theorem adjoin_le_subfield {K : Subfield E} (HF : Set.range (algebraMap F E) ⊆ K) (HS : S ⊆ K) : (adjoin F S).toSubfield ≤ K := by apply Subfield.closure_le.mpr rw [Set.union_subset_iff] exact ⟨HF, HS⟩ #align intermediate_field.adjoin_le_subfield IntermediateField.adjoin_le_subfield theorem adjoin_subset_adjoin_iff {F' : Type*} [Field F'] [Algebra F' E] {S S' : Set E} : (adjoin F S : Set E) ⊆ adjoin F' S' ↔ Set.range (algebraMap F E) ⊆ adjoin F' S' ∧ S ⊆ adjoin F' S' := ⟨fun h => ⟨(adjoin.range_algebraMap_subset _ _).trans h, (subset_adjoin _ _).trans h⟩, fun ⟨hF, hS⟩ => (Subfield.closure_le (t := (adjoin F' S').toSubfield)).mpr (Set.union_subset hF hS)⟩ #align intermediate_field.adjoin_subset_adjoin_iff IntermediateField.adjoin_subset_adjoin_iff /-- `F[S][T] = F[S ∪ T]` -/ theorem adjoin_adjoin_left (T : Set E) : (adjoin (adjoin F S) T).restrictScalars _ = adjoin F (S ∪ T) := by rw [SetLike.ext'_iff] change (↑(adjoin (adjoin F S) T) : Set E) = _ apply Set.eq_of_subset_of_subset <;> rw [adjoin_subset_adjoin_iff] <;> constructor · rintro _ ⟨⟨x, hx⟩, rfl⟩; exact adjoin.mono _ _ _ Set.subset_union_left hx · exact subset_adjoin_of_subset_right _ _ Set.subset_union_right -- Porting note: orginal proof times out · rintro x ⟨f, rfl⟩ refine Subfield.subset_closure ?_ left exact ⟨f, rfl⟩ -- Porting note: orginal proof times out · refine Set.union_subset (fun x hx => Subfield.subset_closure ?_) (fun x hx => Subfield.subset_closure ?_) · left refine ⟨⟨x, Subfield.subset_closure ?_⟩, rfl⟩ right exact hx · right exact hx #align intermediate_field.adjoin_adjoin_left IntermediateField.adjoin_adjoin_left @[simp] theorem adjoin_insert_adjoin (x : E) : adjoin F (insert x (adjoin F S : Set E)) = adjoin F (insert x S) := le_antisymm (adjoin_le_iff.mpr (Set.insert_subset_iff.mpr ⟨subset_adjoin _ _ (Set.mem_insert _ _), adjoin_le_iff.mpr (subset_adjoin_of_subset_right _ _ (Set.subset_insert _ _))⟩)) (adjoin.mono _ _ _ (Set.insert_subset_insert (subset_adjoin _ _))) #align intermediate_field.adjoin_insert_adjoin IntermediateField.adjoin_insert_adjoin /-- `F[S][T] = F[T][S]` -/ theorem adjoin_adjoin_comm (T : Set E) : (adjoin (adjoin F S) T).restrictScalars F = (adjoin (adjoin F T) S).restrictScalars F := by rw [adjoin_adjoin_left, adjoin_adjoin_left, Set.union_comm] #align intermediate_field.adjoin_adjoin_comm IntermediateField.adjoin_adjoin_comm theorem adjoin_map {E' : Type*} [Field E'] [Algebra F E'] (f : E →ₐ[F] E') : (adjoin F S).map f = adjoin F (f '' S) := by ext x show x ∈ (Subfield.closure (Set.range (algebraMap F E) ∪ S)).map (f : E →+* E') ↔ x ∈ Subfield.closure (Set.range (algebraMap F E') ∪ f '' S) rw [RingHom.map_field_closure, Set.image_union, ← Set.range_comp, ← RingHom.coe_comp, f.comp_algebraMap] rfl #align intermediate_field.adjoin_map IntermediateField.adjoin_map @[simp] theorem lift_adjoin (K : IntermediateField F E) (S : Set K) : lift (adjoin F S) = adjoin F (Subtype.val '' S) := adjoin_map _ _ _ theorem lift_adjoin_simple (K : IntermediateField F E) (α : K) : lift (adjoin F {α}) = adjoin F {α.1} := by simp only [lift_adjoin, Set.image_singleton] @[simp] theorem lift_bot (K : IntermediateField F E) : lift (F := K) ⊥ = ⊥ := map_bot _ @[simp] theorem lift_top (K : IntermediateField F E) : lift (F := K) ⊤ = K := by rw [lift, ← AlgHom.fieldRange_eq_map, fieldRange_val] @[simp] theorem adjoin_self (K : IntermediateField F E) : adjoin F K = K := le_antisymm (adjoin_le_iff.2 fun _ ↦ id) (subset_adjoin F _) theorem restrictScalars_adjoin (K : IntermediateField F E) (S : Set E) : restrictScalars F (adjoin K S) = adjoin F (K ∪ S) := by rw [← adjoin_self _ K, adjoin_adjoin_left, adjoin_self _ K] variable {F} in theorem extendScalars_adjoin {K : IntermediateField F E} {S : Set E} (h : K ≤ adjoin F S) : extendScalars h = adjoin K S := restrictScalars_injective F <| by rw [extendScalars_restrictScalars, restrictScalars_adjoin] exact le_antisymm (adjoin.mono F S _ Set.subset_union_right) <| adjoin_le_iff.2 <| Set.union_subset h (subset_adjoin F S) variable {F} in /-- If `E / L / F` and `E / L' / F` are two field extension towers, `L ≃ₐ[F] L'` is an isomorphism compatible with `E / L` and `E / L'`, then for any subset `S` of `E`, `L(S)` and `L'(S)` are equal as intermediate fields of `E / F`. -/ theorem restrictScalars_adjoin_of_algEquiv {L L' : Type*} [Field L] [Field L'] [Algebra F L] [Algebra L E] [Algebra F L'] [Algebra L' E] [IsScalarTower F L E] [IsScalarTower F L' E] (i : L ≃ₐ[F] L') (hi : algebraMap L E = (algebraMap L' E) ∘ i) (S : Set E) : (adjoin L S).restrictScalars F = (adjoin L' S).restrictScalars F := by apply_fun toSubfield using (fun K K' h ↦ by ext x; change x ∈ K.toSubfield ↔ x ∈ K'.toSubfield; rw [h]) change Subfield.closure _ = Subfield.closure _ congr ext x exact ⟨fun ⟨y, h⟩ ↦ ⟨i y, by rw [← h, hi]; rfl⟩, fun ⟨y, h⟩ ↦ ⟨i.symm y, by rw [← h, hi, Function.comp_apply, AlgEquiv.apply_symm_apply]⟩⟩ theorem algebra_adjoin_le_adjoin : Algebra.adjoin F S ≤ (adjoin F S).toSubalgebra := Algebra.adjoin_le (subset_adjoin _ _) #align intermediate_field.algebra_adjoin_le_adjoin IntermediateField.algebra_adjoin_le_adjoin theorem adjoin_eq_algebra_adjoin (inv_mem : ∀ x ∈ Algebra.adjoin F S, x⁻¹ ∈ Algebra.adjoin F S) : (adjoin F S).toSubalgebra = Algebra.adjoin F S := le_antisymm (show adjoin F S ≤ { Algebra.adjoin F S with inv_mem' := inv_mem } from adjoin_le_iff.mpr Algebra.subset_adjoin) (algebra_adjoin_le_adjoin _ _) #align intermediate_field.adjoin_eq_algebra_adjoin IntermediateField.adjoin_eq_algebra_adjoin theorem eq_adjoin_of_eq_algebra_adjoin (K : IntermediateField F E) (h : K.toSubalgebra = Algebra.adjoin F S) : K = adjoin F S := by apply toSubalgebra_injective rw [h] refine (adjoin_eq_algebra_adjoin F _ ?_).symm intro x convert K.inv_mem (x := x) <;> rw [← h] <;> rfl #align intermediate_field.eq_adjoin_of_eq_algebra_adjoin IntermediateField.eq_adjoin_of_eq_algebra_adjoin theorem adjoin_eq_top_of_algebra (hS : Algebra.adjoin F S = ⊤) : adjoin F S = ⊤ := top_le_iff.mp (hS.symm.trans_le <| algebra_adjoin_le_adjoin F S) @[elab_as_elim] theorem adjoin_induction {s : Set E} {p : E → Prop} {x} (h : x ∈ adjoin F s) (mem : ∀ x ∈ s, p x) (algebraMap : ∀ x, p (algebraMap F E x)) (add : ∀ x y, p x → p y → p (x + y)) (neg : ∀ x, p x → p (-x)) (inv : ∀ x, p x → p x⁻¹) (mul : ∀ x y, p x → p y → p (x * y)) : p x := Subfield.closure_induction h (fun x hx => Or.casesOn hx (fun ⟨x, hx⟩ => hx ▸ algebraMap x) (mem x)) ((_root_.algebraMap F E).map_one ▸ algebraMap 1) add neg inv mul #align intermediate_field.adjoin_induction IntermediateField.adjoin_induction /- Porting note (kmill): this notation is replacing the typeclass-based one I had previously written, and it gives true `{x₁, x₂, ..., xₙ}` sets in the `adjoin` term. -/ open Lean in /-- Supporting function for the `F⟮x₁,x₂,...,xₙ⟯` adjunction notation. -/ private partial def mkInsertTerm [Monad m] [MonadQuotation m] (xs : TSyntaxArray `term) : m Term := run 0 where run (i : Nat) : m Term := do if i + 1 == xs.size then ``(singleton $(xs[i]!)) else if i < xs.size then ``(insert $(xs[i]!) $(← run (i + 1))) else ``(EmptyCollection.emptyCollection) /-- If `x₁ x₂ ... xₙ : E` then `F⟮x₁,x₂,...,xₙ⟯` is the `IntermediateField F E` generated by these elements. -/ scoped macro:max K:term "⟮" xs:term,* "⟯" : term => do ``(adjoin $K $(← mkInsertTerm xs.getElems)) open Lean PrettyPrinter.Delaborator SubExpr in @[delab app.IntermediateField.adjoin] partial def delabAdjoinNotation : Delab := whenPPOption getPPNotation do let e ← getExpr guard <| e.isAppOfArity ``adjoin 6 let F ← withNaryArg 0 delab let xs ← withNaryArg 5 delabInsertArray `($F⟮$(xs.toArray),*⟯) where delabInsertArray : DelabM (List Term) := do let e ← getExpr if e.isAppOfArity ``EmptyCollection.emptyCollection 2 then return [] else if e.isAppOfArity ``singleton 4 then let x ← withNaryArg 3 delab return [x] else if e.isAppOfArity ``insert 5 then let x ← withNaryArg 3 delab let xs ← withNaryArg 4 delabInsertArray return x :: xs else failure section AdjoinSimple variable (α : E) -- Porting note: in all the theorems below, mathport translated `F⟮α⟯` into `F⟮⟯`. theorem mem_adjoin_simple_self : α ∈ F⟮α⟯ := subset_adjoin F {α} (Set.mem_singleton α) #align intermediate_field.mem_adjoin_simple_self IntermediateField.mem_adjoin_simple_self /-- generator of `F⟮α⟯` -/ def AdjoinSimple.gen : F⟮α⟯ := ⟨α, mem_adjoin_simple_self F α⟩ #align intermediate_field.adjoin_simple.gen IntermediateField.AdjoinSimple.gen @[simp] theorem AdjoinSimple.coe_gen : (AdjoinSimple.gen F α : E) = α := rfl theorem AdjoinSimple.algebraMap_gen : algebraMap F⟮α⟯ E (AdjoinSimple.gen F α) = α := rfl #align intermediate_field.adjoin_simple.algebra_map_gen IntermediateField.AdjoinSimple.algebraMap_gen @[simp] theorem AdjoinSimple.isIntegral_gen : IsIntegral F (AdjoinSimple.gen F α) ↔ IsIntegral F α := by conv_rhs => rw [← AdjoinSimple.algebraMap_gen F α] rw [isIntegral_algebraMap_iff (algebraMap F⟮α⟯ E).injective] #align intermediate_field.adjoin_simple.is_integral_gen IntermediateField.AdjoinSimple.isIntegral_gen theorem adjoin_simple_adjoin_simple (β : E) : F⟮α⟯⟮β⟯.restrictScalars F = F⟮α, β⟯ := adjoin_adjoin_left _ _ _ #align intermediate_field.adjoin_simple_adjoin_simple IntermediateField.adjoin_simple_adjoin_simple theorem adjoin_simple_comm (β : E) : F⟮α⟯⟮β⟯.restrictScalars F = F⟮β⟯⟮α⟯.restrictScalars F := adjoin_adjoin_comm _ _ _ #align intermediate_field.adjoin_simple_comm IntermediateField.adjoin_simple_comm variable {F} {α} theorem adjoin_algebraic_toSubalgebra {S : Set E} (hS : ∀ x ∈ S, IsAlgebraic F x) : (IntermediateField.adjoin F S).toSubalgebra = Algebra.adjoin F S := by simp only [isAlgebraic_iff_isIntegral] at hS have : Algebra.IsIntegral F (Algebra.adjoin F S) := by rwa [← le_integralClosure_iff_isIntegral, Algebra.adjoin_le_iff] have : IsField (Algebra.adjoin F S) := isField_of_isIntegral_of_isField' (Field.toIsField F) rw [← ((Algebra.adjoin F S).toIntermediateField' this).eq_adjoin_of_eq_algebra_adjoin F S] <;> rfl #align intermediate_field.adjoin_algebraic_to_subalgebra IntermediateField.adjoin_algebraic_toSubalgebra theorem adjoin_simple_toSubalgebra_of_integral (hα : IsIntegral F α) : F⟮α⟯.toSubalgebra = Algebra.adjoin F {α} := by apply adjoin_algebraic_toSubalgebra rintro x (rfl : x = α) rwa [isAlgebraic_iff_isIntegral] #align intermediate_field.adjoin_simple_to_subalgebra_of_integral IntermediateField.adjoin_simple_toSubalgebra_of_integral /-- Characterize `IsSplittingField` with `IntermediateField.adjoin` instead of `Algebra.adjoin`. -/ theorem _root_.isSplittingField_iff_intermediateField {p : F[X]} : p.IsSplittingField F E ↔ p.Splits (algebraMap F E) ∧ adjoin F (p.rootSet E) = ⊤ := by rw [← toSubalgebra_injective.eq_iff, adjoin_algebraic_toSubalgebra fun _ ↦ isAlgebraic_of_mem_rootSet] exact ⟨fun ⟨spl, adj⟩ ↦ ⟨spl, adj⟩, fun ⟨spl, adj⟩ ↦ ⟨spl, adj⟩⟩ -- Note: p.Splits (algebraMap F E) also works theorem isSplittingField_iff {p : F[X]} {K : IntermediateField F E} : p.IsSplittingField F K ↔ p.Splits (algebraMap F K) ∧ K = adjoin F (p.rootSet E) := by suffices _ → (Algebra.adjoin F (p.rootSet K) = ⊤ ↔ K = adjoin F (p.rootSet E)) by exact ⟨fun h ↦ ⟨h.1, (this h.1).mp h.2⟩, fun h ↦ ⟨h.1, (this h.1).mpr h.2⟩⟩ rw [← toSubalgebra_injective.eq_iff, adjoin_algebraic_toSubalgebra fun x ↦ isAlgebraic_of_mem_rootSet] refine fun hp ↦ (adjoin_rootSet_eq_range hp K.val).symm.trans ?_ rw [← K.range_val, eq_comm] #align intermediate_field.is_splitting_field_iff IntermediateField.isSplittingField_iff theorem adjoin_rootSet_isSplittingField {p : F[X]} (hp : p.Splits (algebraMap F E)) : p.IsSplittingField F (adjoin F (p.rootSet E)) := isSplittingField_iff.mpr ⟨splits_of_splits hp fun _ hx ↦ subset_adjoin F (p.rootSet E) hx, rfl⟩ #align intermediate_field.adjoin_root_set_is_splitting_field IntermediateField.adjoin_rootSet_isSplittingField section Supremum variable {K L : Type*} [Field K] [Field L] [Algebra K L] (E1 E2 : IntermediateField K L) theorem le_sup_toSubalgebra : E1.toSubalgebra ⊔ E2.toSubalgebra ≤ (E1 ⊔ E2).toSubalgebra := sup_le (show E1 ≤ E1 ⊔ E2 from le_sup_left) (show E2 ≤ E1 ⊔ E2 from le_sup_right) #align intermediate_field.le_sup_to_subalgebra IntermediateField.le_sup_toSubalgebra theorem sup_toSubalgebra_of_isAlgebraic_right [Algebra.IsAlgebraic K E2] : (E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := by have : (adjoin E1 (E2 : Set L)).toSubalgebra = _ := adjoin_algebraic_toSubalgebra fun x h ↦ IsAlgebraic.tower_top E1 (isAlgebraic_iff.1 (Algebra.IsAlgebraic.isAlgebraic (⟨x, h⟩ : E2))) apply_fun Subalgebra.restrictScalars K at this erw [← restrictScalars_toSubalgebra, restrictScalars_adjoin, Algebra.restrictScalars_adjoin] at this exact this theorem sup_toSubalgebra_of_isAlgebraic_left [Algebra.IsAlgebraic K E1] : (E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := by have := sup_toSubalgebra_of_isAlgebraic_right E2 E1 rwa [sup_comm (a := E1), sup_comm (a := E1.toSubalgebra)] /-- The compositum of two intermediate fields is equal to the compositum of them as subalgebras, if one of them is algebraic over the base field. -/ theorem sup_toSubalgebra_of_isAlgebraic (halg : Algebra.IsAlgebraic K E1 ∨ Algebra.IsAlgebraic K E2) : (E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := halg.elim (fun _ ↦ sup_toSubalgebra_of_isAlgebraic_left E1 E2) (fun _ ↦ sup_toSubalgebra_of_isAlgebraic_right E1 E2) theorem sup_toSubalgebra_of_left [FiniteDimensional K E1] : (E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := sup_toSubalgebra_of_isAlgebraic_left E1 E2 #align intermediate_field.sup_to_subalgebra IntermediateField.sup_toSubalgebra_of_left @[deprecated (since := "2024-01-19")] alias sup_toSubalgebra := sup_toSubalgebra_of_left theorem sup_toSubalgebra_of_right [FiniteDimensional K E2] : (E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := sup_toSubalgebra_of_isAlgebraic_right E1 E2 instance finiteDimensional_sup [FiniteDimensional K E1] [FiniteDimensional K E2] : FiniteDimensional K (E1 ⊔ E2 : IntermediateField K L) := by let g := Algebra.TensorProduct.productMap E1.val E2.val suffices g.range = (E1 ⊔ E2).toSubalgebra by have h : FiniteDimensional K (Subalgebra.toSubmodule g.range) := g.toLinearMap.finiteDimensional_range rwa [this] at h rw [Algebra.TensorProduct.productMap_range, E1.range_val, E2.range_val, sup_toSubalgebra_of_left] #align intermediate_field.finite_dimensional_sup IntermediateField.finiteDimensional_sup variable {ι : Type*} {t : ι → IntermediateField K L} theorem coe_iSup_of_directed [Nonempty ι] (dir : Directed (· ≤ ·) t) : ↑(iSup t) = ⋃ i, (t i : Set L) := let M : IntermediateField K L := { __ := Subalgebra.copy _ _ (Subalgebra.coe_iSup_of_directed dir).symm inv_mem' := fun _ hx ↦ have ⟨i, hi⟩ := Set.mem_iUnion.mp hx Set.mem_iUnion.mpr ⟨i, (t i).inv_mem hi⟩ } have : iSup t = M := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (t i : Set L)) i) (Set.iUnion_subset fun _ ↦ le_iSup t _) this.symm ▸ rfl theorem toSubalgebra_iSup_of_directed (dir : Directed (· ≤ ·) t) : (iSup t).toSubalgebra = ⨆ i, (t i).toSubalgebra := by cases isEmpty_or_nonempty ι · simp_rw [iSup_of_empty, bot_toSubalgebra] · exact SetLike.ext' ((coe_iSup_of_directed dir).trans (Subalgebra.coe_iSup_of_directed dir).symm) instance finiteDimensional_iSup_of_finite [h : Finite ι] [∀ i, FiniteDimensional K (t i)] : FiniteDimensional K (⨆ i, t i : IntermediateField K L) := by rw [← iSup_univ] let P : Set ι → Prop := fun s => FiniteDimensional K (⨆ i ∈ s, t i : IntermediateField K L) change P Set.univ apply Set.Finite.induction_on all_goals dsimp only [P] · exact Set.finite_univ · rw [iSup_emptyset] exact (botEquiv K L).symm.toLinearEquiv.finiteDimensional · intro _ s _ _ hs rw [iSup_insert] exact IntermediateField.finiteDimensional_sup _ _ #align intermediate_field.finite_dimensional_supr_of_finite IntermediateField.finiteDimensional_iSup_of_finite instance finiteDimensional_iSup_of_finset /- Porting note: changed `h` from `∀ i ∈ s, FiniteDimensional K (t i)` because this caused an error. See `finiteDimensional_iSup_of_finset'` for a stronger version, that was the one used in mathlib3. -/ {s : Finset ι} [∀ i, FiniteDimensional K (t i)] : FiniteDimensional K (⨆ i ∈ s, t i : IntermediateField K L) := iSup_subtype'' s t ▸ IntermediateField.finiteDimensional_iSup_of_finite #align intermediate_field.finite_dimensional_supr_of_finset IntermediateField.finiteDimensional_iSup_of_finset theorem finiteDimensional_iSup_of_finset' /- Porting note: this was the mathlib3 version. Using `[h : ...]`, as in mathlib3, causes the error "invalid parametric local instance". -/ {s : Finset ι} (h : ∀ i ∈ s, FiniteDimensional K (t i)) : FiniteDimensional K (⨆ i ∈ s, t i : IntermediateField K L) := have := Subtype.forall'.mp h iSup_subtype'' s t ▸ IntermediateField.finiteDimensional_iSup_of_finite /-- A compositum of splitting fields is a splitting field -/ theorem isSplittingField_iSup {p : ι → K[X]} {s : Finset ι} (h0 : ∏ i ∈ s, p i ≠ 0) (h : ∀ i ∈ s, (p i).IsSplittingField K (t i)) : (∏ i ∈ s, p i).IsSplittingField K (⨆ i ∈ s, t i : IntermediateField K L) := by let F : IntermediateField K L := ⨆ i ∈ s, t i have hF : ∀ i ∈ s, t i ≤ F := fun i hi ↦ le_iSup_of_le i (le_iSup (fun _ ↦ t i) hi) simp only [isSplittingField_iff] at h ⊢ refine ⟨splits_prod (algebraMap K F) fun i hi ↦ splits_comp_of_splits (algebraMap K (t i)) (inclusion (hF i hi)).toRingHom (h i hi).1, ?_⟩ simp only [rootSet_prod p s h0, ← Set.iSup_eq_iUnion, (@gc K _ L _ _).l_iSup₂] exact iSup_congr fun i ↦ iSup_congr fun hi ↦ (h i hi).2 #align intermediate_field.is_splitting_field_supr IntermediateField.isSplittingField_iSup end Supremum section Tower variable (E) variable {K : Type*} [Field K] [Algebra F K] [Algebra E K] [IsScalarTower F E K] /-- If `K / E / F` is a field extension tower, `L` is an intermediate field of `K / F`, such that either `E / F` or `L / F` is algebraic, then `E(L) = E[L]`. -/ theorem adjoin_toSubalgebra_of_isAlgebraic (L : IntermediateField F K) (halg : Algebra.IsAlgebraic F E ∨ Algebra.IsAlgebraic F L) : (adjoin E (L : Set K)).toSubalgebra = Algebra.adjoin E (L : Set K) := by let i := IsScalarTower.toAlgHom F E K let E' := i.fieldRange let i' : E ≃ₐ[F] E' := AlgEquiv.ofInjectiveField i have hi : algebraMap E K = (algebraMap E' K) ∘ i' := by ext x; rfl apply_fun _ using Subalgebra.restrictScalars_injective F erw [← restrictScalars_toSubalgebra, restrictScalars_adjoin_of_algEquiv i' hi, Algebra.restrictScalars_adjoin_of_algEquiv i' hi, restrictScalars_adjoin, Algebra.restrictScalars_adjoin] exact E'.sup_toSubalgebra_of_isAlgebraic L (halg.imp (fun (_ : Algebra.IsAlgebraic F E) ↦ i'.isAlgebraic) id) theorem adjoin_toSubalgebra_of_isAlgebraic_left (L : IntermediateField F K) [halg : Algebra.IsAlgebraic F E] : (adjoin E (L : Set K)).toSubalgebra = Algebra.adjoin E (L : Set K) := adjoin_toSubalgebra_of_isAlgebraic E L (Or.inl halg) theorem adjoin_toSubalgebra_of_isAlgebraic_right (L : IntermediateField F K) [halg : Algebra.IsAlgebraic F L] : (adjoin E (L : Set K)).toSubalgebra = Algebra.adjoin E (L : Set K) := adjoin_toSubalgebra_of_isAlgebraic E L (Or.inr halg) /-- If `K / E / F` is a field extension tower, `L` is an intermediate field of `K / F`, such that either `E / F` or `L / F` is algebraic, then `[E(L) : E] ≤ [L : F]`. A corollary of `Subalgebra.adjoin_rank_le` since in this case `E(L) = E[L]`. -/ theorem adjoin_rank_le_of_isAlgebraic (L : IntermediateField F K) (halg : Algebra.IsAlgebraic F E ∨ Algebra.IsAlgebraic F L) : Module.rank E (adjoin E (L : Set K)) ≤ Module.rank F L := by have h : (adjoin E (L.toSubalgebra : Set K)).toSubalgebra = Algebra.adjoin E (L.toSubalgebra : Set K) := L.adjoin_toSubalgebra_of_isAlgebraic E halg have := L.toSubalgebra.adjoin_rank_le E rwa [(Subalgebra.equivOfEq _ _ h).symm.toLinearEquiv.rank_eq] at this theorem adjoin_rank_le_of_isAlgebraic_left (L : IntermediateField F K) [halg : Algebra.IsAlgebraic F E] : Module.rank E (adjoin E (L : Set K)) ≤ Module.rank F L := adjoin_rank_le_of_isAlgebraic E L (Or.inl halg) theorem adjoin_rank_le_of_isAlgebraic_right (L : IntermediateField F K) [halg : Algebra.IsAlgebraic F L] : Module.rank E (adjoin E (L : Set K)) ≤ Module.rank F L := adjoin_rank_le_of_isAlgebraic E L (Or.inr halg) end Tower open Set CompleteLattice /- Porting note: this was tagged `simp`, but the LHS can be simplified now that the notation has been improved. -/ theorem adjoin_simple_le_iff {K : IntermediateField F E} : F⟮α⟯ ≤ K ↔ α ∈ K := by simp #align intermediate_field.adjoin_simple_le_iff IntermediateField.adjoin_simple_le_iff theorem biSup_adjoin_simple : ⨆ x ∈ S, F⟮x⟯ = adjoin F S := by rw [← iSup_subtype'', ← gc.l_iSup, iSup_subtype'']; congr; exact S.biUnion_of_singleton /-- Adjoining a single element is compact in the lattice of intermediate fields. -/ theorem adjoin_simple_isCompactElement (x : E) : IsCompactElement F⟮x⟯ := by simp_rw [isCompactElement_iff_le_of_directed_sSup_le, adjoin_simple_le_iff, sSup_eq_iSup', ← exists_prop] intro s hne hs hx have := hne.to_subtype rwa [← SetLike.mem_coe, coe_iSup_of_directed hs.directed_val, mem_iUnion, Subtype.exists] at hx #align intermediate_field.adjoin_simple_is_compact_element IntermediateField.adjoin_simple_isCompactElement -- Porting note: original proof times out. /-- Adjoining a finite subset is compact in the lattice of intermediate fields. -/ theorem adjoin_finset_isCompactElement (S : Finset E) : IsCompactElement (adjoin F S : IntermediateField F E) := by rw [← biSup_adjoin_simple] simp_rw [Finset.mem_coe, ← Finset.sup_eq_iSup] exact isCompactElement_finsetSup S fun x _ => adjoin_simple_isCompactElement x #align intermediate_field.adjoin_finset_is_compact_element IntermediateField.adjoin_finset_isCompactElement /-- Adjoining a finite subset is compact in the lattice of intermediate fields. -/ theorem adjoin_finite_isCompactElement {S : Set E} (h : S.Finite) : IsCompactElement (adjoin F S) := Finite.coe_toFinset h ▸ adjoin_finset_isCompactElement h.toFinset #align intermediate_field.adjoin_finite_is_compact_element IntermediateField.adjoin_finite_isCompactElement /-- The lattice of intermediate fields is compactly generated. -/ instance : IsCompactlyGenerated (IntermediateField F E) := ⟨fun s => ⟨(fun x => F⟮x⟯) '' s, ⟨by rintro t ⟨x, _, rfl⟩; exact adjoin_simple_isCompactElement x, sSup_image.trans <| (biSup_adjoin_simple _).trans <| le_antisymm (adjoin_le_iff.mpr le_rfl) <| subset_adjoin F (s : Set E)⟩⟩⟩ theorem exists_finset_of_mem_iSup {ι : Type*} {f : ι → IntermediateField F E} {x : E} (hx : x ∈ ⨆ i, f i) : ∃ s : Finset ι, x ∈ ⨆ i ∈ s, f i := by have := (adjoin_simple_isCompactElement x).exists_finset_of_le_iSup (IntermediateField F E) f simp only [adjoin_simple_le_iff] at this exact this hx #align intermediate_field.exists_finset_of_mem_supr IntermediateField.exists_finset_of_mem_iSup theorem exists_finset_of_mem_supr' {ι : Type*} {f : ι → IntermediateField F E} {x : E} (hx : x ∈ ⨆ i, f i) : ∃ s : Finset (Σ i, f i), x ∈ ⨆ i ∈ s, F⟮(i.2 : E)⟯ := by -- Porting note: writing `fun i x h => ...` does not work. refine exists_finset_of_mem_iSup (SetLike.le_def.mp (iSup_le fun i ↦ ?_) hx) exact fun x h ↦ SetLike.le_def.mp (le_iSup_of_le ⟨i, x, h⟩ (by simp)) (mem_adjoin_simple_self F x) #align intermediate_field.exists_finset_of_mem_supr' IntermediateField.exists_finset_of_mem_supr' theorem exists_finset_of_mem_supr'' {ι : Type*} {f : ι → IntermediateField F E} (h : ∀ i, Algebra.IsAlgebraic F (f i)) {x : E} (hx : x ∈ ⨆ i, f i) : ∃ s : Finset (Σ i, f i), x ∈ ⨆ i ∈ s, adjoin F ((minpoly F (i.2 : _)).rootSet E) := by -- Porting note: writing `fun i x1 hx1 => ...` does not work. refine exists_finset_of_mem_iSup (SetLike.le_def.mp (iSup_le (fun i => ?_)) hx) intro x1 hx1 refine SetLike.le_def.mp (le_iSup_of_le ⟨i, x1, hx1⟩ ?_) (subset_adjoin F (rootSet (minpoly F x1) E) ?_) · rw [IntermediateField.minpoly_eq, Subtype.coe_mk] · rw [mem_rootSet_of_ne, minpoly.aeval] exact minpoly.ne_zero (isIntegral_iff.mp (Algebra.IsIntegral.isIntegral (⟨x1, hx1⟩ : f i))) #align intermediate_field.exists_finset_of_mem_supr'' IntermediateField.exists_finset_of_mem_supr'' theorem exists_finset_of_mem_adjoin {S : Set E} {x : E} (hx : x ∈ adjoin F S) : ∃ T : Finset E, (T : Set E) ⊆ S ∧ x ∈ adjoin F (T : Set E) := by simp_rw [← biSup_adjoin_simple S, ← iSup_subtype''] at hx obtain ⟨s, hx'⟩ := exists_finset_of_mem_iSup hx refine ⟨s.image Subtype.val, by simp, SetLike.le_def.mp ?_ hx'⟩ simp_rw [Finset.coe_image, iSup_le_iff, adjoin_le_iff] rintro _ h _ rfl exact subset_adjoin F _ ⟨_, h, rfl⟩ end AdjoinSimple end AdjoinDef section AdjoinIntermediateFieldLattice variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] {α : E} {S : Set E} @[simp] theorem adjoin_eq_bot_iff : adjoin F S = ⊥ ↔ S ⊆ (⊥ : IntermediateField F E) := by rw [eq_bot_iff, adjoin_le_iff]; rfl #align intermediate_field.adjoin_eq_bot_iff IntermediateField.adjoin_eq_bot_iff /- Porting note: this was tagged `simp`. -/ theorem adjoin_simple_eq_bot_iff : F⟮α⟯ = ⊥ ↔ α ∈ (⊥ : IntermediateField F E) := by simp #align intermediate_field.adjoin_simple_eq_bot_iff IntermediateField.adjoin_simple_eq_bot_iff @[simp] theorem adjoin_zero : F⟮(0 : E)⟯ = ⊥ := adjoin_simple_eq_bot_iff.mpr (zero_mem ⊥) #align intermediate_field.adjoin_zero IntermediateField.adjoin_zero @[simp] theorem adjoin_one : F⟮(1 : E)⟯ = ⊥ := adjoin_simple_eq_bot_iff.mpr (one_mem ⊥) #align intermediate_field.adjoin_one IntermediateField.adjoin_one @[simp] theorem adjoin_intCast (n : ℤ) : F⟮(n : E)⟯ = ⊥ := by exact adjoin_simple_eq_bot_iff.mpr (intCast_mem ⊥ n) #align intermediate_field.adjoin_int IntermediateField.adjoin_intCast @[simp] theorem adjoin_natCast (n : ℕ) : F⟮(n : E)⟯ = ⊥ := adjoin_simple_eq_bot_iff.mpr (natCast_mem ⊥ n) #align intermediate_field.adjoin_nat IntermediateField.adjoin_natCast @[deprecated (since := "2024-04-05")] alias adjoin_int := adjoin_intCast @[deprecated (since := "2024-04-05")] alias adjoin_nat := adjoin_natCast section AdjoinRank open FiniteDimensional Module variable {K L : IntermediateField F E} @[simp]
Mathlib/FieldTheory/Adjoin.lean
968
970
theorem rank_eq_one_iff : Module.rank F K = 1 ↔ K = ⊥ := by
rw [← toSubalgebra_eq_iff, ← rank_eq_rank_subalgebra, Subalgebra.rank_eq_one_iff, bot_toSubalgebra]
/- Copyright (c) 2022 Tian Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tian Chen, Mantas Bakšys -/ import Mathlib.Algebra.GeomSum import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Int import Mathlib.NumberTheory.Padics.PadicVal import Mathlib.RingTheory.Ideal.Quotient #align_import number_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Multiplicity in Number Theory This file contains results in number theory relating to multiplicity. ## Main statements * `multiplicity.Int.pow_sub_pow` is the lifting the exponent lemma for odd primes. We also prove several variations of the lemma. ## References * [Wikipedia, *Lifting-the-exponent lemma*] (https://en.wikipedia.org/wiki/Lifting-the-exponent_lemma) -/ open Ideal Ideal.Quotient Finset variable {R : Type*} {n : ℕ} section CommRing variable [CommRing R] {a b x y : R}
Mathlib/NumberTheory/Multiplicity.lean
39
43
theorem dvd_geom_sum₂_iff_of_dvd_sub {x y p : R} (h : p ∣ x - y) : (p ∣ ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) ↔ p ∣ n * y ^ (n - 1) := by
rw [← mem_span_singleton, ← Ideal.Quotient.eq] at h simp only [← mem_span_singleton, ← eq_zero_iff_mem, RingHom.map_geom_sum₂, h, geom_sum₂_self, _root_.map_mul, map_pow, map_natCast]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot -/ import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Algebra.Order.Interval.Set.Monoid import Mathlib.Data.Set.Pointwise.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax #align_import data.set.pointwise.interval from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # (Pre)images of intervals In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`, then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove lemmas about preimages and images of all intervals. We also prove a few lemmas about images under `x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`. -/ open Interval Pointwise variable {α : Type*} namespace Set /-! ### Binary pointwise operations Note that the subset operations below only cover the cases with the largest possible intervals on the LHS: to conclude that `Ioo a b * Ioo c d ⊆ Ioo (a * c) (c * d)`, you can use monotonicity of `*` and `Set.Ico_mul_Ioc_subset`. TODO: repeat these lemmas for the generality of `mul_le_mul` (which assumes nonnegativity), which the unprimed names have been reserved for -/ section ContravariantLE variable [Mul α] [Preorder α] variable [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (Function.swap HMul.hMul) LE.le] @[to_additive Icc_add_Icc_subset] theorem Icc_mul_Icc_subset' (a b c d : α) : Icc a b * Icc c d ⊆ Icc (a * c) (b * d) := by rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_le_mul' hyb hzd⟩ @[to_additive Iic_add_Iic_subset] theorem Iic_mul_Iic_subset' (a b : α) : Iic a * Iic b ⊆ Iic (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb @[to_additive Ici_add_Ici_subset] theorem Ici_mul_Ici_subset' (a b : α) : Ici a * Ici b ⊆ Ici (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb end ContravariantLE section ContravariantLT variable [Mul α] [PartialOrder α] variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (Function.swap HMul.hMul) LT.lt] @[to_additive Icc_add_Ico_subset] theorem Icc_mul_Ico_subset' (a b c d : α) : Icc a b * Ico c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Icc_subset] theorem Ico_mul_Icc_subset' (a b c d : α) : Ico a b * Icc c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Ioc_add_Ico_subset] theorem Ioc_mul_Ico_subset' (a b c d : α) : Ioc a b * Ico c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_lt_of_le hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Ioc_subset] theorem Ico_mul_Ioc_subset' (a b c d : α) : Ico a b * Ioc c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_le_of_lt hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Iic_add_Iio_subset] theorem Iic_mul_Iio_subset' (a b : α) : Iic a * Iio b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb @[to_additive Iio_add_Iic_subset] theorem Iio_mul_Iic_subset' (a b : α) : Iio a * Iic b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ioi_add_Ici_subset] theorem Ioi_mul_Ici_subset' (a b : α) : Ioi a * Ici b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ici_add_Ioi_subset] theorem Ici_mul_Ioi_subset' (a b : α) : Ici a * Ioi b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb end ContravariantLT section OrderedAddCommGroup variable [OrderedAddCommGroup α] (a b c : α) /-! ### Preimages under `x ↦ a + x` -/ @[simp] theorem preimage_const_add_Ici : (fun x => a + x) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add'.symm #align set.preimage_const_add_Ici Set.preimage_const_add_Ici @[simp] theorem preimage_const_add_Ioi : (fun x => a + x) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add'.symm #align set.preimage_const_add_Ioi Set.preimage_const_add_Ioi @[simp] theorem preimage_const_add_Iic : (fun x => a + x) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le'.symm #align set.preimage_const_add_Iic Set.preimage_const_add_Iic @[simp] theorem preimage_const_add_Iio : (fun x => a + x) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt'.symm #align set.preimage_const_add_Iio Set.preimage_const_add_Iio @[simp] theorem preimage_const_add_Icc : (fun x => a + x) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_const_add_Icc Set.preimage_const_add_Icc @[simp] theorem preimage_const_add_Ico : (fun x => a + x) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_const_add_Ico Set.preimage_const_add_Ico @[simp] theorem preimage_const_add_Ioc : (fun x => a + x) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_const_add_Ioc Set.preimage_const_add_Ioc @[simp] theorem preimage_const_add_Ioo : (fun x => a + x) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_const_add_Ioo Set.preimage_const_add_Ioo /-! ### Preimages under `x ↦ x + a` -/ @[simp] theorem preimage_add_const_Ici : (fun x => x + a) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add.symm #align set.preimage_add_const_Ici Set.preimage_add_const_Ici @[simp] theorem preimage_add_const_Ioi : (fun x => x + a) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add.symm #align set.preimage_add_const_Ioi Set.preimage_add_const_Ioi @[simp] theorem preimage_add_const_Iic : (fun x => x + a) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le.symm #align set.preimage_add_const_Iic Set.preimage_add_const_Iic @[simp] theorem preimage_add_const_Iio : (fun x => x + a) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt.symm #align set.preimage_add_const_Iio Set.preimage_add_const_Iio @[simp] theorem preimage_add_const_Icc : (fun x => x + a) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_add_const_Icc Set.preimage_add_const_Icc @[simp] theorem preimage_add_const_Ico : (fun x => x + a) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_add_const_Ico Set.preimage_add_const_Ico @[simp] theorem preimage_add_const_Ioc : (fun x => x + a) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_add_const_Ioc Set.preimage_add_const_Ioc @[simp] theorem preimage_add_const_Ioo : (fun x => x + a) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_add_const_Ioo Set.preimage_add_const_Ioo /-! ### Preimages under `x ↦ -x` -/ @[simp] theorem preimage_neg_Ici : -Ici a = Iic (-a) := ext fun _x => le_neg #align set.preimage_neg_Ici Set.preimage_neg_Ici @[simp] theorem preimage_neg_Iic : -Iic a = Ici (-a) := ext fun _x => neg_le #align set.preimage_neg_Iic Set.preimage_neg_Iic @[simp] theorem preimage_neg_Ioi : -Ioi a = Iio (-a) := ext fun _x => lt_neg #align set.preimage_neg_Ioi Set.preimage_neg_Ioi @[simp] theorem preimage_neg_Iio : -Iio a = Ioi (-a) := ext fun _x => neg_lt #align set.preimage_neg_Iio Set.preimage_neg_Iio @[simp] theorem preimage_neg_Icc : -Icc a b = Icc (-b) (-a) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_neg_Icc Set.preimage_neg_Icc @[simp] theorem preimage_neg_Ico : -Ico a b = Ioc (-b) (-a) := by simp [← Ici_inter_Iio, ← Ioi_inter_Iic, inter_comm] #align set.preimage_neg_Ico Set.preimage_neg_Ico @[simp] theorem preimage_neg_Ioc : -Ioc a b = Ico (-b) (-a) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_neg_Ioc Set.preimage_neg_Ioc @[simp] theorem preimage_neg_Ioo : -Ioo a b = Ioo (-b) (-a) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_neg_Ioo Set.preimage_neg_Ioo /-! ### Preimages under `x ↦ x - a` -/ @[simp] theorem preimage_sub_const_Ici : (fun x => x - a) ⁻¹' Ici b = Ici (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ici Set.preimage_sub_const_Ici @[simp] theorem preimage_sub_const_Ioi : (fun x => x - a) ⁻¹' Ioi b = Ioi (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioi Set.preimage_sub_const_Ioi @[simp] theorem preimage_sub_const_Iic : (fun x => x - a) ⁻¹' Iic b = Iic (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iic Set.preimage_sub_const_Iic @[simp] theorem preimage_sub_const_Iio : (fun x => x - a) ⁻¹' Iio b = Iio (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iio Set.preimage_sub_const_Iio @[simp] theorem preimage_sub_const_Icc : (fun x => x - a) ⁻¹' Icc b c = Icc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Icc Set.preimage_sub_const_Icc @[simp] theorem preimage_sub_const_Ico : (fun x => x - a) ⁻¹' Ico b c = Ico (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ico Set.preimage_sub_const_Ico @[simp] theorem preimage_sub_const_Ioc : (fun x => x - a) ⁻¹' Ioc b c = Ioc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioc Set.preimage_sub_const_Ioc @[simp] theorem preimage_sub_const_Ioo : (fun x => x - a) ⁻¹' Ioo b c = Ioo (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioo Set.preimage_sub_const_Ioo /-! ### Preimages under `x ↦ a - x` -/ @[simp] theorem preimage_const_sub_Ici : (fun x => a - x) ⁻¹' Ici b = Iic (a - b) := ext fun _x => le_sub_comm #align set.preimage_const_sub_Ici Set.preimage_const_sub_Ici @[simp] theorem preimage_const_sub_Iic : (fun x => a - x) ⁻¹' Iic b = Ici (a - b) := ext fun _x => sub_le_comm #align set.preimage_const_sub_Iic Set.preimage_const_sub_Iic @[simp] theorem preimage_const_sub_Ioi : (fun x => a - x) ⁻¹' Ioi b = Iio (a - b) := ext fun _x => lt_sub_comm #align set.preimage_const_sub_Ioi Set.preimage_const_sub_Ioi @[simp] theorem preimage_const_sub_Iio : (fun x => a - x) ⁻¹' Iio b = Ioi (a - b) := ext fun _x => sub_lt_comm #align set.preimage_const_sub_Iio Set.preimage_const_sub_Iio @[simp] theorem preimage_const_sub_Icc : (fun x => a - x) ⁻¹' Icc b c = Icc (a - c) (a - b) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_const_sub_Icc Set.preimage_const_sub_Icc @[simp] theorem preimage_const_sub_Ico : (fun x => a - x) ⁻¹' Ico b c = Ioc (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ico Set.preimage_const_sub_Ico @[simp] theorem preimage_const_sub_Ioc : (fun x => a - x) ⁻¹' Ioc b c = Ico (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioc Set.preimage_const_sub_Ioc @[simp] theorem preimage_const_sub_Ioo : (fun x => a - x) ⁻¹' Ioo b c = Ioo (a - c) (a - b) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioo Set.preimage_const_sub_Ioo /-! ### Images under `x ↦ a + x` -/ -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iic : (fun x => a + x) '' Iic b = Iic (a + b) := by simp [add_comm] #align set.image_const_add_Iic Set.image_const_add_Iic -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iio : (fun x => a + x) '' Iio b = Iio (a + b) := by simp [add_comm] #align set.image_const_add_Iio Set.image_const_add_Iio /-! ### Images under `x ↦ x + a` -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iic : (fun x => x + a) '' Iic b = Iic (b + a) := by simp #align set.image_add_const_Iic Set.image_add_const_Iic -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iio : (fun x => x + a) '' Iio b = Iio (b + a) := by simp #align set.image_add_const_Iio Set.image_add_const_Iio /-! ### Images under `x ↦ -x` -/ theorem image_neg_Ici : Neg.neg '' Ici a = Iic (-a) := by simp #align set.image_neg_Ici Set.image_neg_Ici theorem image_neg_Iic : Neg.neg '' Iic a = Ici (-a) := by simp #align set.image_neg_Iic Set.image_neg_Iic theorem image_neg_Ioi : Neg.neg '' Ioi a = Iio (-a) := by simp #align set.image_neg_Ioi Set.image_neg_Ioi theorem image_neg_Iio : Neg.neg '' Iio a = Ioi (-a) := by simp #align set.image_neg_Iio Set.image_neg_Iio theorem image_neg_Icc : Neg.neg '' Icc a b = Icc (-b) (-a) := by simp #align set.image_neg_Icc Set.image_neg_Icc theorem image_neg_Ico : Neg.neg '' Ico a b = Ioc (-b) (-a) := by simp #align set.image_neg_Ico Set.image_neg_Ico theorem image_neg_Ioc : Neg.neg '' Ioc a b = Ico (-b) (-a) := by simp #align set.image_neg_Ioc Set.image_neg_Ioc theorem image_neg_Ioo : Neg.neg '' Ioo a b = Ioo (-b) (-a) := by simp #align set.image_neg_Ioo Set.image_neg_Ioo /-! ### Images under `x ↦ a - x` -/ @[simp] theorem image_const_sub_Ici : (fun x => a - x) '' Ici b = Iic (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ici Set.image_const_sub_Ici @[simp] theorem image_const_sub_Iic : (fun x => a - x) '' Iic b = Ici (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iic Set.image_const_sub_Iic @[simp] theorem image_const_sub_Ioi : (fun x => a - x) '' Ioi b = Iio (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioi Set.image_const_sub_Ioi @[simp] theorem image_const_sub_Iio : (fun x => a - x) '' Iio b = Ioi (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iio Set.image_const_sub_Iio @[simp] theorem image_const_sub_Icc : (fun x => a - x) '' Icc b c = Icc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Icc Set.image_const_sub_Icc @[simp] theorem image_const_sub_Ico : (fun x => a - x) '' Ico b c = Ioc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ico Set.image_const_sub_Ico @[simp] theorem image_const_sub_Ioc : (fun x => a - x) '' Ioc b c = Ico (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioc Set.image_const_sub_Ioc @[simp] theorem image_const_sub_Ioo : (fun x => a - x) '' Ioo b c = Ioo (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioo Set.image_const_sub_Ioo /-! ### Images under `x ↦ x - a` -/ @[simp] theorem image_sub_const_Ici : (fun x => x - a) '' Ici b = Ici (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ici Set.image_sub_const_Ici @[simp] theorem image_sub_const_Iic : (fun x => x - a) '' Iic b = Iic (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iic Set.image_sub_const_Iic @[simp] theorem image_sub_const_Ioi : (fun x => x - a) '' Ioi b = Ioi (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioi Set.image_sub_const_Ioi @[simp] theorem image_sub_const_Iio : (fun x => x - a) '' Iio b = Iio (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iio Set.image_sub_const_Iio @[simp] theorem image_sub_const_Icc : (fun x => x - a) '' Icc b c = Icc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Icc Set.image_sub_const_Icc @[simp] theorem image_sub_const_Ico : (fun x => x - a) '' Ico b c = Ico (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ico Set.image_sub_const_Ico @[simp] theorem image_sub_const_Ioc : (fun x => x - a) '' Ioc b c = Ioc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioc Set.image_sub_const_Ioc @[simp] theorem image_sub_const_Ioo : (fun x => x - a) '' Ioo b c = Ioo (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioo Set.image_sub_const_Ioo /-! ### Bijections -/ theorem Iic_add_bij : BijOn (· + a) (Iic b) (Iic (b + a)) := image_add_const_Iic a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iic_add_bij Set.Iic_add_bij theorem Iio_add_bij : BijOn (· + a) (Iio b) (Iio (b + a)) := image_add_const_Iio a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iio_add_bij Set.Iio_add_bij end OrderedAddCommGroup section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup α] (a b c d : α) @[simp] theorem preimage_const_add_uIcc : (fun x => a + x) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simp only [← Icc_min_max, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right] #align set.preimage_const_add_uIcc Set.preimage_const_add_uIcc @[simp] theorem preimage_add_const_uIcc : (fun x => x + a) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simpa only [add_comm] using preimage_const_add_uIcc a b c #align set.preimage_add_const_uIcc Set.preimage_add_const_uIcc -- TODO: Why is the notation `-[[a, b]]` broken? @[simp] theorem preimage_neg_uIcc : @Neg.neg (Set α) Set.neg [[a, b]] = [[-a, -b]] := by simp only [← Icc_min_max, preimage_neg_Icc, min_neg_neg, max_neg_neg] #align set.preimage_neg_uIcc Set.preimage_neg_uIcc @[simp] theorem preimage_sub_const_uIcc : (fun x => x - a) ⁻¹' [[b, c]] = [[b + a, c + a]] := by simp [sub_eq_add_neg] #align set.preimage_sub_const_uIcc Set.preimage_sub_const_uIcc @[simp] theorem preimage_const_sub_uIcc : (fun x => a - x) ⁻¹' [[b, c]] = [[a - b, a - c]] := by simp_rw [← Icc_min_max, preimage_const_sub_Icc] simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg] #align set.preimage_const_sub_uIcc Set.preimage_const_sub_uIcc -- @[simp] -- Porting note (#10618): simp can prove this module `add_comm` theorem image_const_add_uIcc : (fun x => a + x) '' [[b, c]] = [[a + b, a + c]] := by simp [add_comm] #align set.image_const_add_uIcc Set.image_const_add_uIcc -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_uIcc : (fun x => x + a) '' [[b, c]] = [[b + a, c + a]] := by simp #align set.image_add_const_uIcc Set.image_add_const_uIcc @[simp] theorem image_const_sub_uIcc : (fun x => a - x) '' [[b, c]] = [[a - b, a - c]] := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_uIcc Set.image_const_sub_uIcc @[simp] theorem image_sub_const_uIcc : (fun x => x - a) '' [[b, c]] = [[b - a, c - a]] := by simp [sub_eq_add_neg, add_comm] #align set.image_sub_const_uIcc Set.image_sub_const_uIcc theorem image_neg_uIcc : Neg.neg '' [[a, b]] = [[-a, -b]] := by simp #align set.image_neg_uIcc Set.image_neg_uIcc variable {a b c d} /-- If `[c, d]` is a subinterval of `[a, b]`, then the distance between `c` and `d` is less than or equal to that of `a` and `b` -/ theorem abs_sub_le_of_uIcc_subset_uIcc (h : [[c, d]] ⊆ [[a, b]]) : |d - c| ≤ |b - a| := by rw [← max_sub_min_eq_abs, ← max_sub_min_eq_abs] rw [uIcc_subset_uIcc_iff_le] at h exact sub_le_sub h.2 h.1 #align set.abs_sub_le_of_uIcc_subset_uIcc Set.abs_sub_le_of_uIcc_subset_uIcc /-- If `c ∈ [a, b]`, then the distance between `a` and `c` is less than or equal to that of `a` and `b` -/ theorem abs_sub_left_of_mem_uIcc (h : c ∈ [[a, b]]) : |c - a| ≤ |b - a| := abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc_left h #align set.abs_sub_left_of_mem_uIcc Set.abs_sub_left_of_mem_uIcc /-- If `x ∈ [a, b]`, then the distance between `c` and `b` is less than or equal to that of `a` and `b` -/ theorem abs_sub_right_of_mem_uIcc (h : c ∈ [[a, b]]) : |b - c| ≤ |b - a| := abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc_right h #align set.abs_sub_right_of_mem_uIcc Set.abs_sub_right_of_mem_uIcc end LinearOrderedAddCommGroup /-! ### Multiplication and inverse in a field -/ section LinearOrderedField variable [LinearOrderedField α] {a : α} @[simp] theorem preimage_mul_const_Iio (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Iio a = Iio (a / c) := ext fun _x => (lt_div_iff h).symm #align set.preimage_mul_const_Iio Set.preimage_mul_const_Iio @[simp] theorem preimage_mul_const_Ioi (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ioi a = Ioi (a / c) := ext fun _x => (div_lt_iff h).symm #align set.preimage_mul_const_Ioi Set.preimage_mul_const_Ioi @[simp] theorem preimage_mul_const_Iic (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Iic a = Iic (a / c) := ext fun _x => (le_div_iff h).symm #align set.preimage_mul_const_Iic Set.preimage_mul_const_Iic @[simp] theorem preimage_mul_const_Ici (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ici a = Ici (a / c) := ext fun _x => (div_le_iff h).symm #align set.preimage_mul_const_Ici Set.preimage_mul_const_Ici @[simp] theorem preimage_mul_const_Ioo (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ioo a b = Ioo (a / c) (b / c) := by simp [← Ioi_inter_Iio, h] #align set.preimage_mul_const_Ioo Set.preimage_mul_const_Ioo @[simp] theorem preimage_mul_const_Ioc (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ioc a b = Ioc (a / c) (b / c) := by simp [← Ioi_inter_Iic, h] #align set.preimage_mul_const_Ioc Set.preimage_mul_const_Ioc @[simp] theorem preimage_mul_const_Ico (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ico a b = Ico (a / c) (b / c) := by simp [← Ici_inter_Iio, h] #align set.preimage_mul_const_Ico Set.preimage_mul_const_Ico @[simp]
Mathlib/Data/Set/Pointwise/Interval.lean
634
635
theorem preimage_mul_const_Icc (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Icc a b = Icc (a / c) (b / c) := by
simp [← Ici_inter_Iic, h]
/- 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, Bhavik Mehta, Andrew Yang, Emily Riehl -/ import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts #align_import category_theory.limits.shapes.pullbacks from "leanprover-community/mathlib"@"7316286ff2942aa14e540add9058c6b0aa1c8070" /-! # Pullbacks We define a category `WalkingCospan` (resp. `WalkingSpan`), which is the index category for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g` and `span f g` construct functors from the walking (co)span, hitting the given morphisms. We define `pullback f g` and `pushout f g` as limits and colimits of such functors. ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits -- attribute [local tidy] tactic.case_bash Porting note: no tidy, no local /-- The type of objects for the diagram indexing a pullback, defined as a special case of `WidePullbackShape`. -/ abbrev WalkingCospan : Type := WidePullbackShape WalkingPair #align category_theory.limits.walking_cospan CategoryTheory.Limits.WalkingCospan /-- The left point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.left : WalkingCospan := some WalkingPair.left #align category_theory.limits.walking_cospan.left CategoryTheory.Limits.WalkingCospan.left /-- The right point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.right : WalkingCospan := some WalkingPair.right #align category_theory.limits.walking_cospan.right CategoryTheory.Limits.WalkingCospan.right /-- The central point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.one : WalkingCospan := none #align category_theory.limits.walking_cospan.one CategoryTheory.Limits.WalkingCospan.one /-- The type of objects for the diagram indexing a pushout, defined as a special case of `WidePushoutShape`. -/ abbrev WalkingSpan : Type := WidePushoutShape WalkingPair #align category_theory.limits.walking_span CategoryTheory.Limits.WalkingSpan /-- The left point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.left : WalkingSpan := some WalkingPair.left #align category_theory.limits.walking_span.left CategoryTheory.Limits.WalkingSpan.left /-- The right point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.right : WalkingSpan := some WalkingPair.right #align category_theory.limits.walking_span.right CategoryTheory.Limits.WalkingSpan.right /-- The central point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.zero : WalkingSpan := none #align category_theory.limits.walking_span.zero CategoryTheory.Limits.WalkingSpan.zero namespace WalkingCospan /-- The type of arrows for the diagram indexing a pullback. -/ abbrev Hom : WalkingCospan → WalkingCospan → Type := WidePullbackShape.Hom #align category_theory.limits.walking_cospan.hom CategoryTheory.Limits.WalkingCospan.Hom /-- The left arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inl : left ⟶ one := WidePullbackShape.Hom.term _ #align category_theory.limits.walking_cospan.hom.inl CategoryTheory.Limits.WalkingCospan.Hom.inl /-- The right arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inr : right ⟶ one := WidePullbackShape.Hom.term _ #align category_theory.limits.walking_cospan.hom.inr CategoryTheory.Limits.WalkingCospan.Hom.inr /-- The identity arrows of the walking cospan. -/ @[match_pattern] abbrev Hom.id (X : WalkingCospan) : X ⟶ X := WidePullbackShape.Hom.id X #align category_theory.limits.walking_cospan.hom.id CategoryTheory.Limits.WalkingCospan.Hom.id instance (X Y : WalkingCospan) : Subsingleton (X ⟶ Y) := by constructor; intros; simp [eq_iff_true_of_subsingleton] end WalkingCospan namespace WalkingSpan /-- The type of arrows for the diagram indexing a pushout. -/ abbrev Hom : WalkingSpan → WalkingSpan → Type := WidePushoutShape.Hom #align category_theory.limits.walking_span.hom CategoryTheory.Limits.WalkingSpan.Hom /-- The left arrow of the walking span. -/ @[match_pattern] abbrev Hom.fst : zero ⟶ left := WidePushoutShape.Hom.init _ #align category_theory.limits.walking_span.hom.fst CategoryTheory.Limits.WalkingSpan.Hom.fst /-- The right arrow of the walking span. -/ @[match_pattern] abbrev Hom.snd : zero ⟶ right := WidePushoutShape.Hom.init _ #align category_theory.limits.walking_span.hom.snd CategoryTheory.Limits.WalkingSpan.Hom.snd /-- The identity arrows of the walking span. -/ @[match_pattern] abbrev Hom.id (X : WalkingSpan) : X ⟶ X := WidePushoutShape.Hom.id X #align category_theory.limits.walking_span.hom.id CategoryTheory.Limits.WalkingSpan.Hom.id instance (X Y : WalkingSpan) : Subsingleton (X ⟶ Y) := by constructor; intros a b; simp [eq_iff_true_of_subsingleton] end WalkingSpan open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] /-- To construct an isomorphism of cones over the walking cospan, it suffices to construct an isomorphism of the cone points and check it commutes with the legs to `left` and `right`. -/ def WalkingCospan.ext {F : WalkingCospan ⥤ C} {s t : Cone F} (i : s.pt ≅ t.pt) (w₁ : s.π.app WalkingCospan.left = i.hom ≫ t.π.app WalkingCospan.left) (w₂ : s.π.app WalkingCospan.right = i.hom ≫ t.π.app WalkingCospan.right) : s ≅ t := by apply Cones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.π.naturality WalkingCospan.Hom.inl dsimp at h₁ simp only [Category.id_comp] at h₁ have h₂ := t.π.naturality WalkingCospan.Hom.inl dsimp at h₂ simp only [Category.id_comp] at h₂ simp_rw [h₂, ← Category.assoc, ← w₁, ← h₁] · exact w₁ · exact w₂ #align category_theory.limits.walking_cospan.ext CategoryTheory.Limits.WalkingCospan.ext /-- To construct an isomorphism of cocones over the walking span, it suffices to construct an isomorphism of the cocone points and check it commutes with the legs from `left` and `right`. -/ def WalkingSpan.ext {F : WalkingSpan ⥤ C} {s t : Cocone F} (i : s.pt ≅ t.pt) (w₁ : s.ι.app WalkingCospan.left ≫ i.hom = t.ι.app WalkingCospan.left) (w₂ : s.ι.app WalkingCospan.right ≫ i.hom = t.ι.app WalkingCospan.right) : s ≅ t := by apply Cocones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.ι.naturality WalkingSpan.Hom.fst dsimp at h₁ simp only [Category.comp_id] at h₁ have h₂ := t.ι.naturality WalkingSpan.Hom.fst dsimp at h₂ simp only [Category.comp_id] at h₂ simp_rw [← h₁, Category.assoc, w₁, h₂] · exact w₁ · exact w₂ #align category_theory.limits.walking_span.ext CategoryTheory.Limits.WalkingSpan.ext /-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/ def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : WalkingCospan ⥤ C := WidePullbackShape.wideCospan Z (fun j => WalkingPair.casesOn j X Y) fun j => WalkingPair.casesOn j f g #align category_theory.limits.cospan CategoryTheory.Limits.cospan /-- `span f g` is the functor from the walking span hitting `f` and `g`. -/ def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : WalkingSpan ⥤ C := WidePushoutShape.wideSpan X (fun j => WalkingPair.casesOn j Y Z) fun j => WalkingPair.casesOn j f g #align category_theory.limits.span CategoryTheory.Limits.span @[simp] theorem cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.left = X := rfl #align category_theory.limits.cospan_left CategoryTheory.Limits.cospan_left @[simp] theorem span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.left = Y := rfl #align category_theory.limits.span_left CategoryTheory.Limits.span_left @[simp] theorem cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.right = Y := rfl #align category_theory.limits.cospan_right CategoryTheory.Limits.cospan_right @[simp] theorem span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.right = Z := rfl #align category_theory.limits.span_right CategoryTheory.Limits.span_right @[simp] theorem cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.one = Z := rfl #align category_theory.limits.cospan_one CategoryTheory.Limits.cospan_one @[simp] theorem span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.zero = X := rfl #align category_theory.limits.span_zero CategoryTheory.Limits.span_zero @[simp] theorem cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inl = f := rfl #align category_theory.limits.cospan_map_inl CategoryTheory.Limits.cospan_map_inl @[simp] theorem span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.fst = f := rfl #align category_theory.limits.span_map_fst CategoryTheory.Limits.span_map_fst @[simp] theorem cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inr = g := rfl #align category_theory.limits.cospan_map_inr CategoryTheory.Limits.cospan_map_inr @[simp] theorem span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.snd = g := rfl #align category_theory.limits.span_map_snd CategoryTheory.Limits.span_map_snd theorem cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : WalkingCospan) : (cospan f g).map (WalkingCospan.Hom.id w) = 𝟙 _ := rfl #align category_theory.limits.cospan_map_id CategoryTheory.Limits.cospan_map_id theorem span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : WalkingSpan) : (span f g).map (WalkingSpan.Hom.id w) = 𝟙 _ := rfl #align category_theory.limits.span_map_id CategoryTheory.Limits.span_map_id /-- Every diagram indexing a pullback is naturally isomorphic (actually, equal) to a `cospan` -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] def diagramIsoCospan (F : WalkingCospan ⥤ C) : F ≅ cospan (F.map inl) (F.map inr) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.diagram_iso_cospan CategoryTheory.Limits.diagramIsoCospan /-- Every diagram indexing a pushout is naturally isomorphic (actually, equal) to a `span` -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] def diagramIsoSpan (F : WalkingSpan ⥤ C) : F ≅ span (F.map fst) (F.map snd) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.diagram_iso_span CategoryTheory.Limits.diagramIsoSpan variable {D : Type u₂} [Category.{v₂} D] /-- A functor applied to a cospan is a cospan. -/ def cospanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : cospan f g ⋙ F ≅ cospan (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.cospan_comp_iso CategoryTheory.Limits.cospanCompIso section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) @[simp] theorem cospanCompIso_app_left : (cospanCompIso F f g).app WalkingCospan.left = Iso.refl _ := rfl #align category_theory.limits.cospan_comp_iso_app_left CategoryTheory.Limits.cospanCompIso_app_left @[simp] theorem cospanCompIso_app_right : (cospanCompIso F f g).app WalkingCospan.right = Iso.refl _ := rfl #align category_theory.limits.cospan_comp_iso_app_right CategoryTheory.Limits.cospanCompIso_app_right @[simp] theorem cospanCompIso_app_one : (cospanCompIso F f g).app WalkingCospan.one = Iso.refl _ := rfl #align category_theory.limits.cospan_comp_iso_app_one CategoryTheory.Limits.cospanCompIso_app_one @[simp] theorem cospanCompIso_hom_app_left : (cospanCompIso F f g).hom.app WalkingCospan.left = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_hom_app_left CategoryTheory.Limits.cospanCompIso_hom_app_left @[simp] theorem cospanCompIso_hom_app_right : (cospanCompIso F f g).hom.app WalkingCospan.right = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_hom_app_right CategoryTheory.Limits.cospanCompIso_hom_app_right @[simp] theorem cospanCompIso_hom_app_one : (cospanCompIso F f g).hom.app WalkingCospan.one = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_hom_app_one CategoryTheory.Limits.cospanCompIso_hom_app_one @[simp] theorem cospanCompIso_inv_app_left : (cospanCompIso F f g).inv.app WalkingCospan.left = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_inv_app_left CategoryTheory.Limits.cospanCompIso_inv_app_left @[simp] theorem cospanCompIso_inv_app_right : (cospanCompIso F f g).inv.app WalkingCospan.right = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_inv_app_right CategoryTheory.Limits.cospanCompIso_inv_app_right @[simp] theorem cospanCompIso_inv_app_one : (cospanCompIso F f g).inv.app WalkingCospan.one = 𝟙 _ := rfl #align category_theory.limits.cospan_comp_iso_inv_app_one CategoryTheory.Limits.cospanCompIso_inv_app_one end /-- A functor applied to a span is a span. -/ def spanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : span f g ⋙ F ≅ span (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) #align category_theory.limits.span_comp_iso CategoryTheory.Limits.spanCompIso section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) @[simp] theorem spanCompIso_app_left : (spanCompIso F f g).app WalkingSpan.left = Iso.refl _ := rfl #align category_theory.limits.span_comp_iso_app_left CategoryTheory.Limits.spanCompIso_app_left @[simp] theorem spanCompIso_app_right : (spanCompIso F f g).app WalkingSpan.right = Iso.refl _ := rfl #align category_theory.limits.span_comp_iso_app_right CategoryTheory.Limits.spanCompIso_app_right @[simp] theorem spanCompIso_app_zero : (spanCompIso F f g).app WalkingSpan.zero = Iso.refl _ := rfl #align category_theory.limits.span_comp_iso_app_zero CategoryTheory.Limits.spanCompIso_app_zero @[simp] theorem spanCompIso_hom_app_left : (spanCompIso F f g).hom.app WalkingSpan.left = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_hom_app_left CategoryTheory.Limits.spanCompIso_hom_app_left @[simp] theorem spanCompIso_hom_app_right : (spanCompIso F f g).hom.app WalkingSpan.right = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_hom_app_right CategoryTheory.Limits.spanCompIso_hom_app_right @[simp] theorem spanCompIso_hom_app_zero : (spanCompIso F f g).hom.app WalkingSpan.zero = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_hom_app_zero CategoryTheory.Limits.spanCompIso_hom_app_zero @[simp] theorem spanCompIso_inv_app_left : (spanCompIso F f g).inv.app WalkingSpan.left = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_inv_app_left CategoryTheory.Limits.spanCompIso_inv_app_left @[simp] theorem spanCompIso_inv_app_right : (spanCompIso F f g).inv.app WalkingSpan.right = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_inv_app_right CategoryTheory.Limits.spanCompIso_inv_app_right @[simp] theorem spanCompIso_inv_app_zero : (spanCompIso F f g).inv.app WalkingSpan.zero = 𝟙 _ := rfl #align category_theory.limits.span_comp_iso_inv_app_zero CategoryTheory.Limits.spanCompIso_inv_app_zero end section variable {X Y Z X' Y' Z' : C} (iX : X ≅ X') (iY : Y ≅ Y') (iZ : Z ≅ Z') section variable {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} /-- Construct an isomorphism of cospans from components. -/ def cospanExt (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) : cospan f g ≅ cospan f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iZ, iX, iY]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp [wf, wg]) #align category_theory.limits.cospan_ext CategoryTheory.Limits.cospanExt variable (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem cospanExt_app_left : (cospanExt iX iY iZ wf wg).app WalkingCospan.left = iX := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_app_left CategoryTheory.Limits.cospanExt_app_left @[simp] theorem cospanExt_app_right : (cospanExt iX iY iZ wf wg).app WalkingCospan.right = iY := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_app_right CategoryTheory.Limits.cospanExt_app_right @[simp] theorem cospanExt_app_one : (cospanExt iX iY iZ wf wg).app WalkingCospan.one = iZ := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_app_one CategoryTheory.Limits.cospanExt_app_one @[simp] theorem cospanExt_hom_app_left : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.left = iX.hom := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_hom_app_left CategoryTheory.Limits.cospanExt_hom_app_left @[simp] theorem cospanExt_hom_app_right : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.right = iY.hom := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_hom_app_right CategoryTheory.Limits.cospanExt_hom_app_right @[simp] theorem cospanExt_hom_app_one : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.one = iZ.hom := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_hom_app_one CategoryTheory.Limits.cospanExt_hom_app_one @[simp] theorem cospanExt_inv_app_left : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.left = iX.inv := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_inv_app_left CategoryTheory.Limits.cospanExt_inv_app_left @[simp] theorem cospanExt_inv_app_right : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.right = iY.inv := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_inv_app_right CategoryTheory.Limits.cospanExt_inv_app_right @[simp] theorem cospanExt_inv_app_one : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.one = iZ.inv := by dsimp [cospanExt] #align category_theory.limits.cospan_ext_inv_app_one CategoryTheory.Limits.cospanExt_inv_app_one end section variable {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'} /-- Construct an isomorphism of spans from components. -/ def spanExt (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) : span f g ≅ span f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iX, iY, iZ]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp [wf, wg]) #align category_theory.limits.span_ext CategoryTheory.Limits.spanExt variable (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem spanExt_app_left : (spanExt iX iY iZ wf wg).app WalkingSpan.left = iY := by dsimp [spanExt] #align category_theory.limits.span_ext_app_left CategoryTheory.Limits.spanExt_app_left @[simp] theorem spanExt_app_right : (spanExt iX iY iZ wf wg).app WalkingSpan.right = iZ := by dsimp [spanExt] #align category_theory.limits.span_ext_app_right CategoryTheory.Limits.spanExt_app_right @[simp] theorem spanExt_app_one : (spanExt iX iY iZ wf wg).app WalkingSpan.zero = iX := by dsimp [spanExt] #align category_theory.limits.span_ext_app_one CategoryTheory.Limits.spanExt_app_one @[simp] theorem spanExt_hom_app_left : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.left = iY.hom := by dsimp [spanExt] #align category_theory.limits.span_ext_hom_app_left CategoryTheory.Limits.spanExt_hom_app_left @[simp] theorem spanExt_hom_app_right : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.right = iZ.hom := by dsimp [spanExt] #align category_theory.limits.span_ext_hom_app_right CategoryTheory.Limits.spanExt_hom_app_right @[simp] theorem spanExt_hom_app_zero : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.zero = iX.hom := by dsimp [spanExt] #align category_theory.limits.span_ext_hom_app_zero CategoryTheory.Limits.spanExt_hom_app_zero @[simp] theorem spanExt_inv_app_left : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.left = iY.inv := by dsimp [spanExt] #align category_theory.limits.span_ext_inv_app_left CategoryTheory.Limits.spanExt_inv_app_left @[simp] theorem spanExt_inv_app_right : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.right = iZ.inv := by dsimp [spanExt] #align category_theory.limits.span_ext_inv_app_right CategoryTheory.Limits.spanExt_inv_app_right @[simp] theorem spanExt_inv_app_zero : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.zero = iX.inv := by dsimp [spanExt] #align category_theory.limits.span_ext_inv_app_zero CategoryTheory.Limits.spanExt_inv_app_zero end end variable {W X Y Z : C} /-- A pullback cone is just a cone on the cospan formed by two morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`. -/ abbrev PullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) := Cone (cospan f g) #align category_theory.limits.pullback_cone CategoryTheory.Limits.PullbackCone namespace PullbackCone variable {f : X ⟶ Z} {g : Y ⟶ Z} /-- The first projection of a pullback cone. -/ abbrev fst (t : PullbackCone f g) : t.pt ⟶ X := t.π.app WalkingCospan.left #align category_theory.limits.pullback_cone.fst CategoryTheory.Limits.PullbackCone.fst /-- The second projection of a pullback cone. -/ abbrev snd (t : PullbackCone f g) : t.pt ⟶ Y := t.π.app WalkingCospan.right #align category_theory.limits.pullback_cone.snd CategoryTheory.Limits.PullbackCone.snd @[simp] theorem π_app_left (c : PullbackCone f g) : c.π.app WalkingCospan.left = c.fst := rfl #align category_theory.limits.pullback_cone.π_app_left CategoryTheory.Limits.PullbackCone.π_app_left @[simp] theorem π_app_right (c : PullbackCone f g) : c.π.app WalkingCospan.right = c.snd := rfl #align category_theory.limits.pullback_cone.π_app_right CategoryTheory.Limits.PullbackCone.π_app_right @[simp] theorem condition_one (t : PullbackCone f g) : t.π.app WalkingCospan.one = t.fst ≫ f := by have w := t.π.naturality WalkingCospan.Hom.inl dsimp at w; simpa using w #align category_theory.limits.pullback_cone.condition_one CategoryTheory.Limits.PullbackCone.condition_one /-- This is a slightly more convenient method to verify that a pullback cone is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : PullbackCone f g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ t.pt) (fac_left : ∀ s : PullbackCone f g, lift s ≫ t.fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ t.snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ t.pt) (_ : ∀ j : WalkingCospan, m ≫ t.π.app j = s.π.app j), m = lift s) : IsLimit t := { lift fac := fun s j => Option.casesOn j (by rw [← s.w inl, ← t.w inl, ← Category.assoc] congr exact fac_left s) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } #align category_theory.limits.pullback_cone.is_limit_aux CategoryTheory.Limits.PullbackCone.isLimitAux /-- This is another convenient method to verify that a pullback cone is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def isLimitAux' (t : PullbackCone f g) (create : ∀ s : PullbackCone f g, { l // l ≫ t.fst = s.fst ∧ l ≫ t.snd = s.snd ∧ ∀ {m}, m ≫ t.fst = s.fst → m ≫ t.snd = s.snd → m = l }) : Limits.IsLimit t := PullbackCone.isLimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pullback_cone.is_limit_aux' CategoryTheory.Limits.PullbackCone.isLimitAux' /-- A pullback cone on `f` and `g` is determined by morphisms `fst : W ⟶ X` and `snd : W ⟶ Y` such that `fst ≫ f = snd ≫ g`. -/ @[simps] def mk {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : PullbackCone f g where pt := W π := { app := fun j => Option.casesOn j (fst ≫ f) fun j' => WalkingPair.casesOn j' fst snd naturality := by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) j <;> cases j <;> dsimp <;> simp [eq] } #align category_theory.limits.pullback_cone.mk CategoryTheory.Limits.PullbackCone.mk @[simp] theorem mk_π_app_left {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.left = fst := rfl #align category_theory.limits.pullback_cone.mk_π_app_left CategoryTheory.Limits.PullbackCone.mk_π_app_left @[simp] theorem mk_π_app_right {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.right = snd := rfl #align category_theory.limits.pullback_cone.mk_π_app_right CategoryTheory.Limits.PullbackCone.mk_π_app_right @[simp] theorem mk_π_app_one {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.one = fst ≫ f := rfl #align category_theory.limits.pullback_cone.mk_π_app_one CategoryTheory.Limits.PullbackCone.mk_π_app_one @[simp] theorem mk_fst {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).fst = fst := rfl #align category_theory.limits.pullback_cone.mk_fst CategoryTheory.Limits.PullbackCone.mk_fst @[simp] theorem mk_snd {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).snd = snd := rfl #align category_theory.limits.pullback_cone.mk_snd CategoryTheory.Limits.PullbackCone.mk_snd @[reassoc] theorem condition (t : PullbackCone f g) : fst t ≫ f = snd t ≫ g := (t.w inl).trans (t.w inr).symm #align category_theory.limits.pullback_cone.condition CategoryTheory.Limits.PullbackCone.condition /-- To check whether a morphism is equalized by the maps of a pullback cone, it suffices to check it for `fst t` and `snd t` -/ theorem equalizer_ext (t : PullbackCone f g) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : ∀ j : WalkingCospan, k ≫ t.π.app j = l ≫ t.π.app j | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w inl, reassoc_of% h₀] #align category_theory.limits.pullback_cone.equalizer_ext CategoryTheory.Limits.PullbackCone.equalizer_ext theorem IsLimit.hom_ext {t : PullbackCone f g} (ht : IsLimit t) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : k = l := ht.hom_ext <| equalizer_ext _ h₀ h₁ #align category_theory.limits.pullback_cone.is_limit.hom_ext CategoryTheory.Limits.PullbackCone.IsLimit.hom_ext theorem mono_snd_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono f] : Mono t.snd := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht ?_ i⟩ rw [← cancel_mono f, Category.assoc, Category.assoc, condition] have := congrArg (· ≫ g) i; dsimp at this rwa [Category.assoc, Category.assoc] at this #align category_theory.limits.pullback_cone.mono_snd_of_is_pullback_of_mono CategoryTheory.Limits.PullbackCone.mono_snd_of_is_pullback_of_mono theorem mono_fst_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono g] : Mono t.fst := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht i ?_⟩ rw [← cancel_mono g, Category.assoc, Category.assoc, ← condition] have := congrArg (· ≫ f) i; dsimp at this rwa [Category.assoc, Category.assoc] at this #align category_theory.limits.pullback_cone.mono_fst_of_is_pullback_of_mono CategoryTheory.Limits.PullbackCone.mono_fst_of_is_pullback_of_mono /-- To construct an isomorphism of pullback cones, it suffices to construct an isomorphism of the cone points and check it commutes with `fst` and `snd`. -/ def ext {s t : PullbackCone f g} (i : s.pt ≅ t.pt) (w₁ : s.fst = i.hom ≫ t.fst) (w₂ : s.snd = i.hom ≫ t.snd) : s ≅ t := WalkingCospan.ext i w₁ w₂ #align category_theory.limits.pullback_cone.ext CategoryTheory.Limits.PullbackCone.ext -- Porting note: `IsLimit.lift` and the two following simp lemmas were introduced to ease the port /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we get `l : W ⟶ t.pt`, which satisfies `l ≫ fst t = h` and `l ≫ snd t = k`, see `IsLimit.lift_fst` and `IsLimit.lift_snd`. -/ def IsLimit.lift {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ t.pt := ht.lift <| PullbackCone.mk _ _ w @[reassoc (attr := simp)] lemma IsLimit.lift_fst {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ fst t = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsLimit.lift_snd {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ snd t = k := ht.fac _ _ /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we have `l : W ⟶ t.pt` satisfying `l ≫ fst t = h` and `l ≫ snd t = k`. -/ def IsLimit.lift' {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ t.pt // l ≫ fst t = h ∧ l ≫ snd t = k } := ⟨IsLimit.lift ht h k w, by simp⟩ #align category_theory.limits.pullback_cone.is_limit.lift' CategoryTheory.Limits.PullbackCone.IsLimit.lift' /-- This is a more convenient formulation to show that a `PullbackCone` constructed using `PullbackCone.mk` is a limit cone. -/ def IsLimit.mk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (eq : fst ≫ f = snd ≫ g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ W) (fac_left : ∀ s : PullbackCone f g, lift s ≫ fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (mk fst snd eq) := isLimitAux _ lift fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pullback_cone.is_limit.mk CategoryTheory.Limits.PullbackCone.IsLimit.mk section Flip variable (t : PullbackCone f g) /-- The pullback cone obtained by flipping `fst` and `snd`. -/ def flip : PullbackCone g f := PullbackCone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_fst : t.flip.fst = t.snd := rfl @[simp] lemma flip_snd : t.flip.snd = t.fst := rfl /-- Flipping a pullback cone twice gives an isomorphic cone. -/ def flipFlipIso : t.flip.flip ≅ t := PullbackCone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pullback square is a pullback square. -/ def flipIsLimit (ht : IsLimit t) : IsLimit t.flip := IsLimit.mk _ (fun s => ht.lift s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsLimit.hom_ext ht all_goals aesop_cat) /-- A square is a pullback square if its flip is. -/ def isLimitOfFlip (ht : IsLimit t.flip) : IsLimit t := IsLimit.ofIsoLimit (flipIsLimit ht) t.flipFlipIso #align category_theory.limits.pullback_cone.flip_is_limit CategoryTheory.Limits.PullbackCone.isLimitOfFlip end Flip /-- The pullback cone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a limit if `f` is a mono. The converse is shown in `mono_of_pullback_is_id`. -/ def isLimitMkIdId (f : X ⟶ Y) [Mono f] : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f) := IsLimit.mk _ (fun s => s.fst) (fun s => Category.comp_id _) (fun s => by rw [← cancel_mono f, Category.comp_id, s.condition]) fun s m m₁ _ => by simpa using m₁ #align category_theory.limits.pullback_cone.is_limit_mk_id_id CategoryTheory.Limits.PullbackCone.isLimitMkIdId /-- `f` is a mono if the pullback cone `(𝟙 X, 𝟙 X)` is a limit for the pair `(f, f)`. The converse is given in `PullbackCone.is_id_of_mono`. -/ theorem mono_of_isLimitMkIdId (f : X ⟶ Y) (t : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f)) : Mono f := ⟨fun {Z} g h eq => by rcases PullbackCone.IsLimit.lift' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ #align category_theory.limits.pullback_cone.mono_of_is_limit_mk_id_id CategoryTheory.Limits.PullbackCone.mono_of_isLimitMkIdId /-- Suppose `f` and `g` are two morphisms with a common codomain and `s` is a limit cone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through a monomorphism `h` via `x` and `y`, respectively. Then `s` is also a limit cone over the diagram formed by `x` and `y`. -/ def isLimitOfFactors (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ Z) [Mono h] (x : X ⟶ W) (y : Y ⟶ W) (hxh : x ≫ h = f) (hyh : y ≫ h = g) (s : PullbackCone f g) (hs : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ x = s.snd ≫ y from (cancel_mono h).1 <| by simp only [Category.assoc, hxh, hyh, s.condition])) := PullbackCone.isLimitAux' _ fun t => have : fst t ≫ x ≫ h = snd t ≫ y ≫ h := by -- Porting note: reassoc workaround rw [← Category.assoc, ← Category.assoc] apply congrArg (· ≫ h) t.condition ⟨hs.lift (PullbackCone.mk t.fst t.snd <| by rw [← hxh, ← hyh, this]), ⟨hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right, fun hr hr' => by apply PullbackCone.IsLimit.hom_ext hs <;> simp only [PullbackCone.mk_fst, PullbackCone.mk_snd] at hr hr' ⊢ <;> simp only [hr, hr'] <;> symm exacts [hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right]⟩⟩ #align category_theory.limits.pullback_cone.is_limit_of_factors CategoryTheory.Limits.PullbackCone.isLimitOfFactors /-- If `W` is the pullback of `f, g`, it is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/ def isLimitOfCompMono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] (s : PullbackCone f g) (H : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ f ≫ i = s.snd ≫ g ≫ i by rw [← Category.assoc, ← Category.assoc, s.condition])) := by apply PullbackCone.isLimitAux' intro s rcases PullbackCone.IsLimit.lift' H s.fst s.snd ((cancel_mono i).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PullbackCone.IsLimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _) #align category_theory.limits.pullback_cone.is_limit_of_comp_mono CategoryTheory.Limits.PullbackCone.isLimitOfCompMono end PullbackCone /-- A pushout cocone is just a cocone on the span formed by two morphisms `f : X ⟶ Y` and `g : X ⟶ Z`. -/ abbrev PushoutCocone (f : X ⟶ Y) (g : X ⟶ Z) := Cocone (span f g) #align category_theory.limits.pushout_cocone CategoryTheory.Limits.PushoutCocone namespace PushoutCocone variable {f : X ⟶ Y} {g : X ⟶ Z} /-- The first inclusion of a pushout cocone. -/ abbrev inl (t : PushoutCocone f g) : Y ⟶ t.pt := t.ι.app WalkingSpan.left #align category_theory.limits.pushout_cocone.inl CategoryTheory.Limits.PushoutCocone.inl /-- The second inclusion of a pushout cocone. -/ abbrev inr (t : PushoutCocone f g) : Z ⟶ t.pt := t.ι.app WalkingSpan.right #align category_theory.limits.pushout_cocone.inr CategoryTheory.Limits.PushoutCocone.inr @[simp] theorem ι_app_left (c : PushoutCocone f g) : c.ι.app WalkingSpan.left = c.inl := rfl #align category_theory.limits.pushout_cocone.ι_app_left CategoryTheory.Limits.PushoutCocone.ι_app_left @[simp] theorem ι_app_right (c : PushoutCocone f g) : c.ι.app WalkingSpan.right = c.inr := rfl #align category_theory.limits.pushout_cocone.ι_app_right CategoryTheory.Limits.PushoutCocone.ι_app_right @[simp] theorem condition_zero (t : PushoutCocone f g) : t.ι.app WalkingSpan.zero = f ≫ t.inl := by have w := t.ι.naturality WalkingSpan.Hom.fst dsimp at w; simpa using w.symm #align category_theory.limits.pushout_cocone.condition_zero CategoryTheory.Limits.PushoutCocone.condition_zero /-- This is a slightly more convenient method to verify that a pushout cocone is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def isColimitAux (t : PushoutCocone f g) (desc : ∀ s : PushoutCocone f g, t.pt ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, t.inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, t.inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : t.pt ⟶ s.pt) (_ : ∀ j : WalkingSpan, t.ι.app j ≫ m = s.ι.app j), m = desc s) : IsColimit t := { desc fac := fun s j => Option.casesOn j (by simp [← s.w fst, ← t.w fst, fac_left s]) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } #align category_theory.limits.pushout_cocone.is_colimit_aux CategoryTheory.Limits.PushoutCocone.isColimitAux /-- This is another convenient method to verify that a pushout cocone is a colimit cocone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def isColimitAux' (t : PushoutCocone f g) (create : ∀ s : PushoutCocone f g, { l // t.inl ≫ l = s.inl ∧ t.inr ≫ l = s.inr ∧ ∀ {m}, t.inl ≫ m = s.inl → t.inr ≫ m = s.inr → m = l }) : IsColimit t := isColimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pushout_cocone.is_colimit_aux' CategoryTheory.Limits.PushoutCocone.isColimitAux' /-- A pushout cocone on `f` and `g` is determined by morphisms `inl : Y ⟶ W` and `inr : Z ⟶ W` such that `f ≫ inl = g ↠ inr`. -/ @[simps] def mk {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : PushoutCocone f g where pt := W ι := { app := fun j => Option.casesOn j (f ≫ inl) fun j' => WalkingPair.casesOn j' inl inr naturality := by rintro (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) <;> intro f <;> cases f <;> dsimp <;> aesop } #align category_theory.limits.pushout_cocone.mk CategoryTheory.Limits.PushoutCocone.mk @[simp] theorem mk_ι_app_left {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.left = inl := rfl #align category_theory.limits.pushout_cocone.mk_ι_app_left CategoryTheory.Limits.PushoutCocone.mk_ι_app_left @[simp] theorem mk_ι_app_right {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.right = inr := rfl #align category_theory.limits.pushout_cocone.mk_ι_app_right CategoryTheory.Limits.PushoutCocone.mk_ι_app_right @[simp] theorem mk_ι_app_zero {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.zero = f ≫ inl := rfl #align category_theory.limits.pushout_cocone.mk_ι_app_zero CategoryTheory.Limits.PushoutCocone.mk_ι_app_zero @[simp] theorem mk_inl {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inl = inl := rfl #align category_theory.limits.pushout_cocone.mk_inl CategoryTheory.Limits.PushoutCocone.mk_inl @[simp] theorem mk_inr {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inr = inr := rfl #align category_theory.limits.pushout_cocone.mk_inr CategoryTheory.Limits.PushoutCocone.mk_inr @[reassoc] theorem condition (t : PushoutCocone f g) : f ≫ inl t = g ≫ inr t := (t.w fst).trans (t.w snd).symm #align category_theory.limits.pushout_cocone.condition CategoryTheory.Limits.PushoutCocone.condition /-- To check whether a morphism is coequalized by the maps of a pushout cocone, it suffices to check it for `inl t` and `inr t` -/ theorem coequalizer_ext (t : PushoutCocone f g) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : ∀ j : WalkingSpan, t.ι.app j ≫ k = t.ι.app j ≫ l | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w fst, Category.assoc, Category.assoc, h₀] #align category_theory.limits.pushout_cocone.coequalizer_ext CategoryTheory.Limits.PushoutCocone.coequalizer_ext theorem IsColimit.hom_ext {t : PushoutCocone f g} (ht : IsColimit t) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : k = l := ht.hom_ext <| coequalizer_ext _ h₀ h₁ #align category_theory.limits.pushout_cocone.is_colimit.hom_ext CategoryTheory.Limits.PushoutCocone.IsColimit.hom_ext -- Porting note: `IsColimit.desc` and the two following simp lemmas were introduced to ease the port /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`, see `IsColimit.inl_desc` and `IsColimit.inr_desc`-/ def IsColimit.desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : t.pt ⟶ W := ht.desc (PushoutCocone.mk _ _ w) @[reassoc (attr := simp)] lemma IsColimit.inl_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inl t ≫ IsColimit.desc ht h k w = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsColimit.inr_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inr t ≫ IsColimit.desc ht h k w = k := ht.fac _ _ /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`. -/ def IsColimit.desc' {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : t.pt ⟶ W // inl t ≫ l = h ∧ inr t ≫ l = k } := ⟨IsColimit.desc ht h k w, by simp⟩ #align category_theory.limits.pushout_cocone.is_colimit.desc' CategoryTheory.Limits.PushoutCocone.IsColimit.desc' theorem epi_inr_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi f] : Epi t.inr := ⟨fun {W} h k i => IsColimit.hom_ext ht (by simp [← cancel_epi f, t.condition_assoc, i]) i⟩ #align category_theory.limits.pushout_cocone.epi_inr_of_is_pushout_of_epi CategoryTheory.Limits.PushoutCocone.epi_inr_of_is_pushout_of_epi theorem epi_inl_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi g] : Epi t.inl := ⟨fun {W} h k i => IsColimit.hom_ext ht i (by simp [← cancel_epi g, ← t.condition_assoc, i])⟩ #align category_theory.limits.pushout_cocone.epi_inl_of_is_pushout_of_epi CategoryTheory.Limits.PushoutCocone.epi_inl_of_is_pushout_of_epi /-- To construct an isomorphism of pushout cocones, it suffices to construct an isomorphism of the cocone points and check it commutes with `inl` and `inr`. -/ def ext {s t : PushoutCocone f g} (i : s.pt ≅ t.pt) (w₁ : s.inl ≫ i.hom = t.inl) (w₂ : s.inr ≫ i.hom = t.inr) : s ≅ t := WalkingSpan.ext i w₁ w₂ #align category_theory.limits.pushout_cocone.ext CategoryTheory.Limits.PushoutCocone.ext /-- This is a more convenient formulation to show that a `PushoutCocone` constructed using `PushoutCocone.mk` is a colimit cocone. -/ def IsColimit.mk {W : C} {inl : Y ⟶ W} {inr : Z ⟶ W} (eq : f ≫ inl = g ≫ inr) (desc : ∀ s : PushoutCocone f g, W ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (mk inl inr eq) := isColimitAux _ desc fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) #align category_theory.limits.pushout_cocone.is_colimit.mk CategoryTheory.Limits.PushoutCocone.IsColimit.mk section Flip variable (t : PushoutCocone f g) /-- The pushout cocone obtained by flipping `inl` and `inr`. -/ def flip : PushoutCocone g f := PushoutCocone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_inl : t.flip.inl = t.inr := rfl @[simp] lemma flip_inr : t.flip.inr = t.inl := rfl /-- Flipping a pushout cocone twice gives an isomorphic cocone. -/ def flipFlipIso : t.flip.flip ≅ t := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pushout square is a pushout square. -/ def flipIsColimit (ht : IsColimit t) : IsColimit t.flip := IsColimit.mk _ (fun s => ht.desc s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsColimit.hom_ext ht all_goals aesop_cat) /-- A square is a pushout square if its flip is. -/ def isColimitOfFlip (ht : IsColimit t.flip) : IsColimit t := IsColimit.ofIsoColimit (flipIsColimit ht) t.flipFlipIso #align category_theory.limits.pushout_cocone.flip_is_colimit CategoryTheory.Limits.PushoutCocone.isColimitOfFlip end Flip /-- The pushout cocone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a colimit if `f` is an epi. The converse is shown in `epi_of_isColimit_mk_id_id`. -/ def isColimitMkIdId (f : X ⟶ Y) [Epi f] : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f) := IsColimit.mk _ (fun s => s.inl) (fun s => Category.id_comp _) (fun s => by rw [← cancel_epi f, Category.id_comp, s.condition]) fun s m m₁ _ => by simpa using m₁ #align category_theory.limits.pushout_cocone.is_colimit_mk_id_id CategoryTheory.Limits.PushoutCocone.isColimitMkIdId /-- `f` is an epi if the pushout cocone `(𝟙 X, 𝟙 X)` is a colimit for the pair `(f, f)`. The converse is given in `PushoutCocone.isColimitMkIdId`. -/ theorem epi_of_isColimitMkIdId (f : X ⟶ Y) (t : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f)) : Epi f := ⟨fun {Z} g h eq => by rcases PushoutCocone.IsColimit.desc' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ #align category_theory.limits.pushout_cocone.epi_of_is_colimit_mk_id_id CategoryTheory.Limits.PushoutCocone.epi_of_isColimitMkIdId /-- Suppose `f` and `g` are two morphisms with a common domain and `s` is a colimit cocone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through an epimorphism `h` via `x` and `y`, respectively. Then `s` is also a colimit cocone over the diagram formed by `x` and `y`. -/ def isColimitOfFactors (f : X ⟶ Y) (g : X ⟶ Z) (h : X ⟶ W) [Epi h] (x : W ⟶ Y) (y : W ⟶ Z) (hhx : h ≫ x = f) (hhy : h ≫ y = g) (s : PushoutCocone f g) (hs : IsColimit s) : have reassoc₁ : h ≫ x ≫ inl s = f ≫ inl s := by -- Porting note: working around reassoc rw [← Category.assoc]; apply congrArg (· ≫ inl s) hhx have reassoc₂ : h ≫ y ≫ inr s = g ≫ inr s := by rw [← Category.assoc]; apply congrArg (· ≫ inr s) hhy IsColimit (PushoutCocone.mk _ _ (show x ≫ s.inl = y ≫ s.inr from (cancel_epi h).1 <| by rw [reassoc₁, reassoc₂, s.condition])) := PushoutCocone.isColimitAux' _ fun t => ⟨hs.desc (PushoutCocone.mk t.inl t.inr <| by rw [← hhx, ← hhy, Category.assoc, Category.assoc, t.condition]), ⟨hs.fac _ WalkingSpan.left, hs.fac _ WalkingSpan.right, fun hr hr' => by apply PushoutCocone.IsColimit.hom_ext hs; · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr, hr'] symm exact hs.fac _ WalkingSpan.left · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr, hr'] symm exact hs.fac _ WalkingSpan.right⟩⟩ #align category_theory.limits.pushout_cocone.is_colimit_of_factors CategoryTheory.Limits.PushoutCocone.isColimitOfFactors /-- If `W` is the pushout of `f, g`, it is also the pushout of `h ≫ f, h ≫ g` for any epi `h`. -/ def isColimitOfEpiComp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] (s : PushoutCocone f g) (H : IsColimit s) : IsColimit (PushoutCocone.mk _ _ (show (h ≫ f) ≫ s.inl = (h ≫ g) ≫ s.inr by rw [Category.assoc, Category.assoc, s.condition])) := by apply PushoutCocone.isColimitAux' intro s rcases PushoutCocone.IsColimit.desc' H s.inl s.inr ((cancel_epi h).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PushoutCocone.IsColimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _) #align category_theory.limits.pushout_cocone.is_colimit_of_epi_comp CategoryTheory.Limits.PushoutCocone.isColimitOfEpiComp end PushoutCocone /-- This is a helper construction that can be useful when verifying that a category has all pullbacks. Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a pullback cone on `F.map inl` and `F.map inr`, we get a cone on `F`. If you're thinking about using this, have a look at `hasPullbacks_of_hasLimit_cospan`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cone.ofPullbackCone {F : WalkingCospan ⥤ C} (t : PullbackCone (F.map inl) (F.map inr)) : Cone F where pt := t.pt π := t.π ≫ (diagramIsoCospan F).inv #align category_theory.limits.cone.of_pullback_cone CategoryTheory.Limits.Cone.ofPullbackCone /-- This is a helper construction that can be useful when verifying that a category has all pushout. Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a pushout cocone on `F.map fst` and `F.map snd`, we get a cocone on `F`. If you're thinking about using this, have a look at `hasPushouts_of_hasColimit_span`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cocone.ofPushoutCocone {F : WalkingSpan ⥤ C} (t : PushoutCocone (F.map fst) (F.map snd)) : Cocone F where pt := t.pt ι := (diagramIsoSpan F).hom ≫ t.ι #align category_theory.limits.cocone.of_pushout_cocone CategoryTheory.Limits.Cocone.ofPushoutCocone /-- Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a cone on `F`, we get a pullback cone on `F.map inl` and `F.map inr`. -/ @[simps] def PullbackCone.ofCone {F : WalkingCospan ⥤ C} (t : Cone F) : PullbackCone (F.map inl) (F.map inr) where pt := t.pt π := t.π ≫ (diagramIsoCospan F).hom #align category_theory.limits.pullback_cone.of_cone CategoryTheory.Limits.PullbackCone.ofCone /-- A diagram `WalkingCospan ⥤ C` is isomorphic to some `PullbackCone.mk` after composing with `diagramIsoCospan`. -/ @[simps!] def PullbackCone.isoMk {F : WalkingCospan ⥤ C} (t : Cone F) : (Cones.postcompose (diagramIsoCospan.{v} _).hom).obj t ≅ PullbackCone.mk (t.π.app WalkingCospan.left) (t.π.app WalkingCospan.right) ((t.π.naturality inl).symm.trans (t.π.naturality inr : _)) := Cones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> · dsimp simp #align category_theory.limits.pullback_cone.iso_mk CategoryTheory.Limits.PullbackCone.isoMk /-- Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a cocone on `F`, we get a pushout cocone on `F.map fst` and `F.map snd`. -/ @[simps] def PushoutCocone.ofCocone {F : WalkingSpan ⥤ C} (t : Cocone F) : PushoutCocone (F.map fst) (F.map snd) where pt := t.pt ι := (diagramIsoSpan F).inv ≫ t.ι #align category_theory.limits.pushout_cocone.of_cocone CategoryTheory.Limits.PushoutCocone.ofCocone /-- A diagram `WalkingSpan ⥤ C` is isomorphic to some `PushoutCocone.mk` after composing with `diagramIsoSpan`. -/ @[simps!] def PushoutCocone.isoMk {F : WalkingSpan ⥤ C} (t : Cocone F) : (Cocones.precompose (diagramIsoSpan.{v} _).inv).obj t ≅ PushoutCocone.mk (t.ι.app WalkingSpan.left) (t.ι.app WalkingSpan.right) ((t.ι.naturality fst).trans (t.ι.naturality snd).symm) := Cocones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> · dsimp simp #align category_theory.limits.pushout_cocone.iso_mk CategoryTheory.Limits.PushoutCocone.isoMk /-- `HasPullback f g` represents a particular choice of limiting cone for the pair of morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`. -/ abbrev HasPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) := HasLimit (cospan f g) #align category_theory.limits.has_pullback CategoryTheory.Limits.HasPullback /-- `HasPushout f g` represents a particular choice of colimiting cocone for the pair of morphisms `f : X ⟶ Y` and `g : X ⟶ Z`. -/ abbrev HasPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) := HasColimit (span f g) #align category_theory.limits.has_pushout CategoryTheory.Limits.HasPushout /-- `pullback f g` computes the pullback of a pair of morphisms with the same target. -/ abbrev pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] := limit (cospan f g) #align category_theory.limits.pullback CategoryTheory.Limits.pullback /-- `pushout f g` computes the pushout of a pair of morphisms with the same source. -/ abbrev pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] := colimit (span f g) #align category_theory.limits.pushout CategoryTheory.Limits.pushout /-- The first projection of the pullback of `f` and `g`. -/ abbrev pullback.fst {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback f g ⟶ X := limit.π (cospan f g) WalkingCospan.left #align category_theory.limits.pullback.fst CategoryTheory.Limits.pullback.fst /-- The second projection of the pullback of `f` and `g`. -/ abbrev pullback.snd {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback f g ⟶ Y := limit.π (cospan f g) WalkingCospan.right #align category_theory.limits.pullback.snd CategoryTheory.Limits.pullback.snd /-- The first inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inl {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : Y ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.left #align category_theory.limits.pushout.inl CategoryTheory.Limits.pushout.inl /-- The second inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inr {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : Z ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.right #align category_theory.limits.pushout.inr CategoryTheory.Limits.pushout.inr /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `pullback.lift : W ⟶ pullback f g`. -/ abbrev pullback.lift {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ pullback f g := limit.lift _ (PullbackCone.mk h k w) #align category_theory.limits.pullback.lift CategoryTheory.Limits.pullback.lift /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `pushout.desc : pushout f g ⟶ W`. -/ abbrev pushout.desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout f g ⟶ W := colimit.desc _ (PushoutCocone.mk h k w) #align category_theory.limits.pushout.desc CategoryTheory.Limits.pushout.desc @[simp] theorem PullbackCone.fst_colimit_cocone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.fst (limit.cone (cospan f g)) = pullback.fst := rfl #align category_theory.limits.pullback_cone.fst_colimit_cocone CategoryTheory.Limits.PullbackCone.fst_colimit_cocone @[simp] theorem PullbackCone.snd_colimit_cocone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.snd (limit.cone (cospan f g)) = pullback.snd := rfl #align category_theory.limits.pullback_cone.snd_colimit_cocone CategoryTheory.Limits.PullbackCone.snd_colimit_cocone -- Porting note (#10618): simp can prove this; removed simp theorem PushoutCocone.inl_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inl (colimit.cocone (span f g)) = pushout.inl := rfl #align category_theory.limits.pushout_cocone.inl_colimit_cocone CategoryTheory.Limits.PushoutCocone.inl_colimit_cocone -- Porting note (#10618): simp can prove this; removed simp theorem PushoutCocone.inr_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inr (colimit.cocone (span f g)) = pushout.inr := rfl #align category_theory.limits.pushout_cocone.inr_colimit_cocone CategoryTheory.Limits.PushoutCocone.inr_colimit_cocone -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pullback.lift_fst {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.fst = h := limit.lift_π _ _ #align category_theory.limits.pullback.lift_fst CategoryTheory.Limits.pullback.lift_fst -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pullback.lift_snd {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.snd = k := limit.lift_π _ _ #align category_theory.limits.pullback.lift_snd CategoryTheory.Limits.pullback.lift_snd -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pushout.inl_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inl ≫ pushout.desc h k w = h := colimit.ι_desc _ _ #align category_theory.limits.pushout.inl_desc CategoryTheory.Limits.pushout.inl_desc -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pushout.inr_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inr ≫ pushout.desc h k w = k := colimit.ι_desc _ _ #align category_theory.limits.pushout.inr_desc CategoryTheory.Limits.pushout.inr_desc /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `l : W ⟶ pullback f g` such that `l ≫ pullback.fst = h` and `l ≫ pullback.snd = k`. -/ def pullback.lift' {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ pullback f g // l ≫ pullback.fst = h ∧ l ≫ pullback.snd = k } := ⟨pullback.lift h k w, pullback.lift_fst _ _ _, pullback.lift_snd _ _ _⟩ #align category_theory.limits.pullback.lift' CategoryTheory.Limits.pullback.lift' /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `l : pushout f g ⟶ W` such that `pushout.inl ≫ l = h` and `pushout.inr ≫ l = k`. -/ def pullback.desc' {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : pushout f g ⟶ W // pushout.inl ≫ l = h ∧ pushout.inr ≫ l = k } := ⟨pushout.desc h k w, pushout.inl_desc _ _ _, pushout.inr_desc _ _ _⟩ #align category_theory.limits.pullback.desc' CategoryTheory.Limits.pullback.desc' @[reassoc] theorem pullback.condition {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : (pullback.fst : pullback f g ⟶ X) ≫ f = pullback.snd ≫ g := PullbackCone.condition _ #align category_theory.limits.pullback.condition CategoryTheory.Limits.pullback.condition @[reassoc] theorem pushout.condition {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : f ≫ (pushout.inl : Y ⟶ pushout f g) = g ≫ pushout.inr := PushoutCocone.condition _ #align category_theory.limits.pushout.condition CategoryTheory.Limits.pushout.condition /-- Given such a diagram, then there is a natural morphism `W ×ₛ X ⟶ Y ×ₜ Z`. W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z -/ abbrev pullback.map {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : pullback f₁ f₂ ⟶ pullback g₁ g₂ := pullback.lift (pullback.fst ≫ i₁) (pullback.snd ≫ i₂) (by simp [← eq₁, ← eq₂, pullback.condition_assoc]) #align category_theory.limits.pullback.map CategoryTheory.Limits.pullback.map /-- The canonical map `X ×ₛ Y ⟶ X ×ₜ Y` given `S ⟶ T`. -/ abbrev pullback.mapDesc {X Y S T : C} (f : X ⟶ S) (g : Y ⟶ S) (i : S ⟶ T) [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] : pullback f g ⟶ pullback (f ≫ i) (g ≫ i) := pullback.map f g (f ≫ i) (g ≫ i) (𝟙 _) (𝟙 _) i (Category.id_comp _).symm (Category.id_comp _).symm #align category_theory.limits.pullback.map_desc CategoryTheory.Limits.pullback.mapDesc /-- Given such a diagram, then there is a natural morphism `W ⨿ₛ X ⟶ Y ⨿ₜ Z`. W ⟶ Y ↗ ↗ S ⟶ T ↘ ↘ X ⟶ Z -/ abbrev pushout.map {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) : pushout f₁ f₂ ⟶ pushout g₁ g₂ := pushout.desc (i₁ ≫ pushout.inl) (i₂ ≫ pushout.inr) (by simp only [← Category.assoc, eq₁, eq₂] simp [pushout.condition]) #align category_theory.limits.pushout.map CategoryTheory.Limits.pushout.map /-- The canonical map `X ⨿ₛ Y ⟶ X ⨿ₜ Y` given `S ⟶ T`. -/ abbrev pushout.mapLift {X Y S T : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] : pushout (i ≫ f) (i ≫ g) ⟶ pushout f g := pushout.map (i ≫ f) (i ≫ g) f g (𝟙 _) (𝟙 _) i (Category.comp_id _) (Category.comp_id _) #align category_theory.limits.pushout.map_lift CategoryTheory.Limits.pushout.mapLift /-- Two morphisms into a pullback are equal if their compositions with the pullback morphisms are equal -/ @[ext 1100] theorem pullback.hom_ext {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] {W : C} {k l : W ⟶ pullback f g} (h₀ : k ≫ pullback.fst = l ≫ pullback.fst) (h₁ : k ≫ pullback.snd = l ≫ pullback.snd) : k = l := limit.hom_ext <| PullbackCone.equalizer_ext _ h₀ h₁ #align category_theory.limits.pullback.hom_ext CategoryTheory.Limits.pullback.hom_ext /-- The pullback cone built from the pullback projections is a pullback. -/ def pullbackIsPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsLimit (PullbackCone.mk (pullback.fst : pullback f g ⟶ _) pullback.snd pullback.condition) := PullbackCone.IsLimit.mk _ (fun s => pullback.lift s.fst s.snd s.condition) (by simp) (by simp) (by aesop_cat) #align category_theory.limits.pullback_is_pullback CategoryTheory.Limits.pullbackIsPullback /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.fst_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono g] : Mono (pullback.fst : pullback f g ⟶ X) := PullbackCone.mono_fst_of_is_pullback_of_mono (limit.isLimit _) #align category_theory.limits.pullback.fst_of_mono CategoryTheory.Limits.pullback.fst_of_mono /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.snd_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono f] : Mono (pullback.snd : pullback f g ⟶ Y) := PullbackCone.mono_snd_of_is_pullback_of_mono (limit.isLimit _) #align category_theory.limits.pullback.snd_of_mono CategoryTheory.Limits.pullback.snd_of_mono /-- The map `X ×[Z] Y ⟶ X × Y` is mono. -/ instance mono_pullback_to_prod {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasBinaryProduct X Y] : Mono (prod.lift pullback.fst pullback.snd : pullback f g ⟶ _) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => f ≫ prod.fst) h · simpa using congrArg (fun f => f ≫ prod.snd) h⟩ #align category_theory.limits.mono_pullback_to_prod CategoryTheory.Limits.mono_pullback_to_prod /-- Two morphisms out of a pushout are equal if their compositions with the pushout morphisms are equal -/ @[ext 1100] theorem pushout.hom_ext {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] {W : C} {k l : pushout f g ⟶ W} (h₀ : pushout.inl ≫ k = pushout.inl ≫ l) (h₁ : pushout.inr ≫ k = pushout.inr ≫ l) : k = l := colimit.hom_ext <| PushoutCocone.coequalizer_ext _ h₀ h₁ #align category_theory.limits.pushout.hom_ext CategoryTheory.Limits.pushout.hom_ext /-- The pushout cocone built from the pushout coprojections is a pushout. -/ def pushoutIsPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : IsColimit (PushoutCocone.mk (pushout.inl : _ ⟶ pushout f g) pushout.inr pushout.condition) := PushoutCocone.IsColimit.mk _ (fun s => pushout.desc s.inl s.inr s.condition) (by simp) (by simp) (by aesop_cat) #align category_theory.limits.pushout_is_pushout CategoryTheory.Limits.pushoutIsPushout /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inl_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi g] : Epi (pushout.inl : Y ⟶ pushout f g) := PushoutCocone.epi_inl_of_is_pushout_of_epi (colimit.isColimit _) #align category_theory.limits.pushout.inl_of_epi CategoryTheory.Limits.pushout.inl_of_epi /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inr_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi f] : Epi (pushout.inr : Z ⟶ pushout f g) := PushoutCocone.epi_inr_of_is_pushout_of_epi (colimit.isColimit _) #align category_theory.limits.pushout.inr_of_epi CategoryTheory.Limits.pushout.inr_of_epi /-- The map `X ⨿ Y ⟶ X ⨿[Z] Y` is epi. -/ instance epi_coprod_to_pushout {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasBinaryCoproduct Y Z] : Epi (coprod.desc pushout.inl pushout.inr : _ ⟶ pushout f g) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => coprod.inl ≫ f) h · simpa using congrArg (fun f => coprod.inr ≫ f) h⟩ #align category_theory.limits.epi_coprod_to_pushout CategoryTheory.Limits.epi_coprod_to_pushout instance pullback.map_isIso {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pullback.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · aesop_cat · aesop_cat #align category_theory.limits.pullback.map_is_iso CategoryTheory.Limits.pullback.map_isIso /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pullback f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pullback.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : pullback f₁ g₁ ≅ pullback f₂ g₂ := asIso <| pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) #align category_theory.limits.pullback.congr_hom CategoryTheory.Limits.pullback.congrHom @[simp] theorem pullback.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : (pullback.congrHom h₁ h₂).inv = pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext · erw [pullback.lift_fst] rw [Iso.inv_comp_eq] erw [pullback.lift_fst_assoc] rw [Category.comp_id, Category.comp_id] · erw [pullback.lift_snd] rw [Iso.inv_comp_eq] erw [pullback.lift_snd_assoc] rw [Category.comp_id, Category.comp_id] #align category_theory.limits.pullback.congr_hom_inv CategoryTheory.Limits.pullback.congrHom_inv instance pushout.map_isIso {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pushout.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pushout.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · aesop_cat · aesop_cat #align category_theory.limits.pushout.map_is_iso CategoryTheory.Limits.pushout.map_isIso theorem pullback.mapDesc_comp {X Y S T S' : C} (f : X ⟶ T) (g : Y ⟶ T) (i : T ⟶ S) (i' : S ⟶ S') [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] [HasPullback (f ≫ i ≫ i') (g ≫ i ≫ i')] [HasPullback ((f ≫ i) ≫ i') ((g ≫ i) ≫ i')] : pullback.mapDesc f g (i ≫ i') = pullback.mapDesc f g i ≫ pullback.mapDesc _ _ i' ≫ (pullback.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom := by aesop_cat #align category_theory.limits.pullback.map_desc_comp CategoryTheory.Limits.pullback.mapDesc_comp /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pushout f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pushout.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : pushout f₁ g₁ ≅ pushout f₂ g₂ := asIso <| pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) #align category_theory.limits.pushout.congr_hom CategoryTheory.Limits.pushout.congrHom @[simp] theorem pushout.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : (pushout.congrHom h₁ h₂).inv = pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext · erw [pushout.inl_desc] rw [Iso.comp_inv_eq, Category.id_comp] erw [pushout.inl_desc] rw [Category.id_comp] · erw [pushout.inr_desc] rw [Iso.comp_inv_eq, Category.id_comp] erw [pushout.inr_desc] rw [Category.id_comp] #align category_theory.limits.pushout.congr_hom_inv CategoryTheory.Limits.pushout.congrHom_inv theorem pushout.mapLift_comp {X Y S T S' : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) (i' : S' ⟶ S) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] [HasPushout (i' ≫ i ≫ f) (i' ≫ i ≫ g)] [HasPushout ((i' ≫ i) ≫ f) ((i' ≫ i) ≫ g)] : pushout.mapLift f g (i' ≫ i) = (pushout.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom ≫ pushout.mapLift _ _ i' ≫ pushout.mapLift f g i := by aesop_cat #align category_theory.limits.pushout.map_lift_comp CategoryTheory.Limits.pushout.mapLift_comp section variable (G : C ⥤ D) /-- The comparison morphism for the pullback of `f,g`. This is an isomorphism iff `G` preserves the pullback of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : G.obj (pullback f g) ⟶ pullback (G.map f) (G.map g) := pullback.lift (G.map pullback.fst) (G.map pullback.snd) (by simp only [← G.map_comp, pullback.condition]) #align category_theory.limits.pullback_comparison CategoryTheory.Limits.pullbackComparison @[reassoc (attr := simp)] theorem pullbackComparison_comp_fst (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.fst = G.map pullback.fst := pullback.lift_fst _ _ _ #align category_theory.limits.pullback_comparison_comp_fst CategoryTheory.Limits.pullbackComparison_comp_fst @[reassoc (attr := simp)] theorem pullbackComparison_comp_snd (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.snd = G.map pullback.snd := pullback.lift_snd _ _ _ #align category_theory.limits.pullback_comparison_comp_snd CategoryTheory.Limits.pullbackComparison_comp_snd @[reassoc (attr := simp)] theorem map_lift_pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] {W : C} {h : W ⟶ X} {k : W ⟶ Y} (w : h ≫ f = k ≫ g) : G.map (pullback.lift _ _ w) ≫ pullbackComparison G f g = pullback.lift (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] #align category_theory.limits.map_lift_pullback_comparison CategoryTheory.Limits.map_lift_pullbackComparison /-- The comparison morphism for the pushout of `f,g`. This is an isomorphism iff `G` preserves the pushout of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout (G.map f) (G.map g) ⟶ G.obj (pushout f g) := pushout.desc (G.map pushout.inl) (G.map pushout.inr) (by simp only [← G.map_comp, pushout.condition]) #align category_theory.limits.pushout_comparison CategoryTheory.Limits.pushoutComparison @[reassoc (attr := simp)] theorem inl_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inl ≫ pushoutComparison G f g = G.map pushout.inl := pushout.inl_desc _ _ _ #align category_theory.limits.inl_comp_pushout_comparison CategoryTheory.Limits.inl_comp_pushoutComparison @[reassoc (attr := simp)] theorem inr_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inr ≫ pushoutComparison G f g = G.map pushout.inr := pushout.inr_desc _ _ _ #align category_theory.limits.inr_comp_pushout_comparison CategoryTheory.Limits.inr_comp_pushoutComparison @[reassoc (attr := simp)] theorem pushoutComparison_map_desc (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] {W : C} {h : Y ⟶ W} {k : Z ⟶ W} (w : f ≫ h = g ≫ k) : pushoutComparison G f g ≫ G.map (pushout.desc _ _ w) = pushout.desc (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] #align category_theory.limits.pushout_comparison_map_desc CategoryTheory.Limits.pushoutComparison_map_desc end section PullbackSymmetry open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPullback_symmetry [HasPullback f g] : HasPullback g f := ⟨⟨⟨_, PullbackCone.flipIsLimit (pullbackIsPullback f g)⟩⟩⟩ #align category_theory.limits.has_pullback_symmetry CategoryTheory.Limits.hasPullback_symmetry attribute [local instance] hasPullback_symmetry /-- The isomorphism `X ×[Z] Y ≅ Y ×[Z] X`. -/ def pullbackSymmetry [HasPullback f g] : pullback f g ≅ pullback g f := IsLimit.conePointUniqueUpToIso (PullbackCone.flipIsLimit (pullbackIsPullback f g)) (limit.isLimit _) #align category_theory.limits.pullback_symmetry CategoryTheory.Limits.pullbackSymmetry @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_fst [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.fst = pullback.snd := by simp [pullbackSymmetry] #align category_theory.limits.pullback_symmetry_hom_comp_fst CategoryTheory.Limits.pullbackSymmetry_hom_comp_fst @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_snd [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.snd = pullback.fst := by simp [pullbackSymmetry] #align category_theory.limits.pullback_symmetry_hom_comp_snd CategoryTheory.Limits.pullbackSymmetry_hom_comp_snd @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_fst [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.fst = pullback.snd := by simp [Iso.inv_comp_eq] #align category_theory.limits.pullback_symmetry_inv_comp_fst CategoryTheory.Limits.pullbackSymmetry_inv_comp_fst @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_snd [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.snd = pullback.fst := by simp [Iso.inv_comp_eq] #align category_theory.limits.pullback_symmetry_inv_comp_snd CategoryTheory.Limits.pullbackSymmetry_inv_comp_snd end PullbackSymmetry section PushoutSymmetry open WalkingCospan variable (f : X ⟶ Y) (g : X ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPushout_symmetry [HasPushout f g] : HasPushout g f := ⟨⟨⟨_, PushoutCocone.flipIsColimit (pushoutIsPushout f g)⟩⟩⟩ #align category_theory.limits.has_pushout_symmetry CategoryTheory.Limits.hasPushout_symmetry attribute [local instance] hasPushout_symmetry /-- The isomorphism `Y ⨿[X] Z ≅ Z ⨿[X] Y`. -/ def pushoutSymmetry [HasPushout f g] : pushout f g ≅ pushout g f := IsColimit.coconePointUniqueUpToIso (PushoutCocone.flipIsColimit (pushoutIsPushout f g)) (colimit.isColimit _) #align category_theory.limits.pushout_symmetry CategoryTheory.Limits.pushoutSymmetry @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inl ≫ (pushoutSymmetry f g).hom = pushout.inr := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ #align category_theory.limits.inl_comp_pushout_symmetry_hom CategoryTheory.Limits.inl_comp_pushoutSymmetry_hom @[reassoc (attr := simp)] theorem inr_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inr ≫ (pushoutSymmetry f g).hom = pushout.inl := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ #align category_theory.limits.inr_comp_pushout_symmetry_hom CategoryTheory.Limits.inr_comp_pushoutSymmetry_hom @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inl ≫ (pushoutSymmetry f g).inv = pushout.inr := by simp [Iso.comp_inv_eq] #align category_theory.limits.inl_comp_pushout_symmetry_inv CategoryTheory.Limits.inl_comp_pushoutSymmetry_inv @[reassoc (attr := simp)] theorem inr_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inr ≫ (pushoutSymmetry f g).inv = pushout.inl := by simp [Iso.comp_inv_eq] #align category_theory.limits.inr_comp_pushout_symmetry_inv CategoryTheory.Limits.inr_comp_pushoutSymmetry_inv end PushoutSymmetry section PullbackLeftIso open WalkingCospan /-- The pullback of `f, g` is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/ noncomputable def pullbackIsPullbackOfCompMono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] [HasPullback f g] : IsLimit (PullbackCone.mk pullback.fst pullback.snd (show pullback.fst ≫ f ≫ i = pullback.snd ≫ g ≫ i from by -- Porting note: used to be _ simp only [← Category.assoc]; rw [cancel_mono]; apply pullback.condition)) := PullbackCone.isLimitOfCompMono f g i _ (limit.isLimit (cospan f g)) #align category_theory.limits.pullback_is_pullback_of_comp_mono CategoryTheory.Limits.pullbackIsPullbackOfCompMono instance hasPullback_of_comp_mono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] [HasPullback f g] : HasPullback (f ≫ i) (g ≫ i) := ⟨⟨⟨_, pullbackIsPullbackOfCompMono f g i⟩⟩⟩ #align category_theory.limits.has_pullback_of_comp_mono CategoryTheory.Limits.hasPullback_of_comp_mono variable (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso f] /-- If `f : X ⟶ Z` is iso, then `X ×[Z] Y ≅ Y`. This is the explicit limit cone. -/ def pullbackConeOfLeftIso : PullbackCone f g := PullbackCone.mk (g ≫ inv f) (𝟙 _) <| by simp #align category_theory.limits.pullback_cone_of_left_iso CategoryTheory.Limits.pullbackConeOfLeftIso @[simp] theorem pullbackConeOfLeftIso_x : (pullbackConeOfLeftIso f g).pt = Y := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.pullback_cone_of_left_iso_X CategoryTheory.Limits.pullbackConeOfLeftIso_x @[simp] theorem pullbackConeOfLeftIso_fst : (pullbackConeOfLeftIso f g).fst = g ≫ inv f := rfl #align category_theory.limits.pullback_cone_of_left_iso_fst CategoryTheory.Limits.pullbackConeOfLeftIso_fst @[simp] theorem pullbackConeOfLeftIso_snd : (pullbackConeOfLeftIso f g).snd = 𝟙 _ := rfl #align category_theory.limits.pullback_cone_of_left_iso_snd CategoryTheory.Limits.pullbackConeOfLeftIso_snd -- Porting note (#10618): simp can prove this; removed simp theorem pullbackConeOfLeftIso_π_app_none : (pullbackConeOfLeftIso f g).π.app none = g := by simp #align category_theory.limits.pullback_cone_of_left_iso_π_app_none CategoryTheory.Limits.pullbackConeOfLeftIso_π_app_none @[simp] theorem pullbackConeOfLeftIso_π_app_left : (pullbackConeOfLeftIso f g).π.app left = g ≫ inv f := rfl #align category_theory.limits.pullback_cone_of_left_iso_π_app_left CategoryTheory.Limits.pullbackConeOfLeftIso_π_app_left @[simp] theorem pullbackConeOfLeftIso_π_app_right : (pullbackConeOfLeftIso f g).π.app right = 𝟙 _ := rfl #align category_theory.limits.pullback_cone_of_left_iso_π_app_right CategoryTheory.Limits.pullbackConeOfLeftIso_π_app_right /-- Verify that the constructed limit cone is indeed a limit. -/ def pullbackConeOfLeftIsoIsLimit : IsLimit (pullbackConeOfLeftIso f g) := PullbackCone.isLimitAux' _ fun s => ⟨s.snd, by simp [← s.condition_assoc]⟩ #align category_theory.limits.pullback_cone_of_left_iso_is_limit CategoryTheory.Limits.pullbackConeOfLeftIsoIsLimit theorem hasPullback_of_left_iso : HasPullback f g := ⟨⟨⟨_, pullbackConeOfLeftIsoIsLimit f g⟩⟩⟩ #align category_theory.limits.has_pullback_of_left_iso CategoryTheory.Limits.hasPullback_of_left_iso attribute [local instance] hasPullback_of_left_iso instance pullback_snd_iso_of_left_iso : IsIso (pullback.snd : pullback f g ⟶ _) := by refine ⟨⟨pullback.lift (g ≫ inv f) (𝟙 _) (by simp), ?_, by simp⟩⟩ ext · simp [← pullback.condition_assoc] · simp [pullback.condition_assoc] #align category_theory.limits.pullback_snd_iso_of_left_iso CategoryTheory.Limits.pullback_snd_iso_of_left_iso variable (i : Z ⟶ W) [Mono i] instance hasPullback_of_right_factors_mono (f : X ⟶ Z) : HasPullback i (f ≫ i) := by conv => congr rw [← Category.id_comp i] infer_instance #align category_theory.limits.has_pullback_of_right_factors_mono CategoryTheory.Limits.hasPullback_of_right_factors_mono instance pullback_snd_iso_of_right_factors_mono (f : X ⟶ Z) : IsIso (pullback.snd : pullback i (f ≫ i) ⟶ _) := by #adaptation_note /-- nightly-testing 2024-04-01 this could not be placed directly in the `show from` without `dsimp` -/ have := limit.isoLimitCone_hom_π ⟨_, pullbackIsPullbackOfCompMono (𝟙 _) f i⟩ WalkingCospan.right dsimp only [cospan_right, id_eq, eq_mpr_eq_cast, PullbackCone.mk_pt, PullbackCone.mk_π_app, Functor.const_obj_obj, cospan_one] at this convert (congrArg IsIso (show _ ≫ pullback.snd = _ from this)).mp inferInstance · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm #align category_theory.limits.pullback_snd_iso_of_right_factors_mono CategoryTheory.Limits.pullback_snd_iso_of_right_factors_mono end PullbackLeftIso section PullbackRightIso open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso g] /-- If `g : Y ⟶ Z` is iso, then `X ×[Z] Y ≅ X`. This is the explicit limit cone. -/ def pullbackConeOfRightIso : PullbackCone f g := PullbackCone.mk (𝟙 _) (f ≫ inv g) <| by simp #align category_theory.limits.pullback_cone_of_right_iso CategoryTheory.Limits.pullbackConeOfRightIso @[simp] theorem pullbackConeOfRightIso_x : (pullbackConeOfRightIso f g).pt = X := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.pullback_cone_of_right_iso_X CategoryTheory.Limits.pullbackConeOfRightIso_x @[simp] theorem pullbackConeOfRightIso_fst : (pullbackConeOfRightIso f g).fst = 𝟙 _ := rfl #align category_theory.limits.pullback_cone_of_right_iso_fst CategoryTheory.Limits.pullbackConeOfRightIso_fst @[simp] theorem pullbackConeOfRightIso_snd : (pullbackConeOfRightIso f g).snd = f ≫ inv g := rfl #align category_theory.limits.pullback_cone_of_right_iso_snd CategoryTheory.Limits.pullbackConeOfRightIso_snd -- Porting note (#10618): simp can prove this; removed simps theorem pullbackConeOfRightIso_π_app_none : (pullbackConeOfRightIso f g).π.app none = f := by simp #align category_theory.limits.pullback_cone_of_right_iso_π_app_none CategoryTheory.Limits.pullbackConeOfRightIso_π_app_none @[simp] theorem pullbackConeOfRightIso_π_app_left : (pullbackConeOfRightIso f g).π.app left = 𝟙 _ := rfl #align category_theory.limits.pullback_cone_of_right_iso_π_app_left CategoryTheory.Limits.pullbackConeOfRightIso_π_app_left @[simp] theorem pullbackConeOfRightIso_π_app_right : (pullbackConeOfRightIso f g).π.app right = f ≫ inv g := rfl #align category_theory.limits.pullback_cone_of_right_iso_π_app_right CategoryTheory.Limits.pullbackConeOfRightIso_π_app_right /-- Verify that the constructed limit cone is indeed a limit. -/ def pullbackConeOfRightIsoIsLimit : IsLimit (pullbackConeOfRightIso f g) := PullbackCone.isLimitAux' _ fun s => ⟨s.fst, by simp [s.condition_assoc]⟩ #align category_theory.limits.pullback_cone_of_right_iso_is_limit CategoryTheory.Limits.pullbackConeOfRightIsoIsLimit theorem hasPullback_of_right_iso : HasPullback f g := ⟨⟨⟨_, pullbackConeOfRightIsoIsLimit f g⟩⟩⟩ #align category_theory.limits.has_pullback_of_right_iso CategoryTheory.Limits.hasPullback_of_right_iso attribute [local instance] hasPullback_of_right_iso instance pullback_snd_iso_of_right_iso : IsIso (pullback.fst : pullback f g ⟶ _) := by refine ⟨⟨pullback.lift (𝟙 _) (f ≫ inv g) (by simp), ?_, by simp⟩⟩ ext · simp · simp [pullback.condition_assoc] #align category_theory.limits.pullback_snd_iso_of_right_iso CategoryTheory.Limits.pullback_snd_iso_of_right_iso variable (i : Z ⟶ W) [Mono i] instance hasPullback_of_left_factors_mono (f : X ⟶ Z) : HasPullback (f ≫ i) i := by conv => congr case g => rw [← Category.id_comp i] infer_instance #align category_theory.limits.has_pullback_of_left_factors_mono CategoryTheory.Limits.hasPullback_of_left_factors_mono instance pullback_snd_iso_of_left_factors_mono (f : X ⟶ Z) : IsIso (pullback.fst : pullback (f ≫ i) i ⟶ _) := by #adaptation_note /-- nightly-testing 2024-04-01 this could not be placed directly in the `show from` without `dsimp` -/ have := limit.isoLimitCone_hom_π ⟨_, pullbackIsPullbackOfCompMono f (𝟙 _) i⟩ WalkingCospan.left dsimp only [cospan_left, id_eq, eq_mpr_eq_cast, PullbackCone.mk_pt, PullbackCone.mk_π_app, Functor.const_obj_obj, cospan_one] at this convert (congrArg IsIso (show _ ≫ pullback.fst = _ from this)).mp inferInstance · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm #align category_theory.limits.pullback_snd_iso_of_left_factors_mono CategoryTheory.Limits.pullback_snd_iso_of_left_factors_mono end PullbackRightIso section PushoutLeftIso open WalkingSpan /-- The pushout of `f, g` is also the pullback of `h ≫ f, h ≫ g` for any epi `h`. -/ noncomputable def pushoutIsPushoutOfEpiComp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] [HasPushout f g] : IsColimit (PushoutCocone.mk pushout.inl pushout.inr (show (h ≫ f) ≫ pushout.inl = (h ≫ g) ≫ pushout.inr from by simp only [Category.assoc]; rw [cancel_epi]; exact pushout.condition)) := PushoutCocone.isColimitOfEpiComp f g h _ (colimit.isColimit (span f g)) #align category_theory.limits.pushout_is_pushout_of_epi_comp CategoryTheory.Limits.pushoutIsPushoutOfEpiComp instance hasPushout_of_epi_comp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] [HasPushout f g] : HasPushout (h ≫ f) (h ≫ g) := ⟨⟨⟨_, pushoutIsPushoutOfEpiComp f g h⟩⟩⟩ #align category_theory.limits.has_pushout_of_epi_comp CategoryTheory.Limits.hasPushout_of_epi_comp variable (f : X ⟶ Y) (g : X ⟶ Z) [IsIso f] /-- If `f : X ⟶ Y` is iso, then `Y ⨿[X] Z ≅ Z`. This is the explicit colimit cocone. -/ def pushoutCoconeOfLeftIso : PushoutCocone f g := PushoutCocone.mk (inv f ≫ g) (𝟙 _) <| by simp #align category_theory.limits.pushout_cocone_of_left_iso CategoryTheory.Limits.pushoutCoconeOfLeftIso @[simp] theorem pushoutCoconeOfLeftIso_x : (pushoutCoconeOfLeftIso f g).pt = Z := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.pushout_cocone_of_left_iso_X CategoryTheory.Limits.pushoutCoconeOfLeftIso_x @[simp] theorem pushoutCoconeOfLeftIso_inl : (pushoutCoconeOfLeftIso f g).inl = inv f ≫ g := rfl #align category_theory.limits.pushout_cocone_of_left_iso_inl CategoryTheory.Limits.pushoutCoconeOfLeftIso_inl @[simp] theorem pushoutCoconeOfLeftIso_inr : (pushoutCoconeOfLeftIso f g).inr = 𝟙 _ := rfl #align category_theory.limits.pushout_cocone_of_left_iso_inr CategoryTheory.Limits.pushoutCoconeOfLeftIso_inr -- Porting note (#10618): simp can prove this; removed simp theorem pushoutCoconeOfLeftIso_ι_app_none : (pushoutCoconeOfLeftIso f g).ι.app none = g := by simp #align category_theory.limits.pushout_cocone_of_left_iso_ι_app_none CategoryTheory.Limits.pushoutCoconeOfLeftIso_ι_app_none @[simp] theorem pushoutCoconeOfLeftIso_ι_app_left : (pushoutCoconeOfLeftIso f g).ι.app left = inv f ≫ g := rfl #align category_theory.limits.pushout_cocone_of_left_iso_ι_app_left CategoryTheory.Limits.pushoutCoconeOfLeftIso_ι_app_left @[simp] theorem pushoutCoconeOfLeftIso_ι_app_right : (pushoutCoconeOfLeftIso f g).ι.app right = 𝟙 _ := rfl #align category_theory.limits.pushout_cocone_of_left_iso_ι_app_right CategoryTheory.Limits.pushoutCoconeOfLeftIso_ι_app_right /-- Verify that the constructed cocone is indeed a colimit. -/ def pushoutCoconeOfLeftIsoIsLimit : IsColimit (pushoutCoconeOfLeftIso f g) := PushoutCocone.isColimitAux' _ fun s => ⟨s.inr, by simp [← s.condition]⟩ #align category_theory.limits.pushout_cocone_of_left_iso_is_limit CategoryTheory.Limits.pushoutCoconeOfLeftIsoIsLimit theorem hasPushout_of_left_iso : HasPushout f g := ⟨⟨⟨_, pushoutCoconeOfLeftIsoIsLimit f g⟩⟩⟩ #align category_theory.limits.has_pushout_of_left_iso CategoryTheory.Limits.hasPushout_of_left_iso attribute [local instance] hasPushout_of_left_iso instance pushout_inr_iso_of_left_iso : IsIso (pushout.inr : _ ⟶ pushout f g) := by refine ⟨⟨pushout.desc (inv f ≫ g) (𝟙 _) (by simp), by simp, ?_⟩⟩ ext · simp [← pushout.condition] · simp [pushout.condition_assoc] #align category_theory.limits.pushout_inr_iso_of_left_iso CategoryTheory.Limits.pushout_inr_iso_of_left_iso variable (h : W ⟶ X) [Epi h] instance hasPushout_of_right_factors_epi (f : X ⟶ Y) : HasPushout h (h ≫ f) := by conv => congr rw [← Category.comp_id h] infer_instance #align category_theory.limits.has_pushout_of_right_factors_epi CategoryTheory.Limits.hasPushout_of_right_factors_epi instance pushout_inr_iso_of_right_factors_epi (f : X ⟶ Y) : IsIso (pushout.inr : _ ⟶ pushout h (h ≫ f)) := by convert (congrArg IsIso (show pushout.inr ≫ _ = _ from colimit.isoColimitCocone_ι_inv ⟨_, pushoutIsPushoutOfEpiComp (𝟙 _) f h⟩ WalkingSpan.right)).mp inferInstance · apply (Category.comp_id _).symm · apply (Category.comp_id _).symm #align category_theory.limits.pushout_inr_iso_of_right_factors_epi CategoryTheory.Limits.pushout_inr_iso_of_right_factors_epi end PushoutLeftIso section PushoutRightIso open WalkingSpan variable (f : X ⟶ Y) (g : X ⟶ Z) [IsIso g] /-- If `f : X ⟶ Z` is iso, then `Y ⨿[X] Z ≅ Y`. This is the explicit colimit cocone. -/ def pushoutCoconeOfRightIso : PushoutCocone f g := PushoutCocone.mk (𝟙 _) (inv g ≫ f) <| by simp #align category_theory.limits.pushout_cocone_of_right_iso CategoryTheory.Limits.pushoutCoconeOfRightIso @[simp] theorem pushoutCoconeOfRightIso_x : (pushoutCoconeOfRightIso f g).pt = Y := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.pushout_cocone_of_right_iso_X CategoryTheory.Limits.pushoutCoconeOfRightIso_x @[simp] theorem pushoutCoconeOfRightIso_inl : (pushoutCoconeOfRightIso f g).inl = 𝟙 _ := rfl #align category_theory.limits.pushout_cocone_of_right_iso_inl CategoryTheory.Limits.pushoutCoconeOfRightIso_inl @[simp] theorem pushoutCoconeOfRightIso_inr : (pushoutCoconeOfRightIso f g).inr = inv g ≫ f := rfl #align category_theory.limits.pushout_cocone_of_right_iso_inr CategoryTheory.Limits.pushoutCoconeOfRightIso_inr -- Porting note (#10618): simp can prove this; removed simp theorem pushoutCoconeOfRightIso_ι_app_none : (pushoutCoconeOfRightIso f g).ι.app none = f := by simp #align category_theory.limits.pushout_cocone_of_right_iso_ι_app_none CategoryTheory.Limits.pushoutCoconeOfRightIso_ι_app_none @[simp] theorem pushoutCoconeOfRightIso_ι_app_left : (pushoutCoconeOfRightIso f g).ι.app left = 𝟙 _ := rfl #align category_theory.limits.pushout_cocone_of_right_iso_ι_app_left CategoryTheory.Limits.pushoutCoconeOfRightIso_ι_app_left @[simp] theorem pushoutCoconeOfRightIso_ι_app_right : (pushoutCoconeOfRightIso f g).ι.app right = inv g ≫ f := rfl #align category_theory.limits.pushout_cocone_of_right_iso_ι_app_right CategoryTheory.Limits.pushoutCoconeOfRightIso_ι_app_right /-- Verify that the constructed cocone is indeed a colimit. -/ def pushoutCoconeOfRightIsoIsLimit : IsColimit (pushoutCoconeOfRightIso f g) := PushoutCocone.isColimitAux' _ fun s => ⟨s.inl, by simp [← s.condition]⟩ #align category_theory.limits.pushout_cocone_of_right_iso_is_limit CategoryTheory.Limits.pushoutCoconeOfRightIsoIsLimit theorem hasPushout_of_right_iso : HasPushout f g := ⟨⟨⟨_, pushoutCoconeOfRightIsoIsLimit f g⟩⟩⟩ #align category_theory.limits.has_pushout_of_right_iso CategoryTheory.Limits.hasPushout_of_right_iso attribute [local instance] hasPushout_of_right_iso instance pushout_inl_iso_of_right_iso : IsIso (pushout.inl : _ ⟶ pushout f g) := by refine ⟨⟨pushout.desc (𝟙 _) (inv g ≫ f) (by simp), by simp, ?_⟩⟩ ext · simp [← pushout.condition] · simp [pushout.condition] #align category_theory.limits.pushout_inl_iso_of_right_iso CategoryTheory.Limits.pushout_inl_iso_of_right_iso variable (h : W ⟶ X) [Epi h] instance hasPushout_of_left_factors_epi (f : X ⟶ Y) : HasPushout (h ≫ f) h := by conv => congr case g => rw [← Category.comp_id h] infer_instance #align category_theory.limits.has_pushout_of_left_factors_epi CategoryTheory.Limits.hasPushout_of_left_factors_epi instance pushout_inl_iso_of_left_factors_epi (f : X ⟶ Y) : IsIso (pushout.inl : _ ⟶ pushout (h ≫ f) h) := by convert (congrArg IsIso (show pushout.inl ≫ _ = _ from colimit.isoColimitCocone_ι_inv ⟨_, pushoutIsPushoutOfEpiComp f (𝟙 _) h⟩ WalkingSpan.left)).mp inferInstance; · exact (Category.comp_id _).symm · exact (Category.comp_id _).symm #align category_theory.limits.pushout_inl_iso_of_left_factors_epi CategoryTheory.Limits.pushout_inl_iso_of_left_factors_epi end PushoutRightIso section open WalkingCospan variable (f : X ⟶ Y) instance has_kernel_pair_of_mono [Mono f] : HasPullback f f := ⟨⟨⟨_, PullbackCone.isLimitMkIdId f⟩⟩⟩ #align category_theory.limits.has_kernel_pair_of_mono CategoryTheory.Limits.has_kernel_pair_of_mono theorem fst_eq_snd_of_mono_eq [Mono f] : (pullback.fst : pullback f f ⟶ _) = pullback.snd := ((PullbackCone.isLimitMkIdId f).fac (getLimitCone (cospan f f)).cone left).symm.trans ((PullbackCone.isLimitMkIdId f).fac (getLimitCone (cospan f f)).cone right : _) #align category_theory.limits.fst_eq_snd_of_mono_eq CategoryTheory.Limits.fst_eq_snd_of_mono_eq @[simp] theorem pullbackSymmetry_hom_of_mono_eq [Mono f] : (pullbackSymmetry f f).hom = 𝟙 _ := by ext · simp [fst_eq_snd_of_mono_eq] · simp [fst_eq_snd_of_mono_eq] #align category_theory.limits.pullback_symmetry_hom_of_mono_eq CategoryTheory.Limits.pullbackSymmetry_hom_of_mono_eq instance fst_iso_of_mono_eq [Mono f] : IsIso (pullback.fst : pullback f f ⟶ _) := by refine ⟨⟨pullback.lift (𝟙 _) (𝟙 _) (by simp), ?_, by simp⟩⟩ ext · simp · simp [fst_eq_snd_of_mono_eq] #align category_theory.limits.fst_iso_of_mono_eq CategoryTheory.Limits.fst_iso_of_mono_eq instance snd_iso_of_mono_eq [Mono f] : IsIso (pullback.snd : pullback f f ⟶ _) := by rw [← fst_eq_snd_of_mono_eq] infer_instance #align category_theory.limits.snd_iso_of_mono_eq CategoryTheory.Limits.snd_iso_of_mono_eq end section open WalkingSpan variable (f : X ⟶ Y) instance has_cokernel_pair_of_epi [Epi f] : HasPushout f f := ⟨⟨⟨_, PushoutCocone.isColimitMkIdId f⟩⟩⟩ #align category_theory.limits.has_cokernel_pair_of_epi CategoryTheory.Limits.has_cokernel_pair_of_epi theorem inl_eq_inr_of_epi_eq [Epi f] : (pushout.inl : _ ⟶ pushout f f) = pushout.inr := ((PushoutCocone.isColimitMkIdId f).fac (getColimitCocone (span f f)).cocone left).symm.trans ((PushoutCocone.isColimitMkIdId f).fac (getColimitCocone (span f f)).cocone right : _) #align category_theory.limits.inl_eq_inr_of_epi_eq CategoryTheory.Limits.inl_eq_inr_of_epi_eq @[simp] theorem pullback_symmetry_hom_of_epi_eq [Epi f] : (pushoutSymmetry f f).hom = 𝟙 _ := by ext <;> simp [inl_eq_inr_of_epi_eq] #align category_theory.limits.pullback_symmetry_hom_of_epi_eq CategoryTheory.Limits.pullback_symmetry_hom_of_epi_eq instance inl_iso_of_epi_eq [Epi f] : IsIso (pushout.inl : _ ⟶ pushout f f) := by refine ⟨⟨pushout.desc (𝟙 _) (𝟙 _) (by simp), by simp, ?_⟩⟩ apply pushout.hom_ext · simp · simp [inl_eq_inr_of_epi_eq] #align category_theory.limits.inl_iso_of_epi_eq CategoryTheory.Limits.inl_iso_of_epi_eq instance inr_iso_of_epi_eq [Epi f] : IsIso (pushout.inr : _ ⟶ pushout f f) := by rw [← inl_eq_inr_of_epi_eq] infer_instance #align category_theory.limits.inr_iso_of_epi_eq CategoryTheory.Limits.inr_iso_of_epi_eq end section PasteLemma variable {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃) (g₁ : Y₁ ⟶ Y₂) (g₂ : Y₂ ⟶ Y₃) variable (i₁ : X₁ ⟶ Y₁) (i₂ : X₂ ⟶ Y₂) (i₃ : X₃ ⟶ Y₃) variable (h₁ : i₁ ≫ g₁ = f₁ ≫ i₂) (h₂ : i₂ ≫ g₂ = f₂ ≫ i₃) /-- Given X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ Then the big square is a pullback if both the small squares are. -/ def bigSquareIsPullback (H : IsLimit (PullbackCone.mk _ _ h₂)) (H' : IsLimit (PullbackCone.mk _ _ h₁)) : IsLimit (PullbackCone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃ by rw [← Category.assoc, h₁, Category.assoc, h₂, Category.assoc])) := by fapply PullbackCone.isLimitAux' intro s have : (s.fst ≫ g₁) ≫ g₂ = s.snd ≫ i₃ := by rw [← s.condition, Category.assoc] rcases PullbackCone.IsLimit.lift' H (s.fst ≫ g₁) s.snd this with ⟨l₁, hl₁, hl₁'⟩ rcases PullbackCone.IsLimit.lift' H' s.fst l₁ hl₁.symm with ⟨l₂, hl₂, hl₂'⟩ use l₂ use hl₂ use show l₂ ≫ f₁ ≫ f₂ = s.snd by rw [← hl₁', ← hl₂', Category.assoc] rfl intro m hm₁ hm₂ apply PullbackCone.IsLimit.hom_ext H' · erw [hm₁, hl₂] · apply PullbackCone.IsLimit.hom_ext H · erw [Category.assoc, ← h₁, ← Category.assoc, hm₁, ← hl₂, Category.assoc, Category.assoc, h₁] rfl · erw [Category.assoc, hm₂, ← hl₁', ← hl₂'] #align category_theory.limits.big_square_is_pullback CategoryTheory.Limits.bigSquareIsPullback /-- Given X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ Then the big square is a pushout if both the small squares are. -/ def bigSquareIsPushout (H : IsColimit (PushoutCocone.mk _ _ h₂)) (H' : IsColimit (PushoutCocone.mk _ _ h₁)) : IsColimit (PushoutCocone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃ by rw [← Category.assoc, h₁, Category.assoc, h₂, Category.assoc])) := by fapply PushoutCocone.isColimitAux' intro s have : i₁ ≫ s.inl = f₁ ≫ f₂ ≫ s.inr := by rw [s.condition, Category.assoc] rcases PushoutCocone.IsColimit.desc' H' s.inl (f₂ ≫ s.inr) this with ⟨l₁, hl₁, hl₁'⟩ rcases PushoutCocone.IsColimit.desc' H l₁ s.inr hl₁' with ⟨l₂, hl₂, hl₂'⟩ use l₂ use show (g₁ ≫ g₂) ≫ l₂ = s.inl by rw [← hl₁, ← hl₂, Category.assoc] rfl use hl₂' intro m hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H · apply PushoutCocone.IsColimit.hom_ext H' · erw [← Category.assoc, hm₁, hl₂, hl₁] · erw [← Category.assoc, h₂, Category.assoc, hm₂, ← hl₂', ← Category.assoc, ← Category.assoc, ← h₂] rfl · erw [hm₂, hl₂'] #align category_theory.limits.big_square_is_pushout CategoryTheory.Limits.bigSquareIsPushout /-- Given X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ Then the left square is a pullback if the right square and the big square are. -/ def leftSquareIsPullback (H : IsLimit (PullbackCone.mk _ _ h₂)) (H' : IsLimit (PullbackCone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃ by rw [← Category.assoc, h₁, Category.assoc, h₂, Category.assoc]))) : IsLimit (PullbackCone.mk _ _ h₁) := by fapply PullbackCone.isLimitAux' intro s have : s.fst ≫ g₁ ≫ g₂ = (s.snd ≫ f₂) ≫ i₃ := by rw [← Category.assoc, s.condition, Category.assoc, Category.assoc, h₂] rcases PullbackCone.IsLimit.lift' H' s.fst (s.snd ≫ f₂) this with ⟨l₁, hl₁, hl₁'⟩ use l₁ use hl₁ constructor · apply PullbackCone.IsLimit.hom_ext H · erw [Category.assoc, ← h₁, ← Category.assoc, hl₁, s.condition] rfl · erw [Category.assoc, hl₁'] rfl · intro m hm₁ hm₂ apply PullbackCone.IsLimit.hom_ext H' · erw [hm₁, hl₁] · erw [hl₁', ← hm₂] exact (Category.assoc _ _ _).symm #align category_theory.limits.left_square_is_pullback CategoryTheory.Limits.leftSquareIsPullback /-- Given X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ Then the right square is a pushout if the left square and the big square are. -/ def rightSquareIsPushout (H : IsColimit (PushoutCocone.mk _ _ h₁)) (H' : IsColimit (PushoutCocone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃ by rw [← Category.assoc, h₁, Category.assoc, h₂, Category.assoc]))) : IsColimit (PushoutCocone.mk _ _ h₂) := by fapply PushoutCocone.isColimitAux' intro s have : i₁ ≫ g₁ ≫ s.inl = (f₁ ≫ f₂) ≫ s.inr := by rw [Category.assoc, ← s.condition, ← Category.assoc, ← Category.assoc, h₁] rcases PushoutCocone.IsColimit.desc' H' (g₁ ≫ s.inl) s.inr this with ⟨l₁, hl₁, hl₁'⟩ dsimp at * use l₁ refine ⟨?_, ?_, ?_⟩ · apply PushoutCocone.IsColimit.hom_ext H · erw [← Category.assoc, hl₁] rfl · erw [← Category.assoc, h₂, Category.assoc, hl₁', s.condition] · exact hl₁' · intro m hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H' · erw [hl₁, Category.assoc, hm₁] · erw [hm₂, hl₁'] #align category_theory.limits.right_square_is_pushout CategoryTheory.Limits.rightSquareIsPushout end PasteLemma section variable (f : X ⟶ Z) (g : Y ⟶ Z) (f' : W ⟶ X) variable [HasPullback f g] [HasPullback f' (pullback.fst : pullback f g ⟶ _)] variable [HasPullback (f' ≫ f) g] /-- The canonical isomorphism `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y` -/ noncomputable def pullbackRightPullbackFstIso : pullback f' (pullback.fst : pullback f g ⟶ _) ≅ pullback (f' ≫ f) g := by let this := bigSquareIsPullback (pullback.snd : pullback f' (pullback.fst : pullback f g ⟶ _) ⟶ _) pullback.snd f' f pullback.fst pullback.fst g pullback.condition pullback.condition (pullbackIsPullback _ _) (pullbackIsPullback _ _) exact (this.conePointUniqueUpToIso (pullbackIsPullback _ _) : _) #align category_theory.limits.pullback_right_pullback_fst_iso CategoryTheory.Limits.pullbackRightPullbackFstIso @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_hom_fst : (pullbackRightPullbackFstIso f g f').hom ≫ pullback.fst = pullback.fst := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left #align category_theory.limits.pullback_right_pullback_fst_iso_hom_fst CategoryTheory.Limits.pullbackRightPullbackFstIso_hom_fst @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_hom_snd : (pullbackRightPullbackFstIso f g f').hom ≫ pullback.snd = pullback.snd ≫ pullback.snd := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right #align category_theory.limits.pullback_right_pullback_fst_iso_hom_snd CategoryTheory.Limits.pullbackRightPullbackFstIso_hom_snd @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_fst : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.fst = pullback.fst := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left #align category_theory.limits.pullback_right_pullback_fst_iso_inv_fst CategoryTheory.Limits.pullbackRightPullbackFstIso_inv_fst @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_snd_snd : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.snd ≫ pullback.snd = pullback.snd := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.right #align category_theory.limits.pullback_right_pullback_fst_iso_inv_snd_snd CategoryTheory.Limits.pullbackRightPullbackFstIso_inv_snd_snd @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_snd_fst : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.snd ≫ pullback.fst = pullback.fst ≫ f' := by rw [← pullback.condition] exact pullbackRightPullbackFstIso_inv_fst_assoc _ _ _ _ #align category_theory.limits.pullback_right_pullback_fst_iso_inv_snd_fst CategoryTheory.Limits.pullbackRightPullbackFstIso_inv_snd_fst end section variable (f : X ⟶ Y) (g : X ⟶ Z) (g' : Z ⟶ W) variable [HasPushout f g] [HasPushout (pushout.inr : _ ⟶ pushout f g) g'] variable [HasPushout f (g ≫ g')] /-- The canonical isomorphism `(Y ⨿[X] Z) ⨿[Z] W ≅ Y ×[X] W` -/ noncomputable def pushoutLeftPushoutInrIso : pushout (pushout.inr : _ ⟶ pushout f g) g' ≅ pushout f (g ≫ g') := ((bigSquareIsPushout g g' _ _ f _ _ pushout.condition pushout.condition (pushoutIsPushout _ _) (pushoutIsPushout _ _)).coconePointUniqueUpToIso (pushoutIsPushout _ _) : _) #align category_theory.limits.pushout_left_pushout_inr_iso CategoryTheory.Limits.pushoutLeftPushoutInrIso @[reassoc (attr := simp)] theorem inl_pushoutLeftPushoutInrIso_inv : pushout.inl ≫ (pushoutLeftPushoutInrIso f g g').inv = pushout.inl ≫ pushout.inl := ((bigSquareIsPushout g g' _ _ f _ _ pushout.condition pushout.condition (pushoutIsPushout _ _) (pushoutIsPushout _ _)).comp_coconePointUniqueUpToIso_inv (pushoutIsPushout _ _) WalkingSpan.left : _) #align category_theory.limits.inl_pushout_left_pushout_inr_iso_inv CategoryTheory.Limits.inl_pushoutLeftPushoutInrIso_inv @[reassoc (attr := simp)] theorem inr_pushoutLeftPushoutInrIso_hom : pushout.inr ≫ (pushoutLeftPushoutInrIso f g g').hom = pushout.inr := ((bigSquareIsPushout g g' _ _ f _ _ pushout.condition pushout.condition (pushoutIsPushout _ _) (pushoutIsPushout _ _)).comp_coconePointUniqueUpToIso_hom (pushoutIsPushout _ _) WalkingSpan.right : _) #align category_theory.limits.inr_pushout_left_pushout_inr_iso_hom CategoryTheory.Limits.inr_pushoutLeftPushoutInrIso_hom @[reassoc (attr := simp)] theorem inr_pushoutLeftPushoutInrIso_inv : pushout.inr ≫ (pushoutLeftPushoutInrIso f g g').inv = pushout.inr := by rw [Iso.comp_inv_eq, inr_pushoutLeftPushoutInrIso_hom] #align category_theory.limits.inr_pushout_left_pushout_inr_iso_inv CategoryTheory.Limits.inr_pushoutLeftPushoutInrIso_inv @[reassoc (attr := simp)] theorem inl_inl_pushoutLeftPushoutInrIso_hom : pushout.inl ≫ pushout.inl ≫ (pushoutLeftPushoutInrIso f g g').hom = pushout.inl := by rw [← Category.assoc, ← Iso.eq_comp_inv, inl_pushoutLeftPushoutInrIso_inv] #align category_theory.limits.inl_inl_pushout_left_pushout_inr_iso_hom CategoryTheory.Limits.inl_inl_pushoutLeftPushoutInrIso_hom @[reassoc (attr := simp)] theorem inr_inl_pushoutLeftPushoutInrIso_hom : pushout.inr ≫ pushout.inl ≫ (pushoutLeftPushoutInrIso f g g').hom = g' ≫ pushout.inr := by rw [← Category.assoc, ← Iso.eq_comp_inv, Category.assoc, inr_pushoutLeftPushoutInrIso_inv, pushout.condition] #align category_theory.limits.inr_inl_pushout_left_pushout_inr_iso_hom CategoryTheory.Limits.inr_inl_pushoutLeftPushoutInrIso_hom end section PullbackAssoc /- The objects and morphisms are as follows: Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ where the two squares are pullbacks. We can then construct the pullback squares W - l₂ -> Z₂ - g₄ -> X₃ | | l₁ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ and W' - l₂' -> Z₂ | | l₁' g₃ ∨ ∨ Z₁ X₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ We will show that both `W` and `W'` are pullbacks over `g₁, g₂`, and thus we may construct a canonical isomorphism between them. -/ variable {X₁ X₂ X₃ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₁) (f₃ : X₂ ⟶ Y₂) variable (f₄ : X₃ ⟶ Y₂) [HasPullback f₁ f₂] [HasPullback f₃ f₄] local notation "Z₁" => pullback f₁ f₂ local notation "Z₂" => pullback f₃ f₄ local notation "g₁" => (pullback.fst : Z₁ ⟶ X₁) local notation "g₂" => (pullback.snd : Z₁ ⟶ X₂) local notation "g₃" => (pullback.fst : Z₂ ⟶ X₂) local notation "g₄" => (pullback.snd : Z₂ ⟶ X₃) local notation "W" => pullback (g₂ ≫ f₃) f₄ local notation "W'" => pullback f₁ (g₃ ≫ f₂) local notation "l₁" => (pullback.fst : W ⟶ Z₁) local notation "l₂" => (pullback.lift (pullback.fst ≫ g₂) pullback.snd (Eq.trans (Category.assoc _ _ _) pullback.condition) : W ⟶ Z₂) local notation "l₁'" => (pullback.lift pullback.fst (pullback.snd ≫ g₃) (pullback.condition.trans (Eq.symm (Category.assoc _ _ _))) : W' ⟶ Z₁) local notation "l₂'" => (pullback.snd : W' ⟶ Z₂) /-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/ def pullbackPullbackLeftIsPullback [HasPullback (g₂ ≫ f₃) f₄] : IsLimit (PullbackCone.mk l₁ l₂ (show l₁ ≫ g₂ = l₂ ≫ g₃ from (pullback.lift_fst _ _ _).symm)) := by apply leftSquareIsPullback · exact pullbackIsPullback f₃ f₄ convert pullbackIsPullback (g₂ ≫ f₃) f₄ rw [pullback.lift_snd] #align category_theory.limits.pullback_pullback_left_is_pullback CategoryTheory.Limits.pullbackPullbackLeftIsPullback /-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/ def pullbackAssocIsPullback [HasPullback (g₂ ≫ f₃) f₄] : IsLimit (PullbackCone.mk (l₁ ≫ g₁) l₂ (show (l₁ ≫ g₁) ≫ f₁ = l₂ ≫ g₃ ≫ f₂ by rw [pullback.lift_fst_assoc, Category.assoc, Category.assoc, pullback.condition])) := by apply PullbackCone.isLimitOfFlip apply bigSquareIsPullback · apply PullbackCone.isLimitOfFlip exact pullbackIsPullback f₁ f₂ · apply PullbackCone.isLimitOfFlip apply pullbackPullbackLeftIsPullback · exact pullback.lift_fst _ _ _ · exact pullback.condition.symm #align category_theory.limits.pullback_assoc_is_pullback CategoryTheory.Limits.pullbackAssocIsPullback theorem hasPullback_assoc [HasPullback (g₂ ≫ f₃) f₄] : HasPullback f₁ (g₃ ≫ f₂) := ⟨⟨⟨_, pullbackAssocIsPullback f₁ f₂ f₃ f₄⟩⟩⟩ #align category_theory.limits.has_pullback_assoc CategoryTheory.Limits.hasPullback_assoc /-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/ def pullbackPullbackRightIsPullback [HasPullback f₁ (g₃ ≫ f₂)] : IsLimit (PullbackCone.mk l₁' l₂' (show l₁' ≫ g₂ = l₂' ≫ g₃ from pullback.lift_snd _ _ _)) := by apply PullbackCone.isLimitOfFlip apply leftSquareIsPullback · apply PullbackCone.isLimitOfFlip exact pullbackIsPullback f₁ f₂ · apply PullbackCone.isLimitOfFlip exact IsLimit.ofIsoLimit (pullbackIsPullback f₁ (g₃ ≫ f₂)) (PullbackCone.ext (Iso.refl _) (by simp) (by simp)) · exact pullback.condition.symm #align category_theory.limits.pullback_pullback_right_is_pullback CategoryTheory.Limits.pullbackPullbackRightIsPullback /-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[Y₂] X₃`. -/ def pullbackAssocSymmIsPullback [HasPullback f₁ (g₃ ≫ f₂)] : IsLimit (PullbackCone.mk l₁' (l₂' ≫ g₄) (show l₁' ≫ g₂ ≫ f₃ = (l₂' ≫ g₄) ≫ f₄ by rw [pullback.lift_snd_assoc, Category.assoc, Category.assoc, pullback.condition])) := by apply bigSquareIsPullback · exact pullbackIsPullback f₃ f₄ · apply pullbackPullbackRightIsPullback #align category_theory.limits.pullback_assoc_symm_is_pullback CategoryTheory.Limits.pullbackAssocSymmIsPullback theorem hasPullback_assoc_symm [HasPullback f₁ (g₃ ≫ f₂)] : HasPullback (g₂ ≫ f₃) f₄ := ⟨⟨⟨_, pullbackAssocSymmIsPullback f₁ f₂ f₃ f₄⟩⟩⟩ #align category_theory.limits.has_pullback_assoc_symm CategoryTheory.Limits.hasPullback_assoc_symm /- Porting note: these don't seem to be propagating change from -- variable [HasPullback (g₂ ≫ f₃) f₄] [HasPullback f₁ (g₃ ≫ f₂)] -/ variable [HasPullback (g₂ ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] /-- The canonical isomorphism `(X₁ ×[Y₁] X₂) ×[Y₂] X₃ ≅ X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/ noncomputable def pullbackAssoc [HasPullback ((pullback.snd : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] : pullback (pullback.snd ≫ f₃ : pullback f₁ f₂ ⟶ _) f₄ ≅ pullback f₁ (pullback.fst ≫ f₂ : pullback f₃ f₄ ⟶ _) := (pullbackPullbackLeftIsPullback f₁ f₂ f₃ f₄).conePointUniqueUpToIso (pullbackPullbackRightIsPullback f₁ f₂ f₃ f₄) #align category_theory.limits.pullback_assoc CategoryTheory.Limits.pullbackAssoc @[reassoc (attr := simp)] theorem pullbackAssoc_inv_fst_fst [HasPullback ((pullback.snd : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst ≫ pullback.fst = pullback.fst := by trans l₁' ≫ pullback.fst · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left · exact pullback.lift_fst _ _ _ #align category_theory.limits.pullback_assoc_inv_fst_fst CategoryTheory.Limits.pullbackAssoc_inv_fst_fst @[reassoc (attr := simp)] theorem pullbackAssoc_hom_fst [HasPullback ((pullback.snd : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.fst = pullback.fst ≫ pullback.fst := by rw [← Iso.eq_inv_comp, pullbackAssoc_inv_fst_fst] #align category_theory.limits.pullback_assoc_hom_fst CategoryTheory.Limits.pullbackAssoc_hom_fst @[reassoc (attr := simp)] theorem pullbackAssoc_hom_snd_fst [HasPullback ((pullback.snd : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd ≫ pullback.fst = pullback.fst ≫ pullback.snd := by trans l₂ ≫ pullback.fst · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right · exact pullback.lift_fst _ _ _ #align category_theory.limits.pullback_assoc_hom_snd_fst CategoryTheory.Limits.pullbackAssoc_hom_snd_fst @[reassoc (attr := simp)] theorem pullbackAssoc_hom_snd_snd [HasPullback ((pullback.snd : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd ≫ pullback.snd = pullback.snd := by trans l₂ ≫ pullback.snd · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right · exact pullback.lift_snd _ _ _ #align category_theory.limits.pullback_assoc_hom_snd_snd CategoryTheory.Limits.pullbackAssoc_hom_snd_snd @[reassoc (attr := simp)] theorem pullbackAssoc_inv_fst_snd [HasPullback ((pullback.snd : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst ≫ pullback.snd = pullback.snd ≫ pullback.fst := by rw [Iso.inv_comp_eq, pullbackAssoc_hom_snd_fst] #align category_theory.limits.pullback_assoc_inv_fst_snd CategoryTheory.Limits.pullbackAssoc_inv_fst_snd @[reassoc (attr := simp)] theorem pullbackAssoc_inv_snd [HasPullback ((pullback.snd : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.snd = pullback.snd ≫ pullback.snd := by rw [Iso.inv_comp_eq, pullbackAssoc_hom_snd_snd] #align category_theory.limits.pullback_assoc_inv_snd CategoryTheory.Limits.pullbackAssoc_inv_snd end PullbackAssoc section PushoutAssoc /- The objects and morphisms are as follows: Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ where the two squares are pushouts. We can then construct the pushout squares Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ l₂ ∨ ∨ X₁ - f₁ -> Y₁ - l₁ -> W and Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ X₂ Y₂ | | f₂ l₂' ∨ ∨ Y₁ - l₁' -> W' We will show that both `W` and `W'` are pushouts over `f₂, f₃`, and thus we may construct a canonical isomorphism between them. -/ variable {X₁ X₂ X₃ Z₁ Z₂ : C} (g₁ : Z₁ ⟶ X₁) (g₂ : Z₁ ⟶ X₂) (g₃ : Z₂ ⟶ X₂) variable (g₄ : Z₂ ⟶ X₃) [HasPushout g₁ g₂] [HasPushout g₃ g₄] local notation "Y₁" => pushout g₁ g₂ local notation "Y₂" => pushout g₃ g₄ local notation "f₁" => (pushout.inl : X₁ ⟶ Y₁) local notation "f₂" => (pushout.inr : X₂ ⟶ Y₁) local notation "f₃" => (pushout.inl : X₂ ⟶ Y₂) local notation "f₄" => (pushout.inr : X₃ ⟶ Y₂) local notation "W" => pushout g₁ (g₂ ≫ f₃) local notation "W'" => pushout (g₃ ≫ f₂) g₄ local notation "l₁" => (pushout.desc pushout.inl (f₃ ≫ pushout.inr) (pushout.condition.trans (Category.assoc _ _ _)) : Y₁ ⟶ W) local notation "l₂" => (pushout.inr : Y₂ ⟶ W) local notation "l₁'" => (pushout.inl : Y₁ ⟶ W') local notation "l₂'" => (pushout.desc (f₂ ≫ pushout.inl) pushout.inr (Eq.trans (Eq.symm (Category.assoc _ _ _)) pushout.condition) : Y₂ ⟶ W') /-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutPushoutLeftIsPushout [HasPushout (g₃ ≫ f₂) g₄] : IsColimit (PushoutCocone.mk l₁' l₂' (show f₂ ≫ l₁' = f₃ ≫ l₂' from (pushout.inl_desc _ _ _).symm)) := by apply PushoutCocone.isColimitOfFlip apply rightSquareIsPushout · apply PushoutCocone.isColimitOfFlip exact pushoutIsPushout g₃ g₄ · exact IsColimit.ofIsoColimit (PushoutCocone.flipIsColimit (pushoutIsPushout (g₃ ≫ f₂) g₄)) (PushoutCocone.ext (Iso.refl _) (by simp) (by simp)) · exact pushout.condition.symm #align category_theory.limits.pushout_pushout_left_is_pushout CategoryTheory.Limits.pushoutPushoutLeftIsPushout /-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutAssocIsPushout [HasPushout (g₃ ≫ f₂) g₄] : IsColimit (PushoutCocone.mk (f₁ ≫ l₁') l₂' (show g₁ ≫ f₁ ≫ l₁' = (g₂ ≫ f₃) ≫ l₂' by rw [Category.assoc, pushout.inl_desc, pushout.condition_assoc])) := by apply bigSquareIsPushout · apply pushoutPushoutLeftIsPushout · exact pushoutIsPushout _ _ #align category_theory.limits.pushout_assoc_is_pushout CategoryTheory.Limits.pushoutAssocIsPushout theorem hasPushout_assoc [HasPushout (g₃ ≫ f₂) g₄] : HasPushout g₁ (g₂ ≫ f₃) := ⟨⟨⟨_, pushoutAssocIsPushout g₁ g₂ g₃ g₄⟩⟩⟩ #align category_theory.limits.has_pushout_assoc CategoryTheory.Limits.hasPushout_assoc /-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutPushoutRightIsPushout [HasPushout g₁ (g₂ ≫ f₃)] : IsColimit (PushoutCocone.mk l₁ l₂ (show f₂ ≫ l₁ = f₃ ≫ l₂ from pushout.inr_desc _ _ _)) := by apply rightSquareIsPushout · exact pushoutIsPushout _ _ · convert pushoutIsPushout g₁ (g₂ ≫ f₃) rw [pushout.inl_desc] #align category_theory.limits.pushout_pushout_right_is_pushout CategoryTheory.Limits.pushoutPushoutRightIsPushout /-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃`. -/ def pushoutAssocSymmIsPushout [HasPushout g₁ (g₂ ≫ f₃)] : IsColimit (PushoutCocone.mk l₁ (f₄ ≫ l₂) (show (g₃ ≫ f₂) ≫ l₁ = g₄ ≫ f₄ ≫ l₂ by rw [Category.assoc, pushout.inr_desc, pushout.condition_assoc])) := by apply PushoutCocone.isColimitOfFlip apply bigSquareIsPushout · apply PushoutCocone.isColimitOfFlip apply pushoutPushoutRightIsPushout · apply PushoutCocone.isColimitOfFlip exact pushoutIsPushout g₃ g₄ · exact pushout.condition.symm · exact (pushout.inr_desc _ _ _).symm #align category_theory.limits.pushout_assoc_symm_is_pushout CategoryTheory.Limits.pushoutAssocSymmIsPushout theorem hasPushout_assoc_symm [HasPushout g₁ (g₂ ≫ f₃)] : HasPushout (g₃ ≫ f₂) g₄ := ⟨⟨⟨_, pushoutAssocSymmIsPushout g₁ g₂ g₃ g₄⟩⟩⟩ #align category_theory.limits.has_pushout_assoc_symm CategoryTheory.Limits.hasPushout_assoc_symm -- Porting note: these are not propagating so moved into statements -- variable [HasPushout (g₃ ≫ f₂) g₄] [HasPushout g₁ (g₂ ≫ f₃)] /-- The canonical isomorphism `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃ ≅ X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/ noncomputable def pushoutAssoc [HasPushout (g₃ ≫ (pushout.inr : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl : X₂ ⟶ Y₂))] : pushout (g₃ ≫ pushout.inr : _ ⟶ pushout g₁ g₂) g₄ ≅ pushout g₁ (g₂ ≫ pushout.inl : _ ⟶ pushout g₃ g₄) := (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).coconePointUniqueUpToIso (pushoutPushoutRightIsPushout g₁ g₂ g₃ g₄) #align category_theory.limits.pushout_assoc CategoryTheory.Limits.pushoutAssoc @[reassoc (attr := simp)] theorem inl_inl_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl : X₂ ⟶ Y₂))] : pushout.inl ≫ pushout.inl ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inl := by trans f₁ ≫ l₁ · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_hom _ WalkingCospan.left · exact pushout.inl_desc _ _ _ #align category_theory.limits.inl_inl_pushout_assoc_hom CategoryTheory.Limits.inl_inl_pushoutAssoc_hom @[reassoc (attr := simp)] theorem inr_inl_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl : X₂ ⟶ Y₂))] : pushout.inr ≫ pushout.inl ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inl ≫ pushout.inr := by trans f₂ ≫ l₁ · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_hom _ WalkingCospan.left · exact pushout.inr_desc _ _ _ #align category_theory.limits.inr_inl_pushout_assoc_hom CategoryTheory.Limits.inr_inl_pushoutAssoc_hom @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/Shapes/Pullbacks.lean
2,644
2,652
theorem inr_inr_pushoutAssoc_inv [HasPushout (g₃ ≫ (pushout.inr : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl : X₂ ⟶ Y₂))] : pushout.inr ≫ pushout.inr ≫ (pushoutAssoc g₁ g₂ g₃ g₄).inv = pushout.inr := by
trans f₄ ≫ l₂' · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_inv (pushoutPushoutRightIsPushout g₁ g₂ g₃ g₄) WalkingCospan.right · exact pushout.inr_desc _ _ _
/- 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] 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] #align polynomial.nat_degree_mul Polynomial.natDegree_mul theorem trailingDegree_mul : (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by by_cases hp : p = 0 · rw [hp, zero_mul, trailingDegree_zero, top_add] by_cases hq : q = 0 · rw [hq, mul_zero, trailingDegree_zero, add_top] · rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, trailingDegree_eq_natTrailingDegree (mul_ne_zero hp hq), natTrailingDegree_mul hp hq] apply WithTop.coe_add #align polynomial.trailing_degree_mul Polynomial.trailingDegree_mul @[simp] theorem natDegree_pow (p : R[X]) (n : ℕ) : natDegree (p ^ n) = n * natDegree p := by classical obtain rfl | hp := eq_or_ne p 0 · obtain rfl | hn := eq_or_ne n 0 <;> simp [*] exact natDegree_pow' $ by rw [← leadingCoeff_pow, Ne, leadingCoeff_eq_zero]; exact pow_ne_zero _ hp #align polynomial.nat_degree_pow Polynomial.natDegree_pow theorem degree_le_mul_left (p : R[X]) (hq : q ≠ 0) : degree p ≤ degree (p * q) := by classical exact if hp : p = 0 then by simp only [hp, zero_mul, le_refl] else by rw [degree_mul, degree_eq_natDegree hp, degree_eq_natDegree hq]; exact WithBot.coe_le_coe.2 (Nat.le_add_right _ _) #align polynomial.degree_le_mul_left Polynomial.degree_le_mul_left theorem natDegree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) : p.natDegree ≤ q.natDegree := by rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2 rw [natDegree_mul h2.1 h2.2]; exact Nat.le_add_right _ _ #align polynomial.nat_degree_le_of_dvd Polynomial.natDegree_le_of_dvd theorem degree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) : degree p ≤ degree q := by rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2 exact degree_le_mul_left p h2.2 #align polynomial.degree_le_of_dvd Polynomial.degree_le_of_dvd theorem eq_zero_of_dvd_of_degree_lt {p q : R[X]} (h₁ : p ∣ q) (h₂ : degree q < degree p) : q = 0 := by by_contra hc exact (lt_iff_not_ge _ _).mp h₂ (degree_le_of_dvd h₁ hc) #align polynomial.eq_zero_of_dvd_of_degree_lt Polynomial.eq_zero_of_dvd_of_degree_lt
Mathlib/Algebra/Polynomial/RingDivision.lean
172
175
theorem eq_zero_of_dvd_of_natDegree_lt {p q : R[X]} (h₁ : p ∣ q) (h₂ : natDegree q < natDegree p) : q = 0 := by
by_contra hc exact (lt_iff_not_ge _ _).mp h₂ (natDegree_le_of_dvd h₁ hc)
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.DiscreteCategory import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Terminal #align_import category_theory.limits.shapes.binary_products from "leanprover-community/mathlib"@"fec1d95fc61c750c1ddbb5b1f7f48b8e811a80d7" /-! # Binary (co)products We define a category `WalkingPair`, which is the index category for a binary (co)product diagram. A convenience method `pair X Y` constructs the functor from the walking pair, hitting the given objects. We define `prod X Y` and `coprod X Y` as limits and colimits of such functors. Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence of (co)limits shaped as walking pairs. We include lemmas for simplifying equations involving projections and coprojections, and define braiding and associating isomorphisms, and the product comparison morphism. ## References * [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R) * [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN) -/ noncomputable section universe v u u₂ open CategoryTheory namespace CategoryTheory.Limits /-- The type of objects for the diagram indexing a binary (co)product. -/ inductive WalkingPair : Type | left | right deriving DecidableEq, Inhabited #align category_theory.limits.walking_pair CategoryTheory.Limits.WalkingPair open WalkingPair /-- The equivalence swapping left and right. -/ def WalkingPair.swap : WalkingPair ≃ WalkingPair where toFun j := WalkingPair.recOn j right left invFun j := WalkingPair.recOn j right left left_inv j := by cases j; repeat rfl right_inv j := by cases j; repeat rfl #align category_theory.limits.walking_pair.swap CategoryTheory.Limits.WalkingPair.swap @[simp] theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right := rfl #align category_theory.limits.walking_pair.swap_apply_left CategoryTheory.Limits.WalkingPair.swap_apply_left @[simp] theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left := rfl #align category_theory.limits.walking_pair.swap_apply_right CategoryTheory.Limits.WalkingPair.swap_apply_right @[simp] theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right := rfl #align category_theory.limits.walking_pair.swap_symm_apply_tt CategoryTheory.Limits.WalkingPair.swap_symm_apply_tt @[simp] theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left := rfl #align category_theory.limits.walking_pair.swap_symm_apply_ff CategoryTheory.Limits.WalkingPair.swap_symm_apply_ff /-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits. -/ def WalkingPair.equivBool : WalkingPair ≃ Bool where toFun j := WalkingPair.recOn j true false -- to match equiv.sum_equiv_sigma_bool invFun b := Bool.recOn b right left left_inv j := by cases j; repeat rfl right_inv b := by cases b; repeat rfl #align category_theory.limits.walking_pair.equiv_bool CategoryTheory.Limits.WalkingPair.equivBool @[simp] theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true := rfl #align category_theory.limits.walking_pair.equiv_bool_apply_left CategoryTheory.Limits.WalkingPair.equivBool_apply_left @[simp] theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false := rfl #align category_theory.limits.walking_pair.equiv_bool_apply_right CategoryTheory.Limits.WalkingPair.equivBool_apply_right @[simp] theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left := rfl #align category_theory.limits.walking_pair.equiv_bool_symm_apply_tt CategoryTheory.Limits.WalkingPair.equivBool_symm_apply_true @[simp] theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right := rfl #align category_theory.limits.walking_pair.equiv_bool_symm_apply_ff CategoryTheory.Limits.WalkingPair.equivBool_symm_apply_false variable {C : Type u} /-- The function on the walking pair, sending the two points to `X` and `Y`. -/ def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y #align category_theory.limits.pair_function CategoryTheory.Limits.pairFunction @[simp] theorem pairFunction_left (X Y : C) : pairFunction X Y left = X := rfl #align category_theory.limits.pair_function_left CategoryTheory.Limits.pairFunction_left @[simp] theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y := rfl #align category_theory.limits.pair_function_right CategoryTheory.Limits.pairFunction_right variable [Category.{v} C] /-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/ def pair (X Y : C) : Discrete WalkingPair ⥤ C := Discrete.functor fun j => WalkingPair.casesOn j X Y #align category_theory.limits.pair CategoryTheory.Limits.pair @[simp] theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X := rfl #align category_theory.limits.pair_obj_left CategoryTheory.Limits.pair_obj_left @[simp] theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y := rfl #align category_theory.limits.pair_obj_right CategoryTheory.Limits.pair_obj_right section variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- The natural transformation between two functors out of the walking pair, specified by its components. -/ def mapPair : F ⟶ G where app j := Discrete.recOn j fun j => WalkingPair.casesOn j f g naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat #align category_theory.limits.map_pair CategoryTheory.Limits.mapPair @[simp] theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f := rfl #align category_theory.limits.map_pair_left CategoryTheory.Limits.mapPair_left @[simp] theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g := rfl #align category_theory.limits.map_pair_right CategoryTheory.Limits.mapPair_right /-- The natural isomorphism between two functors out of the walking pair, specified by its components. -/ @[simps!] def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G := NatIso.ofComponents (fun j => Discrete.recOn j fun j => WalkingPair.casesOn j f g) (fun ⟨⟨u⟩⟩ => by aesop_cat) #align category_theory.limits.map_pair_iso CategoryTheory.Limits.mapPairIso end /-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/ @[simps!] def diagramIsoPair (F : Discrete WalkingPair ⥤ C) : F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) := mapPairIso (Iso.refl _) (Iso.refl _) #align category_theory.limits.diagram_iso_pair CategoryTheory.Limits.diagramIsoPair section variable {D : Type u} [Category.{v} D] /-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/ def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) := diagramIsoPair _ #align category_theory.limits.pair_comp CategoryTheory.Limits.pairComp end /-- A binary fan is just a cone on a diagram indexing a product. -/ abbrev BinaryFan (X Y : C) := Cone (pair X Y) #align category_theory.limits.binary_fan CategoryTheory.Limits.BinaryFan /-- The first projection of a binary fan. -/ abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.left⟩ #align category_theory.limits.binary_fan.fst CategoryTheory.Limits.BinaryFan.fst /-- The second projection of a binary fan. -/ abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_fan.snd CategoryTheory.Limits.BinaryFan.snd @[simp] theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst := rfl #align category_theory.limits.binary_fan.π_app_left CategoryTheory.Limits.BinaryFan.π_app_left @[simp] theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd := rfl #align category_theory.limits.binary_fan.π_app_right CategoryTheory.Limits.BinaryFan.π_app_right /-- A convenient way to show that a binary fan is a limit. -/ def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y) (lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt) (hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f) (hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g) (uniq : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g), m = lift f g) : IsLimit s := Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t)) (by rintro t (rfl | rfl) · exact hl₁ _ _ · exact hl₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) #align category_theory.limits.binary_fan.is_limit.mk CategoryTheory.Limits.BinaryFan.IsLimit.mk theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt} (h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ #align category_theory.limits.binary_fan.is_limit.hom_ext CategoryTheory.Limits.BinaryFan.IsLimit.hom_ext /-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/ abbrev BinaryCofan (X Y : C) := Cocone (pair X Y) #align category_theory.limits.binary_cofan CategoryTheory.Limits.BinaryCofan /-- The first inclusion of a binary cofan. -/ abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩ #align category_theory.limits.binary_cofan.inl CategoryTheory.Limits.BinaryCofan.inl /-- The second inclusion of a binary cofan. -/ abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_cofan.inr CategoryTheory.Limits.BinaryCofan.inr @[simp] theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl #align category_theory.limits.binary_cofan.ι_app_left CategoryTheory.Limits.BinaryCofan.ι_app_left @[simp] theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl #align category_theory.limits.binary_cofan.ι_app_right CategoryTheory.Limits.BinaryCofan.ι_app_right /-- A convenient way to show that a binary cofan is a colimit. -/ def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y) (desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T) (hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f) (hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g) (uniq : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g), m = desc f g) : IsColimit s := Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t)) (by rintro t (rfl | rfl) · exact hd₁ _ _ · exact hd₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) #align category_theory.limits.binary_cofan.is_colimit.mk CategoryTheory.Limits.BinaryCofan.IsColimit.mk theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) {f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ #align category_theory.limits.binary_cofan.is_colimit.hom_ext CategoryTheory.Limits.BinaryCofan.IsColimit.hom_ext variable {X Y : C} section attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/ @[simps pt] def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where pt := P π := { app := fun ⟨j⟩ => by cases j <;> simpa } #align category_theory.limits.binary_fan.mk CategoryTheory.Limits.BinaryFan.mk /-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/ @[simps pt] def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where pt := P ι := { app := fun ⟨j⟩ => by cases j <;> simpa } #align category_theory.limits.binary_cofan.mk CategoryTheory.Limits.BinaryCofan.mk end @[simp] theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ := rfl #align category_theory.limits.binary_fan.mk_fst CategoryTheory.Limits.BinaryFan.mk_fst @[simp] theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ := rfl #align category_theory.limits.binary_fan.mk_snd CategoryTheory.Limits.BinaryFan.mk_snd @[simp] theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ := rfl #align category_theory.limits.binary_cofan.mk_inl CategoryTheory.Limits.BinaryCofan.mk_inl @[simp] theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ := rfl #align category_theory.limits.binary_cofan.mk_inr CategoryTheory.Limits.BinaryCofan.mk_inr /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd := Cones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp #align category_theory.limits.iso_binary_fan_mk CategoryTheory.Limits.isoBinaryFanMk /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr := Cocones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp #align category_theory.limits.iso_binary_cofan_mk CategoryTheory.Limits.isoBinaryCofanMk /-- This is a more convenient formulation to show that a `BinaryFan` constructed using `BinaryFan.mk` is a limit cone. -/ def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W) (fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst) (fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd) (uniq : ∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (BinaryFan.mk fst snd) := { lift := lift fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } #align category_theory.limits.binary_fan.is_limit_mk CategoryTheory.Limits.BinaryFan.isLimitMk /-- This is a more convenient formulation to show that a `BinaryCofan` constructed using `BinaryCofan.mk` is a colimit cocone. -/ def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W} (desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt) (fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl) (fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr) (uniq : ∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (BinaryCofan.mk inl inr) := { desc := desc fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } #align category_theory.limits.binary_cofan.is_colimit_mk CategoryTheory.Limits.BinaryCofan.isColimitMk /-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`. -/ @[simps] def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } := ⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩ #align category_theory.limits.binary_fan.is_limit.lift' CategoryTheory.Limits.BinaryFan.IsLimit.lift' /-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`. -/ @[simps] def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W) (g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } := ⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩ #align category_theory.limits.binary_cofan.is_colimit.desc' CategoryTheory.Limits.BinaryCofan.IsColimit.desc' /-- Binary products are symmetric. -/ def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) : IsLimit (BinaryFan.mk c.snd c.fst) := BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryFan.IsLimit.hom_ext hc (e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm) #align category_theory.limits.binary_fan.is_limit_flip CategoryTheory.Limits.BinaryFan.isLimitFlip theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.fst := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X) exact ⟨⟨l, BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _) (h.hom_ext _ _), hl⟩⟩ · intro exact ⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩ #align category_theory.limits.binary_fan.is_limit_iff_is_iso_fst CategoryTheory.Limits.BinaryFan.isLimit_iff_isIso_fst theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.snd := by refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst)) exact ⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h => ⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩ #align category_theory.limits.binary_fan.is_limit_iff_is_iso_snd CategoryTheory.Limits.BinaryFan.isLimit_iff_isIso_snd /-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/ noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by fapply BinaryFan.isLimitMk · exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd) · intro s -- Porting note: simp timed out here simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id, BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc] · intro s -- Porting note: simp timed out here simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac] · intro s m e₁ e₂ -- Porting note: simpa timed out here also apply BinaryFan.IsLimit.hom_ext h · simpa only [BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv] · simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac] #align category_theory.limits.binary_fan.is_limit_comp_left_iso CategoryTheory.Limits.BinaryFan.isLimitCompLeftIso /-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/ noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) := BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h) #align category_theory.limits.binary_fan.is_limit_comp_right_iso CategoryTheory.Limits.BinaryFan.isLimitCompRightIso /-- Binary coproducts are symmetric. -/ def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) : IsColimit (BinaryCofan.mk c.inr c.inl) := BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryCofan.IsColimit.hom_ext hc (e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm) #align category_theory.limits.binary_cofan.is_colimit_flip CategoryTheory.Limits.BinaryCofan.isColimitFlip theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inl := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X) refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩ rw [Category.comp_id] have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl rwa [Category.assoc,Category.id_comp] at e · intro exact ⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f) (fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => (IsIso.eq_inv_comp _).mpr e⟩ #align category_theory.limits.binary_cofan.is_colimit_iff_is_iso_inl CategoryTheory.Limits.BinaryCofan.isColimit_iff_isIso_inl theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inr := by refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl)) exact ⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h => ⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩ #align category_theory.limits.binary_cofan.is_colimit_iff_is_iso_inr CategoryTheory.Limits.BinaryCofan.isColimit_iff_isIso_inr /-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/ noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by fapply BinaryCofan.isColimitMk · exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr) · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] · intro s m e₁ e₂ apply BinaryCofan.IsColimit.hom_ext h · rw [← cancel_epi f] -- Porting note: simp timed out here too simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁ -- Porting note: simp timed out here too · simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] #align category_theory.limits.binary_cofan.is_colimit_comp_left_iso CategoryTheory.Limits.BinaryCofan.isColimitCompLeftIso /-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/ noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) := BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h) #align category_theory.limits.binary_cofan.is_colimit_comp_right_iso CategoryTheory.Limits.BinaryCofan.isColimitCompRightIso /-- An abbreviation for `HasLimit (pair X Y)`. -/ abbrev HasBinaryProduct (X Y : C) := HasLimit (pair X Y) #align category_theory.limits.has_binary_product CategoryTheory.Limits.HasBinaryProduct /-- An abbreviation for `HasColimit (pair X Y)`. -/ abbrev HasBinaryCoproduct (X Y : C) := HasColimit (pair X Y) #align category_theory.limits.has_binary_coproduct CategoryTheory.Limits.HasBinaryCoproduct /-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or `X ⨯ Y`. -/ abbrev prod (X Y : C) [HasBinaryProduct X Y] := limit (pair X Y) #align category_theory.limits.prod CategoryTheory.Limits.prod /-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or `X ⨿ Y`. -/ abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] := colimit (pair X Y) #align category_theory.limits.coprod CategoryTheory.Limits.coprod /-- Notation for the product -/ notation:20 X " ⨯ " Y:20 => prod X Y /-- Notation for the coproduct -/ notation:20 X " ⨿ " Y:20 => coprod X Y /-- The projection map to the first component of the product. -/ abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X := limit.π (pair X Y) ⟨WalkingPair.left⟩ #align category_theory.limits.prod.fst CategoryTheory.Limits.prod.fst /-- The projection map to the second component of the product. -/ abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y := limit.π (pair X Y) ⟨WalkingPair.right⟩ #align category_theory.limits.prod.snd CategoryTheory.Limits.prod.snd /-- The inclusion map from the first component of the coproduct. -/ abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.left⟩ #align category_theory.limits.coprod.inl CategoryTheory.Limits.coprod.inl /-- The inclusion map from the second component of the coproduct. -/ abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.right⟩ #align category_theory.limits.coprod.inr CategoryTheory.Limits.coprod.inr /-- The binary fan constructed from the projection maps is a limit. -/ def prodIsProd (X Y : C) [HasBinaryProduct X Y] : IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) := (limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.id_comp]; rfl · dsimp; simp only [Category.id_comp]; rfl )) #align category_theory.limits.prod_is_prod CategoryTheory.Limits.prodIsProd /-- The binary cofan constructed from the coprojection maps is a colimit. -/ def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] : IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) := (colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.comp_id] · dsimp; simp only [Category.comp_id] )) #align category_theory.limits.coprod_is_coprod CategoryTheory.Limits.coprodIsCoprod @[ext 1100] theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y} (h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g := BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂ #align category_theory.limits.prod.hom_ext CategoryTheory.Limits.prod.hom_ext @[ext 1100] theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W} (h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂ #align category_theory.limits.coprod.hom_ext CategoryTheory.Limits.coprod.hom_ext /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/ abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y := limit.lift _ (BinaryFan.mk f g) #align category_theory.limits.prod.lift CategoryTheory.Limits.prod.lift /-- diagonal arrow of the binary product in the category `fam I` -/ abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X := prod.lift (𝟙 _) (𝟙 _) #align category_theory.limits.diag CategoryTheory.Limits.diag /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/ abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W := colimit.desc _ (BinaryCofan.mk f g) #align category_theory.limits.coprod.desc CategoryTheory.Limits.coprod.desc /-- codiagonal arrow of the binary coproduct -/ abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X := coprod.desc (𝟙 _) (𝟙 _) #align category_theory.limits.codiag CategoryTheory.Limits.codiag -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.fst = f := limit.lift_π _ _ #align category_theory.limits.prod.lift_fst CategoryTheory.Limits.prod.lift_fst #align category_theory.limits.prod.lift_fst_assoc CategoryTheory.Limits.prod.lift_fst_assoc -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.snd = g := limit.lift_π _ _ #align category_theory.limits.prod.lift_snd CategoryTheory.Limits.prod.lift_snd #align category_theory.limits.prod.lift_snd_assoc CategoryTheory.Limits.prod.lift_snd_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inl ≫ coprod.desc f g = f := colimit.ι_desc _ _ #align category_theory.limits.coprod.inl_desc CategoryTheory.Limits.coprod.inl_desc #align category_theory.limits.coprod.inl_desc_assoc CategoryTheory.Limits.coprod.inl_desc_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inr ≫ coprod.desc f g = g := colimit.ι_desc _ _ #align category_theory.limits.coprod.inr_desc CategoryTheory.Limits.coprod.inr_desc #align category_theory.limits.coprod.inr_desc_assoc CategoryTheory.Limits.coprod.inr_desc_assoc instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_fst _ _ #align category_theory.limits.prod.mono_lift_of_mono_left CategoryTheory.Limits.prod.mono_lift_of_mono_left instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_snd _ _ #align category_theory.limits.prod.mono_lift_of_mono_right CategoryTheory.Limits.prod.mono_lift_of_mono_right instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inl_desc _ _ #align category_theory.limits.coprod.epi_desc_of_epi_left CategoryTheory.Limits.coprod.epi_desc_of_epi_left instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inr_desc _ _ #align category_theory.limits.coprod.epi_desc_of_epi_right CategoryTheory.Limits.coprod.epi_desc_of_epi_right /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/ def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } := ⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩ #align category_theory.limits.prod.lift' CategoryTheory.Limits.prod.lift' /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and `coprod.inr ≫ l = g`. -/ def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : { l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } := ⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩ #align category_theory.limits.coprod.desc' CategoryTheory.Limits.coprod.desc' /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/ def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z := limMap (mapPair f g) #align category_theory.limits.prod.map CategoryTheory.Limits.prod.map /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/ def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z := colimMap (mapPair f g) #align category_theory.limits.coprod.map CategoryTheory.Limits.coprod.map section ProdLemmas -- Making the reassoc version of this a simp lemma seems to be more harmful than helpful. @[reassoc, simp] theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) : f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp #align category_theory.limits.prod.comp_lift CategoryTheory.Limits.prod.comp_lift #align category_theory.limits.prod.comp_lift_assoc CategoryTheory.Limits.prod.comp_lift_assoc theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) : f ≫ diag Y = prod.lift f f := by simp #align category_theory.limits.prod.comp_diag CategoryTheory.Limits.prod.comp_diag @[reassoc (attr := simp)] theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f := limMap_π _ _ #align category_theory.limits.prod.map_fst CategoryTheory.Limits.prod.map_fst #align category_theory.limits.prod.map_fst_assoc CategoryTheory.Limits.prod.map_fst_assoc @[reassoc (attr := simp)] theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g := limMap_π _ _ #align category_theory.limits.prod.map_snd CategoryTheory.Limits.prod.map_snd #align category_theory.limits.prod.map_snd_assoc CategoryTheory.Limits.prod.map_snd_assoc @[simp] theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp #align category_theory.limits.prod.map_id_id CategoryTheory.Limits.prod.map_id_id @[simp] theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] : prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp #align category_theory.limits.prod.lift_fst_snd CategoryTheory.Limits.prod.lift_fst_snd @[reassoc (attr := simp)] theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W) (g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) : prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.prod.lift_map CategoryTheory.Limits.prod.lift_map #align category_theory.limits.prod.lift_map_assoc CategoryTheory.Limits.prod.lift_map_assoc @[simp] theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by rw [← prod.lift_map] simp #align category_theory.limits.prod.lift_fst_comp_snd_comp CategoryTheory.Limits.prod.lift_fst_comp_snd_comp -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just -- as well. @[reassoc (attr := simp)] theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂] [HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.prod.map_map CategoryTheory.Limits.prod.map_map #align category_theory.limits.prod.map_map_assoc CategoryTheory.Limits.prod.map_map_assoc -- TODO: is it necessary to weaken the assumption here? @[reassoc] theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasLimitsOfShape (Discrete WalkingPair) C] : prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp #align category_theory.limits.prod.map_swap CategoryTheory.Limits.prod.map_swap #align category_theory.limits.prod.map_swap_assoc CategoryTheory.Limits.prod.map_swap_assoc @[reassoc] theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W] [HasBinaryProduct Z W] [HasBinaryProduct Y W] : prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp #align category_theory.limits.prod.map_comp_id CategoryTheory.Limits.prod.map_comp_id #align category_theory.limits.prod.map_comp_id_assoc CategoryTheory.Limits.prod.map_comp_id_assoc @[reassoc] theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X] [HasBinaryProduct W Y] [HasBinaryProduct W Z] : prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp #align category_theory.limits.prod.map_id_comp CategoryTheory.Limits.prod.map_id_comp #align category_theory.limits.prod.map_id_comp_assoc CategoryTheory.Limits.prod.map_id_comp_assoc /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/ @[simps] def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where hom := prod.map f.hom g.hom inv := prod.map f.inv g.inv #align category_theory.limits.prod.map_iso CategoryTheory.Limits.prod.mapIso instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) := (prod.mapIso (asIso f) (asIso g)).isIso_hom #align category_theory.limits.is_iso_prod CategoryTheory.Limits.isIso_prod instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_mono f] simpa using congr_arg (fun f => f ≫ prod.fst) h · rw [← cancel_mono g] simpa using congr_arg (fun f => f ≫ prod.snd) h⟩ #align category_theory.limits.prod.map_mono CategoryTheory.Limits.prod.map_mono @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] : diag X ≫ prod.map f f = f ≫ diag Y := by simp #align category_theory.limits.prod.diag_map CategoryTheory.Limits.prod.diag_map #align category_theory.limits.prod.diag_map_assoc CategoryTheory.Limits.prod.diag_map_assoc @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] : diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp #align category_theory.limits.prod.diag_map_fst_snd CategoryTheory.Limits.prod.diag_map_fst_snd #align category_theory.limits.prod.diag_map_fst_snd_assoc CategoryTheory.Limits.prod.diag_map_fst_snd_assoc @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp #align category_theory.limits.prod.diag_map_fst_snd_comp CategoryTheory.Limits.prod.diag_map_fst_snd_comp #align category_theory.limits.prod.diag_map_fst_snd_comp_assoc CategoryTheory.Limits.prod.diag_map_fst_snd_comp_assoc instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) := IsSplitMono.mk' { retraction := prod.fst } end ProdLemmas section CoprodLemmas -- @[reassoc (attr := simp)] @[simp] -- Porting note: removing reassoc tag since result is not hygienic (two h's) theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by ext <;> simp #align category_theory.limits.coprod.desc_comp CategoryTheory.Limits.coprod.desc_comp -- Porting note: hand generated reassoc here. Simp can prove it theorem coprod.desc_comp_assoc {C : Type u} [Category C] {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) {Z : C} (l : W ⟶ Z) : coprod.desc g h ≫ f ≫ l = coprod.desc (g ≫ f) (h ≫ f) ≫ l := by simp #align category_theory.limits.coprod.desc_comp_assoc CategoryTheory.Limits.coprod.desc_comp theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) : codiag X ≫ f = coprod.desc f f := by simp #align category_theory.limits.coprod.diag_comp CategoryTheory.Limits.coprod.diag_comp @[reassoc (attr := simp)] theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl := ι_colimMap _ _ #align category_theory.limits.coprod.inl_map CategoryTheory.Limits.coprod.inl_map #align category_theory.limits.coprod.inl_map_assoc CategoryTheory.Limits.coprod.inl_map_assoc @[reassoc (attr := simp)] theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr := ι_colimMap _ _ #align category_theory.limits.coprod.inr_map CategoryTheory.Limits.coprod.inr_map #align category_theory.limits.coprod.inr_map_assoc CategoryTheory.Limits.coprod.inr_map_assoc @[simp] theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp #align category_theory.limits.coprod.map_id_id CategoryTheory.Limits.coprod.map_id_id @[simp] theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] : coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp #align category_theory.limits.coprod.desc_inl_inr CategoryTheory.Limits.coprod.desc_inl_inr -- The simp linter says simp can prove the reassoc version of this lemma. @[reassoc, simp] theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V] (f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) : coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by ext <;> simp #align category_theory.limits.coprod.map_desc CategoryTheory.Limits.coprod.map_desc #align category_theory.limits.coprod.map_desc_assoc CategoryTheory.Limits.coprod.map_desc_assoc @[simp] theorem coprod.desc_comp_inl_comp_inr {W X Y Z : C} [HasBinaryCoproduct W Y] [HasBinaryCoproduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : coprod.desc (g ≫ coprod.inl) (g' ≫ coprod.inr) = coprod.map g g' := by rw [← coprod.map_desc]; simp #align category_theory.limits.coprod.desc_comp_inl_comp_inr CategoryTheory.Limits.coprod.desc_comp_inl_comp_inr -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `inl_map` and `inr_map` can still work just -- as well. @[reassoc (attr := simp)] theorem coprod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryCoproduct A₁ B₁] [HasBinaryCoproduct A₂ B₂] [HasBinaryCoproduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : coprod.map f g ≫ coprod.map h k = coprod.map (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.coprod.map_map CategoryTheory.Limits.coprod.map_map #align category_theory.limits.coprod.map_map_assoc CategoryTheory.Limits.coprod.map_map_assoc -- I don't think it's a good idea to make any of the following three simp lemmas. @[reassoc] theorem coprod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasColimitsOfShape (Discrete WalkingPair) C] : coprod.map (𝟙 X) f ≫ coprod.map g (𝟙 B) = coprod.map g (𝟙 A) ≫ coprod.map (𝟙 Y) f := by simp #align category_theory.limits.coprod.map_swap CategoryTheory.Limits.coprod.map_swap #align category_theory.limits.coprod.map_swap_assoc CategoryTheory.Limits.coprod.map_swap_assoc @[reassoc] theorem coprod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct Z W] [HasBinaryCoproduct Y W] [HasBinaryCoproduct X W] : coprod.map (f ≫ g) (𝟙 W) = coprod.map f (𝟙 W) ≫ coprod.map g (𝟙 W) := by simp #align category_theory.limits.coprod.map_comp_id CategoryTheory.Limits.coprod.map_comp_id #align category_theory.limits.coprod.map_comp_id_assoc CategoryTheory.Limits.coprod.map_comp_id_assoc @[reassoc] theorem coprod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct W X] [HasBinaryCoproduct W Y] [HasBinaryCoproduct W Z] : coprod.map (𝟙 W) (f ≫ g) = coprod.map (𝟙 W) f ≫ coprod.map (𝟙 W) g := by simp #align category_theory.limits.coprod.map_id_comp CategoryTheory.Limits.coprod.map_id_comp #align category_theory.limits.coprod.map_id_comp_assoc CategoryTheory.Limits.coprod.map_id_comp_assoc /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : W ≅ Z` induces an isomorphism `coprod.mapIso f g : W ⨿ X ≅ Y ⨿ Z`. -/ @[simps] def coprod.mapIso {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨿ X ≅ Y ⨿ Z where hom := coprod.map f.hom g.hom inv := coprod.map f.inv g.inv #align category_theory.limits.coprod.map_iso CategoryTheory.Limits.coprod.mapIso instance isIso_coprod {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (coprod.map f g) := (coprod.mapIso (asIso f) (asIso g)).isIso_hom #align category_theory.limits.is_iso_coprod CategoryTheory.Limits.isIso_coprod instance coprod.map_epi {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f] [Epi g] [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] : Epi (coprod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_epi f] simpa using congr_arg (fun f => coprod.inl ≫ f) h · rw [← cancel_epi g] simpa using congr_arg (fun f => coprod.inr ≫ f) h⟩ #align category_theory.limits.coprod.map_epi CategoryTheory.Limits.coprod.map_epi -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc] theorem coprod.map_codiag {X Y : C} (f : X ⟶ Y) [HasBinaryCoproduct X X] [HasBinaryCoproduct Y Y] : coprod.map f f ≫ codiag Y = codiag X ≫ f := by simp #align category_theory.limits.coprod.map_codiag CategoryTheory.Limits.coprod.map_codiag #align category_theory.limits.coprod.map_codiag_assoc CategoryTheory.Limits.coprod.map_codiag_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc] theorem coprod.map_inl_inr_codiag {X Y : C} [HasBinaryCoproduct X Y] [HasBinaryCoproduct (X ⨿ Y) (X ⨿ Y)] : coprod.map coprod.inl coprod.inr ≫ codiag (X ⨿ Y) = 𝟙 (X ⨿ Y) := by simp #align category_theory.limits.coprod.map_inl_inr_codiag CategoryTheory.Limits.coprod.map_inl_inr_codiag #align category_theory.limits.coprod.map_inl_inr_codiag_assoc CategoryTheory.Limits.coprod.map_inl_inr_codiag_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc] theorem coprod.map_comp_inl_inr_codiag [HasColimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : coprod.map (g ≫ coprod.inl) (g' ≫ coprod.inr) ≫ codiag (Y ⨿ Y') = coprod.map g g' := by simp #align category_theory.limits.coprod.map_comp_inl_inr_codiag CategoryTheory.Limits.coprod.map_comp_inl_inr_codiag #align category_theory.limits.coprod.map_comp_inl_inr_codiag_assoc CategoryTheory.Limits.coprod.map_comp_inl_inr_codiag_assoc end CoprodLemmas variable (C) /-- `HasBinaryProducts` represents a choice of product for every pair of objects. See <https://stacks.math.columbia.edu/tag/001T>. -/ abbrev HasBinaryProducts := HasLimitsOfShape (Discrete WalkingPair) C #align category_theory.limits.has_binary_products CategoryTheory.Limits.HasBinaryProducts /-- `HasBinaryCoproducts` represents a choice of coproduct for every pair of objects. See <https://stacks.math.columbia.edu/tag/04AP>. -/ abbrev HasBinaryCoproducts := HasColimitsOfShape (Discrete WalkingPair) C #align category_theory.limits.has_binary_coproducts CategoryTheory.Limits.HasBinaryCoproducts /-- If `C` has all limits of diagrams `pair X Y`, then it has all binary products -/ theorem hasBinaryProducts_of_hasLimit_pair [∀ {X Y : C}, HasLimit (pair X Y)] : HasBinaryProducts C := { has_limit := fun F => hasLimitOfIso (diagramIsoPair F).symm } #align category_theory.limits.has_binary_products_of_has_limit_pair CategoryTheory.Limits.hasBinaryProducts_of_hasLimit_pair /-- If `C` has all colimits of diagrams `pair X Y`, then it has all binary coproducts -/ theorem hasBinaryCoproducts_of_hasColimit_pair [∀ {X Y : C}, HasColimit (pair X Y)] : HasBinaryCoproducts C := { has_colimit := fun F => hasColimitOfIso (diagramIsoPair F) } #align category_theory.limits.has_binary_coproducts_of_has_colimit_pair CategoryTheory.Limits.hasBinaryCoproducts_of_hasColimit_pair section variable {C} /-- The braiding isomorphism which swaps a binary product. -/ @[simps] def prod.braiding (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : P ⨯ Q ≅ Q ⨯ P where hom := prod.lift prod.snd prod.fst inv := prod.lift prod.snd prod.fst #align category_theory.limits.prod.braiding CategoryTheory.Limits.prod.braiding /-- The braiding isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem braid_natural [HasBinaryProducts C] {W X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ W) : prod.map f g ≫ (prod.braiding _ _).hom = (prod.braiding _ _).hom ≫ prod.map g f := by simp #align category_theory.limits.braid_natural CategoryTheory.Limits.braid_natural #align category_theory.limits.braid_natural_assoc CategoryTheory.Limits.braid_natural_assoc @[reassoc] theorem prod.symmetry' (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : prod.lift prod.snd prod.fst ≫ prod.lift prod.snd prod.fst = 𝟙 (P ⨯ Q) := (prod.braiding _ _).hom_inv_id #align category_theory.limits.prod.symmetry' CategoryTheory.Limits.prod.symmetry' #align category_theory.limits.prod.symmetry'_assoc CategoryTheory.Limits.prod.symmetry'_assoc /-- The braiding isomorphism is symmetric. -/ @[reassoc] theorem prod.symmetry (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : (prod.braiding P Q).hom ≫ (prod.braiding Q P).hom = 𝟙 _ := (prod.braiding _ _).hom_inv_id #align category_theory.limits.prod.symmetry CategoryTheory.Limits.prod.symmetry #align category_theory.limits.prod.symmetry_assoc CategoryTheory.Limits.prod.symmetry_assoc /-- The associator isomorphism for binary products. -/ @[simps] def prod.associator [HasBinaryProducts C] (P Q R : C) : (P ⨯ Q) ⨯ R ≅ P ⨯ Q ⨯ R where hom := prod.lift (prod.fst ≫ prod.fst) (prod.lift (prod.fst ≫ prod.snd) prod.snd) inv := prod.lift (prod.lift prod.fst (prod.snd ≫ prod.fst)) (prod.snd ≫ prod.snd) #align category_theory.limits.prod.associator CategoryTheory.Limits.prod.associator @[reassoc] theorem prod.pentagon [HasBinaryProducts C] (W X Y Z : C) : prod.map (prod.associator W X Y).hom (𝟙 Z) ≫ (prod.associator W (X ⨯ Y) Z).hom ≫ prod.map (𝟙 W) (prod.associator X Y Z).hom = (prod.associator (W ⨯ X) Y Z).hom ≫ (prod.associator W X (Y ⨯ Z)).hom := by simp #align category_theory.limits.prod.pentagon CategoryTheory.Limits.prod.pentagon #align category_theory.limits.prod.pentagon_assoc CategoryTheory.Limits.prod.pentagon_assoc @[reassoc] theorem prod.associator_naturality [HasBinaryProducts C] {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) : prod.map (prod.map f₁ f₂) f₃ ≫ (prod.associator Y₁ Y₂ Y₃).hom = (prod.associator X₁ X₂ X₃).hom ≫ prod.map f₁ (prod.map f₂ f₃) := by simp #align category_theory.limits.prod.associator_naturality CategoryTheory.Limits.prod.associator_naturality #align category_theory.limits.prod.associator_naturality_assoc CategoryTheory.Limits.prod.associator_naturality_assoc variable [HasTerminal C] /-- The left unitor isomorphism for binary products with the terminal object. -/ @[simps] def prod.leftUnitor (P : C) [HasBinaryProduct (⊤_ C) P] : (⊤_ C) ⨯ P ≅ P where hom := prod.snd inv := prod.lift (terminal.from P) (𝟙 _) hom_inv_id := by apply prod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp #align category_theory.limits.prod.left_unitor CategoryTheory.Limits.prod.leftUnitor /-- The right unitor isomorphism for binary products with the terminal object. -/ @[simps] def prod.rightUnitor (P : C) [HasBinaryProduct P (⊤_ C)] : P ⨯ ⊤_ C ≅ P where hom := prod.fst inv := prod.lift (𝟙 _) (terminal.from P) hom_inv_id := by apply prod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp #align category_theory.limits.prod.right_unitor CategoryTheory.Limits.prod.rightUnitor @[reassoc] theorem prod.leftUnitor_hom_naturality [HasBinaryProducts C] (f : X ⟶ Y) : prod.map (𝟙 _) f ≫ (prod.leftUnitor Y).hom = (prod.leftUnitor X).hom ≫ f := prod.map_snd _ _ #align category_theory.limits.prod.left_unitor_hom_naturality CategoryTheory.Limits.prod.leftUnitor_hom_naturality #align category_theory.limits.prod.left_unitor_hom_naturality_assoc CategoryTheory.Limits.prod.leftUnitor_hom_naturality_assoc @[reassoc] theorem prod.leftUnitor_inv_naturality [HasBinaryProducts C] (f : X ⟶ Y) : (prod.leftUnitor X).inv ≫ prod.map (𝟙 _) f = f ≫ (prod.leftUnitor Y).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, prod.leftUnitor_hom_naturality] #align category_theory.limits.prod.left_unitor_inv_naturality CategoryTheory.Limits.prod.leftUnitor_inv_naturality #align category_theory.limits.prod.left_unitor_inv_naturality_assoc CategoryTheory.Limits.prod.leftUnitor_inv_naturality_assoc @[reassoc] theorem prod.rightUnitor_hom_naturality [HasBinaryProducts C] (f : X ⟶ Y) : prod.map f (𝟙 _) ≫ (prod.rightUnitor Y).hom = (prod.rightUnitor X).hom ≫ f := prod.map_fst _ _ #align category_theory.limits.prod.right_unitor_hom_naturality CategoryTheory.Limits.prod.rightUnitor_hom_naturality #align category_theory.limits.prod.right_unitor_hom_naturality_assoc CategoryTheory.Limits.prod.rightUnitor_hom_naturality_assoc @[reassoc] theorem prod_rightUnitor_inv_naturality [HasBinaryProducts C] (f : X ⟶ Y) : (prod.rightUnitor X).inv ≫ prod.map f (𝟙 _) = f ≫ (prod.rightUnitor Y).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, prod.rightUnitor_hom_naturality] #align category_theory.limits.prod_right_unitor_inv_naturality CategoryTheory.Limits.prod_rightUnitor_inv_naturality #align category_theory.limits.prod_right_unitor_inv_naturality_assoc CategoryTheory.Limits.prod_rightUnitor_inv_naturality_assoc
Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean
1,113
1,116
theorem prod.triangle [HasBinaryProducts C] (X Y : C) : (prod.associator X (⊤_ C) Y).hom ≫ prod.map (𝟙 X) (prod.leftUnitor Y).hom = prod.map (prod.rightUnitor X).hom (𝟙 Y) := by
ext <;> simp
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real #align_import analysis.special_functions.pow.nnreal from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Power function on `ℝ≥0` and `ℝ≥0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open scoped Classical open Real NNReal ENNReal ComplexConjugate open Finset Function Set namespace NNReal variable {w x y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/ noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ #align nnreal.rpow NNReal.rpow noncomputable instance : Pow ℝ≥0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y := rfl #align nnreal.rpow_eq_pow NNReal.rpow_eq_pow @[simp, norm_cast] theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y := rfl #align nnreal.coe_rpow NNReal.coe_rpow @[simp] theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ #align nnreal.rpow_zero NNReal.rpow_zero @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 #align nnreal.rpow_eq_zero_iff NNReal.rpow_eq_zero_iff @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h #align nnreal.zero_rpow NNReal.zero_rpow @[simp] theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ #align nnreal.rpow_one NNReal.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ #align nnreal.one_rpow NNReal.one_rpow theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add (pos_iff_ne_zero.2 hx) _ _ #align nnreal.rpow_add NNReal.rpow_add theorem rpow_add' (x : ℝ≥0) {y z : ℝ} (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h #align nnreal.rpow_add' NNReal.rpow_add' /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z #align nnreal.rpow_mul NNReal.rpow_mul theorem rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ #align nnreal.rpow_neg NNReal.rpow_neg theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] #align nnreal.rpow_neg_one NNReal.rpow_neg_one theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub (pos_iff_ne_zero.2 hx) y z #align nnreal.rpow_sub NNReal.rpow_sub theorem rpow_sub' (x : ℝ≥0) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h #align nnreal.rpow_sub' NNReal.rpow_sub' theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] #align nnreal.rpow_inv_rpow_self NNReal.rpow_inv_rpow_self theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] #align nnreal.rpow_self_rpow_inv NNReal.rpow_self_rpow_inv theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y #align nnreal.inv_rpow NNReal.inv_rpow theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z #align nnreal.div_rpow NNReal.div_rpow theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 #align nnreal.sqrt_eq_rpow NNReal.sqrt_eq_rpow @[simp, norm_cast] theorem rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n #align nnreal.rpow_nat_cast NNReal.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] : x ^ (no_index (OfNat.ofNat n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) := rpow_natCast x n theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 #align nnreal.rpow_two NNReal.rpow_two theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 #align nnreal.mul_rpow NNReal.mul_rpow /-- `rpow` as a `MonoidHom`-/ @[simps] def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where toFun := (· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0`-/ theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/ lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/ lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := by lift l to List ℝ≥0 using hl have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊢ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ) (hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] · rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := by induction' s using Quotient.inductionOn with l simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := Real.rpow_le_rpow x.2 h₁ h₂ #align nnreal.rpow_le_rpow NNReal.rpow_le_rpow @[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ h₂ #align nnreal.rpow_lt_rpow NNReal.rpow_lt_rpow theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz #align nnreal.rpow_lt_rpow_iff NNReal.rpow_lt_rpow_iff theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := Real.rpow_le_rpow_iff x.2 y.2 hz #align nnreal.rpow_le_rpow_iff NNReal.rpow_le_rpow_iff theorem le_rpow_one_div_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ (1 / z) ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne'] #align nnreal.le_rpow_one_div_iff NNReal.le_rpow_one_div_iff theorem rpow_one_div_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ (1 / z) ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne'] #align nnreal.rpow_one_div_le_iff NNReal.rpow_one_div_le_iff @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz #align nnreal.rpow_lt_rpow_of_exponent_lt NNReal.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_le hx hyz #align nnreal.rpow_le_rpow_of_exponent_le NNReal.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz #align nnreal.rpow_lt_rpow_of_exponent_gt NNReal.rpow_lt_rpow_of_exponent_gt theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz #align nnreal.rpow_le_rpow_of_exponent_ge NNReal.rpow_le_rpow_of_exponent_ge theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by intro p hp_pos rw [← zero_rpow hp_pos.ne'] exact rpow_lt_rpow hx_pos hp_pos rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg) · exact rpow_pos_of_nonneg hp_pos · simp only [zero_lt_one, rpow_zero] · rw [← neg_neg p, rpow_neg, inv_pos] exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) #align nnreal.rpow_pos NNReal.rpow_pos theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 := Real.rpow_lt_one (coe_nonneg x) hx1 hz #align nnreal.rpow_lt_one NNReal.rpow_lt_one theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := Real.rpow_le_one x.2 hx2 hz #align nnreal.rpow_le_one NNReal.rpow_le_one theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := Real.rpow_lt_one_of_one_lt_of_neg hx hz #align nnreal.rpow_lt_one_of_one_lt_of_neg NNReal.rpow_lt_one_of_one_lt_of_neg theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hx hz #align nnreal.rpow_le_one_of_one_le_of_nonpos NNReal.rpow_le_one_of_one_le_of_nonpos theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := Real.one_lt_rpow hx hz #align nnreal.one_lt_rpow NNReal.one_lt_rpow theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z := Real.one_le_rpow h h₁ #align nnreal.one_le_rpow NNReal.one_le_rpow theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz #align nnreal.one_lt_rpow_of_pos_of_lt_one_of_neg NNReal.one_lt_rpow_of_pos_of_lt_one_of_neg theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z ≤ 0) : 1 ≤ x ^ z := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz #align nnreal.one_le_rpow_of_pos_of_le_one_of_nonpos NNReal.one_le_rpow_of_pos_of_le_one_of_nonpos theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x)) · have : z ≠ 0 := by linarith simp [this] nth_rw 2 [← NNReal.rpow_one x] exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le #align nnreal.rpow_le_self_of_le_one NNReal.rpow_le_self_of_le_one theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x := fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz #align nnreal.rpow_left_injective NNReal.rpow_left_injective theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injective hz).eq_iff #align nnreal.rpow_eq_rpow_iff NNReal.rpow_eq_rpow_iff theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x := fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, _root_.inv_mul_cancel hx, rpow_one]⟩ #align nnreal.rpow_left_surjective NNReal.rpow_left_surjective theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ #align nnreal.rpow_left_bijective NNReal.rpow_left_bijective theorem eq_rpow_one_div_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ (1 / z) ↔ x ^ z = y := by rw [← rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz] #align nnreal.eq_rpow_one_div_iff NNReal.eq_rpow_one_div_iff theorem rpow_one_div_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ (1 / z) = y ↔ x = y ^ z := by rw [← rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz] #align nnreal.rpow_one_div_eq_iff NNReal.rpow_one_div_eq_iff @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancel hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancel hy, rpow_one] theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow] exact Real.pow_rpow_inv_natCast x.2 hn #align nnreal.pow_nat_rpow_nat_inv NNReal.pow_rpow_inv_natCast theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow] exact Real.rpow_inv_natCast_pow x.2 hn #align nnreal.rpow_nat_inv_pow_nat NNReal.rpow_inv_natCast_pow theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_rpow, Real.toNNReal_coe] #align real.to_nnreal_rpow_of_nonneg Real.toNNReal_rpow_of_nonneg theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z := fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z := h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div]; rfl end NNReal namespace ENNReal /-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and `y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and `⊤ ^ x = 1 / 0 ^ x`). -/ noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞ | some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0) | none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0 #align ennreal.rpow ENNReal.rpow noncomputable instance : Pow ℝ≥0∞ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y := rfl #align ennreal.rpow_eq_pow ENNReal.rpow_eq_pow @[simp] theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by cases x <;> · dsimp only [(· ^ ·), Pow.pow, rpow] simp [lt_irrefl] #align ennreal.rpow_zero ENNReal.rpow_zero theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 := rfl #align ennreal.top_rpow_def ENNReal.top_rpow_def @[simp] theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h] #align ennreal.top_rpow_of_pos ENNReal.top_rpow_of_pos @[simp] theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by simp [top_rpow_def, asymm h, ne_of_lt h] #align ennreal.top_rpow_of_neg ENNReal.top_rpow_of_neg @[simp] theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, asymm h, ne_of_gt h] #align ennreal.zero_rpow_of_pos ENNReal.zero_rpow_of_pos @[simp] theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, ne_of_gt h] #align ennreal.zero_rpow_of_neg ENNReal.zero_rpow_of_neg theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H) · simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] · simp [lt_irrefl] · simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] #align ennreal.zero_rpow_def ENNReal.zero_rpow_def @[simp] theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by rw [zero_rpow_def] split_ifs exacts [zero_mul _, one_mul _, top_mul_top] #align ennreal.zero_rpow_mul_self ENNReal.zero_rpow_mul_self @[norm_cast] theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) := by rw [← ENNReal.some_eq_coe] dsimp only [(· ^ ·), Pow.pow, rpow] simp [h] #align ennreal.coe_rpow_of_ne_zero ENNReal.coe_rpow_of_ne_zero @[norm_cast]
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
452
457
theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : (x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) := by
by_cases hx : x = 0 · rcases le_iff_eq_or_lt.1 h with (H | H) · simp [hx, H.symm] · simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)] · exact coe_rpow_of_ne_zero hx _
/- 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.Algebra.Group.Prod import Mathlib.Data.Set.Lattice #align_import data.nat.pairing from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # Naturals pairing function This file defines a pairing function for the naturals as follows: ```text 0 1 4 9 16 2 3 5 10 17 6 7 8 11 18 12 13 14 15 19 20 21 22 23 24 ``` It has the advantage of being monotone in both directions and sending `⟦0, n^2 - 1⟧` to `⟦0, n - 1⟧²`. -/ assert_not_exists MonoidWithZero open Prod Decidable Function namespace Nat /-- Pairing function for the natural numbers. -/ -- Porting note: no pp_nodot --@[pp_nodot] def pair (a b : ℕ) : ℕ := if a < b then b * b + a else a * a + a + b #align nat.mkpair Nat.pair /-- Unpairing function for the natural numbers. -/ -- Porting note: no pp_nodot --@[pp_nodot] def unpair (n : ℕ) : ℕ × ℕ := let s := sqrt n if n - s * s < s then (n - s * s, s) else (s, n - s * s - s) #align nat.unpair Nat.unpair @[simp] theorem pair_unpair (n : ℕ) : pair (unpair n).1 (unpair n).2 = n := by dsimp only [unpair]; let s := sqrt n have sm : s * s + (n - s * s) = n := Nat.add_sub_cancel' (sqrt_le _) split_ifs with h · simp [pair, h, sm] · have hl : n - s * s - s ≤ s := Nat.sub_le_iff_le_add.2 (Nat.sub_le_iff_le_add'.2 <| by rw [← Nat.add_assoc]; apply sqrt_le_add) simp [pair, hl.not_lt, Nat.add_assoc, Nat.add_sub_cancel' (le_of_not_gt h), sm] #align nat.mkpair_unpair Nat.pair_unpair theorem pair_unpair' {n a b} (H : unpair n = (a, b)) : pair a b = n := by simpa [H] using pair_unpair n #align nat.mkpair_unpair' Nat.pair_unpair' @[simp]
Mathlib/Data/Nat/Pairing.lean
64
73
theorem unpair_pair (a b : ℕ) : unpair (pair a b) = (a, b) := by
dsimp only [pair]; split_ifs with h · show unpair (b * b + a) = (a, b) have be : sqrt (b * b + a) = b := sqrt_add_eq _ (le_trans (le_of_lt h) (Nat.le_add_left _ _)) simp [unpair, be, Nat.add_sub_cancel_left, h] · show unpair (a * a + a + b) = (a, b) have ae : sqrt (a * a + (a + b)) = a := by rw [sqrt_add_eq] exact Nat.add_le_add_left (le_of_not_gt h) _ simp [unpair, ae, Nat.not_lt_zero, Nat.add_assoc, Nat.add_sub_cancel_left]
/- 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` -/
Mathlib/Data/Ordmap/Ordset.lean
574
575
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] }
/- 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
Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean
142
143
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]
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.ToSquareZero import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.IsTensorProduct import Mathlib.Algebra.Exact import Mathlib.Algebra.MvPolynomial.PDeriv import Mathlib.Algebra.Polynomial.Derivation #align_import ring_theory.kaehler from "leanprover-community/mathlib"@"4b92a463033b5587bb011657e25e4710bfca7364" /-! # The module of kaehler differentials ## Main results - `KaehlerDifferential`: The module of kaehler differentials. For an `R`-algebra `S`, we provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. - `KaehlerDifferential.D`: The derivation into the module of kaehler differentials. - `KaehlerDifferential.span_range_derivation`: The image of `D` spans `Ω[S⁄R]` as an `S`-module. - `KaehlerDifferential.linearMapEquivDerivation`: The isomorphism `Hom_R(Ω[S⁄R], M) ≃ₗ[S] Der_R(S, M)`. - `KaehlerDifferential.quotKerTotalEquiv`: An alternative description of `Ω[S⁄R]` as `S` copies of `S` with kernel (`KaehlerDifferential.kerTotal`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` - `KaehlerDifferential.map`: Given a map between the arrows `R →+* A` and `S →+* B`, we have an `A`-linear map `Ω[A⁄R] → Ω[B⁄S]`. - `KaehlerDifferential.map_surjective`: The sequence `Ω[B⁄R] → Ω[B⁄A] → 0` is exact. - `KaehlerDifferential.exact_mapBaseChange_map`: The sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A]` is exact. ## Future project - Define the `IsKaehlerDifferential` predicate. -/ suppress_compilation section KaehlerDifferential open scoped TensorProduct open Algebra universe u v variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- The kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ abbrev KaehlerDifferential.ideal : Ideal (S ⊗[R] S) := RingHom.ker (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) #align kaehler_differential.ideal KaehlerDifferential.ideal variable {S} theorem KaehlerDifferential.one_smul_sub_smul_one_mem_ideal (a : S) : (1 : S) ⊗ₜ[R] a - a ⊗ₜ[R] (1 : S) ∈ KaehlerDifferential.ideal R S := by simp [RingHom.mem_ker] #align kaehler_differential.one_smul_sub_smul_one_mem_ideal KaehlerDifferential.one_smul_sub_smul_one_mem_ideal variable {R} variable {M : Type*} [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] /-- For a `R`-derivation `S → M`, this is the map `S ⊗[R] S →ₗ[S] M` sending `s ⊗ₜ t ↦ s • D t`. -/ def Derivation.tensorProductTo (D : Derivation R S M) : S ⊗[R] S →ₗ[S] M := TensorProduct.AlgebraTensorModule.lift ((LinearMap.lsmul S (S →ₗ[R] M)).flip D.toLinearMap) #align derivation.tensor_product_to Derivation.tensorProductTo theorem Derivation.tensorProductTo_tmul (D : Derivation R S M) (s t : S) : D.tensorProductTo (s ⊗ₜ t) = s • D t := rfl #align derivation.tensor_product_to_tmul Derivation.tensorProductTo_tmul theorem Derivation.tensorProductTo_mul (D : Derivation R S M) (x y : S ⊗[R] S) : D.tensorProductTo (x * y) = TensorProduct.lmul' (S := S) R x • D.tensorProductTo y + TensorProduct.lmul' (S := S) R y • D.tensorProductTo x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [zero_mul, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [add_mul, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x₁ x₂ refine TensorProduct.induction_on y ?_ ?_ ?_ · rw [mul_zero, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [mul_add, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x y simp only [TensorProduct.tmul_mul_tmul, Derivation.tensorProductTo, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul', TensorProduct.lmul'_apply_tmul] dsimp rw [D.leibniz] simp only [smul_smul, smul_add, mul_comm (x * y) x₁, mul_right_comm x₁ x₂, ← mul_assoc] #align derivation.tensor_product_to_mul Derivation.tensorProductTo_mul variable (R S) /-- The kernel of `S ⊗[R] S →ₐ[R] S` is generated by `1 ⊗ s - s ⊗ 1` as a `S`-module. -/ theorem KaehlerDifferential.submodule_span_range_eq_ideal : Submodule.span S (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = (KaehlerDifferential.ideal R S).restrictScalars S := by apply le_antisymm · rw [Submodule.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · rintro x (hx : _ = _) have : x - TensorProduct.lmul' (S := S) R x ⊗ₜ[R] (1 : S) = x := by rw [hx, TensorProduct.zero_tmul, sub_zero] rw [← this] clear this hx refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [map_zero, TensorProduct.zero_tmul, sub_zero]; exact zero_mem _ · intro x y have : x ⊗ₜ[R] y - (x * y) ⊗ₜ[R] (1 : S) = x • ((1 : S) ⊗ₜ y - y ⊗ₜ (1 : S)) := by simp_rw [smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] rw [TensorProduct.lmul'_apply_tmul, this] refine Submodule.smul_mem _ x ?_ apply Submodule.subset_span exact Set.mem_range_self y · intro x y hx hy rw [map_add, TensorProduct.add_tmul, ← sub_add_sub_comm] exact add_mem hx hy #align kaehler_differential.submodule_span_range_eq_ideal KaehlerDifferential.submodule_span_range_eq_ideal theorem KaehlerDifferential.span_range_eq_ideal : Ideal.span (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = KaehlerDifferential.ideal R S := by apply le_antisymm · rw [Ideal.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · change (KaehlerDifferential.ideal R S).restrictScalars S ≤ (Ideal.span _).restrictScalars S rw [← KaehlerDifferential.submodule_span_range_eq_ideal, Ideal.span] conv_rhs => rw [← Submodule.span_span_of_tower S] exact Submodule.subset_span #align kaehler_differential.span_range_eq_ideal KaehlerDifferential.span_range_eq_ideal /-- The module of Kähler differentials (Kahler differentials, Kaehler differentials). This is implemented as `I / I ^ 2` with `I` the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. To view elements as a linear combination of the form `s • D s'`, use `KaehlerDifferential.tensorProductTo_surjective` and `Derivation.tensorProductTo_tmul`. We also provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. -/ def KaehlerDifferential : Type v := (KaehlerDifferential.ideal R S).Cotangent #align kaehler_differential KaehlerDifferential instance : AddCommGroup (KaehlerDifferential R S) := by unfold KaehlerDifferential infer_instance instance KaehlerDifferential.module : Module (S ⊗[R] S) (KaehlerDifferential R S) := Ideal.Cotangent.moduleOfTower _ #align kaehler_differential.module KaehlerDifferential.module @[inherit_doc KaehlerDifferential] notation:100 "Ω[" S "⁄" R "]" => KaehlerDifferential R S instance : Nonempty (Ω[S⁄R]) := ⟨0⟩ instance KaehlerDifferential.module' {R' : Type*} [CommRing R'] [Algebra R' S] [SMulCommClass R R' S] : Module R' (Ω[S⁄R]) := Submodule.Quotient.module' _ #align kaehler_differential.module' KaehlerDifferential.module' instance : IsScalarTower S (S ⊗[R] S) (Ω[S⁄R]) := Ideal.Cotangent.isScalarTower _ instance KaehlerDifferential.isScalarTower_of_tower {R₁ R₂ : Type*} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [SMul R₁ R₂] [SMulCommClass R R₁ S] [SMulCommClass R R₂ S] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ #align kaehler_differential.is_scalar_tower_of_tower KaehlerDifferential.isScalarTower_of_tower instance KaehlerDifferential.isScalarTower' : IsScalarTower R (S ⊗[R] S) (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ #align kaehler_differential.is_scalar_tower' KaehlerDifferential.isScalarTower' /-- The quotient map `I → Ω[S⁄R]` with `I` being the kernel of `S ⊗[R] S → S`. -/ def KaehlerDifferential.fromIdeal : KaehlerDifferential.ideal R S →ₗ[S ⊗[R] S] Ω[S⁄R] := (KaehlerDifferential.ideal R S).toCotangent #align kaehler_differential.from_ideal KaehlerDifferential.fromIdeal /-- (Implementation) The underlying linear map of the derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.DLinearMap : S →ₗ[R] Ω[S⁄R] := ((KaehlerDifferential.fromIdeal R S).restrictScalars R).comp ((TensorProduct.includeRight.toLinearMap - TensorProduct.includeLeft.toLinearMap : S →ₗ[R] S ⊗[R] S).codRestrict ((KaehlerDifferential.ideal R S).restrictScalars R) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R) : _ →ₗ[R] _) set_option linter.uppercaseLean3 false in #align kaehler_differential.D_linear_map KaehlerDifferential.DLinearMap theorem KaehlerDifferential.DLinearMap_apply (s : S) : KaehlerDifferential.DLinearMap R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl set_option linter.uppercaseLean3 false in #align kaehler_differential.D_linear_map_apply KaehlerDifferential.DLinearMap_apply /-- The universal derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.D : Derivation R S (Ω[S⁄R]) := { toLinearMap := KaehlerDifferential.DLinearMap R S map_one_eq_zero' := by dsimp [KaehlerDifferential.DLinearMap_apply, Ideal.toCotangent_apply] congr rw [sub_self] leibniz' := fun a b => by have : LinearMap.CompatibleSMul { x // x ∈ ideal R S } (Ω[S⁄R]) S (S ⊗[R] S) := inferInstance dsimp [KaehlerDifferential.DLinearMap_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← LinearMap.map_smul_of_tower (M₂ := Ω[S⁄R]), ← LinearMap.map_smul_of_tower (M₂ := Ω[S⁄R]), ← map_add, Ideal.toCotangent_eq, pow_two] convert Submodule.mul_mem_mul (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R a : _) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R b : _) using 1 simp only [AddSubgroupClass.coe_sub, Submodule.coe_add, Submodule.coe_mk, TensorProduct.tmul_mul_tmul, mul_sub, sub_mul, mul_comm b, Submodule.coe_smul_of_tower, smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] ring_nf } set_option linter.uppercaseLean3 false in #align kaehler_differential.D KaehlerDifferential.D theorem KaehlerDifferential.D_apply (s : S) : KaehlerDifferential.D R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl set_option linter.uppercaseLean3 false in #align kaehler_differential.D_apply KaehlerDifferential.D_apply theorem KaehlerDifferential.span_range_derivation : Submodule.span S (Set.range <| KaehlerDifferential.D R S) = ⊤ := by rw [_root_.eq_top_iff] rintro x - obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x have : x ∈ (KaehlerDifferential.ideal R S).restrictScalars S := hx rw [← KaehlerDifferential.submodule_span_range_eq_ideal] at this suffices ∃ hx, (KaehlerDifferential.ideal R S).toCotangent ⟨x, hx⟩ ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) by exact this.choose_spec refine Submodule.span_induction this ?_ ?_ ?_ ?_ · rintro _ ⟨x, rfl⟩ refine ⟨KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x, ?_⟩ apply Submodule.subset_span exact ⟨x, KaehlerDifferential.DLinearMap_apply R S x⟩ · exact ⟨zero_mem _, Submodule.zero_mem _⟩ · rintro x y ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩; exact ⟨add_mem hx₁ hy₁, Submodule.add_mem _ hx₂ hy₂⟩ · rintro r x ⟨hx₁, hx₂⟩; exact ⟨((KaehlerDifferential.ideal R S).restrictScalars S).smul_mem r hx₁, Submodule.smul_mem _ r hx₂⟩ #align kaehler_differential.span_range_derivation KaehlerDifferential.span_range_derivation variable {R S} /-- The linear map from `Ω[S⁄R]`, associated with a derivation. -/ def Derivation.liftKaehlerDifferential (D : Derivation R S M) : Ω[S⁄R] →ₗ[S] M := by refine LinearMap.comp ((((KaehlerDifferential.ideal R S) • (⊤ : Submodule (S ⊗[R] S) (KaehlerDifferential.ideal R S))).restrictScalars S).liftQ ?_ ?_) (Submodule.Quotient.restrictScalarsEquiv S _).symm.toLinearMap · exact D.tensorProductTo.comp ((KaehlerDifferential.ideal R S).subtype.restrictScalars S) · intro x hx rw [LinearMap.mem_ker] refine Submodule.smul_induction_on hx ?_ ?_ · rintro x hx y - rw [RingHom.mem_ker] at hx dsimp rw [Derivation.tensorProductTo_mul, hx, y.prop, zero_smul, zero_smul, zero_add] · intro x y ex ey; rw [map_add, ex, ey, zero_add] #align derivation.lift_kaehler_differential Derivation.liftKaehlerDifferential theorem Derivation.liftKaehlerDifferential_apply (D : Derivation R S M) (x) : D.liftKaehlerDifferential ((KaehlerDifferential.ideal R S).toCotangent x) = D.tensorProductTo x := rfl #align derivation.lift_kaehler_differential_apply Derivation.liftKaehlerDifferential_apply theorem Derivation.liftKaehlerDifferential_comp (D : Derivation R S M) : D.liftKaehlerDifferential.compDer (KaehlerDifferential.D R S) = D := by ext a dsimp [KaehlerDifferential.D_apply] refine (D.liftKaehlerDifferential_apply _).trans ?_ rw [Subtype.coe_mk, map_sub, Derivation.tensorProductTo_tmul, Derivation.tensorProductTo_tmul, one_smul, D.map_one_eq_zero, smul_zero, sub_zero] #align derivation.lift_kaehler_differential_comp Derivation.liftKaehlerDifferential_comp @[simp] theorem Derivation.liftKaehlerDifferential_comp_D (D' : Derivation R S M) (x : S) : D'.liftKaehlerDifferential (KaehlerDifferential.D R S x) = D' x := Derivation.congr_fun D'.liftKaehlerDifferential_comp x set_option linter.uppercaseLean3 false in #align derivation.lift_kaehler_differential_comp_D Derivation.liftKaehlerDifferential_comp_D @[ext] theorem Derivation.liftKaehlerDifferential_unique (f f' : Ω[S⁄R] →ₗ[S] M) (hf : f.compDer (KaehlerDifferential.D R S) = f'.compDer (KaehlerDifferential.D R S)) : f = f' := by apply LinearMap.ext intro x have : x ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) := by rw [KaehlerDifferential.span_range_derivation]; trivial refine Submodule.span_induction this ?_ ?_ ?_ ?_ · rintro _ ⟨x, rfl⟩; exact congr_arg (fun D : Derivation R S M => D x) hf · rw [map_zero, map_zero] · intro x y hx hy; rw [map_add, map_add, hx, hy] · intro a x e; simp [e] #align derivation.lift_kaehler_differential_unique Derivation.liftKaehlerDifferential_unique variable (R S) theorem Derivation.liftKaehlerDifferential_D : (KaehlerDifferential.D R S).liftKaehlerDifferential = LinearMap.id := Derivation.liftKaehlerDifferential_unique _ _ (KaehlerDifferential.D R S).liftKaehlerDifferential_comp set_option linter.uppercaseLean3 false in #align derivation.lift_kaehler_differential_D Derivation.liftKaehlerDifferential_D variable {R S} theorem KaehlerDifferential.D_tensorProductTo (x : KaehlerDifferential.ideal R S) : (KaehlerDifferential.D R S).tensorProductTo x = (KaehlerDifferential.ideal R S).toCotangent x := by rw [← Derivation.liftKaehlerDifferential_apply, Derivation.liftKaehlerDifferential_D] rfl set_option linter.uppercaseLean3 false in #align kaehler_differential.D_tensor_product_to KaehlerDifferential.D_tensorProductTo variable (R S) theorem KaehlerDifferential.tensorProductTo_surjective : Function.Surjective (KaehlerDifferential.D R S).tensorProductTo := by intro x; obtain ⟨x, rfl⟩ := (KaehlerDifferential.ideal R S).toCotangent_surjective x exact ⟨x, KaehlerDifferential.D_tensorProductTo x⟩ #align kaehler_differential.tensor_product_to_surjective KaehlerDifferential.tensorProductTo_surjective /-- The `S`-linear maps from `Ω[S⁄R]` to `M` are (`S`-linearly) equivalent to `R`-derivations from `S` to `M`. -/ @[simps! symm_apply apply_apply] def KaehlerDifferential.linearMapEquivDerivation : (Ω[S⁄R] →ₗ[S] M) ≃ₗ[S] Derivation R S M := { Derivation.llcomp.flip <| KaehlerDifferential.D R S with invFun := Derivation.liftKaehlerDifferential left_inv := fun _ => Derivation.liftKaehlerDifferential_unique _ _ (Derivation.liftKaehlerDifferential_comp _) right_inv := Derivation.liftKaehlerDifferential_comp } #align kaehler_differential.linear_map_equiv_derivation KaehlerDifferential.linearMapEquivDerivation /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S`. -/ def KaehlerDifferential.quotientCotangentIdealRingEquiv : (S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal ≃+* S := by have : Function.RightInverse (TensorProduct.includeLeft (R := R) (S := R) (A := S) (B := S)) (↑(TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) : S ⊗[R] S →+* S) := by intro x; rw [AlgHom.coe_toRingHom, ← AlgHom.comp_apply, TensorProduct.lmul'_comp_includeLeft] rfl refine (Ideal.quotCotangent _).trans ?_ refine (Ideal.quotEquivOfEq ?_).trans (RingHom.quotientKerEquivOfRightInverse this) ext; rfl #align kaehler_differential.quotient_cotangent_ideal_ring_equiv KaehlerDifferential.quotientCotangentIdealRingEquiv /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S` as an `S`-algebra. -/ def KaehlerDifferential.quotientCotangentIdeal : ((S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal) ≃ₐ[S] S := { KaehlerDifferential.quotientCotangentIdealRingEquiv R S with commutes' := (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).apply_symm_apply } #align kaehler_differential.quotient_cotangent_ideal KaehlerDifferential.quotientCotangentIdeal theorem KaehlerDifferential.End_equiv_aux (f : S →ₐ[R] S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) : (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ ↔ (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S := by rw [AlgHom.ext_iff, AlgHom.ext_iff] apply forall_congr' intro x have e₁ : (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift (f x) = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (Ideal.Quotient.mk (KaehlerDifferential.ideal R S).cotangentIdeal <| f x) := by generalize f x = y; obtain ⟨y, rfl⟩ := Ideal.Quotient.mk_surjective y; rfl have e₂ : x = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (IsScalarTower.toAlgHom R S _ x) := (mul_one x).symm constructor · intro e exact (e₁.trans (@RingEquiv.congr_arg _ _ _ _ _ _ (KaehlerDifferential.quotientCotangentIdealRingEquiv R S) _ _ e)).trans e₂.symm · intro e; apply (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).injective exact e₁.symm.trans (e.trans e₂) #align kaehler_differential.End_equiv_aux KaehlerDifferential.End_equiv_aux /- Note: Lean is slow to synthesize theses instances (times out). Without them the endEquivDerivation' and endEquivAuxEquiv both have significant timeouts. In Mathlib 3, it was slow but not this slow. -/ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance smul_SSmod_SSmod : SMul (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Mul.toSMul _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_S_right : IsScalarTower S (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_R_right : IsScalarTower R (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_SS_right : IsScalarTower (S ⊗[R] S) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instS : Module S (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instR : Module R (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instSS : Module (S ⊗[R] S) (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- Derivations into `Ω[S⁄R]` is equivalent to derivations into `(KaehlerDifferential.ideal R S).cotangentIdeal`. -/ noncomputable def KaehlerDifferential.endEquivDerivation' : Derivation R S (Ω[S⁄R]) ≃ₗ[R] Derivation R S (ideal R S).cotangentIdeal := LinearEquiv.compDer ((KaehlerDifferential.ideal R S).cotangentEquivIdeal.restrictScalars S) #align kaehler_differential.End_equiv_derivation' KaehlerDifferential.endEquivDerivation' /-- (Implementation) An `Equiv` version of `KaehlerDifferential.End_equiv_aux`. Used in `KaehlerDifferential.endEquiv`. -/ def KaehlerDifferential.endEquivAuxEquiv : { f // (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ } ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (Equiv.refl _).subtypeEquiv (KaehlerDifferential.End_equiv_aux R S) #align kaehler_differential.End_equiv_aux_equiv KaehlerDifferential.endEquivAuxEquiv /-- The endomorphisms of `Ω[S⁄R]` corresponds to sections of the surjection `S ⊗[R] S ⧸ J ^ 2 →ₐ[R] S`, with `J` being the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ noncomputable def KaehlerDifferential.endEquiv : Module.End S (Ω[S⁄R]) ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (KaehlerDifferential.linearMapEquivDerivation R S).toEquiv.trans <| (KaehlerDifferential.endEquivDerivation' R S).toEquiv.trans <| (derivationToSquareZeroEquivLift (KaehlerDifferential.ideal R S).cotangentIdeal (KaehlerDifferential.ideal R S).cotangentIdeal_square).trans <| KaehlerDifferential.endEquivAuxEquiv R S #align kaehler_differential.End_equiv KaehlerDifferential.endEquiv section Presentation open KaehlerDifferential (D) open Finsupp (single) /-- The `S`-submodule of `S →₀ S` (the direct sum of copies of `S` indexed by `S`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` where `db` is the unit in the copy of `S` with index `b`. This is the kernel of the surjection `Finsupp.total S Ω[S⁄R] S (KaehlerDifferential.D R S)`. See `KaehlerDifferential.kerTotal_eq` and `KaehlerDifferential.total_surjective`. -/ noncomputable def KaehlerDifferential.kerTotal : Submodule S (S →₀ S) := Submodule.span S (((Set.range fun x : S × S => single x.1 1 + single x.2 1 - single (x.1 + x.2) 1) ∪ Set.range fun x : S × S => single x.2 x.1 + single x.1 x.2 - single (x.1 * x.2) 1) ∪ Set.range fun x : R => single (algebraMap R S x) 1) #align kaehler_differential.ker_total KaehlerDifferential.kerTotal unsuppress_compilation in -- Porting note: was `local notation x "𝖣" y => (KaehlerDifferential.kerTotal R S).mkQ (single y x)` -- but not having `DFunLike.coe` leads to `kerTotal_mkQ_single_smul` failing. local notation3 x "𝖣" y => DFunLike.coe (KaehlerDifferential.kerTotal R S).mkQ (single y x) theorem KaehlerDifferential.kerTotal_mkQ_single_add (x y z) : (z𝖣x + y) = (z𝖣x) + z𝖣y := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inl <| ⟨⟨_, _⟩, rfl⟩)) #align kaehler_differential.ker_total_mkq_single_add KaehlerDifferential.kerTotal_mkQ_single_add theorem KaehlerDifferential.kerTotal_mkQ_single_mul (x y z) : (z𝖣x * y) = ((z * x)𝖣y) + (z * y)𝖣x := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← @smul_eq_mul _ _ z, ← Finsupp.smul_single, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inr <| ⟨⟨_, _⟩, rfl⟩)) #align kaehler_differential.ker_total_mkq_single_mul KaehlerDifferential.kerTotal_mkQ_single_mul theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap (x y) : (y𝖣algebraMap R S x) = 0 := by rw [Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero, ← Finsupp.smul_single_one _ y] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inr <| ⟨_, rfl⟩)) #align kaehler_differential.ker_total_mkq_single_algebra_map KaehlerDifferential.kerTotal_mkQ_single_algebraMap theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one (x) : (x𝖣1) = 0 := by rw [← (algebraMap R S).map_one, KaehlerDifferential.kerTotal_mkQ_single_algebraMap] #align kaehler_differential.ker_total_mkq_single_algebra_map_one KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one theorem KaehlerDifferential.kerTotal_mkQ_single_smul (r : R) (x y) : (y𝖣r • x) = r • y𝖣x := by letI : SMulZeroClass R S := inferInstance rw [Algebra.smul_def, KaehlerDifferential.kerTotal_mkQ_single_mul, KaehlerDifferential.kerTotal_mkQ_single_algebraMap, add_zero, ← LinearMap.map_smul_of_tower, Finsupp.smul_single, mul_comm, Algebra.smul_def] #align kaehler_differential.ker_total_mkq_single_smul KaehlerDifferential.kerTotal_mkQ_single_smul /-- The (universal) derivation into `(S →₀ S) ⧸ KaehlerDifferential.kerTotal R S`. -/ noncomputable def KaehlerDifferential.derivationQuotKerTotal : Derivation R S ((S →₀ S) ⧸ KaehlerDifferential.kerTotal R S) where toFun x := 1𝖣x map_add' x y := KaehlerDifferential.kerTotal_mkQ_single_add _ _ _ _ _ map_smul' r s := KaehlerDifferential.kerTotal_mkQ_single_smul _ _ _ _ _ map_one_eq_zero' := KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one _ _ _ leibniz' a b := (KaehlerDifferential.kerTotal_mkQ_single_mul _ _ _ _ _).trans (by simp_rw [← Finsupp.smul_single_one _ (1 * _ : S)]; dsimp; simp) #align kaehler_differential.derivation_quot_ker_total KaehlerDifferential.derivationQuotKerTotal theorem KaehlerDifferential.derivationQuotKerTotal_apply (x) : KaehlerDifferential.derivationQuotKerTotal R S x = 1𝖣x := rfl #align kaehler_differential.derivation_quot_ker_total_apply KaehlerDifferential.derivationQuotKerTotal_apply theorem KaehlerDifferential.derivationQuotKerTotal_lift_comp_total : (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential.comp (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) = Submodule.mkQ _ := by apply Finsupp.lhom_ext intro a b conv_rhs => rw [← Finsupp.smul_single_one a b, LinearMap.map_smul] simp [KaehlerDifferential.derivationQuotKerTotal_apply] #align kaehler_differential.derivation_quot_ker_total_lift_comp_total KaehlerDifferential.derivationQuotKerTotal_lift_comp_total theorem KaehlerDifferential.kerTotal_eq : LinearMap.ker (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) = KaehlerDifferential.kerTotal R S := by apply le_antisymm · conv_rhs => rw [← (KaehlerDifferential.kerTotal R S).ker_mkQ] rw [← KaehlerDifferential.derivationQuotKerTotal_lift_comp_total] exact LinearMap.ker_le_ker_comp _ _ · rw [KaehlerDifferential.kerTotal, Submodule.span_le] rintro _ ((⟨⟨x, y⟩, rfl⟩ | ⟨⟨x, y⟩, rfl⟩) | ⟨x, rfl⟩) <;> dsimp <;> simp [LinearMap.mem_ker] #align kaehler_differential.ker_total_eq KaehlerDifferential.kerTotal_eq
Mathlib/RingTheory/Kaehler.lean
565
567
theorem KaehlerDifferential.total_surjective : Function.Surjective (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) := by
rw [← LinearMap.range_eq_top, Finsupp.range_total, KaehlerDifferential.span_range_derivation]
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.Logic.Equiv.Basic #align_import category_theory.limits.has_limits from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone #align category_theory.limits.limit_cone CategoryTheory.Limits.LimitCone #align category_theory.limits.limit_cone.is_limit CategoryTheory.Limits.LimitCone.isLimit /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) #align category_theory.limits.has_limit CategoryTheory.Limits.HasLimit theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_limit.mk CategoryTheory.Limits.HasLimit.mk /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit #align category_theory.limits.get_limit_cone CategoryTheory.Limits.getLimitCone variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance #align category_theory.limits.has_limits_of_shape CategoryTheory.Limits.HasLimitsOfShape /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance #align category_theory.limits.has_limits_of_size CategoryTheory.Limits.HasLimitsOfSize /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C #align category_theory.limits.has_limits CategoryTheory.Limits.HasLimits theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits.has_limits_of_shape CategoryTheory.Limits.HasLimits.has_limits_of_shape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F #align category_theory.limits.has_limit_of_has_limits_of_shape CategoryTheory.Limits.hasLimitOfHasLimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits_of_shape_of_has_limits CategoryTheory.Limits.hasLimitsOfShapeOfHasLimits -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone #align category_theory.limits.limit.cone CategoryTheory.Limits.limit.cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt #align category_theory.limits.limit CategoryTheory.Limits.limit /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j #align category_theory.limits.limit.π CategoryTheory.Limits.limit.π @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.limit.cone_X CategoryTheory.Limits.limit.cone_x @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl #align category_theory.limits.limit.cone_π CategoryTheory.Limits.limit.cone_π @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f #align category_theory.limits.limit.w CategoryTheory.Limits.limit.w /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit #align category_theory.limits.limit.is_limit CategoryTheory.Limits.limit.isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c #align category_theory.limits.limit.lift CategoryTheory.Limits.limit.lift @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl #align category_theory.limits.limit.is_limit_lift CategoryTheory.Limits.limit.isLimit_lift @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j #align category_theory.limits.limit.lift_π CategoryTheory.Limits.limit.lift_π /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α #align category_theory.limits.lim_map CategoryTheory.Limits.limMap @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j #align category_theory.limits.lim_map_π CategoryTheory.Limits.limMap_π /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c #align category_theory.limits.limit.cone_morphism CategoryTheory.Limits.limit.coneMorphism @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl #align category_theory.limits.limit.cone_morphism_hom CategoryTheory.Limits.limit.coneMorphism_hom theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp #align category_theory.limits.limit.cone_morphism_π CategoryTheory.Limits.limit.coneMorphism_π @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_hom_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_hom_comp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_inv_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_inv_comp theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ #align category_theory.limits.limit.exists_unique CategoryTheory.Limits.limit.existsUnique /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit #align category_theory.limits.limit.iso_limit_cone CategoryTheory.Limits.limit.isoLimitCone @[reassoc (attr := simp)] theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_hom_π CategoryTheory.Limits.limit.isoLimitCone_hom_π @[reassoc (attr := simp)] theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_inv_π CategoryTheory.Limits.limit.isoLimitCone_inv_π @[ext] theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.isLimit F).hom_ext w #align category_theory.limits.limit.hom_ext CategoryTheory.Limits.limit.hom_ext @[simp] theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) : limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by ext rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π] rfl #align category_theory.limits.limit.lift_map CategoryTheory.Limits.limit.lift_map @[simp] theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) := (limit.isLimit _).lift_self #align category_theory.limits.limit.lift_cone CategoryTheory.Limits.limit.lift_cone /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and cones with cone point `W`. -/ def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) := (limit.isLimit F).homIso W #align category_theory.limits.limit.hom_iso CategoryTheory.Limits.limit.homIso @[simp] theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) : (limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π := (limit.isLimit F).homIso_hom f #align category_theory.limits.limit.hom_iso_hom CategoryTheory.Limits.limit.homIso_hom /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and an explicit componentwise description of cones with cone point `W`. -/ def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.isLimit F).homIso' W #align category_theory.limits.limit.hom_iso' CategoryTheory.Limits.limit.homIso' theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by aesop_cat #align category_theory.limits.limit.lift_extend CategoryTheory.Limits.limit.lift_extend /-- If a functor `F` has a limit, so does any naturally isomorphic functor. -/ theorem hasLimitOfIso {F G : J ⥤ C} [HasLimit F] (α : F ≅ G) : HasLimit G := HasLimit.mk { cone := (Cones.postcompose α.hom).obj (limit.cone F) isLimit := (IsLimit.postcomposeHomEquiv _ _).symm (limit.isLimit F) } #align category_theory.limits.has_limit_of_iso CategoryTheory.Limits.hasLimitOfIso -- See the construction of limits from products and equalizers -- for an example usage. /-- If a functor `G` has the same collection of cones as a functor `F` which has a limit, then `G` also has a limit. -/ theorem HasLimit.ofConesIso {J K : Type u₁} [Category.{v₁} J] [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cones ≅ G.cones) [HasLimit F] : HasLimit G := HasLimit.mk ⟨_, IsLimit.ofNatIso (IsLimit.natIso (limit.isLimit F) ≪≫ h)⟩ #align category_theory.limits.has_limit.of_cones_iso CategoryTheory.Limits.HasLimit.ofConesIso /-- The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasLimit.isoOfNatIso {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) : limit F ≅ limit G := IsLimit.conePointsIsoOfNatIso (limit.isLimit F) (limit.isLimit G) w #align category_theory.limits.has_limit.iso_of_nat_iso CategoryTheory.Limits.HasLimit.isoOfNatIso @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_hom_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j := IsLimit.conePointsIsoOfNatIso_hom_comp _ _ _ _ #align category_theory.limits.has_limit.iso_of_nat_iso_hom_π CategoryTheory.Limits.HasLimit.isoOfNatIso_hom_π @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_inv_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j := IsLimit.conePointsIsoOfNatIso_inv_comp _ _ _ _ #align category_theory.limits.has_limit.iso_of_nat_iso_inv_π CategoryTheory.Limits.HasLimit.isoOfNatIso_inv_π @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_hom {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone F) (w : F ≅ G) : limit.lift F t ≫ (HasLimit.isoOfNatIso w).hom = limit.lift G ((Cones.postcompose w.hom).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_hom _ _ _ #align category_theory.limits.has_limit.lift_iso_of_nat_iso_hom CategoryTheory.Limits.HasLimit.lift_isoOfNatIso_hom @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_inv {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone G) (w : F ≅ G) : limit.lift G t ≫ (HasLimit.isoOfNatIso w).inv = limit.lift F ((Cones.postcompose w.inv).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_inv _ _ _ #align category_theory.limits.has_limit.lift_iso_of_nat_iso_inv CategoryTheory.Limits.HasLimit.lift_isoOfNatIso_inv /-- The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasLimit.isoOfEquivalence {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : limit F ≅ limit G := IsLimit.conePointsIsoOfEquivalence (limit.isLimit F) (limit.isLimit G) e w #align category_theory.limits.has_limit.iso_of_equivalence CategoryTheory.Limits.HasLimit.isoOfEquivalence @[simp] theorem HasLimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : (HasLimit.isoOfEquivalence e w).hom ≫ limit.π G k = limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp #align category_theory.limits.has_limit.iso_of_equivalence_hom_π CategoryTheory.Limits.HasLimit.isoOfEquivalence_hom_π @[simp] theorem HasLimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : (HasLimit.isoOfEquivalence e w).inv ≫ limit.π F j = limit.π G (e.functor.obj j) ≫ w.hom.app j := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp #align category_theory.limits.has_limit.iso_of_equivalence_inv_π CategoryTheory.Limits.HasLimit.isoOfEquivalence_inv_π section Pre variable (F) [HasLimit F] (E : K ⥤ J) [HasLimit (E ⋙ F)] /-- The canonical morphism from the limit of `F` to the limit of `E ⋙ F`. -/ def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) ((limit.cone F).whisker E) #align category_theory.limits.limit.pre CategoryTheory.Limits.limit.pre @[reassoc (attr := simp)] theorem limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw [IsLimit.fac] rfl #align category_theory.limits.limit.pre_π CategoryTheory.Limits.limit.pre_π @[simp] theorem limit.lift_pre (c : Cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp #align category_theory.limits.limit.lift_pre CategoryTheory.Limits.limit.lift_pre variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) [HasLimit (D ⋙ E ⋙ F)] @[simp] theorem limit.pre_pre [h : HasLimit (D ⋙ E ⋙ F)] : haveI : HasLimit ((D ⋙ E) ⋙ F) := h; limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by haveI : HasLimit ((D ⋙ E) ⋙ F) := h ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; rfl #align category_theory.limits.limit.pre_pre CategoryTheory.Limits.limit.pre_pre variable {E F} /-- - If we have particular limit cones available for `E ⋙ F` and for `F`, we obtain a formula for `limit.pre F E`. -/ theorem limit.pre_eq (s : LimitCone (E ⋙ F)) (t : LimitCone F) : limit.pre F E = (limit.isoLimitCone t).hom ≫ s.isLimit.lift (t.cone.whisker E) ≫ (limit.isoLimitCone s).inv := by aesop_cat #align category_theory.limits.limit.pre_eq CategoryTheory.Limits.limit.pre_eq end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F) [HasLimit F] (G : C ⥤ D) [HasLimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`. -/ def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) (G.mapCone (limit.cone F)) #align category_theory.limits.limit.post CategoryTheory.Limits.limit.post @[reassoc (attr := simp)] theorem limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw [IsLimit.fac] rfl #align category_theory.limits.limit.post_π CategoryTheory.Limits.limit.post_π @[simp] theorem limit.lift_post (c : Cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.mapCone c) := by ext rw [assoc, limit.post_π, ← G.map_comp, limit.lift_π, limit.lift_π] rfl #align category_theory.limits.limit.lift_post CategoryTheory.Limits.limit.lift_post @[simp] theorem limit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) [h : HasLimit ((F ⋙ G) ⋙ H)] : -- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) haveI : HasLimit (F ⋙ G ⋙ H) := h H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by haveI : HasLimit (F ⋙ G ⋙ H) := h ext; erw [assoc, limit.post_π, ← H.map_comp, limit.post_π, limit.post_π]; rfl #align category_theory.limits.limit.post_post CategoryTheory.Limits.limit.post_post end Post theorem limit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasLimit F] [HasLimit (E ⋙ F)] [HasLimit (F ⋙ G)] [h : HasLimit ((E ⋙ F) ⋙ G)] :-- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or haveI : HasLimit (E ⋙ F ⋙ G) := h G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by haveI : HasLimit (E ⋙ F ⋙ G) := h ext; erw [assoc, limit.post_π, ← G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π] #align category_theory.limits.limit.pre_post CategoryTheory.Limits.limit.pre_post open CategoryTheory.Equivalence instance hasLimitEquivalenceComp (e : K ≌ J) [HasLimit F] : HasLimit (e.functor ⋙ F) := HasLimit.mk { cone := Cone.whisker e.functor (limit.cone F) isLimit := IsLimit.whiskerEquivalence (limit.isLimit F) e } #align category_theory.limits.has_limit_equivalence_comp CategoryTheory.Limits.hasLimitEquivalenceComp -- Porting note: testing whether this still needed -- attribute [local elab_without_expected_type] inv_fun_id_assoc -- not entirely sure why this is needed /-- If a `E ⋙ F` has a limit, and `E` is an equivalence, we can construct a limit of `F`. -/ theorem hasLimitOfEquivalenceComp (e : K ≌ J) [HasLimit (e.functor ⋙ F)] : HasLimit F := by haveI : HasLimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasLimitEquivalenceComp e.symm apply hasLimitOfIso (e.invFunIdAssoc F) #align category_theory.limits.has_limit_of_equivalence_comp CategoryTheory.Limits.hasLimitOfEquivalenceComp -- `hasLimitCompEquivalence` and `hasLimitOfCompEquivalence` -- are proved in `CategoryTheory/Adjunction/Limits.lean`. section LimFunctor variable [HasLimitsOfShape J C] section /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ @[simps] def lim : (J ⥤ C) ⥤ C where obj F := limit F map α := limMap α map_id F := by apply Limits.limit.hom_ext; intro j erw [limMap_π, Category.id_comp, Category.comp_id] map_comp α β := by apply Limits.limit.hom_ext; intro j erw [assoc, IsLimit.fac, IsLimit.fac, ← assoc, IsLimit.fac, assoc]; rfl #align category_theory.limits.lim CategoryTheory.Limits.lim #align category_theory.limits.lim_map_eq_lim_map CategoryTheory.Limits.lim_map end variable {G : J ⥤ C} (α : F ⟶ G) theorem limit.map_pre [HasLimitsOfShape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whiskerLeft E α) := by ext simp #align category_theory.limits.limit.map_pre CategoryTheory.Limits.limit.map_pre theorem limit.map_pre' [HasLimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whiskerRight α F) := by ext1; simp [← category.assoc] #align category_theory.limits.limit.map_pre' CategoryTheory.Limits.limit.map_pre' theorem limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (Functor.leftUnitor F).inv := by aesop_cat #align category_theory.limits.limit.id_pre CategoryTheory.Limits.limit.id_pre theorem limit.map_post {D : Type u'} [Category.{v'} D] [HasLimitsOfShape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (limMap α) ≫ limit.post G H = limit.post F H ≫ limMap (whiskerRight α H) := by ext simp only [whiskerRight_app, limMap_π, assoc, limit.post_π_assoc, limit.post_π, ← H.map_comp] #align category_theory.limits.limit.map_post CategoryTheory.Limits.limit.map_post /-- The isomorphism between morphisms from `W` to the cone point of the limit cone for `F` and cones over `F` with cone point `W` is natural in `F`. -/ def limYoneda : lim ⋙ yoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => limit.homIso F (unop W) #align category_theory.limits.lim_yoneda CategoryTheory.Limits.limYoneda /-- The constant functor and limit functor are adjoint to each other-/ def constLimAdj : (const J : C ⥤ J ⥤ C) ⊣ lim where homEquiv c g := { toFun := fun f => limit.lift _ ⟨c, f⟩ invFun := fun f => { app := fun j => f ≫ limit.π _ _ } left_inv := by aesop_cat right_inv := by aesop_cat } unit := { app := fun c => limit.lift _ ⟨_, 𝟙 _⟩ } counit := { app := fun g => { app := limit.π _ } } -- This used to be automatic before leanprover/lean4#2644 homEquiv_unit := by -- Sad that aesop can no longer do this! intros dsimp ext simp #align category_theory.limits.const_lim_adj CategoryTheory.Limits.constLimAdj instance : IsRightAdjoint (lim : (J ⥤ C) ⥤ C) := ⟨_, ⟨constLimAdj⟩⟩ end LimFunctor instance limMap_mono' {F G : J ⥤ C} [HasLimitsOfShape J C] (α : F ⟶ G) [Mono α] : Mono (limMap α) := (lim : (J ⥤ C) ⥤ C).map_mono α #align category_theory.limits.lim_map_mono' CategoryTheory.Limits.limMap_mono' instance limMap_mono {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) [∀ j, Mono (α.app j)] : Mono (limMap α) := ⟨fun {Z} u v h => limit.hom_ext fun j => (cancel_mono (α.app j)).1 <| by simpa using h =≫ limit.π _ j⟩ #align category_theory.limits.lim_map_mono CategoryTheory.Limits.limMap_mono section Adjunction variable {L : (J ⥤ C) ⥤ C} (adj : Functor.const _ ⊣ L) /- The fact that the existence of limits of shape `J` is equivalent to the existence of a right adjoint to the constant functor `C ⥤ (J ⥤ C)` is obtained in the file `Mathlib.CategoryTheory.Limits.ConeCategory`: see the lemma `hasLimitsOfShape_iff_isLeftAdjoint_const`. In the definitions below, given an adjunction `adj : Functor.const _ ⊣ (L : (J ⥤ C) ⥤ C)`, we directly construct a limit cone for any `F : J ⥤ C`. -/ /-- The limit cone obtained from a right adjoint of the constant functor. -/ @[simps] noncomputable def coneOfAdj (F : J ⥤ C) : Cone F where pt := L.obj F π := adj.counit.app F /-- The cones defined by `coneOfAdj` are limit cones. -/ @[simps] def isLimitConeOfAdj (F : J ⥤ C) : IsLimit (coneOfAdj adj F) where lift s := adj.homEquiv _ _ s.π fac s j := by have eq := NatTrans.congr_app (adj.counit.naturality s.π) j have eq' := NatTrans.congr_app (adj.left_triangle_components s.pt) j dsimp at eq eq' ⊢ rw [Adjunction.homEquiv_unit, assoc, eq, reassoc_of% eq'] uniq s m hm := (adj.homEquiv _ _).symm.injective (by ext j; simpa using hm j) end Adjunction /-- We can transport limits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasLimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasLimitsOfShape J C] : HasLimitsOfShape J' C := by constructor intro F apply hasLimitOfEquivalenceComp e #align category_theory.limits.has_limits_of_shape_of_equivalence CategoryTheory.Limits.hasLimitsOfShape_of_equivalence variable (C) /-- A category that has larger limits also has smaller limits. -/ theorem hasLimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₂, u₂} C where has_limits_of_shape J {_} := hasLimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasLimitsOfSizeShrink.{v u} C` tries to obtain `HasLimitsOfSize.{v u} C` from some other `HasLimitsOfSize C`. -/ theorem hasLimitsOfSizeShrink [HasLimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasLimitsOfSize.{v₁, u₁} C := hasLimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C #align category_theory.limits.has_limits_of_size_shrink CategoryTheory.Limits.hasLimitsOfSizeShrink instance (priority := 100) hasSmallestLimitsOfHasLimits [HasLimits C] : HasLimitsOfSize.{0, 0} C := hasLimitsOfSizeShrink.{0, 0} C #align category_theory.limits.has_smallest_limits_of_has_limits CategoryTheory.Limits.hasSmallestLimitsOfHasLimits end Limit section Colimit /-- `ColimitCocone F` contains a cocone over `F` together with the information that it is a colimit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure ColimitCocone (F : J ⥤ C) where /-- The cocone itself -/ cocone : Cocone F /-- The proof that it is the colimit cocone -/ isColimit : IsColimit cocone #align category_theory.limits.colimit_cocone CategoryTheory.Limits.ColimitCocone #align category_theory.limits.colimit_cocone.is_colimit CategoryTheory.Limits.ColimitCocone.isColimit /-- `HasColimit F` represents the mere existence of a colimit for `F`. -/ class HasColimit (F : J ⥤ C) : Prop where mk' :: /-- There exists a colimit for `F` -/ exists_colimit : Nonempty (ColimitCocone F) #align category_theory.limits.has_colimit CategoryTheory.Limits.HasColimit theorem HasColimit.mk {F : J ⥤ C} (d : ColimitCocone F) : HasColimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_colimit.mk CategoryTheory.Limits.HasColimit.mk /-- Use the axiom of choice to extract explicit `ColimitCocone F` from `HasColimit F`. -/ def getColimitCocone (F : J ⥤ C) [HasColimit F] : ColimitCocone F := Classical.choice <| HasColimit.exists_colimit #align category_theory.limits.get_colimit_cocone CategoryTheory.Limits.getColimitCocone variable (J C) /-- `C` has colimits of shape `J` if there exists a colimit for every functor `F : J ⥤ C`. -/ class HasColimitsOfShape : Prop where /-- All `F : J ⥤ C` have colimits for a fixed `J` -/ has_colimit : ∀ F : J ⥤ C, HasColimit F := by infer_instance #align category_theory.limits.has_colimits_of_shape CategoryTheory.Limits.HasColimitsOfShape /-- `C` has all colimits of size `v₁ u₁` (`HasColimitsOfSize.{v₁ u₁} C`) if it has colimits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasColimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All `F : J ⥤ C` have colimits for all small `J` -/ has_colimits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasColimitsOfShape J C := by infer_instance #align category_theory.limits.has_colimits_of_size CategoryTheory.Limits.HasColimitsOfSize /-- `C` has all (small) colimits if it has colimits of every shape that is as big as its hom-sets. -/ abbrev HasColimits (C : Type u) [Category.{v} C] : Prop := HasColimitsOfSize.{v, v} C #align category_theory.limits.has_colimits CategoryTheory.Limits.HasColimits theorem HasColimits.hasColimitsOfShape {C : Type u} [Category.{v} C] [HasColimits C] (J : Type v) [Category.{v} J] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J #align category_theory.limits.has_colimits.has_colimits_of_shape CategoryTheory.Limits.HasColimits.hasColimitsOfShape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasColimitOfHasColimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasColimitsOfShape J C] (F : J ⥤ C) : HasColimit F := HasColimitsOfShape.has_colimit F #align category_theory.limits.has_colimit_of_has_colimits_of_shape CategoryTheory.Limits.hasColimitOfHasColimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasColimitsOfShapeOfHasColimitsOfSize {J : Type u₁} [Category.{v₁} J] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J #align category_theory.limits.has_colimits_of_shape_of_has_colimits_of_size CategoryTheory.Limits.hasColimitsOfShapeOfHasColimitsOfSize -- Interface to the `HasColimit` class. /-- An arbitrary choice of colimit cocone of a functor. -/ def colimit.cocone (F : J ⥤ C) [HasColimit F] : Cocone F := (getColimitCocone F).cocone #align category_theory.limits.colimit.cocone CategoryTheory.Limits.colimit.cocone /-- An arbitrary choice of colimit object of a functor. -/ def colimit (F : J ⥤ C) [HasColimit F] := (colimit.cocone F).pt #align category_theory.limits.colimit CategoryTheory.Limits.colimit /-- The coprojection from a value of the functor to the colimit object. -/ def colimit.ι (F : J ⥤ C) [HasColimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j #align category_theory.limits.colimit.ι CategoryTheory.Limits.colimit.ι @[simp] theorem colimit.cocone_ι {F : J ⥤ C} [HasColimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl #align category_theory.limits.colimit.cocone_ι CategoryTheory.Limits.colimit.cocone_ι @[simp] theorem colimit.cocone_x {F : J ⥤ C} [HasColimit F] : (colimit.cocone F).pt = colimit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.colimit.cocone_X CategoryTheory.Limits.colimit.cocone_x @[reassoc (attr := simp)] theorem colimit.w (F : J ⥤ C) [HasColimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f #align category_theory.limits.colimit.w CategoryTheory.Limits.colimit.w /-- Evidence that the arbitrary choice of cocone is a colimit cocone. -/ def colimit.isColimit (F : J ⥤ C) [HasColimit F] : IsColimit (colimit.cocone F) := (getColimitCocone F).isColimit #align category_theory.limits.colimit.is_colimit CategoryTheory.Limits.colimit.isColimit /-- The morphism from the colimit object to the cone point of any other cocone. -/ def colimit.desc (F : J ⥤ C) [HasColimit F] (c : Cocone F) : colimit F ⟶ c.pt := (colimit.isColimit F).desc c #align category_theory.limits.colimit.desc CategoryTheory.Limits.colimit.desc @[simp] theorem colimit.isColimit_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.isColimit F).desc c = colimit.desc F c := rfl #align category_theory.limits.colimit.is_colimit_desc CategoryTheory.Limits.colimit.isColimit_desc /-- We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`, and combined with `colimit.ext` we rely on these lemmas for many calculations. However, since `Category.assoc` is a `@[simp]` lemma, often expressions are right associated, and it's hard to apply these lemmas about `colimit.ι`. We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism. (see `Tactic/reassoc_axiom.lean`) -/ @[reassoc (attr := simp)] theorem colimit.ι_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := IsColimit.fac _ c j #align category_theory.limits.colimit.ι_desc CategoryTheory.Limits.colimit.ι_desc /-- Functoriality of colimits. Usually this morphism should be accessed through `colim.map`, but may be needed separately when you have specified colimits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) : colimit F ⟶ colimit G := IsColimit.map (colimit.isColimit F) _ α #align category_theory.limits.colim_map CategoryTheory.Limits.colimMap @[reassoc (attr := simp)] theorem ι_colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) (j : J) : colimit.ι F j ≫ colimMap α = α.app j ≫ colimit.ι G j := colimit.ι_desc _ j #align category_theory.limits.ι_colim_map CategoryTheory.Limits.ι_colimMap /-- The cocone morphism from the arbitrary choice of colimit cocone to any cocone. -/ def colimit.coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) : colimit.cocone F ⟶ c := (colimit.isColimit F).descCoconeMorphism c #align category_theory.limits.colimit.cocone_morphism CategoryTheory.Limits.colimit.coconeMorphism @[simp] theorem colimit.coconeMorphism_hom {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.coconeMorphism c).hom = colimit.desc F c := rfl #align category_theory.limits.colimit.cocone_morphism_hom CategoryTheory.Limits.colimit.coconeMorphism_hom theorem colimit.ι_coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ (colimit.coconeMorphism c).hom = c.ι.app j := by simp #align category_theory.limits.colimit.ι_cocone_morphism CategoryTheory.Limits.colimit.ι_coconeMorphism @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_hom {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hc).hom = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _ #align category_theory.limits.colimit.comp_cocone_point_unique_up_to_iso_hom CategoryTheory.Limits.colimit.comp_coconePointUniqueUpToIso_hom @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_inv {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso hc (colimit.isColimit _)).inv = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _ #align category_theory.limits.colimit.comp_cocone_point_unique_up_to_iso_inv CategoryTheory.Limits.colimit.comp_coconePointUniqueUpToIso_inv theorem colimit.existsUnique {F : J ⥤ C} [HasColimit F] (t : Cocone F) : ∃! d : colimit F ⟶ t.pt, ∀ j, colimit.ι F j ≫ d = t.ι.app j := (colimit.isColimit F).existsUnique _ #align category_theory.limits.colimit.exists_unique CategoryTheory.Limits.colimit.existsUnique /-- Given any other colimit cocone for `F`, the chosen `colimit F` is isomorphic to the cocone point. -/ def colimit.isoColimitCocone {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) : colimit F ≅ t.cocone.pt := IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) t.isColimit #align category_theory.limits.colimit.iso_colimit_cocone CategoryTheory.Limits.colimit.isoColimitCocone @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_hom {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : colimit.ι F j ≫ (colimit.isoColimitCocone t).hom = t.cocone.ι.app j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat #align category_theory.limits.colimit.iso_colimit_cocone_ι_hom CategoryTheory.Limits.colimit.isoColimitCocone_ι_hom @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_inv {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : t.cocone.ι.app j ≫ (colimit.isoColimitCocone t).inv = colimit.ι F j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat #align category_theory.limits.colimit.iso_colimit_cocone_ι_inv CategoryTheory.Limits.colimit.isoColimitCocone_ι_inv @[ext] theorem colimit.hom_ext {F : J ⥤ C} [HasColimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.isColimit F).hom_ext w #align category_theory.limits.colimit.hom_ext CategoryTheory.Limits.colimit.hom_ext @[simp] theorem colimit.desc_cocone {F : J ⥤ C} [HasColimit F] : colimit.desc F (colimit.cocone F) = 𝟙 (colimit F) := (colimit.isColimit _).desc_self #align category_theory.limits.colimit.desc_cocone CategoryTheory.Limits.colimit.desc_cocone /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and cocones with cone point `W`. -/ def colimit.homIso (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ F.cocones.obj W := (colimit.isColimit F).homIso W #align category_theory.limits.colimit.hom_iso CategoryTheory.Limits.colimit.homIso @[simp] theorem colimit.homIso_hom (F : J ⥤ C) [HasColimit F] {W : C} (f : ULift (colimit F ⟶ W)) : (colimit.homIso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f.down := (colimit.isColimit F).homIso_hom f #align category_theory.limits.colimit.hom_iso_hom CategoryTheory.Limits.colimit.homIso_hom /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and an explicit componentwise description of cocones with cone point `W`. -/ def colimit.homIso' (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.isColimit F).homIso' W #align category_theory.limits.colimit.hom_iso' CategoryTheory.Limits.colimit.homIso' theorem colimit.desc_extend (F : J ⥤ C) [HasColimit F] (c : Cocone F) {X : C} (f : c.pt ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := by ext1; rw [← Category.assoc]; simp #align category_theory.limits.colimit.desc_extend CategoryTheory.Limits.colimit.desc_extend -- This has the isomorphism pointing in the opposite direction than in `has_limit_of_iso`. -- This is intentional; it seems to help with elaboration. /-- If `F` has a colimit, so does any naturally isomorphic functor. -/ theorem hasColimitOfIso {F G : J ⥤ C} [HasColimit F] (α : G ≅ F) : HasColimit G := HasColimit.mk { cocone := (Cocones.precompose α.hom).obj (colimit.cocone F) isColimit := (IsColimit.precomposeHomEquiv _ _).symm (colimit.isColimit F) } #align category_theory.limits.has_colimit_of_iso CategoryTheory.Limits.hasColimitOfIso /-- If a functor `G` has the same collection of cocones as a functor `F` which has a colimit, then `G` also has a colimit. -/ theorem HasColimit.ofCoconesIso {K : Type u₁} [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cocones ≅ G.cocones) [HasColimit F] : HasColimit G := HasColimit.mk ⟨_, IsColimit.ofNatIso (IsColimit.natIso (colimit.isColimit F) ≪≫ h)⟩ #align category_theory.limits.has_colimit.of_cocones_iso CategoryTheory.Limits.HasColimit.ofCoconesIso /-- The colimits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasColimit.isoOfNatIso {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfNatIso (colimit.isColimit F) (colimit.isColimit G) w #align category_theory.limits.has_colimit.iso_of_nat_iso CategoryTheory.Limits.HasColimit.isoOfNatIso @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_hom {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfNatIso w).hom = w.hom.app j ≫ colimit.ι G j := IsColimit.comp_coconePointsIsoOfNatIso_hom _ _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_ι_hom CategoryTheory.Limits.HasColimit.isoOfNatIso_ι_hom @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_inv {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι G j ≫ (HasColimit.isoOfNatIso w).inv = w.inv.app j ≫ colimit.ι F j := IsColimit.comp_coconePointsIsoOfNatIso_inv _ _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_ι_inv CategoryTheory.Limits.HasColimit.isoOfNatIso_ι_inv @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_hom_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone G) (w : F ≅ G) : (HasColimit.isoOfNatIso w).hom ≫ colimit.desc G t = colimit.desc F ((Cocones.precompose w.hom).obj _) := IsColimit.coconePointsIsoOfNatIso_hom_desc _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_hom_desc CategoryTheory.Limits.HasColimit.isoOfNatIso_hom_desc @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_inv_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone F) (w : F ≅ G) : (HasColimit.isoOfNatIso w).inv ≫ colimit.desc F t = colimit.desc G ((Cocones.precompose w.inv).obj _) := IsColimit.coconePointsIsoOfNatIso_inv_desc _ _ _ #align category_theory.limits.has_colimit.iso_of_nat_iso_inv_desc CategoryTheory.Limits.HasColimit.isoOfNatIso_inv_desc /-- The colimits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasColimit.isoOfEquivalence {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfEquivalence (colimit.isColimit F) (colimit.isColimit G) e w #align category_theory.limits.has_colimit.iso_of_equivalence CategoryTheory.Limits.HasColimit.isoOfEquivalence @[simp] theorem HasColimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfEquivalence e w).hom = F.map (e.unit.app j) ≫ w.inv.app _ ≫ colimit.ι G _ := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] #align category_theory.limits.has_colimit.iso_of_equivalence_hom_π CategoryTheory.Limits.HasColimit.isoOfEquivalence_hom_π @[simp]
Mathlib/CategoryTheory/Limits/HasLimits.lean
976
980
theorem HasColimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : colimit.ι G k ≫ (HasColimit.isoOfEquivalence e w).inv = G.map (e.counitInv.app k) ≫ w.hom.app (e.inverse.obj k) ≫ colimit.ι F (e.inverse.obj k) := by
simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Topology.Order.MonotoneContinuity import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.Instances.NNReal import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Order.T5 #align_import topology.instances.ennreal from "leanprover-community/mathlib"@"ec4b2eeb50364487f80421c0b4c41328a611f30d" /-! # Topology on extended non-negative reals -/ noncomputable section open Set Filter Metric Function open scoped Classical Topology ENNReal NNReal Filter variable {α : Type*} {β : Type*} {γ : Type*} namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞} section TopologicalSpace open TopologicalSpace /-- Topology on `ℝ≥0∞`. Note: this is different from the `EMetricSpace` topology. The `EMetricSpace` topology has `IsOpen {∞}`, while this topology doesn't have singleton elements. -/ instance : TopologicalSpace ℝ≥0∞ := Preorder.topology ℝ≥0∞ instance : OrderTopology ℝ≥0∞ := ⟨rfl⟩ -- short-circuit type class inference instance : T2Space ℝ≥0∞ := inferInstance instance : T5Space ℝ≥0∞ := inferInstance instance : T4Space ℝ≥0∞ := inferInstance instance : SecondCountableTopology ℝ≥0∞ := orderIsoUnitIntervalBirational.toHomeomorph.embedding.secondCountableTopology instance : MetrizableSpace ENNReal := orderIsoUnitIntervalBirational.toHomeomorph.embedding.metrizableSpace theorem embedding_coe : Embedding ((↑) : ℝ≥0 → ℝ≥0∞) := coe_strictMono.embedding_of_ordConnected <| by rw [range_coe']; exact ordConnected_Iio #align ennreal.embedding_coe ENNReal.embedding_coe theorem isOpen_ne_top : IsOpen { a : ℝ≥0∞ | a ≠ ∞ } := isOpen_ne #align ennreal.is_open_ne_top ENNReal.isOpen_ne_top theorem isOpen_Ico_zero : IsOpen (Ico 0 b) := by rw [ENNReal.Ico_eq_Iio] exact isOpen_Iio #align ennreal.is_open_Ico_zero ENNReal.isOpen_Ico_zero theorem openEmbedding_coe : OpenEmbedding ((↑) : ℝ≥0 → ℝ≥0∞) := ⟨embedding_coe, by rw [range_coe']; exact isOpen_Iio⟩ #align ennreal.open_embedding_coe ENNReal.openEmbedding_coe theorem coe_range_mem_nhds : range ((↑) : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) := IsOpen.mem_nhds openEmbedding_coe.isOpen_range <| mem_range_self _ #align ennreal.coe_range_mem_nhds ENNReal.coe_range_mem_nhds @[norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {a : ℝ≥0} : Tendsto (fun a => (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm #align ennreal.tendsto_coe ENNReal.tendsto_coe theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ≥0∞) := embedding_coe.continuous #align ennreal.continuous_coe ENNReal.continuous_coe theorem continuous_coe_iff {α} [TopologicalSpace α] {f : α → ℝ≥0} : (Continuous fun a => (f a : ℝ≥0∞)) ↔ Continuous f := embedding_coe.continuous_iff.symm #align ennreal.continuous_coe_iff ENNReal.continuous_coe_iff theorem nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map (↑) := (openEmbedding_coe.map_nhds_eq r).symm #align ennreal.nhds_coe ENNReal.nhds_coe theorem tendsto_nhds_coe_iff {α : Type*} {l : Filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} : Tendsto f (𝓝 ↑x) l ↔ Tendsto (f ∘ (↑) : ℝ≥0 → α) (𝓝 x) l := by rw [nhds_coe, tendsto_map'_iff] #align ennreal.tendsto_nhds_coe_iff ENNReal.tendsto_nhds_coe_iff theorem continuousAt_coe_iff {α : Type*} [TopologicalSpace α] {x : ℝ≥0} {f : ℝ≥0∞ → α} : ContinuousAt f ↑x ↔ ContinuousAt (f ∘ (↑) : ℝ≥0 → α) x := tendsto_nhds_coe_iff #align ennreal.continuous_at_coe_iff ENNReal.continuousAt_coe_iff theorem nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map fun p : ℝ≥0 × ℝ≥0 => (↑p.1, ↑p.2) := ((openEmbedding_coe.prod openEmbedding_coe).map_nhds_eq (r, p)).symm #align ennreal.nhds_coe_coe ENNReal.nhds_coe_coe theorem continuous_ofReal : Continuous ENNReal.ofReal := (continuous_coe_iff.2 continuous_id).comp continuous_real_toNNReal #align ennreal.continuous_of_real ENNReal.continuous_ofReal theorem tendsto_ofReal {f : Filter α} {m : α → ℝ} {a : ℝ} (h : Tendsto m f (𝓝 a)) : Tendsto (fun a => ENNReal.ofReal (m a)) f (𝓝 (ENNReal.ofReal a)) := (continuous_ofReal.tendsto a).comp h #align ennreal.tendsto_of_real ENNReal.tendsto_ofReal theorem tendsto_toNNReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toNNReal (𝓝 a) (𝓝 a.toNNReal) := by lift a to ℝ≥0 using ha rw [nhds_coe, tendsto_map'_iff] exact tendsto_id #align ennreal.tendsto_to_nnreal ENNReal.tendsto_toNNReal theorem eventuallyEq_of_toReal_eventuallyEq {l : Filter α} {f g : α → ℝ≥0∞} (hfi : ∀ᶠ x in l, f x ≠ ∞) (hgi : ∀ᶠ x in l, g x ≠ ∞) (hfg : (fun x => (f x).toReal) =ᶠ[l] fun x => (g x).toReal) : f =ᶠ[l] g := by filter_upwards [hfi, hgi, hfg] with _ hfx hgx _ rwa [← ENNReal.toReal_eq_toReal hfx hgx] #align ennreal.eventually_eq_of_to_real_eventually_eq ENNReal.eventuallyEq_of_toReal_eventuallyEq theorem continuousOn_toNNReal : ContinuousOn ENNReal.toNNReal { a | a ≠ ∞ } := fun _a ha => ContinuousAt.continuousWithinAt (tendsto_toNNReal ha) #align ennreal.continuous_on_to_nnreal ENNReal.continuousOn_toNNReal theorem tendsto_toReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toReal (𝓝 a) (𝓝 a.toReal) := NNReal.tendsto_coe.2 <| tendsto_toNNReal ha #align ennreal.tendsto_to_real ENNReal.tendsto_toReal lemma continuousOn_toReal : ContinuousOn ENNReal.toReal { a | a ≠ ∞ } := NNReal.continuous_coe.comp_continuousOn continuousOn_toNNReal lemma continuousAt_toReal (hx : x ≠ ∞) : ContinuousAt ENNReal.toReal x := continuousOn_toReal.continuousAt (isOpen_ne_top.mem_nhds_iff.mpr hx) /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def neTopHomeomorphNNReal : { a | a ≠ ∞ } ≃ₜ ℝ≥0 where toEquiv := neTopEquivNNReal continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toNNReal continuous_invFun := continuous_coe.subtype_mk _ #align ennreal.ne_top_homeomorph_nnreal ENNReal.neTopHomeomorphNNReal /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def ltTopHomeomorphNNReal : { a | a < ∞ } ≃ₜ ℝ≥0 := by refine (Homeomorph.setCongr ?_).trans neTopHomeomorphNNReal simp only [mem_setOf_eq, lt_top_iff_ne_top] #align ennreal.lt_top_homeomorph_nnreal ENNReal.ltTopHomeomorphNNReal theorem nhds_top : 𝓝 ∞ = ⨅ (a) (_ : a ≠ ∞), 𝓟 (Ioi a) := nhds_top_order.trans <| by simp [lt_top_iff_ne_top, Ioi] #align ennreal.nhds_top ENNReal.nhds_top theorem nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi ↑r) := nhds_top.trans <| iInf_ne_top _ #align ennreal.nhds_top' ENNReal.nhds_top' theorem nhds_top_basis : (𝓝 ∞).HasBasis (fun a => a < ∞) fun a => Ioi a := _root_.nhds_top_basis #align ennreal.nhds_top_basis ENNReal.nhds_top_basis theorem tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a := by simp only [nhds_top', tendsto_iInf, tendsto_principal, mem_Ioi] #align ennreal.tendsto_nhds_top_iff_nnreal ENNReal.tendsto_nhds_top_iff_nnreal theorem tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a := tendsto_nhds_top_iff_nnreal.trans ⟨fun h n => by simpa only [ENNReal.coe_natCast] using h n, fun h x => let ⟨n, hn⟩ := exists_nat_gt x (h n).mono fun y => lt_trans <| by rwa [← ENNReal.coe_natCast, coe_lt_coe]⟩ #align ennreal.tendsto_nhds_top_iff_nat ENNReal.tendsto_nhds_top_iff_nat theorem tendsto_nhds_top {m : α → ℝ≥0∞} {f : Filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : Tendsto m f (𝓝 ∞) := tendsto_nhds_top_iff_nat.2 h #align ennreal.tendsto_nhds_top ENNReal.tendsto_nhds_top theorem tendsto_nat_nhds_top : Tendsto (fun n : ℕ => ↑n) atTop (𝓝 ∞) := tendsto_nhds_top fun n => mem_atTop_sets.2 ⟨n + 1, fun _m hm => mem_setOf.2 <| Nat.cast_lt.2 <| Nat.lt_of_succ_le hm⟩ #align ennreal.tendsto_nat_nhds_top ENNReal.tendsto_nat_nhds_top @[simp, norm_cast] theorem tendsto_coe_nhds_top {f : α → ℝ≥0} {l : Filter α} : Tendsto (fun x => (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ Tendsto f l atTop := by rw [tendsto_nhds_top_iff_nnreal, atTop_basis_Ioi.tendsto_right_iff]; simp #align ennreal.tendsto_coe_nhds_top ENNReal.tendsto_coe_nhds_top theorem tendsto_ofReal_atTop : Tendsto ENNReal.ofReal atTop (𝓝 ∞) := tendsto_coe_nhds_top.2 tendsto_real_toNNReal_atTop #align ennreal.tendsto_of_real_at_top ENNReal.tendsto_ofReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅ (a) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp [pos_iff_ne_zero, Iio] #align ennreal.nhds_zero ENNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) fun a => Iio a := nhds_bot_basis #align ennreal.nhds_zero_basis ENNReal.nhds_zero_basis theorem nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) Iic := nhds_bot_basis_Iic #align ennreal.nhds_zero_basis_Iic ENNReal.nhds_zero_basis_Iic -- Porting note (#11215): TODO: add a TC for `≠ ∞`? @[instance] theorem nhdsWithin_Ioi_coe_neBot {r : ℝ≥0} : (𝓝[>] (r : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_self_neBot' ⟨∞, ENNReal.coe_lt_top⟩ #align ennreal.nhds_within_Ioi_coe_ne_bot ENNReal.nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_zero_neBot : (𝓝[>] (0 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot #align ennreal.nhds_within_Ioi_zero_ne_bot ENNReal.nhdsWithin_Ioi_zero_neBot @[instance] theorem nhdsWithin_Ioi_one_neBot : (𝓝[>] (1 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_nat_neBot (n : ℕ) : (𝓝[>] (n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_ofNat_nebot (n : ℕ) [n.AtLeastTwo] : (𝓝[>] (OfNat.ofNat n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Iio_neBot [NeZero x] : (𝓝[<] x).NeBot := nhdsWithin_Iio_self_neBot' ⟨0, NeZero.pos x⟩ /-- Closed intervals `Set.Icc (x - ε) (x + ε)`, `ε ≠ 0`, form a basis of neighborhoods of an extended nonnegative real number `x ≠ ∞`. We use `Set.Icc` instead of `Set.Ioo` because this way the statement works for `x = 0`. -/ theorem hasBasis_nhds_of_ne_top' (xt : x ≠ ∞) : (𝓝 x).HasBasis (· ≠ 0) (fun ε => Icc (x - ε) (x + ε)) := by rcases (zero_le x).eq_or_gt with rfl | x0 · simp_rw [zero_tsub, zero_add, ← bot_eq_zero, Icc_bot, ← bot_lt_iff_ne_bot] exact nhds_bot_basis_Iic · refine (nhds_basis_Ioo' ⟨_, x0⟩ ⟨_, xt.lt_top⟩).to_hasBasis ?_ fun ε ε0 => ?_ · rintro ⟨a, b⟩ ⟨ha, hb⟩ rcases exists_between (tsub_pos_of_lt ha) with ⟨ε, ε0, hε⟩ rcases lt_iff_exists_add_pos_lt.1 hb with ⟨δ, δ0, hδ⟩ refine ⟨min ε δ, (lt_min ε0 (coe_pos.2 δ0)).ne', Icc_subset_Ioo ?_ ?_⟩ · exact lt_tsub_comm.2 ((min_le_left _ _).trans_lt hε) · exact (add_le_add_left (min_le_right _ _) _).trans_lt hδ · exact ⟨(x - ε, x + ε), ⟨ENNReal.sub_lt_self xt x0.ne' ε0, lt_add_right xt ε0⟩, Ioo_subset_Icc_self⟩ theorem hasBasis_nhds_of_ne_top (xt : x ≠ ∞) : (𝓝 x).HasBasis (0 < ·) (fun ε => Icc (x - ε) (x + ε)) := by simpa only [pos_iff_ne_zero] using hasBasis_nhds_of_ne_top' xt theorem Icc_mem_nhds (xt : x ≠ ∞) (ε0 : ε ≠ 0) : Icc (x - ε) (x + ε) ∈ 𝓝 x := (hasBasis_nhds_of_ne_top' xt).mem_of_mem ε0 #align ennreal.Icc_mem_nhds ENNReal.Icc_mem_nhds theorem nhds_of_ne_top (xt : x ≠ ∞) : 𝓝 x = ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) := (hasBasis_nhds_of_ne_top xt).eq_biInf #align ennreal.nhds_of_ne_top ENNReal.nhds_of_ne_top theorem biInf_le_nhds : ∀ x : ℝ≥0∞, ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) ≤ 𝓝 x | ∞ => iInf₂_le_of_le 1 one_pos <| by simpa only [← coe_one, top_sub_coe, top_add, Icc_self, principal_singleton] using pure_le_nhds _ | (x : ℝ≥0) => (nhds_of_ne_top coe_ne_top).ge -- Porting note (#10756): new lemma protected theorem tendsto_nhds_of_Icc {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε)) : Tendsto u f (𝓝 a) := by refine Tendsto.mono_right ?_ (biInf_le_nhds _) simpa only [tendsto_iInf, tendsto_principal] /-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_iInf, tendsto_principal] #align ennreal.tendsto_nhds ENNReal.tendsto_nhds protected theorem tendsto_nhds_zero {f : Filter α} {u : α → ℝ≥0∞} : Tendsto u f (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ≤ ε := nhds_zero_basis_Iic.tendsto_right_iff #align ennreal.tendsto_nhds_zero ENNReal.tendsto_nhds_zero protected theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto f atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ∈ Icc (a - ε) (a + ε) := .trans (atTop_basis.tendsto_iff (hasBasis_nhds_of_ne_top ha)) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top ENNReal.tendsto_atTop instance : ContinuousAdd ℝ≥0∞ := by refine ⟨continuous_iff_continuousAt.2 ?_⟩ rintro ⟨_ | a, b⟩ · exact tendsto_nhds_top_mono' continuousAt_fst fun p => le_add_right le_rfl rcases b with (_ | b) · exact tendsto_nhds_top_mono' continuousAt_snd fun p => le_add_left le_rfl simp only [ContinuousAt, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (· ∘ ·), tendsto_coe, tendsto_add] protected theorem tendsto_atTop_zero [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} : Tendsto f atTop (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε := .trans (atTop_basis.tendsto_iff nhds_zero_basis_Iic) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top_zero ENNReal.tendsto_atTop_zero theorem tendsto_sub : ∀ {a b : ℝ≥0∞}, (a ≠ ∞ ∨ b ≠ ∞) → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) (𝓝 (a, b)) (𝓝 (a - b)) | ∞, ∞, h => by simp only [ne_eq, not_true_eq_false, or_self] at h | ∞, (b : ℝ≥0), _ => by rw [top_sub_coe, tendsto_nhds_top_iff_nnreal] refine fun x => ((lt_mem_nhds <| @coe_lt_top (b + 1 + x)).prod_nhds (ge_mem_nhds <| coe_lt_coe.2 <| lt_add_one b)).mono fun y hy => ?_ rw [lt_tsub_iff_left] calc y.2 + x ≤ ↑(b + 1) + x := add_le_add_right hy.2 _ _ < y.1 := hy.1 | (a : ℝ≥0), ∞, _ => by rw [sub_top] refine (tendsto_pure.2 ?_).mono_right (pure_le_nhds _) exact ((gt_mem_nhds <| coe_lt_coe.2 <| lt_add_one a).prod_nhds (lt_mem_nhds <| @coe_lt_top (a + 1))).mono fun x hx => tsub_eq_zero_iff_le.2 (hx.1.trans hx.2).le | (a : ℝ≥0), (b : ℝ≥0), _ => by simp only [nhds_coe_coe, tendsto_map'_iff, ← ENNReal.coe_sub, (· ∘ ·), tendsto_coe] exact continuous_sub.tendsto (a, b) #align ennreal.tendsto_sub ENNReal.tendsto_sub protected theorem Tendsto.sub {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (hmb : Tendsto mb f (𝓝 b)) (h : a ≠ ∞ ∨ b ≠ ∞) : Tendsto (fun a => ma a - mb a) f (𝓝 (a - b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a - b)) from Tendsto.comp (ENNReal.tendsto_sub h) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.sub ENNReal.Tendsto.sub protected theorem tendsto_mul (ha : a ≠ 0 ∨ b ≠ ∞) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := by have ht : ∀ b : ℝ≥0∞, b ≠ 0 → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (∞, b)) (𝓝 ∞) := fun b hb => by refine tendsto_nhds_top_iff_nnreal.2 fun n => ?_ rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩ have : ∀ᶠ c : ℝ≥0∞ × ℝ≥0∞ in 𝓝 (∞, b), ↑n / ↑ε < c.1 ∧ ↑ε < c.2 := (lt_mem_nhds <| div_lt_top coe_ne_top hε.ne').prod_nhds (lt_mem_nhds hεb) refine this.mono fun c hc => ?_ exact (ENNReal.div_mul_cancel hε.ne' coe_ne_top).symm.trans_lt (mul_lt_mul hc.1 hc.2) induction a with | top => simp only [ne_eq, or_false, not_true_eq_false] at hb; simp [ht b hb, top_mul hb] | coe a => induction b with | top => simp only [ne_eq, or_false, not_true_eq_false] at ha simpa [(· ∘ ·), mul_comm, mul_top ha] using (ht a ha).comp (continuous_swap.tendsto (ofNNReal a, ∞)) | coe b => simp only [nhds_coe_coe, ← coe_mul, tendsto_coe, tendsto_map'_iff, (· ∘ ·), tendsto_mul] #align ennreal.tendsto_mul ENNReal.tendsto_mul protected theorem Tendsto.mul {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun a => ma a * mb a) f (𝓝 (a * b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a * b)) from Tendsto.comp (ENNReal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.mul ENNReal.Tendsto.mul theorem _root_.ContinuousOn.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₁ : ∀ x ∈ s, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x ∈ s, g x ≠ 0 ∨ f x ≠ ∞) : ContinuousOn (fun x => f x * g x) s := fun x hx => ENNReal.Tendsto.mul (hf x hx) (h₁ x hx) (hg x hx) (h₂ x hx) #align continuous_on.ennreal_mul ContinuousOn.ennreal_mul theorem _root_.Continuous.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} (hf : Continuous f) (hg : Continuous g) (h₁ : ∀ x, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x, g x ≠ 0 ∨ f x ≠ ∞) : Continuous fun x => f x * g x := continuous_iff_continuousAt.2 fun x => ENNReal.Tendsto.mul hf.continuousAt (h₁ x) hg.continuousAt (h₂ x) #align continuous.ennreal_mul Continuous.ennreal_mul protected theorem Tendsto.const_mul {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun b => a * m b) f (𝓝 (a * b)) := by_cases (fun (this : a = 0) => by simp [this, tendsto_const_nhds]) fun ha : a ≠ 0 => ENNReal.Tendsto.mul tendsto_const_nhds (Or.inl ha) hm hb #align ennreal.tendsto.const_mul ENNReal.Tendsto.const_mul protected theorem Tendsto.mul_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) : Tendsto (fun x => m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ENNReal.Tendsto.const_mul hm ha #align ennreal.tendsto.mul_const ENNReal.Tendsto.mul_const theorem tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : Filter α} {a : ι → ℝ≥0∞} (s : Finset ι) (h : ∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞) : Tendsto (fun b => ∏ c ∈ s, f c b) x (𝓝 (∏ c ∈ s, a c)) := by induction' s using Finset.induction with a s has IH · simp [tendsto_const_nhds] simp only [Finset.prod_insert has] apply Tendsto.mul (h _ (Finset.mem_insert_self _ _)) · right exact (prod_lt_top fun i hi => h' _ (Finset.mem_insert_of_mem hi)).ne · exact IH (fun i hi => h _ (Finset.mem_insert_of_mem hi)) fun i hi => h' _ (Finset.mem_insert_of_mem hi) · exact Or.inr (h' _ (Finset.mem_insert_self _ _)) #align ennreal.tendsto_finset_prod_of_ne_top ENNReal.tendsto_finset_prod_of_ne_top protected theorem continuousAt_const_mul {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (a * ·) b := Tendsto.const_mul tendsto_id h.symm #align ennreal.continuous_at_const_mul ENNReal.continuousAt_const_mul protected theorem continuousAt_mul_const {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (fun x => x * a) b := Tendsto.mul_const tendsto_id h.symm #align ennreal.continuous_at_mul_const ENNReal.continuousAt_mul_const protected theorem continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous (a * ·) := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_const_mul (Or.inl ha) #align ennreal.continuous_const_mul ENNReal.continuous_const_mul protected theorem continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous fun x => x * a := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_mul_const (Or.inl ha) #align ennreal.continuous_mul_const ENNReal.continuous_mul_const protected theorem continuous_div_const (c : ℝ≥0∞) (c_ne_zero : c ≠ 0) : Continuous fun x : ℝ≥0∞ => x / c := by simp_rw [div_eq_mul_inv, continuous_iff_continuousAt] intro x exact ENNReal.continuousAt_mul_const (Or.intro_left _ (inv_ne_top.mpr c_ne_zero)) #align ennreal.continuous_div_const ENNReal.continuous_div_const @[continuity] theorem continuous_pow (n : ℕ) : Continuous fun a : ℝ≥0∞ => a ^ n := by induction' n with n IH · simp [continuous_const] simp_rw [pow_add, pow_one, continuous_iff_continuousAt] intro x refine ENNReal.Tendsto.mul (IH.tendsto _) ?_ tendsto_id ?_ <;> by_cases H : x = 0 · simp only [H, zero_ne_top, Ne, or_true_iff, not_false_iff] · exact Or.inl fun h => H (pow_eq_zero h) · simp only [H, pow_eq_top_iff, zero_ne_top, false_or_iff, eq_self_iff_true, not_true, Ne, not_false_iff, false_and_iff] · simp only [H, true_or_iff, Ne, not_false_iff] #align ennreal.continuous_pow ENNReal.continuous_pow theorem continuousOn_sub : ContinuousOn (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) { p : ℝ≥0∞ × ℝ≥0∞ | p ≠ ⟨∞, ∞⟩ } := by rw [ContinuousOn] rintro ⟨x, y⟩ hp simp only [Ne, Set.mem_setOf_eq, Prod.mk.inj_iff] at hp exact tendsto_nhdsWithin_of_tendsto_nhds (tendsto_sub (not_and_or.mp hp)) #align ennreal.continuous_on_sub ENNReal.continuousOn_sub theorem continuous_sub_left {a : ℝ≥0∞} (a_ne_top : a ≠ ∞) : Continuous (a - ·) := by change Continuous (Function.uncurry Sub.sub ∘ (a, ·)) refine continuousOn_sub.comp_continuous (Continuous.Prod.mk a) fun x => ?_ simp only [a_ne_top, Ne, mem_setOf_eq, Prod.mk.inj_iff, false_and_iff, not_false_iff] #align ennreal.continuous_sub_left ENNReal.continuous_sub_left theorem continuous_nnreal_sub {a : ℝ≥0} : Continuous fun x : ℝ≥0∞ => (a : ℝ≥0∞) - x := continuous_sub_left coe_ne_top #align ennreal.continuous_nnreal_sub ENNReal.continuous_nnreal_sub theorem continuousOn_sub_left (a : ℝ≥0∞) : ContinuousOn (a - ·) { x : ℝ≥0∞ | x ≠ ∞ } := by rw [show (fun x => a - x) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨a, x⟩ by rfl] apply ContinuousOn.comp continuousOn_sub (Continuous.continuousOn (Continuous.Prod.mk a)) rintro _ h (_ | _) exact h none_eq_top #align ennreal.continuous_on_sub_left ENNReal.continuousOn_sub_left theorem continuous_sub_right (a : ℝ≥0∞) : Continuous fun x : ℝ≥0∞ => x - a := by by_cases a_infty : a = ∞ · simp [a_infty, continuous_const] · rw [show (fun x => x - a) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨x, a⟩ by rfl] apply ContinuousOn.comp_continuous continuousOn_sub (continuous_id'.prod_mk continuous_const) intro x simp only [a_infty, Ne, mem_setOf_eq, Prod.mk.inj_iff, and_false_iff, not_false_iff] #align ennreal.continuous_sub_right ENNReal.continuous_sub_right protected theorem Tendsto.pow {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} {n : ℕ} (hm : Tendsto m f (𝓝 a)) : Tendsto (fun x => m x ^ n) f (𝓝 (a ^ n)) := ((continuous_pow n).tendsto a).comp hm #align ennreal.tendsto.pow ENNReal.Tendsto.pow theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := by have : Tendsto (· * x) (𝓝[<] 1) (𝓝 (1 * x)) := (ENNReal.continuousAt_mul_const (Or.inr one_ne_zero)).mono_left inf_le_left rw [one_mul] at this exact le_of_tendsto this (eventually_nhdsWithin_iff.2 <| eventually_of_forall h) #align ennreal.le_of_forall_lt_one_mul_le ENNReal.le_of_forall_lt_one_mul_le theorem iInf_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, a * f i = a * ⨅ i, f i := by by_cases H : a = ∞ ∧ ⨅ i, f i = 0 · rcases h H.1 H.2 with ⟨i, hi⟩ rw [H.2, mul_zero, ← bot_eq_zero, iInf_eq_bot] exact fun b hb => ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ · rw [not_and_or] at H cases isEmpty_or_nonempty ι · rw [iInf_of_empty, iInf_of_empty, mul_top] exact mt h0 (not_nonempty_iff.2 ‹_›) · exact (ENNReal.mul_left_mono.map_iInf_of_continuousAt' (ENNReal.continuousAt_const_mul H)).symm #align ennreal.infi_mul_left' ENNReal.iInf_mul_left' theorem iInf_mul_left {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, a * f i = a * ⨅ i, f i := iInf_mul_left' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_left ENNReal.iInf_mul_left theorem iInf_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, f i * a = (⨅ i, f i) * a := by simpa only [mul_comm a] using iInf_mul_left' h h0 #align ennreal.infi_mul_right' ENNReal.iInf_mul_right' theorem iInf_mul_right {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, f i * a = (⨅ i, f i) * a := iInf_mul_right' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_right ENNReal.iInf_mul_right theorem inv_map_iInf {ι : Sort*} {x : ι → ℝ≥0∞} : (iInf x)⁻¹ = ⨆ i, (x i)⁻¹ := OrderIso.invENNReal.map_iInf x #align ennreal.inv_map_infi ENNReal.inv_map_iInf theorem inv_map_iSup {ι : Sort*} {x : ι → ℝ≥0∞} : (iSup x)⁻¹ = ⨅ i, (x i)⁻¹ := OrderIso.invENNReal.map_iSup x #align ennreal.inv_map_supr ENNReal.inv_map_iSup theorem inv_limsup {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (limsup x l)⁻¹ = liminf (fun i => (x i)⁻¹) l := OrderIso.invENNReal.limsup_apply #align ennreal.inv_limsup ENNReal.inv_limsup theorem inv_liminf {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (liminf x l)⁻¹ = limsup (fun i => (x i)⁻¹) l := OrderIso.invENNReal.liminf_apply #align ennreal.inv_liminf ENNReal.inv_liminf instance : ContinuousInv ℝ≥0∞ := ⟨OrderIso.invENNReal.continuous⟩ @[simp] -- Porting note (#11215): TODO: generalize to `[InvolutiveInv _] [ContinuousInv _]` protected theorem tendsto_inv_iff {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} : Tendsto (fun x => (m x)⁻¹) f (𝓝 a⁻¹) ↔ Tendsto m f (𝓝 a) := ⟨fun h => by simpa only [inv_inv] using Tendsto.inv h, Tendsto.inv⟩ #align ennreal.tendsto_inv_iff ENNReal.tendsto_inv_iff protected theorem Tendsto.div {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun a => ma a / mb a) f (𝓝 (a / b)) := by apply Tendsto.mul hma _ (ENNReal.tendsto_inv_iff.2 hmb) _ <;> simp [ha, hb] #align ennreal.tendsto.div ENNReal.Tendsto.div protected theorem Tendsto.const_div {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun b => a / m b) f (𝓝 (a / b)) := by apply Tendsto.const_mul (ENNReal.tendsto_inv_iff.2 hm) simp [hb] #align ennreal.tendsto.const_div ENNReal.Tendsto.const_div protected theorem Tendsto.div_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : Tendsto (fun x => m x / b) f (𝓝 (a / b)) := by apply Tendsto.mul_const hm simp [ha] #align ennreal.tendsto.div_const ENNReal.Tendsto.div_const protected theorem tendsto_inv_nat_nhds_zero : Tendsto (fun n : ℕ => (n : ℝ≥0∞)⁻¹) atTop (𝓝 0) := ENNReal.inv_top ▸ ENNReal.tendsto_inv_iff.2 tendsto_nat_nhds_top #align ennreal.tendsto_inv_nat_nhds_zero ENNReal.tendsto_inv_nat_nhds_zero theorem iSup_add {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : iSup s + a = ⨆ b, s b + a := Monotone.map_iSup_of_continuousAt' (continuousAt_id.add continuousAt_const) <| monotone_id.add monotone_const #align ennreal.supr_add ENNReal.iSup_add theorem biSup_add' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (⨆ (i) (_ : p i), f i) + a = ⨆ (i) (_ : p i), f i + a := by haveI : Nonempty { i // p i } := nonempty_subtype.2 h simp only [iSup_subtype', iSup_add] #align ennreal.bsupr_add' ENNReal.biSup_add' theorem add_biSup' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (a + ⨆ (i) (_ : p i), f i) = ⨆ (i) (_ : p i), a + f i := by simp only [add_comm a, biSup_add' h] #align ennreal.add_bsupr' ENNReal.add_biSup' theorem biSup_add {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a := biSup_add' hs #align ennreal.bsupr_add ENNReal.biSup_add theorem add_biSup {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (a + ⨆ i ∈ s, f i) = ⨆ i ∈ s, a + f i := add_biSup' hs #align ennreal.add_bsupr ENNReal.add_biSup theorem sSup_add {s : Set ℝ≥0∞} (hs : s.Nonempty) : sSup s + a = ⨆ b ∈ s, b + a := by rw [sSup_eq_iSup, biSup_add hs] #align ennreal.Sup_add ENNReal.sSup_add theorem add_iSup {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : a + iSup s = ⨆ b, a + s b := by rw [add_comm, iSup_add]; simp [add_comm] #align ennreal.add_supr ENNReal.add_iSup theorem iSup_add_iSup_le {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i j, f i + g j ≤ a) : iSup f + iSup g ≤ a := by simp_rw [iSup_add, add_iSup]; exact iSup₂_le h #align ennreal.supr_add_supr_le ENNReal.iSup_add_iSup_le theorem biSup_add_biSup_le' {ι ι'} {p : ι → Prop} {q : ι' → Prop} (hp : ∃ i, p i) (hq : ∃ j, q j) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i, p i → ∀ j, q j → f i + g j ≤ a) : ((⨆ (i) (_ : p i), f i) + ⨆ (j) (_ : q j), g j) ≤ a := by simp_rw [biSup_add' hp, add_biSup' hq] exact iSup₂_le fun i hi => iSup₂_le (h i hi) #align ennreal.bsupr_add_bsupr_le' ENNReal.biSup_add_biSup_le' theorem biSup_add_biSup_le {ι ι'} {s : Set ι} {t : Set ι'} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i ∈ s, ∀ j ∈ t, f i + g j ≤ a) : ((⨆ i ∈ s, f i) + ⨆ j ∈ t, g j) ≤ a := biSup_add_biSup_le' hs ht h #align ennreal.bsupr_add_bsupr_le ENNReal.biSup_add_biSup_le theorem iSup_add_iSup {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀ i j, ∃ k, f i + g j ≤ f k + g k) : iSup f + iSup g = ⨆ a, f a + g a := by cases isEmpty_or_nonempty ι · simp only [iSup_of_empty, bot_eq_zero, zero_add] · refine le_antisymm ?_ (iSup_le fun a => add_le_add (le_iSup _ _) (le_iSup _ _)) refine iSup_add_iSup_le fun i j => ?_ rcases h i j with ⟨k, hk⟩ exact le_iSup_of_le k hk #align ennreal.supr_add_supr ENNReal.iSup_add_iSup theorem iSup_add_iSup_of_monotone {ι : Type*} [SemilatticeSup ι] {f g : ι → ℝ≥0∞} (hf : Monotone f) (hg : Monotone g) : iSup f + iSup g = ⨆ a, f a + g a := iSup_add_iSup fun i j => ⟨i ⊔ j, add_le_add (hf <| le_sup_left) (hg <| le_sup_right)⟩ #align ennreal.supr_add_supr_of_monotone ENNReal.iSup_add_iSup_of_monotone theorem finset_sum_iSup_nat {α} {ι} [SemilatticeSup ι] {s : Finset α} {f : α → ι → ℝ≥0∞} (hf : ∀ a, Monotone (f a)) : (∑ a ∈ s, iSup (f a)) = ⨆ n, ∑ a ∈ s, f a n := by refine Finset.induction_on s ?_ ?_ · simp · intro a s has ih simp only [Finset.sum_insert has] rw [ih, iSup_add_iSup_of_monotone (hf a)] intro i j h exact Finset.sum_le_sum fun a _ => hf a h #align ennreal.finset_sum_supr_nat ENNReal.finset_sum_iSup_nat theorem mul_iSup {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : a * iSup f = ⨆ i, a * f i := by by_cases hf : ∀ i, f i = 0 · obtain rfl : f = fun _ => 0 := funext hf simp only [iSup_zero_eq_zero, mul_zero] · refine (monotone_id.const_mul' _).map_iSup_of_continuousAt ?_ (mul_zero a) refine ENNReal.Tendsto.const_mul tendsto_id (Or.inl ?_) exact mt iSup_eq_zero.1 hf #align ennreal.mul_supr ENNReal.mul_iSup theorem mul_sSup {s : Set ℝ≥0∞} {a : ℝ≥0∞} : a * sSup s = ⨆ i ∈ s, a * i := by simp only [sSup_eq_iSup, mul_iSup] #align ennreal.mul_Sup ENNReal.mul_sSup theorem iSup_mul {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f * a = ⨆ i, f i * a := by rw [mul_comm, mul_iSup]; congr; funext; rw [mul_comm] #align ennreal.supr_mul ENNReal.iSup_mul theorem smul_iSup {ι : Sort*} {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (f : ι → ℝ≥0∞) (c : R) : (c • ⨆ i, f i) = ⨆ i, c • f i := by -- Porting note: replaced `iSup _` with `iSup f` simp only [← smul_one_mul c (f _), ← smul_one_mul c (iSup f), ENNReal.mul_iSup] #align ennreal.smul_supr ENNReal.smul_iSup theorem smul_sSup {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (s : Set ℝ≥0∞) (c : R) : c • sSup s = ⨆ i ∈ s, c • i := by -- Porting note: replaced `_` with `s` simp_rw [← smul_one_mul c (sSup s), ENNReal.mul_sSup, smul_one_mul] #align ennreal.smul_Sup ENNReal.smul_sSup theorem iSup_div {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f / a = ⨆ i, f i / a := iSup_mul #align ennreal.supr_div ENNReal.iSup_div protected theorem tendsto_coe_sub {b : ℝ≥0∞} : Tendsto (fun b : ℝ≥0∞ => ↑r - b) (𝓝 b) (𝓝 (↑r - b)) := continuous_nnreal_sub.tendsto _ #align ennreal.tendsto_coe_sub ENNReal.tendsto_coe_sub theorem sub_iSup {ι : Sort*} [Nonempty ι] {b : ι → ℝ≥0∞} (hr : a < ∞) : (a - ⨆ i, b i) = ⨅ i, a - b i := antitone_const_tsub.map_iSup_of_continuousAt' (continuous_sub_left hr.ne).continuousAt #align ennreal.sub_supr ENNReal.sub_iSup theorem exists_countable_dense_no_zero_top : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ 0 ∉ s ∧ ∞ ∉ s := by obtain ⟨s, s_count, s_dense, hs⟩ : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ (∀ x, IsBot x → x ∉ s) ∧ ∀ x, IsTop x → x ∉ s := exists_countable_dense_no_bot_top ℝ≥0∞ exact ⟨s, s_count, s_dense, fun h => hs.1 0 (by simp) h, fun h => hs.2 ∞ (by simp) h⟩ #align ennreal.exists_countable_dense_no_zero_top ENNReal.exists_countable_dense_no_zero_top theorem exists_lt_add_of_lt_add {x y z : ℝ≥0∞} (h : x < y + z) (hy : y ≠ 0) (hz : z ≠ 0) : ∃ y' z', y' < y ∧ z' < z ∧ x < y' + z' := by have : NeZero y := ⟨hy⟩ have : NeZero z := ⟨hz⟩ have A : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 + p.2) (𝓝[<] y ×ˢ 𝓝[<] z) (𝓝 (y + z)) := by apply Tendsto.mono_left _ (Filter.prod_mono nhdsWithin_le_nhds nhdsWithin_le_nhds) rw [← nhds_prod_eq] exact tendsto_add rcases ((A.eventually (lt_mem_nhds h)).and (Filter.prod_mem_prod self_mem_nhdsWithin self_mem_nhdsWithin)).exists with ⟨⟨y', z'⟩, hx, hy', hz'⟩ exact ⟨y', z', hy', hz', hx⟩ #align ennreal.exists_lt_add_of_lt_add ENNReal.exists_lt_add_of_lt_add theorem ofReal_cinfi (f : α → ℝ) [Nonempty α] : ENNReal.ofReal (⨅ i, f i) = ⨅ i, ENNReal.ofReal (f i) := by by_cases hf : BddBelow (range f) · exact Monotone.map_ciInf_of_continuousAt ENNReal.continuous_ofReal.continuousAt (fun i j hij => ENNReal.ofReal_le_ofReal hij) hf · symm rw [Real.iInf_of_not_bddBelow hf, ENNReal.ofReal_zero, ← ENNReal.bot_eq_zero, iInf_eq_bot] obtain ⟨y, hy_mem, hy_neg⟩ := not_bddBelow_iff.mp hf 0 obtain ⟨i, rfl⟩ := mem_range.mpr hy_mem refine fun x hx => ⟨i, ?_⟩ rwa [ENNReal.ofReal_of_nonpos hy_neg.le] #align ennreal.of_real_cinfi ENNReal.ofReal_cinfi end TopologicalSpace section Liminf theorem exists_frequently_lt_of_liminf_ne_top {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, x n < R := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h r] with i hi using hi.trans (le_abs_self (x i)) #align ennreal.exists_frequently_lt_of_liminf_ne_top ENNReal.exists_frequently_lt_of_liminf_ne_top theorem exists_frequently_lt_of_liminf_ne_top' {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, R < x n := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h (-r)] with i hi using(le_neg.1 hi).trans (neg_le_abs _) #align ennreal.exists_frequently_lt_of_liminf_ne_top' ENNReal.exists_frequently_lt_of_liminf_ne_top' theorem exists_upcrossings_of_not_bounded_under {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hf : liminf (fun i => (Real.nnabs (x i) : ℝ≥0∞)) l ≠ ∞) (hbdd : ¬IsBoundedUnder (· ≤ ·) l fun i => |x i|) : ∃ a b : ℚ, a < b ∧ (∃ᶠ i in l, x i < a) ∧ ∃ᶠ i in l, ↑b < x i := by rw [isBoundedUnder_le_abs, not_and_or] at hbdd obtain hbdd | hbdd := hbdd · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top hf obtain ⟨q, hq⟩ := exists_rat_gt R refine ⟨q, q + 1, (lt_add_iff_pos_right _).2 zero_lt_one, ?_, ?_⟩ · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 (lt_of_lt_of_le hq (not_lt.1 hx)).le · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q + 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top' hf obtain ⟨q, hq⟩ := exists_rat_lt R refine ⟨q - 1, q, (sub_lt_self_iff _).2 zero_lt_one, ?_, ?_⟩ · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q - 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 ((not_lt.1 hx).trans hq.le) #align ennreal.exists_upcrossings_of_not_bounded_under ENNReal.exists_upcrossings_of_not_bounded_under end Liminf section tsum variable {f g : α → ℝ≥0∞} @[norm_cast] protected theorem hasSum_coe {f : α → ℝ≥0} {r : ℝ≥0} : HasSum (fun a => (f a : ℝ≥0∞)) ↑r ↔ HasSum f r := by simp only [HasSum, ← coe_finset_sum, tendsto_coe] #align ennreal.has_sum_coe ENNReal.hasSum_coe protected theorem tsum_coe_eq {f : α → ℝ≥0} (h : HasSum f r) : (∑' a, (f a : ℝ≥0∞)) = r := (ENNReal.hasSum_coe.2 h).tsum_eq #align ennreal.tsum_coe_eq ENNReal.tsum_coe_eq protected theorem coe_tsum {f : α → ℝ≥0} : Summable f → ↑(tsum f) = ∑' a, (f a : ℝ≥0∞) | ⟨r, hr⟩ => by rw [hr.tsum_eq, ENNReal.tsum_coe_eq hr] #align ennreal.coe_tsum ENNReal.coe_tsum protected theorem hasSum : HasSum f (⨆ s : Finset α, ∑ a ∈ s, f a) := tendsto_atTop_iSup fun _ _ => Finset.sum_le_sum_of_subset #align ennreal.has_sum ENNReal.hasSum @[simp] protected theorem summable : Summable f := ⟨_, ENNReal.hasSum⟩ #align ennreal.summable ENNReal.summable theorem tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} : (∑' b, (f b : ℝ≥0∞)) ≠ ∞ ↔ Summable f := by refine ⟨fun h => ?_, fun h => ENNReal.coe_tsum h ▸ ENNReal.coe_ne_top⟩ lift ∑' b, (f b : ℝ≥0∞) to ℝ≥0 using h with a ha refine ⟨a, ENNReal.hasSum_coe.1 ?_⟩ rw [ha] exact ENNReal.summable.hasSum #align ennreal.tsum_coe_ne_top_iff_summable ENNReal.tsum_coe_ne_top_iff_summable protected theorem tsum_eq_iSup_sum : ∑' a, f a = ⨆ s : Finset α, ∑ a ∈ s, f a := ENNReal.hasSum.tsum_eq #align ennreal.tsum_eq_supr_sum ENNReal.tsum_eq_iSup_sum protected theorem tsum_eq_iSup_sum' {ι : Type*} (s : ι → Finset α) (hs : ∀ t, ∃ i, t ⊆ s i) : ∑' a, f a = ⨆ i, ∑ a ∈ s i, f a := by rw [ENNReal.tsum_eq_iSup_sum] symm change ⨆ i : ι, (fun t : Finset α => ∑ a ∈ t, f a) (s i) = ⨆ s : Finset α, ∑ a ∈ s, f a exact (Finset.sum_mono_set f).iSup_comp_eq hs #align ennreal.tsum_eq_supr_sum' ENNReal.tsum_eq_iSup_sum' protected theorem tsum_sigma {β : α → Type*} (f : ∀ a, β a → ℝ≥0∞) : ∑' p : Σa, β a, f p.1 p.2 = ∑' (a) (b), f a b := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma ENNReal.tsum_sigma protected theorem tsum_sigma' {β : α → Type*} (f : (Σa, β a) → ℝ≥0∞) : ∑' p : Σa, β a, f p = ∑' (a) (b), f ⟨a, b⟩ := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma' ENNReal.tsum_sigma' protected theorem tsum_prod {f : α → β → ℝ≥0∞} : ∑' p : α × β, f p.1 p.2 = ∑' (a) (b), f a b := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod ENNReal.tsum_prod protected theorem tsum_prod' {f : α × β → ℝ≥0∞} : ∑' p : α × β, f p = ∑' (a) (b), f (a, b) := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod' ENNReal.tsum_prod' protected theorem tsum_comm {f : α → β → ℝ≥0∞} : ∑' a, ∑' b, f a b = ∑' b, ∑' a, f a b := tsum_comm' ENNReal.summable (fun _ => ENNReal.summable) fun _ => ENNReal.summable #align ennreal.tsum_comm ENNReal.tsum_comm protected theorem tsum_add : ∑' a, (f a + g a) = ∑' a, f a + ∑' a, g a := tsum_add ENNReal.summable ENNReal.summable #align ennreal.tsum_add ENNReal.tsum_add protected theorem tsum_le_tsum (h : ∀ a, f a ≤ g a) : ∑' a, f a ≤ ∑' a, g a := tsum_le_tsum h ENNReal.summable ENNReal.summable #align ennreal.tsum_le_tsum ENNReal.tsum_le_tsum @[gcongr] protected theorem _root_.GCongr.ennreal_tsum_le_tsum (h : ∀ a, f a ≤ g a) : tsum f ≤ tsum g := ENNReal.tsum_le_tsum h protected theorem sum_le_tsum {f : α → ℝ≥0∞} (s : Finset α) : ∑ x ∈ s, f x ≤ ∑' x, f x := sum_le_tsum s (fun _ _ => zero_le _) ENNReal.summable #align ennreal.sum_le_tsum ENNReal.sum_le_tsum protected theorem tsum_eq_iSup_nat' {f : ℕ → ℝ≥0∞} {N : ℕ → ℕ} (hN : Tendsto N atTop atTop) : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range (N i), f a := ENNReal.tsum_eq_iSup_sum' _ fun t => let ⟨n, hn⟩ := t.exists_nat_subset_range let ⟨k, _, hk⟩ := exists_le_of_tendsto_atTop hN 0 n ⟨k, Finset.Subset.trans hn (Finset.range_mono hk)⟩ #align ennreal.tsum_eq_supr_nat' ENNReal.tsum_eq_iSup_nat' protected theorem tsum_eq_iSup_nat {f : ℕ → ℝ≥0∞} : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range i, f a := ENNReal.tsum_eq_iSup_sum' _ Finset.exists_nat_subset_range #align ennreal.tsum_eq_supr_nat ENNReal.tsum_eq_iSup_nat protected theorem tsum_eq_liminf_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = liminf (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.liminf_eq.symm #align ennreal.tsum_eq_liminf_sum_nat ENNReal.tsum_eq_liminf_sum_nat protected theorem tsum_eq_limsup_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = limsup (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.limsup_eq.symm protected theorem le_tsum (a : α) : f a ≤ ∑' a, f a := le_tsum' ENNReal.summable a #align ennreal.le_tsum ENNReal.le_tsum @[simp] protected theorem tsum_eq_zero : ∑' i, f i = 0 ↔ ∀ i, f i = 0 := tsum_eq_zero_iff ENNReal.summable #align ennreal.tsum_eq_zero ENNReal.tsum_eq_zero protected theorem tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → ∑' a, f a = ∞ | ⟨a, ha⟩ => top_unique <| ha ▸ ENNReal.le_tsum a #align ennreal.tsum_eq_top_of_eq_top ENNReal.tsum_eq_top_of_eq_top protected theorem lt_top_of_tsum_ne_top {a : α → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) (j : α) : a j < ∞ := by contrapose! tsum_ne_top with h exact ENNReal.tsum_eq_top_of_eq_top ⟨j, top_unique h⟩ #align ennreal.lt_top_of_tsum_ne_top ENNReal.lt_top_of_tsum_ne_top @[simp] protected theorem tsum_top [Nonempty α] : ∑' _ : α, ∞ = ∞ := let ⟨a⟩ := ‹Nonempty α› ENNReal.tsum_eq_top_of_eq_top ⟨a, rfl⟩ #align ennreal.tsum_top ENNReal.tsum_top theorem tsum_const_eq_top_of_ne_zero {α : Type*} [Infinite α] {c : ℝ≥0∞} (hc : c ≠ 0) : ∑' _ : α, c = ∞ := by have A : Tendsto (fun n : ℕ => (n : ℝ≥0∞) * c) atTop (𝓝 (∞ * c)) := by apply ENNReal.Tendsto.mul_const tendsto_nat_nhds_top simp only [true_or_iff, top_ne_zero, Ne, not_false_iff] have B : ∀ n : ℕ, (n : ℝ≥0∞) * c ≤ ∑' _ : α, c := fun n => by rcases Infinite.exists_subset_card_eq α n with ⟨s, hs⟩ simpa [hs] using @ENNReal.sum_le_tsum α (fun _ => c) s simpa [hc] using le_of_tendsto' A B #align ennreal.tsum_const_eq_top_of_ne_zero ENNReal.tsum_const_eq_top_of_ne_zero protected theorem ne_top_of_tsum_ne_top (h : ∑' a, f a ≠ ∞) (a : α) : f a ≠ ∞ := fun ha => h <| ENNReal.tsum_eq_top_of_eq_top ⟨a, ha⟩ #align ennreal.ne_top_of_tsum_ne_top ENNReal.ne_top_of_tsum_ne_top protected theorem tsum_mul_left : ∑' i, a * f i = a * ∑' i, f i := by by_cases hf : ∀ i, f i = 0 · simp [hf] · rw [← ENNReal.tsum_eq_zero] at hf have : Tendsto (fun s : Finset α => ∑ j ∈ s, a * f j) atTop (𝓝 (a * ∑' i, f i)) := by simp only [← Finset.mul_sum] exact ENNReal.Tendsto.const_mul ENNReal.summable.hasSum (Or.inl hf) exact HasSum.tsum_eq this #align ennreal.tsum_mul_left ENNReal.tsum_mul_left protected theorem tsum_mul_right : ∑' i, f i * a = (∑' i, f i) * a := by simp [mul_comm, ENNReal.tsum_mul_left] #align ennreal.tsum_mul_right ENNReal.tsum_mul_right protected theorem tsum_const_smul {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (a : R) : ∑' i, a • f i = a • ∑' i, f i := by simpa only [smul_one_mul] using @ENNReal.tsum_mul_left _ (a • (1 : ℝ≥0∞)) _ #align ennreal.tsum_const_smul ENNReal.tsum_const_smul @[simp] theorem tsum_iSup_eq {α : Type*} (a : α) {f : α → ℝ≥0∞} : (∑' b : α, ⨆ _ : a = b, f b) = f a := (tsum_eq_single a fun _ h => by simp [h.symm]).trans <| by simp #align ennreal.tsum_supr_eq ENNReal.tsum_iSup_eq theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0∞} (r : ℝ≥0∞) : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by refine ⟨HasSum.tendsto_sum_nat, fun h => ?_⟩ rw [← iSup_eq_of_tendsto _ h, ← ENNReal.tsum_eq_iSup_nat] · exact ENNReal.summable.hasSum · exact fun s t hst => Finset.sum_le_sum_of_subset (Finset.range_subset.2 hst) #align ennreal.has_sum_iff_tendsto_nat ENNReal.hasSum_iff_tendsto_nat theorem tendsto_nat_tsum (f : ℕ → ℝ≥0∞) : Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 (∑' n, f n)) := by rw [← hasSum_iff_tendsto_nat] exact ENNReal.summable.hasSum #align ennreal.tendsto_nat_tsum ENNReal.tendsto_nat_tsum theorem toNNReal_apply_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) (x : α) : (((ENNReal.toNNReal ∘ f) x : ℝ≥0) : ℝ≥0∞) = f x := coe_toNNReal <| ENNReal.ne_top_of_tsum_ne_top hf _ #align ennreal.to_nnreal_apply_of_tsum_ne_top ENNReal.toNNReal_apply_of_tsum_ne_top theorem summable_toNNReal_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) : Summable (ENNReal.toNNReal ∘ f) := by simpa only [← tsum_coe_ne_top_iff_summable, toNNReal_apply_of_tsum_ne_top hf] using hf #align ennreal.summable_to_nnreal_of_tsum_ne_top ENNReal.summable_toNNReal_of_tsum_ne_top theorem tendsto_cofinite_zero_of_tsum_ne_top {α} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f cofinite (𝓝 0) := by have f_ne_top : ∀ n, f n ≠ ∞ := ENNReal.ne_top_of_tsum_ne_top hf have h_f_coe : f = fun n => ((f n).toNNReal : ENNReal) := funext fun n => (coe_toNNReal (f_ne_top n)).symm rw [h_f_coe, ← @coe_zero, tendsto_coe] exact NNReal.tendsto_cofinite_zero_of_summable (summable_toNNReal_of_tsum_ne_top hf) #align ennreal.tendsto_cofinite_zero_of_tsum_ne_top ENNReal.tendsto_cofinite_zero_of_tsum_ne_top theorem tendsto_atTop_zero_of_tsum_ne_top {f : ℕ → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f atTop (𝓝 0) := by rw [← Nat.cofinite_eq_atTop] exact tendsto_cofinite_zero_of_tsum_ne_top hf #align ennreal.tendsto_at_top_zero_of_tsum_ne_top ENNReal.tendsto_atTop_zero_of_tsum_ne_top /-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole space. This does not need a summability assumption, as otherwise all sums are zero. -/ theorem tendsto_tsum_compl_atTop_zero {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto (fun s : Finset α => ∑' b : { x // x ∉ s }, f b) atTop (𝓝 0) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hf convert ENNReal.tendsto_coe.2 (NNReal.tendsto_tsum_compl_atTop_zero f) rw [ENNReal.coe_tsum] exact NNReal.summable_comp_injective (tsum_coe_ne_top_iff_summable.1 hf) Subtype.coe_injective #align ennreal.tendsto_tsum_compl_at_top_zero ENNReal.tendsto_tsum_compl_atTop_zero protected theorem tsum_apply {ι α : Type*} {f : ι → α → ℝ≥0∞} {x : α} : (∑' i, f i) x = ∑' i, f i x := tsum_apply <| Pi.summable.mpr fun _ => ENNReal.summable #align ennreal.tsum_apply ENNReal.tsum_apply theorem tsum_sub {f : ℕ → ℝ≥0∞} {g : ℕ → ℝ≥0∞} (h₁ : ∑' i, g i ≠ ∞) (h₂ : g ≤ f) : ∑' i, (f i - g i) = ∑' i, f i - ∑' i, g i := have : ∀ i, f i - g i + g i = f i := fun i => tsub_add_cancel_of_le (h₂ i) ENNReal.eq_sub_of_add_eq h₁ <| by simp only [← ENNReal.tsum_add, this] #align ennreal.tsum_sub ENNReal.tsum_sub theorem tsum_comp_le_tsum_of_injective {f : α → β} (hf : Injective f) (g : β → ℝ≥0∞) : ∑' x, g (f x) ≤ ∑' y, g y := tsum_le_tsum_of_inj f hf (fun _ _ => zero_le _) (fun _ => le_rfl) ENNReal.summable ENNReal.summable theorem tsum_le_tsum_comp_of_surjective {f : α → β} (hf : Surjective f) (g : β → ℝ≥0∞) : ∑' y, g y ≤ ∑' x, g (f x) := calc ∑' y, g y = ∑' y, g (f (surjInv hf y)) := by simp only [surjInv_eq hf] _ ≤ ∑' x, g (f x) := tsum_comp_le_tsum_of_injective (injective_surjInv hf) _ theorem tsum_mono_subtype (f : α → ℝ≥0∞) {s t : Set α} (h : s ⊆ t) : ∑' x : s, f x ≤ ∑' x : t, f x := tsum_comp_le_tsum_of_injective (inclusion_injective h) _ #align ennreal.tsum_mono_subtype ENNReal.tsum_mono_subtype theorem tsum_iUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑' i, ∑' x : t i, f x := calc ∑' x : ⋃ i, t i, f x ≤ ∑' x : Σ i, t i, f x.2 := tsum_le_tsum_comp_of_surjective (sigmaToiUnion_surjective t) _ _ = ∑' i, ∑' x : t i, f x := ENNReal.tsum_sigma' _ theorem tsum_biUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (s : Set ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s , t i, f x ≤ ∑' i : s, ∑' x : t i, f x := calc ∑' x : ⋃ i ∈ s, t i, f x = ∑' x : ⋃ i : s, t i, f x := tsum_congr_set_coe _ <| by simp _ ≤ ∑' i : s, ∑' x : t i, f x := tsum_iUnion_le_tsum _ _ theorem tsum_biUnion_le {ι : Type*} (f : α → ℝ≥0∞) (s : Finset ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s, t i, f x ≤ ∑ i ∈ s, ∑' x : t i, f x := (tsum_biUnion_le_tsum f s.toSet t).trans_eq (Finset.tsum_subtype s fun i => ∑' x : t i, f x) #align ennreal.tsum_bUnion_le ENNReal.tsum_biUnion_le theorem tsum_iUnion_le {ι : Type*} [Fintype ι] (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑ i, ∑' x : t i, f x := by rw [← tsum_fintype] exact tsum_iUnion_le_tsum f t #align ennreal.tsum_Union_le ENNReal.tsum_iUnion_le theorem tsum_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∑' x : ↑(s ∪ t), f x ≤ ∑' x : s, f x + ∑' x : t, f x := calc ∑' x : ↑(s ∪ t), f x = ∑' x : ⋃ b, cond b s t, f x := tsum_congr_set_coe _ union_eq_iUnion _ ≤ _ := by simpa using tsum_iUnion_le f (cond · s t) #align ennreal.tsum_union_le ENNReal.tsum_union_le theorem tsum_eq_add_tsum_ite {f : β → ℝ≥0∞} (b : β) : ∑' x, f x = f b + ∑' x, ite (x = b) 0 (f x) := tsum_eq_add_tsum_ite' b ENNReal.summable #align ennreal.tsum_eq_add_tsum_ite ENNReal.tsum_eq_add_tsum_ite theorem tsum_add_one_eq_top {f : ℕ → ℝ≥0∞} (hf : ∑' n, f n = ∞) (hf0 : f 0 ≠ ∞) : ∑' n, f (n + 1) = ∞ := by rw [tsum_eq_zero_add' ENNReal.summable, add_eq_top] at hf exact hf.resolve_left hf0 #align ennreal.tsum_add_one_eq_top ENNReal.tsum_add_one_eq_top /-- A sum of extended nonnegative reals which is finite can have only finitely many terms above any positive threshold. -/ theorem finite_const_le_of_tsum_ne_top {ι : Type*} {a : ι → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : { i : ι | ε ≤ a i }.Finite := by by_contra h have := Infinite.to_subtype h refine tsum_ne_top (top_unique ?_) calc ∞ = ∑' _ : { i | ε ≤ a i }, ε := (tsum_const_eq_top_of_ne_zero ε_ne_zero).symm _ ≤ ∑' i, a i := tsum_le_tsum_of_inj (↑) Subtype.val_injective (fun _ _ => zero_le _) (fun i => i.2) ENNReal.summable ENNReal.summable #align ennreal.finite_const_le_of_tsum_ne_top ENNReal.finite_const_le_of_tsum_ne_top /-- Markov's inequality for `Finset.card` and `tsum` in `ℝ≥0∞`. -/ theorem finset_card_const_le_le_of_tsum_le {ι : Type*} {a : ι → ℝ≥0∞} {c : ℝ≥0∞} (c_ne_top : c ≠ ∞) (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : ∃ hf : { i : ι | ε ≤ a i }.Finite, ↑hf.toFinset.card ≤ c / ε := by have hf : { i : ι | ε ≤ a i }.Finite := finite_const_le_of_tsum_ne_top (ne_top_of_le_ne_top c_ne_top tsum_le_c) ε_ne_zero refine ⟨hf, (ENNReal.le_div_iff_mul_le (.inl ε_ne_zero) (.inr c_ne_top)).2 ?_⟩ calc ↑hf.toFinset.card * ε = ∑ _i ∈ hf.toFinset, ε := by rw [Finset.sum_const, nsmul_eq_mul] _ ≤ ∑ i ∈ hf.toFinset, a i := Finset.sum_le_sum fun i => hf.mem_toFinset.1 _ ≤ ∑' i, a i := ENNReal.sum_le_tsum _ _ ≤ c := tsum_le_c #align ennreal.finset_card_const_le_le_of_tsum_le ENNReal.finset_card_const_le_le_of_tsum_le theorem tsum_fiberwise (f : β → ℝ≥0∞) (g : β → γ) : ∑' x, ∑' b : g ⁻¹' {x}, f b = ∑' i, f i := by apply HasSum.tsum_eq let equiv := Equiv.sigmaFiberEquiv g apply (equiv.hasSum_iff.mpr ENNReal.summable.hasSum).sigma exact fun _ ↦ ENNReal.summable.hasSum_iff.mpr rfl end tsum theorem tendsto_toReal_iff {ι} {fi : Filter ι} {f : ι → ℝ≥0∞} (hf : ∀ i, f i ≠ ∞) {x : ℝ≥0∞} (hx : x ≠ ∞) : Tendsto (fun n => (f n).toReal) fi (𝓝 x.toReal) ↔ Tendsto f fi (𝓝 x) := by lift f to ι → ℝ≥0 using hf lift x to ℝ≥0 using hx simp [tendsto_coe] #align ennreal.tendsto_to_real_iff ENNReal.tendsto_toReal_iff theorem tsum_coe_ne_top_iff_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) ≠ ∞ ↔ Summable fun a => (f a : ℝ) := by rw [NNReal.summable_coe] exact tsum_coe_ne_top_iff_summable #align ennreal.tsum_coe_ne_top_iff_summable_coe ENNReal.tsum_coe_ne_top_iff_summable_coe theorem tsum_coe_eq_top_iff_not_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) = ∞ ↔ ¬Summable fun a => (f a : ℝ) := tsum_coe_ne_top_iff_summable_coe.not_right #align ennreal.tsum_coe_eq_top_iff_not_summable_coe ENNReal.tsum_coe_eq_top_iff_not_summable_coe theorem hasSum_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : HasSum (fun x => (f x).toReal) (∑' x, (f x).toReal) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hsum simp only [coe_toReal, ← NNReal.coe_tsum, NNReal.hasSum_coe] exact (tsum_coe_ne_top_iff_summable.1 hsum).hasSum #align ennreal.has_sum_to_real ENNReal.hasSum_toReal theorem summable_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : Summable fun x => (f x).toReal := (hasSum_toReal hsum).summable #align ennreal.summable_to_real ENNReal.summable_toReal end ENNReal namespace NNReal theorem tsum_eq_toNNReal_tsum {f : β → ℝ≥0} : ∑' b, f b = (∑' b, (f b : ℝ≥0∞)).toNNReal := by by_cases h : Summable f · rw [← ENNReal.coe_tsum h, ENNReal.toNNReal_coe] · have A := tsum_eq_zero_of_not_summable h simp only [← ENNReal.tsum_coe_ne_top_iff_summable, Classical.not_not] at h simp only [h, ENNReal.top_toNNReal, A] #align nnreal.tsum_eq_to_nnreal_tsum NNReal.tsum_eq_toNNReal_tsum /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem exists_le_hasSum_of_le {f g : β → ℝ≥0} {r : ℝ≥0} (hgf : ∀ b, g b ≤ f b) (hfr : HasSum f r) : ∃ p ≤ r, HasSum g p := have : (∑' b, (g b : ℝ≥0∞)) ≤ r := by refine hasSum_le (fun b => ?_) ENNReal.summable.hasSum (ENNReal.hasSum_coe.2 hfr) exact ENNReal.coe_le_coe.2 (hgf _) let ⟨p, Eq, hpr⟩ := ENNReal.le_coe_iff.1 this ⟨p, hpr, ENNReal.hasSum_coe.1 <| Eq ▸ ENNReal.summable.hasSum⟩ #align nnreal.exists_le_has_sum_of_le NNReal.exists_le_hasSum_of_le /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem summable_of_le {f g : β → ℝ≥0} (hgf : ∀ b, g b ≤ f b) : Summable f → Summable g | ⟨_r, hfr⟩ => let ⟨_p, _, hp⟩ := exists_le_hasSum_of_le hgf hfr hp.summable #align nnreal.summable_of_le NNReal.summable_of_le /-- Summable non-negative functions have countable support -/ theorem _root_.Summable.countable_support_nnreal (f : α → ℝ≥0) (h : Summable f) : f.support.Countable := by rw [← NNReal.summable_coe] at h simpa [support] using h.countable_support /-- A series of non-negative real numbers converges to `r` in the sense of `HasSum` if and only if the sequence of partial sum converges to `r`. -/ theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by rw [← ENNReal.hasSum_coe, ENNReal.hasSum_iff_tendsto_nat] simp only [← ENNReal.coe_finset_sum] exact ENNReal.tendsto_coe #align nnreal.has_sum_iff_tendsto_nat NNReal.hasSum_iff_tendsto_nat theorem not_summable_iff_tendsto_nat_atTop {f : ℕ → ℝ≥0} : ¬Summable f ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by constructor · intro h refine ((tendsto_of_monotone ?_).resolve_right h).comp ?_ exacts [Finset.sum_mono_set _, tendsto_finset_range] · rintro hnat ⟨r, hr⟩ exact not_tendsto_nhds_of_tendsto_atTop hnat _ (hasSum_iff_tendsto_nat.1 hr) #align nnreal.not_summable_iff_tendsto_nat_at_top NNReal.not_summable_iff_tendsto_nat_atTop theorem summable_iff_not_tendsto_nat_atTop {f : ℕ → ℝ≥0} : Summable f ↔ ¬Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by rw [← not_iff_not, Classical.not_not, not_summable_iff_tendsto_nat_atTop] #align nnreal.summable_iff_not_tendsto_nat_at_top NNReal.summable_iff_not_tendsto_nat_atTop theorem summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : Summable f := by refine summable_iff_not_tendsto_nat_atTop.2 fun H => ?_ rcases exists_lt_of_tendsto_atTop H 0 c with ⟨n, -, hn⟩ exact lt_irrefl _ (hn.trans_le (h n)) #align nnreal.summable_of_sum_range_le NNReal.summable_of_sum_range_le theorem tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : ∑' n, f n ≤ c := _root_.tsum_le_of_sum_range_le (summable_of_sum_range_le h) h #align nnreal.tsum_le_of_sum_range_le NNReal.tsum_le_of_sum_range_le theorem tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : Summable f) {i : β → α} (hi : Function.Injective i) : (∑' x, f (i x)) ≤ ∑' x, f x := tsum_le_tsum_of_inj i hi (fun _ _ => zero_le _) (fun _ => le_rfl) (summable_comp_injective hf hi) hf #align nnreal.tsum_comp_le_tsum_of_inj NNReal.tsum_comp_le_tsum_of_inj theorem summable_sigma {β : α → Type*} {f : (Σ x, β x) → ℝ≥0} : Summable f ↔ (∀ x, Summable fun y => f ⟨x, y⟩) ∧ Summable fun x => ∑' y, f ⟨x, y⟩ := by constructor · simp only [← NNReal.summable_coe, NNReal.coe_tsum] exact fun h => ⟨h.sigma_factor, h.sigma⟩ · rintro ⟨h₁, h₂⟩ simpa only [← ENNReal.tsum_coe_ne_top_iff_summable, ENNReal.tsum_sigma', ENNReal.coe_tsum (h₁ _)] using h₂ #align nnreal.summable_sigma NNReal.summable_sigma theorem indicator_summable {f : α → ℝ≥0} (hf : Summable f) (s : Set α) : Summable (s.indicator f) := by refine NNReal.summable_of_le (fun a => le_trans (le_of_eq (s.indicator_apply f a)) ?_) hf split_ifs · exact le_refl (f a) · exact zero_le_coe #align nnreal.indicator_summable NNReal.indicator_summable theorem tsum_indicator_ne_zero {f : α → ℝ≥0} (hf : Summable f) {s : Set α} (h : ∃ a ∈ s, f a ≠ 0) : (∑' x, (s.indicator f) x) ≠ 0 := fun h' => let ⟨a, ha, hap⟩ := h hap ((Set.indicator_apply_eq_self.mpr (absurd ha)).symm.trans ((tsum_eq_zero_iff (indicator_summable hf s)).1 h' a)) #align nnreal.tsum_indicator_ne_zero NNReal.tsum_indicator_ne_zero open Finset /-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability assumption on `f`, as otherwise all sums are zero. -/ theorem tendsto_sum_nat_add (f : ℕ → ℝ≥0) : Tendsto (fun i => ∑' k, f (k + i)) atTop (𝓝 0) := by rw [← tendsto_coe] convert _root_.tendsto_sum_nat_add fun i => (f i : ℝ) norm_cast #align nnreal.tendsto_sum_nat_add NNReal.tendsto_sum_nat_add nonrec theorem hasSum_lt {f g : α → ℝ≥0} {sf sg : ℝ≥0} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hf : HasSum f sf) (hg : HasSum g sg) : sf < sg := by have A : ∀ a : α, (f a : ℝ) ≤ g a := fun a => NNReal.coe_le_coe.2 (h a) have : (sf : ℝ) < sg := hasSum_lt A (NNReal.coe_lt_coe.2 hi) (hasSum_coe.2 hf) (hasSum_coe.2 hg) exact NNReal.coe_lt_coe.1 this #align nnreal.has_sum_lt NNReal.hasSum_lt @[mono] theorem hasSum_strict_mono {f g : α → ℝ≥0} {sf sg : ℝ≥0} (hf : HasSum f sf) (hg : HasSum g sg) (h : f < g) : sf < sg := let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h hasSum_lt hle hi hf hg #align nnreal.has_sum_strict_mono NNReal.hasSum_strict_mono theorem tsum_lt_tsum {f g : α → ℝ≥0} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hg : Summable g) : ∑' n, f n < ∑' n, g n := hasSum_lt h hi (summable_of_le h hg).hasSum hg.hasSum #align nnreal.tsum_lt_tsum NNReal.tsum_lt_tsum @[mono] theorem tsum_strict_mono {f g : α → ℝ≥0} (hg : Summable g) (h : f < g) : ∑' n, f n < ∑' n, g n := let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h tsum_lt_tsum hle hi hg #align nnreal.tsum_strict_mono NNReal.tsum_strict_mono theorem tsum_pos {g : α → ℝ≥0} (hg : Summable g) (i : α) (hi : 0 < g i) : 0 < ∑' b, g b := by rw [← tsum_zero] exact tsum_lt_tsum (fun a => zero_le _) hi hg #align nnreal.tsum_pos NNReal.tsum_pos theorem tsum_eq_add_tsum_ite {f : α → ℝ≥0} (hf : Summable f) (i : α) : ∑' x, f x = f i + ∑' x, ite (x = i) 0 (f x) := by refine tsum_eq_add_tsum_ite' i (NNReal.summable_of_le (fun i' => ?_) hf) rw [Function.update_apply] split_ifs <;> simp only [zero_le', le_rfl] #align nnreal.tsum_eq_add_tsum_ite NNReal.tsum_eq_add_tsum_ite end NNReal namespace ENNReal theorem tsum_toNNReal_eq {f : α → ℝ≥0∞} (hf : ∀ a, f a ≠ ∞) : (∑' a, f a).toNNReal = ∑' a, (f a).toNNReal := (congr_arg ENNReal.toNNReal (tsum_congr fun x => (coe_toNNReal (hf x)).symm)).trans NNReal.tsum_eq_toNNReal_tsum.symm #align ennreal.tsum_to_nnreal_eq ENNReal.tsum_toNNReal_eq theorem tsum_toReal_eq {f : α → ℝ≥0∞} (hf : ∀ a, f a ≠ ∞) : (∑' a, f a).toReal = ∑' a, (f a).toReal := by simp only [ENNReal.toReal, tsum_toNNReal_eq hf, NNReal.coe_tsum] #align ennreal.tsum_to_real_eq ENNReal.tsum_toReal_eq theorem tendsto_sum_nat_add (f : ℕ → ℝ≥0∞) (hf : ∑' i, f i ≠ ∞) : Tendsto (fun i => ∑' k, f (k + i)) atTop (𝓝 0) := by lift f to ℕ → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hf replace hf : Summable f := tsum_coe_ne_top_iff_summable.1 hf simp only [← ENNReal.coe_tsum, NNReal.summable_nat_add _ hf, ← ENNReal.coe_zero] exact mod_cast NNReal.tendsto_sum_nat_add f #align ennreal.tendsto_sum_nat_add ENNReal.tendsto_sum_nat_add theorem tsum_le_of_sum_range_le {f : ℕ → ℝ≥0∞} {c : ℝ≥0∞} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : ∑' n, f n ≤ c := _root_.tsum_le_of_sum_range_le ENNReal.summable h #align ennreal.tsum_le_of_sum_range_le ENNReal.tsum_le_of_sum_range_le theorem hasSum_lt {f g : α → ℝ≥0∞} {sf sg : ℝ≥0∞} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hsf : sf ≠ ∞) (hf : HasSum f sf) (hg : HasSum g sg) : sf < sg := by by_cases hsg : sg = ∞ · exact hsg.symm ▸ lt_of_le_of_ne le_top hsf · have hg' : ∀ x, g x ≠ ∞ := ENNReal.ne_top_of_tsum_ne_top (hg.tsum_eq.symm ▸ hsg) lift f to α → ℝ≥0 using fun x => ne_of_lt (lt_of_le_of_lt (h x) <| lt_of_le_of_ne le_top (hg' x)) lift g to α → ℝ≥0 using hg' lift sf to ℝ≥0 using hsf lift sg to ℝ≥0 using hsg simp only [coe_le_coe, coe_lt_coe] at h hi ⊢ exact NNReal.hasSum_lt h hi (ENNReal.hasSum_coe.1 hf) (ENNReal.hasSum_coe.1 hg) #align ennreal.has_sum_lt ENNReal.hasSum_lt theorem tsum_lt_tsum {f g : α → ℝ≥0∞} {i : α} (hfi : tsum f ≠ ∞) (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) : ∑' x, f x < ∑' x, g x := hasSum_lt h hi hfi ENNReal.summable.hasSum ENNReal.summable.hasSum #align ennreal.tsum_lt_tsum ENNReal.tsum_lt_tsum end ENNReal theorem tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ} (hf : Summable f) (hn : ∀ a, 0 ≤ f a) {i : β → α} (hi : Function.Injective i) : tsum (f ∘ i) ≤ tsum f := by lift f to α → ℝ≥0 using hn rw [NNReal.summable_coe] at hf simpa only [(· ∘ ·), ← NNReal.coe_tsum] using NNReal.tsum_comp_le_tsum_of_inj hf hi #align tsum_comp_le_tsum_of_inj tsum_comp_le_tsum_of_inj /-- Comparison test of convergence of series of non-negative real numbers. -/
Mathlib/Topology/Instances/ENNReal.lean
1,330
1,335
theorem Summable.of_nonneg_of_le {f g : β → ℝ} (hg : ∀ b, 0 ≤ g b) (hgf : ∀ b, g b ≤ f b) (hf : Summable f) : Summable g := by
lift f to β → ℝ≥0 using fun b => (hg b).trans (hgf b) lift g to β → ℝ≥0 using hg rw [NNReal.summable_coe] at hf ⊢ exact NNReal.summable_of_le (fun b => NNReal.coe_le_coe.1 (hgf b)) hf
/- Copyright (c) 2021 Shing Tak Lam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shing Tak Lam -/ import Mathlib.Topology.Order.ProjIcc import Mathlib.Topology.ContinuousFunction.Ordered import Mathlib.Topology.CompactOpen import Mathlib.Topology.UnitInterval #align_import topology.homotopy.basic from "leanprover-community/mathlib"@"11c53f174270aa43140c0b26dabce5fc4a253e80" /-! # Homotopy between functions In this file, we define a homotopy between two functions `f₀` and `f₁`. First we define `ContinuousMap.Homotopy` between the two functions, with no restrictions on the intermediate maps. Then, as in the formalisation in HOL-Analysis, we define `ContinuousMap.HomotopyWith f₀ f₁ P`, for homotopies between `f₀` and `f₁`, where the intermediate maps satisfy the predicate `P`. Finally, we define `ContinuousMap.HomotopyRel f₀ f₁ S`, for homotopies between `f₀` and `f₁` which are fixed on `S`. ## Definitions * `ContinuousMap.Homotopy f₀ f₁` is the type of homotopies between `f₀` and `f₁`. * `ContinuousMap.HomotopyWith f₀ f₁ P` is the type of homotopies between `f₀` and `f₁`, where the intermediate maps satisfy the predicate `P`. * `ContinuousMap.HomotopyRel f₀ f₁ S` is the type of homotopies between `f₀` and `f₁` which are fixed on `S`. For each of the above, we have * `refl f`, which is the constant homotopy from `f` to `f`. * `symm F`, which reverses the homotopy `F`. For example, if `F : ContinuousMap.Homotopy f₀ f₁`, then `F.symm : ContinuousMap.Homotopy f₁ f₀`. * `trans F G`, which concatenates the homotopies `F` and `G`. For example, if `F : ContinuousMap.Homotopy f₀ f₁` and `G : ContinuousMap.Homotopy f₁ f₂`, then `F.trans G : ContinuousMap.Homotopy f₀ f₂`. We also define the relations * `ContinuousMap.Homotopic f₀ f₁` is defined to be `Nonempty (ContinuousMap.Homotopy f₀ f₁)` * `ContinuousMap.HomotopicWith f₀ f₁ P` is defined to be `Nonempty (ContinuousMap.HomotopyWith f₀ f₁ P)` * `ContinuousMap.HomotopicRel f₀ f₁ P` is defined to be `Nonempty (ContinuousMap.HomotopyRel f₀ f₁ P)` and for `ContinuousMap.homotopic` and `ContinuousMap.homotopic_rel`, we also define the `setoid` and `quotient` in `C(X, Y)` by these relations. ## References - [HOL-Analysis formalisation](https://isabelle.in.tum.de/library/HOL/HOL-Analysis/Homotopy.html) -/ noncomputable section universe u v w x variable {F : Type*} {X : Type u} {Y : Type v} {Z : Type w} {Z' : Type x} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace Z'] open unitInterval namespace ContinuousMap /-- `ContinuousMap.Homotopy f₀ f₁` is the type of homotopies from `f₀` to `f₁`. When possible, instead of parametrizing results over `(f : Homotopy f₀ f₁)`, you should parametrize over `{F : Type*} [HomotopyLike F f₀ f₁] (f : F)`. When you extend this structure, make sure to extend `ContinuousMap.HomotopyLike`. -/ structure Homotopy (f₀ f₁ : C(X, Y)) extends C(I × X, Y) where /-- value of the homotopy at 0 -/ map_zero_left : ∀ x, toFun (0, x) = f₀ x /-- value of the homotopy at 1 -/ map_one_left : ∀ x, toFun (1, x) = f₁ x #align continuous_map.homotopy ContinuousMap.Homotopy section /-- `ContinuousMap.HomotopyLike F f₀ f₁` states that `F` is a type of homotopies between `f₀` and `f₁`. You should extend this class when you extend `ContinuousMap.Homotopy`. -/ class HomotopyLike {X Y : outParam Type*} [TopologicalSpace X] [TopologicalSpace Y] (F : Type*) (f₀ f₁ : outParam <| C(X, Y)) [FunLike F (I × X) Y] extends ContinuousMapClass F (I × X) Y : Prop where /-- value of the homotopy at 0 -/ map_zero_left (f : F) : ∀ x, f (0, x) = f₀ x /-- value of the homotopy at 1 -/ map_one_left (f : F) : ∀ x, f (1, x) = f₁ x #align continuous_map.homotopy_like ContinuousMap.HomotopyLike end namespace Homotopy section variable {f₀ f₁ : C(X, Y)} instance instFunLike : FunLike (Homotopy f₀ f₁) (I × X) Y where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : HomotopyLike (Homotopy f₀ f₁) f₀ f₁ where map_continuous f := f.continuous_toFun map_zero_left f := f.map_zero_left map_one_left f := f.map_one_left @[ext] theorem ext {F G : Homotopy f₀ f₁} (h : ∀ x, F x = G x) : F = G := DFunLike.ext _ _ h #align continuous_map.homotopy.ext ContinuousMap.Homotopy.ext /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (F : Homotopy f₀ f₁) : I × X → Y := F #align continuous_map.homotopy.simps.apply ContinuousMap.Homotopy.Simps.apply initialize_simps_projections Homotopy (toFun → apply, -toContinuousMap) /-- Deprecated. Use `map_continuous` instead. -/ protected theorem continuous (F : Homotopy f₀ f₁) : Continuous F := F.continuous_toFun #align continuous_map.homotopy.continuous ContinuousMap.Homotopy.continuous @[simp] theorem apply_zero (F : Homotopy f₀ f₁) (x : X) : F (0, x) = f₀ x := F.map_zero_left x #align continuous_map.homotopy.apply_zero ContinuousMap.Homotopy.apply_zero @[simp] theorem apply_one (F : Homotopy f₀ f₁) (x : X) : F (1, x) = f₁ x := F.map_one_left x #align continuous_map.homotopy.apply_one ContinuousMap.Homotopy.apply_one @[simp] theorem coe_toContinuousMap (F : Homotopy f₀ f₁) : ⇑F.toContinuousMap = F := rfl #align continuous_map.homotopy.coe_to_continuous_map ContinuousMap.Homotopy.coe_toContinuousMap /-- Currying a homotopy to a continuous function from `I` to `C(X, Y)`. -/ def curry (F : Homotopy f₀ f₁) : C(I, C(X, Y)) := F.toContinuousMap.curry #align continuous_map.homotopy.curry ContinuousMap.Homotopy.curry @[simp] theorem curry_apply (F : Homotopy f₀ f₁) (t : I) (x : X) : F.curry t x = F (t, x) := rfl #align continuous_map.homotopy.curry_apply ContinuousMap.Homotopy.curry_apply /-- Continuously extending a curried homotopy to a function from `ℝ` to `C(X, Y)`. -/ def extend (F : Homotopy f₀ f₁) : C(ℝ, C(X, Y)) := F.curry.IccExtend zero_le_one #align continuous_map.homotopy.extend ContinuousMap.Homotopy.extend theorem extend_apply_of_le_zero (F : Homotopy f₀ f₁) {t : ℝ} (ht : t ≤ 0) (x : X) : F.extend t x = f₀ x := by rw [← F.apply_zero] exact ContinuousMap.congr_fun (Set.IccExtend_of_le_left (zero_le_one' ℝ) F.curry ht) x #align continuous_map.homotopy.extend_apply_of_le_zero ContinuousMap.Homotopy.extend_apply_of_le_zero
Mathlib/Topology/Homotopy/Basic.lean
172
175
theorem extend_apply_of_one_le (F : Homotopy f₀ f₁) {t : ℝ} (ht : 1 ≤ t) (x : X) : F.extend t x = f₁ x := by
rw [← F.apply_one] exact ContinuousMap.congr_fun (Set.IccExtend_of_right_le (zero_le_one' ℝ) F.curry ht) x
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.BigOperators.NatAntidiagonal import Mathlib.Topology.Algebra.InfiniteSum.Constructions import Mathlib.Topology.Algebra.Ring.Basic #align_import topology.algebra.infinite_sum.ring from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Infinite sum in a ring This file provides lemmas about the interaction between infinite sums and multiplication. ## Main results * `tsum_mul_tsum_eq_tsum_sum_antidiagonal`: Cauchy product formula -/ open Filter Finset Function open scoped Classical variable {ι κ R α : Type*} section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] [TopologicalSpace α] [TopologicalSemiring α] {f g : ι → α} {a a₁ a₂ : α} theorem HasSum.mul_left (a₂) (h : HasSum f a₁) : HasSum (fun i ↦ a₂ * f i) (a₂ * a₁) := by simpa only using h.map (AddMonoidHom.mulLeft a₂) (continuous_const.mul continuous_id) #align has_sum.mul_left HasSum.mul_left
Mathlib/Topology/Algebra/InfiniteSum/Ring.lean
38
39
theorem HasSum.mul_right (a₂) (hf : HasSum f a₁) : HasSum (fun i ↦ f i * a₂) (a₁ * a₂) := by
simpa only using hf.map (AddMonoidHom.mulRight a₂) (continuous_id.mul continuous_const)
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Scott Morrison -/ import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.Products.Basic #align_import category_theory.pi.basic from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Categories of indexed families of objects. We define the pointwise category structure on indexed families of objects in a category (and also the dependent generalization). -/ namespace CategoryTheory universe w₀ w₁ w₂ v₁ v₂ v₃ u₁ u₂ u₃ variable {I : Type w₀} {J : Type w₁} (C : I → Type u₁) [∀ i, Category.{v₁} (C i)] /-- `pi C` gives the cartesian product of an indexed family of categories. -/ instance pi : Category.{max w₀ v₁} (∀ i, C i) where Hom X Y := ∀ i, X i ⟶ Y i id X i := 𝟙 (X i) comp f g i := f i ≫ g i #align category_theory.pi CategoryTheory.pi /-- This provides some assistance to typeclass search in a common situation, which otherwise fails. (Without this `CategoryTheory.Pi.has_limit_of_has_limit_comp_eval` fails.) -/ abbrev pi' {I : Type v₁} (C : I → Type u₁) [∀ i, Category.{v₁} (C i)] : Category.{v₁} (∀ i, C i) := CategoryTheory.pi C #align category_theory.pi' CategoryTheory.pi' attribute [instance] pi' namespace Pi @[simp] theorem id_apply (X : ∀ i, C i) (i) : (𝟙 X : ∀ i, X i ⟶ X i) i = 𝟙 (X i) := rfl #align category_theory.pi.id_apply CategoryTheory.Pi.id_apply @[simp] theorem comp_apply {X Y Z : ∀ i, C i} (f : X ⟶ Y) (g : Y ⟶ Z) (i) : (f ≫ g : ∀ i, X i ⟶ Z i) i = f i ≫ g i := rfl #align category_theory.pi.comp_apply CategoryTheory.Pi.comp_apply -- Porting note: need to add an additional `ext` lemma. @[ext] lemma ext {X Y : ∀ i, C i} {f g : X ⟶ Y} (w : ∀ i, f i = g i) : f = g := funext (w ·) /-- The evaluation functor at `i : I`, sending an `I`-indexed family of objects to the object over `i`. -/ @[simps] def eval (i : I) : (∀ i, C i) ⥤ C i where obj f := f i map α := α i #align category_theory.pi.eval CategoryTheory.Pi.eval section variable {J : Type w₁} /- Porting note: add this because Lean cannot see directly through the `∘` for `Function.comp` -/ instance (f : J → I) : (j : J) → Category ((C ∘ f) j) := by dsimp infer_instance /-- Pull back an `I`-indexed family of objects to a `J`-indexed family, along a function `J → I`. -/ @[simps] def comap (h : J → I) : (∀ i, C i) ⥤ (∀ j, C (h j)) where obj f i := f (h i) map α i := α (h i) #align category_theory.pi.comap CategoryTheory.Pi.comap variable (I) /-- The natural isomorphism between pulling back a grading along the identity function, and the identity functor. -/ @[simps] def comapId : comap C (id : I → I) ≅ 𝟭 (∀ i, C i) where hom := { app := fun X => 𝟙 X } inv := { app := fun X => 𝟙 X } #align category_theory.pi.comap_id CategoryTheory.Pi.comapId example (g : J → I) : (j : J) → Category (C (g j)) := by infer_instance variable {I} variable {K : Type w₂} /-- The natural isomorphism comparing between pulling back along two successive functions, and pulling back along their composition -/ @[simps!] def comapComp (f : K → J) (g : J → I) : comap C g ⋙ comap (C ∘ g) f ≅ comap C (g ∘ f) where hom := { app := fun X b => 𝟙 (X (g (f b))) naturality := fun X Y f' => by simp only [comap, Function.comp]; funext; simp } inv := { app := fun X b => 𝟙 (X (g (f b))) naturality := fun X Y f' => by simp only [comap, Function.comp]; funext; simp } #align category_theory.pi.comap_comp CategoryTheory.Pi.comapComp /-- The natural isomorphism between pulling back then evaluating, and just evaluating. -/ @[simps!] def comapEvalIsoEval (h : J → I) (j : J) : comap C h ⋙ eval (C ∘ h) j ≅ eval C (h j) := NatIso.ofComponents (fun f => Iso.refl _) (by simp only [Iso.refl]; aesop_cat) #align category_theory.pi.comap_eval_iso_eval CategoryTheory.Pi.comapEvalIsoEval end section variable {J : Type w₀} {D : J → Type u₁} [∀ j, Category.{v₁} (D j)] /- Porting note: maybe mixing up universes -/ instance sumElimCategory : ∀ s : Sum I J, Category.{v₁} (Sum.elim C D s) | Sum.inl i => by dsimp infer_instance | Sum.inr j => by dsimp infer_instance #align category_theory.pi.sum_elim_category CategoryTheory.Pi.sumElimCategoryₓ /- Porting note: replaced `Sum.rec` with `match`'s per the error about current state of code generation -/ /-- The bifunctor combining an `I`-indexed family of objects with a `J`-indexed family of objects to obtain an `I ⊕ J`-indexed family of objects. -/ @[simps] def sum : (∀ i, C i) ⥤ (∀ j, D j) ⥤ ∀ s : Sum I J, Sum.elim C D s where obj X := { obj := fun Y s => match s with | .inl i => X i | .inr j => Y j map := fun {Y} {Y'} f s => match s with | .inl i => 𝟙 (X i) | .inr j => f j } map {X} {X'} f := { app := fun Y s => match s with | .inl i => f i | .inr j => 𝟙 (Y j) } #align category_theory.pi.sum CategoryTheory.Pi.sum end variable {C} /-- An isomorphism between `I`-indexed objects gives an isomorphism between each pair of corresponding components. -/ @[simps] def isoApp {X Y : ∀ i, C i} (f : X ≅ Y) (i : I) : X i ≅ Y i := ⟨f.hom i, f.inv i, by rw [← comp_apply, Iso.hom_inv_id, id_apply], by rw [← comp_apply, Iso.inv_hom_id, id_apply]⟩ #align category_theory.pi.iso_app CategoryTheory.Pi.isoApp @[simp] theorem isoApp_refl (X : ∀ i, C i) (i : I) : isoApp (Iso.refl X) i = Iso.refl (X i) := rfl #align category_theory.pi.iso_app_refl CategoryTheory.Pi.isoApp_refl @[simp] theorem isoApp_symm {X Y : ∀ i, C i} (f : X ≅ Y) (i : I) : isoApp f.symm i = (isoApp f i).symm := rfl #align category_theory.pi.iso_app_symm CategoryTheory.Pi.isoApp_symm @[simp] theorem isoApp_trans {X Y Z : ∀ i, C i} (f : X ≅ Y) (g : Y ≅ Z) (i : I) : isoApp (f ≪≫ g) i = isoApp f i ≪≫ isoApp g i := rfl #align category_theory.pi.iso_app_trans CategoryTheory.Pi.isoApp_trans end Pi namespace Functor variable {C} variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)] {A : Type u₃} [Category.{v₃} A] /-- Assemble an `I`-indexed family of functors into a functor between the pi types. -/ @[simps] def pi (F : ∀ i, C i ⥤ D i) : (∀ i, C i) ⥤ ∀ i, D i where obj f i := (F i).obj (f i) map α i := (F i).map (α i) #align category_theory.functor.pi CategoryTheory.Functor.pi /-- Similar to `pi`, but all functors come from the same category `A` -/ @[simps] def pi' (f : ∀ i, A ⥤ C i) : A ⥤ ∀ i, C i where obj a i := (f i).obj a map h i := (f i).map h #align category_theory.functor.pi' CategoryTheory.Functor.pi' /-- The projections of `Functor.pi' F` are isomorphic to the functors of the family `F` -/ @[simps!] def pi'CompEval {A : Type*} [Category A] (F : ∀ i, A ⥤ C i) (i : I) : pi' F ⋙ Pi.eval C i ≅ F i := Iso.refl _ section EqToHom @[simp]
Mathlib/CategoryTheory/Pi/Basic.lean
226
229
theorem eqToHom_proj {x x' : ∀ i, C i} (h : x = x') (i : I) : (eqToHom h : x ⟶ x') i = eqToHom (Function.funext_iff.mp h i) := by
subst h rfl
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Data.Real.Basic import Mathlib.Data.Set.Image #align_import data.complex.basic from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004" /-! # The complex numbers The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field of characteristic zero. The result that the complex numbers are algebraically closed, see `FieldTheory.AlgebraicClosure`. -/ open Set Function /-! ### Definition and basic arithmetic -/ /-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/ structure Complex : Type where /-- The real part of a complex number. -/ re : ℝ /-- The imaginary part of a complex number. -/ im : ℝ #align complex Complex @[inherit_doc] notation "ℂ" => Complex namespace Complex open ComplexConjugate noncomputable instance : DecidableEq ℂ := Classical.decEq _ /-- The equivalence between the complex numbers and `ℝ × ℝ`. -/ @[simps apply] def equivRealProd : ℂ ≃ ℝ × ℝ where toFun z := ⟨z.re, z.im⟩ invFun p := ⟨p.1, p.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl #align complex.equiv_real_prod Complex.equivRealProd @[simp] theorem eta : ∀ z : ℂ, Complex.mk z.re z.im = z | ⟨_, _⟩ => rfl #align complex.eta Complex.eta -- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `ℂ` appear. theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w | ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl #align complex.ext Complex.ext attribute [local ext] Complex.ext theorem ext_iff {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im := ⟨fun H => by simp [H], fun h => ext h.1 h.2⟩ #align complex.ext_iff Complex.ext_iff theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩ #align complex.re_surjective Complex.re_surjective theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩ #align complex.im_surjective Complex.im_surjective @[simp] theorem range_re : range re = univ := re_surjective.range_eq #align complex.range_re Complex.range_re @[simp] theorem range_im : range im = univ := im_surjective.range_eq #align complex.range_im Complex.range_im -- Porting note: refactored instance to allow `norm_cast` to work /-- The natural inclusion of the real numbers into the complex numbers. The name `Complex.ofReal` is reserved for the bundled homomorphism. -/ @[coe] def ofReal' (r : ℝ) : ℂ := ⟨r, 0⟩ instance : Coe ℝ ℂ := ⟨ofReal'⟩ @[simp, norm_cast] theorem ofReal_re (r : ℝ) : Complex.re (r : ℂ) = r := rfl #align complex.of_real_re Complex.ofReal_re @[simp, norm_cast] theorem ofReal_im (r : ℝ) : (r : ℂ).im = 0 := rfl #align complex.of_real_im Complex.ofReal_im theorem ofReal_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl #align complex.of_real_def Complex.ofReal_def @[simp, norm_cast] theorem ofReal_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w := ⟨congrArg re, by apply congrArg⟩ #align complex.of_real_inj Complex.ofReal_inj -- Porting note: made coercion explicit theorem ofReal_injective : Function.Injective ((↑) : ℝ → ℂ) := fun _ _ => congrArg re #align complex.of_real_injective Complex.ofReal_injective -- Porting note: made coercion explicit instance canLift : CanLift ℂ ℝ (↑) fun z => z.im = 0 where prf z hz := ⟨z.re, ext rfl hz.symm⟩ #align complex.can_lift Complex.canLift /-- The product of a set on the real axis and a set on the imaginary axis of the complex plane, denoted by `s ×ℂ t`. -/ def Set.reProdIm (s t : Set ℝ) : Set ℂ := re ⁻¹' s ∩ im ⁻¹' t #align set.re_prod_im Complex.Set.reProdIm @[inherit_doc] infixl:72 " ×ℂ " => Set.reProdIm theorem mem_reProdIm {z : ℂ} {s t : Set ℝ} : z ∈ s ×ℂ t ↔ z.re ∈ s ∧ z.im ∈ t := Iff.rfl #align complex.mem_re_prod_im Complex.mem_reProdIm instance : Zero ℂ := ⟨(0 : ℝ)⟩ instance : Inhabited ℂ := ⟨0⟩ @[simp] theorem zero_re : (0 : ℂ).re = 0 := rfl #align complex.zero_re Complex.zero_re @[simp] theorem zero_im : (0 : ℂ).im = 0 := rfl #align complex.zero_im Complex.zero_im @[simp, norm_cast] theorem ofReal_zero : ((0 : ℝ) : ℂ) = 0 := rfl #align complex.of_real_zero Complex.ofReal_zero @[simp] theorem ofReal_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := ofReal_inj #align complex.of_real_eq_zero Complex.ofReal_eq_zero theorem ofReal_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr ofReal_eq_zero #align complex.of_real_ne_zero Complex.ofReal_ne_zero instance : One ℂ := ⟨(1 : ℝ)⟩ @[simp] theorem one_re : (1 : ℂ).re = 1 := rfl #align complex.one_re Complex.one_re @[simp] theorem one_im : (1 : ℂ).im = 0 := rfl #align complex.one_im Complex.one_im @[simp, norm_cast] theorem ofReal_one : ((1 : ℝ) : ℂ) = 1 := rfl #align complex.of_real_one Complex.ofReal_one @[simp] theorem ofReal_eq_one {z : ℝ} : (z : ℂ) = 1 ↔ z = 1 := ofReal_inj #align complex.of_real_eq_one Complex.ofReal_eq_one theorem ofReal_ne_one {z : ℝ} : (z : ℂ) ≠ 1 ↔ z ≠ 1 := not_congr ofReal_eq_one #align complex.of_real_ne_one Complex.ofReal_ne_one instance : Add ℂ := ⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩ @[simp] theorem add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl #align complex.add_re Complex.add_re @[simp] theorem add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl #align complex.add_im Complex.add_im -- replaced by `re_ofNat` #noalign complex.bit0_re #noalign complex.bit1_re -- replaced by `im_ofNat` #noalign complex.bit0_im #noalign complex.bit1_im @[simp, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := ext_iff.2 <| by simp [ofReal'] #align complex.of_real_add Complex.ofReal_add -- replaced by `Complex.ofReal_ofNat` #noalign complex.of_real_bit0 #noalign complex.of_real_bit1 instance : Neg ℂ := ⟨fun z => ⟨-z.re, -z.im⟩⟩ @[simp] theorem neg_re (z : ℂ) : (-z).re = -z.re := rfl #align complex.neg_re Complex.neg_re @[simp] theorem neg_im (z : ℂ) : (-z).im = -z.im := rfl #align complex.neg_im Complex.neg_im @[simp, norm_cast] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := ext_iff.2 <| by simp [ofReal'] #align complex.of_real_neg Complex.ofReal_neg instance : Sub ℂ := ⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩ instance : Mul ℂ := ⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩ @[simp] theorem mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl #align complex.mul_re Complex.mul_re @[simp] theorem mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl #align complex.mul_im Complex.mul_im @[simp, norm_cast] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := ext_iff.2 <| by simp [ofReal'] #align complex.of_real_mul Complex.ofReal_mul theorem re_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).re = r * z.re := by simp [ofReal'] #align complex.of_real_mul_re Complex.re_ofReal_mul
Mathlib/Data/Complex/Basic.lean
262
262
theorem im_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).im = r * z.im := by
simp [ofReal']
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.Convex.SpecificFunctions.Deriv import Mathlib.Analysis.SpecialFunctions.Pow.Complex #align_import analysis.special_functions.trigonometric.complex from "leanprover-community/mathlib"@"8f9fea08977f7e450770933ee6abb20733b47c92" /-! # Complex trigonometric functions Basic facts and derivatives for the complex trigonometric functions. Several facts about the real trigonometric functions have the proofs deferred here, rather than `Analysis.SpecialFunctions.Trigonometric.Basic`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions, or require additional imports which are not available in that file. -/ noncomputable section namespace Complex open Set Filter open scoped Real theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 := by have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1 := by rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 two_ne_zero, zero_mul, add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, ← div_eq_iff (exp_ne_zero _), ← exp_sub] ring_nf rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm] refine exists_congr fun x => ?_ refine (iff_of_eq <| congr_arg _ ?_).trans (mul_right_inj' <| mul_ne_zero two_ne_zero I_ne_zero) field_simp; ring #align complex.cos_eq_zero_iff Complex.cos_eq_zero_iff theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 := by rw [← not_exists, not_iff_not, cos_eq_zero_iff] #align complex.cos_ne_zero_iff Complex.cos_ne_zero_iff theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π := by rw [← Complex.cos_sub_pi_div_two, cos_eq_zero_iff] constructor · rintro ⟨k, hk⟩ use k + 1 field_simp [eq_add_of_sub_eq hk] ring · rintro ⟨k, rfl⟩ use k - 1 field_simp ring #align complex.sin_eq_zero_iff Complex.sin_eq_zero_iff theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] #align complex.sin_ne_zero_iff Complex.sin_ne_zero_iff /-- The tangent of a complex number is equal to zero iff this number is equal to `k * π / 2` for an integer `k`. Note that this lemma takes into account that we use zero as the junk value for division by zero. See also `Complex.tan_eq_zero_iff'`. -/ theorem tan_eq_zero_iff {θ : ℂ} : tan θ = 0 ↔ ∃ k : ℤ, k * π / 2 = θ := by rw [tan, div_eq_zero_iff, ← mul_eq_zero, ← mul_right_inj' two_ne_zero, mul_zero, ← mul_assoc, ← sin_two_mul, sin_eq_zero_iff] field_simp [mul_comm, eq_comm] #align complex.tan_eq_zero_iff Complex.tan_eq_zero_iff theorem tan_ne_zero_iff {θ : ℂ} : tan θ ≠ 0 ↔ ∀ k : ℤ, (k * π / 2 : ℂ) ≠ θ := by rw [← not_exists, not_iff_not, tan_eq_zero_iff] #align complex.tan_ne_zero_iff Complex.tan_ne_zero_iff theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 := tan_eq_zero_iff.mpr (by use n) #align complex.tan_int_mul_pi_div_two Complex.tan_int_mul_pi_div_two /-- If the tangent of a complex number is well-defined, then it is equal to zero iff the number is equal to `k * π` for an integer `k`. See also `Complex.tan_eq_zero_iff` for a version that takes into account junk values of `θ`. -/ theorem tan_eq_zero_iff' {θ : ℂ} (hθ : cos θ ≠ 0) : tan θ = 0 ↔ ∃ k : ℤ, k * π = θ := by simp only [tan, hθ, div_eq_zero_iff, sin_eq_zero_iff]; simp [eq_comm] theorem cos_eq_cos_iff {x y : ℂ} : cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := calc cos x = cos y ↔ cos x - cos y = 0 := sub_eq_zero.symm _ ↔ -2 * sin ((x + y) / 2) * sin ((x - y) / 2) = 0 := by rw [cos_sub_cos] _ ↔ sin ((x + y) / 2) = 0 ∨ sin ((x - y) / 2) = 0 := by simp [(by norm_num : (2 : ℂ) ≠ 0)] _ ↔ sin ((x - y) / 2) = 0 ∨ sin ((x + y) / 2) = 0 := or_comm _ ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ ∃ k : ℤ, y = 2 * k * π - x := by apply or_congr <;> field_simp [sin_eq_zero_iff, (by norm_num : -(2 : ℂ) ≠ 0), eq_sub_iff_add_eq', sub_eq_iff_eq_add, mul_comm (2 : ℂ), mul_right_comm _ (2 : ℂ)] constructor <;> · rintro ⟨k, rfl⟩; use -k; simp _ ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := exists_or.symm #align complex.cos_eq_cos_iff Complex.cos_eq_cos_iff theorem sin_eq_sin_iff {x y : ℂ} : sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x := by simp only [← Complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add] refine exists_congr fun k => or_congr ?_ ?_ <;> refine Eq.congr rfl ?_ <;> field_simp <;> ring #align complex.sin_eq_sin_iff Complex.sin_eq_sin_iff theorem cos_eq_one_iff {x : ℂ} : cos x = 1 ↔ ∃ k : ℤ, k * (2 * π) = x := by rw [← cos_zero, eq_comm, cos_eq_cos_iff] simp [mul_assoc, mul_left_comm, eq_comm]
Mathlib/Analysis/SpecialFunctions/Trigonometric/Complex.lean
114
116
theorem cos_eq_neg_one_iff {x : ℂ} : cos x = -1 ↔ ∃ k : ℤ, π + k * (2 * π) = x := by
rw [← neg_eq_iff_eq_neg, ← cos_sub_pi, cos_eq_one_iff] simp only [eq_sub_iff_add_eq']
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.NormedSpace.Banach import Mathlib.LinearAlgebra.SesquilinearForm #align_import analysis.inner_product_space.symmetric from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Symmetric linear maps in an inner product space This file defines and proves basic theorems about symmetric **not necessarily bounded** operators on an inner product space, i.e linear maps `T : E → E` such that `∀ x y, ⟪T x, y⟫ = ⟪x, T y⟫`. In comparison to `IsSelfAdjoint`, this definition works for non-continuous linear maps, and doesn't rely on the definition of the adjoint, which allows it to be stated in non-complete space. ## Main definitions * `LinearMap.IsSymmetric`: a (not necessarily bounded) operator on an inner product space is symmetric, if for all `x`, `y`, we have `⟪T x, y⟫ = ⟪x, T y⟫` ## Main statements * `IsSymmetric.continuous`: if a symmetric operator is defined on a complete space, then it is automatically continuous. ## Tags self-adjoint, symmetric -/ open RCLike open ComplexConjugate variable {𝕜 E E' F G : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] variable [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] variable [NormedAddCommGroup E'] [InnerProductSpace ℝ E'] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y namespace LinearMap /-! ### Symmetric operators -/ /-- A (not necessarily bounded) operator on an inner product space is symmetric, if for all `x`, `y`, we have `⟪T x, y⟫ = ⟪x, T y⟫`. -/ def IsSymmetric (T : E →ₗ[𝕜] E) : Prop := ∀ x y, ⟪T x, y⟫ = ⟪x, T y⟫ #align linear_map.is_symmetric LinearMap.IsSymmetric section Real /-- An operator `T` on an inner product space is symmetric if and only if it is `LinearMap.IsSelfAdjoint` with respect to the sesquilinear form given by the inner product. -/ theorem isSymmetric_iff_sesqForm (T : E →ₗ[𝕜] E) : T.IsSymmetric ↔ LinearMap.IsSelfAdjoint (R := 𝕜) (M := E) sesqFormOfInner T := ⟨fun h x y => (h y x).symm, fun h x y => (h y x).symm⟩ #align linear_map.is_symmetric_iff_sesq_form LinearMap.isSymmetric_iff_sesqForm end Real theorem IsSymmetric.conj_inner_sym {T : E →ₗ[𝕜] E} (hT : IsSymmetric T) (x y : E) : conj ⟪T x, y⟫ = ⟪T y, x⟫ := by rw [hT x y, inner_conj_symm] #align linear_map.is_symmetric.conj_inner_sym LinearMap.IsSymmetric.conj_inner_sym @[simp] theorem IsSymmetric.apply_clm {T : E →L[𝕜] E} (hT : IsSymmetric (T : E →ₗ[𝕜] E)) (x y : E) : ⟪T x, y⟫ = ⟪x, T y⟫ := hT x y #align linear_map.is_symmetric.apply_clm LinearMap.IsSymmetric.apply_clm theorem isSymmetric_zero : (0 : E →ₗ[𝕜] E).IsSymmetric := fun x y => (inner_zero_right x : ⟪x, 0⟫ = 0).symm ▸ (inner_zero_left y : ⟪0, y⟫ = 0) #align linear_map.is_symmetric_zero LinearMap.isSymmetric_zero theorem isSymmetric_id : (LinearMap.id : E →ₗ[𝕜] E).IsSymmetric := fun _ _ => rfl #align linear_map.is_symmetric_id LinearMap.isSymmetric_id theorem IsSymmetric.add {T S : E →ₗ[𝕜] E} (hT : T.IsSymmetric) (hS : S.IsSymmetric) : (T + S).IsSymmetric := by intro x y rw [LinearMap.add_apply, inner_add_left, hT x y, hS x y, ← inner_add_right] rfl #align linear_map.is_symmetric.add LinearMap.IsSymmetric.add /-- The **Hellinger--Toeplitz theorem**: if a symmetric operator is defined on a complete space, then it is automatically continuous. -/
Mathlib/Analysis/InnerProductSpace/Symmetric.lean
97
110
theorem IsSymmetric.continuous [CompleteSpace E] {T : E →ₗ[𝕜] E} (hT : IsSymmetric T) : Continuous T := by
-- We prove it by using the closed graph theorem refine T.continuous_of_seq_closed_graph fun u x y hu hTu => ?_ rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hlhs : ∀ k : ℕ, ⟪T (u k) - T x, y - T x⟫ = ⟪u k - x, T (y - T x)⟫ := by intro k rw [← T.map_sub, hT] refine tendsto_nhds_unique ((hTu.sub_const _).inner tendsto_const_nhds) ?_ simp_rw [Function.comp_apply, hlhs] rw [← inner_zero_left (T (y - T x))] refine Filter.Tendsto.inner ?_ tendsto_const_nhds rw [← sub_self x] exact hu.sub_const _
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.PEquiv #align_import data.matrix.pequiv from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # partial equivalences for matrices Using partial equivalences to represent matrices. This file introduces the function `PEquiv.toMatrix`, which returns a matrix containing ones and zeros. For any partial equivalence `f`, `f.toMatrix i j = 1 ↔ f i = some j`. The following important properties of this function are proved `toMatrix_trans : (f.trans g).toMatrix = f.toMatrix * g.toMatrix` `toMatrix_symm : f.symm.toMatrix = f.toMatrixᵀ` `toMatrix_refl : (PEquiv.refl n).toMatrix = 1` `toMatrix_bot : ⊥.toMatrix = 0` This theory gives the matrix representation of projection linear maps, and their right inverses. For example, the matrix `(single (0 : Fin 1) (i : Fin n)).toMatrix` corresponds to the ith projection map from R^n to R. Any injective function `Fin m → Fin n` gives rise to a `PEquiv`, whose matrix is the projection map from R^m → R^n represented by the same function. The transpose of this matrix is the right inverse of this map, sending anything not in the image to zero. ## notations This file uses `ᵀ` for `Matrix.transpose`. -/ namespace PEquiv open Matrix universe u v variable {k l m n : Type*} variable {α : Type v} open Matrix /-- `toMatrix` returns a matrix containing ones and zeros. `f.toMatrix i j` is `1` if `f i = some j` and `0` otherwise -/ def toMatrix [DecidableEq n] [Zero α] [One α] (f : m ≃. n) : Matrix m n α := of fun i j => if j ∈ f i then (1 : α) else 0 #align pequiv.to_matrix PEquiv.toMatrix -- TODO: set as an equation lemma for `toMatrix`, see mathlib4#3024 @[simp] theorem toMatrix_apply [DecidableEq n] [Zero α] [One α] (f : m ≃. n) (i j) : toMatrix f i j = if j ∈ f i then (1 : α) else 0 := rfl #align pequiv.to_matrix_apply PEquiv.toMatrix_apply theorem mul_matrix_apply [Fintype m] [DecidableEq m] [Semiring α] (f : l ≃. m) (M : Matrix m n α) (i j) : (f.toMatrix * M :) i j = Option.casesOn (f i) 0 fun fi => M fi j := by dsimp [toMatrix, Matrix.mul_apply] cases' h : f i with fi · simp [h] · rw [Finset.sum_eq_single fi] <;> simp (config := { contextual := true }) [h, eq_comm] #align pequiv.mul_matrix_apply PEquiv.mul_matrix_apply theorem toMatrix_symm [DecidableEq m] [DecidableEq n] [Zero α] [One α] (f : m ≃. n) : (f.symm.toMatrix : Matrix n m α) = f.toMatrixᵀ := by ext simp only [transpose, mem_iff_mem f, toMatrix_apply] congr #align pequiv.to_matrix_symm PEquiv.toMatrix_symm @[simp] theorem toMatrix_refl [DecidableEq n] [Zero α] [One α] : ((PEquiv.refl n).toMatrix : Matrix n n α) = 1 := by ext simp [toMatrix_apply, one_apply] #align pequiv.to_matrix_refl PEquiv.toMatrix_refl theorem matrix_mul_apply [Fintype m] [Semiring α] [DecidableEq n] (M : Matrix l m α) (f : m ≃. n) (i j) : (M * f.toMatrix :) i j = Option.casesOn (f.symm j) 0 fun fj => M i fj := by dsimp [toMatrix, Matrix.mul_apply] cases' h : f.symm j with fj · simp [h, ← f.eq_some_iff] · rw [Finset.sum_eq_single fj] · simp [h, ← f.eq_some_iff] · rintro b - n simp [h, ← f.eq_some_iff, n.symm] · simp #align pequiv.matrix_mul_apply PEquiv.matrix_mul_apply theorem toPEquiv_mul_matrix [Fintype m] [DecidableEq m] [Semiring α] (f : m ≃ m) (M : Matrix m n α) : f.toPEquiv.toMatrix * M = M.submatrix f id := by ext i j rw [mul_matrix_apply, Equiv.toPEquiv_apply, submatrix_apply, id] #align pequiv.to_pequiv_mul_matrix PEquiv.toPEquiv_mul_matrix theorem mul_toPEquiv_toMatrix {m n α : Type*} [Fintype n] [DecidableEq n] [Semiring α] (f : n ≃ n) (M : Matrix m n α) : M * f.toPEquiv.toMatrix = M.submatrix id f.symm := Matrix.ext fun i j => by rw [PEquiv.matrix_mul_apply, ← Equiv.toPEquiv_symm, Equiv.toPEquiv_apply, Matrix.submatrix_apply, id] #align pequiv.mul_to_pequiv_to_matrix PEquiv.mul_toPEquiv_toMatrix theorem toMatrix_trans [Fintype m] [DecidableEq m] [DecidableEq n] [Semiring α] (f : l ≃. m) (g : m ≃. n) : ((f.trans g).toMatrix : Matrix l n α) = f.toMatrix * g.toMatrix := by ext i j rw [mul_matrix_apply] dsimp [toMatrix, PEquiv.trans] cases f i <;> simp #align pequiv.to_matrix_trans PEquiv.toMatrix_trans @[simp] theorem toMatrix_bot [DecidableEq n] [Zero α] [One α] : ((⊥ : PEquiv m n).toMatrix : Matrix m n α) = 0 := rfl #align pequiv.to_matrix_bot PEquiv.toMatrix_bot
Mathlib/Data/Matrix/PEquiv.lean
123
139
theorem toMatrix_injective [DecidableEq n] [MonoidWithZero α] [Nontrivial α] : Function.Injective (@toMatrix m n α _ _ _) := by
classical intro f g refine not_imp_not.1 ?_ simp only [Matrix.ext_iff.symm, toMatrix_apply, PEquiv.ext_iff, not_forall, exists_imp] intro i hi use i cases' hf : f i with fi · cases' hg : g i with gi -- Porting note: was `cc` · rw [hf, hg] at hi exact (hi rfl).elim · use gi simp · use fi simp [hf.symm, Ne.symm hi]
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Probability.Martingale.Convergence import Mathlib.Probability.Martingale.OptionalStopping import Mathlib.Probability.Martingale.Centering #align_import probability.martingale.borel_cantelli from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Generalized Borel-Cantelli lemma This file proves Lévy's generalized Borel-Cantelli lemma which is a generalization of the Borel-Cantelli lemmas. With this generalization, one can easily deduce the Borel-Cantelli lemmas by choosing appropriate filtrations. This file also contains the one sided martingale bound which is required to prove the generalized Borel-Cantelli. **Note**: the usual Borel-Cantelli lemmas are not in this file. See `MeasureTheory.measure_limsup_eq_zero` for the first (which does not depend on the results here), and `ProbabilityTheory.measure_limsup_eq_one` for the second (which does). ## Main results - `MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto`: the one sided martingale bound: given a submartingale `f` with uniformly bounded differences, the set for which `f` converges is almost everywhere equal to the set for which it is bounded. - `MeasureTheory.ae_mem_limsup_atTop_iff`: Lévy's generalized Borel-Cantelli: given a filtration `ℱ` and a sequence of sets `s` such that `s n ∈ ℱ n` for all `n`, `limsup atTop s` is almost everywhere equal to the set for which `∑ ℙ[s (n + 1)∣ℱ n] = ∞`. -/ open Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory BigOperators Topology namespace MeasureTheory variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0} {f : ℕ → Ω → ℝ} {ω : Ω} /-! ### One sided martingale bound -/ -- TODO: `leastGE` should be defined taking values in `WithTop ℕ` once the `stoppedProcess` -- refactor is complete /-- `leastGE f r n` is the stopping time corresponding to the first time `f ≥ r`. -/ noncomputable def leastGE (f : ℕ → Ω → ℝ) (r : ℝ) (n : ℕ) := hitting f (Set.Ici r) 0 n #align measure_theory.least_ge MeasureTheory.leastGE theorem Adapted.isStoppingTime_leastGE (r : ℝ) (n : ℕ) (hf : Adapted ℱ f) : IsStoppingTime ℱ (leastGE f r n) := hitting_isStoppingTime hf measurableSet_Ici #align measure_theory.adapted.is_stopping_time_least_ge MeasureTheory.Adapted.isStoppingTime_leastGE theorem leastGE_le {i : ℕ} {r : ℝ} (ω : Ω) : leastGE f r i ω ≤ i := hitting_le ω #align measure_theory.least_ge_le MeasureTheory.leastGE_le -- The following four lemmas shows `leastGE` behaves like a stopped process. Ideally we should -- define `leastGE` as a stopping time and take its stopped process. However, we can't do that -- with our current definition since a stopping time takes only finite indicies. An upcomming -- refactor should hopefully make it possible to have stopping times taking infinity as a value theorem leastGE_mono {n m : ℕ} (hnm : n ≤ m) (r : ℝ) (ω : Ω) : leastGE f r n ω ≤ leastGE f r m ω := hitting_mono hnm #align measure_theory.least_ge_mono MeasureTheory.leastGE_mono theorem leastGE_eq_min (π : Ω → ℕ) (r : ℝ) (ω : Ω) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : leastGE f r (π ω) ω = min (π ω) (leastGE f r n ω) := by classical refine le_antisymm (le_min (leastGE_le _) (leastGE_mono (hπn ω) r ω)) ?_ by_cases hle : π ω ≤ leastGE f r n ω · rw [min_eq_left hle, leastGE] by_cases h : ∃ j ∈ Set.Icc 0 (π ω), f j ω ∈ Set.Ici r · refine hle.trans (Eq.le ?_) rw [leastGE, ← hitting_eq_hitting_of_exists (hπn ω) h] · simp only [hitting, if_neg h, le_rfl] · rw [min_eq_right (not_le.1 hle).le, leastGE, leastGE, ← hitting_eq_hitting_of_exists (hπn ω) _] rw [not_le, leastGE, hitting_lt_iff _ (hπn ω)] at hle exact let ⟨j, hj₁, hj₂⟩ := hle ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ #align measure_theory.least_ge_eq_min MeasureTheory.leastGE_eq_min theorem stoppedValue_stoppedValue_leastGE (f : ℕ → Ω → ℝ) (π : Ω → ℕ) (r : ℝ) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : stoppedValue (fun i => stoppedValue f (leastGE f r i)) π = stoppedValue (stoppedProcess f (leastGE f r n)) π := by ext1 ω simp (config := { unfoldPartialApp := true }) only [stoppedProcess, stoppedValue] rw [leastGE_eq_min _ _ _ hπn] #align measure_theory.stopped_value_stopped_value_least_ge MeasureTheory.stoppedValue_stoppedValue_leastGE theorem Submartingale.stoppedValue_leastGE [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (r : ℝ) : Submartingale (fun i => stoppedValue f (leastGE f r i)) ℱ μ := by rw [submartingale_iff_expected_stoppedValue_mono] · intro σ π hσ hπ hσ_le_π hπ_bdd obtain ⟨n, hπ_le_n⟩ := hπ_bdd simp_rw [stoppedValue_stoppedValue_leastGE f σ r fun i => (hσ_le_π i).trans (hπ_le_n i)] simp_rw [stoppedValue_stoppedValue_leastGE f π r hπ_le_n] refine hf.expected_stoppedValue_mono ?_ ?_ ?_ fun ω => (min_le_left _ _).trans (hπ_le_n ω) · exact hσ.min (hf.adapted.isStoppingTime_leastGE _ _) · exact hπ.min (hf.adapted.isStoppingTime_leastGE _ _) · exact fun ω => min_le_min (hσ_le_π ω) le_rfl · exact fun i => stronglyMeasurable_stoppedValue_of_le hf.adapted.progMeasurable_of_discrete (hf.adapted.isStoppingTime_leastGE _ _) leastGE_le · exact fun i => integrable_stoppedValue _ (hf.adapted.isStoppingTime_leastGE _ _) hf.integrable leastGE_le #align measure_theory.submartingale.stopped_value_least_ge MeasureTheory.Submartingale.stoppedValue_leastGE variable {r : ℝ} {R : ℝ≥0} theorem norm_stoppedValue_leastGE_le (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : ∀ᵐ ω ∂μ, stoppedValue f (leastGE f r i) ω ≤ r + R := by filter_upwards [hbdd] with ω hbddω change f (leastGE f r i ω) ω ≤ r + R by_cases heq : leastGE f r i ω = 0 · rw [heq, hf0, Pi.zero_apply] exact add_nonneg hr R.coe_nonneg · obtain ⟨k, hk⟩ := Nat.exists_eq_succ_of_ne_zero heq rw [hk, add_comm, ← sub_le_iff_le_add] have := not_mem_of_lt_hitting (hk.symm ▸ k.lt_succ_self : k < leastGE f r i ω) (zero_le _) simp only [Set.mem_union, Set.mem_Iic, Set.mem_Ici, not_or, not_le] at this exact (sub_lt_sub_left this _).le.trans ((le_abs_self _).trans (hbddω _)) #align measure_theory.norm_stopped_value_least_ge_le MeasureTheory.norm_stoppedValue_leastGE_le theorem Submartingale.stoppedValue_leastGE_snorm_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : snorm (stoppedValue f (leastGE f r i)) 1 μ ≤ 2 * μ Set.univ * ENNReal.ofReal (r + R) := by refine snorm_one_le_of_le' ((hf.stoppedValue_leastGE r).integrable _) ?_ (norm_stoppedValue_leastGE_le hr hf0 hbdd i) rw [← integral_univ] refine le_trans ?_ ((hf.stoppedValue_leastGE r).setIntegral_le (zero_le _) MeasurableSet.univ) simp_rw [stoppedValue, leastGE, hitting_of_le le_rfl, hf0, integral_zero', le_rfl] #align measure_theory.submartingale.stopped_value_least_ge_snorm_le MeasureTheory.Submartingale.stoppedValue_leastGE_snorm_le theorem Submartingale.stoppedValue_leastGE_snorm_le' [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : snorm (stoppedValue f (leastGE f r i)) 1 μ ≤ ENNReal.toNNReal (2 * μ Set.univ * ENNReal.ofReal (r + R)) := by refine (hf.stoppedValue_leastGE_snorm_le hr hf0 hbdd i).trans ?_ simp [ENNReal.coe_toNNReal (measure_ne_top μ _), ENNReal.coe_toNNReal] #align measure_theory.submartingale.stopped_value_least_ge_snorm_le' MeasureTheory.Submartingale.stoppedValue_leastGE_snorm_le' /-- This lemma is superseded by `Submartingale.bddAbove_iff_exists_tendsto`. -/ theorem Submartingale.exists_tendsto_of_abs_bddAbove_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) → ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by have ht : ∀ᵐ ω ∂μ, ∀ i : ℕ, ∃ c, Tendsto (fun n => stoppedValue f (leastGE f i n) ω) atTop (𝓝 c) := by rw [ae_all_iff] exact fun i => Submartingale.exists_ae_tendsto_of_bdd (hf.stoppedValue_leastGE i) (hf.stoppedValue_leastGE_snorm_le' i.cast_nonneg hf0 hbdd) filter_upwards [ht] with ω hω hωb rw [BddAbove] at hωb obtain ⟨i, hi⟩ := exists_nat_gt hωb.some have hib : ∀ n, f n ω < i := by intro n exact lt_of_le_of_lt ((mem_upperBounds.1 hωb.some_mem) _ ⟨n, rfl⟩) hi have heq : ∀ n, stoppedValue f (leastGE f i n) ω = f n ω := by intro n rw [leastGE]; unfold hitting; rw [stoppedValue] rw [if_neg] simp only [Set.mem_Icc, Set.mem_union, Set.mem_Ici] push_neg exact fun j _ => hib j simp only [← heq, hω i] #align measure_theory.submartingale.exists_tendsto_of_abs_bdd_above_aux MeasureTheory.Submartingale.exists_tendsto_of_abs_bddAbove_aux theorem Submartingale.bddAbove_iff_exists_tendsto_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by filter_upwards [hf.exists_tendsto_of_abs_bddAbove_aux hf0 hbdd] with ω hω using ⟨hω, fun ⟨c, hc⟩ => hc.bddAbove_range⟩ #align measure_theory.submartingale.bdd_above_iff_exists_tendsto_aux MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto_aux /-- One sided martingale bound: If `f` is a submartingale which has uniformly bounded differences, then for almost every `ω`, `f n ω` is bounded above (in `n`) if and only if it converges. -/ theorem Submartingale.bddAbove_iff_exists_tendsto [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by set g : ℕ → Ω → ℝ := fun n ω => f n ω - f 0 ω have hg : Submartingale g ℱ μ := hf.sub_martingale (martingale_const_fun _ _ (hf.adapted 0) (hf.integrable 0)) have hg0 : g 0 = 0 := by ext ω simp only [g, sub_self, Pi.zero_apply] have hgbdd : ∀ᵐ ω ∂μ, ∀ i : ℕ, |g (i + 1) ω - g i ω| ≤ ↑R := by simpa only [g, sub_sub_sub_cancel_right] filter_upwards [hg.bddAbove_iff_exists_tendsto_aux hg0 hgbdd] with ω hω convert hω using 1 · refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨b, hb⟩ := h <;> refine ⟨b + |f 0 ω|, fun y hy => ?_⟩ <;> obtain ⟨n, rfl⟩ := hy · simp_rw [g, sub_eq_add_neg] exact add_le_add (hb ⟨n, rfl⟩) (neg_le_abs _) · exact sub_le_iff_le_add.1 (le_trans (sub_le_sub_left (le_abs_self _) _) (hb ⟨n, rfl⟩)) · refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨c, hc⟩ := h · exact ⟨c - f 0 ω, hc.sub_const _⟩ · refine ⟨c + f 0 ω, ?_⟩ have := hc.add_const (f 0 ω) simpa only [g, sub_add_cancel] #align measure_theory.submartingale.bdd_above_iff_exists_tendsto MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto /-! ### Lévy's generalization of the Borel-Cantelli lemma Lévy's generalization of the Borel-Cantelli lemma states that: given a natural number indexed filtration $(\mathcal{F}_n)$, and a sequence of sets $(s_n)$ such that for all $n$, $s_n \in \mathcal{F}_n$, $limsup_n s_n$ is almost everywhere equal to the set for which $\sum_n \mathbb{P}[s_n \mid \mathcal{F}_n] = \infty$. The proof strategy follows by constructing a martingale satisfying the one sided martingale bound. In particular, we define $$ f_n := \sum_{k < n} \mathbf{1}_{s_{n + 1}} - \mathbb{P}[s_{n + 1} \mid \mathcal{F}_n]. $$ Then, as a martingale is both a sub and a super-martingale, the set for which it is unbounded from above must agree with the set for which it is unbounded from below almost everywhere. Thus, it can only converge to $\pm \infty$ with probability 0. Thus, by considering $$ \limsup_n s_n = \{\sum_n \mathbf{1}_{s_n} = \infty\} $$ almost everywhere, the result follows. -/ theorem Martingale.bddAbove_range_iff_bddBelow_range [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ BddBelow (Set.range fun n => f n ω) := by have hbdd' : ∀ᵐ ω ∂μ, ∀ i, |(-f) (i + 1) ω - (-f) i ω| ≤ R := by filter_upwards [hbdd] with ω hω i erw [← abs_neg, neg_sub, sub_neg_eq_add, neg_add_eq_sub] exact hω i have hup := hf.submartingale.bddAbove_iff_exists_tendsto hbdd have hdown := hf.neg.submartingale.bddAbove_iff_exists_tendsto hbdd' filter_upwards [hup, hdown] with ω hω₁ hω₂ have : (∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c)) ↔ ∃ c, Tendsto (fun n => (-f) n ω) atTop (𝓝 c) := by constructor <;> rintro ⟨c, hc⟩ · exact ⟨-c, hc.neg⟩ · refine ⟨-c, ?_⟩ convert hc.neg simp only [neg_neg, Pi.neg_apply] rw [hω₁, this, ← hω₂] constructor <;> rintro ⟨c, hc⟩ <;> refine ⟨-c, fun ω hω => ?_⟩ · rw [mem_upperBounds] at hc refine neg_le.2 (hc _ ?_) simpa only [Pi.neg_apply, Set.mem_range, neg_inj] · rw [mem_lowerBounds] at hc simp_rw [Set.mem_range, Pi.neg_apply, neg_eq_iff_eq_neg] at hω refine le_neg.1 (hc _ ?_) simpa only [Set.mem_range] #align measure_theory.martingale.bdd_above_range_iff_bdd_below_range MeasureTheory.Martingale.bddAbove_range_iff_bddBelow_range theorem Martingale.ae_not_tendsto_atTop_atTop [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atTop := by filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using unbounded_of_tendsto_atTop htop (hω.2 <| bddBelow_range_of_tendsto_atTop_atTop htop) #align measure_theory.martingale.ae_not_tendsto_at_top_at_top MeasureTheory.Martingale.ae_not_tendsto_atTop_atTop theorem Martingale.ae_not_tendsto_atTop_atBot [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atBot := by filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using unbounded_of_tendsto_atBot htop (hω.1 <| bddAbove_range_of_tendsto_atTop_atBot htop) #align measure_theory.martingale.ae_not_tendsto_at_top_at_bot MeasureTheory.Martingale.ae_not_tendsto_atTop_atBot namespace BorelCantelli /-- Auxiliary definition required to prove Lévy's generalization of the Borel-Cantelli lemmas for which we will take the martingale part. -/ noncomputable def process (s : ℕ → Set Ω) (n : ℕ) : Ω → ℝ := ∑ k ∈ Finset.range n, (s (k + 1)).indicator 1 #align measure_theory.borel_cantelli.process MeasureTheory.BorelCantelli.process variable {s : ℕ → Set Ω}
Mathlib/Probability/Martingale/BorelCantelli.lean
287
287
theorem process_zero : process s 0 = 0 := by
rw [process, Finset.range_zero, Finset.sum_empty]
/- 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.Computability.Partrec import Mathlib.Data.Option.Basic #align_import computability.partrec_code from "leanprover-community/mathlib"@"6155d4351090a6fad236e3d2e4e0e4e7342668e8" /-! # Gödel Numbering for Partial Recursive Functions. This file defines `Nat.Partrec.Code`, an inductive datatype describing code for partial recursive functions on ℕ. It defines an encoding for these codes, and proves that the constructors are primitive recursive with respect to the encoding. It also defines the evaluation of these codes as partial functions using `PFun`, and proves that a function is partially recursive (as defined by `Nat.Partrec`) if and only if it is the evaluation of some code. ## Main Definitions * `Nat.Partrec.Code`: Inductive datatype for partial recursive codes. * `Nat.Partrec.Code.encodeCode`: A (computable) encoding of codes as natural numbers. * `Nat.Partrec.Code.ofNatCode`: The inverse of this encoding. * `Nat.Partrec.Code.eval`: The interpretation of a `Nat.Partrec.Code` as a partial function. ## Main Results * `Nat.Partrec.Code.rec_prim`: Recursion on `Nat.Partrec.Code` is primitive recursive. * `Nat.Partrec.Code.rec_computable`: Recursion on `Nat.Partrec.Code` is computable. * `Nat.Partrec.Code.smn`: The $S_n^m$ theorem. * `Nat.Partrec.Code.exists_code`: Partial recursiveness is equivalent to being the eval of a code. * `Nat.Partrec.Code.evaln_prim`: `evaln` is primitive recursive. * `Nat.Partrec.Code.fixed_point`: Roger's fixed point theorem. ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open Encodable Denumerable namespace Nat.Partrec theorem rfind' {f} (hf : Nat.Partrec f) : Nat.Partrec (Nat.unpaired fun a m => (Nat.rfind fun n => (fun m => m = 0) <$> f (Nat.pair a (n + m))).map (· + m)) := Partrec₂.unpaired'.2 <| by refine Partrec.map ((@Partrec₂.unpaired' fun a b : ℕ => Nat.rfind fun n => (fun m => m = 0) <$> f (Nat.pair a (n + b))).1 ?_) (Primrec.nat_add.comp Primrec.snd <| Primrec.snd.comp Primrec.fst).to_comp.to₂ have : Nat.Partrec (fun a => Nat.rfind (fun n => (fun m => decide (m = 0)) <$> Nat.unpaired (fun a b => f (Nat.pair (Nat.unpair a).1 (b + (Nat.unpair a).2))) (Nat.pair a n))) := rfind (Partrec₂.unpaired'.2 ((Partrec.nat_iff.2 hf).comp (Primrec₂.pair.comp (Primrec.fst.comp <| Primrec.unpair.comp Primrec.fst) (Primrec.nat_add.comp Primrec.snd (Primrec.snd.comp <| Primrec.unpair.comp Primrec.fst))).to_comp)) simp at this; exact this #align nat.partrec.rfind' Nat.Partrec.rfind' /-- Code for partial recursive functions from ℕ to ℕ. See `Nat.Partrec.Code.eval` for the interpretation of these constructors. -/ inductive Code : Type | zero : Code | succ : Code | left : Code | right : Code | pair : Code → Code → Code | comp : Code → Code → Code | prec : Code → Code → Code | rfind' : Code → Code #align nat.partrec.code Nat.Partrec.Code -- Porting note: `Nat.Partrec.Code.recOn` is noncomputable in Lean4, so we make it computable. compile_inductive% Code end Nat.Partrec namespace Nat.Partrec.Code instance instInhabited : Inhabited Code := ⟨zero⟩ #align nat.partrec.code.inhabited Nat.Partrec.Code.instInhabited /-- Returns a code for the constant function outputting a particular natural. -/ protected def const : ℕ → Code | 0 => zero | n + 1 => comp succ (Code.const n) #align nat.partrec.code.const Nat.Partrec.Code.const theorem const_inj : ∀ {n₁ n₂}, Nat.Partrec.Code.const n₁ = Nat.Partrec.Code.const n₂ → n₁ = n₂ | 0, 0, _ => by simp | n₁ + 1, n₂ + 1, h => by dsimp [Nat.Partrec.Code.const] at h injection h with h₁ h₂ simp only [const_inj h₂] #align nat.partrec.code.const_inj Nat.Partrec.Code.const_inj /-- A code for the identity function. -/ protected def id : Code := pair left right #align nat.partrec.code.id Nat.Partrec.Code.id /-- Given a code `c` taking a pair as input, returns a code using `n` as the first argument to `c`. -/ def curry (c : Code) (n : ℕ) : Code := comp c (pair (Code.const n) Code.id) #align nat.partrec.code.curry Nat.Partrec.Code.curry -- Porting note: `bit0` and `bit1` are deprecated. /-- An encoding of a `Nat.Partrec.Code` as a ℕ. -/ def encodeCode : Code → ℕ | zero => 0 | succ => 1 | left => 2 | right => 3 | pair cf cg => 2 * (2 * Nat.pair (encodeCode cf) (encodeCode cg)) + 4 | comp cf cg => 2 * (2 * Nat.pair (encodeCode cf) (encodeCode cg) + 1) + 4 | prec cf cg => (2 * (2 * Nat.pair (encodeCode cf) (encodeCode cg)) + 1) + 4 | rfind' cf => (2 * (2 * encodeCode cf + 1) + 1) + 4 #align nat.partrec.code.encode_code Nat.Partrec.Code.encodeCode /-- A decoder for `Nat.Partrec.Code.encodeCode`, taking any ℕ to the `Nat.Partrec.Code` it represents. -/ def ofNatCode : ℕ → Code | 0 => zero | 1 => succ | 2 => left | 3 => right | n + 4 => let m := n.div2.div2 have hm : m < n + 4 := by simp only [m, div2_val] exact lt_of_le_of_lt (le_trans (Nat.div_le_self _ _) (Nat.div_le_self _ _)) (Nat.succ_le_succ (Nat.le_add_right _ _)) have _m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm have _m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm match n.bodd, n.div2.bodd with | false, false => pair (ofNatCode m.unpair.1) (ofNatCode m.unpair.2) | false, true => comp (ofNatCode m.unpair.1) (ofNatCode m.unpair.2) | true , false => prec (ofNatCode m.unpair.1) (ofNatCode m.unpair.2) | true , true => rfind' (ofNatCode m) #align nat.partrec.code.of_nat_code Nat.Partrec.Code.ofNatCode /-- Proof that `Nat.Partrec.Code.ofNatCode` is the inverse of `Nat.Partrec.Code.encodeCode`-/ private theorem encode_ofNatCode : ∀ n, encodeCode (ofNatCode n) = n | 0 => by simp [ofNatCode, encodeCode] | 1 => by simp [ofNatCode, encodeCode] | 2 => by simp [ofNatCode, encodeCode] | 3 => by simp [ofNatCode, encodeCode] | n + 4 => by let m := n.div2.div2 have hm : m < n + 4 := by simp only [m, div2_val] exact lt_of_le_of_lt (le_trans (Nat.div_le_self _ _) (Nat.div_le_self _ _)) (Nat.succ_le_succ (Nat.le_add_right _ _)) have _m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm have _m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm have IH := encode_ofNatCode m have IH1 := encode_ofNatCode m.unpair.1 have IH2 := encode_ofNatCode m.unpair.2 conv_rhs => rw [← Nat.bit_decomp n, ← Nat.bit_decomp n.div2] simp only [ofNatCode.eq_5] cases n.bodd <;> cases n.div2.bodd <;> simp [encodeCode, ofNatCode, IH, IH1, IH2, Nat.bit_val] instance instDenumerable : Denumerable Code := mk' ⟨encodeCode, ofNatCode, fun c => by induction c <;> try {rfl} <;> simp [encodeCode, ofNatCode, Nat.div2_val, *], encode_ofNatCode⟩ #align nat.partrec.code.denumerable Nat.Partrec.Code.instDenumerable theorem encodeCode_eq : encode = encodeCode := rfl #align nat.partrec.code.encode_code_eq Nat.Partrec.Code.encodeCode_eq theorem ofNatCode_eq : ofNat Code = ofNatCode := rfl #align nat.partrec.code.of_nat_code_eq Nat.Partrec.Code.ofNatCode_eq theorem encode_lt_pair (cf cg) : encode cf < encode (pair cf cg) ∧ encode cg < encode (pair cf cg) := by simp only [encodeCode_eq, encodeCode] have := Nat.mul_le_mul_right (Nat.pair cf.encodeCode cg.encodeCode) (by decide : 1 ≤ 2 * 2) rw [one_mul, mul_assoc] at this have := lt_of_le_of_lt this (lt_add_of_pos_right _ (by decide : 0 < 4)) exact ⟨lt_of_le_of_lt (Nat.left_le_pair _ _) this, lt_of_le_of_lt (Nat.right_le_pair _ _) this⟩ #align nat.partrec.code.encode_lt_pair Nat.Partrec.Code.encode_lt_pair theorem encode_lt_comp (cf cg) : encode cf < encode (comp cf cg) ∧ encode cg < encode (comp cf cg) := by have : encode (pair cf cg) < encode (comp cf cg) := by simp [encodeCode_eq, encodeCode] exact (encode_lt_pair cf cg).imp (fun h => lt_trans h this) fun h => lt_trans h this #align nat.partrec.code.encode_lt_comp Nat.Partrec.Code.encode_lt_comp theorem encode_lt_prec (cf cg) : encode cf < encode (prec cf cg) ∧ encode cg < encode (prec cf cg) := by have : encode (pair cf cg) < encode (prec cf cg) := by simp [encodeCode_eq, encodeCode] exact (encode_lt_pair cf cg).imp (fun h => lt_trans h this) fun h => lt_trans h this #align nat.partrec.code.encode_lt_prec Nat.Partrec.Code.encode_lt_prec theorem encode_lt_rfind' (cf) : encode cf < encode (rfind' cf) := by simp only [encodeCode_eq, encodeCode] have := Nat.mul_le_mul_right cf.encodeCode (by decide : 1 ≤ 2 * 2) rw [one_mul, mul_assoc] at this refine lt_of_le_of_lt (le_trans this ?_) (lt_add_of_pos_right _ (by decide : 0 < 4)) exact le_of_lt (Nat.lt_succ_of_le <| Nat.mul_le_mul_left _ <| le_of_lt <| Nat.lt_succ_of_le <| Nat.mul_le_mul_left _ <| le_rfl) #align nat.partrec.code.encode_lt_rfind' Nat.Partrec.Code.encode_lt_rfind' end Nat.Partrec.Code -- Porting note: Opening `Primrec` inside `namespace Nat.Partrec.Code` causes it to resolve -- to `Nat.Partrec`. Needs `open _root_.Partrec` support section open Primrec namespace Nat.Partrec.Code theorem pair_prim : Primrec₂ pair := Primrec₂.ofNat_iff.2 <| Primrec₂.encode_iff.1 <| nat_add.comp (nat_double.comp <| nat_double.comp <| Primrec₂.natPair.comp (encode_iff.2 <| (Primrec.ofNat Code).comp fst) (encode_iff.2 <| (Primrec.ofNat Code).comp snd)) (Primrec₂.const 4) #align nat.partrec.code.pair_prim Nat.Partrec.Code.pair_prim theorem comp_prim : Primrec₂ comp := Primrec₂.ofNat_iff.2 <| Primrec₂.encode_iff.1 <| nat_add.comp (nat_double.comp <| nat_double_succ.comp <| Primrec₂.natPair.comp (encode_iff.2 <| (Primrec.ofNat Code).comp fst) (encode_iff.2 <| (Primrec.ofNat Code).comp snd)) (Primrec₂.const 4) #align nat.partrec.code.comp_prim Nat.Partrec.Code.comp_prim theorem prec_prim : Primrec₂ prec := Primrec₂.ofNat_iff.2 <| Primrec₂.encode_iff.1 <| nat_add.comp (nat_double_succ.comp <| nat_double.comp <| Primrec₂.natPair.comp (encode_iff.2 <| (Primrec.ofNat Code).comp fst) (encode_iff.2 <| (Primrec.ofNat Code).comp snd)) (Primrec₂.const 4) #align nat.partrec.code.prec_prim Nat.Partrec.Code.prec_prim theorem rfind_prim : Primrec rfind' := ofNat_iff.2 <| encode_iff.1 <| nat_add.comp (nat_double_succ.comp <| nat_double_succ.comp <| encode_iff.2 <| Primrec.ofNat Code) (const 4) #align nat.partrec.code.rfind_prim Nat.Partrec.Code.rfind_prim theorem rec_prim' {α σ} [Primcodable α] [Primcodable σ] {c : α → Code} (hc : Primrec c) {z : α → σ} (hz : Primrec z) {s : α → σ} (hs : Primrec s) {l : α → σ} (hl : Primrec l) {r : α → σ} (hr : Primrec r) {pr : α → Code × Code × σ × σ → σ} (hpr : Primrec₂ pr) {co : α → Code × Code × σ × σ → σ} (hco : Primrec₂ co) {pc : α → Code × Code × σ × σ → σ} (hpc : Primrec₂ pc) {rf : α → Code × σ → σ} (hrf : Primrec₂ rf) : let PR (a) cf cg hf hg := pr a (cf, cg, hf, hg) let CO (a) cf cg hf hg := co a (cf, cg, hf, hg) let PC (a) cf cg hf hg := pc a (cf, cg, hf, hg) let RF (a) cf hf := rf a (cf, hf) let F (a : α) (c : Code) : σ := Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a) Primrec (fun a => F a (c a) : α → σ) := by intros _ _ _ _ F let G₁ : (α × List σ) × ℕ × ℕ → Option σ := fun p => letI a := p.1.1; letI IH := p.1.2; letI n := p.2.1; letI m := p.2.2 (IH.get? m).bind fun s => (IH.get? m.unpair.1).bind fun s₁ => (IH.get? m.unpair.2).map fun s₂ => cond n.bodd (cond n.div2.bodd (rf a (ofNat Code m, s)) (pc a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂))) (cond n.div2.bodd (co a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂)) (pr a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂))) have : Primrec G₁ := option_bind (list_get?.comp (snd.comp fst) (snd.comp snd)) <| .mk <| option_bind ((list_get?.comp (snd.comp fst) (fst.comp <| Primrec.unpair.comp (snd.comp snd))).comp fst) <| .mk <| option_map ((list_get?.comp (snd.comp fst) (snd.comp <| Primrec.unpair.comp (snd.comp snd))).comp <| fst.comp fst) <| .mk <| have a := fst.comp (fst.comp <| fst.comp <| fst.comp fst) have n := fst.comp (snd.comp <| fst.comp <| fst.comp fst) have m := snd.comp (snd.comp <| fst.comp <| fst.comp fst) have m₁ := fst.comp (Primrec.unpair.comp m) have m₂ := snd.comp (Primrec.unpair.comp m) have s := snd.comp (fst.comp fst) have s₁ := snd.comp fst have s₂ := snd (nat_bodd.comp n).cond ((nat_bodd.comp <| nat_div2.comp n).cond (hrf.comp a (((Primrec.ofNat Code).comp m).pair s)) (hpc.comp a (((Primrec.ofNat Code).comp m₁).pair <| ((Primrec.ofNat Code).comp m₂).pair <| s₁.pair s₂))) (Primrec.cond (nat_bodd.comp <| nat_div2.comp n) (hco.comp a (((Primrec.ofNat Code).comp m₁).pair <| ((Primrec.ofNat Code).comp m₂).pair <| s₁.pair s₂)) (hpr.comp a (((Primrec.ofNat Code).comp m₁).pair <| ((Primrec.ofNat Code).comp m₂).pair <| s₁.pair s₂))) let G : α → List σ → Option σ := fun a IH => IH.length.casesOn (some (z a)) fun n => n.casesOn (some (s a)) fun n => n.casesOn (some (l a)) fun n => n.casesOn (some (r a)) fun n => G₁ ((a, IH), n, n.div2.div2) have : Primrec₂ G := .mk <| nat_casesOn (list_length.comp snd) (option_some_iff.2 (hz.comp fst)) <| .mk <| nat_casesOn snd (option_some_iff.2 (hs.comp (fst.comp fst))) <| .mk <| nat_casesOn snd (option_some_iff.2 (hl.comp (fst.comp <| fst.comp fst))) <| .mk <| nat_casesOn snd (option_some_iff.2 (hr.comp (fst.comp <| fst.comp <| fst.comp fst))) <| .mk <| this.comp <| ((fst.pair snd).comp <| fst.comp <| fst.comp <| fst.comp <| fst).pair <| snd.pair <| nat_div2.comp <| nat_div2.comp snd refine (nat_strong_rec (fun a n => F a (ofNat Code n)) this.to₂ fun a n => ?_) |>.comp .id (encode_iff.2 hc) |>.of_eq fun a => by simp simp iterate 4 cases' n with n; · simp [ofNatCode_eq, ofNatCode]; rfl simp only [G]; rw [List.length_map, List.length_range] let m := n.div2.div2 show G₁ ((a, (List.range (n + 4)).map fun n => F a (ofNat Code n)), n, m) = some (F a (ofNat Code (n + 4))) have hm : m < n + 4 := by simp only [m, div2_val] exact lt_of_le_of_lt (le_trans (Nat.div_le_self ..) (Nat.div_le_self ..)) (Nat.succ_le_succ (Nat.le_add_right ..)) have m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm have m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm simp [G₁]; simp [m, List.get?_map, List.get?_range, hm, m1, m2] rw [show ofNat Code (n + 4) = ofNatCode (n + 4) from rfl] simp [ofNatCode] cases n.bodd <;> cases n.div2.bodd <;> rfl #align nat.partrec.code.rec_prim' Nat.Partrec.Code.rec_prim' /-- Recursion on `Nat.Partrec.Code` is primitive recursive. -/ theorem rec_prim {α σ} [Primcodable α] [Primcodable σ] {c : α → Code} (hc : Primrec c) {z : α → σ} (hz : Primrec z) {s : α → σ} (hs : Primrec s) {l : α → σ} (hl : Primrec l) {r : α → σ} (hr : Primrec r) {pr : α → Code → Code → σ → σ → σ} (hpr : Primrec fun a : α × Code × Code × σ × σ => pr a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2) {co : α → Code → Code → σ → σ → σ} (hco : Primrec fun a : α × Code × Code × σ × σ => co a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2) {pc : α → Code → Code → σ → σ → σ} (hpc : Primrec fun a : α × Code × Code × σ × σ => pc a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2) {rf : α → Code → σ → σ} (hrf : Primrec fun a : α × Code × σ => rf a.1 a.2.1 a.2.2) : let F (a : α) (c : Code) : σ := Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (pr a) (co a) (pc a) (rf a) Primrec fun a => F a (c a) := rec_prim' hc hz hs hl hr (pr := fun a b => pr a b.1 b.2.1 b.2.2.1 b.2.2.2) (.mk hpr) (co := fun a b => co a b.1 b.2.1 b.2.2.1 b.2.2.2) (.mk hco) (pc := fun a b => pc a b.1 b.2.1 b.2.2.1 b.2.2.2) (.mk hpc) (rf := fun a b => rf a b.1 b.2) (.mk hrf) #align nat.partrec.code.rec_prim Nat.Partrec.Code.rec_prim end Nat.Partrec.Code end namespace Nat.Partrec.Code section open Computable /-- Recursion on `Nat.Partrec.Code` is computable. -/ theorem rec_computable {α σ} [Primcodable α] [Primcodable σ] {c : α → Code} (hc : Computable c) {z : α → σ} (hz : Computable z) {s : α → σ} (hs : Computable s) {l : α → σ} (hl : Computable l) {r : α → σ} (hr : Computable r) {pr : α → Code × Code × σ × σ → σ} (hpr : Computable₂ pr) {co : α → Code × Code × σ × σ → σ} (hco : Computable₂ co) {pc : α → Code × Code × σ × σ → σ} (hpc : Computable₂ pc) {rf : α → Code × σ → σ} (hrf : Computable₂ rf) : let PR (a) cf cg hf hg := pr a (cf, cg, hf, hg) let CO (a) cf cg hf hg := co a (cf, cg, hf, hg) let PC (a) cf cg hf hg := pc a (cf, cg, hf, hg) let RF (a) cf hf := rf a (cf, hf) let F (a : α) (c : Code) : σ := Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a) Computable fun a => F a (c a) := by -- TODO(Mario): less copy-paste from previous proof intros _ _ _ _ F let G₁ : (α × List σ) × ℕ × ℕ → Option σ := fun p => letI a := p.1.1; letI IH := p.1.2; letI n := p.2.1; letI m := p.2.2 (IH.get? m).bind fun s => (IH.get? m.unpair.1).bind fun s₁ => (IH.get? m.unpair.2).map fun s₂ => cond n.bodd (cond n.div2.bodd (rf a (ofNat Code m, s)) (pc a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂))) (cond n.div2.bodd (co a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂)) (pr a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂))) have : Computable G₁ := by refine option_bind (list_get?.comp (snd.comp fst) (snd.comp snd)) <| .mk ?_ refine option_bind ((list_get?.comp (snd.comp fst) (fst.comp <| Computable.unpair.comp (snd.comp snd))).comp fst) <| .mk ?_ refine option_map ((list_get?.comp (snd.comp fst) (snd.comp <| Computable.unpair.comp (snd.comp snd))).comp <| fst.comp fst) <| .mk ?_ exact have a := fst.comp (fst.comp <| fst.comp <| fst.comp fst) have n := fst.comp (snd.comp <| fst.comp <| fst.comp fst) have m := snd.comp (snd.comp <| fst.comp <| fst.comp fst) have m₁ := fst.comp (Computable.unpair.comp m) have m₂ := snd.comp (Computable.unpair.comp m) have s := snd.comp (fst.comp fst) have s₁ := snd.comp fst have s₂ := snd (nat_bodd.comp n).cond ((nat_bodd.comp <| nat_div2.comp n).cond (hrf.comp a (((Computable.ofNat Code).comp m).pair s)) (hpc.comp a (((Computable.ofNat Code).comp m₁).pair <| ((Computable.ofNat Code).comp m₂).pair <| s₁.pair s₂))) (Computable.cond (nat_bodd.comp <| nat_div2.comp n) (hco.comp a (((Computable.ofNat Code).comp m₁).pair <| ((Computable.ofNat Code).comp m₂).pair <| s₁.pair s₂)) (hpr.comp a (((Computable.ofNat Code).comp m₁).pair <| ((Computable.ofNat Code).comp m₂).pair <| s₁.pair s₂))) let G : α → List σ → Option σ := fun a IH => IH.length.casesOn (some (z a)) fun n => n.casesOn (some (s a)) fun n => n.casesOn (some (l a)) fun n => n.casesOn (some (r a)) fun n => G₁ ((a, IH), n, n.div2.div2) have : Computable₂ G := .mk <| nat_casesOn (list_length.comp snd) (option_some_iff.2 (hz.comp fst)) <| .mk <| nat_casesOn snd (option_some_iff.2 (hs.comp (fst.comp fst))) <| .mk <| nat_casesOn snd (option_some_iff.2 (hl.comp (fst.comp <| fst.comp fst))) <| .mk <| nat_casesOn snd (option_some_iff.2 (hr.comp (fst.comp <| fst.comp <| fst.comp fst))) <| .mk <| this.comp <| ((fst.pair snd).comp <| fst.comp <| fst.comp <| fst.comp <| fst).pair <| snd.pair <| nat_div2.comp <| nat_div2.comp snd refine (nat_strong_rec (fun a n => F a (ofNat Code n)) this.to₂ fun a n => ?_) |>.comp .id (encode_iff.2 hc) |>.of_eq fun a => by simp simp iterate 4 cases' n with n; · simp [ofNatCode_eq, ofNatCode]; rfl simp only [G]; rw [List.length_map, List.length_range] let m := n.div2.div2 show G₁ ((a, (List.range (n + 4)).map fun n => F a (ofNat Code n)), n, m) = some (F a (ofNat Code (n + 4))) have hm : m < n + 4 := by simp only [m, div2_val] exact lt_of_le_of_lt (le_trans (Nat.div_le_self ..) (Nat.div_le_self ..)) (Nat.succ_le_succ (Nat.le_add_right ..)) have m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm have m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm simp [G₁]; simp [m, List.get?_map, List.get?_range, hm, m1, m2] rw [show ofNat Code (n + 4) = ofNatCode (n + 4) from rfl] simp [ofNatCode] cases n.bodd <;> cases n.div2.bodd <;> rfl #align nat.partrec.code.rec_computable Nat.Partrec.Code.rec_computable end /-- The interpretation of a `Nat.Partrec.Code` as a partial function. * `Nat.Partrec.Code.zero`: The constant zero function. * `Nat.Partrec.Code.succ`: The successor function. * `Nat.Partrec.Code.left`: Left unpairing of a pair of ℕ (encoded by `Nat.pair`) * `Nat.Partrec.Code.right`: Right unpairing of a pair of ℕ (encoded by `Nat.pair`) * `Nat.Partrec.Code.pair`: Pairs the outputs of argument codes using `Nat.pair`. * `Nat.Partrec.Code.comp`: Composition of two argument codes. * `Nat.Partrec.Code.prec`: Primitive recursion. Given an argument of the form `Nat.pair a n`: * If `n = 0`, returns `eval cf a`. * If `n = succ k`, returns `eval cg (pair a (pair k (eval (prec cf cg) (pair a k))))` * `Nat.Partrec.Code.rfind'`: Minimization. For `f` an argument of the form `Nat.pair a m`, `rfind' f m` returns the least `a` such that `f a m = 0`, if one exists and `f b m` terminates for `b < a` -/ def eval : Code → ℕ →. ℕ | zero => pure 0 | succ => Nat.succ | left => ↑fun n : ℕ => n.unpair.1 | right => ↑fun n : ℕ => n.unpair.2 | pair cf cg => fun n => Nat.pair <$> eval cf n <*> eval cg n | comp cf cg => fun n => eval cg n >>= eval cf | prec cf cg => Nat.unpaired fun a n => n.rec (eval cf a) fun y IH => do let i ← IH eval cg (Nat.pair a (Nat.pair y i)) | rfind' cf => Nat.unpaired fun a m => (Nat.rfind fun n => (fun m => m = 0) <$> eval cf (Nat.pair a (n + m))).map (· + m) #align nat.partrec.code.eval Nat.Partrec.Code.eval /-- Helper lemma for the evaluation of `prec` in the base case. -/ @[simp] theorem eval_prec_zero (cf cg : Code) (a : ℕ) : eval (prec cf cg) (Nat.pair a 0) = eval cf a := by rw [eval, Nat.unpaired, Nat.unpair_pair] simp (config := { Lean.Meta.Simp.neutralConfig with proj := true }) only [] rw [Nat.rec_zero] #align nat.partrec.code.eval_prec_zero Nat.Partrec.Code.eval_prec_zero /-- Helper lemma for the evaluation of `prec` in the recursive case. -/ theorem eval_prec_succ (cf cg : Code) (a k : ℕ) : eval (prec cf cg) (Nat.pair a (Nat.succ k)) = do {let ih ← eval (prec cf cg) (Nat.pair a k); eval cg (Nat.pair a (Nat.pair k ih))} := by rw [eval, Nat.unpaired, Part.bind_eq_bind, Nat.unpair_pair] simp #align nat.partrec.code.eval_prec_succ Nat.Partrec.Code.eval_prec_succ instance : Membership (ℕ →. ℕ) Code := ⟨fun f c => eval c = f⟩ @[simp] theorem eval_const : ∀ n m, eval (Code.const n) m = Part.some n | 0, m => rfl | n + 1, m => by simp! [eval_const n m] #align nat.partrec.code.eval_const Nat.Partrec.Code.eval_const @[simp] theorem eval_id (n) : eval Code.id n = Part.some n := by simp! [Seq.seq] #align nat.partrec.code.eval_id Nat.Partrec.Code.eval_id @[simp] theorem eval_curry (c n x) : eval (curry c n) x = eval c (Nat.pair n x) := by simp! [Seq.seq] #align nat.partrec.code.eval_curry Nat.Partrec.Code.eval_curry theorem const_prim : Primrec Code.const := (_root_.Primrec.id.nat_iterate (_root_.Primrec.const zero) (comp_prim.comp (_root_.Primrec.const succ) Primrec.snd).to₂).of_eq fun n => by simp; induction n <;> simp [*, Code.const, Function.iterate_succ', -Function.iterate_succ] #align nat.partrec.code.const_prim Nat.Partrec.Code.const_prim theorem curry_prim : Primrec₂ curry := comp_prim.comp Primrec.fst <| pair_prim.comp (const_prim.comp Primrec.snd) (_root_.Primrec.const Code.id) #align nat.partrec.code.curry_prim Nat.Partrec.Code.curry_prim theorem curry_inj {c₁ c₂ n₁ n₂} (h : curry c₁ n₁ = curry c₂ n₂) : c₁ = c₂ ∧ n₁ = n₂ := ⟨by injection h, by injection h with h₁ h₂ injection h₂ with h₃ h₄ exact const_inj h₃⟩ #align nat.partrec.code.curry_inj Nat.Partrec.Code.curry_inj /-- The $S_n^m$ theorem: There is a computable function, namely `Nat.Partrec.Code.curry`, that takes a program and a ℕ `n`, and returns a new program using `n` as the first argument. -/ theorem smn : ∃ f : Code → ℕ → Code, Computable₂ f ∧ ∀ c n x, eval (f c n) x = eval c (Nat.pair n x) := ⟨curry, Primrec₂.to_comp curry_prim, eval_curry⟩ #align nat.partrec.code.smn Nat.Partrec.Code.smn /-- A function is partial recursive if and only if there is a code implementing it. Therefore, `eval` is a **universal partial recursive function**. -/ theorem exists_code {f : ℕ →. ℕ} : Nat.Partrec f ↔ ∃ c : Code, eval c = f := by refine ⟨fun h => ?_, ?_⟩ · induction h with | zero => exact ⟨zero, rfl⟩ | succ => exact ⟨succ, rfl⟩ | left => exact ⟨left, rfl⟩ | right => exact ⟨right, rfl⟩ | pair pf pg hf hg => rcases hf with ⟨cf, rfl⟩; rcases hg with ⟨cg, rfl⟩ exact ⟨pair cf cg, rfl⟩ | comp pf pg hf hg => rcases hf with ⟨cf, rfl⟩; rcases hg with ⟨cg, rfl⟩ exact ⟨comp cf cg, rfl⟩ | prec pf pg hf hg => rcases hf with ⟨cf, rfl⟩; rcases hg with ⟨cg, rfl⟩ exact ⟨prec cf cg, rfl⟩ | rfind pf hf => rcases hf with ⟨cf, rfl⟩ refine ⟨comp (rfind' cf) (pair Code.id zero), ?_⟩ simp [eval, Seq.seq, pure, PFun.pure, Part.map_id'] · rintro ⟨c, rfl⟩ induction c with | zero => exact Nat.Partrec.zero | succ => exact Nat.Partrec.succ | left => exact Nat.Partrec.left | right => exact Nat.Partrec.right | pair cf cg pf pg => exact pf.pair pg | comp cf cg pf pg => exact pf.comp pg | prec cf cg pf pg => exact pf.prec pg | rfind' cf pf => exact pf.rfind' #align nat.partrec.code.exists_code Nat.Partrec.Code.exists_code -- Porting note: `>>`s in `evaln` are now `>>=` because `>>`s are not elaborated well in Lean4. /-- A modified evaluation for the code which returns an `Option ℕ` instead of a `Part ℕ`. To avoid undecidability, `evaln` takes a parameter `k` and fails if it encounters a number ≥ k in the course of its execution. Other than this, the semantics are the same as in `Nat.Partrec.Code.eval`. -/ def evaln : ℕ → Code → ℕ → Option ℕ | 0, _ => fun _ => Option.none | k + 1, zero => fun n => do guard (n ≤ k) return 0 | k + 1, succ => fun n => do guard (n ≤ k) return (Nat.succ n) | k + 1, left => fun n => do guard (n ≤ k) return n.unpair.1 | k + 1, right => fun n => do guard (n ≤ k) pure n.unpair.2 | k + 1, pair cf cg => fun n => do guard (n ≤ k) Nat.pair <$> evaln (k + 1) cf n <*> evaln (k + 1) cg n | k + 1, comp cf cg => fun n => do guard (n ≤ k) let x ← evaln (k + 1) cg n evaln (k + 1) cf x | k + 1, prec cf cg => fun n => do guard (n ≤ k) n.unpaired fun a n => n.casesOn (evaln (k + 1) cf a) fun y => do let i ← evaln k (prec cf cg) (Nat.pair a y) evaln (k + 1) cg (Nat.pair a (Nat.pair y i)) | k + 1, rfind' cf => fun n => do guard (n ≤ k) n.unpaired fun a m => do let x ← evaln (k + 1) cf (Nat.pair a m) if x = 0 then pure m else evaln k (rfind' cf) (Nat.pair a (m + 1)) #align nat.partrec.code.evaln Nat.Partrec.Code.evaln theorem evaln_bound : ∀ {k c n x}, x ∈ evaln k c n → n < k | 0, c, n, x, h => by simp [evaln] at h | k + 1, c, n, x, h => by suffices ∀ {o : Option ℕ}, x ∈ do { guard (n ≤ k); o } → n < k + 1 by cases c <;> rw [evaln] at h <;> exact this h simpa [Option.bind_eq_some] using Nat.lt_succ_of_le #align nat.partrec.code.evaln_bound Nat.Partrec.Code.evaln_bound theorem evaln_mono : ∀ {k₁ k₂ c n x}, k₁ ≤ k₂ → x ∈ evaln k₁ c n → x ∈ evaln k₂ c n | 0, k₂, c, n, x, _, h => by simp [evaln] at h | k + 1, k₂ + 1, c, n, x, hl, h => by have hl' := Nat.le_of_succ_le_succ hl have : ∀ {k k₂ n x : ℕ} {o₁ o₂ : Option ℕ}, k ≤ k₂ → (x ∈ o₁ → x ∈ o₂) → x ∈ do { guard (n ≤ k); o₁ } → x ∈ do { guard (n ≤ k₂); o₂ } := by simp only [Option.mem_def, bind, Option.bind_eq_some, Option.guard_eq_some', exists_and_left, exists_const, and_imp] introv h h₁ h₂ h₃ exact ⟨le_trans h₂ h, h₁ h₃⟩ simp? at h ⊢ says simp only [Option.mem_def] at h ⊢ induction' c with cf cg hf hg cf cg hf hg cf cg hf hg cf hf generalizing x n <;> rw [evaln] at h ⊢ <;> refine this hl' (fun h => ?_) h iterate 4 exact h · -- pair cf cg simp? [Seq.seq, Option.bind_eq_some] at h ⊢ says simp only [Seq.seq, Option.map_eq_map, Option.mem_def, Option.bind_eq_some, Option.map_eq_some', exists_exists_and_eq_and] at h ⊢ exact h.imp fun a => And.imp (hf _ _) <| Exists.imp fun b => And.imp_left (hg _ _) · -- comp cf cg simp? [Bind.bind, Option.bind_eq_some] at h ⊢ says simp only [bind, Option.mem_def, Option.bind_eq_some] at h ⊢ exact h.imp fun a => And.imp (hg _ _) (hf _ _) · -- prec cf cg revert h simp only [unpaired, bind, Option.mem_def] induction n.unpair.2 <;> simp [Option.bind_eq_some] · apply hf · exact fun y h₁ h₂ => ⟨y, evaln_mono hl' h₁, hg _ _ h₂⟩ · -- rfind' cf simp? [Bind.bind, Option.bind_eq_some] at h ⊢ says simp only [unpaired, bind, pair_unpair, Option.pure_def, Option.mem_def, Option.bind_eq_some] at h ⊢ refine h.imp fun x => And.imp (hf _ _) ?_ by_cases x0 : x = 0 <;> simp [x0] exact evaln_mono hl' #align nat.partrec.code.evaln_mono Nat.Partrec.Code.evaln_mono theorem evaln_sound : ∀ {k c n x}, x ∈ evaln k c n → x ∈ eval c n | 0, _, n, x, h => by simp [evaln] at h | k + 1, c, n, x, h => by induction' c with cf cg hf hg cf cg hf hg cf cg hf hg cf hf generalizing x n <;> simp [eval, evaln, Option.bind_eq_some, Seq.seq] at h ⊢ <;> cases' h with _ h iterate 4 simpa [pure, PFun.pure, eq_comm] using h · -- pair cf cg rcases h with ⟨y, ef, z, eg, rfl⟩ exact ⟨_, hf _ _ ef, _, hg _ _ eg, rfl⟩ · --comp hf hg rcases h with ⟨y, eg, ef⟩ exact ⟨_, hg _ _ eg, hf _ _ ef⟩ · -- prec cf cg revert h induction' n.unpair.2 with m IH generalizing x <;> simp [Option.bind_eq_some] · apply hf · refine fun y h₁ h₂ => ⟨y, IH _ ?_, ?_⟩ · have := evaln_mono k.le_succ h₁ simp [evaln, Option.bind_eq_some] at this exact this.2 · exact hg _ _ h₂ · -- rfind' cf rcases h with ⟨m, h₁, h₂⟩ by_cases m0 : m = 0 <;> simp [m0] at h₂ · exact ⟨0, ⟨by simpa [m0] using hf _ _ h₁, fun {m} => (Nat.not_lt_zero _).elim⟩, by simp [h₂]⟩ · have := evaln_sound h₂ simp [eval] at this rcases this with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩ refine ⟨y + 1, ⟨by simpa [add_comm, add_left_comm] using hy₁, fun {i} im => ?_⟩, by simp [add_comm, add_left_comm]⟩ cases' i with i · exact ⟨m, by simpa using hf _ _ h₁, m0⟩ · rcases hy₂ (Nat.lt_of_succ_lt_succ im) with ⟨z, hz, z0⟩ exact ⟨z, by simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hz, z0⟩ #align nat.partrec.code.evaln_sound Nat.Partrec.Code.evaln_sound
Mathlib/Computability/PartrecCode.lean
729
795
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n := by
refine ⟨fun h => ?_, fun ⟨k, h⟩ => evaln_sound h⟩ rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n · exact ⟨k + 1, h⟩ induction c generalizing n x with simp [eval, evaln, pure, PFun.pure, Seq.seq, Option.bind_eq_some] at h ⊢ | pair cf cg hf hg => rcases h with ⟨x, hx, y, hy, rfl⟩ rcases hf hx with ⟨k₁, hk₁⟩; rcases hg hy with ⟨k₂, hk₂⟩ refine ⟨max k₁ k₂, ?_⟩ refine ⟨le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁, _, evaln_mono (Nat.succ_le_succ <| le_max_left _ _) hk₁, _, evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂, rfl⟩ | comp cf cg hf hg => rcases h with ⟨y, hy, hx⟩ rcases hg hy with ⟨k₁, hk₁⟩; rcases hf hx with ⟨k₂, hk₂⟩ refine ⟨max k₁ k₂, ?_⟩ exact ⟨le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁, _, evaln_mono (Nat.succ_le_succ <| le_max_left _ _) hk₁, evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂⟩ | prec cf cg hf hg => revert h generalize n.unpair.1 = n₁; generalize n.unpair.2 = n₂ induction' n₂ with m IH generalizing x n <;> simp [Option.bind_eq_some] · intro h rcases hf h with ⟨k, hk⟩ exact ⟨_, le_max_left _ _, evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk⟩ · intro y hy hx rcases IH hy with ⟨k₁, nk₁, hk₁⟩ rcases hg hx with ⟨k₂, hk₂⟩ refine ⟨(max k₁ k₂).succ, Nat.le_succ_of_le <| le_max_of_le_left <| le_trans (le_max_left _ (Nat.pair n₁ m)) nk₁, y, evaln_mono (Nat.succ_le_succ <| le_max_left _ _) ?_, evaln_mono (Nat.succ_le_succ <| Nat.le_succ_of_le <| le_max_right _ _) hk₂⟩ simp only [evaln.eq_8, bind, unpaired, unpair_pair, Option.mem_def, Option.bind_eq_some, Option.guard_eq_some', exists_and_left, exists_const] exact ⟨le_trans (le_max_right _ _) nk₁, hk₁⟩ | rfind' cf hf => rcases h with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩ suffices ∃ k, y + n.unpair.2 ∈ evaln (k + 1) (rfind' cf) (Nat.pair n.unpair.1 n.unpair.2) by simpa [evaln, Option.bind_eq_some] revert hy₁ hy₂ generalize n.unpair.2 = m intro hy₁ hy₂ induction' y with y IH generalizing m <;> simp [evaln, Option.bind_eq_some] · simp at hy₁ rcases hf hy₁ with ⟨k, hk⟩ exact ⟨_, Nat.le_of_lt_succ <| evaln_bound hk, _, hk, by simp⟩ · rcases hy₂ (Nat.succ_pos _) with ⟨a, ha, a0⟩ rcases hf ha with ⟨k₁, hk₁⟩ rcases IH m.succ (by simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hy₁) fun {i} hi => by simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hy₂ (Nat.succ_lt_succ hi) with ⟨k₂, hk₂⟩ use (max k₁ k₂).succ rw [zero_add] at hk₁ use Nat.le_succ_of_le <| le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁ use a use evaln_mono (Nat.succ_le_succ <| Nat.le_succ_of_le <| le_max_left _ _) hk₁ simpa [Nat.succ_eq_add_one, a0, -max_eq_left, -max_eq_right, add_comm, add_left_comm] using evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂ | _ => exact ⟨⟨_, le_rfl⟩, h.symm⟩
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.NumberTheory.LegendreSymbol.AddCharacter import Mathlib.NumberTheory.LegendreSymbol.ZModChar import Mathlib.Algebra.CharP.CharAndCard #align_import number_theory.legendre_symbol.gauss_sum from "leanprover-community/mathlib"@"e3f4be1fcb5376c4948d7f095bec45350bfb9d1a" /-! # Gauss sums We define the Gauss sum associated to a multiplicative and an additive character of a finite field and prove some results about them. ## Main definition Let `R` be a finite commutative ring and let `R'` be another commutative ring. If `χ` is a multiplicative character `R → R'` (type `MulChar R R'`) and `ψ` is an additive character `R → R'` (type `AddChar R R'`, which abbreviates `(Multiplicative R) →* R'`), then the *Gauss sum* of `χ` and `ψ` is `∑ a, χ a * ψ a`. ## Main results Some important results are as follows. * `gaussSum_mul_gaussSum_eq_card`: The product of the Gauss sums of `χ` and `ψ` and that of `χ⁻¹` and `ψ⁻¹` is the cardinality of the source ring `R` (if `χ` is nontrivial, `ψ` is primitive and `R` is a field). * `gaussSum_sq`: The square of the Gauss sum is `χ(-1)` times the cardinality of `R` if in addition `χ` is a quadratic character. * `MulChar.IsQuadratic.gaussSum_frob`: For a quadratic character `χ`, raising the Gauss sum to the `p`th power (where `p` is the characteristic of the target ring `R'`) multiplies it by `χ p`. * `Char.card_pow_card`: When `F` and `F'` are finite fields and `χ : F → F'` is a nontrivial quadratic character, then `(χ (-1) * #F)^(#F'/2) = χ #F'`. * `FiniteField.two_pow_card`: For every finite field `F` of odd characteristic, we have `2^(#F/2) = χ₈#F` in `F`. This machinery can be used to derive (a generalization of) the Law of Quadratic Reciprocity. ## Tags additive character, multiplicative character, Gauss sum -/ universe u v open AddChar MulChar section GaussSumDef -- `R` is the domain of the characters variable {R : Type u} [CommRing R] [Fintype R] -- `R'` is the target of the characters variable {R' : Type v} [CommRing R'] /-! ### Definition and first properties -/ /-- Definition of the Gauss sum associated to a multiplicative and an additive character. -/ def gaussSum (χ : MulChar R R') (ψ : AddChar R R') : R' := ∑ a, χ a * ψ a #align gauss_sum gaussSum /-- Replacing `ψ` by `mulShift ψ a` and multiplying the Gauss sum by `χ a` does not change it. -/ theorem gaussSum_mulShift (χ : MulChar R R') (ψ : AddChar R R') (a : Rˣ) : χ a * gaussSum χ (mulShift ψ a) = gaussSum χ ψ := by simp only [gaussSum, mulShift_apply, Finset.mul_sum] simp_rw [← mul_assoc, ← map_mul] exact Fintype.sum_bijective _ a.mulLeft_bijective _ _ fun x => rfl #align gauss_sum_mul_shift gaussSum_mulShift end GaussSumDef /-! ### The product of two Gauss sums -/ section GaussSumProd -- In the following, we need `R` to be a finite field and `R'` to be a domain. variable {R : Type u} [Field R] [Fintype R] {R' : Type v} [CommRing R'] [IsDomain R'] -- A helper lemma for `gaussSum_mul_gaussSum_eq_card` below -- Is this useful enough in other contexts to be public? private theorem gaussSum_mul_aux {χ : MulChar R R'} (hχ : IsNontrivial χ) (ψ : AddChar R R') (b : R) : ∑ a, χ (a * b⁻¹) * ψ (a - b) = ∑ c, χ c * ψ (b * (c - 1)) := by rcases eq_or_ne b 0 with hb | hb · -- case `b = 0` simp only [hb, inv_zero, mul_zero, MulChar.map_zero, zero_mul, Finset.sum_const_zero, map_zero_eq_one, mul_one] exact (hχ.sum_eq_zero).symm · -- case `b ≠ 0` refine (Fintype.sum_bijective _ (mulLeft_bijective₀ b hb) _ _ fun x => ?_).symm rw [mul_assoc, mul_comm x, ← mul_assoc, mul_inv_cancel hb, one_mul, mul_sub, mul_one] /-- We have `gaussSum χ ψ * gaussSum χ⁻¹ ψ⁻¹ = Fintype.card R` when `χ` is nontrivial and `ψ` is primitive (and `R` is a field). -/ theorem gaussSum_mul_gaussSum_eq_card {χ : MulChar R R'} (hχ : IsNontrivial χ) {ψ : AddChar R R'} (hψ : IsPrimitive ψ) : gaussSum χ ψ * gaussSum χ⁻¹ ψ⁻¹ = Fintype.card R := by simp only [gaussSum, AddChar.inv_apply, Finset.sum_mul, Finset.mul_sum, MulChar.inv_apply'] conv => lhs; congr; next => skip ext; congr; next => skip ext rw [mul_mul_mul_comm, ← map_mul, ← map_add_eq_mul, ← sub_eq_add_neg] -- conv in _ * _ * (_ * _) => rw [mul_mul_mul_comm, ← map_mul, ← map_add_eq_mul, ← sub_eq_add_neg] simp_rw [gaussSum_mul_aux hχ ψ] rw [Finset.sum_comm] classical -- to get `[DecidableEq R]` for `sum_mulShift` simp_rw [← Finset.mul_sum, sum_mulShift _ hψ, sub_eq_zero, apply_ite, Nat.cast_zero, mul_zero] rw [Finset.sum_ite_eq' Finset.univ (1 : R)] simp only [Finset.mem_univ, map_one, one_mul, if_true] #align gauss_sum_mul_gauss_sum_eq_card gaussSum_mul_gaussSum_eq_card /-- When `χ` is a nontrivial quadratic character, then the square of `gaussSum χ ψ` is `χ(-1)` times the cardinality of `R`. -/ theorem gaussSum_sq {χ : MulChar R R'} (hχ₁ : IsNontrivial χ) (hχ₂ : IsQuadratic χ) {ψ : AddChar R R'} (hψ : IsPrimitive ψ) : gaussSum χ ψ ^ 2 = χ (-1) * Fintype.card R := by rw [pow_two, ← gaussSum_mul_gaussSum_eq_card hχ₁ hψ, hχ₂.inv, mul_rotate'] congr rw [mul_comm, ← gaussSum_mulShift _ _ (-1 : Rˣ), inv_mulShift] rfl #align gauss_sum_sq gaussSum_sq end GaussSumProd /-! ### Gauss sums and Frobenius -/ section gaussSum_frob variable {R : Type u} [CommRing R] [Fintype R] {R' : Type v} [CommRing R'] -- We assume that the target ring `R'` has prime characteristic `p`. variable (p : ℕ) [fp : Fact p.Prime] [hch : CharP R' p] /-- When `R'` has prime characteristic `p`, then the `p`th power of the Gauss sum of `χ` and `ψ` is the Gauss sum of `χ^p` and `ψ^p`. -/
Mathlib/NumberTheory/GaussSum.lean
151
155
theorem gaussSum_frob (χ : MulChar R R') (ψ : AddChar R R') : gaussSum χ ψ ^ p = gaussSum (χ ^ p) (ψ ^ p) := by
rw [← frobenius_def, gaussSum, gaussSum, map_sum] simp_rw [pow_apply' χ fp.1.ne_zero, map_mul, frobenius_def] rfl