Context stringlengths 285 157k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 18 3.69k | theorem stringlengths 25 2.71k | proof stringlengths 5 10.6k |
|---|---|---|---|---|---|
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.NormedSpace.IndicatorFunction
import Mathlib.MeasureTheory.Function.EssSup
import Mathlib.MeasureTheory.Function.AEEqFun
import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
#align_import measure_theory.function.lp_seminorm from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9"
/-!
# ℒp space
This file describes properties of almost everywhere strongly measurable functions with finite
`p`-seminorm, denoted by `snorm f p μ` and defined for `p:ℝ≥0∞` as `0` if `p=0`,
`(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and `essSup ‖f‖ μ` for `p=∞`.
The Prop-valued `Memℒp f p μ` states that a function `f : α → E` has finite `p`-seminorm
and is almost everywhere strongly measurable.
## Main definitions
* `snorm' f p μ` : `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `f : α → F` and `p : ℝ`, where `α` is a measurable
space and `F` is a normed group.
* `snormEssSup f μ` : seminorm in `ℒ∞`, equal to the essential supremum `ess_sup ‖f‖ μ`.
* `snorm f p μ` : for `p : ℝ≥0∞`, seminorm in `ℒp`, equal to `0` for `p=0`, to `snorm' f p μ`
for `0 < p < ∞` and to `snormEssSup f μ` for `p = ∞`.
* `Memℒp f p μ` : property that the function `f` is almost everywhere strongly measurable and has
finite `p`-seminorm for the measure `μ` (`snorm f p μ < ∞`)
-/
noncomputable section
set_option linter.uppercaseLean3 false
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology
variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G]
namespace MeasureTheory
section ℒp
/-!
### ℒp seminorm
We define the ℒp seminorm, denoted by `snorm f p μ`. For real `p`, it is given by an integral
formula (for which we use the notation `snorm' f p μ`), and for `p = ∞` it is the essential
supremum (for which we use the notation `snormEssSup f μ`).
We also define a predicate `Memℒp f p μ`, requesting that a function is almost everywhere
measurable and has finite `snorm f p μ`.
This paragraph is devoted to the basic properties of these definitions. It is constructed as
follows: for a given property, we prove it for `snorm'` and `snormEssSup` when it makes sense,
deduce it for `snorm`, and translate it in terms of `Memℒp`.
-/
section ℒpSpaceDefinition
/-- `(∫ ‖f a‖^q ∂μ) ^ (1/q)`, which is a seminorm on the space of measurable functions for which
this quantity is finite -/
def snorm' {_ : MeasurableSpace α} (f : α → F) (q : ℝ) (μ : Measure α) : ℝ≥0∞ :=
(∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q)
#align measure_theory.snorm' MeasureTheory.snorm'
/-- seminorm for `ℒ∞`, equal to the essential supremum of `‖f‖`. -/
def snormEssSup {_ : MeasurableSpace α} (f : α → F) (μ : Measure α) :=
essSup (fun x => (‖f x‖₊ : ℝ≥0∞)) μ
#align measure_theory.snorm_ess_sup MeasureTheory.snormEssSup
/-- `ℒp` seminorm, equal to `0` for `p=0`, to `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and to
`essSup ‖f‖ μ` for `p = ∞`. -/
def snorm {_ : MeasurableSpace α} (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : ℝ≥0∞ :=
if p = 0 then 0 else if p = ∞ then snormEssSup f μ else snorm' f (ENNReal.toReal p) μ
#align measure_theory.snorm MeasureTheory.snorm
theorem snorm_eq_snorm' (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} :
snorm f p μ = snorm' f (ENNReal.toReal p) μ := by simp [snorm, hp_ne_zero, hp_ne_top]
#align measure_theory.snorm_eq_snorm' MeasureTheory.snorm_eq_snorm'
theorem snorm_eq_lintegral_rpow_nnnorm (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} :
snorm f p μ = (∫⁻ x, (‖f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) ^ (1 / p.toReal) := by
rw [snorm_eq_snorm' hp_ne_zero hp_ne_top, snorm']
#align measure_theory.snorm_eq_lintegral_rpow_nnnorm MeasureTheory.snorm_eq_lintegral_rpow_nnnorm
theorem snorm_one_eq_lintegral_nnnorm {f : α → F} : snorm f 1 μ = ∫⁻ x, ‖f x‖₊ ∂μ := by
simp_rw [snorm_eq_lintegral_rpow_nnnorm one_ne_zero ENNReal.coe_ne_top, ENNReal.one_toReal,
one_div_one, ENNReal.rpow_one]
#align measure_theory.snorm_one_eq_lintegral_nnnorm MeasureTheory.snorm_one_eq_lintegral_nnnorm
@[simp]
theorem snorm_exponent_top {f : α → F} : snorm f ∞ μ = snormEssSup f μ := by simp [snorm]
#align measure_theory.snorm_exponent_top MeasureTheory.snorm_exponent_top
/-- The property that `f:α→E` is ae strongly measurable and `(∫ ‖f a‖^p ∂μ)^(1/p)` is finite
if `p < ∞`, or `essSup f < ∞` if `p = ∞`. -/
def Memℒp {α} {_ : MeasurableSpace α} (f : α → E) (p : ℝ≥0∞)
(μ : Measure α := by volume_tac) : Prop :=
AEStronglyMeasurable f μ ∧ snorm f p μ < ∞
#align measure_theory.mem_ℒp MeasureTheory.Memℒp
theorem Memℒp.aestronglyMeasurable {f : α → E} {p : ℝ≥0∞} (h : Memℒp f p μ) :
AEStronglyMeasurable f μ :=
h.1
#align measure_theory.mem_ℒp.ae_strongly_measurable MeasureTheory.Memℒp.aestronglyMeasurable
theorem lintegral_rpow_nnnorm_eq_rpow_snorm' {f : α → F} (hq0_lt : 0 < q) :
(∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) = snorm' f q μ ^ q := by
rw [snorm', ← ENNReal.rpow_mul, one_div, inv_mul_cancel, ENNReal.rpow_one]
exact (ne_of_lt hq0_lt).symm
#align measure_theory.lintegral_rpow_nnnorm_eq_rpow_snorm' MeasureTheory.lintegral_rpow_nnnorm_eq_rpow_snorm'
end ℒpSpaceDefinition
section Top
theorem Memℒp.snorm_lt_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ < ∞ :=
hfp.2
#align measure_theory.mem_ℒp.snorm_lt_top MeasureTheory.Memℒp.snorm_lt_top
theorem Memℒp.snorm_ne_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ ≠ ∞ :=
ne_of_lt hfp.2
#align measure_theory.mem_ℒp.snorm_ne_top MeasureTheory.Memℒp.snorm_ne_top
theorem lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top {f : α → F} (hq0_lt : 0 < q)
(hfq : snorm' f q μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) < ∞ := by
rw [lintegral_rpow_nnnorm_eq_rpow_snorm' hq0_lt]
exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq)
#align measure_theory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top MeasureTheory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top
theorem lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hfp : snorm f p μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) < ∞ := by
apply lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top
· exact ENNReal.toReal_pos hp_ne_zero hp_ne_top
· simpa [snorm_eq_snorm' hp_ne_zero hp_ne_top] using hfp
#align measure_theory.lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top MeasureTheory.lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top
theorem snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) : snorm f p μ < ∞ ↔ (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) < ∞ :=
⟨lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_ne_zero hp_ne_top, by
intro h
have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top
have : 0 < 1 / p.toReal := div_pos zero_lt_one hp'
simpa [snorm_eq_lintegral_rpow_nnnorm hp_ne_zero hp_ne_top] using
ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩
#align measure_theory.snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top MeasureTheory.snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top
end Top
section Zero
@[simp]
theorem snorm'_exponent_zero {f : α → F} : snorm' f 0 μ = 1 := by
rw [snorm', div_zero, ENNReal.rpow_zero]
#align measure_theory.snorm'_exponent_zero MeasureTheory.snorm'_exponent_zero
@[simp]
theorem snorm_exponent_zero {f : α → F} : snorm f 0 μ = 0 := by simp [snorm]
#align measure_theory.snorm_exponent_zero MeasureTheory.snorm_exponent_zero
@[simp]
theorem memℒp_zero_iff_aestronglyMeasurable {f : α → E} :
Memℒp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [Memℒp, snorm_exponent_zero]
#align measure_theory.mem_ℒp_zero_iff_ae_strongly_measurable MeasureTheory.memℒp_zero_iff_aestronglyMeasurable
@[simp]
theorem snorm'_zero (hp0_lt : 0 < q) : snorm' (0 : α → F) q μ = 0 := by simp [snorm', hp0_lt]
#align measure_theory.snorm'_zero MeasureTheory.snorm'_zero
@[simp]
theorem snorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : snorm' (0 : α → F) q μ = 0 := by
rcases le_or_lt 0 q with hq0 | hq_neg
· exact snorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm)
· simp [snorm', ENNReal.rpow_eq_zero_iff, hμ, hq_neg]
#align measure_theory.snorm'_zero' MeasureTheory.snorm'_zero'
@[simp]
theorem snormEssSup_zero : snormEssSup (0 : α → F) μ = 0 := by
simp_rw [snormEssSup, Pi.zero_apply, nnnorm_zero, ENNReal.coe_zero, ← ENNReal.bot_eq_zero]
exact essSup_const_bot
#align measure_theory.snorm_ess_sup_zero MeasureTheory.snormEssSup_zero
@[simp]
theorem snorm_zero : snorm (0 : α → F) p μ = 0 := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp only [h_top, snorm_exponent_top, snormEssSup_zero]
rw [← Ne] at h0
simp [snorm_eq_snorm' h0 h_top, ENNReal.toReal_pos h0 h_top]
#align measure_theory.snorm_zero MeasureTheory.snorm_zero
@[simp]
theorem snorm_zero' : snorm (fun _ : α => (0 : F)) p μ = 0 := by convert snorm_zero (F := F)
#align measure_theory.snorm_zero' MeasureTheory.snorm_zero'
theorem zero_memℒp : Memℒp (0 : α → E) p μ :=
⟨aestronglyMeasurable_zero, by
rw [snorm_zero]
exact ENNReal.coe_lt_top⟩
#align measure_theory.zero_mem_ℒp MeasureTheory.zero_memℒp
theorem zero_mem_ℒp' : Memℒp (fun _ : α => (0 : E)) p μ := zero_memℒp (E := E)
#align measure_theory.zero_mem_ℒp' MeasureTheory.zero_mem_ℒp'
variable [MeasurableSpace α]
theorem snorm'_measure_zero_of_pos {f : α → F} (hq_pos : 0 < q) :
snorm' f q (0 : Measure α) = 0 := by simp [snorm', hq_pos]
#align measure_theory.snorm'_measure_zero_of_pos MeasureTheory.snorm'_measure_zero_of_pos
theorem snorm'_measure_zero_of_exponent_zero {f : α → F} : snorm' f 0 (0 : Measure α) = 1 := by
simp [snorm']
#align measure_theory.snorm'_measure_zero_of_exponent_zero MeasureTheory.snorm'_measure_zero_of_exponent_zero
theorem snorm'_measure_zero_of_neg {f : α → F} (hq_neg : q < 0) :
snorm' f q (0 : Measure α) = ∞ := by simp [snorm', hq_neg]
#align measure_theory.snorm'_measure_zero_of_neg MeasureTheory.snorm'_measure_zero_of_neg
@[simp]
theorem snormEssSup_measure_zero {f : α → F} : snormEssSup f (0 : Measure α) = 0 := by
simp [snormEssSup]
#align measure_theory.snorm_ess_sup_measure_zero MeasureTheory.snormEssSup_measure_zero
@[simp]
theorem snorm_measure_zero {f : α → F} : snorm f p (0 : Measure α) = 0 := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp [h_top]
rw [← Ne] at h0
simp [snorm_eq_snorm' h0 h_top, snorm', ENNReal.toReal_pos h0 h_top]
#align measure_theory.snorm_measure_zero MeasureTheory.snorm_measure_zero
end Zero
section Neg
@[simp]
theorem snorm'_neg {f : α → F} : snorm' (-f) q μ = snorm' f q μ := by simp [snorm']
#align measure_theory.snorm'_neg MeasureTheory.snorm'_neg
@[simp]
theorem snorm_neg {f : α → F} : snorm (-f) p μ = snorm f p μ := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp [h_top, snormEssSup]
simp [snorm_eq_snorm' h0 h_top]
#align measure_theory.snorm_neg MeasureTheory.snorm_neg
theorem Memℒp.neg {f : α → E} (hf : Memℒp f p μ) : Memℒp (-f) p μ :=
⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩
#align measure_theory.mem_ℒp.neg MeasureTheory.Memℒp.neg
theorem memℒp_neg_iff {f : α → E} : Memℒp (-f) p μ ↔ Memℒp f p μ :=
⟨fun h => neg_neg f ▸ h.neg, Memℒp.neg⟩
#align measure_theory.mem_ℒp_neg_iff MeasureTheory.memℒp_neg_iff
end Neg
section Const
theorem snorm'_const (c : F) (hq_pos : 0 < q) :
snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / q) := by
rw [snorm', lintegral_const, ENNReal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)]
congr
rw [← ENNReal.rpow_mul]
suffices hq_cancel : q * (1 / q) = 1 by rw [hq_cancel, ENNReal.rpow_one]
rw [one_div, mul_inv_cancel (ne_of_lt hq_pos).symm]
#align measure_theory.snorm'_const MeasureTheory.snorm'_const
theorem snorm'_const' [IsFiniteMeasure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) :
snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / q) := by
rw [snorm', lintegral_const, ENNReal.mul_rpow_of_ne_top _ (measure_ne_top μ Set.univ)]
· congr
rw [← ENNReal.rpow_mul]
suffices hp_cancel : q * (1 / q) = 1 by rw [hp_cancel, ENNReal.rpow_one]
rw [one_div, mul_inv_cancel hq_ne_zero]
· rw [Ne, ENNReal.rpow_eq_top_iff, not_or, not_and_or, not_and_or]
constructor
· left
rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero]
· exact Or.inl ENNReal.coe_ne_top
#align measure_theory.snorm'_const' MeasureTheory.snorm'_const'
theorem snormEssSup_const (c : F) (hμ : μ ≠ 0) :
snormEssSup (fun _ : α => c) μ = (‖c‖₊ : ℝ≥0∞) := by rw [snormEssSup, essSup_const _ hμ]
#align measure_theory.snorm_ess_sup_const MeasureTheory.snormEssSup_const
theorem snorm'_const_of_isProbabilityMeasure (c : F) (hq_pos : 0 < q) [IsProbabilityMeasure μ] :
snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) := by simp [snorm'_const c hq_pos, measure_univ]
#align measure_theory.snorm'_const_of_is_probability_measure MeasureTheory.snorm'_const_of_isProbabilityMeasure
theorem snorm_const (c : F) (h0 : p ≠ 0) (hμ : μ ≠ 0) :
snorm (fun _ : α => c) p μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / ENNReal.toReal p) := by
by_cases h_top : p = ∞
· simp [h_top, snormEssSup_const c hμ]
simp [snorm_eq_snorm' h0 h_top, snorm'_const, ENNReal.toReal_pos h0 h_top]
#align measure_theory.snorm_const MeasureTheory.snorm_const
theorem snorm_const' (c : F) (h0 : p ≠ 0) (h_top : p ≠ ∞) :
snorm (fun _ : α => c) p μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / ENNReal.toReal p) := by
simp [snorm_eq_snorm' h0 h_top, snorm'_const, ENNReal.toReal_pos h0 h_top]
#align measure_theory.snorm_const' MeasureTheory.snorm_const'
theorem snorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
snorm (fun _ : α => c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := by
have hp : 0 < p.toReal := ENNReal.toReal_pos hp_ne_zero hp_ne_top
by_cases hμ : μ = 0
· simp only [hμ, Measure.coe_zero, Pi.zero_apply, or_true_iff, ENNReal.zero_lt_top,
snorm_measure_zero]
by_cases hc : c = 0
· simp only [hc, true_or_iff, eq_self_iff_true, ENNReal.zero_lt_top, snorm_zero']
rw [snorm_const' c hp_ne_zero hp_ne_top]
by_cases hμ_top : μ Set.univ = ∞
· simp [hc, hμ_top, hp]
rw [ENNReal.mul_lt_top_iff]
simp only [true_and_iff, one_div, ENNReal.rpow_eq_zero_iff, hμ, false_or_iff, or_false_iff,
ENNReal.coe_lt_top, nnnorm_eq_zero, ENNReal.coe_eq_zero,
MeasureTheory.Measure.measure_univ_eq_zero, hp, inv_lt_zero, hc, and_false_iff, false_and_iff,
inv_pos, or_self_iff, hμ_top, Ne.lt_top hμ_top, iff_true_iff]
exact ENNReal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_top
#align measure_theory.snorm_const_lt_top_iff MeasureTheory.snorm_const_lt_top_iff
theorem memℒp_const (c : E) [IsFiniteMeasure μ] : Memℒp (fun _ : α => c) p μ := by
refine ⟨aestronglyMeasurable_const, ?_⟩
by_cases h0 : p = 0
· simp [h0]
by_cases hμ : μ = 0
· simp [hμ]
rw [snorm_const c h0 hμ]
refine ENNReal.mul_lt_top ENNReal.coe_ne_top ?_
refine (ENNReal.rpow_lt_top_of_nonneg ?_ (measure_ne_top μ Set.univ)).ne
simp
#align measure_theory.mem_ℒp_const MeasureTheory.memℒp_const
theorem memℒp_top_const (c : E) : Memℒp (fun _ : α => c) ∞ μ := by
refine ⟨aestronglyMeasurable_const, ?_⟩
by_cases h : μ = 0
· simp only [h, snorm_measure_zero, ENNReal.zero_lt_top]
· rw [snorm_const _ ENNReal.top_ne_zero h]
simp only [ENNReal.top_toReal, div_zero, ENNReal.rpow_zero, mul_one, ENNReal.coe_lt_top]
#align measure_theory.mem_ℒp_top_const MeasureTheory.memℒp_top_const
theorem memℒp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
Memℒp (fun _ : α => c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := by
rw [← snorm_const_lt_top_iff hp_ne_zero hp_ne_top]
exact ⟨fun h => h.2, fun h => ⟨aestronglyMeasurable_const, h⟩⟩
#align measure_theory.mem_ℒp_const_iff MeasureTheory.memℒp_const_iff
end Const
theorem snorm'_mono_nnnorm_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
snorm' f q μ ≤ snorm' g q μ := by
simp only [snorm']
gcongr ?_ ^ (1/q)
refine lintegral_mono_ae (h.mono fun x hx => ?_)
gcongr
#align measure_theory.snorm'_mono_nnnorm_ae MeasureTheory.snorm'_mono_nnnorm_ae
theorem snorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) :
snorm' f q μ ≤ snorm' g q μ :=
snorm'_mono_nnnorm_ae hq h
#align measure_theory.snorm'_mono_ae MeasureTheory.snorm'_mono_ae
theorem snorm'_congr_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) :
snorm' f q μ = snorm' g q μ := by
have : (fun x => (‖f x‖₊ : ℝ≥0∞) ^ q) =ᵐ[μ] fun x => (‖g x‖₊ : ℝ≥0∞) ^ q :=
hfg.mono fun x hx => by simp_rw [hx]
simp only [snorm', lintegral_congr_ae this]
#align measure_theory.snorm'_congr_nnnorm_ae MeasureTheory.snorm'_congr_nnnorm_ae
theorem snorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) :
snorm' f q μ = snorm' g q μ :=
snorm'_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx
#align measure_theory.snorm'_congr_norm_ae MeasureTheory.snorm'_congr_norm_ae
theorem snorm'_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm' f q μ = snorm' g q μ :=
snorm'_congr_nnnorm_ae (hfg.fun_comp _)
#align measure_theory.snorm'_congr_ae MeasureTheory.snorm'_congr_ae
theorem snormEssSup_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snormEssSup f μ = snormEssSup g μ :=
essSup_congr_ae (hfg.fun_comp (((↑) : ℝ≥0 → ℝ≥0∞) ∘ nnnorm))
#align measure_theory.snorm_ess_sup_congr_ae MeasureTheory.snormEssSup_congr_ae
theorem snormEssSup_mono_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
snormEssSup f μ ≤ snormEssSup g μ :=
essSup_mono_ae <| hfg.mono fun _x hx => ENNReal.coe_le_coe.mpr hx
#align measure_theory.snorm_ess_sup_mono_nnnorm_ae MeasureTheory.snormEssSup_mono_nnnorm_ae
theorem snorm_mono_nnnorm_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
snorm f p μ ≤ snorm g p μ := by
simp only [snorm]
split_ifs
· exact le_rfl
· exact essSup_mono_ae (h.mono fun x hx => ENNReal.coe_le_coe.mpr hx)
· exact snorm'_mono_nnnorm_ae ENNReal.toReal_nonneg h
#align measure_theory.snorm_mono_nnnorm_ae MeasureTheory.snorm_mono_nnnorm_ae
theorem snorm_mono_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) :
snorm f p μ ≤ snorm g p μ :=
snorm_mono_nnnorm_ae h
#align measure_theory.snorm_mono_ae MeasureTheory.snorm_mono_ae
theorem snorm_mono_ae_real {f : α → F} {g : α → ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) :
snorm f p μ ≤ snorm g p μ :=
snorm_mono_ae <| h.mono fun _x hx => hx.trans ((le_abs_self _).trans (Real.norm_eq_abs _).symm.le)
#align measure_theory.snorm_mono_ae_real MeasureTheory.snorm_mono_ae_real
theorem snorm_mono_nnnorm {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖₊ ≤ ‖g x‖₊) :
snorm f p μ ≤ snorm g p μ :=
snorm_mono_nnnorm_ae (eventually_of_forall fun x => h x)
#align measure_theory.snorm_mono_nnnorm MeasureTheory.snorm_mono_nnnorm
theorem snorm_mono {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖ ≤ ‖g x‖) : snorm f p μ ≤ snorm g p μ :=
snorm_mono_ae (eventually_of_forall fun x => h x)
#align measure_theory.snorm_mono MeasureTheory.snorm_mono
theorem snorm_mono_real {f : α → F} {g : α → ℝ} (h : ∀ x, ‖f x‖ ≤ g x) :
snorm f p μ ≤ snorm g p μ :=
snorm_mono_ae_real (eventually_of_forall fun x => h x)
#align measure_theory.snorm_mono_real MeasureTheory.snorm_mono_real
theorem snormEssSup_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) :
snormEssSup f μ ≤ C :=
essSup_le_of_ae_le (C : ℝ≥0∞) <| hfC.mono fun _x hx => ENNReal.coe_le_coe.mpr hx
#align measure_theory.snorm_ess_sup_le_of_ae_nnnorm_bound MeasureTheory.snormEssSup_le_of_ae_nnnorm_bound
theorem snormEssSup_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
snormEssSup f μ ≤ ENNReal.ofReal C :=
snormEssSup_le_of_ae_nnnorm_bound <| hfC.mono fun _x hx => hx.trans C.le_coe_toNNReal
#align measure_theory.snorm_ess_sup_le_of_ae_bound MeasureTheory.snormEssSup_le_of_ae_bound
theorem snormEssSup_lt_top_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) :
snormEssSup f μ < ∞ :=
(snormEssSup_le_of_ae_nnnorm_bound hfC).trans_lt ENNReal.coe_lt_top
#align measure_theory.snorm_ess_sup_lt_top_of_ae_nnnorm_bound MeasureTheory.snormEssSup_lt_top_of_ae_nnnorm_bound
theorem snormEssSup_lt_top_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
snormEssSup f μ < ∞ :=
(snormEssSup_le_of_ae_bound hfC).trans_lt ENNReal.ofReal_lt_top
#align measure_theory.snorm_ess_sup_lt_top_of_ae_bound MeasureTheory.snormEssSup_lt_top_of_ae_bound
theorem snorm_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) :
snorm f p μ ≤ C • μ Set.univ ^ p.toReal⁻¹ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· simp
by_cases hp : p = 0
· simp [hp]
have : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖(C : ℝ)‖₊ := hfC.mono fun x hx => hx.trans_eq C.nnnorm_eq.symm
refine (snorm_mono_ae this).trans_eq ?_
rw [snorm_const _ hp (NeZero.ne μ), C.nnnorm_eq, one_div, ENNReal.smul_def, smul_eq_mul]
#align measure_theory.snorm_le_of_ae_nnnorm_bound MeasureTheory.snorm_le_of_ae_nnnorm_bound
theorem snorm_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
snorm f p μ ≤ μ Set.univ ^ p.toReal⁻¹ * ENNReal.ofReal C := by
rw [← mul_comm]
exact snorm_le_of_ae_nnnorm_bound (hfC.mono fun x hx => hx.trans C.le_coe_toNNReal)
#align measure_theory.snorm_le_of_ae_bound MeasureTheory.snorm_le_of_ae_bound
theorem snorm_congr_nnnorm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) :
snorm f p μ = snorm g p μ :=
le_antisymm (snorm_mono_nnnorm_ae <| EventuallyEq.le hfg)
(snorm_mono_nnnorm_ae <| (EventuallyEq.symm hfg).le)
#align measure_theory.snorm_congr_nnnorm_ae MeasureTheory.snorm_congr_nnnorm_ae
theorem snorm_congr_norm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) :
snorm f p μ = snorm g p μ :=
snorm_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx
#align measure_theory.snorm_congr_norm_ae MeasureTheory.snorm_congr_norm_ae
open scoped symmDiff in
theorem snorm_indicator_sub_indicator (s t : Set α) (f : α → E) :
snorm (s.indicator f - t.indicator f) p μ = snorm ((s ∆ t).indicator f) p μ :=
snorm_congr_norm_ae <| ae_of_all _ fun x ↦ by
simp only [Pi.sub_apply, Set.apply_indicator_symmDiff norm_neg]
@[simp]
theorem snorm'_norm {f : α → F} : snorm' (fun a => ‖f a‖) q μ = snorm' f q μ := by simp [snorm']
#align measure_theory.snorm'_norm MeasureTheory.snorm'_norm
@[simp]
theorem snorm_norm (f : α → F) : snorm (fun x => ‖f x‖) p μ = snorm f p μ :=
snorm_congr_norm_ae <| eventually_of_forall fun _ => norm_norm _
#align measure_theory.snorm_norm MeasureTheory.snorm_norm
theorem snorm'_norm_rpow (f : α → F) (p q : ℝ) (hq_pos : 0 < q) :
snorm' (fun x => ‖f x‖ ^ q) p μ = snorm' f (p * q) μ ^ q := by
simp_rw [snorm']
rw [← ENNReal.rpow_mul, ← one_div_mul_one_div]
simp_rw [one_div]
rw [mul_assoc, inv_mul_cancel hq_pos.ne.symm, mul_one]
congr
ext1 x
simp_rw [← ofReal_norm_eq_coe_nnnorm]
rw [Real.norm_eq_abs, abs_eq_self.mpr (Real.rpow_nonneg (norm_nonneg _) _), mul_comm, ←
ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) hq_pos.le, ENNReal.rpow_mul]
#align measure_theory.snorm'_norm_rpow MeasureTheory.snorm'_norm_rpow
theorem snorm_norm_rpow (f : α → F) (hq_pos : 0 < q) :
snorm (fun x => ‖f x‖ ^ q) p μ = snorm f (p * ENNReal.ofReal q) μ ^ q := by
by_cases h0 : p = 0
· simp [h0, ENNReal.zero_rpow_of_pos hq_pos]
by_cases hp_top : p = ∞
· simp only [hp_top, snorm_exponent_top, ENNReal.top_mul', hq_pos.not_le, ENNReal.ofReal_eq_zero,
if_false, snorm_exponent_top, snormEssSup]
have h_rpow :
essSup (fun x : α => (‖‖f x‖ ^ q‖₊ : ℝ≥0∞)) μ =
essSup (fun x : α => (‖f x‖₊ : ℝ≥0∞) ^ q) μ := by
congr
ext1 x
conv_rhs => rw [← nnnorm_norm]
rw [ENNReal.coe_rpow_of_nonneg _ hq_pos.le, ENNReal.coe_inj]
ext
push_cast
rw [Real.norm_rpow_of_nonneg (norm_nonneg _)]
rw [h_rpow]
have h_rpow_mono := ENNReal.strictMono_rpow_of_pos hq_pos
have h_rpow_surj := (ENNReal.rpow_left_bijective hq_pos.ne.symm).2
let iso := h_rpow_mono.orderIsoOfSurjective _ h_rpow_surj
exact (iso.essSup_apply (fun x => (‖f x‖₊ : ℝ≥0∞)) μ).symm
rw [snorm_eq_snorm' h0 hp_top, snorm_eq_snorm' _ _]
swap;
· refine mul_ne_zero h0 ?_
rwa [Ne, ENNReal.ofReal_eq_zero, not_le]
swap; · exact ENNReal.mul_ne_top hp_top ENNReal.ofReal_ne_top
rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal hq_pos.le]
exact snorm'_norm_rpow f p.toReal q hq_pos
#align measure_theory.snorm_norm_rpow MeasureTheory.snorm_norm_rpow
theorem snorm_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm f p μ = snorm g p μ :=
snorm_congr_norm_ae <| hfg.mono fun _x hx => hx ▸ rfl
#align measure_theory.snorm_congr_ae MeasureTheory.snorm_congr_ae
theorem memℒp_congr_ae {f g : α → E} (hfg : f =ᵐ[μ] g) : Memℒp f p μ ↔ Memℒp g p μ := by
simp only [Memℒp, snorm_congr_ae hfg, aestronglyMeasurable_congr hfg]
#align measure_theory.mem_ℒp_congr_ae MeasureTheory.memℒp_congr_ae
theorem Memℒp.ae_eq {f g : α → E} (hfg : f =ᵐ[μ] g) (hf_Lp : Memℒp f p μ) : Memℒp g p μ :=
(memℒp_congr_ae hfg).1 hf_Lp
#align measure_theory.mem_ℒp.ae_eq MeasureTheory.Memℒp.ae_eq
theorem Memℒp.of_le {f : α → E} {g : α → F} (hg : Memℒp g p μ) (hf : AEStronglyMeasurable f μ)
(hfg : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : Memℒp f p μ :=
⟨hf, (snorm_mono_ae hfg).trans_lt hg.snorm_lt_top⟩
#align measure_theory.mem_ℒp.of_le MeasureTheory.Memℒp.of_le
alias Memℒp.mono := Memℒp.of_le
#align measure_theory.mem_ℒp.mono MeasureTheory.Memℒp.mono
theorem Memℒp.mono' {f : α → E} {g : α → ℝ} (hg : Memℒp g p μ) (hf : AEStronglyMeasurable f μ)
(h : ∀ᵐ a ∂μ, ‖f a‖ ≤ g a) : Memℒp f p μ :=
hg.mono hf <| h.mono fun _x hx => le_trans hx (le_abs_self _)
#align measure_theory.mem_ℒp.mono' MeasureTheory.Memℒp.mono'
theorem Memℒp.congr_norm {f : α → E} {g : α → F} (hf : Memℒp f p μ) (hg : AEStronglyMeasurable g μ)
(h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : Memℒp g p μ :=
hf.mono hg <| EventuallyEq.le <| EventuallyEq.symm h
#align measure_theory.mem_ℒp.congr_norm MeasureTheory.Memℒp.congr_norm
theorem memℒp_congr_norm {f : α → E} {g : α → F} (hf : AEStronglyMeasurable f μ)
(hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : Memℒp f p μ ↔ Memℒp g p μ :=
⟨fun h2f => h2f.congr_norm hg h, fun h2g => h2g.congr_norm hf <| EventuallyEq.symm h⟩
#align measure_theory.mem_ℒp_congr_norm MeasureTheory.memℒp_congr_norm
theorem memℒp_top_of_bound {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ)
(hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : Memℒp f ∞ μ :=
⟨hf, by
rw [snorm_exponent_top]
exact snormEssSup_lt_top_of_ae_bound hfC⟩
#align measure_theory.mem_ℒp_top_of_bound MeasureTheory.memℒp_top_of_bound
theorem Memℒp.of_bound [IsFiniteMeasure μ] {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ)
(hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : Memℒp f p μ :=
(memℒp_const C).of_le hf (hfC.mono fun _x hx => le_trans hx (le_abs_self _))
#align measure_theory.mem_ℒp.of_bound MeasureTheory.Memℒp.of_bound
@[mono]
theorem snorm'_mono_measure (f : α → F) (hμν : ν ≤ μ) (hq : 0 ≤ q) :
snorm' f q ν ≤ snorm' f q μ := by
simp_rw [snorm']
gcongr
exact lintegral_mono' hμν le_rfl
#align measure_theory.snorm'_mono_measure MeasureTheory.snorm'_mono_measure
@[mono]
theorem snormEssSup_mono_measure (f : α → F) (hμν : ν ≪ μ) : snormEssSup f ν ≤ snormEssSup f μ := by
simp_rw [snormEssSup]
exact essSup_mono_measure hμν
#align measure_theory.snorm_ess_sup_mono_measure MeasureTheory.snormEssSup_mono_measure
@[mono]
theorem snorm_mono_measure (f : α → F) (hμν : ν ≤ μ) : snorm f p ν ≤ snorm f p μ := by
by_cases hp0 : p = 0
· simp [hp0]
by_cases hp_top : p = ∞
· simp [hp_top, snormEssSup_mono_measure f (Measure.absolutelyContinuous_of_le hμν)]
simp_rw [snorm_eq_snorm' hp0 hp_top]
exact snorm'_mono_measure f hμν ENNReal.toReal_nonneg
#align measure_theory.snorm_mono_measure MeasureTheory.snorm_mono_measure
theorem Memℒp.mono_measure {f : α → E} (hμν : ν ≤ μ) (hf : Memℒp f p μ) : Memℒp f p ν :=
⟨hf.1.mono_measure hμν, (snorm_mono_measure f hμν).trans_lt hf.2⟩
#align measure_theory.mem_ℒp.mono_measure MeasureTheory.Memℒp.mono_measure
lemma snorm_restrict_le (f : α → F) (p : ℝ≥0∞) (μ : Measure α) (s : Set α) :
snorm f p (μ.restrict s) ≤ snorm f p μ :=
snorm_mono_measure f Measure.restrict_le_self
theorem Memℒp.restrict (s : Set α) {f : α → E} (hf : Memℒp f p μ) : Memℒp f p (μ.restrict s) :=
hf.mono_measure Measure.restrict_le_self
#align measure_theory.mem_ℒp.restrict MeasureTheory.Memℒp.restrict
theorem snorm'_smul_measure {p : ℝ} (hp : 0 ≤ p) {f : α → F} (c : ℝ≥0∞) :
snorm' f p (c • μ) = c ^ (1 / p) * snorm' f p μ := by
rw [snorm', lintegral_smul_measure, ENNReal.mul_rpow_of_nonneg, snorm']
simp [hp]
#align measure_theory.snorm'_smul_measure MeasureTheory.snorm'_smul_measure
theorem snormEssSup_smul_measure {f : α → F} {c : ℝ≥0∞} (hc : c ≠ 0) :
snormEssSup f (c • μ) = snormEssSup f μ := by
simp_rw [snormEssSup]
exact essSup_smul_measure hc
#align measure_theory.snorm_ess_sup_smul_measure MeasureTheory.snormEssSup_smul_measure
/-- Use `snorm_smul_measure_of_ne_top` instead. -/
private theorem snorm_smul_measure_of_ne_zero_of_ne_top {p : ℝ≥0∞} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) {f : α → F} (c : ℝ≥0∞) :
snorm f p (c • μ) = c ^ (1 / p).toReal • snorm f p μ := by
simp_rw [snorm_eq_snorm' hp_ne_zero hp_ne_top]
rw [snorm'_smul_measure ENNReal.toReal_nonneg]
congr
simp_rw [one_div]
rw [ENNReal.toReal_inv]
theorem snorm_smul_measure_of_ne_zero {p : ℝ≥0∞} {f : α → F} {c : ℝ≥0∞} (hc : c ≠ 0) :
snorm f p (c • μ) = c ^ (1 / p).toReal • snorm f p μ := by
by_cases hp0 : p = 0
· simp [hp0]
by_cases hp_top : p = ∞
· simp [hp_top, snormEssSup_smul_measure hc]
exact snorm_smul_measure_of_ne_zero_of_ne_top hp0 hp_top c
#align measure_theory.snorm_smul_measure_of_ne_zero MeasureTheory.snorm_smul_measure_of_ne_zero
theorem snorm_smul_measure_of_ne_top {p : ℝ≥0∞} (hp_ne_top : p ≠ ∞) {f : α → F} (c : ℝ≥0∞) :
snorm f p (c • μ) = c ^ (1 / p).toReal • snorm f p μ := by
by_cases hp0 : p = 0
· simp [hp0]
· exact snorm_smul_measure_of_ne_zero_of_ne_top hp0 hp_ne_top c
#align measure_theory.snorm_smul_measure_of_ne_top MeasureTheory.snorm_smul_measure_of_ne_top
theorem snorm_one_smul_measure {f : α → F} (c : ℝ≥0∞) : snorm f 1 (c • μ) = c * snorm f 1 μ := by
rw [@snorm_smul_measure_of_ne_top _ _ _ μ _ 1 (@ENNReal.coe_ne_top 1) f c]
simp
#align measure_theory.snorm_one_smul_measure MeasureTheory.snorm_one_smul_measure
theorem Memℒp.of_measure_le_smul {μ' : Measure α} (c : ℝ≥0∞) (hc : c ≠ ∞) (hμ'_le : μ' ≤ c • μ)
{f : α → E} (hf : Memℒp f p μ) : Memℒp f p μ' := by
refine ⟨hf.1.mono_ac (Measure.absolutelyContinuous_of_le_smul hμ'_le), ?_⟩
refine (snorm_mono_measure f hμ'_le).trans_lt ?_
by_cases hc0 : c = 0
· simp [hc0]
rw [snorm_smul_measure_of_ne_zero hc0, smul_eq_mul]
refine ENNReal.mul_lt_top ?_ hf.2.ne
simp [hc, hc0]
#align measure_theory.mem_ℒp.of_measure_le_smul MeasureTheory.Memℒp.of_measure_le_smul
theorem Memℒp.smul_measure {f : α → E} {c : ℝ≥0∞} (hf : Memℒp f p μ) (hc : c ≠ ∞) :
Memℒp f p (c • μ) :=
hf.of_measure_le_smul c hc le_rfl
#align measure_theory.mem_ℒp.smul_measure MeasureTheory.Memℒp.smul_measure
theorem snorm_one_add_measure (f : α → F) (μ ν : Measure α) :
snorm f 1 (μ + ν) = snorm f 1 μ + snorm f 1 ν := by
simp_rw [snorm_one_eq_lintegral_nnnorm]
rw [lintegral_add_measure _ μ ν]
#align measure_theory.snorm_one_add_measure MeasureTheory.snorm_one_add_measure
theorem snorm_le_add_measure_right (f : α → F) (μ ν : Measure α) {p : ℝ≥0∞} :
snorm f p μ ≤ snorm f p (μ + ν) :=
snorm_mono_measure f <| Measure.le_add_right <| le_refl _
#align measure_theory.snorm_le_add_measure_right MeasureTheory.snorm_le_add_measure_right
theorem snorm_le_add_measure_left (f : α → F) (μ ν : Measure α) {p : ℝ≥0∞} :
snorm f p ν ≤ snorm f p (μ + ν) :=
snorm_mono_measure f <| Measure.le_add_left <| le_refl _
#align measure_theory.snorm_le_add_measure_left MeasureTheory.snorm_le_add_measure_left
theorem Memℒp.left_of_add_measure {f : α → E} (h : Memℒp f p (μ + ν)) : Memℒp f p μ :=
h.mono_measure <| Measure.le_add_right <| le_refl _
#align measure_theory.mem_ℒp.left_of_add_measure MeasureTheory.Memℒp.left_of_add_measure
theorem Memℒp.right_of_add_measure {f : α → E} (h : Memℒp f p (μ + ν)) : Memℒp f p ν :=
h.mono_measure <| Measure.le_add_left <| le_refl _
#align measure_theory.mem_ℒp.right_of_add_measure MeasureTheory.Memℒp.right_of_add_measure
theorem Memℒp.norm {f : α → E} (h : Memℒp f p μ) : Memℒp (fun x => ‖f x‖) p μ :=
h.of_le h.aestronglyMeasurable.norm (eventually_of_forall fun x => by simp)
#align measure_theory.mem_ℒp.norm MeasureTheory.Memℒp.norm
theorem memℒp_norm_iff {f : α → E} (hf : AEStronglyMeasurable f μ) :
Memℒp (fun x => ‖f x‖) p μ ↔ Memℒp f p μ :=
⟨fun h => ⟨hf, by rw [← snorm_norm]; exact h.2⟩, fun h => h.norm⟩
#align measure_theory.mem_ℒp_norm_iff MeasureTheory.memℒp_norm_iff
theorem snorm'_eq_zero_of_ae_zero {f : α → F} (hq0_lt : 0 < q) (hf_zero : f =ᵐ[μ] 0) :
snorm' f q μ = 0 := by rw [snorm'_congr_ae hf_zero, snorm'_zero hq0_lt]
#align measure_theory.snorm'_eq_zero_of_ae_zero MeasureTheory.snorm'_eq_zero_of_ae_zero
theorem snorm'_eq_zero_of_ae_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) {f : α → F} (hf_zero : f =ᵐ[μ] 0) :
snorm' f q μ = 0 := by rw [snorm'_congr_ae hf_zero, snorm'_zero' hq0_ne hμ]
#align measure_theory.snorm'_eq_zero_of_ae_zero' MeasureTheory.snorm'_eq_zero_of_ae_zero'
theorem ae_eq_zero_of_snorm'_eq_zero {f : α → E} (hq0 : 0 ≤ q) (hf : AEStronglyMeasurable f μ)
(h : snorm' f q μ = 0) : f =ᵐ[μ] 0 := by
rw [snorm', ENNReal.rpow_eq_zero_iff] at h
cases h with
| inl h =>
rw [lintegral_eq_zero_iff' (hf.ennnorm.pow_const q)] at h
refine h.left.mono fun x hx => ?_
rw [Pi.zero_apply, ENNReal.rpow_eq_zero_iff] at hx
cases hx with
| inl hx =>
cases' hx with hx _
rwa [← ENNReal.coe_zero, ENNReal.coe_inj, nnnorm_eq_zero] at hx
| inr hx =>
exact absurd hx.left ENNReal.coe_ne_top
| inr h =>
exfalso
rw [one_div, inv_lt_zero] at h
exact hq0.not_lt h.right
#align measure_theory.ae_eq_zero_of_snorm'_eq_zero MeasureTheory.ae_eq_zero_of_snorm'_eq_zero
theorem snorm'_eq_zero_iff (hq0_lt : 0 < q) {f : α → E} (hf : AEStronglyMeasurable f μ) :
snorm' f q μ = 0 ↔ f =ᵐ[μ] 0 :=
⟨ae_eq_zero_of_snorm'_eq_zero (le_of_lt hq0_lt) hf, snorm'_eq_zero_of_ae_zero hq0_lt⟩
#align measure_theory.snorm'_eq_zero_iff MeasureTheory.snorm'_eq_zero_iff
theorem coe_nnnorm_ae_le_snormEssSup {_ : MeasurableSpace α} (f : α → F) (μ : Measure α) :
∀ᵐ x ∂μ, (‖f x‖₊ : ℝ≥0∞) ≤ snormEssSup f μ :=
ENNReal.ae_le_essSup fun x => (‖f x‖₊ : ℝ≥0∞)
#align measure_theory.coe_nnnorm_ae_le_snorm_ess_sup MeasureTheory.coe_nnnorm_ae_le_snormEssSup
@[simp]
theorem snormEssSup_eq_zero_iff {f : α → F} : snormEssSup f μ = 0 ↔ f =ᵐ[μ] 0 := by
simp [EventuallyEq, snormEssSup]
#align measure_theory.snorm_ess_sup_eq_zero_iff MeasureTheory.snormEssSup_eq_zero_iff
theorem snorm_eq_zero_iff {f : α → E} (hf : AEStronglyMeasurable f μ) (h0 : p ≠ 0) :
snorm f p μ = 0 ↔ f =ᵐ[μ] 0 := by
by_cases h_top : p = ∞
· rw [h_top, snorm_exponent_top, snormEssSup_eq_zero_iff]
rw [snorm_eq_snorm' h0 h_top]
exact snorm'_eq_zero_iff (ENNReal.toReal_pos h0 h_top) hf
#align measure_theory.snorm_eq_zero_iff MeasureTheory.snorm_eq_zero_iff
theorem ae_le_snormEssSup {f : α → F} : ∀ᵐ y ∂μ, ‖f y‖₊ ≤ snormEssSup f μ :=
ae_le_essSup
#align measure_theory.ae_le_snorm_ess_sup MeasureTheory.ae_le_snormEssSup
theorem meas_snormEssSup_lt {f : α → F} : μ { y | snormEssSup f μ < ‖f y‖₊ } = 0 :=
meas_essSup_lt
#align measure_theory.meas_snorm_ess_sup_lt MeasureTheory.meas_snormEssSup_lt
lemma snormEssSup_piecewise {s : Set α} (f g : α → E) [DecidablePred (· ∈ s)]
(hs : MeasurableSet s) :
snormEssSup (Set.piecewise s f g) μ
= max (snormEssSup f (μ.restrict s)) (snormEssSup g (μ.restrict sᶜ)) := by
simp only [snormEssSup, ← ENNReal.essSup_piecewise hs]
congr with x
by_cases hx : x ∈ s <;> simp [hx]
lemma snorm_top_piecewise {s : Set α} (f g : α → E) [DecidablePred (· ∈ s)]
(hs : MeasurableSet s) :
snorm (Set.piecewise s f g) ∞ μ
= max (snorm f ∞ (μ.restrict s)) (snorm g ∞ (μ.restrict sᶜ)) :=
snormEssSup_piecewise f g hs
section MapMeasure
variable {β : Type*} {mβ : MeasurableSpace β} {f : α → β} {g : β → E}
theorem snormEssSup_map_measure (hg : AEStronglyMeasurable g (Measure.map f μ))
(hf : AEMeasurable f μ) : snormEssSup g (Measure.map f μ) = snormEssSup (g ∘ f) μ :=
essSup_map_measure hg.ennnorm hf
#align measure_theory.snorm_ess_sup_map_measure MeasureTheory.snormEssSup_map_measure
theorem snorm_map_measure (hg : AEStronglyMeasurable g (Measure.map f μ)) (hf : AEMeasurable f μ) :
snorm g p (Measure.map f μ) = snorm (g ∘ f) p μ := by
by_cases hp_zero : p = 0
· simp only [hp_zero, snorm_exponent_zero]
by_cases hp_top : p = ∞
· simp_rw [hp_top, snorm_exponent_top]
exact snormEssSup_map_measure hg hf
simp_rw [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_top]
rw [lintegral_map' (hg.ennnorm.pow_const p.toReal) hf]
rfl
#align measure_theory.snorm_map_measure MeasureTheory.snorm_map_measure
theorem memℒp_map_measure_iff (hg : AEStronglyMeasurable g (Measure.map f μ))
(hf : AEMeasurable f μ) : Memℒp g p (Measure.map f μ) ↔ Memℒp (g ∘ f) p μ := by
simp [Memℒp, snorm_map_measure hg hf, hg.comp_aemeasurable hf, hg]
#align measure_theory.mem_ℒp_map_measure_iff MeasureTheory.memℒp_map_measure_iff
theorem Memℒp.comp_of_map (hg : Memℒp g p (Measure.map f μ)) (hf : AEMeasurable f μ) :
Memℒp (g ∘ f) p μ :=
(memℒp_map_measure_iff hg.aestronglyMeasurable hf).1 hg
theorem snorm_comp_measurePreserving {ν : MeasureTheory.Measure β} (hg : AEStronglyMeasurable g ν)
(hf : MeasurePreserving f μ ν) : snorm (g ∘ f) p μ = snorm g p ν :=
Eq.symm <| hf.map_eq ▸ snorm_map_measure (hf.map_eq ▸ hg) hf.aemeasurable
theorem AEEqFun.snorm_compMeasurePreserving {ν : MeasureTheory.Measure β} (g : β →ₘ[ν] E)
(hf : MeasurePreserving f μ ν) :
snorm (g.compMeasurePreserving f hf) p μ = snorm g p ν := by
rw [snorm_congr_ae (g.coeFn_compMeasurePreserving _)]
exact snorm_comp_measurePreserving g.aestronglyMeasurable hf
theorem Memℒp.comp_measurePreserving {ν : MeasureTheory.Measure β} (hg : Memℒp g p ν)
(hf : MeasurePreserving f μ ν) : Memℒp (g ∘ f) p μ :=
.comp_of_map (hf.map_eq.symm ▸ hg) hf.aemeasurable
theorem _root_.MeasurableEmbedding.snormEssSup_map_measure {g : β → F}
(hf : MeasurableEmbedding f) : snormEssSup g (Measure.map f μ) = snormEssSup (g ∘ f) μ :=
hf.essSup_map_measure
#align measurable_embedding.snorm_ess_sup_map_measure MeasurableEmbedding.snormEssSup_map_measure
theorem _root_.MeasurableEmbedding.snorm_map_measure {g : β → F} (hf : MeasurableEmbedding f) :
snorm g p (Measure.map f μ) = snorm (g ∘ f) p μ := by
by_cases hp_zero : p = 0
· simp only [hp_zero, snorm_exponent_zero]
by_cases hp : p = ∞
· simp_rw [hp, snorm_exponent_top]
exact hf.essSup_map_measure
· simp_rw [snorm_eq_lintegral_rpow_nnnorm hp_zero hp]
rw [hf.lintegral_map]
rfl
#align measurable_embedding.snorm_map_measure MeasurableEmbedding.snorm_map_measure
theorem _root_.MeasurableEmbedding.memℒp_map_measure_iff {g : β → F} (hf : MeasurableEmbedding f) :
Memℒp g p (Measure.map f μ) ↔ Memℒp (g ∘ f) p μ := by
simp_rw [Memℒp, hf.aestronglyMeasurable_map_iff, hf.snorm_map_measure]
#align measurable_embedding.mem_ℒp_map_measure_iff MeasurableEmbedding.memℒp_map_measure_iff
theorem _root_.MeasurableEquiv.memℒp_map_measure_iff (f : α ≃ᵐ β) {g : β → F} :
Memℒp g p (Measure.map f μ) ↔ Memℒp (g ∘ f) p μ :=
f.measurableEmbedding.memℒp_map_measure_iff
#align measurable_equiv.mem_ℒp_map_measure_iff MeasurableEquiv.memℒp_map_measure_iff
end MapMeasure
section Monotonicity
theorem snorm'_le_nnreal_smul_snorm'_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ≥0}
(h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) {p : ℝ} (hp : 0 < p) : snorm' f p μ ≤ c • snorm' g p μ := by
simp_rw [snorm']
rw [← ENNReal.rpow_le_rpow_iff hp, ENNReal.smul_def, smul_eq_mul,
ENNReal.mul_rpow_of_nonneg _ _ hp.le]
simp_rw [← ENNReal.rpow_mul, one_div, inv_mul_cancel hp.ne.symm, ENNReal.rpow_one,
ENNReal.coe_rpow_of_nonneg _ hp.le, ← lintegral_const_mul' _ _ ENNReal.coe_ne_top, ←
ENNReal.coe_mul]
apply lintegral_mono_ae
simp_rw [ENNReal.coe_le_coe, ← NNReal.mul_rpow, NNReal.rpow_le_rpow_iff hp]
exact h
#align measure_theory.snorm'_le_nnreal_smul_snorm'_of_ae_le_mul MeasureTheory.snorm'_le_nnreal_smul_snorm'_of_ae_le_mul
theorem snormEssSup_le_nnreal_smul_snormEssSup_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ≥0}
(h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : snormEssSup f μ ≤ c • snormEssSup g μ :=
calc
essSup (fun x => (‖f x‖₊ : ℝ≥0∞)) μ ≤ essSup (fun x => (↑(c * ‖g x‖₊) : ℝ≥0∞)) μ :=
essSup_mono_ae <| h.mono fun x hx => ENNReal.coe_le_coe.mpr hx
_ = essSup (fun x => (c * ‖g x‖₊ : ℝ≥0∞)) μ := by simp_rw [ENNReal.coe_mul]
_ = c • essSup (fun x => (‖g x‖₊ : ℝ≥0∞)) μ := ENNReal.essSup_const_mul
#align measure_theory.snorm_ess_sup_le_nnreal_smul_snorm_ess_sup_of_ae_le_mul MeasureTheory.snormEssSup_le_nnreal_smul_snormEssSup_of_ae_le_mul
theorem snorm_le_nnreal_smul_snorm_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ≥0}
(h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) (p : ℝ≥0∞) : snorm f p μ ≤ c • snorm g p μ := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· rw [h_top]
exact snormEssSup_le_nnreal_smul_snormEssSup_of_ae_le_mul h
simp_rw [snorm_eq_snorm' h0 h_top]
exact snorm'_le_nnreal_smul_snorm'_of_ae_le_mul h (ENNReal.toReal_pos h0 h_top)
#align measure_theory.snorm_le_nnreal_smul_snorm_of_ae_le_mul MeasureTheory.snorm_le_nnreal_smul_snorm_of_ae_le_mul
-- TODO: add the whole family of lemmas?
private theorem le_mul_iff_eq_zero_of_nonneg_of_neg_of_nonneg {α} [LinearOrderedSemiring α]
{a b c : α} (ha : 0 ≤ a) (hb : b < 0) (hc : 0 ≤ c) : a ≤ b * c ↔ a = 0 ∧ c = 0 := by
constructor
· intro h
exact
⟨(h.trans (mul_nonpos_of_nonpos_of_nonneg hb.le hc)).antisymm ha,
(nonpos_of_mul_nonneg_right (ha.trans h) hb).antisymm hc⟩
· rintro ⟨rfl, rfl⟩
rw [mul_zero]
/-- When `c` is negative, `‖f x‖ ≤ c * ‖g x‖` is nonsense and forces both `f` and `g` to have an
`snorm` of `0`. -/
| Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean | 911 | 917 | theorem snorm_eq_zero_and_zero_of_ae_le_mul_neg {f : α → F} {g : α → G} {c : ℝ}
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) (hc : c < 0) (p : ℝ≥0∞) :
snorm f p μ = 0 ∧ snorm g p μ = 0 := by |
simp_rw [le_mul_iff_eq_zero_of_nonneg_of_neg_of_nonneg (norm_nonneg _) hc (norm_nonneg _),
norm_eq_zero, eventually_and] at h
change f =ᵐ[μ] 0 ∧ g =ᵐ[μ] 0 at h
simp [snorm_congr_ae h.1, snorm_congr_ae h.2]
|
/-
Copyright (c) 2017 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.Data.PFunctor.Univariate.Basic
#align_import data.pfunctor.univariate.M from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1"
/-!
# M-types
M types are potentially infinite tree-like structures. They are defined
as the greatest fixpoint of a polynomial functor.
-/
universe u v w
open Nat Function
open List
variable (F : PFunctor.{u})
-- Porting note: the ♯ tactic is never used
-- local prefix:0 "♯" => cast (by first |simp [*]|cc|solve_by_elim)
namespace PFunctor
namespace Approx
/-- `CofixA F n` is an `n` level approximation of an M-type -/
inductive CofixA : ℕ → Type u
| continue : CofixA 0
| intro {n} : ∀ a, (F.B a → CofixA n) → CofixA (succ n)
#align pfunctor.approx.cofix_a PFunctor.Approx.CofixA
/-- default inhabitant of `CofixA` -/
protected def CofixA.default [Inhabited F.A] : ∀ n, CofixA F n
| 0 => CofixA.continue
| succ n => CofixA.intro default fun _ => CofixA.default n
#align pfunctor.approx.cofix_a.default PFunctor.Approx.CofixA.default
instance [Inhabited F.A] {n} : Inhabited (CofixA F n) :=
⟨CofixA.default F n⟩
theorem cofixA_eq_zero : ∀ x y : CofixA F 0, x = y
| CofixA.continue, CofixA.continue => rfl
#align pfunctor.approx.cofix_a_eq_zero PFunctor.Approx.cofixA_eq_zero
variable {F}
/-- The label of the root of the tree for a non-trivial
approximation of the cofix of a pfunctor.
-/
def head' : ∀ {n}, CofixA F (succ n) → F.A
| _, CofixA.intro i _ => i
#align pfunctor.approx.head' PFunctor.Approx.head'
/-- for a non-trivial approximation, return all the subtrees of the root -/
def children' : ∀ {n} (x : CofixA F (succ n)), F.B (head' x) → CofixA F n
| _, CofixA.intro _ f => f
#align pfunctor.approx.children' PFunctor.Approx.children'
theorem approx_eta {n : ℕ} (x : CofixA F (n + 1)) : x = CofixA.intro (head' x) (children' x) := by
cases x; rfl
#align pfunctor.approx.approx_eta PFunctor.Approx.approx_eta
/-- Relation between two approximations of the cofix of a pfunctor
that state they both contain the same data until one of them is truncated -/
inductive Agree : ∀ {n : ℕ}, CofixA F n → CofixA F (n + 1) → Prop
| continu (x : CofixA F 0) (y : CofixA F 1) : Agree x y
| intro {n} {a} (x : F.B a → CofixA F n) (x' : F.B a → CofixA F (n + 1)) :
(∀ i : F.B a, Agree (x i) (x' i)) → Agree (CofixA.intro a x) (CofixA.intro a x')
#align pfunctor.approx.agree PFunctor.Approx.Agree
/-- Given an infinite series of approximations `approx`,
`AllAgree approx` states that they are all consistent with each other.
-/
def AllAgree (x : ∀ n, CofixA F n) :=
∀ n, Agree (x n) (x (succ n))
#align pfunctor.approx.all_agree PFunctor.Approx.AllAgree
@[simp]
theorem agree_trival {x : CofixA F 0} {y : CofixA F 1} : Agree x y := by constructor
#align pfunctor.approx.agree_trival PFunctor.Approx.agree_trival
theorem agree_children {n : ℕ} (x : CofixA F (succ n)) (y : CofixA F (succ n + 1)) {i j}
(h₀ : HEq i j) (h₁ : Agree x y) : Agree (children' x i) (children' y j) := by
cases' h₁ with _ _ _ _ _ _ hagree; cases h₀
apply hagree
#align pfunctor.approx.agree_children PFunctor.Approx.agree_children
/-- `truncate a` turns `a` into a more limited approximation -/
def truncate : ∀ {n : ℕ}, CofixA F (n + 1) → CofixA F n
| 0, CofixA.intro _ _ => CofixA.continue
| succ _, CofixA.intro i f => CofixA.intro i <| truncate ∘ f
#align pfunctor.approx.truncate PFunctor.Approx.truncate
theorem truncate_eq_of_agree {n : ℕ} (x : CofixA F n) (y : CofixA F (succ n)) (h : Agree x y) :
truncate y = x := by
induction n <;> cases x <;> cases y
· rfl
· -- cases' h with _ _ _ _ _ h₀ h₁
cases h
simp only [truncate, Function.comp, true_and_iff, eq_self_iff_true, heq_iff_eq]
-- Porting note: used to be `ext y`
rename_i n_ih a f y h₁
suffices (fun x => truncate (y x)) = f
by simp [this]
funext y
apply n_ih
apply h₁
#align pfunctor.approx.truncate_eq_of_agree PFunctor.Approx.truncate_eq_of_agree
variable {X : Type w}
variable (f : X → F X)
/-- `sCorec f i n` creates an approximation of height `n`
of the final coalgebra of `f` -/
def sCorec : X → ∀ n, CofixA F n
| _, 0 => CofixA.continue
| j, succ _ => CofixA.intro (f j).1 fun i => sCorec ((f j).2 i) _
#align pfunctor.approx.s_corec PFunctor.Approx.sCorec
theorem P_corec (i : X) (n : ℕ) : Agree (sCorec f i n) (sCorec f i (succ n)) := by
induction' n with n n_ih generalizing i
constructor
cases' f i with y g
constructor
introv
apply n_ih
set_option linter.uppercaseLean3 false in
#align pfunctor.approx.P_corec PFunctor.Approx.P_corec
/-- `Path F` provides indices to access internal nodes in `Corec F` -/
def Path (F : PFunctor.{u}) :=
List F.Idx
#align pfunctor.approx.path PFunctor.Approx.Path
instance Path.inhabited : Inhabited (Path F) :=
⟨[]⟩
#align pfunctor.approx.path.inhabited PFunctor.Approx.Path.inhabited
open List Nat
instance CofixA.instSubsingleton : Subsingleton (CofixA F 0) :=
⟨by rintro ⟨⟩ ⟨⟩; rfl⟩
theorem head_succ' (n m : ℕ) (x : ∀ n, CofixA F n) (Hconsistent : AllAgree x) :
head' (x (succ n)) = head' (x (succ m)) := by
suffices ∀ n, head' (x (succ n)) = head' (x 1) by simp [this]
clear m n
intro n
cases' h₀ : x (succ n) with _ i₀ f₀
cases' h₁ : x 1 with _ i₁ f₁
dsimp only [head']
induction' n with n n_ih
· rw [h₁] at h₀
cases h₀
trivial
· have H := Hconsistent (succ n)
cases' h₂ : x (succ n) with _ i₂ f₂
rw [h₀, h₂] at H
apply n_ih (truncate ∘ f₀)
rw [h₂]
cases' H with _ _ _ _ _ _ hagree
congr
funext j
dsimp only [comp_apply]
rw [truncate_eq_of_agree]
apply hagree
#align pfunctor.approx.head_succ' PFunctor.Approx.head_succ'
end Approx
open Approx
/-- Internal definition for `M`. It is needed to avoid name clashes
between `M.mk` and `M.cases_on` and the declarations generated for
the structure -/
structure MIntl where
/-- An `n`-th level approximation, for each depth `n` -/
approx : ∀ n, CofixA F n
/-- Each approximation agrees with the next -/
consistent : AllAgree approx
set_option linter.uppercaseLean3 false in
#align pfunctor.M_intl PFunctor.MIntl
/-- For polynomial functor `F`, `M F` is its final coalgebra -/
def M :=
MIntl F
set_option linter.uppercaseLean3 false in
#align pfunctor.M PFunctor.M
theorem M.default_consistent [Inhabited F.A] : ∀ n, Agree (default : CofixA F n) default
| 0 => Agree.continu _ _
| succ n => Agree.intro _ _ fun _ => M.default_consistent n
set_option linter.uppercaseLean3 false in
#align pfunctor.M.default_consistent PFunctor.M.default_consistent
instance M.inhabited [Inhabited F.A] : Inhabited (M F) :=
⟨{ approx := default
consistent := M.default_consistent _ }⟩
set_option linter.uppercaseLean3 false in
#align pfunctor.M.inhabited PFunctor.M.inhabited
instance MIntl.inhabited [Inhabited F.A] : Inhabited (MIntl F) :=
show Inhabited (M F) by infer_instance
set_option linter.uppercaseLean3 false in
#align pfunctor.M_intl.inhabited PFunctor.MIntl.inhabited
namespace M
theorem ext' (x y : M F) (H : ∀ i : ℕ, x.approx i = y.approx i) : x = y := by
cases x
cases y
congr with n
apply H
set_option linter.uppercaseLean3 false in
#align pfunctor.M.ext' PFunctor.M.ext'
variable {X : Type*}
variable (f : X → F X)
variable {F}
/-- Corecursor for the M-type defined by `F`. -/
protected def corec (i : X) : M F where
approx := sCorec f i
consistent := P_corec _ _
set_option linter.uppercaseLean3 false in
#align pfunctor.M.corec PFunctor.M.corec
/-- given a tree generated by `F`, `head` gives us the first piece of data
it contains -/
def head (x : M F) :=
head' (x.1 1)
set_option linter.uppercaseLean3 false in
#align pfunctor.M.head PFunctor.M.head
/-- return all the subtrees of the root of a tree `x : M F` -/
def children (x : M F) (i : F.B (head x)) : M F :=
let H := fun n : ℕ => @head_succ' _ n 0 x.1 x.2
{ approx := fun n => children' (x.1 _) (cast (congr_arg _ <| by simp only [head, H]) i)
consistent := by
intro n
have P' := x.2 (succ n)
apply agree_children _ _ _ P'
trans i
· apply cast_heq
symm
apply cast_heq }
set_option linter.uppercaseLean3 false in
#align pfunctor.M.children PFunctor.M.children
/-- select a subtree using an `i : F.Idx` or return an arbitrary tree if
`i` designates no subtree of `x` -/
def ichildren [Inhabited (M F)] [DecidableEq F.A] (i : F.Idx) (x : M F) : M F :=
if H' : i.1 = head x then children x (cast (congr_arg _ <| by simp only [head, H']) i.2)
else default
set_option linter.uppercaseLean3 false in
#align pfunctor.M.ichildren PFunctor.M.ichildren
theorem head_succ (n m : ℕ) (x : M F) : head' (x.approx (succ n)) = head' (x.approx (succ m)) :=
head_succ' n m _ x.consistent
set_option linter.uppercaseLean3 false in
#align pfunctor.M.head_succ PFunctor.M.head_succ
theorem head_eq_head' : ∀ (x : M F) (n : ℕ), head x = head' (x.approx <| n + 1)
| ⟨_, h⟩, _ => head_succ' _ _ _ h
set_option linter.uppercaseLean3 false in
#align pfunctor.M.head_eq_head' PFunctor.M.head_eq_head'
theorem head'_eq_head : ∀ (x : M F) (n : ℕ), head' (x.approx <| n + 1) = head x
| ⟨_, h⟩, _ => head_succ' _ _ _ h
set_option linter.uppercaseLean3 false in
#align pfunctor.M.head'_eq_head PFunctor.M.head'_eq_head
theorem truncate_approx (x : M F) (n : ℕ) : truncate (x.approx <| n + 1) = x.approx n :=
truncate_eq_of_agree _ _ (x.consistent _)
set_option linter.uppercaseLean3 false in
#align pfunctor.M.truncate_approx PFunctor.M.truncate_approx
/-- unfold an M-type -/
def dest : M F → F (M F)
| x => ⟨head x, fun i => children x i⟩
set_option linter.uppercaseLean3 false in
#align pfunctor.M.dest PFunctor.M.dest
namespace Approx
/-- generates the approximations needed for `M.mk` -/
protected def sMk (x : F (M F)) : ∀ n, CofixA F n
| 0 => CofixA.continue
| succ n => CofixA.intro x.1 fun i => (x.2 i).approx n
set_option linter.uppercaseLean3 false in
#align pfunctor.M.approx.s_mk PFunctor.M.Approx.sMk
protected theorem P_mk (x : F (M F)) : AllAgree (Approx.sMk x)
| 0 => by constructor
| succ n => by
constructor
introv
apply (x.2 i).consistent
set_option linter.uppercaseLean3 false in
#align pfunctor.M.approx.P_mk PFunctor.M.Approx.P_mk
end Approx
/-- constructor for M-types -/
protected def mk (x : F (M F)) : M F where
approx := Approx.sMk x
consistent := Approx.P_mk x
set_option linter.uppercaseLean3 false in
#align pfunctor.M.mk PFunctor.M.mk
/-- `Agree' n` relates two trees of type `M F` that
are the same up to depth `n` -/
inductive Agree' : ℕ → M F → M F → Prop
| trivial (x y : M F) : Agree' 0 x y
| step {n : ℕ} {a} (x y : F.B a → M F) {x' y'} :
x' = M.mk ⟨a, x⟩ → y' = M.mk ⟨a, y⟩ → (∀ i, Agree' n (x i) (y i)) → Agree' (succ n) x' y'
set_option linter.uppercaseLean3 false in
#align pfunctor.M.agree' PFunctor.M.Agree'
@[simp]
theorem dest_mk (x : F (M F)) : dest (M.mk x) = x := rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.dest_mk PFunctor.M.dest_mk
@[simp]
theorem mk_dest (x : M F) : M.mk (dest x) = x := by
apply ext'
intro n
dsimp only [M.mk]
induction' n with n
· apply @Subsingleton.elim _ CofixA.instSubsingleton
dsimp only [Approx.sMk, dest, head]
cases' h : x.approx (succ n) with _ hd ch
have h' : hd = head' (x.approx 1) := by
rw [← head_succ' n, h, head']
· split
injections
· apply x.consistent
revert ch
rw [h']
intros ch h
congr
ext a
dsimp only [children]
generalize hh : cast _ a = a''
rw [cast_eq_iff_heq] at hh
revert a''
rw [h]
intros _ hh
cases hh
rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.mk_dest PFunctor.M.mk_dest
theorem mk_inj {x y : F (M F)} (h : M.mk x = M.mk y) : x = y := by rw [← dest_mk x, h, dest_mk]
set_option linter.uppercaseLean3 false in
#align pfunctor.M.mk_inj PFunctor.M.mk_inj
/-- destructor for M-types -/
protected def cases {r : M F → Sort w} (f : ∀ x : F (M F), r (M.mk x)) (x : M F) : r x :=
suffices r (M.mk (dest x)) by
rw [← mk_dest x]
exact this
f _
set_option linter.uppercaseLean3 false in
#align pfunctor.M.cases PFunctor.M.cases
/-- destructor for M-types -/
protected def casesOn {r : M F → Sort w} (x : M F) (f : ∀ x : F (M F), r (M.mk x)) : r x :=
M.cases f x
set_option linter.uppercaseLean3 false in
#align pfunctor.M.cases_on PFunctor.M.casesOn
/-- destructor for M-types, similar to `casesOn` but also
gives access directly to the root and subtrees on an M-type -/
protected def casesOn' {r : M F → Sort w} (x : M F) (f : ∀ a f, r (M.mk ⟨a, f⟩)) : r x :=
M.casesOn x (fun ⟨a, g⟩ => f a g)
set_option linter.uppercaseLean3 false in
#align pfunctor.M.cases_on' PFunctor.M.casesOn'
theorem approx_mk (a : F.A) (f : F.B a → M F) (i : ℕ) :
(M.mk ⟨a, f⟩).approx (succ i) = CofixA.intro a fun j => (f j).approx i :=
rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.approx_mk PFunctor.M.approx_mk
@[simp]
theorem agree'_refl {n : ℕ} (x : M F) : Agree' n x x := by
induction' n with _ n_ih generalizing x <;>
induction x using PFunctor.M.casesOn' <;> constructor <;> try rfl
intros
apply n_ih
set_option linter.uppercaseLean3 false in
#align pfunctor.M.agree'_refl PFunctor.M.agree'_refl
theorem agree_iff_agree' {n : ℕ} (x y : M F) :
Agree (x.approx n) (y.approx <| n + 1) ↔ Agree' n x y := by
constructor <;> intro h
· induction' n with _ n_ih generalizing x y
· constructor
· induction x using PFunctor.M.casesOn'
induction y using PFunctor.M.casesOn'
simp only [approx_mk] at h
cases' h with _ _ _ _ _ _ hagree
constructor <;> try rfl
intro i
apply n_ih
apply hagree
· induction' n with _ n_ih generalizing x y
· constructor
· cases' h with _ _ _ a x' y'
induction' x using PFunctor.M.casesOn' with x_a x_f
induction' y using PFunctor.M.casesOn' with y_a y_f
simp only [approx_mk]
have h_a_1 := mk_inj ‹M.mk ⟨x_a, x_f⟩ = M.mk ⟨a, x'⟩›
cases h_a_1
replace h_a_2 := mk_inj ‹M.mk ⟨y_a, y_f⟩ = M.mk ⟨a, y'⟩›
cases h_a_2
constructor
intro i
apply n_ih
simp [*]
set_option linter.uppercaseLean3 false in
#align pfunctor.M.agree_iff_agree' PFunctor.M.agree_iff_agree'
@[simp]
theorem cases_mk {r : M F → Sort*} (x : F (M F)) (f : ∀ x : F (M F), r (M.mk x)) :
PFunctor.M.cases f (M.mk x) = f x := by
dsimp only [M.mk, PFunctor.M.cases, dest, head, Approx.sMk, head']
cases x; dsimp only [Approx.sMk]
simp only [Eq.mpr]
apply congrFun
rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.cases_mk PFunctor.M.cases_mk
@[simp]
theorem casesOn_mk {r : M F → Sort*} (x : F (M F)) (f : ∀ x : F (M F), r (M.mk x)) :
PFunctor.M.casesOn (M.mk x) f = f x :=
cases_mk x f
set_option linter.uppercaseLean3 false in
#align pfunctor.M.cases_on_mk PFunctor.M.casesOn_mk
@[simp]
theorem casesOn_mk' {r : M F → Sort*} {a} (x : F.B a → M F)
(f : ∀ (a) (f : F.B a → M F), r (M.mk ⟨a, f⟩)) :
PFunctor.M.casesOn' (M.mk ⟨a, x⟩) f = f a x :=
@cases_mk F r ⟨a, x⟩ (fun ⟨a, g⟩ => f a g)
set_option linter.uppercaseLean3 false in
#align pfunctor.M.cases_on_mk' PFunctor.M.casesOn_mk'
/-- `IsPath p x` tells us if `p` is a valid path through `x` -/
inductive IsPath : Path F → M F → Prop
| nil (x : M F) : IsPath [] x
|
cons (xs : Path F) {a} (x : M F) (f : F.B a → M F) (i : F.B a) :
x = M.mk ⟨a, f⟩ → IsPath xs (f i) → IsPath (⟨a, i⟩ :: xs) x
set_option linter.uppercaseLean3 false in
#align pfunctor.M.is_path PFunctor.M.IsPath
theorem isPath_cons {xs : Path F} {a a'} {f : F.B a → M F} {i : F.B a'} :
IsPath (⟨a', i⟩ :: xs) (M.mk ⟨a, f⟩) → a = a' := by
generalize h : M.mk ⟨a, f⟩ = x
rintro (_ | ⟨_, _, _, _, rfl, _⟩)
cases mk_inj h
rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.is_path_cons PFunctor.M.isPath_cons
theorem isPath_cons' {xs : Path F} {a} {f : F.B a → M F} {i : F.B a} :
IsPath (⟨a, i⟩ :: xs) (M.mk ⟨a, f⟩) → IsPath xs (f i) := by
generalize h : M.mk ⟨a, f⟩ = x
rintro (_ | ⟨_, _, _, _, rfl, hp⟩)
cases mk_inj h
exact hp
set_option linter.uppercaseLean3 false in
#align pfunctor.M.is_path_cons' PFunctor.M.isPath_cons'
/-- follow a path through a value of `M F` and return the subtree
found at the end of the path if it is a valid path for that value and
return a default tree -/
def isubtree [DecidableEq F.A] [Inhabited (M F)] : Path F → M F → M F
| [], x => x
| ⟨a, i⟩ :: ps, x =>
PFunctor.M.casesOn' (r := fun _ => M F) x (fun a' f =>
if h : a = a' then
isubtree ps (f <| cast (by rw [h]) i)
else
default (α := M F)
)
set_option linter.uppercaseLean3 false in
#align pfunctor.M.isubtree PFunctor.M.isubtree
/-- similar to `isubtree` but returns the data at the end of the path instead
of the whole subtree -/
def iselect [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) : M F → F.A := fun x : M F =>
head <| isubtree ps x
set_option linter.uppercaseLean3 false in
#align pfunctor.M.iselect PFunctor.M.iselect
theorem iselect_eq_default [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) (x : M F)
(h : ¬IsPath ps x) : iselect ps x = head default := by
induction' ps with ps_hd ps_tail ps_ih generalizing x
· exfalso
apply h
constructor
· cases' ps_hd with a i
induction' x using PFunctor.M.casesOn' with x_a x_f
simp only [iselect, isubtree] at ps_ih ⊢
by_cases h'' : a = x_a
· subst x_a
simp only [dif_pos, eq_self_iff_true, casesOn_mk']
rw [ps_ih]
intro h'
apply h
constructor <;> try rfl
apply h'
· simp [*]
set_option linter.uppercaseLean3 false in
#align pfunctor.M.iselect_eq_default PFunctor.M.iselect_eq_default
@[simp]
theorem head_mk (x : F (M F)) : head (M.mk x) = x.1 :=
Eq.symm <|
calc
x.1 = (dest (M.mk x)).1 := by rw [dest_mk]
_ = head (M.mk x) := rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.head_mk PFunctor.M.head_mk
theorem children_mk {a} (x : F.B a → M F) (i : F.B (head (M.mk ⟨a, x⟩))) :
children (M.mk ⟨a, x⟩) i = x (cast (by rw [head_mk]) i) := by apply ext'; intro n; rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.children_mk PFunctor.M.children_mk
@[simp]
theorem ichildren_mk [DecidableEq F.A] [Inhabited (M F)] (x : F (M F)) (i : F.Idx) :
ichildren i (M.mk x) = x.iget i := by
dsimp only [ichildren, PFunctor.Obj.iget]
congr with h
set_option linter.uppercaseLean3 false in
#align pfunctor.M.ichildren_mk PFunctor.M.ichildren_mk
@[simp]
theorem isubtree_cons [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) {a} (f : F.B a → M F)
{i : F.B a} : isubtree (⟨_, i⟩ :: ps) (M.mk ⟨a, f⟩) = isubtree ps (f i) := by
simp only [isubtree, ichildren_mk, PFunctor.Obj.iget, dif_pos, isubtree, M.casesOn_mk']; rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.isubtree_cons PFunctor.M.isubtree_cons
@[simp]
theorem iselect_nil [DecidableEq F.A] [Inhabited (M F)] {a} (f : F.B a → M F) :
iselect nil (M.mk ⟨a, f⟩) = a := rfl
set_option linter.uppercaseLean3 false in
#align pfunctor.M.iselect_nil PFunctor.M.iselect_nil
@[simp]
theorem iselect_cons [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) {a} (f : F.B a → M F) {i} :
iselect (⟨a, i⟩ :: ps) (M.mk ⟨a, f⟩) = iselect ps (f i) := by simp only [iselect, isubtree_cons]
set_option linter.uppercaseLean3 false in
#align pfunctor.M.iselect_cons PFunctor.M.iselect_cons
theorem corec_def {X} (f : X → F X) (x₀ : X) : M.corec f x₀ = M.mk (F.map (M.corec f) (f x₀)) := by
dsimp only [M.corec, M.mk]
congr with n
cases' n with n
· dsimp only [sCorec, Approx.sMk]
· dsimp only [sCorec, Approx.sMk]
cases f x₀
dsimp only [PFunctor.map]
congr
set_option linter.uppercaseLean3 false in
#align pfunctor.M.corec_def PFunctor.M.corec_def
| Mathlib/Data/PFunctor/Univariate/M.lean | 585 | 618 | theorem ext_aux [Inhabited (M F)] [DecidableEq F.A] {n : ℕ} (x y z : M F) (hx : Agree' n z x)
(hy : Agree' n z y) (hrec : ∀ ps : Path F, n = ps.length → iselect ps x = iselect ps y) :
x.approx (n + 1) = y.approx (n + 1) := by |
induction' n with n n_ih generalizing x y z
· specialize hrec [] rfl
induction x using PFunctor.M.casesOn'
induction y using PFunctor.M.casesOn'
simp only [iselect_nil] at hrec
subst hrec
simp only [approx_mk, true_and_iff, eq_self_iff_true, heq_iff_eq, zero_eq, CofixA.intro.injEq,
heq_eq_eq, eq_iff_true_of_subsingleton, and_self]
· cases hx
cases hy
induction x using PFunctor.M.casesOn'
induction y using PFunctor.M.casesOn'
subst z
iterate 3 (have := mk_inj ‹_›; cases this)
rename_i n_ih a f₃ f₂ hAgree₂ _ _ h₂ _ _ f₁ h₁ hAgree₁ clr
simp only [approx_mk, true_and_iff, eq_self_iff_true, heq_iff_eq]
have := mk_inj h₁
cases this; clear h₁
have := mk_inj h₂
cases this; clear h₂
congr
ext i
apply n_ih
· solve_by_elim
· solve_by_elim
introv h
specialize hrec (⟨_, i⟩ :: ps) (congr_arg _ h)
simp only [iselect_cons] at hrec
exact hrec
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.Ring.Regular
import Mathlib.Tactic.Common
#align_import algebra.gcd_monoid.basic from "leanprover-community/mathlib"@"550b58538991c8977703fdeb7c9d51a5aa27df11"
/-!
# Monoids with normalization functions, `gcd`, and `lcm`
This file defines extra structures on `CancelCommMonoidWithZero`s, including `IsDomain`s.
## Main Definitions
* `NormalizationMonoid`
* `GCDMonoid`
* `NormalizedGCDMonoid`
* `gcdMonoid_of_gcd`, `gcdMonoid_of_exists_gcd`, `normalizedGCDMonoid_of_gcd`,
`normalizedGCDMonoid_of_exists_gcd`
* `gcdMonoid_of_lcm`, `gcdMonoid_of_exists_lcm`, `normalizedGCDMonoid_of_lcm`,
`normalizedGCDMonoid_of_exists_lcm`
For the `NormalizedGCDMonoid` instances on `ℕ` and `ℤ`, see `Mathlib.Algebra.GCDMonoid.Nat`.
## Implementation Notes
* `NormalizationMonoid` is defined by assigning to each element a `normUnit` such that multiplying
by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This
definition as currently implemented does casework on `0`.
* `GCDMonoid` contains the definitions of `gcd` and `lcm` with the usual properties. They are
both determined up to a unit.
* `NormalizedGCDMonoid` extends `NormalizationMonoid`, so the `gcd` and `lcm` are always
normalized. This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains,
and monoids without zero.
* `gcdMonoid_of_gcd` and `normalizedGCDMonoid_of_gcd` noncomputably construct a `GCDMonoid`
(resp. `NormalizedGCDMonoid`) structure just from the `gcd` and its properties.
* `gcdMonoid_of_exists_gcd` and `normalizedGCDMonoid_of_exists_gcd` noncomputably construct a
`GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements
have a (not necessarily normalized) `gcd`.
* `gcdMonoid_of_lcm` and `normalizedGCDMonoid_of_lcm` noncomputably construct a `GCDMonoid`
(resp. `NormalizedGCDMonoid`) structure just from the `lcm` and its properties.
* `gcdMonoid_of_exists_lcm` and `normalizedGCDMonoid_of_exists_lcm` noncomputably construct a
`GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements
have a (not necessarily normalized) `lcm`.
## TODO
* Port GCD facts about nats, definition of coprime
* Generalize normalization monoids to commutative (cancellative) monoids with or without zero
## Tags
divisibility, gcd, lcm, normalize
-/
variable {α : Type*}
-- Porting note: mathlib3 had a `@[protect_proj]` here, but adding `protected` to all the fields
-- adds unnecessary clutter to later code
/-- Normalization monoid: multiplying with `normUnit` gives a normal form for associated
elements. -/
class NormalizationMonoid (α : Type*) [CancelCommMonoidWithZero α] where
/-- `normUnit` assigns to each element of the monoid a unit of the monoid. -/
normUnit : α → αˣ
/-- The proposition that `normUnit` maps `0` to the identity. -/
normUnit_zero : normUnit 0 = 1
/-- The proposition that `normUnit` respects multiplication of non-zero elements. -/
normUnit_mul : ∀ {a b}, a ≠ 0 → b ≠ 0 → normUnit (a * b) = normUnit a * normUnit b
/-- The proposition that `normUnit` maps units to their inverses. -/
normUnit_coe_units : ∀ u : αˣ, normUnit u = u⁻¹
#align normalization_monoid NormalizationMonoid
export NormalizationMonoid (normUnit normUnit_zero normUnit_mul normUnit_coe_units)
attribute [simp] normUnit_coe_units normUnit_zero normUnit_mul
section NormalizationMonoid
variable [CancelCommMonoidWithZero α] [NormalizationMonoid α]
@[simp]
theorem normUnit_one : normUnit (1 : α) = 1 :=
normUnit_coe_units 1
#align norm_unit_one normUnit_one
-- Porting note (#11083): quite slow. Improve performance?
/-- Chooses an element of each associate class, by multiplying by `normUnit` -/
def normalize : α →*₀ α where
toFun x := x * normUnit x
map_zero' := by
simp only [normUnit_zero]
exact mul_one (0:α)
map_one' := by dsimp only; rw [normUnit_one, one_mul]; rfl
map_mul' x y :=
(by_cases fun hx : x = 0 => by dsimp only; rw [hx, zero_mul, zero_mul, zero_mul]) fun hx =>
(by_cases fun hy : y = 0 => by dsimp only; rw [hy, mul_zero, zero_mul, mul_zero]) fun hy => by
simp only [normUnit_mul hx hy, Units.val_mul]; simp only [mul_assoc, mul_left_comm y]
#align normalize normalize
theorem associated_normalize (x : α) : Associated x (normalize x) :=
⟨_, rfl⟩
#align associated_normalize associated_normalize
theorem normalize_associated (x : α) : Associated (normalize x) x :=
(associated_normalize _).symm
#align normalize_associated normalize_associated
theorem associated_normalize_iff {x y : α} : Associated x (normalize y) ↔ Associated x y :=
⟨fun h => h.trans (normalize_associated y), fun h => h.trans (associated_normalize y)⟩
#align associated_normalize_iff associated_normalize_iff
theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Associated x y :=
⟨fun h => (associated_normalize _).trans h, fun h => (normalize_associated _).trans h⟩
#align normalize_associated_iff normalize_associated_iff
theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x :=
Associates.mk_eq_mk_iff_associated.2 (normalize_associated _)
#align associates.mk_normalize Associates.mk_normalize
@[simp]
theorem normalize_apply (x : α) : normalize x = x * normUnit x :=
rfl
#align normalize_apply normalize_apply
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem normalize_zero : normalize (0 : α) = 0 :=
normalize.map_zero
#align normalize_zero normalize_zero
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem normalize_one : normalize (1 : α) = 1 :=
normalize.map_one
#align normalize_one normalize_one
| Mathlib/Algebra/GCDMonoid/Basic.lean | 148 | 148 | theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by | simp
|
/-
Copyright (c) 2023 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Integral.Bochner
/-!
# Integration of bounded continuous functions
In this file, some results are collected about integrals of bounded continuous functions. They are
mostly specializations of results in general integration theory, but they are used directly in this
specialized form in some other files, in particular in those related to the topology of weak
convergence of probability measures and finite measures.
-/
open MeasureTheory Filter
open scoped ENNReal NNReal BoundedContinuousFunction Topology
namespace BoundedContinuousFunction
section NNRealValued
lemma apply_le_nndist_zero {X : Type*} [TopologicalSpace X] (f : X →ᵇ ℝ≥0) (x : X) :
f x ≤ nndist 0 f := by
convert nndist_coe_le_nndist x
simp only [coe_zero, Pi.zero_apply, NNReal.nndist_zero_eq_val]
variable {X : Type*} [MeasurableSpace X] [TopologicalSpace X] [OpensMeasurableSpace X]
lemma lintegral_le_edist_mul (f : X →ᵇ ℝ≥0) (μ : Measure X) :
(∫⁻ x, f x ∂μ) ≤ edist 0 f * (μ Set.univ) :=
le_trans (lintegral_mono (fun x ↦ ENNReal.coe_le_coe.mpr (f.apply_le_nndist_zero x))) (by simp)
theorem measurable_coe_ennreal_comp (f : X →ᵇ ℝ≥0) :
Measurable fun x ↦ (f x : ℝ≥0∞) :=
measurable_coe_nnreal_ennreal.comp f.continuous.measurable
#align bounded_continuous_function.nnreal.to_ennreal_comp_measurable BoundedContinuousFunction.measurable_coe_ennreal_comp
variable (μ : Measure X) [IsFiniteMeasure μ]
theorem lintegral_lt_top_of_nnreal (f : X →ᵇ ℝ≥0) : ∫⁻ x, f x ∂μ < ∞ := by
apply IsFiniteMeasure.lintegral_lt_top_of_bounded_to_ennreal
refine ⟨nndist f 0, fun x ↦ ?_⟩
have key := BoundedContinuousFunction.NNReal.upper_bound f x
rwa [ENNReal.coe_le_coe]
#align measure_theory.lintegral_lt_top_of_bounded_continuous_to_nnreal BoundedContinuousFunction.lintegral_lt_top_of_nnreal
| Mathlib/MeasureTheory/Integral/BoundedContinuousFunction.lean | 49 | 52 | theorem integrable_of_nnreal (f : X →ᵇ ℝ≥0) : Integrable (((↑) : ℝ≥0 → ℝ) ∘ ⇑f) μ := by |
refine ⟨(NNReal.continuous_coe.comp f.continuous).measurable.aestronglyMeasurable, ?_⟩
simp only [HasFiniteIntegral, Function.comp_apply, NNReal.nnnorm_eq]
exact lintegral_lt_top_of_nnreal _ f
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Regular.Pow
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Data.Finsupp.Antidiagonal
import Mathlib.Order.SymmDiff
import Mathlib.RingTheory.Adjoin.Basic
#align_import data.mv_polynomial.basic from "leanprover-community/mathlib"@"c8734e8953e4b439147bd6f75c2163f6d27cdce6"
/-!
# Multivariate polynomials
This file defines polynomial rings over a base ring (or even semiring),
with variables from a general type `σ` (which could be infinite).
## Important definitions
Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary
type. This file creates the type `MvPolynomial σ R`, which mathematicians
might denote $R[X_i : i \in σ]$. It is the type of multivariate
(a.k.a. multivariable) polynomials, with variables
corresponding to the terms in `σ`, and coefficients in `R`.
### Notation
In the definitions below, we use the following notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `a : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
### Definitions
* `MvPolynomial σ R` : the type of polynomials with variables of type `σ` and coefficients
in the commutative semiring `R`
* `monomial s a` : the monomial which mathematically would be denoted `a * X^s`
* `C a` : the constant polynomial with value `a`
* `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`.
* `coeff s p` : the coefficient of `s` in `p`.
* `eval₂ (f : R → S₁) (g : σ → S₁) p` : given a semiring homomorphism from `R` to another
semiring `S₁`, and a map `σ → S₁`, evaluates `p` at this valuation, returning a term of type `S₁`.
Note that `eval₂` can be made using `eval` and `map` (see below), and it has been suggested
that sticking to `eval` and `map` might make the code less brittle.
* `eval (g : σ → R) p` : given a map `σ → R`, evaluates `p` at this valuation,
returning a term of type `R`
* `map (f : R → S₁) p` : returns the multivariate polynomial obtained from `p` by the change of
coefficient semiring corresponding to `f`
## Implementation notes
Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite
support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`.
The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all
monomials in the variables, and the function to `R` sends a monomial to its coefficient in
the polynomial being represented.
## Tags
polynomial, multivariate polynomial, multivariable polynomial
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
open scoped Pointwise
universe u v w x
variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x}
/-- Multivariate polynomial, where `σ` is the index set of the variables and
`R` is the coefficient ring -/
def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] :=
AddMonoidAlgebra R (σ →₀ ℕ)
#align mv_polynomial MvPolynomial
namespace MvPolynomial
-- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws
-- tons of warnings in this file, and it's easier to just disable them globally in the file
set_option linter.uppercaseLean3 false
variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
section Instances
instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] :
DecidableEq (MvPolynomial σ R) :=
Finsupp.instDecidableEq
#align mv_polynomial.decidable_eq_mv_polynomial MvPolynomial.decidableEqMvPolynomial
instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) :=
AddMonoidAlgebra.commSemiring
instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) :=
⟨0⟩
instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] :
DistribMulAction R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.distribMulAction
instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] :
SMulZeroClass R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulZeroClass
instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] :
FaithfulSMul R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.faithfulSMul
instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.module
instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.isScalarTower
instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.smulCommClass
instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁]
[IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isCentralScalar
instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] :
Algebra R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.algebra
instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] :
IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isScalarTower_self _
#align mv_polynomial.is_scalar_tower_right MvPolynomial.isScalarTower_right
instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] :
SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulCommClass_self _
#align mv_polynomial.smul_comm_class_right MvPolynomial.smulCommClass_right
/-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/
instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) :=
AddMonoidAlgebra.unique
#align mv_polynomial.unique MvPolynomial.unique
end Instances
variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R}
/-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/
def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R :=
lsingle s
#align mv_polynomial.monomial MvPolynomial.monomial
theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a :=
rfl
#align mv_polynomial.single_eq_monomial MvPolynomial.single_eq_monomial
theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) :=
AddMonoidAlgebra.mul_def
#align mv_polynomial.mul_def MvPolynomial.mul_def
/-- `C a` is the constant polynomial with value `a` -/
def C : R →+* MvPolynomial σ R :=
{ singleZeroRingHom with toFun := monomial 0 }
#align mv_polynomial.C MvPolynomial.C
variable (R σ)
@[simp]
theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C :=
rfl
#align mv_polynomial.algebra_map_eq MvPolynomial.algebraMap_eq
variable {R σ}
/-- `X n` is the degree `1` monomial $X_n$. -/
def X (n : σ) : MvPolynomial σ R :=
monomial (Finsupp.single n 1) 1
#align mv_polynomial.X MvPolynomial.X
theorem monomial_left_injective {r : R} (hr : r ≠ 0) :
Function.Injective fun s : σ →₀ ℕ => monomial s r :=
Finsupp.single_left_injective hr
#align mv_polynomial.monomial_left_injective MvPolynomial.monomial_left_injective
@[simp]
theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) :
monomial s r = monomial t r ↔ s = t :=
Finsupp.single_left_inj hr
#align mv_polynomial.monomial_left_inj MvPolynomial.monomial_left_inj
theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a :=
rfl
#align mv_polynomial.C_apply MvPolynomial.C_apply
-- Porting note (#10618): `simp` can prove this
theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _
#align mv_polynomial.C_0 MvPolynomial.C_0
-- Porting note (#10618): `simp` can prove this
theorem C_1 : C 1 = (1 : MvPolynomial σ R) :=
rfl
#align mv_polynomial.C_1 MvPolynomial.C_1
theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by
-- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas
show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _
simp [C_apply, single_mul_single]
#align mv_polynomial.C_mul_monomial MvPolynomial.C_mul_monomial
-- Porting note (#10618): `simp` can prove this
theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' :=
Finsupp.single_add _ _ _
#align mv_polynomial.C_add MvPolynomial.C_add
-- Porting note (#10618): `simp` can prove this
theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' :=
C_mul_monomial.symm
#align mv_polynomial.C_mul MvPolynomial.C_mul
-- Porting note (#10618): `simp` can prove this
theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n :=
map_pow _ _ _
#align mv_polynomial.C_pow MvPolynomial.C_pow
theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] :
Function.Injective (C : R → MvPolynomial σ R) :=
Finsupp.single_injective _
#align mv_polynomial.C_injective MvPolynomial.C_injective
theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] :
Function.Surjective (C : R → MvPolynomial σ R) := by
refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩
simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0),
single_eq_same]
rfl
#align mv_polynomial.C_surjective MvPolynomial.C_surjective
@[simp]
theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) :
(C r : MvPolynomial σ R) = C s ↔ r = s :=
(C_injective σ R).eq_iff
#align mv_polynomial.C_inj MvPolynomial.C_inj
instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] :
Nontrivial (MvPolynomial σ R) :=
inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ))
instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] :
Infinite (MvPolynomial σ R) :=
Infinite.of_injective C (C_injective _ _)
#align mv_polynomial.infinite_of_infinite MvPolynomial.infinite_of_infinite
instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R]
[Nontrivial R] : Infinite (MvPolynomial σ R) :=
Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ))
<| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _)
#align mv_polynomial.infinite_of_nonempty MvPolynomial.infinite_of_nonempty
theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by
induction n <;> simp [Nat.succ_eq_add_one, *]
#align mv_polynomial.C_eq_coe_nat MvPolynomial.C_eq_coe_nat
theorem C_mul' : MvPolynomial.C a * p = a • p :=
(Algebra.smul_def a p).symm
#align mv_polynomial.C_mul' MvPolynomial.C_mul'
theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p :=
C_mul'.symm
#align mv_polynomial.smul_eq_C_mul MvPolynomial.smul_eq_C_mul
theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by
rw [← C_mul', mul_one]
#align mv_polynomial.C_eq_smul_one MvPolynomial.C_eq_smul_one
theorem smul_monomial {S₁ : Type*} [SMulZeroClass S₁ R] (r : S₁) :
r • monomial s a = monomial s (r • a) :=
Finsupp.smul_single _ _ _
#align mv_polynomial.smul_monomial MvPolynomial.smul_monomial
theorem X_injective [Nontrivial R] : Function.Injective (X : σ → MvPolynomial σ R) :=
(monomial_left_injective one_ne_zero).comp (Finsupp.single_left_injective one_ne_zero)
#align mv_polynomial.X_injective MvPolynomial.X_injective
@[simp]
theorem X_inj [Nontrivial R] (m n : σ) : X m = (X n : MvPolynomial σ R) ↔ m = n :=
X_injective.eq_iff
#align mv_polynomial.X_inj MvPolynomial.X_inj
theorem monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) :=
AddMonoidAlgebra.single_pow e
#align mv_polynomial.monomial_pow MvPolynomial.monomial_pow
@[simp]
theorem monomial_mul {s s' : σ →₀ ℕ} {a b : R} :
monomial s a * monomial s' b = monomial (s + s') (a * b) :=
AddMonoidAlgebra.single_mul_single
#align mv_polynomial.monomial_mul MvPolynomial.monomial_mul
variable (σ R)
/-- `fun s ↦ monomial s 1` as a homomorphism. -/
def monomialOneHom : Multiplicative (σ →₀ ℕ) →* MvPolynomial σ R :=
AddMonoidAlgebra.of _ _
#align mv_polynomial.monomial_one_hom MvPolynomial.monomialOneHom
variable {σ R}
@[simp]
theorem monomialOneHom_apply : monomialOneHom R σ s = (monomial s 1 : MvPolynomial σ R) :=
rfl
#align mv_polynomial.monomial_one_hom_apply MvPolynomial.monomialOneHom_apply
theorem X_pow_eq_monomial : X n ^ e = monomial (Finsupp.single n e) (1 : R) := by
simp [X, monomial_pow]
#align mv_polynomial.X_pow_eq_monomial MvPolynomial.X_pow_eq_monomial
theorem monomial_add_single : monomial (s + Finsupp.single n e) a = monomial s a * X n ^ e := by
rw [X_pow_eq_monomial, monomial_mul, mul_one]
#align mv_polynomial.monomial_add_single MvPolynomial.monomial_add_single
theorem monomial_single_add : monomial (Finsupp.single n e + s) a = X n ^ e * monomial s a := by
rw [X_pow_eq_monomial, monomial_mul, one_mul]
#align mv_polynomial.monomial_single_add MvPolynomial.monomial_single_add
theorem C_mul_X_pow_eq_monomial {s : σ} {a : R} {n : ℕ} :
C a * X s ^ n = monomial (Finsupp.single s n) a := by
rw [← zero_add (Finsupp.single s n), monomial_add_single, C_apply]
#align mv_polynomial.C_mul_X_pow_eq_monomial MvPolynomial.C_mul_X_pow_eq_monomial
theorem C_mul_X_eq_monomial {s : σ} {a : R} : C a * X s = monomial (Finsupp.single s 1) a := by
rw [← C_mul_X_pow_eq_monomial, pow_one]
#align mv_polynomial.C_mul_X_eq_monomial MvPolynomial.C_mul_X_eq_monomial
-- Porting note (#10618): `simp` can prove this
theorem monomial_zero {s : σ →₀ ℕ} : monomial s (0 : R) = 0 :=
Finsupp.single_zero _
#align mv_polynomial.monomial_zero MvPolynomial.monomial_zero
@[simp]
theorem monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → MvPolynomial σ R) = C :=
rfl
#align mv_polynomial.monomial_zero' MvPolynomial.monomial_zero'
@[simp]
theorem monomial_eq_zero {s : σ →₀ ℕ} {b : R} : monomial s b = 0 ↔ b = 0 :=
Finsupp.single_eq_zero
#align mv_polynomial.monomial_eq_zero MvPolynomial.monomial_eq_zero
@[simp]
theorem sum_monomial_eq {A : Type*} [AddCommMonoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A}
(w : b u 0 = 0) : sum (monomial u r) b = b u r :=
Finsupp.sum_single_index w
#align mv_polynomial.sum_monomial_eq MvPolynomial.sum_monomial_eq
@[simp]
theorem sum_C {A : Type*} [AddCommMonoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) :
sum (C a) b = b 0 a :=
sum_monomial_eq w
#align mv_polynomial.sum_C MvPolynomial.sum_C
theorem monomial_sum_one {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) :
(monomial (∑ i ∈ s, f i) 1 : MvPolynomial σ R) = ∏ i ∈ s, monomial (f i) 1 :=
map_prod (monomialOneHom R σ) (fun i => Multiplicative.ofAdd (f i)) s
#align mv_polynomial.monomial_sum_one MvPolynomial.monomial_sum_one
theorem monomial_sum_index {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) (a : R) :
monomial (∑ i ∈ s, f i) a = C a * ∏ i ∈ s, monomial (f i) 1 := by
rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one]
#align mv_polynomial.monomial_sum_index MvPolynomial.monomial_sum_index
theorem monomial_finsupp_sum_index {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → σ →₀ ℕ)
(a : R) : monomial (f.sum g) a = C a * f.prod fun a b => monomial (g a b) 1 :=
monomial_sum_index _ _ _
#align mv_polynomial.monomial_finsupp_sum_index MvPolynomial.monomial_finsupp_sum_index
theorem monomial_eq_monomial_iff {α : Type*} (a₁ a₂ : α →₀ ℕ) (b₁ b₂ : R) :
monomial a₁ b₁ = monomial a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 :=
Finsupp.single_eq_single_iff _ _ _ _
#align mv_polynomial.monomial_eq_monomial_iff MvPolynomial.monomial_eq_monomial_iff
theorem monomial_eq : monomial s a = C a * (s.prod fun n e => X n ^ e : MvPolynomial σ R) := by
simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, Finsupp.sum_single]
#align mv_polynomial.monomial_eq MvPolynomial.monomial_eq
@[simp]
lemma prod_X_pow_eq_monomial : ∏ x ∈ s.support, X x ^ s x = monomial s (1 : R) := by
simp only [monomial_eq, map_one, one_mul, Finsupp.prod]
theorem induction_on_monomial {M : MvPolynomial σ R → Prop} (h_C : ∀ a, M (C a))
(h_X : ∀ p n, M p → M (p * X n)) : ∀ s a, M (monomial s a) := by
intro s a
apply @Finsupp.induction σ ℕ _ _ s
· show M (monomial 0 a)
exact h_C a
· intro n e p _hpn _he ih
have : ∀ e : ℕ, M (monomial p a * X n ^ e) := by
intro e
induction e with
| zero => simp [ih]
| succ e e_ih => simp [ih, pow_succ, (mul_assoc _ _ _).symm, h_X, e_ih]
simp [add_comm, monomial_add_single, this]
#align mv_polynomial.induction_on_monomial MvPolynomial.induction_on_monomial
/-- Analog of `Polynomial.induction_on'`.
To prove something about mv_polynomials,
it suffices to show the condition is closed under taking sums,
and it holds for monomials. -/
@[elab_as_elim]
theorem induction_on' {P : MvPolynomial σ R → Prop} (p : MvPolynomial σ R)
(h1 : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a))
(h2 : ∀ p q : MvPolynomial σ R, P p → P q → P (p + q)) : P p :=
Finsupp.induction p
(suffices P (monomial 0 0) by rwa [monomial_zero] at this
show P (monomial 0 0) from h1 0 0)
fun a b f _ha _hb hPf => h2 _ _ (h1 _ _) hPf
#align mv_polynomial.induction_on' MvPolynomial.induction_on'
/-- Similar to `MvPolynomial.induction_on` but only a weak form of `h_add` is required. -/
theorem induction_on''' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a))
(h_add_weak :
∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R),
a ∉ f.support → b ≠ 0 → M f → M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f)) :
M p :=
-- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient.
Finsupp.induction p (C_0.rec <| h_C 0) h_add_weak
#align mv_polynomial.induction_on''' MvPolynomial.induction_on'''
/-- Similar to `MvPolynomial.induction_on` but only a yet weaker form of `h_add` is required. -/
theorem induction_on'' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a))
(h_add_weak :
∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R),
a ∉ f.support → b ≠ 0 → M f → M (monomial a b) →
M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f))
(h_X : ∀ (p : MvPolynomial σ R) (n : σ), M p → M (p * MvPolynomial.X n)) : M p :=
-- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient.
induction_on''' p h_C fun a b f ha hb hf =>
h_add_weak a b f ha hb hf <| induction_on_monomial h_C h_X a b
#align mv_polynomial.induction_on'' MvPolynomial.induction_on''
/-- Analog of `Polynomial.induction_on`. -/
@[recursor 5]
theorem induction_on {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a))
(h_add : ∀ p q, M p → M q → M (p + q)) (h_X : ∀ p n, M p → M (p * X n)) : M p :=
induction_on'' p h_C (fun a b f _ha _hb hf hm => h_add (monomial a b) f hm hf) h_X
#align mv_polynomial.induction_on MvPolynomial.induction_on
theorem ringHom_ext {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A}
(hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) : f = g := by
refine AddMonoidAlgebra.ringHom_ext' ?_ ?_
-- Porting note: this has high priority, but Lean still chooses `RingHom.ext`, why?
-- probably because of the type synonym
· ext x
exact hC _
· apply Finsupp.mulHom_ext'; intros x
-- Porting note: `Finsupp.mulHom_ext'` needs to have increased priority
apply MonoidHom.ext_mnat
exact hX _
#align mv_polynomial.ring_hom_ext MvPolynomial.ringHom_ext
/-- See note [partially-applied ext lemmas]. -/
@[ext 1100]
theorem ringHom_ext' {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A}
(hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) : f = g :=
ringHom_ext (RingHom.ext_iff.1 hC) hX
#align mv_polynomial.ring_hom_ext' MvPolynomial.ringHom_ext'
theorem hom_eq_hom [Semiring S₂] (f g : MvPolynomial σ R →+* S₂) (hC : f.comp C = g.comp C)
(hX : ∀ n : σ, f (X n) = g (X n)) (p : MvPolynomial σ R) : f p = g p :=
RingHom.congr_fun (ringHom_ext' hC hX) p
#align mv_polynomial.hom_eq_hom MvPolynomial.hom_eq_hom
theorem is_id (f : MvPolynomial σ R →+* MvPolynomial σ R) (hC : f.comp C = C)
(hX : ∀ n : σ, f (X n) = X n) (p : MvPolynomial σ R) : f p = p :=
hom_eq_hom f (RingHom.id _) hC hX p
#align mv_polynomial.is_id MvPolynomial.is_id
@[ext 1100]
theorem algHom_ext' {A B : Type*} [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B]
{f g : MvPolynomial σ A →ₐ[R] B}
(h₁ :
f.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)) =
g.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)))
(h₂ : ∀ i, f (X i) = g (X i)) : f = g :=
AlgHom.coe_ringHom_injective (MvPolynomial.ringHom_ext' (congr_arg AlgHom.toRingHom h₁) h₂)
#align mv_polynomial.alg_hom_ext' MvPolynomial.algHom_ext'
@[ext 1200]
theorem algHom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : MvPolynomial σ R →ₐ[R] A}
(hf : ∀ i : σ, f (X i) = g (X i)) : f = g :=
AddMonoidAlgebra.algHom_ext' (mulHom_ext' fun X : σ => MonoidHom.ext_mnat (hf X))
#align mv_polynomial.alg_hom_ext MvPolynomial.algHom_ext
@[simp]
theorem algHom_C {τ : Type*} (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) (r : R) :
f (C r) = C r :=
f.commutes r
#align mv_polynomial.alg_hom_C MvPolynomial.algHom_C
@[simp]
theorem adjoin_range_X : Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) = ⊤ := by
set S := Algebra.adjoin R (range (X : σ → MvPolynomial σ R))
refine top_unique fun p hp => ?_; clear hp
induction p using MvPolynomial.induction_on with
| h_C => exact S.algebraMap_mem _
| h_add p q hp hq => exact S.add_mem hp hq
| h_X p i hp => exact S.mul_mem hp (Algebra.subset_adjoin <| mem_range_self _)
#align mv_polynomial.adjoin_range_X MvPolynomial.adjoin_range_X
@[ext]
theorem linearMap_ext {M : Type*} [AddCommMonoid M] [Module R M] {f g : MvPolynomial σ R →ₗ[R] M}
(h : ∀ s, f ∘ₗ monomial s = g ∘ₗ monomial s) : f = g :=
Finsupp.lhom_ext' h
#align mv_polynomial.linear_map_ext MvPolynomial.linearMap_ext
section Support
/-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/
def support (p : MvPolynomial σ R) : Finset (σ →₀ ℕ) :=
Finsupp.support p
#align mv_polynomial.support MvPolynomial.support
theorem finsupp_support_eq_support (p : MvPolynomial σ R) : Finsupp.support p = p.support :=
rfl
#align mv_polynomial.finsupp_support_eq_support MvPolynomial.finsupp_support_eq_support
theorem support_monomial [h : Decidable (a = 0)] :
(monomial s a).support = if a = 0 then ∅ else {s} := by
rw [← Subsingleton.elim (Classical.decEq R a 0) h]
rfl
-- Porting note: the proof in Lean 3 wasn't fundamentally better and needed `by convert rfl`
-- the issue is the different decidability instances in the `ite` expressions
#align mv_polynomial.support_monomial MvPolynomial.support_monomial
theorem support_monomial_subset : (monomial s a).support ⊆ {s} :=
support_single_subset
#align mv_polynomial.support_monomial_subset MvPolynomial.support_monomial_subset
theorem support_add [DecidableEq σ] : (p + q).support ⊆ p.support ∪ q.support :=
Finsupp.support_add
#align mv_polynomial.support_add MvPolynomial.support_add
theorem support_X [Nontrivial R] : (X n : MvPolynomial σ R).support = {Finsupp.single n 1} := by
classical rw [X, support_monomial, if_neg]; exact one_ne_zero
#align mv_polynomial.support_X MvPolynomial.support_X
theorem support_X_pow [Nontrivial R] (s : σ) (n : ℕ) :
(X s ^ n : MvPolynomial σ R).support = {Finsupp.single s n} := by
classical
rw [X_pow_eq_monomial, support_monomial, if_neg (one_ne_zero' R)]
#align mv_polynomial.support_X_pow MvPolynomial.support_X_pow
@[simp]
theorem support_zero : (0 : MvPolynomial σ R).support = ∅ :=
rfl
#align mv_polynomial.support_zero MvPolynomial.support_zero
theorem support_smul {S₁ : Type*} [SMulZeroClass S₁ R] {a : S₁} {f : MvPolynomial σ R} :
(a • f).support ⊆ f.support :=
Finsupp.support_smul
#align mv_polynomial.support_smul MvPolynomial.support_smul
theorem support_sum {α : Type*} [DecidableEq σ] {s : Finset α} {f : α → MvPolynomial σ R} :
(∑ x ∈ s, f x).support ⊆ s.biUnion fun x => (f x).support :=
Finsupp.support_finset_sum
#align mv_polynomial.support_sum MvPolynomial.support_sum
end Support
section Coeff
/-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/
def coeff (m : σ →₀ ℕ) (p : MvPolynomial σ R) : R :=
@DFunLike.coe ((σ →₀ ℕ) →₀ R) _ _ _ p m
-- Porting note: I changed this from `@CoeFun.coe _ _ (MonoidAlgebra.coeFun _ _) p m` because
-- I think it should work better syntactically. They are defeq.
#align mv_polynomial.coeff MvPolynomial.coeff
@[simp]
theorem mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∈ p.support ↔ p.coeff m ≠ 0 := by
simp [support, coeff]
#align mv_polynomial.mem_support_iff MvPolynomial.mem_support_iff
theorem not_mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∉ p.support ↔ p.coeff m = 0 :=
by simp
#align mv_polynomial.not_mem_support_iff MvPolynomial.not_mem_support_iff
theorem sum_def {A} [AddCommMonoid A] {p : MvPolynomial σ R} {b : (σ →₀ ℕ) → R → A} :
p.sum b = ∑ m ∈ p.support, b m (p.coeff m) := by simp [support, Finsupp.sum, coeff]
#align mv_polynomial.sum_def MvPolynomial.sum_def
theorem support_mul [DecidableEq σ] (p q : MvPolynomial σ R) :
(p * q).support ⊆ p.support + q.support :=
AddMonoidAlgebra.support_mul p q
#align mv_polynomial.support_mul MvPolynomial.support_mul
@[ext]
theorem ext (p q : MvPolynomial σ R) : (∀ m, coeff m p = coeff m q) → p = q :=
Finsupp.ext
#align mv_polynomial.ext MvPolynomial.ext
theorem ext_iff (p q : MvPolynomial σ R) : p = q ↔ ∀ m, coeff m p = coeff m q :=
⟨fun h m => by rw [h], ext p q⟩
#align mv_polynomial.ext_iff MvPolynomial.ext_iff
@[simp]
theorem coeff_add (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p + q) = coeff m p + coeff m q :=
add_apply p q m
#align mv_polynomial.coeff_add MvPolynomial.coeff_add
@[simp]
theorem coeff_smul {S₁ : Type*} [SMulZeroClass S₁ R] (m : σ →₀ ℕ) (C : S₁) (p : MvPolynomial σ R) :
coeff m (C • p) = C • coeff m p :=
smul_apply C p m
#align mv_polynomial.coeff_smul MvPolynomial.coeff_smul
@[simp]
theorem coeff_zero (m : σ →₀ ℕ) : coeff m (0 : MvPolynomial σ R) = 0 :=
rfl
#align mv_polynomial.coeff_zero MvPolynomial.coeff_zero
@[simp]
theorem coeff_zero_X (i : σ) : coeff 0 (X i : MvPolynomial σ R) = 0 :=
single_eq_of_ne fun h => by cases Finsupp.single_eq_zero.1 h
#align mv_polynomial.coeff_zero_X MvPolynomial.coeff_zero_X
/-- `MvPolynomial.coeff m` but promoted to an `AddMonoidHom`. -/
@[simps]
def coeffAddMonoidHom (m : σ →₀ ℕ) : MvPolynomial σ R →+ R where
toFun := coeff m
map_zero' := coeff_zero m
map_add' := coeff_add m
#align mv_polynomial.coeff_add_monoid_hom MvPolynomial.coeffAddMonoidHom
variable (R) in
/-- `MvPolynomial.coeff m` but promoted to a `LinearMap`. -/
@[simps]
def lcoeff (m : σ →₀ ℕ) : MvPolynomial σ R →ₗ[R] R where
toFun := coeff m
map_add' := coeff_add m
map_smul' := coeff_smul m
theorem coeff_sum {X : Type*} (s : Finset X) (f : X → MvPolynomial σ R) (m : σ →₀ ℕ) :
coeff m (∑ x ∈ s, f x) = ∑ x ∈ s, coeff m (f x) :=
map_sum (@coeffAddMonoidHom R σ _ _) _ s
#align mv_polynomial.coeff_sum MvPolynomial.coeff_sum
theorem monic_monomial_eq (m) :
monomial m (1 : R) = (m.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp [monomial_eq]
#align mv_polynomial.monic_monomial_eq MvPolynomial.monic_monomial_eq
@[simp]
theorem coeff_monomial [DecidableEq σ] (m n) (a) :
coeff m (monomial n a : MvPolynomial σ R) = if n = m then a else 0 :=
Finsupp.single_apply
#align mv_polynomial.coeff_monomial MvPolynomial.coeff_monomial
@[simp]
theorem coeff_C [DecidableEq σ] (m) (a) :
coeff m (C a : MvPolynomial σ R) = if 0 = m then a else 0 :=
Finsupp.single_apply
#align mv_polynomial.coeff_C MvPolynomial.coeff_C
lemma eq_C_of_isEmpty [IsEmpty σ] (p : MvPolynomial σ R) :
p = C (p.coeff 0) := by
obtain ⟨x, rfl⟩ := C_surjective σ p
simp
theorem coeff_one [DecidableEq σ] (m) : coeff m (1 : MvPolynomial σ R) = if 0 = m then 1 else 0 :=
coeff_C m 1
#align mv_polynomial.coeff_one MvPolynomial.coeff_one
@[simp]
theorem coeff_zero_C (a) : coeff 0 (C a : MvPolynomial σ R) = a :=
single_eq_same
#align mv_polynomial.coeff_zero_C MvPolynomial.coeff_zero_C
@[simp]
theorem coeff_zero_one : coeff 0 (1 : MvPolynomial σ R) = 1 :=
coeff_zero_C 1
#align mv_polynomial.coeff_zero_one MvPolynomial.coeff_zero_one
theorem coeff_X_pow [DecidableEq σ] (i : σ) (m) (k : ℕ) :
coeff m (X i ^ k : MvPolynomial σ R) = if Finsupp.single i k = m then 1 else 0 := by
have := coeff_monomial m (Finsupp.single i k) (1 : R)
rwa [@monomial_eq _ _ (1 : R) (Finsupp.single i k) _, C_1, one_mul, Finsupp.prod_single_index]
at this
exact pow_zero _
#align mv_polynomial.coeff_X_pow MvPolynomial.coeff_X_pow
| Mathlib/Algebra/MvPolynomial/Basic.lean | 703 | 705 | theorem coeff_X' [DecidableEq σ] (i : σ) (m) :
coeff m (X i : MvPolynomial σ R) = if Finsupp.single i 1 = m then 1 else 0 := by |
rw [← coeff_X_pow, pow_one]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kyle Miller
-/
import Mathlib.Data.Finset.Basic
import Mathlib.Data.Finite.Basic
import Mathlib.Data.Set.Functor
import Mathlib.Data.Set.Lattice
#align_import data.set.finite from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83"
/-!
# Finite sets
This file defines predicates for finite and infinite sets and provides
`Fintype` instances for many set constructions. It also proves basic facts
about finite sets and gives ways to manipulate `Set.Finite` expressions.
## Main definitions
* `Set.Finite : Set α → Prop`
* `Set.Infinite : Set α → Prop`
* `Set.toFinite` to prove `Set.Finite` for a `Set` from a `Finite` instance.
* `Set.Finite.toFinset` to noncomputably produce a `Finset` from a `Set.Finite` proof.
(See `Set.toFinset` for a computable version.)
## Implementation
A finite set is defined to be a set whose coercion to a type has a `Finite` instance.
There are two components to finiteness constructions. The first is `Fintype` instances for each
construction. This gives a way to actually compute a `Finset` that represents the set, and these
may be accessed using `set.toFinset`. This gets the `Finset` in the correct form, since otherwise
`Finset.univ : Finset s` is a `Finset` for the subtype for `s`. The second component is
"constructors" for `Set.Finite` that give proofs that `Fintype` instances exist classically given
other `Set.Finite` proofs. Unlike the `Fintype` instances, these *do not* use any decidability
instances since they do not compute anything.
## Tags
finite sets
-/
assert_not_exists OrderedRing
assert_not_exists MonoidWithZero
open Set Function
universe u v w x
variable {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x}
namespace Set
/-- A set is finite if the corresponding `Subtype` is finite,
i.e., if there exists a natural `n : ℕ` and an equivalence `s ≃ Fin n`. -/
protected def Finite (s : Set α) : Prop := Finite s
#align set.finite Set.Finite
-- The `protected` attribute does not take effect within the same namespace block.
end Set
namespace Set
theorem finite_def {s : Set α} : s.Finite ↔ Nonempty (Fintype s) :=
finite_iff_nonempty_fintype s
#align set.finite_def Set.finite_def
protected alias ⟨Finite.nonempty_fintype, _⟩ := finite_def
#align set.finite.nonempty_fintype Set.Finite.nonempty_fintype
theorem finite_coe_iff {s : Set α} : Finite s ↔ s.Finite := .rfl
#align set.finite_coe_iff Set.finite_coe_iff
/-- Constructor for `Set.Finite` using a `Finite` instance. -/
theorem toFinite (s : Set α) [Finite s] : s.Finite := ‹_›
#align set.to_finite Set.toFinite
/-- Construct a `Finite` instance for a `Set` from a `Finset` with the same elements. -/
protected theorem Finite.ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : p.Finite :=
have := Fintype.ofFinset s H; p.toFinite
#align set.finite.of_finset Set.Finite.ofFinset
/-- Projection of `Set.Finite` to its `Finite` instance.
This is intended to be used with dot notation.
See also `Set.Finite.Fintype` and `Set.Finite.nonempty_fintype`. -/
protected theorem Finite.to_subtype {s : Set α} (h : s.Finite) : Finite s := h
#align set.finite.to_subtype Set.Finite.to_subtype
/-- A finite set coerced to a type is a `Fintype`.
This is the `Fintype` projection for a `Set.Finite`.
Note that because `Finite` isn't a typeclass, this definition will not fire if it
is made into an instance -/
protected noncomputable def Finite.fintype {s : Set α} (h : s.Finite) : Fintype s :=
h.nonempty_fintype.some
#align set.finite.fintype Set.Finite.fintype
/-- Using choice, get the `Finset` that represents this `Set`. -/
protected noncomputable def Finite.toFinset {s : Set α} (h : s.Finite) : Finset α :=
@Set.toFinset _ _ h.fintype
#align set.finite.to_finset Set.Finite.toFinset
theorem Finite.toFinset_eq_toFinset {s : Set α} [Fintype s] (h : s.Finite) :
h.toFinset = s.toFinset := by
-- Porting note: was `rw [Finite.toFinset]; congr`
-- in Lean 4, a goal is left after `congr`
have : h.fintype = ‹_› := Subsingleton.elim _ _
rw [Finite.toFinset, this]
#align set.finite.to_finset_eq_to_finset Set.Finite.toFinset_eq_toFinset
@[simp]
theorem toFinite_toFinset (s : Set α) [Fintype s] : s.toFinite.toFinset = s.toFinset :=
s.toFinite.toFinset_eq_toFinset
#align set.to_finite_to_finset Set.toFinite_toFinset
theorem Finite.exists_finset {s : Set α} (h : s.Finite) :
∃ s' : Finset α, ∀ a : α, a ∈ s' ↔ a ∈ s := by
cases h.nonempty_fintype
exact ⟨s.toFinset, fun _ => mem_toFinset⟩
#align set.finite.exists_finset Set.Finite.exists_finset
theorem Finite.exists_finset_coe {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ↑s' = s := by
cases h.nonempty_fintype
exact ⟨s.toFinset, s.coe_toFinset⟩
#align set.finite.exists_finset_coe Set.Finite.exists_finset_coe
/-- Finite sets can be lifted to finsets. -/
instance : CanLift (Set α) (Finset α) (↑) Set.Finite where prf _ hs := hs.exists_finset_coe
/-- A set is infinite if it is not finite.
This is protected so that it does not conflict with global `Infinite`. -/
protected def Infinite (s : Set α) : Prop :=
¬s.Finite
#align set.infinite Set.Infinite
@[simp]
theorem not_infinite {s : Set α} : ¬s.Infinite ↔ s.Finite :=
not_not
#align set.not_infinite Set.not_infinite
alias ⟨_, Finite.not_infinite⟩ := not_infinite
#align set.finite.not_infinite Set.Finite.not_infinite
attribute [simp] Finite.not_infinite
/-- See also `finite_or_infinite`, `fintypeOrInfinite`. -/
protected theorem finite_or_infinite (s : Set α) : s.Finite ∨ s.Infinite :=
em _
#align set.finite_or_infinite Set.finite_or_infinite
protected theorem infinite_or_finite (s : Set α) : s.Infinite ∨ s.Finite :=
em' _
#align set.infinite_or_finite Set.infinite_or_finite
/-! ### Basic properties of `Set.Finite.toFinset` -/
namespace Finite
variable {s t : Set α} {a : α} (hs : s.Finite) {ht : t.Finite}
@[simp]
protected theorem mem_toFinset : a ∈ hs.toFinset ↔ a ∈ s :=
@mem_toFinset _ _ hs.fintype _
#align set.finite.mem_to_finset Set.Finite.mem_toFinset
@[simp]
protected theorem coe_toFinset : (hs.toFinset : Set α) = s :=
@coe_toFinset _ _ hs.fintype
#align set.finite.coe_to_finset Set.Finite.coe_toFinset
@[simp]
protected theorem toFinset_nonempty : hs.toFinset.Nonempty ↔ s.Nonempty := by
rw [← Finset.coe_nonempty, Finite.coe_toFinset]
#align set.finite.to_finset_nonempty Set.Finite.toFinset_nonempty
/-- Note that this is an equality of types not holding definitionally. Use wisely. -/
theorem coeSort_toFinset : ↥hs.toFinset = ↥s := by
rw [← Finset.coe_sort_coe _, hs.coe_toFinset]
#align set.finite.coe_sort_to_finset Set.Finite.coeSort_toFinset
/-- The identity map, bundled as an equivalence between the subtypes of `s : Set α` and of
`h.toFinset : Finset α`, where `h` is a proof of finiteness of `s`. -/
@[simps!] def subtypeEquivToFinset : {x // x ∈ s} ≃ {x // x ∈ hs.toFinset} :=
(Equiv.refl α).subtypeEquiv fun _ ↦ hs.mem_toFinset.symm
variable {hs}
@[simp]
protected theorem toFinset_inj : hs.toFinset = ht.toFinset ↔ s = t :=
@toFinset_inj _ _ _ hs.fintype ht.fintype
#align set.finite.to_finset_inj Set.Finite.toFinset_inj
@[simp]
theorem toFinset_subset {t : Finset α} : hs.toFinset ⊆ t ↔ s ⊆ t := by
rw [← Finset.coe_subset, Finite.coe_toFinset]
#align set.finite.to_finset_subset Set.Finite.toFinset_subset
@[simp]
theorem toFinset_ssubset {t : Finset α} : hs.toFinset ⊂ t ↔ s ⊂ t := by
rw [← Finset.coe_ssubset, Finite.coe_toFinset]
#align set.finite.to_finset_ssubset Set.Finite.toFinset_ssubset
@[simp]
theorem subset_toFinset {s : Finset α} : s ⊆ ht.toFinset ↔ ↑s ⊆ t := by
rw [← Finset.coe_subset, Finite.coe_toFinset]
#align set.finite.subset_to_finset Set.Finite.subset_toFinset
@[simp]
theorem ssubset_toFinset {s : Finset α} : s ⊂ ht.toFinset ↔ ↑s ⊂ t := by
rw [← Finset.coe_ssubset, Finite.coe_toFinset]
#align set.finite.ssubset_to_finset Set.Finite.ssubset_toFinset
@[mono]
protected theorem toFinset_subset_toFinset : hs.toFinset ⊆ ht.toFinset ↔ s ⊆ t := by
simp only [← Finset.coe_subset, Finite.coe_toFinset]
#align set.finite.to_finset_subset_to_finset Set.Finite.toFinset_subset_toFinset
@[mono]
protected theorem toFinset_ssubset_toFinset : hs.toFinset ⊂ ht.toFinset ↔ s ⊂ t := by
simp only [← Finset.coe_ssubset, Finite.coe_toFinset]
#align set.finite.to_finset_ssubset_to_finset Set.Finite.toFinset_ssubset_toFinset
alias ⟨_, toFinset_mono⟩ := Finite.toFinset_subset_toFinset
#align set.finite.to_finset_mono Set.Finite.toFinset_mono
alias ⟨_, toFinset_strictMono⟩ := Finite.toFinset_ssubset_toFinset
#align set.finite.to_finset_strict_mono Set.Finite.toFinset_strictMono
-- Porting note: attribute [protected] doesn't work
-- attribute [protected] toFinset_mono toFinset_strictMono
-- Porting note: `simp` can simplify LHS but then it simplifies something
-- in the generated `Fintype {x | p x}` instance and fails to apply `Set.toFinset_setOf`
@[simp high]
protected theorem toFinset_setOf [Fintype α] (p : α → Prop) [DecidablePred p]
(h : { x | p x }.Finite) : h.toFinset = Finset.univ.filter p := by
ext
-- Porting note: `simp` doesn't use the `simp` lemma `Set.toFinset_setOf` without the `_`
simp [Set.toFinset_setOf _]
#align set.finite.to_finset_set_of Set.Finite.toFinset_setOf
@[simp]
nonrec theorem disjoint_toFinset {hs : s.Finite} {ht : t.Finite} :
Disjoint hs.toFinset ht.toFinset ↔ Disjoint s t :=
@disjoint_toFinset _ _ _ hs.fintype ht.fintype
#align set.finite.disjoint_to_finset Set.Finite.disjoint_toFinset
protected theorem toFinset_inter [DecidableEq α] (hs : s.Finite) (ht : t.Finite)
(h : (s ∩ t).Finite) : h.toFinset = hs.toFinset ∩ ht.toFinset := by
ext
simp
#align set.finite.to_finset_inter Set.Finite.toFinset_inter
protected theorem toFinset_union [DecidableEq α] (hs : s.Finite) (ht : t.Finite)
(h : (s ∪ t).Finite) : h.toFinset = hs.toFinset ∪ ht.toFinset := by
ext
simp
#align set.finite.to_finset_union Set.Finite.toFinset_union
protected theorem toFinset_diff [DecidableEq α] (hs : s.Finite) (ht : t.Finite)
(h : (s \ t).Finite) : h.toFinset = hs.toFinset \ ht.toFinset := by
ext
simp
#align set.finite.to_finset_diff Set.Finite.toFinset_diff
open scoped symmDiff in
protected theorem toFinset_symmDiff [DecidableEq α] (hs : s.Finite) (ht : t.Finite)
(h : (s ∆ t).Finite) : h.toFinset = hs.toFinset ∆ ht.toFinset := by
ext
simp [mem_symmDiff, Finset.mem_symmDiff]
#align set.finite.to_finset_symm_diff Set.Finite.toFinset_symmDiff
protected theorem toFinset_compl [DecidableEq α] [Fintype α] (hs : s.Finite) (h : sᶜ.Finite) :
h.toFinset = hs.toFinsetᶜ := by
ext
simp
#align set.finite.to_finset_compl Set.Finite.toFinset_compl
protected theorem toFinset_univ [Fintype α] (h : (Set.univ : Set α).Finite) :
h.toFinset = Finset.univ := by
simp
#align set.finite.to_finset_univ Set.Finite.toFinset_univ
@[simp]
protected theorem toFinset_eq_empty {h : s.Finite} : h.toFinset = ∅ ↔ s = ∅ :=
@toFinset_eq_empty _ _ h.fintype
#align set.finite.to_finset_eq_empty Set.Finite.toFinset_eq_empty
protected theorem toFinset_empty (h : (∅ : Set α).Finite) : h.toFinset = ∅ := by
simp
#align set.finite.to_finset_empty Set.Finite.toFinset_empty
@[simp]
protected theorem toFinset_eq_univ [Fintype α] {h : s.Finite} :
h.toFinset = Finset.univ ↔ s = univ :=
@toFinset_eq_univ _ _ _ h.fintype
#align set.finite.to_finset_eq_univ Set.Finite.toFinset_eq_univ
protected theorem toFinset_image [DecidableEq β] (f : α → β) (hs : s.Finite) (h : (f '' s).Finite) :
h.toFinset = hs.toFinset.image f := by
ext
simp
#align set.finite.to_finset_image Set.Finite.toFinset_image
-- Porting note (#10618): now `simp` can prove it but it needs the `fintypeRange` instance
-- from the next section
protected theorem toFinset_range [DecidableEq α] [Fintype β] (f : β → α) (h : (range f).Finite) :
h.toFinset = Finset.univ.image f := by
ext
simp
#align set.finite.to_finset_range Set.Finite.toFinset_range
end Finite
/-! ### Fintype instances
Every instance here should have a corresponding `Set.Finite` constructor in the next section.
-/
section FintypeInstances
instance fintypeUniv [Fintype α] : Fintype (@univ α) :=
Fintype.ofEquiv α (Equiv.Set.univ α).symm
#align set.fintype_univ Set.fintypeUniv
/-- If `(Set.univ : Set α)` is finite then `α` is a finite type. -/
noncomputable def fintypeOfFiniteUniv (H : (univ (α := α)).Finite) : Fintype α :=
@Fintype.ofEquiv _ (univ : Set α) H.fintype (Equiv.Set.univ _)
#align set.fintype_of_finite_univ Set.fintypeOfFiniteUniv
instance fintypeUnion [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] :
Fintype (s ∪ t : Set α) :=
Fintype.ofFinset (s.toFinset ∪ t.toFinset) <| by simp
#align set.fintype_union Set.fintypeUnion
instance fintypeSep (s : Set α) (p : α → Prop) [Fintype s] [DecidablePred p] :
Fintype ({ a ∈ s | p a } : Set α) :=
Fintype.ofFinset (s.toFinset.filter p) <| by simp
#align set.fintype_sep Set.fintypeSep
instance fintypeInter (s t : Set α) [DecidableEq α] [Fintype s] [Fintype t] :
Fintype (s ∩ t : Set α) :=
Fintype.ofFinset (s.toFinset ∩ t.toFinset) <| by simp
#align set.fintype_inter Set.fintypeInter
/-- A `Fintype` instance for set intersection where the left set has a `Fintype` instance. -/
instance fintypeInterOfLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] :
Fintype (s ∩ t : Set α) :=
Fintype.ofFinset (s.toFinset.filter (· ∈ t)) <| by simp
#align set.fintype_inter_of_left Set.fintypeInterOfLeft
/-- A `Fintype` instance for set intersection where the right set has a `Fintype` instance. -/
instance fintypeInterOfRight (s t : Set α) [Fintype t] [DecidablePred (· ∈ s)] :
Fintype (s ∩ t : Set α) :=
Fintype.ofFinset (t.toFinset.filter (· ∈ s)) <| by simp [and_comm]
#align set.fintype_inter_of_right Set.fintypeInterOfRight
/-- A `Fintype` structure on a set defines a `Fintype` structure on its subset. -/
def fintypeSubset (s : Set α) {t : Set α} [Fintype s] [DecidablePred (· ∈ t)] (h : t ⊆ s) :
Fintype t := by
rw [← inter_eq_self_of_subset_right h]
apply Set.fintypeInterOfLeft
#align set.fintype_subset Set.fintypeSubset
instance fintypeDiff [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] :
Fintype (s \ t : Set α) :=
Fintype.ofFinset (s.toFinset \ t.toFinset) <| by simp
#align set.fintype_diff Set.fintypeDiff
instance fintypeDiffLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] :
Fintype (s \ t : Set α) :=
Set.fintypeSep s (· ∈ tᶜ)
#align set.fintype_diff_left Set.fintypeDiffLeft
instance fintypeiUnion [DecidableEq α] [Fintype (PLift ι)] (f : ι → Set α) [∀ i, Fintype (f i)] :
Fintype (⋃ i, f i) :=
Fintype.ofFinset (Finset.univ.biUnion fun i : PLift ι => (f i.down).toFinset) <| by simp
#align set.fintype_Union Set.fintypeiUnion
instance fintypesUnion [DecidableEq α] {s : Set (Set α)} [Fintype s]
[H : ∀ t : s, Fintype (t : Set α)] : Fintype (⋃₀ s) := by
rw [sUnion_eq_iUnion]
exact @Set.fintypeiUnion _ _ _ _ _ H
#align set.fintype_sUnion Set.fintypesUnion
/-- A union of sets with `Fintype` structure over a set with `Fintype` structure has a `Fintype`
structure. -/
def fintypeBiUnion [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α)
(H : ∀ i ∈ s, Fintype (t i)) : Fintype (⋃ x ∈ s, t x) :=
haveI : ∀ i : toFinset s, Fintype (t i) := fun i => H i (mem_toFinset.1 i.2)
Fintype.ofFinset (s.toFinset.attach.biUnion fun x => (t x).toFinset) fun x => by simp
#align set.fintype_bUnion Set.fintypeBiUnion
instance fintypeBiUnion' [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α)
[∀ i, Fintype (t i)] : Fintype (⋃ x ∈ s, t x) :=
Fintype.ofFinset (s.toFinset.biUnion fun x => (t x).toFinset) <| by simp
#align set.fintype_bUnion' Set.fintypeBiUnion'
section monad
attribute [local instance] Set.monad
/-- If `s : Set α` is a set with `Fintype` instance and `f : α → Set β` is a function such that
each `f a`, `a ∈ s`, has a `Fintype` structure, then `s >>= f` has a `Fintype` structure. -/
def fintypeBind {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β)
(H : ∀ a ∈ s, Fintype (f a)) : Fintype (s >>= f) :=
Set.fintypeBiUnion s f H
#align set.fintype_bind Set.fintypeBind
instance fintypeBind' {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β)
[∀ a, Fintype (f a)] : Fintype (s >>= f) :=
Set.fintypeBiUnion' s f
#align set.fintype_bind' Set.fintypeBind'
end monad
instance fintypeEmpty : Fintype (∅ : Set α) :=
Fintype.ofFinset ∅ <| by simp
#align set.fintype_empty Set.fintypeEmpty
instance fintypeSingleton (a : α) : Fintype ({a} : Set α) :=
Fintype.ofFinset {a} <| by simp
#align set.fintype_singleton Set.fintypeSingleton
instance fintypePure : ∀ a : α, Fintype (pure a : Set α) :=
Set.fintypeSingleton
#align set.fintype_pure Set.fintypePure
/-- A `Fintype` instance for inserting an element into a `Set` using the
corresponding `insert` function on `Finset`. This requires `DecidableEq α`.
There is also `Set.fintypeInsert'` when `a ∈ s` is decidable. -/
instance fintypeInsert (a : α) (s : Set α) [DecidableEq α] [Fintype s] :
Fintype (insert a s : Set α) :=
Fintype.ofFinset (insert a s.toFinset) <| by simp
#align set.fintype_insert Set.fintypeInsert
/-- A `Fintype` structure on `insert a s` when inserting a new element. -/
def fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉ s) :
Fintype (insert a s : Set α) :=
Fintype.ofFinset ⟨a ::ₘ s.toFinset.1, s.toFinset.nodup.cons (by simp [h])⟩ <| by simp
#align set.fintype_insert_of_not_mem Set.fintypeInsertOfNotMem
/-- A `Fintype` structure on `insert a s` when inserting a pre-existing element. -/
def fintypeInsertOfMem {a : α} (s : Set α) [Fintype s] (h : a ∈ s) : Fintype (insert a s : Set α) :=
Fintype.ofFinset s.toFinset <| by simp [h]
#align set.fintype_insert_of_mem Set.fintypeInsertOfMem
/-- The `Set.fintypeInsert` instance requires decidable equality, but when `a ∈ s`
is decidable for this particular `a` we can still get a `Fintype` instance by using
`Set.fintypeInsertOfNotMem` or `Set.fintypeInsertOfMem`.
This instance pre-dates `Set.fintypeInsert`, and it is less efficient.
When `Set.decidableMemOfFintype` is made a local instance, then this instance would
override `Set.fintypeInsert` if not for the fact that its priority has been
adjusted. See Note [lower instance priority]. -/
instance (priority := 100) fintypeInsert' (a : α) (s : Set α) [Decidable <| a ∈ s] [Fintype s] :
Fintype (insert a s : Set α) :=
if h : a ∈ s then fintypeInsertOfMem s h else fintypeInsertOfNotMem s h
#align set.fintype_insert' Set.fintypeInsert'
instance fintypeImage [DecidableEq β] (s : Set α) (f : α → β) [Fintype s] : Fintype (f '' s) :=
Fintype.ofFinset (s.toFinset.image f) <| by simp
#align set.fintype_image Set.fintypeImage
/-- If a function `f` has a partial inverse and sends a set `s` to a set with `[Fintype]` instance,
then `s` has a `Fintype` structure as well. -/
def fintypeOfFintypeImage (s : Set α) {f : α → β} {g} (I : IsPartialInv f g) [Fintype (f '' s)] :
Fintype s :=
Fintype.ofFinset ⟨_, (f '' s).toFinset.2.filterMap g <| injective_of_isPartialInv_right I⟩
fun a => by
suffices (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s by
simpa [exists_and_left.symm, and_comm, and_left_comm, and_assoc]
rw [exists_swap]
suffices (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s by simpa [and_comm, and_left_comm, and_assoc]
simp [I _, (injective_of_isPartialInv I).eq_iff]
#align set.fintype_of_fintype_image Set.fintypeOfFintypeImage
instance fintypeRange [DecidableEq α] (f : ι → α) [Fintype (PLift ι)] : Fintype (range f) :=
Fintype.ofFinset (Finset.univ.image <| f ∘ PLift.down) <| by simp
#align set.fintype_range Set.fintypeRange
instance fintypeMap {α β} [DecidableEq β] :
∀ (s : Set α) (f : α → β) [Fintype s], Fintype (f <$> s) :=
Set.fintypeImage
#align set.fintype_map Set.fintypeMap
instance fintypeLTNat (n : ℕ) : Fintype { i | i < n } :=
Fintype.ofFinset (Finset.range n) <| by simp
#align set.fintype_lt_nat Set.fintypeLTNat
instance fintypeLENat (n : ℕ) : Fintype { i | i ≤ n } := by
simpa [Nat.lt_succ_iff] using Set.fintypeLTNat (n + 1)
#align set.fintype_le_nat Set.fintypeLENat
/-- This is not an instance so that it does not conflict with the one
in `Mathlib/Order/LocallyFinite.lean`. -/
def Nat.fintypeIio (n : ℕ) : Fintype (Iio n) :=
Set.fintypeLTNat n
#align set.nat.fintype_Iio Set.Nat.fintypeIio
instance fintypeProd (s : Set α) (t : Set β) [Fintype s] [Fintype t] :
Fintype (s ×ˢ t : Set (α × β)) :=
Fintype.ofFinset (s.toFinset ×ˢ t.toFinset) <| by simp
#align set.fintype_prod Set.fintypeProd
instance fintypeOffDiag [DecidableEq α] (s : Set α) [Fintype s] : Fintype s.offDiag :=
Fintype.ofFinset s.toFinset.offDiag <| by simp
#align set.fintype_off_diag Set.fintypeOffDiag
/-- `image2 f s t` is `Fintype` if `s` and `t` are. -/
instance fintypeImage2 [DecidableEq γ] (f : α → β → γ) (s : Set α) (t : Set β) [hs : Fintype s]
[ht : Fintype t] : Fintype (image2 f s t : Set γ) := by
rw [← image_prod]
apply Set.fintypeImage
#align set.fintype_image2 Set.fintypeImage2
instance fintypeSeq [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f] [Fintype s] :
Fintype (f.seq s) := by
rw [seq_def]
apply Set.fintypeBiUnion'
#align set.fintype_seq Set.fintypeSeq
instance fintypeSeq' {α β : Type u} [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f]
[Fintype s] : Fintype (f <*> s) :=
Set.fintypeSeq f s
#align set.fintype_seq' Set.fintypeSeq'
instance fintypeMemFinset (s : Finset α) : Fintype { a | a ∈ s } :=
Finset.fintypeCoeSort s
#align set.fintype_mem_finset Set.fintypeMemFinset
end FintypeInstances
end Set
theorem Equiv.set_finite_iff {s : Set α} {t : Set β} (hst : s ≃ t) : s.Finite ↔ t.Finite := by
simp_rw [← Set.finite_coe_iff, hst.finite_iff]
#align equiv.set_finite_iff Equiv.set_finite_iff
/-! ### Finset -/
namespace Finset
/-- Gives a `Set.Finite` for the `Finset` coerced to a `Set`.
This is a wrapper around `Set.toFinite`. -/
@[simp]
theorem finite_toSet (s : Finset α) : (s : Set α).Finite :=
Set.toFinite _
#align finset.finite_to_set Finset.finite_toSet
-- Porting note (#10618): was @[simp], now `simp` can prove it
theorem finite_toSet_toFinset (s : Finset α) : s.finite_toSet.toFinset = s := by
rw [toFinite_toFinset, toFinset_coe]
#align finset.finite_to_set_to_finset Finset.finite_toSet_toFinset
end Finset
namespace Multiset
@[simp]
theorem finite_toSet (s : Multiset α) : { x | x ∈ s }.Finite := by
classical simpa only [← Multiset.mem_toFinset] using s.toFinset.finite_toSet
#align multiset.finite_to_set Multiset.finite_toSet
@[simp]
theorem finite_toSet_toFinset [DecidableEq α] (s : Multiset α) :
s.finite_toSet.toFinset = s.toFinset := by
ext x
simp
#align multiset.finite_to_set_to_finset Multiset.finite_toSet_toFinset
end Multiset
@[simp]
theorem List.finite_toSet (l : List α) : { x | x ∈ l }.Finite :=
(show Multiset α from ⟦l⟧).finite_toSet
#align list.finite_to_set List.finite_toSet
/-! ### Finite instances
There is seemingly some overlap between the following instances and the `Fintype` instances
in `Data.Set.Finite`. While every `Fintype` instance gives a `Finite` instance, those
instances that depend on `Fintype` or `Decidable` instances need an additional `Finite` instance
to be able to generally apply.
Some set instances do not appear here since they are consequences of others, for example
`Subtype.Finite` for subsets of a finite type.
-/
namespace Finite.Set
open scoped Classical
example {s : Set α} [Finite α] : Finite s :=
inferInstance
example : Finite (∅ : Set α) :=
inferInstance
example (a : α) : Finite ({a} : Set α) :=
inferInstance
instance finite_union (s t : Set α) [Finite s] [Finite t] : Finite (s ∪ t : Set α) := by
cases nonempty_fintype s
cases nonempty_fintype t
infer_instance
#align finite.set.finite_union Finite.Set.finite_union
instance finite_sep (s : Set α) (p : α → Prop) [Finite s] : Finite ({ a ∈ s | p a } : Set α) := by
cases nonempty_fintype s
infer_instance
#align finite.set.finite_sep Finite.Set.finite_sep
protected theorem subset (s : Set α) {t : Set α} [Finite s] (h : t ⊆ s) : Finite t := by
rw [← sep_eq_of_subset h]
infer_instance
#align finite.set.subset Finite.Set.subset
instance finite_inter_of_right (s t : Set α) [Finite t] : Finite (s ∩ t : Set α) :=
Finite.Set.subset t inter_subset_right
#align finite.set.finite_inter_of_right Finite.Set.finite_inter_of_right
instance finite_inter_of_left (s t : Set α) [Finite s] : Finite (s ∩ t : Set α) :=
Finite.Set.subset s inter_subset_left
#align finite.set.finite_inter_of_left Finite.Set.finite_inter_of_left
instance finite_diff (s t : Set α) [Finite s] : Finite (s \ t : Set α) :=
Finite.Set.subset s diff_subset
#align finite.set.finite_diff Finite.Set.finite_diff
instance finite_range (f : ι → α) [Finite ι] : Finite (range f) := by
haveI := Fintype.ofFinite (PLift ι)
infer_instance
#align finite.set.finite_range Finite.Set.finite_range
instance finite_iUnion [Finite ι] (f : ι → Set α) [∀ i, Finite (f i)] : Finite (⋃ i, f i) := by
rw [iUnion_eq_range_psigma]
apply Set.finite_range
#align finite.set.finite_Union Finite.Set.finite_iUnion
instance finite_sUnion {s : Set (Set α)} [Finite s] [H : ∀ t : s, Finite (t : Set α)] :
Finite (⋃₀ s) := by
rw [sUnion_eq_iUnion]
exact @Finite.Set.finite_iUnion _ _ _ _ H
#align finite.set.finite_sUnion Finite.Set.finite_sUnion
theorem finite_biUnion {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α)
(H : ∀ i ∈ s, Finite (t i)) : Finite (⋃ x ∈ s, t x) := by
rw [biUnion_eq_iUnion]
haveI : ∀ i : s, Finite (t i) := fun i => H i i.property
infer_instance
#align finite.set.finite_bUnion Finite.Set.finite_biUnion
instance finite_biUnion' {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) [∀ i, Finite (t i)] :
Finite (⋃ x ∈ s, t x) :=
finite_biUnion s t fun _ _ => inferInstance
#align finite.set.finite_bUnion' Finite.Set.finite_biUnion'
/-- Example: `Finite (⋃ (i < n), f i)` where `f : ℕ → Set α` and `[∀ i, Finite (f i)]`
(when given instances from `Order.Interval.Finset.Nat`).
-/
instance finite_biUnion'' {ι : Type*} (p : ι → Prop) [h : Finite { x | p x }] (t : ι → Set α)
[∀ i, Finite (t i)] : Finite (⋃ (x) (_ : p x), t x) :=
@Finite.Set.finite_biUnion' _ _ (setOf p) h t _
#align finite.set.finite_bUnion'' Finite.Set.finite_biUnion''
instance finite_iInter {ι : Sort*} [Nonempty ι] (t : ι → Set α) [∀ i, Finite (t i)] :
Finite (⋂ i, t i) :=
Finite.Set.subset (t <| Classical.arbitrary ι) (iInter_subset _ _)
#align finite.set.finite_Inter Finite.Set.finite_iInter
instance finite_insert (a : α) (s : Set α) [Finite s] : Finite (insert a s : Set α) :=
Finite.Set.finite_union {a} s
#align finite.set.finite_insert Finite.Set.finite_insert
instance finite_image (s : Set α) (f : α → β) [Finite s] : Finite (f '' s) := by
cases nonempty_fintype s
infer_instance
#align finite.set.finite_image Finite.Set.finite_image
instance finite_replacement [Finite α] (f : α → β) :
Finite {f x | x : α} :=
Finite.Set.finite_range f
#align finite.set.finite_replacement Finite.Set.finite_replacement
instance finite_prod (s : Set α) (t : Set β) [Finite s] [Finite t] :
Finite (s ×ˢ t : Set (α × β)) :=
Finite.of_equiv _ (Equiv.Set.prod s t).symm
#align finite.set.finite_prod Finite.Set.finite_prod
instance finite_image2 (f : α → β → γ) (s : Set α) (t : Set β) [Finite s] [Finite t] :
Finite (image2 f s t : Set γ) := by
rw [← image_prod]
infer_instance
#align finite.set.finite_image2 Finite.Set.finite_image2
instance finite_seq (f : Set (α → β)) (s : Set α) [Finite f] [Finite s] : Finite (f.seq s) := by
rw [seq_def]
infer_instance
#align finite.set.finite_seq Finite.Set.finite_seq
end Finite.Set
namespace Set
/-! ### Constructors for `Set.Finite`
Every constructor here should have a corresponding `Fintype` instance in the previous section
(or in the `Fintype` module).
The implementation of these constructors ideally should be no more than `Set.toFinite`,
after possibly setting up some `Fintype` and classical `Decidable` instances.
-/
section SetFiniteConstructors
@[nontriviality]
theorem Finite.of_subsingleton [Subsingleton α] (s : Set α) : s.Finite :=
s.toFinite
#align set.finite.of_subsingleton Set.Finite.of_subsingleton
theorem finite_univ [Finite α] : (@univ α).Finite :=
Set.toFinite _
#align set.finite_univ Set.finite_univ
theorem finite_univ_iff : (@univ α).Finite ↔ Finite α := (Equiv.Set.univ α).finite_iff
#align set.finite_univ_iff Set.finite_univ_iff
alias ⟨_root_.Finite.of_finite_univ, _⟩ := finite_univ_iff
#align finite.of_finite_univ Finite.of_finite_univ
theorem Finite.subset {s : Set α} (hs : s.Finite) {t : Set α} (ht : t ⊆ s) : t.Finite := by
have := hs.to_subtype
exact Finite.Set.subset _ ht
#align set.finite.subset Set.Finite.subset
theorem Finite.union {s t : Set α} (hs : s.Finite) (ht : t.Finite) : (s ∪ t).Finite := by
rw [Set.Finite] at hs ht
apply toFinite
#align set.finite.union Set.Finite.union
theorem Finite.finite_of_compl {s : Set α} (hs : s.Finite) (hsc : sᶜ.Finite) : Finite α := by
rw [← finite_univ_iff, ← union_compl_self s]
exact hs.union hsc
#align set.finite.finite_of_compl Set.Finite.finite_of_compl
theorem Finite.sup {s t : Set α} : s.Finite → t.Finite → (s ⊔ t).Finite :=
Finite.union
#align set.finite.sup Set.Finite.sup
theorem Finite.sep {s : Set α} (hs : s.Finite) (p : α → Prop) : { a ∈ s | p a }.Finite :=
hs.subset <| sep_subset _ _
#align set.finite.sep Set.Finite.sep
theorem Finite.inter_of_left {s : Set α} (hs : s.Finite) (t : Set α) : (s ∩ t).Finite :=
hs.subset inter_subset_left
#align set.finite.inter_of_left Set.Finite.inter_of_left
theorem Finite.inter_of_right {s : Set α} (hs : s.Finite) (t : Set α) : (t ∩ s).Finite :=
hs.subset inter_subset_right
#align set.finite.inter_of_right Set.Finite.inter_of_right
theorem Finite.inf_of_left {s : Set α} (h : s.Finite) (t : Set α) : (s ⊓ t).Finite :=
h.inter_of_left t
#align set.finite.inf_of_left Set.Finite.inf_of_left
theorem Finite.inf_of_right {s : Set α} (h : s.Finite) (t : Set α) : (t ⊓ s).Finite :=
h.inter_of_right t
#align set.finite.inf_of_right Set.Finite.inf_of_right
protected lemma Infinite.mono {s t : Set α} (h : s ⊆ t) : s.Infinite → t.Infinite :=
mt fun ht ↦ ht.subset h
#align set.infinite.mono Set.Infinite.mono
theorem Finite.diff {s : Set α} (hs : s.Finite) (t : Set α) : (s \ t).Finite :=
hs.subset diff_subset
#align set.finite.diff Set.Finite.diff
theorem Finite.of_diff {s t : Set α} (hd : (s \ t).Finite) (ht : t.Finite) : s.Finite :=
(hd.union ht).subset <| subset_diff_union _ _
#align set.finite.of_diff Set.Finite.of_diff
theorem finite_iUnion [Finite ι] {f : ι → Set α} (H : ∀ i, (f i).Finite) : (⋃ i, f i).Finite :=
haveI := fun i => (H i).to_subtype
toFinite _
#align set.finite_Union Set.finite_iUnion
/-- Dependent version of `Finite.biUnion`. -/
theorem Finite.biUnion' {ι} {s : Set ι} (hs : s.Finite) {t : ∀ i ∈ s, Set α}
(ht : ∀ i (hi : i ∈ s), (t i hi).Finite) : (⋃ i ∈ s, t i ‹_›).Finite := by
have := hs.to_subtype
rw [biUnion_eq_iUnion]
apply finite_iUnion fun i : s => ht i.1 i.2
#align set.finite.bUnion' Set.Finite.biUnion'
theorem Finite.biUnion {ι} {s : Set ι} (hs : s.Finite) {t : ι → Set α}
(ht : ∀ i ∈ s, (t i).Finite) : (⋃ i ∈ s, t i).Finite :=
hs.biUnion' ht
#align set.finite.bUnion Set.Finite.biUnion
theorem Finite.sUnion {s : Set (Set α)} (hs : s.Finite) (H : ∀ t ∈ s, Set.Finite t) :
(⋃₀ s).Finite := by
simpa only [sUnion_eq_biUnion] using hs.biUnion H
#align set.finite.sUnion Set.Finite.sUnion
theorem Finite.sInter {α : Type*} {s : Set (Set α)} {t : Set α} (ht : t ∈ s) (hf : t.Finite) :
(⋂₀ s).Finite :=
hf.subset (sInter_subset_of_mem ht)
#align set.finite.sInter Set.Finite.sInter
/-- If sets `s i` are finite for all `i` from a finite set `t` and are empty for `i ∉ t`, then the
union `⋃ i, s i` is a finite set. -/
theorem Finite.iUnion {ι : Type*} {s : ι → Set α} {t : Set ι} (ht : t.Finite)
(hs : ∀ i ∈ t, (s i).Finite) (he : ∀ i, i ∉ t → s i = ∅) : (⋃ i, s i).Finite := by
suffices ⋃ i, s i ⊆ ⋃ i ∈ t, s i by exact (ht.biUnion hs).subset this
refine iUnion_subset fun i x hx => ?_
by_cases hi : i ∈ t
· exact mem_biUnion hi hx
· rw [he i hi, mem_empty_iff_false] at hx
contradiction
#align set.finite.Union Set.Finite.iUnion
section monad
attribute [local instance] Set.monad
theorem Finite.bind {α β} {s : Set α} {f : α → Set β} (h : s.Finite) (hf : ∀ a ∈ s, (f a).Finite) :
(s >>= f).Finite :=
h.biUnion hf
#align set.finite.bind Set.Finite.bind
end monad
@[simp]
theorem finite_empty : (∅ : Set α).Finite :=
toFinite _
#align set.finite_empty Set.finite_empty
protected theorem Infinite.nonempty {s : Set α} (h : s.Infinite) : s.Nonempty :=
nonempty_iff_ne_empty.2 <| by
rintro rfl
exact h finite_empty
#align set.infinite.nonempty Set.Infinite.nonempty
@[simp]
theorem finite_singleton (a : α) : ({a} : Set α).Finite :=
toFinite _
#align set.finite_singleton Set.finite_singleton
theorem finite_pure (a : α) : (pure a : Set α).Finite :=
toFinite _
#align set.finite_pure Set.finite_pure
@[simp]
protected theorem Finite.insert (a : α) {s : Set α} (hs : s.Finite) : (insert a s).Finite :=
(finite_singleton a).union hs
#align set.finite.insert Set.Finite.insert
theorem Finite.image {s : Set α} (f : α → β) (hs : s.Finite) : (f '' s).Finite := by
have := hs.to_subtype
apply toFinite
#align set.finite.image Set.Finite.image
theorem finite_range (f : ι → α) [Finite ι] : (range f).Finite :=
toFinite _
#align set.finite_range Set.finite_range
lemma Finite.of_surjOn {s : Set α} {t : Set β} (f : α → β) (hf : SurjOn f s t) (hs : s.Finite) :
t.Finite := (hs.image _).subset hf
theorem Finite.dependent_image {s : Set α} (hs : s.Finite) (F : ∀ i ∈ s, β) :
{y : β | ∃ x hx, F x hx = y}.Finite := by
have := hs.to_subtype
simpa [range] using finite_range fun x : s => F x x.2
#align set.finite.dependent_image Set.Finite.dependent_image
theorem Finite.map {α β} {s : Set α} : ∀ f : α → β, s.Finite → (f <$> s).Finite :=
Finite.image
#align set.finite.map Set.Finite.map
theorem Finite.of_finite_image {s : Set α} {f : α → β} (h : (f '' s).Finite) (hi : Set.InjOn f s) :
s.Finite :=
have := h.to_subtype
.of_injective _ hi.bijOn_image.bijective.injective
#align set.finite.of_finite_image Set.Finite.of_finite_image
section preimage
variable {f : α → β} {s : Set β}
theorem finite_of_finite_preimage (h : (f ⁻¹' s).Finite) (hs : s ⊆ range f) : s.Finite := by
rw [← image_preimage_eq_of_subset hs]
exact Finite.image f h
#align set.finite_of_finite_preimage Set.finite_of_finite_preimage
theorem Finite.of_preimage (h : (f ⁻¹' s).Finite) (hf : Surjective f) : s.Finite :=
hf.image_preimage s ▸ h.image _
#align set.finite.of_preimage Set.Finite.of_preimage
theorem Finite.preimage (I : Set.InjOn f (f ⁻¹' s)) (h : s.Finite) : (f ⁻¹' s).Finite :=
(h.subset (image_preimage_subset f s)).of_finite_image I
#align set.finite.preimage Set.Finite.preimage
protected lemma Infinite.preimage (hs : s.Infinite) (hf : s ⊆ range f) : (f ⁻¹' s).Infinite :=
fun h ↦ hs <| finite_of_finite_preimage h hf
lemma Infinite.preimage' (hs : (s ∩ range f).Infinite) : (f ⁻¹' s).Infinite :=
(hs.preimage inter_subset_right).mono <| preimage_mono inter_subset_left
theorem Finite.preimage_embedding {s : Set β} (f : α ↪ β) (h : s.Finite) : (f ⁻¹' s).Finite :=
h.preimage fun _ _ _ _ h' => f.injective h'
#align set.finite.preimage_embedding Set.Finite.preimage_embedding
end preimage
theorem finite_lt_nat (n : ℕ) : Set.Finite { i | i < n } :=
toFinite _
#align set.finite_lt_nat Set.finite_lt_nat
theorem finite_le_nat (n : ℕ) : Set.Finite { i | i ≤ n } :=
toFinite _
#align set.finite_le_nat Set.finite_le_nat
section MapsTo
variable {s : Set α} {f : α → α} (hs : s.Finite) (hm : MapsTo f s s)
theorem Finite.surjOn_iff_bijOn_of_mapsTo : SurjOn f s s ↔ BijOn f s s := by
refine ⟨fun h ↦ ⟨hm, ?_, h⟩, BijOn.surjOn⟩
have : Finite s := finite_coe_iff.mpr hs
exact hm.restrict_inj.mp (Finite.injective_iff_surjective.mpr <| hm.restrict_surjective_iff.mpr h)
theorem Finite.injOn_iff_bijOn_of_mapsTo : InjOn f s ↔ BijOn f s s := by
refine ⟨fun h ↦ ⟨hm, h, ?_⟩, BijOn.injOn⟩
have : Finite s := finite_coe_iff.mpr hs
exact hm.restrict_surjective_iff.mp (Finite.injective_iff_surjective.mp <| hm.restrict_inj.mpr h)
end MapsTo
section Prod
variable {s : Set α} {t : Set β}
protected theorem Finite.prod (hs : s.Finite) (ht : t.Finite) : (s ×ˢ t : Set (α × β)).Finite := by
have := hs.to_subtype
have := ht.to_subtype
apply toFinite
#align set.finite.prod Set.Finite.prod
theorem Finite.of_prod_left (h : (s ×ˢ t : Set (α × β)).Finite) : t.Nonempty → s.Finite :=
fun ⟨b, hb⟩ => (h.image Prod.fst).subset fun a ha => ⟨(a, b), ⟨ha, hb⟩, rfl⟩
#align set.finite.of_prod_left Set.Finite.of_prod_left
theorem Finite.of_prod_right (h : (s ×ˢ t : Set (α × β)).Finite) : s.Nonempty → t.Finite :=
fun ⟨a, ha⟩ => (h.image Prod.snd).subset fun b hb => ⟨(a, b), ⟨ha, hb⟩, rfl⟩
#align set.finite.of_prod_right Set.Finite.of_prod_right
protected theorem Infinite.prod_left (hs : s.Infinite) (ht : t.Nonempty) : (s ×ˢ t).Infinite :=
fun h => hs <| h.of_prod_left ht
#align set.infinite.prod_left Set.Infinite.prod_left
protected theorem Infinite.prod_right (ht : t.Infinite) (hs : s.Nonempty) : (s ×ˢ t).Infinite :=
fun h => ht <| h.of_prod_right hs
#align set.infinite.prod_right Set.Infinite.prod_right
protected theorem infinite_prod :
(s ×ˢ t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by
refine ⟨fun h => ?_, ?_⟩
· simp_rw [Set.Infinite, @and_comm ¬_, ← Classical.not_imp]
by_contra!
exact h ((this.1 h.nonempty.snd).prod <| this.2 h.nonempty.fst)
· rintro (h | h)
· exact h.1.prod_left h.2
· exact h.1.prod_right h.2
#align set.infinite_prod Set.infinite_prod
theorem finite_prod : (s ×ˢ t).Finite ↔ (s.Finite ∨ t = ∅) ∧ (t.Finite ∨ s = ∅) := by
simp only [← not_infinite, Set.infinite_prod, not_or, not_and_or, not_nonempty_iff_eq_empty]
#align set.finite_prod Set.finite_prod
protected theorem Finite.offDiag {s : Set α} (hs : s.Finite) : s.offDiag.Finite :=
(hs.prod hs).subset s.offDiag_subset_prod
#align set.finite.off_diag Set.Finite.offDiag
protected theorem Finite.image2 (f : α → β → γ) (hs : s.Finite) (ht : t.Finite) :
(image2 f s t).Finite := by
have := hs.to_subtype
have := ht.to_subtype
apply toFinite
#align set.finite.image2 Set.Finite.image2
end Prod
theorem Finite.seq {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) :
(f.seq s).Finite :=
hf.image2 _ hs
#align set.finite.seq Set.Finite.seq
theorem Finite.seq' {α β : Type u} {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) :
(f <*> s).Finite :=
hf.seq hs
#align set.finite.seq' Set.Finite.seq'
theorem finite_mem_finset (s : Finset α) : { a | a ∈ s }.Finite :=
toFinite _
#align set.finite_mem_finset Set.finite_mem_finset
theorem Subsingleton.finite {s : Set α} (h : s.Subsingleton) : s.Finite :=
h.induction_on finite_empty finite_singleton
#align set.subsingleton.finite Set.Subsingleton.finite
theorem Infinite.nontrivial {s : Set α} (hs : s.Infinite) : s.Nontrivial :=
not_subsingleton_iff.1 <| mt Subsingleton.finite hs
theorem finite_preimage_inl_and_inr {s : Set (Sum α β)} :
(Sum.inl ⁻¹' s).Finite ∧ (Sum.inr ⁻¹' s).Finite ↔ s.Finite :=
⟨fun h => image_preimage_inl_union_image_preimage_inr s ▸ (h.1.image _).union (h.2.image _),
fun h => ⟨h.preimage Sum.inl_injective.injOn, h.preimage Sum.inr_injective.injOn⟩⟩
#align set.finite_preimage_inl_and_inr Set.finite_preimage_inl_and_inr
theorem exists_finite_iff_finset {p : Set α → Prop} :
(∃ s : Set α, s.Finite ∧ p s) ↔ ∃ s : Finset α, p ↑s :=
⟨fun ⟨_, hs, hps⟩ => ⟨hs.toFinset, hs.coe_toFinset.symm ▸ hps⟩, fun ⟨s, hs⟩ =>
⟨s, s.finite_toSet, hs⟩⟩
#align set.exists_finite_iff_finset Set.exists_finite_iff_finset
/-- There are finitely many subsets of a given finite set -/
theorem Finite.finite_subsets {α : Type u} {a : Set α} (h : a.Finite) : { b | b ⊆ a }.Finite := by
convert ((Finset.powerset h.toFinset).map Finset.coeEmb.1).finite_toSet
ext s
simpa [← @exists_finite_iff_finset α fun t => t ⊆ a ∧ t = s, Finite.subset_toFinset,
← and_assoc, Finset.coeEmb] using h.subset
#align set.finite.finite_subsets Set.Finite.finite_subsets
section Pi
variable {ι : Type*} [Finite ι] {κ : ι → Type*} {t : ∀ i, Set (κ i)}
/-- Finite product of finite sets is finite -/
theorem Finite.pi (ht : ∀ i, (t i).Finite) : (pi univ t).Finite := by
cases nonempty_fintype ι
lift t to ∀ d, Finset (κ d) using ht
classical
rw [← Fintype.coe_piFinset]
apply Finset.finite_toSet
#align set.finite.pi Set.Finite.pi
/-- Finite product of finite sets is finite. Note this is a variant of `Set.Finite.pi` without the
extra `i ∈ univ` binder. -/
lemma Finite.pi' (ht : ∀ i, (t i).Finite) : {f : ∀ i, κ i | ∀ i, f i ∈ t i}.Finite := by
simpa [Set.pi] using Finite.pi ht
end Pi
/-- A finite union of finsets is finite. -/
theorem union_finset_finite_of_range_finite (f : α → Finset β) (h : (range f).Finite) :
(⋃ a, (f a : Set β)).Finite := by
rw [← biUnion_range]
exact h.biUnion fun y _ => y.finite_toSet
#align set.union_finset_finite_of_range_finite Set.union_finset_finite_of_range_finite
theorem finite_range_ite {p : α → Prop} [DecidablePred p] {f g : α → β} (hf : (range f).Finite)
(hg : (range g).Finite) : (range fun x => if p x then f x else g x).Finite :=
(hf.union hg).subset range_ite_subset
#align set.finite_range_ite Set.finite_range_ite
theorem finite_range_const {c : β} : (range fun _ : α => c).Finite :=
(finite_singleton c).subset range_const_subset
#align set.finite_range_const Set.finite_range_const
end SetFiniteConstructors
/-! ### Properties -/
instance Finite.inhabited : Inhabited { s : Set α // s.Finite } :=
⟨⟨∅, finite_empty⟩⟩
#align set.finite.inhabited Set.Finite.inhabited
@[simp]
theorem finite_union {s t : Set α} : (s ∪ t).Finite ↔ s.Finite ∧ t.Finite :=
⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun ⟨hs, ht⟩ =>
hs.union ht⟩
#align set.finite_union Set.finite_union
theorem finite_image_iff {s : Set α} {f : α → β} (hi : InjOn f s) : (f '' s).Finite ↔ s.Finite :=
⟨fun h => h.of_finite_image hi, Finite.image _⟩
#align set.finite_image_iff Set.finite_image_iff
theorem univ_finite_iff_nonempty_fintype : (univ : Set α).Finite ↔ Nonempty (Fintype α) :=
⟨fun h => ⟨fintypeOfFiniteUniv h⟩, fun ⟨_i⟩ => finite_univ⟩
#align set.univ_finite_iff_nonempty_fintype Set.univ_finite_iff_nonempty_fintype
-- Porting note: moved `@[simp]` to `Set.toFinset_singleton` because `simp` can now simplify LHS
theorem Finite.toFinset_singleton {a : α} (ha : ({a} : Set α).Finite := finite_singleton _) :
ha.toFinset = {a} :=
Set.toFinite_toFinset _
#align set.finite.to_finset_singleton Set.Finite.toFinset_singleton
@[simp]
theorem Finite.toFinset_insert [DecidableEq α] {s : Set α} {a : α} (hs : (insert a s).Finite) :
hs.toFinset = insert a (hs.subset <| subset_insert _ _).toFinset :=
Finset.ext <| by simp
#align set.finite.to_finset_insert Set.Finite.toFinset_insert
theorem Finite.toFinset_insert' [DecidableEq α] {a : α} {s : Set α} (hs : s.Finite) :
(hs.insert a).toFinset = insert a hs.toFinset :=
Finite.toFinset_insert _
#align set.finite.to_finset_insert' Set.Finite.toFinset_insert'
theorem Finite.toFinset_prod {s : Set α} {t : Set β} (hs : s.Finite) (ht : t.Finite) :
hs.toFinset ×ˢ ht.toFinset = (hs.prod ht).toFinset :=
Finset.ext <| by simp
#align set.finite.to_finset_prod Set.Finite.toFinset_prod
theorem Finite.toFinset_offDiag {s : Set α} [DecidableEq α] (hs : s.Finite) :
hs.offDiag.toFinset = hs.toFinset.offDiag :=
Finset.ext <| by simp
#align set.finite.to_finset_off_diag Set.Finite.toFinset_offDiag
theorem Finite.fin_embedding {s : Set α} (h : s.Finite) :
∃ (n : ℕ) (f : Fin n ↪ α), range f = s :=
⟨_, (Fintype.equivFin (h.toFinset : Set α)).symm.asEmbedding, by
simp only [Finset.coe_sort_coe, Equiv.asEmbedding_range, Finite.coe_toFinset, setOf_mem_eq]⟩
#align set.finite.fin_embedding Set.Finite.fin_embedding
theorem Finite.fin_param {s : Set α} (h : s.Finite) :
∃ (n : ℕ) (f : Fin n → α), Injective f ∧ range f = s :=
let ⟨n, f, hf⟩ := h.fin_embedding
⟨n, f, f.injective, hf⟩
#align set.finite.fin_param Set.Finite.fin_param
theorem finite_option {s : Set (Option α)} : s.Finite ↔ { x : α | some x ∈ s }.Finite :=
⟨fun h => h.preimage_embedding Embedding.some, fun h =>
((h.image some).insert none).subset fun x =>
x.casesOn (fun _ => Or.inl rfl) fun _ hx => Or.inr <| mem_image_of_mem _ hx⟩
#align set.finite_option Set.finite_option
theorem finite_image_fst_and_snd_iff {s : Set (α × β)} :
(Prod.fst '' s).Finite ∧ (Prod.snd '' s).Finite ↔ s.Finite :=
⟨fun h => (h.1.prod h.2).subset fun _ h => ⟨mem_image_of_mem _ h, mem_image_of_mem _ h⟩,
fun h => ⟨h.image _, h.image _⟩⟩
#align set.finite_image_fst_and_snd_iff Set.finite_image_fst_and_snd_iff
theorem forall_finite_image_eval_iff {δ : Type*} [Finite δ] {κ : δ → Type*} {s : Set (∀ d, κ d)} :
(∀ d, (eval d '' s).Finite) ↔ s.Finite :=
⟨fun h => (Finite.pi h).subset <| subset_pi_eval_image _ _, fun h _ => h.image _⟩
#align set.forall_finite_image_eval_iff Set.forall_finite_image_eval_iff
theorem finite_subset_iUnion {s : Set α} (hs : s.Finite) {ι} {t : ι → Set α} (h : s ⊆ ⋃ i, t i) :
∃ I : Set ι, I.Finite ∧ s ⊆ ⋃ i ∈ I, t i := by
have := hs.to_subtype
choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i by simpa [subset_def] using h
refine ⟨range f, finite_range f, fun x hx => ?_⟩
rw [biUnion_range, mem_iUnion]
exact ⟨⟨x, hx⟩, hf _⟩
#align set.finite_subset_Union Set.finite_subset_iUnion
theorem eq_finite_iUnion_of_finite_subset_iUnion {ι} {s : ι → Set α} {t : Set α} (tfin : t.Finite)
(h : t ⊆ ⋃ i, s i) :
∃ I : Set ι,
I.Finite ∧
∃ σ : { i | i ∈ I } → Set α, (∀ i, (σ i).Finite) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i :=
let ⟨I, Ifin, hI⟩ := finite_subset_iUnion tfin h
⟨I, Ifin, fun x => s x ∩ t, fun i => tfin.subset inter_subset_right, fun i =>
inter_subset_left, by
ext x
rw [mem_iUnion]
constructor
· intro x_in
rcases mem_iUnion.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩
exact ⟨⟨i, hi⟩, ⟨H, x_in⟩⟩
· rintro ⟨i, -, H⟩
exact H⟩
#align set.eq_finite_Union_of_finite_subset_Union Set.eq_finite_iUnion_of_finite_subset_iUnion
@[elab_as_elim]
theorem Finite.induction_on {C : Set α → Prop} {s : Set α} (h : s.Finite) (H0 : C ∅)
(H1 : ∀ {a s}, a ∉ s → Set.Finite s → C s → C (insert a s)) : C s := by
lift s to Finset α using h
induction' s using Finset.cons_induction_on with a s ha hs
· rwa [Finset.coe_empty]
· rw [Finset.coe_cons]
exact @H1 a s ha (Set.toFinite _) hs
#align set.finite.induction_on Set.Finite.induction_on
/-- Analogous to `Finset.induction_on'`. -/
@[elab_as_elim]
theorem Finite.induction_on' {C : Set α → Prop} {S : Set α} (h : S.Finite) (H0 : C ∅)
(H1 : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)) : C S := by
refine @Set.Finite.induction_on α (fun s => s ⊆ S → C s) S h (fun _ => H0) ?_ Subset.rfl
intro a s has _ hCs haS
rw [insert_subset_iff] at haS
exact H1 haS.1 haS.2 has (hCs haS.2)
#align set.finite.induction_on' Set.Finite.induction_on'
@[elab_as_elim]
theorem Finite.dinduction_on {C : ∀ s : Set α, s.Finite → Prop} (s : Set α) (h : s.Finite)
(H0 : C ∅ finite_empty)
(H1 : ∀ {a s}, a ∉ s → ∀ h : Set.Finite s, C s h → C (insert a s) (h.insert a)) : C s h :=
have : ∀ h : s.Finite, C s h :=
Finite.induction_on h (fun _ => H0) fun has hs ih _ => H1 has hs (ih _)
this h
#align set.finite.dinduction_on Set.Finite.dinduction_on
/-- Induction up to a finite set `S`. -/
theorem Finite.induction_to {C : Set α → Prop} {S : Set α} (h : S.Finite)
(S0 : Set α) (hS0 : S0 ⊆ S) (H0 : C S0) (H1 : ∀ s ⊂ S, C s → ∃ a ∈ S \ s, C (insert a s)) :
C S := by
have : Finite S := Finite.to_subtype h
have : Finite {T : Set α // T ⊆ S} := Finite.of_equiv (Set S) (Equiv.Set.powerset S).symm
rw [← Subtype.coe_mk (p := (· ⊆ S)) _ le_rfl]
rw [← Subtype.coe_mk (p := (· ⊆ S)) _ hS0] at H0
refine Finite.to_wellFoundedGT.wf.induction_bot' (fun s hs hs' ↦ ?_) H0
obtain ⟨a, ⟨ha1, ha2⟩, ha'⟩ := H1 s (ssubset_of_ne_of_subset hs s.2) hs'
exact ⟨⟨insert a s.1, insert_subset ha1 s.2⟩, Set.ssubset_insert ha2, ha'⟩
/-- Induction up to `univ`. -/
theorem Finite.induction_to_univ [Finite α] {C : Set α → Prop} (S0 : Set α)
(H0 : C S0) (H1 : ∀ S ≠ univ, C S → ∃ a ∉ S, C (insert a S)) : C univ :=
finite_univ.induction_to S0 (subset_univ S0) H0 (by simpa [ssubset_univ_iff])
section
attribute [local instance] Nat.fintypeIio
/-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set
`t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.
(We use this later to show sequentially compact sets are totally bounded.)
-/
theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop}
(h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by
haveI : Nonempty γ := (h ∅ finite_empty).nonempty
choose! c hc using h
set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2)
set u : ℕ → γ := fun n => Nat.strongRecOn' n f
refine ⟨u, fun n => ?_⟩
convert hc (u '' Iio n) ((finite_lt_nat _).image _)
rw [image_eq_range]
exact Nat.strongRecOn'_beta
#align set.seq_of_forall_finite_exists Set.seq_of_forall_finite_exists
end
/-! ### Cardinality -/
theorem empty_card : Fintype.card (∅ : Set α) = 0 :=
rfl
#align set.empty_card Set.empty_card
theorem empty_card' {h : Fintype.{u} (∅ : Set α)} : @Fintype.card (∅ : Set α) h = 0 := by
simp
#align set.empty_card' Set.empty_card'
theorem card_fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉ s) :
@Fintype.card _ (fintypeInsertOfNotMem s h) = Fintype.card s + 1 := by
simp [fintypeInsertOfNotMem, Fintype.card_ofFinset]
#align set.card_fintype_insert_of_not_mem Set.card_fintypeInsertOfNotMem
@[simp]
theorem card_insert {a : α} (s : Set α) [Fintype s] (h : a ∉ s)
{d : Fintype.{u} (insert a s : Set α)} : @Fintype.card _ d = Fintype.card s + 1 := by
rw [← card_fintypeInsertOfNotMem s h]; congr; exact Subsingleton.elim _ _
#align set.card_insert Set.card_insert
theorem card_image_of_inj_on {s : Set α} [Fintype s] {f : α → β} [Fintype (f '' s)]
(H : ∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y) : Fintype.card (f '' s) = Fintype.card s :=
haveI := Classical.propDecidable
calc
Fintype.card (f '' s) = (s.toFinset.image f).card := Fintype.card_of_finset' _ (by simp)
_ = s.toFinset.card :=
Finset.card_image_of_injOn fun x hx y hy hxy =>
H x (mem_toFinset.1 hx) y (mem_toFinset.1 hy) hxy
_ = Fintype.card s := (Fintype.card_of_finset' _ fun a => mem_toFinset).symm
#align set.card_image_of_inj_on Set.card_image_of_inj_on
theorem card_image_of_injective (s : Set α) [Fintype s] {f : α → β} [Fintype (f '' s)]
(H : Function.Injective f) : Fintype.card (f '' s) = Fintype.card s :=
card_image_of_inj_on fun _ _ _ _ h => H h
#align set.card_image_of_injective Set.card_image_of_injective
@[simp]
theorem card_singleton (a : α) : Fintype.card ({a} : Set α) = 1 :=
Fintype.card_ofSubsingleton _
#align set.card_singleton Set.card_singleton
theorem card_lt_card {s t : Set α} [Fintype s] [Fintype t] (h : s ⊂ t) :
Fintype.card s < Fintype.card t :=
Fintype.card_lt_of_injective_not_surjective (Set.inclusion h.1) (Set.inclusion_injective h.1)
fun hst => (ssubset_iff_subset_ne.1 h).2 (eq_of_inclusion_surjective hst)
#align set.card_lt_card Set.card_lt_card
theorem card_le_card {s t : Set α} [Fintype s] [Fintype t] (hsub : s ⊆ t) :
Fintype.card s ≤ Fintype.card t :=
Fintype.card_le_of_injective (Set.inclusion hsub) (Set.inclusion_injective hsub)
#align set.card_le_card Set.card_le_card
theorem eq_of_subset_of_card_le {s t : Set α} [Fintype s] [Fintype t] (hsub : s ⊆ t)
(hcard : Fintype.card t ≤ Fintype.card s) : s = t :=
(eq_or_ssubset_of_subset hsub).elim id fun h => absurd hcard <| not_le_of_lt <| card_lt_card h
#align set.eq_of_subset_of_card_le Set.eq_of_subset_of_card_le
theorem card_range_of_injective [Fintype α] {f : α → β} (hf : Injective f) [Fintype (range f)] :
Fintype.card (range f) = Fintype.card α :=
Eq.symm <| Fintype.card_congr <| Equiv.ofInjective f hf
#align set.card_range_of_injective Set.card_range_of_injective
theorem Finite.card_toFinset {s : Set α} [Fintype s] (h : s.Finite) :
h.toFinset.card = Fintype.card s :=
Eq.symm <| Fintype.card_of_finset' _ fun _ ↦ h.mem_toFinset
#align set.finite.card_to_finset Set.Finite.card_toFinset
theorem card_ne_eq [Fintype α] (a : α) [Fintype { x : α | x ≠ a }] :
Fintype.card { x : α | x ≠ a } = Fintype.card α - 1 := by
haveI := Classical.decEq α
rw [← toFinset_card, toFinset_setOf, Finset.filter_ne',
Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ]
#align set.card_ne_eq Set.card_ne_eq
/-! ### Infinite sets -/
variable {s t : Set α}
theorem infinite_univ_iff : (@univ α).Infinite ↔ Infinite α := by
rw [Set.Infinite, finite_univ_iff, not_finite_iff_infinite]
#align set.infinite_univ_iff Set.infinite_univ_iff
theorem infinite_univ [h : Infinite α] : (@univ α).Infinite :=
infinite_univ_iff.2 h
#align set.infinite_univ Set.infinite_univ
theorem infinite_coe_iff {s : Set α} : Infinite s ↔ s.Infinite :=
not_finite_iff_infinite.symm.trans finite_coe_iff.not
#align set.infinite_coe_iff Set.infinite_coe_iff
-- Porting note: something weird happened here
alias ⟨_, Infinite.to_subtype⟩ := infinite_coe_iff
#align set.infinite.to_subtype Set.Infinite.to_subtype
lemma Infinite.exists_not_mem_finite (hs : s.Infinite) (ht : t.Finite) : ∃ a, a ∈ s ∧ a ∉ t := by
by_contra! h; exact hs <| ht.subset h
lemma Infinite.exists_not_mem_finset (hs : s.Infinite) (t : Finset α) : ∃ a ∈ s, a ∉ t :=
hs.exists_not_mem_finite t.finite_toSet
#align set.infinite.exists_not_mem_finset Set.Infinite.exists_not_mem_finset
section Infinite
variable [Infinite α]
lemma Finite.exists_not_mem (hs : s.Finite) : ∃ a, a ∉ s := by
by_contra! h; exact infinite_univ (hs.subset fun a _ ↦ h _)
lemma _root_.Finset.exists_not_mem (s : Finset α) : ∃ a, a ∉ s := s.finite_toSet.exists_not_mem
end Infinite
/-- Embedding of `ℕ` into an infinite set. -/
noncomputable def Infinite.natEmbedding (s : Set α) (h : s.Infinite) : ℕ ↪ s :=
h.to_subtype.natEmbedding
#align set.infinite.nat_embedding Set.Infinite.natEmbedding
theorem Infinite.exists_subset_card_eq {s : Set α} (hs : s.Infinite) (n : ℕ) :
∃ t : Finset α, ↑t ⊆ s ∧ t.card = n :=
⟨((Finset.range n).map (hs.natEmbedding _)).map (Embedding.subtype _), by simp⟩
#align set.infinite.exists_subset_card_eq Set.Infinite.exists_subset_card_eq
theorem infinite_of_finite_compl [Infinite α] {s : Set α} (hs : sᶜ.Finite) : s.Infinite := fun h =>
Set.infinite_univ (by simpa using hs.union h)
#align set.infinite_of_finite_compl Set.infinite_of_finite_compl
theorem Finite.infinite_compl [Infinite α] {s : Set α} (hs : s.Finite) : sᶜ.Infinite := fun h =>
Set.infinite_univ (by simpa using hs.union h)
#align set.finite.infinite_compl Set.Finite.infinite_compl
theorem Infinite.diff {s t : Set α} (hs : s.Infinite) (ht : t.Finite) : (s \ t).Infinite := fun h =>
hs <| h.of_diff ht
#align set.infinite.diff Set.Infinite.diff
@[simp]
theorem infinite_union {s t : Set α} : (s ∪ t).Infinite ↔ s.Infinite ∨ t.Infinite := by
simp only [Set.Infinite, finite_union, not_and_or]
#align set.infinite_union Set.infinite_union
theorem Infinite.of_image (f : α → β) {s : Set α} (hs : (f '' s).Infinite) : s.Infinite :=
mt (Finite.image f) hs
#align set.infinite.of_image Set.Infinite.of_image
theorem infinite_image_iff {s : Set α} {f : α → β} (hi : InjOn f s) :
(f '' s).Infinite ↔ s.Infinite :=
not_congr <| finite_image_iff hi
#align set.infinite_image_iff Set.infinite_image_iff
theorem infinite_range_iff {f : α → β} (hi : Injective f) :
(range f).Infinite ↔ Infinite α := by
rw [← image_univ, infinite_image_iff hi.injOn, infinite_univ_iff]
alias ⟨_, Infinite.image⟩ := infinite_image_iff
#align set.infinite.image Set.Infinite.image
-- Porting note: attribute [protected] doesn't work
-- attribute [protected] infinite.image
section Image2
variable {f : α → β → γ} {s : Set α} {t : Set β} {a : α} {b : β}
protected theorem Infinite.image2_left (hs : s.Infinite) (hb : b ∈ t)
(hf : InjOn (fun a => f a b) s) : (image2 f s t).Infinite :=
(hs.image hf).mono <| image_subset_image2_left hb
#align set.infinite.image2_left Set.Infinite.image2_left
protected theorem Infinite.image2_right (ht : t.Infinite) (ha : a ∈ s) (hf : InjOn (f a) t) :
(image2 f s t).Infinite :=
(ht.image hf).mono <| image_subset_image2_right ha
#align set.infinite.image2_right Set.Infinite.image2_right
theorem infinite_image2 (hfs : ∀ b ∈ t, InjOn (fun a => f a b) s) (hft : ∀ a ∈ s, InjOn (f a) t) :
(image2 f s t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by
refine ⟨fun h => Set.infinite_prod.1 ?_, ?_⟩
· rw [← image_uncurry_prod] at h
exact h.of_image _
· rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩)
· exact hs.image2_left hb (hfs _ hb)
· exact ht.image2_right ha (hft _ ha)
#align set.infinite_image2 Set.infinite_image2
lemma finite_image2 (hfs : ∀ b ∈ t, InjOn (f · b) s) (hft : ∀ a ∈ s, InjOn (f a) t) :
(image2 f s t).Finite ↔ s.Finite ∧ t.Finite ∨ s = ∅ ∨ t = ∅ := by
rw [← not_infinite, infinite_image2 hfs hft]
simp [not_or, -not_and, not_and_or, not_nonempty_iff_eq_empty]
aesop
end Image2
theorem infinite_of_injOn_mapsTo {s : Set α} {t : Set β} {f : α → β} (hi : InjOn f s)
(hm : MapsTo f s t) (hs : s.Infinite) : t.Infinite :=
((infinite_image_iff hi).2 hs).mono (mapsTo'.mp hm)
#align set.infinite_of_inj_on_maps_to Set.infinite_of_injOn_mapsTo
theorem Infinite.exists_ne_map_eq_of_mapsTo {s : Set α} {t : Set β} {f : α → β} (hs : s.Infinite)
(hf : MapsTo f s t) (ht : t.Finite) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
contrapose! ht
exact infinite_of_injOn_mapsTo (fun x hx y hy => not_imp_not.1 (ht x hx y hy)) hf hs
#align set.infinite.exists_ne_map_eq_of_maps_to Set.Infinite.exists_ne_map_eq_of_mapsTo
theorem infinite_range_of_injective [Infinite α] {f : α → β} (hi : Injective f) :
(range f).Infinite := by
rw [← image_univ, infinite_image_iff hi.injOn]
exact infinite_univ
#align set.infinite_range_of_injective Set.infinite_range_of_injective
theorem infinite_of_injective_forall_mem [Infinite α] {s : Set β} {f : α → β} (hi : Injective f)
(hf : ∀ x : α, f x ∈ s) : s.Infinite := by
rw [← range_subset_iff] at hf
exact (infinite_range_of_injective hi).mono hf
#align set.infinite_of_injective_forall_mem Set.infinite_of_injective_forall_mem
theorem not_injOn_infinite_finite_image {f : α → β} {s : Set α} (h_inf : s.Infinite)
(h_fin : (f '' s).Finite) : ¬InjOn f s := by
have : Finite (f '' s) := finite_coe_iff.mpr h_fin
have : Infinite s := infinite_coe_iff.mpr h_inf
have h := not_injective_infinite_finite
((f '' s).codRestrict (s.restrict f) fun x => ⟨x, x.property, rfl⟩)
contrapose! h
rwa [injective_codRestrict, ← injOn_iff_injective]
#align set.not_inj_on_infinite_finite_image Set.not_injOn_infinite_finite_image
/-! ### Order properties -/
section Preorder
variable [Preorder α] [Nonempty α] {s : Set α}
| Mathlib/Data/Set/Finite.lean | 1,477 | 1,482 | theorem infinite_of_forall_exists_gt (h : ∀ a, ∃ b ∈ s, a < b) : s.Infinite := by |
inhabit α
set f : ℕ → α := fun n => Nat.recOn n (h default).choose fun _ a => (h a).choose
have hf : ∀ n, f n ∈ s := by rintro (_ | _) <;> exact (h _).choose_spec.1
exact infinite_of_injective_forall_mem
(strictMono_nat_of_lt_succ fun n => (h _).choose_spec.2).injective hf
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Scott Morrison
-/
import Mathlib.CategoryTheory.Subobject.Lattice
#align_import category_theory.subobject.limits from "leanprover-community/mathlib"@"956af7c76589f444f2e1313911bad16366ea476d"
/-!
# Specific subobjects
We define `equalizerSubobject`, `kernelSubobject` and `imageSubobject`, which are the subobjects
represented by the equalizer, kernel and image of (a pair of) morphism(s) and provide conditions
for `P.factors f`, where `P` is one of these special subobjects.
TODO: Add conditions for when `P` is a pullback subobject.
TODO: an iff characterisation of `(imageSubobject f).Factors h`
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Subobject Opposite
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace CategoryTheory
namespace Limits
section Equalizer
variable (f g : X ⟶ Y) [HasEqualizer f g]
/-- The equalizer of morphisms `f g : X ⟶ Y` as a `Subobject X`. -/
abbrev equalizerSubobject : Subobject X :=
Subobject.mk (equalizer.ι f g)
#align category_theory.limits.equalizer_subobject CategoryTheory.Limits.equalizerSubobject
/-- The underlying object of `equalizerSubobject f g` is (up to isomorphism!)
the same as the chosen object `equalizer f g`. -/
def equalizerSubobjectIso : (equalizerSubobject f g : C) ≅ equalizer f g :=
Subobject.underlyingIso (equalizer.ι f g)
#align category_theory.limits.equalizer_subobject_iso CategoryTheory.Limits.equalizerSubobjectIso
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow :
(equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = (equalizerSubobject f g).arrow := by
simp [equalizerSubobjectIso]
#align category_theory.limits.equalizer_subobject_arrow CategoryTheory.Limits.equalizerSubobject_arrow
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow' :
(equalizerSubobjectIso f g).inv ≫ (equalizerSubobject f g).arrow = equalizer.ι f g := by
simp [equalizerSubobjectIso]
#align category_theory.limits.equalizer_subobject_arrow' CategoryTheory.Limits.equalizerSubobject_arrow'
@[reassoc]
theorem equalizerSubobject_arrow_comp :
(equalizerSubobject f g).arrow ≫ f = (equalizerSubobject f g).arrow ≫ g := by
rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition]
#align category_theory.limits.equalizer_subobject_arrow_comp CategoryTheory.Limits.equalizerSubobject_arrow_comp
theorem equalizerSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = h ≫ g) :
(equalizerSubobject f g).Factors h :=
⟨equalizer.lift h w, by simp⟩
#align category_theory.limits.equalizer_subobject_factors CategoryTheory.Limits.equalizerSubobject_factors
theorem equalizerSubobject_factors_iff {W : C} (h : W ⟶ X) :
(equalizerSubobject f g).Factors h ↔ h ≫ f = h ≫ g :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp,
Category.assoc],
equalizerSubobject_factors f g h⟩
#align category_theory.limits.equalizer_subobject_factors_iff CategoryTheory.Limits.equalizerSubobject_factors_iff
end Equalizer
section Kernel
variable [HasZeroMorphisms C] (f : X ⟶ Y) [HasKernel f]
/-- The kernel of a morphism `f : X ⟶ Y` as a `Subobject X`. -/
abbrev kernelSubobject : Subobject X :=
Subobject.mk (kernel.ι f)
#align category_theory.limits.kernel_subobject CategoryTheory.Limits.kernelSubobject
/-- The underlying object of `kernelSubobject f` is (up to isomorphism!)
the same as the chosen object `kernel f`. -/
def kernelSubobjectIso : (kernelSubobject f : C) ≅ kernel f :=
Subobject.underlyingIso (kernel.ι f)
#align category_theory.limits.kernel_subobject_iso CategoryTheory.Limits.kernelSubobjectIso
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow :
(kernelSubobjectIso f).hom ≫ kernel.ι f = (kernelSubobject f).arrow := by
simp [kernelSubobjectIso]
#align category_theory.limits.kernel_subobject_arrow CategoryTheory.Limits.kernelSubobject_arrow
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow' :
(kernelSubobjectIso f).inv ≫ (kernelSubobject f).arrow = kernel.ι f := by
simp [kernelSubobjectIso]
#align category_theory.limits.kernel_subobject_arrow' CategoryTheory.Limits.kernelSubobject_arrow'
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow_comp : (kernelSubobject f).arrow ≫ f = 0 := by
rw [← kernelSubobject_arrow]
simp only [Category.assoc, kernel.condition, comp_zero]
#align category_theory.limits.kernel_subobject_arrow_comp CategoryTheory.Limits.kernelSubobject_arrow_comp
theorem kernelSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
(kernelSubobject f).Factors h :=
⟨kernel.lift _ h w, by simp⟩
#align category_theory.limits.kernel_subobject_factors CategoryTheory.Limits.kernelSubobject_factors
theorem kernelSubobject_factors_iff {W : C} (h : W ⟶ X) :
(kernelSubobject f).Factors h ↔ h ≫ f = 0 :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, kernelSubobject_arrow_comp,
comp_zero],
kernelSubobject_factors f h⟩
#align category_theory.limits.kernel_subobject_factors_iff CategoryTheory.Limits.kernelSubobject_factors_iff
/-- A factorisation of `h : W ⟶ X` through `kernelSubobject f`, assuming `h ≫ f = 0`. -/
def factorThruKernelSubobject {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : W ⟶ kernelSubobject f :=
(kernelSubobject f).factorThru h (kernelSubobject_factors f h w)
#align category_theory.limits.factor_thru_kernel_subobject CategoryTheory.Limits.factorThruKernelSubobject
@[simp]
theorem factorThruKernelSubobject_comp_arrow {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobject f).arrow = h := by
dsimp [factorThruKernelSubobject]
simp
#align category_theory.limits.factor_thru_kernel_subobject_comp_arrow CategoryTheory.Limits.factorThruKernelSubobject_comp_arrow
@[simp]
theorem factorThruKernelSubobject_comp_kernelSubobjectIso {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobjectIso f).hom = kernel.lift f h w :=
(cancel_mono (kernel.ι f)).1 <| by simp
#align category_theory.limits.factor_thru_kernel_subobject_comp_kernel_subobject_iso CategoryTheory.Limits.factorThruKernelSubobject_comp_kernelSubobjectIso
section
variable {f} {X' Y' : C} {f' : X' ⟶ Y'} [HasKernel f']
/-- A commuting square induces a morphism between the kernel subobjects. -/
def kernelSubobjectMap (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobject f : C) ⟶ (kernelSubobject f' : C) :=
Subobject.factorThru _ ((kernelSubobject f).arrow ≫ sq.left)
(kernelSubobject_factors _ _ (by simp [sq.w]))
#align category_theory.limits.kernel_subobject_map CategoryTheory.Limits.kernelSubobjectMap
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobjectMap_arrow (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernelSubobjectMap sq ≫ (kernelSubobject f').arrow = (kernelSubobject f).arrow ≫ sq.left := by
simp [kernelSubobjectMap]
#align category_theory.limits.kernel_subobject_map_arrow CategoryTheory.Limits.kernelSubobjectMap_arrow
@[simp]
theorem kernelSubobjectMap_id : kernelSubobjectMap (𝟙 (Arrow.mk f)) = 𝟙 _ := by aesop_cat
#align category_theory.limits.kernel_subobject_map_id CategoryTheory.Limits.kernelSubobjectMap_id
@[simp]
theorem kernelSubobjectMap_comp {X'' Y'' : C} {f'' : X'' ⟶ Y''} [HasKernel f'']
(sq : Arrow.mk f ⟶ Arrow.mk f') (sq' : Arrow.mk f' ⟶ Arrow.mk f'') :
kernelSubobjectMap (sq ≫ sq') = kernelSubobjectMap sq ≫ kernelSubobjectMap sq' := by
aesop_cat
#align category_theory.limits.kernel_subobject_map_comp CategoryTheory.Limits.kernelSubobjectMap_comp
@[reassoc]
theorem kernel_map_comp_kernelSubobjectIso_inv (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernel.map f f' sq.1 sq.2 sq.3.symm ≫ (kernelSubobjectIso _).inv =
(kernelSubobjectIso _).inv ≫ kernelSubobjectMap sq := by aesop_cat
#align category_theory.limits.kernel_map_comp_kernel_subobject_iso_inv CategoryTheory.Limits.kernel_map_comp_kernelSubobjectIso_inv
@[reassoc]
theorem kernelSubobjectIso_comp_kernel_map (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobjectIso _).hom ≫ kernel.map f f' sq.1 sq.2 sq.3.symm =
kernelSubobjectMap sq ≫ (kernelSubobjectIso _).hom := by
simp [← Iso.comp_inv_eq, kernel_map_comp_kernelSubobjectIso_inv]
#align category_theory.limits.kernel_subobject_iso_comp_kernel_map CategoryTheory.Limits.kernelSubobjectIso_comp_kernel_map
end
@[simp]
theorem kernelSubobject_zero {A B : C} : kernelSubobject (0 : A ⟶ B) = ⊤ :=
(isIso_iff_mk_eq_top _).mp (by infer_instance)
#align category_theory.limits.kernel_subobject_zero CategoryTheory.Limits.kernelSubobject_zero
instance isIso_kernelSubobject_zero_arrow : IsIso (kernelSubobject (0 : X ⟶ Y)).arrow :=
(isIso_arrow_iff_eq_top _).mpr kernelSubobject_zero
#align category_theory.limits.is_iso_kernel_subobject_zero_arrow CategoryTheory.Limits.isIso_kernelSubobject_zero_arrow
theorem le_kernelSubobject (A : Subobject X) (h : A.arrow ≫ f = 0) : A ≤ kernelSubobject f :=
Subobject.le_mk_of_comm (kernel.lift f A.arrow h) (by simp)
#align category_theory.limits.le_kernel_subobject CategoryTheory.Limits.le_kernelSubobject
/-- The isomorphism between the kernel of `f ≫ g` and the kernel of `g`,
when `f` is an isomorphism.
-/
def kernelSubobjectIsoComp {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobject (f ≫ g) : C) ≅ (kernelSubobject g : C) :=
kernelSubobjectIso _ ≪≫ kernelIsIsoComp f g ≪≫ (kernelSubobjectIso _).symm
#align category_theory.limits.kernel_subobject_iso_comp CategoryTheory.Limits.kernelSubobjectIsoComp
@[simp]
theorem kernelSubobjectIsoComp_hom_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).hom ≫ (kernelSubobject g).arrow =
(kernelSubobject (f ≫ g)).arrow ≫ f := by
simp [kernelSubobjectIsoComp]
#align category_theory.limits.kernel_subobject_iso_comp_hom_arrow CategoryTheory.Limits.kernelSubobjectIsoComp_hom_arrow
@[simp]
theorem kernelSubobjectIsoComp_inv_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).inv ≫ (kernelSubobject (f ≫ g)).arrow =
(kernelSubobject g).arrow ≫ inv f := by
simp [kernelSubobjectIsoComp]
#align category_theory.limits.kernel_subobject_iso_comp_inv_arrow CategoryTheory.Limits.kernelSubobjectIsoComp_inv_arrow
/-- The kernel of `f` is always a smaller subobject than the kernel of `f ≫ h`. -/
theorem kernelSubobject_comp_le (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [HasKernel (f ≫ h)] :
kernelSubobject f ≤ kernelSubobject (f ≫ h) :=
le_kernelSubobject _ _ (by simp)
#align category_theory.limits.kernel_subobject_comp_le CategoryTheory.Limits.kernelSubobject_comp_le
/-- Postcomposing by a monomorphism does not change the kernel subobject. -/
@[simp]
theorem kernelSubobject_comp_mono (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
kernelSubobject (f ≫ h) = kernelSubobject f :=
le_antisymm (le_kernelSubobject _ _ ((cancel_mono h).mp (by simp))) (kernelSubobject_comp_le f h)
#align category_theory.limits.kernel_subobject_comp_mono CategoryTheory.Limits.kernelSubobject_comp_mono
instance kernelSubobject_comp_mono_isIso (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
IsIso (Subobject.ofLE _ _ (kernelSubobject_comp_le f h)) := by
rw [ofLE_mk_le_mk_of_comm (kernelCompMono f h).inv]
· infer_instance
· simp
#align category_theory.limits.kernel_subobject_comp_mono_is_iso CategoryTheory.Limits.kernelSubobject_comp_mono_isIso
/-- Taking cokernels is an order-reversing map from the subobjects of `X` to the quotient objects
of `X`. -/
@[simps]
def cokernelOrderHom [HasCokernels C] (X : C) : Subobject X →o (Subobject (op X))ᵒᵈ where
toFun :=
Subobject.lift (fun A f _ => Subobject.mk (cokernel.π f).op)
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ (Iso.op ?_) (Quiver.Hom.unop_inj ?_)
· exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _)
(isCokernelEpiComp (colimit.isColimit _) i.hom rfl)).symm
· simp only [Iso.comp_inv_eq, Iso.op_hom, Iso.symm_hom, unop_comp, Quiver.Hom.unop_op,
colimit.comp_coconePointUniqueUpToIso_hom, Cofork.ofπ_ι_app,
coequalizer.cofork_π])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (cokernel.desc f (cokernel.π g) ?_).op ?_
· rw [← Subobject.ofMkLEMk_comp h, Category.assoc, cokernel.condition, comp_zero]
· exact Quiver.Hom.unop_inj (cokernel.π_desc _ _ _)
#align category_theory.limits.cokernel_order_hom CategoryTheory.Limits.cokernelOrderHom
/-- Taking kernels is an order-reversing map from the quotient objects of `X` to the subobjects of
`X`. -/
@[simps]
def kernelOrderHom [HasKernels C] (X : C) : (Subobject (op X))ᵒᵈ →o Subobject X where
toFun :=
Subobject.lift (fun A f _ => Subobject.mk (kernel.ι f.unop))
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ ?_ ?_
· exact
IsLimit.conePointUniqueUpToIso (limit.isLimit _)
(isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) i.unop.hom rfl)
· dsimp
simp only [← Iso.eq_inv_comp, limit.conePointUniqueUpToIso_inv_comp,
Fork.ofι_π_app])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (kernel.lift g.unop (kernel.ι f.unop) ?_) ?_
· rw [← Subobject.ofMkLEMk_comp h, unop_comp, kernel.condition_assoc, zero_comp]
· exact Quiver.Hom.op_inj (by simp)
#align category_theory.limits.kernel_order_hom CategoryTheory.Limits.kernelOrderHom
end Kernel
section Image
variable (f : X ⟶ Y) [HasImage f]
/-- The image of a morphism `f g : X ⟶ Y` as a `Subobject Y`. -/
abbrev imageSubobject : Subobject Y :=
Subobject.mk (image.ι f)
#align category_theory.limits.image_subobject CategoryTheory.Limits.imageSubobject
/-- The underlying object of `imageSubobject f` is (up to isomorphism!)
the same as the chosen object `image f`. -/
def imageSubobjectIso : (imageSubobject f : C) ≅ image f :=
Subobject.underlyingIso (image.ι f)
#align category_theory.limits.image_subobject_iso CategoryTheory.Limits.imageSubobjectIso
@[reassoc (attr := simp)]
theorem imageSubobject_arrow :
(imageSubobjectIso f).hom ≫ image.ι f = (imageSubobject f).arrow := by simp [imageSubobjectIso]
#align category_theory.limits.image_subobject_arrow CategoryTheory.Limits.imageSubobject_arrow
@[reassoc (attr := simp)]
theorem imageSubobject_arrow' :
(imageSubobjectIso f).inv ≫ (imageSubobject f).arrow = image.ι f := by simp [imageSubobjectIso]
#align category_theory.limits.image_subobject_arrow' CategoryTheory.Limits.imageSubobject_arrow'
/-- A factorisation of `f : X ⟶ Y` through `imageSubobject f`. -/
def factorThruImageSubobject : X ⟶ imageSubobject f :=
factorThruImage f ≫ (imageSubobjectIso f).inv
#align category_theory.limits.factor_thru_image_subobject CategoryTheory.Limits.factorThruImageSubobject
instance [HasEqualizers C] : Epi (factorThruImageSubobject f) := by
dsimp [factorThruImageSubobject]
apply epi_comp
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem imageSubobject_arrow_comp : factorThruImageSubobject f ≫ (imageSubobject f).arrow = f := by
simp [factorThruImageSubobject, imageSubobject_arrow]
#align category_theory.limits.image_subobject_arrow_comp CategoryTheory.Limits.imageSubobject_arrow_comp
theorem imageSubobject_arrow_comp_eq_zero [HasZeroMorphisms C] {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z}
[HasImage f] [Epi (factorThruImageSubobject f)] (h : f ≫ g = 0) :
(imageSubobject f).arrow ≫ g = 0 :=
zero_of_epi_comp (factorThruImageSubobject f) <| by simp [h]
#align category_theory.limits.image_subobject_arrow_comp_eq_zero CategoryTheory.Limits.imageSubobject_arrow_comp_eq_zero
theorem imageSubobject_factors_comp_self {W : C} (k : W ⟶ X) : (imageSubobject f).Factors (k ≫ f) :=
⟨k ≫ factorThruImage f, by simp⟩
#align category_theory.limits.image_subobject_factors_comp_self CategoryTheory.Limits.imageSubobject_factors_comp_self
@[simp]
| Mathlib/CategoryTheory/Subobject/Limits.lean | 343 | 346 | theorem factorThruImageSubobject_comp_self {W : C} (k : W ⟶ X) (h) :
(imageSubobject f).factorThru (k ≫ f) h = k ≫ factorThruImageSubobject f := by |
ext
simp
|
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.Real
#align_import analysis.specific_limits.floor_pow from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8"
/-!
# Results on discretized exponentials
We state several auxiliary results pertaining to sequences of the form `⌊c^n⌋₊`.
* `tendsto_div_of_monotone_of_tendsto_div_floor_pow`: If a monotone sequence `u` is such that
`u ⌊c^n⌋₊ / ⌊c^n⌋₊` converges to a limit `l` for all `c > 1`, then `u n / n` tends to `l`.
* `sum_div_nat_floor_pow_sq_le_div_sq`: The sum of `1/⌊c^i⌋₊^2` above a threshold `j` is comparable
to `1/j^2`, up to a multiplicative constant.
-/
open Filter Finset
open Topology
/-- If a monotone sequence `u` is such that `u n / n` tends to a limit `l` along subsequences with
exponential growth rate arbitrarily close to `1`, then `u n / n` tends to `l`. -/
theorem tendsto_div_of_monotone_of_exists_subseq_tendsto_div (u : ℕ → ℝ) (l : ℝ)
(hmono : Monotone u)
(hlim : ∀ a : ℝ, 1 < a → ∃ c : ℕ → ℕ, (∀ᶠ n in atTop, (c (n + 1) : ℝ) ≤ a * c n) ∧
Tendsto c atTop atTop ∧ Tendsto (fun n => u (c n) / c n) atTop (𝓝 l)) :
Tendsto (fun n => u n / n) atTop (𝓝 l) := by
/- To check the result up to some `ε > 0`, we use a sequence `c` for which the ratio
`c (N+1) / c N` is bounded by `1 + ε`. Sandwiching a given `n` between two consecutive values of
`c`, say `c N` and `c (N+1)`, one can then bound `u n / n` from above by `u (c N) / c (N - 1)`
and from below by `u (c (N - 1)) / c N` (using that `u` is monotone), which are both comparable
to the limit `l` up to `1 + ε`.
We give a version of this proof by clearing out denominators first, to avoid discussing the sign
of different quantities. -/
have lnonneg : 0 ≤ l := by
rcases hlim 2 one_lt_two with ⟨c, _, ctop, clim⟩
have : Tendsto (fun n => u 0 / c n) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_iff.2 ctop)
apply le_of_tendsto_of_tendsto' this clim fun n => ?_
gcongr
exact hmono (zero_le _)
have A : ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, u n - n * l ≤ ε * (1 + ε + l) * n := by
intro ε εpos
rcases hlim (1 + ε) ((lt_add_iff_pos_right _).2 εpos) with ⟨c, cgrowth, ctop, clim⟩
have L : ∀ᶠ n in atTop, u (c n) - c n * l ≤ ε * c n := by
rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ,
Asymptotics.isLittleO_iff] at clim
filter_upwards [clim εpos, ctop (Ioi_mem_atTop 0)] with n hn cnpos'
have cnpos : 0 < c n := cnpos'
calc
u (c n) - c n * l = (u (c n) / c n - l) * c n := by
simp only [cnpos.ne', Ne, Nat.cast_eq_zero, not_false_iff, field_simps]
_ ≤ ε * c n := by
gcongr
refine (le_abs_self _).trans ?_
simpa using hn
obtain ⟨a, ha⟩ :
∃ a : ℕ, ∀ b : ℕ, a ≤ b → (c (b + 1) : ℝ) ≤ (1 + ε) * c b ∧ u (c b) - c b * l ≤ ε * c b :=
eventually_atTop.1 (cgrowth.and L)
let M := ((Finset.range (a + 1)).image fun i => c i).max' (by simp)
filter_upwards [Ici_mem_atTop M] with n hn
have exN : ∃ N, n < c N := by
rcases (tendsto_atTop.1 ctop (n + 1)).exists with ⟨N, hN⟩
exact ⟨N, by linarith only [hN]⟩
let N := Nat.find exN
have ncN : n < c N := Nat.find_spec exN
have aN : a + 1 ≤ N := by
by_contra! h
have cNM : c N ≤ M := by
apply le_max'
apply mem_image_of_mem
exact mem_range.2 h
exact lt_irrefl _ ((cNM.trans hn).trans_lt ncN)
have Npos : 0 < N := lt_of_lt_of_le Nat.succ_pos' aN
have cNn : c (N - 1) ≤ n := by
have : N - 1 < N := Nat.pred_lt Npos.ne'
simpa only [not_lt] using Nat.find_min exN this
have IcN : (c N : ℝ) ≤ (1 + ε) * c (N - 1) := by
have A : a ≤ N - 1 := by
apply @Nat.le_of_add_le_add_right a 1 (N - 1)
rw [Nat.sub_add_cancel Npos]
exact aN
have B : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos
have := (ha _ A).1
rwa [B] at this
calc
u n - n * l ≤ u (c N) - c (N - 1) * l := by gcongr; exact hmono ncN.le
_ = u (c N) - c N * l + (c N - c (N - 1)) * l := by ring
_ ≤ ε * c N + ε * c (N - 1) * l := by
gcongr
· exact (ha N (a.le_succ.trans aN)).2
· linarith only [IcN]
_ ≤ ε * ((1 + ε) * c (N - 1)) + ε * c (N - 1) * l := by gcongr
_ = ε * (1 + ε + l) * c (N - 1) := by ring
_ ≤ ε * (1 + ε + l) * n := by gcongr
have B : ∀ ε : ℝ, 0 < ε → ∀ᶠ n : ℕ in atTop, (n : ℝ) * l - u n ≤ ε * (1 + l) * n := by
intro ε εpos
rcases hlim (1 + ε) ((lt_add_iff_pos_right _).2 εpos) with ⟨c, cgrowth, ctop, clim⟩
have L : ∀ᶠ n : ℕ in atTop, (c n : ℝ) * l - u (c n) ≤ ε * c n := by
rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ,
Asymptotics.isLittleO_iff] at clim
filter_upwards [clim εpos, ctop (Ioi_mem_atTop 0)] with n hn cnpos'
have cnpos : 0 < c n := cnpos'
calc
(c n : ℝ) * l - u (c n) = -(u (c n) / c n - l) * c n := by
simp only [cnpos.ne', Ne, Nat.cast_eq_zero, not_false_iff, neg_sub, field_simps]
_ ≤ ε * c n := by
gcongr
refine le_trans (neg_le_abs _) ?_
simpa using hn
obtain ⟨a, ha⟩ :
∃ a : ℕ,
∀ b : ℕ, a ≤ b → (c (b + 1) : ℝ) ≤ (1 + ε) * c b ∧ (c b : ℝ) * l - u (c b) ≤ ε * c b :=
eventually_atTop.1 (cgrowth.and L)
let M := ((Finset.range (a + 1)).image fun i => c i).max' (by simp)
filter_upwards [Ici_mem_atTop M] with n hn
have exN : ∃ N, n < c N := by
rcases (tendsto_atTop.1 ctop (n + 1)).exists with ⟨N, hN⟩
exact ⟨N, by linarith only [hN]⟩
let N := Nat.find exN
have ncN : n < c N := Nat.find_spec exN
have aN : a + 1 ≤ N := by
by_contra! h
have cNM : c N ≤ M := by
apply le_max'
apply mem_image_of_mem
exact mem_range.2 h
exact lt_irrefl _ ((cNM.trans hn).trans_lt ncN)
have Npos : 0 < N := lt_of_lt_of_le Nat.succ_pos' aN
have aN' : a ≤ N - 1 := by
apply @Nat.le_of_add_le_add_right a 1 (N - 1)
rw [Nat.sub_add_cancel Npos]
exact aN
have cNn : c (N - 1) ≤ n := by
have : N - 1 < N := Nat.pred_lt Npos.ne'
simpa only [not_lt] using Nat.find_min exN this
calc
(n : ℝ) * l - u n ≤ c N * l - u (c (N - 1)) := by
gcongr
exact hmono cNn
_ ≤ (1 + ε) * c (N - 1) * l - u (c (N - 1)) := by
gcongr
have B : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos
simpa [B] using (ha _ aN').1
_ = c (N - 1) * l - u (c (N - 1)) + ε * c (N - 1) * l := by ring
_ ≤ ε * c (N - 1) + ε * c (N - 1) * l := add_le_add (ha _ aN').2 le_rfl
_ = ε * (1 + l) * c (N - 1) := by ring
_ ≤ ε * (1 + l) * n := by gcongr
refine tendsto_order.2 ⟨fun d hd => ?_, fun d hd => ?_⟩
· obtain ⟨ε, hε, εpos⟩ : ∃ ε : ℝ, d + ε * (1 + l) < l ∧ 0 < ε := by
have L : Tendsto (fun ε => d + ε * (1 + l)) (𝓝[>] 0) (𝓝 (d + 0 * (1 + l))) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
exact tendsto_const_nhds.add (tendsto_id.mul tendsto_const_nhds)
simp only [zero_mul, add_zero] at L
exact (((tendsto_order.1 L).2 l hd).and self_mem_nhdsWithin).exists
filter_upwards [B ε εpos, Ioi_mem_atTop 0] with n hn npos
simp_rw [div_eq_inv_mul]
calc
d < (n : ℝ)⁻¹ * n * (l - ε * (1 + l)) := by
rw [inv_mul_cancel, one_mul]
· linarith only [hε]
· exact Nat.cast_ne_zero.2 (ne_of_gt npos)
_ = (n : ℝ)⁻¹ * (n * l - ε * (1 + l) * n) := by ring
_ ≤ (n : ℝ)⁻¹ * u n := by gcongr; linarith only [hn]
· obtain ⟨ε, hε, εpos⟩ : ∃ ε : ℝ, l + ε * (1 + ε + l) < d ∧ 0 < ε := by
have L : Tendsto (fun ε => l + ε * (1 + ε + l)) (𝓝[>] 0) (𝓝 (l + 0 * (1 + 0 + l))) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
exact
tendsto_const_nhds.add
(tendsto_id.mul ((tendsto_const_nhds.add tendsto_id).add tendsto_const_nhds))
simp only [zero_mul, add_zero] at L
exact (((tendsto_order.1 L).2 d hd).and self_mem_nhdsWithin).exists
filter_upwards [A ε εpos, Ioi_mem_atTop 0] with n hn (npos : 0 < n)
calc
u n / n ≤ (n * l + ε * (1 + ε + l) * n) / n := by gcongr; linarith only [hn]
_ = (l + ε * (1 + ε + l)) := by field_simp; ring
_ < d := hε
#align tendsto_div_of_monotone_of_exists_subseq_tendsto_div tendsto_div_of_monotone_of_exists_subseq_tendsto_div
/-- If a monotone sequence `u` is such that `u ⌊c^n⌋₊ / ⌊c^n⌋₊` converges to a limit `l` for all
`c > 1`, then `u n / n` tends to `l`. It is even enough to have the assumption for a sequence of
`c`s converging to `1`. -/
| Mathlib/Analysis/SpecificLimits/FloorPow.lean | 188 | 218 | theorem tendsto_div_of_monotone_of_tendsto_div_floor_pow (u : ℕ → ℝ) (l : ℝ) (hmono : Monotone u)
(c : ℕ → ℝ) (cone : ∀ k, 1 < c k) (clim : Tendsto c atTop (𝓝 1))
(hc : ∀ k, Tendsto (fun n : ℕ => u ⌊c k ^ n⌋₊ / ⌊c k ^ n⌋₊) atTop (𝓝 l)) :
Tendsto (fun n => u n / n) atTop (𝓝 l) := by |
apply tendsto_div_of_monotone_of_exists_subseq_tendsto_div u l hmono
intro a ha
obtain ⟨k, hk⟩ : ∃ k, c k < a := ((tendsto_order.1 clim).2 a ha).exists
refine
⟨fun n => ⌊c k ^ n⌋₊, ?_,
(tendsto_nat_floor_atTop (α := ℝ)).comp (tendsto_pow_atTop_atTop_of_one_lt (cone k)), hc k⟩
have H : ∀ n : ℕ, (0 : ℝ) < ⌊c k ^ n⌋₊ := by
intro n
refine zero_lt_one.trans_le ?_
simp only [Real.rpow_natCast, Nat.one_le_cast, Nat.one_le_floor_iff,
one_le_pow_of_one_le (cone k).le n]
have A :
Tendsto (fun n : ℕ => (⌊c k ^ (n + 1)⌋₊ : ℝ) / c k ^ (n + 1) * c k / (⌊c k ^ n⌋₊ / c k ^ n))
atTop (𝓝 (1 * c k / 1)) := by
refine Tendsto.div (Tendsto.mul ?_ tendsto_const_nhds) ?_ one_ne_zero
· refine tendsto_nat_floor_div_atTop.comp ?_
exact (tendsto_pow_atTop_atTop_of_one_lt (cone k)).comp (tendsto_add_atTop_nat 1)
· refine tendsto_nat_floor_div_atTop.comp ?_
exact tendsto_pow_atTop_atTop_of_one_lt (cone k)
have B : Tendsto (fun n : ℕ => (⌊c k ^ (n + 1)⌋₊ : ℝ) / ⌊c k ^ n⌋₊) atTop (𝓝 (c k)) := by
simp only [one_mul, div_one] at A
convert A using 1
ext1 n
field_simp [(zero_lt_one.trans (cone k)).ne', (H n).ne']
ring
filter_upwards [(tendsto_order.1 B).2 a hk] with n hn
exact (div_le_iff (H n)).1 hn.le
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Data.Bundle
import Mathlib.Data.Set.Image
import Mathlib.Topology.PartialHomeomorph
import Mathlib.Topology.Order.Basic
#align_import topology.fiber_bundle.trivialization from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833"
/-!
# Trivializations
## Main definitions
### Basic definitions
* `Trivialization F p` : structure extending partial homeomorphisms, defining a local
trivialization of a topological space `Z` with projection `p` and fiber `F`.
* `Pretrivialization F proj` : trivialization as a partial equivalence, mainly used when the
topology on the total space has not yet been defined.
### Operations on bundles
We provide the following operations on `Trivialization`s.
* `Trivialization.compHomeomorph`: given a local trivialization `e` of a fiber bundle
`p : Z → B` and a homeomorphism `h : Z' ≃ₜ Z`, returns a local trivialization of the fiber bundle
`p ∘ h`.
## Implementation notes
Previously, in mathlib, there was a structure `topological_vector_bundle.trivialization` which
extended another structure `topological_fiber_bundle.trivialization` by a linearity hypothesis. As
of PR leanprover-community/mathlib#17359, we have changed this to a single structure
`Trivialization` (no namespace), together with a mixin class `Trivialization.IsLinear`.
This permits all the *data* of a vector bundle to be held at the level of fiber bundles, so that the
same trivializations can underlie an object's structure as (say) a vector bundle over `ℂ` and as a
vector bundle over `ℝ`, as well as its structure simply as a fiber bundle.
This might be a little surprising, given the general trend of the library to ever-increased
bundling. But in this case the typical motivation for more bundling does not apply: there is no
algebraic or order structure on the whole type of linear (say) trivializations of a bundle.
Indeed, since trivializations only have meaning on their base sets (taking junk values outside), the
type of linear trivializations is not even particularly well-behaved.
-/
open TopologicalSpace Filter Set Bundle Function
open scoped Topology Classical Bundle
variable {ι : Type*} {B : Type*} {F : Type*} {E : B → Type*}
variable (F) {Z : Type*} [TopologicalSpace B] [TopologicalSpace F] {proj : Z → B}
/-- This structure contains the information left for a local trivialization (which is implemented
below as `Trivialization F proj`) if the total space has not been given a topology, but we
have a topology on both the fiber and the base space. Through the construction
`topological_fiber_prebundle F proj` it will be possible to promote a
`Pretrivialization F proj` to a `Trivialization F proj`. -/
structure Pretrivialization (proj : Z → B) extends PartialEquiv Z (B × F) where
open_target : IsOpen target
baseSet : Set B
open_baseSet : IsOpen baseSet
source_eq : source = proj ⁻¹' baseSet
target_eq : target = baseSet ×ˢ univ
proj_toFun : ∀ p ∈ source, (toFun p).1 = proj p
#align pretrivialization Pretrivialization
namespace Pretrivialization
variable {F}
variable (e : Pretrivialization F proj) {x : Z}
/-- Coercion of a pretrivialization to a function. We don't use `e.toFun` in the `CoeFun` instance
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' : Z → (B × F) := e.toFun
instance : CoeFun (Pretrivialization F proj) fun _ => Z → B × F := ⟨toFun'⟩
@[ext]
lemma ext' (e e' : Pretrivialization F proj) (h₁ : e.toPartialEquiv = e'.toPartialEquiv)
(h₂ : e.baseSet = e'.baseSet) : e = e' := by
cases e; cases e'; congr
#align pretrivialization.ext Pretrivialization.ext'
-- Porting note (#11215): TODO: move `ext` here?
lemma ext {e e' : Pretrivialization F proj} (h₁ : ∀ x, e x = e' x)
(h₂ : ∀ x, e.toPartialEquiv.symm x = e'.toPartialEquiv.symm x) (h₃ : e.baseSet = e'.baseSet) :
e = e' := by
ext1 <;> [ext1; exact h₃]
· apply h₁
· apply h₂
· rw [e.source_eq, e'.source_eq, h₃]
/-- If the fiber is nonempty, then the projection also is. -/
lemma toPartialEquiv_injective [Nonempty F] :
Injective (toPartialEquiv : Pretrivialization F proj → PartialEquiv Z (B × F)) := by
refine fun e e' h ↦ ext' _ _ h ?_
simpa only [fst_image_prod, univ_nonempty, target_eq]
using congr_arg (Prod.fst '' PartialEquiv.target ·) h
@[simp, mfld_simps]
theorem coe_coe : ⇑e.toPartialEquiv = e :=
rfl
#align pretrivialization.coe_coe Pretrivialization.coe_coe
@[simp, mfld_simps]
theorem coe_fst (ex : x ∈ e.source) : (e x).1 = proj x :=
e.proj_toFun x ex
#align pretrivialization.coe_fst Pretrivialization.coe_fst
theorem mem_source : x ∈ e.source ↔ proj x ∈ e.baseSet := by rw [e.source_eq, mem_preimage]
#align pretrivialization.mem_source Pretrivialization.mem_source
theorem coe_fst' (ex : proj x ∈ e.baseSet) : (e x).1 = proj x :=
e.coe_fst (e.mem_source.2 ex)
#align pretrivialization.coe_fst' Pretrivialization.coe_fst'
protected theorem eqOn : EqOn (Prod.fst ∘ e) proj e.source := fun _ hx => e.coe_fst hx
#align pretrivialization.eq_on Pretrivialization.eqOn
theorem mk_proj_snd (ex : x ∈ e.source) : (proj x, (e x).2) = e x :=
Prod.ext (e.coe_fst ex).symm rfl
#align pretrivialization.mk_proj_snd Pretrivialization.mk_proj_snd
theorem mk_proj_snd' (ex : proj x ∈ e.baseSet) : (proj x, (e x).2) = e x :=
Prod.ext (e.coe_fst' ex).symm rfl
#align pretrivialization.mk_proj_snd' Pretrivialization.mk_proj_snd'
/-- Composition of inverse and coercion from the subtype of the target. -/
def setSymm : e.target → Z :=
e.target.restrict e.toPartialEquiv.symm
#align pretrivialization.set_symm Pretrivialization.setSymm
theorem mem_target {x : B × F} : x ∈ e.target ↔ x.1 ∈ e.baseSet := by
rw [e.target_eq, prod_univ, mem_preimage]
#align pretrivialization.mem_target Pretrivialization.mem_target
theorem proj_symm_apply {x : B × F} (hx : x ∈ e.target) : proj (e.toPartialEquiv.symm x) = x.1 := by
have := (e.coe_fst (e.map_target hx)).symm
rwa [← e.coe_coe, e.right_inv hx] at this
#align pretrivialization.proj_symm_apply Pretrivialization.proj_symm_apply
theorem proj_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) :
proj (e.toPartialEquiv.symm (b, x)) = b :=
e.proj_symm_apply (e.mem_target.2 hx)
#align pretrivialization.proj_symm_apply' Pretrivialization.proj_symm_apply'
theorem proj_surjOn_baseSet [Nonempty F] : Set.SurjOn proj e.source e.baseSet := fun b hb =>
let ⟨y⟩ := ‹Nonempty F›
⟨e.toPartialEquiv.symm (b, y), e.toPartialEquiv.map_target <| e.mem_target.2 hb,
e.proj_symm_apply' hb⟩
#align pretrivialization.proj_surj_on_base_set Pretrivialization.proj_surjOn_baseSet
theorem apply_symm_apply {x : B × F} (hx : x ∈ e.target) : e (e.toPartialEquiv.symm x) = x :=
e.toPartialEquiv.right_inv hx
#align pretrivialization.apply_symm_apply Pretrivialization.apply_symm_apply
theorem apply_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) :
e (e.toPartialEquiv.symm (b, x)) = (b, x) :=
e.apply_symm_apply (e.mem_target.2 hx)
#align pretrivialization.apply_symm_apply' Pretrivialization.apply_symm_apply'
theorem symm_apply_apply {x : Z} (hx : x ∈ e.source) : e.toPartialEquiv.symm (e x) = x :=
e.toPartialEquiv.left_inv hx
#align pretrivialization.symm_apply_apply Pretrivialization.symm_apply_apply
@[simp, mfld_simps]
theorem symm_apply_mk_proj {x : Z} (ex : x ∈ e.source) :
e.toPartialEquiv.symm (proj x, (e x).2) = x := by
rw [← e.coe_fst ex, ← e.coe_coe, e.left_inv ex]
#align pretrivialization.symm_apply_mk_proj Pretrivialization.symm_apply_mk_proj
@[simp, mfld_simps]
theorem preimage_symm_proj_baseSet :
e.toPartialEquiv.symm ⁻¹' (proj ⁻¹' e.baseSet) ∩ e.target = e.target := by
refine inter_eq_right.mpr fun x hx => ?_
simp only [mem_preimage, PartialEquiv.invFun_as_coe, e.proj_symm_apply hx]
exact e.mem_target.mp hx
#align pretrivialization.preimage_symm_proj_base_set Pretrivialization.preimage_symm_proj_baseSet
@[simp, mfld_simps]
theorem preimage_symm_proj_inter (s : Set B) :
e.toPartialEquiv.symm ⁻¹' (proj ⁻¹' s) ∩ e.baseSet ×ˢ univ = (s ∩ e.baseSet) ×ˢ univ := by
ext ⟨x, y⟩
suffices x ∈ e.baseSet → (proj (e.toPartialEquiv.symm (x, y)) ∈ s ↔ x ∈ s) by
simpa only [prod_mk_mem_set_prod_eq, mem_inter_iff, and_true_iff, mem_univ, and_congr_left_iff]
intro h
rw [e.proj_symm_apply' h]
#align pretrivialization.preimage_symm_proj_inter Pretrivialization.preimage_symm_proj_inter
theorem target_inter_preimage_symm_source_eq (e f : Pretrivialization F proj) :
f.target ∩ f.toPartialEquiv.symm ⁻¹' e.source = (e.baseSet ∩ f.baseSet) ×ˢ univ := by
rw [inter_comm, f.target_eq, e.source_eq, f.preimage_symm_proj_inter]
#align pretrivialization.target_inter_preimage_symm_source_eq Pretrivialization.target_inter_preimage_symm_source_eq
theorem trans_source (e f : Pretrivialization F proj) :
(f.toPartialEquiv.symm.trans e.toPartialEquiv).source = (e.baseSet ∩ f.baseSet) ×ˢ univ := by
rw [PartialEquiv.trans_source, PartialEquiv.symm_source, e.target_inter_preimage_symm_source_eq]
#align pretrivialization.trans_source Pretrivialization.trans_source
theorem symm_trans_symm (e e' : Pretrivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).symm
= e'.toPartialEquiv.symm.trans e.toPartialEquiv := by
rw [PartialEquiv.trans_symm_eq_symm_trans_symm, PartialEquiv.symm_symm]
#align pretrivialization.symm_trans_symm Pretrivialization.symm_trans_symm
theorem symm_trans_source_eq (e e' : Pretrivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).source = (e.baseSet ∩ e'.baseSet) ×ˢ univ := by
rw [PartialEquiv.trans_source, e'.source_eq, PartialEquiv.symm_source, e.target_eq, inter_comm,
e.preimage_symm_proj_inter, inter_comm]
#align pretrivialization.symm_trans_source_eq Pretrivialization.symm_trans_source_eq
theorem symm_trans_target_eq (e e' : Pretrivialization F proj) :
(e.toPartialEquiv.symm.trans e'.toPartialEquiv).target = (e.baseSet ∩ e'.baseSet) ×ˢ univ := by
rw [← PartialEquiv.symm_source, symm_trans_symm, symm_trans_source_eq, inter_comm]
#align pretrivialization.symm_trans_target_eq Pretrivialization.symm_trans_target_eq
variable (e' : Pretrivialization F (π F E)) {x' : TotalSpace F E} {b : B} {y : E b}
@[simp]
theorem coe_mem_source : ↑y ∈ e'.source ↔ b ∈ e'.baseSet :=
e'.mem_source
#align pretrivialization.coe_mem_source Pretrivialization.coe_mem_source
@[simp, mfld_simps]
theorem coe_coe_fst (hb : b ∈ e'.baseSet) : (e' y).1 = b :=
e'.coe_fst (e'.mem_source.2 hb)
#align pretrivialization.coe_coe_fst Pretrivialization.coe_coe_fst
theorem mk_mem_target {x : B} {y : F} : (x, y) ∈ e'.target ↔ x ∈ e'.baseSet :=
e'.mem_target
#align pretrivialization.mk_mem_target Pretrivialization.mk_mem_target
theorem symm_coe_proj {x : B} {y : F} (e' : Pretrivialization F (π F E)) (h : x ∈ e'.baseSet) :
(e'.toPartialEquiv.symm (x, y)).1 = x :=
e'.proj_symm_apply' h
#align pretrivialization.symm_coe_proj Pretrivialization.symm_coe_proj
section Zero
variable [∀ x, Zero (E x)]
/-- A fiberwise inverse to `e`. This is the function `F → E b` that induces a local inverse
`B × F → TotalSpace F E` of `e` on `e.baseSet`. It is defined to be `0` outside `e.baseSet`. -/
protected noncomputable def symm (e : Pretrivialization F (π F E)) (b : B) (y : F) : E b :=
if hb : b ∈ e.baseSet then
cast (congr_arg E (e.proj_symm_apply' hb)) (e.toPartialEquiv.symm (b, y)).2
else 0
#align pretrivialization.symm Pretrivialization.symm
theorem symm_apply (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
e.symm b y = cast (congr_arg E (e.symm_coe_proj hb)) (e.toPartialEquiv.symm (b, y)).2 :=
dif_pos hb
#align pretrivialization.symm_apply Pretrivialization.symm_apply
theorem symm_apply_of_not_mem (e : Pretrivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet)
(y : F) : e.symm b y = 0 :=
dif_neg hb
#align pretrivialization.symm_apply_of_not_mem Pretrivialization.symm_apply_of_not_mem
theorem coe_symm_of_not_mem (e : Pretrivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet) :
(e.symm b : F → E b) = 0 :=
funext fun _ => dif_neg hb
#align pretrivialization.coe_symm_of_not_mem Pretrivialization.coe_symm_of_not_mem
theorem mk_symm (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
TotalSpace.mk b (e.symm b y) = e.toPartialEquiv.symm (b, y) := by
simp only [e.symm_apply hb, TotalSpace.mk_cast (e.proj_symm_apply' hb), TotalSpace.eta]
#align pretrivialization.mk_symm Pretrivialization.mk_symm
theorem symm_proj_apply (e : Pretrivialization F (π F E)) (z : TotalSpace F E)
(hz : z.proj ∈ e.baseSet) : e.symm z.proj (e z).2 = z.2 := by
rw [e.symm_apply hz, cast_eq_iff_heq, e.mk_proj_snd' hz, e.symm_apply_apply (e.mem_source.mpr hz)]
#align pretrivialization.symm_proj_apply Pretrivialization.symm_proj_apply
theorem symm_apply_apply_mk (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet)
(y : E b) : e.symm b (e ⟨b, y⟩).2 = y :=
e.symm_proj_apply ⟨b, y⟩ hb
#align pretrivialization.symm_apply_apply_mk Pretrivialization.symm_apply_apply_mk
| Mathlib/Topology/FiberBundle/Trivialization.lean | 288 | 290 | theorem apply_mk_symm (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) :
e ⟨b, e.symm b y⟩ = (b, y) := by |
rw [e.mk_symm hb, e.apply_symm_apply (e.mk_mem_target.mpr hb)]
|
/-
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.Adjunction.Basic
import Mathlib.CategoryTheory.Limits.Cones
#align_import category_theory.limits.is_limit from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da"
/-!
# Limits and colimits
We set up the general theory of limits and colimits in a category.
In this introduction we only describe the setup for limits;
it is repeated, with slightly different names, for colimits.
The main structures defined in this file is
* `IsLimit c`, for `c : Cone F`, `F : J ⥤ C`, expressing that `c` is a limit cone,
See also `CategoryTheory.Limits.HasLimits` which further builds:
* `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`.
## 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
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe v₁ v₂ v₃ v₄ u₁ 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}
/-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique
cone morphism to `t`.
See <https://stacks.math.columbia.edu/tag/002E>.
-/
-- porting note (#5171): removed @[nolint has_nonempty_instance]
structure IsLimit (t : Cone F) where
/-- There is a morphism from any cone point to `t.pt` -/
lift : ∀ s : Cone F, s.pt ⟶ t.pt
/-- The map makes the triangle with the two natural transformations commute -/
fac : ∀ (s : Cone F) (j : J), lift s ≫ t.π.app j = s.π.app j := by aesop_cat
/-- It is the unique such map to do this -/
uniq : ∀ (s : Cone F) (m : s.pt ⟶ t.pt) (_ : ∀ j : J, m ≫ t.π.app j = s.π.app j), m = lift s := by
aesop_cat
#align category_theory.limits.is_limit CategoryTheory.Limits.IsLimit
#align category_theory.limits.is_limit.fac' CategoryTheory.Limits.IsLimit.fac
#align category_theory.limits.is_limit.uniq' CategoryTheory.Limits.IsLimit.uniq
-- Porting note (#10618): simp can prove this. Linter complains it still exists
attribute [-simp, nolint simpNF] IsLimit.mk.injEq
attribute [reassoc (attr := simp)] IsLimit.fac
namespace IsLimit
instance subsingleton {t : Cone F} : Subsingleton (IsLimit t) :=
⟨by intro P Q; cases P; cases Q; congr; aesop_cat⟩
#align category_theory.limits.is_limit.subsingleton CategoryTheory.Limits.IsLimit.subsingleton
/-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cone point
of any cone over `F` to the cone point of a limit cone over `G`. -/
def map {F G : J ⥤ C} (s : Cone F) {t : Cone G} (P : IsLimit t) (α : F ⟶ G) : s.pt ⟶ t.pt :=
P.lift ((Cones.postcompose α).obj s)
#align category_theory.limits.is_limit.map CategoryTheory.Limits.IsLimit.map
@[reassoc (attr := simp)]
theorem map_π {F G : J ⥤ C} (c : Cone F) {d : Cone G} (hd : IsLimit d) (α : F ⟶ G) (j : J) :
hd.map c α ≫ d.π.app j = c.π.app j ≫ α.app j :=
fac _ _ _
#align category_theory.limits.is_limit.map_π CategoryTheory.Limits.IsLimit.map_π
@[simp]
theorem lift_self {c : Cone F} (t : IsLimit c) : t.lift c = 𝟙 c.pt :=
(t.uniq _ _ fun _ => id_comp _).symm
#align category_theory.limits.is_limit.lift_self CategoryTheory.Limits.IsLimit.lift_self
-- Repackaging the definition in terms of cone morphisms.
/-- The universal morphism from any other cone to a limit cone. -/
@[simps]
def liftConeMorphism {t : Cone F} (h : IsLimit t) (s : Cone F) : s ⟶ t where hom := h.lift s
#align category_theory.limits.is_limit.lift_cone_morphism CategoryTheory.Limits.IsLimit.liftConeMorphism
theorem uniq_cone_morphism {s t : Cone F} (h : IsLimit t) {f f' : s ⟶ t} : f = f' :=
have : ∀ {g : s ⟶ t}, g = h.liftConeMorphism s := by
intro g; apply ConeMorphism.ext; exact h.uniq _ _ g.w
this.trans this.symm
#align category_theory.limits.is_limit.uniq_cone_morphism CategoryTheory.Limits.IsLimit.uniq_cone_morphism
/-- Restating the definition of a limit cone in terms of the ∃! operator. -/
theorem existsUnique {t : Cone F} (h : IsLimit t) (s : Cone F) :
∃! l : s.pt ⟶ t.pt, ∀ j, l ≫ t.π.app j = s.π.app j :=
⟨h.lift s, h.fac s, h.uniq s⟩
#align category_theory.limits.is_limit.exists_unique CategoryTheory.Limits.IsLimit.existsUnique
/-- Noncomputably make a limit cone from the existence of unique factorizations. -/
def ofExistsUnique {t : Cone F}
(ht : ∀ s : Cone F, ∃! l : s.pt ⟶ t.pt, ∀ j, l ≫ t.π.app j = s.π.app j) : IsLimit t := by
choose s hs hs' using ht
exact ⟨s, hs, hs'⟩
#align category_theory.limits.is_limit.of_exists_unique CategoryTheory.Limits.IsLimit.ofExistsUnique
/-- Alternative constructor for `isLimit`,
providing a morphism of cones rather than a morphism between the cone points
and separately the factorisation condition.
-/
@[simps]
def mkConeMorphism {t : Cone F} (lift : ∀ s : Cone F, s ⟶ t)
(uniq : ∀ (s : Cone F) (m : s ⟶ t), m = lift s) : IsLimit t where
lift s := (lift s).hom
uniq s m w :=
have : ConeMorphism.mk m w = lift s := by apply uniq
congrArg ConeMorphism.hom this
#align category_theory.limits.is_limit.mk_cone_morphism CategoryTheory.Limits.IsLimit.mkConeMorphism
/-- Limit cones on `F` are unique up to isomorphism. -/
@[simps]
def uniqueUpToIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : s ≅ t where
hom := Q.liftConeMorphism s
inv := P.liftConeMorphism t
hom_inv_id := P.uniq_cone_morphism
inv_hom_id := Q.uniq_cone_morphism
#align category_theory.limits.is_limit.unique_up_to_iso CategoryTheory.Limits.IsLimit.uniqueUpToIso
/-- Any cone morphism between limit cones is an isomorphism. -/
theorem hom_isIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (f : s ⟶ t) : IsIso f :=
⟨⟨P.liftConeMorphism t, ⟨P.uniq_cone_morphism, Q.uniq_cone_morphism⟩⟩⟩
#align category_theory.limits.is_limit.hom_is_iso CategoryTheory.Limits.IsLimit.hom_isIso
/-- Limits of `F` are unique up to isomorphism. -/
def conePointUniqueUpToIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : s.pt ≅ t.pt :=
(Cones.forget F).mapIso (uniqueUpToIso P Q)
#align category_theory.limits.is_limit.cone_point_unique_up_to_iso CategoryTheory.Limits.IsLimit.conePointUniqueUpToIso
@[reassoc (attr := simp)]
theorem conePointUniqueUpToIso_hom_comp {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (j : J) :
(conePointUniqueUpToIso P Q).hom ≫ t.π.app j = s.π.app j :=
(uniqueUpToIso P Q).hom.w _
#align category_theory.limits.is_limit.cone_point_unique_up_to_iso_hom_comp CategoryTheory.Limits.IsLimit.conePointUniqueUpToIso_hom_comp
@[reassoc (attr := simp)]
theorem conePointUniqueUpToIso_inv_comp {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (j : J) :
(conePointUniqueUpToIso P Q).inv ≫ s.π.app j = t.π.app j :=
(uniqueUpToIso P Q).inv.w _
#align category_theory.limits.is_limit.cone_point_unique_up_to_iso_inv_comp CategoryTheory.Limits.IsLimit.conePointUniqueUpToIso_inv_comp
@[reassoc (attr := simp)]
theorem lift_comp_conePointUniqueUpToIso_hom {r s t : Cone F} (P : IsLimit s) (Q : IsLimit t) :
P.lift r ≫ (conePointUniqueUpToIso P Q).hom = Q.lift r :=
Q.uniq _ _ (by simp)
#align category_theory.limits.is_limit.lift_comp_cone_point_unique_up_to_iso_hom CategoryTheory.Limits.IsLimit.lift_comp_conePointUniqueUpToIso_hom
@[reassoc (attr := simp)]
theorem lift_comp_conePointUniqueUpToIso_inv {r s t : Cone F} (P : IsLimit s) (Q : IsLimit t) :
Q.lift r ≫ (conePointUniqueUpToIso P Q).inv = P.lift r :=
P.uniq _ _ (by simp)
#align category_theory.limits.is_limit.lift_comp_cone_point_unique_up_to_iso_inv CategoryTheory.Limits.IsLimit.lift_comp_conePointUniqueUpToIso_inv
/-- Transport evidence that a cone is a limit cone across an isomorphism of cones. -/
def ofIsoLimit {r t : Cone F} (P : IsLimit r) (i : r ≅ t) : IsLimit t :=
IsLimit.mkConeMorphism (fun s => P.liftConeMorphism s ≫ i.hom) fun s m => by
rw [← i.comp_inv_eq]; apply P.uniq_cone_morphism
#align category_theory.limits.is_limit.of_iso_limit CategoryTheory.Limits.IsLimit.ofIsoLimit
@[simp]
theorem ofIsoLimit_lift {r t : Cone F} (P : IsLimit r) (i : r ≅ t) (s) :
(P.ofIsoLimit i).lift s = P.lift s ≫ i.hom.hom :=
rfl
#align category_theory.limits.is_limit.of_iso_limit_lift CategoryTheory.Limits.IsLimit.ofIsoLimit_lift
/-- Isomorphism of cones preserves whether or not they are limiting cones. -/
def equivIsoLimit {r t : Cone F} (i : r ≅ t) : IsLimit r ≃ IsLimit t where
toFun h := h.ofIsoLimit i
invFun h := h.ofIsoLimit i.symm
left_inv := by aesop_cat
right_inv := by aesop_cat
#align category_theory.limits.is_limit.equiv_iso_limit CategoryTheory.Limits.IsLimit.equivIsoLimit
@[simp]
theorem equivIsoLimit_apply {r t : Cone F} (i : r ≅ t) (P : IsLimit r) :
equivIsoLimit i P = P.ofIsoLimit i :=
rfl
#align category_theory.limits.is_limit.equiv_iso_limit_apply CategoryTheory.Limits.IsLimit.equivIsoLimit_apply
@[simp]
theorem equivIsoLimit_symm_apply {r t : Cone F} (i : r ≅ t) (P : IsLimit t) :
(equivIsoLimit i).symm P = P.ofIsoLimit i.symm :=
rfl
#align category_theory.limits.is_limit.equiv_iso_limit_symm_apply CategoryTheory.Limits.IsLimit.equivIsoLimit_symm_apply
/-- If the canonical morphism from a cone point to a limiting cone point is an iso, then the
first cone was limiting also.
-/
def ofPointIso {r t : Cone F} (P : IsLimit r) [i : IsIso (P.lift t)] : IsLimit t :=
ofIsoLimit P (by
haveI : IsIso (P.liftConeMorphism t).hom := i
haveI : IsIso (P.liftConeMorphism t) := Cones.cone_iso_of_hom_iso _
symm
apply asIso (P.liftConeMorphism t))
#align category_theory.limits.is_limit.of_point_iso CategoryTheory.Limits.IsLimit.ofPointIso
variable {t : Cone F}
theorem hom_lift (h : IsLimit t) {W : C} (m : W ⟶ t.pt) :
m = h.lift { pt := W, π := { app := fun b => m ≫ t.π.app b } } :=
h.uniq { pt := W, π := { app := fun b => m ≫ t.π.app b } } m fun b => rfl
#align category_theory.limits.is_limit.hom_lift CategoryTheory.Limits.IsLimit.hom_lift
/-- Two morphisms into a limit are equal if their compositions with
each cone morphism are equal. -/
theorem hom_ext (h : IsLimit t) {W : C} {f f' : W ⟶ t.pt}
(w : ∀ j, f ≫ t.π.app j = f' ≫ t.π.app j) :
f = f' := by
rw [h.hom_lift f, h.hom_lift f']; congr; exact funext w
#align category_theory.limits.is_limit.hom_ext CategoryTheory.Limits.IsLimit.hom_ext
/-- Given a right adjoint functor between categories of cones,
the image of a limit cone is a limit cone.
-/
def ofRightAdjoint {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} {left : Cone F ⥤ Cone G}
{right : Cone G ⥤ Cone F}
(adj : left ⊣ right) {c : Cone G} (t : IsLimit c) : IsLimit (right.obj c) :=
mkConeMorphism (fun s => adj.homEquiv s c (t.liftConeMorphism _))
fun _ _ => (Adjunction.eq_homEquiv_apply _ _ _).2 t.uniq_cone_morphism
#align category_theory.limits.is_limit.of_right_adjoint CategoryTheory.Limits.IsLimit.ofRightAdjoint
/-- Given two functors which have equivalent categories of cones, we can transport a limiting cone
across the equivalence.
-/
def ofConeEquiv {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F) {c : Cone G} :
IsLimit (h.functor.obj c) ≃ IsLimit c where
toFun P := ofIsoLimit (ofRightAdjoint h.toAdjunction P) (h.unitIso.symm.app c)
invFun := ofRightAdjoint h.symm.toAdjunction
left_inv := by aesop_cat
right_inv := by aesop_cat
#align category_theory.limits.is_limit.of_cone_equiv CategoryTheory.Limits.IsLimit.ofConeEquiv
@[simp]
theorem ofConeEquiv_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F)
{c : Cone G} (P : IsLimit (h.functor.obj c)) (s) :
(ofConeEquiv h P).lift s =
((h.unitIso.hom.app s).hom ≫ (h.inverse.map (P.liftConeMorphism (h.functor.obj s))).hom) ≫
(h.unitIso.inv.app c).hom :=
rfl
#align category_theory.limits.is_limit.of_cone_equiv_apply_desc CategoryTheory.Limits.IsLimit.ofConeEquiv_apply_desc
@[simp]
theorem ofConeEquiv_symm_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D}
(h : Cone G ≌ Cone F) {c : Cone G} (P : IsLimit c) (s) :
((ofConeEquiv h).symm P).lift s =
(h.counitIso.inv.app s).hom ≫ (h.functor.map (P.liftConeMorphism (h.inverse.obj s))).hom :=
rfl
#align category_theory.limits.is_limit.of_cone_equiv_symm_apply_desc CategoryTheory.Limits.IsLimit.ofConeEquiv_symm_apply_desc
/--
A cone postcomposed with a natural isomorphism is a limit cone if and only if the original cone is.
-/
def postcomposeHomEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cone F) :
IsLimit ((Cones.postcompose α.hom).obj c) ≃ IsLimit c :=
ofConeEquiv (Cones.postcomposeEquivalence α)
#align category_theory.limits.is_limit.postcompose_hom_equiv CategoryTheory.Limits.IsLimit.postcomposeHomEquiv
/-- A cone postcomposed with the inverse of a natural isomorphism is a limit cone if and only if
the original cone is.
-/
def postcomposeInvEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cone G) :
IsLimit ((Cones.postcompose α.inv).obj c) ≃ IsLimit c :=
postcomposeHomEquiv α.symm c
#align category_theory.limits.is_limit.postcompose_inv_equiv CategoryTheory.Limits.IsLimit.postcomposeInvEquiv
/-- Constructing an equivalence `IsLimit c ≃ IsLimit d` from a natural isomorphism
between the underlying functors, and then an isomorphism between `c` transported along this and `d`.
-/
def equivOfNatIsoOfIso {F G : J ⥤ C} (α : F ≅ G) (c : Cone F) (d : Cone G)
(w : (Cones.postcompose α.hom).obj c ≅ d) : IsLimit c ≃ IsLimit d :=
(postcomposeHomEquiv α _).symm.trans (equivIsoLimit w)
#align category_theory.limits.is_limit.equiv_of_nat_iso_of_iso CategoryTheory.Limits.IsLimit.equivOfNatIsoOfIso
/-- The cone points of two limit cones for naturally isomorphic functors
are themselves isomorphic.
-/
@[simps]
def conePointsIsoOfNatIso {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t)
(w : F ≅ G) : s.pt ≅ t.pt where
hom := Q.map s w.hom
inv := P.map t w.inv
hom_inv_id := P.hom_ext (by aesop_cat)
inv_hom_id := Q.hom_ext (by aesop_cat)
#align category_theory.limits.is_limit.cone_points_iso_of_nat_iso CategoryTheory.Limits.IsLimit.conePointsIsoOfNatIso
@[reassoc]
theorem conePointsIsoOfNatIso_hom_comp {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s)
(Q : IsLimit t) (w : F ≅ G) (j : J) :
(conePointsIsoOfNatIso P Q w).hom ≫ t.π.app j = s.π.app j ≫ w.hom.app j := by simp
#align category_theory.limits.is_limit.cone_points_iso_of_nat_iso_hom_comp CategoryTheory.Limits.IsLimit.conePointsIsoOfNatIso_hom_comp
@[reassoc]
theorem conePointsIsoOfNatIso_inv_comp {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s)
(Q : IsLimit t) (w : F ≅ G) (j : J) :
(conePointsIsoOfNatIso P Q w).inv ≫ s.π.app j = t.π.app j ≫ w.inv.app j := by simp
#align category_theory.limits.is_limit.cone_points_iso_of_nat_iso_inv_comp CategoryTheory.Limits.IsLimit.conePointsIsoOfNatIso_inv_comp
@[reassoc]
theorem lift_comp_conePointsIsoOfNatIso_hom {F G : J ⥤ C} {r s : Cone F} {t : Cone G}
(P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) :
P.lift r ≫ (conePointsIsoOfNatIso P Q w).hom = Q.map r w.hom :=
Q.hom_ext (by simp)
#align category_theory.limits.is_limit.lift_comp_cone_points_iso_of_nat_iso_hom CategoryTheory.Limits.IsLimit.lift_comp_conePointsIsoOfNatIso_hom
@[reassoc]
theorem lift_comp_conePointsIsoOfNatIso_inv {F G : J ⥤ C} {r s : Cone G} {t : Cone F}
(P : IsLimit t) (Q : IsLimit s) (w : F ≅ G) :
Q.lift r ≫ (conePointsIsoOfNatIso P Q w).inv = P.map r w.inv :=
P.hom_ext (by simp)
#align category_theory.limits.is_limit.lift_comp_cone_points_iso_of_nat_iso_inv CategoryTheory.Limits.IsLimit.lift_comp_conePointsIsoOfNatIso_inv
section Equivalence
open CategoryTheory.Equivalence
/-- If `s : Cone F` is a limit cone, so is `s` whiskered by an equivalence `e`.
-/
def whiskerEquivalence {s : Cone F} (P : IsLimit s) (e : K ≌ J) : IsLimit (s.whisker e.functor) :=
ofRightAdjoint (Cones.whiskeringEquivalence e).symm.toAdjunction P
#align category_theory.limits.is_limit.whisker_equivalence CategoryTheory.Limits.IsLimit.whiskerEquivalence
/-- If `s : Cone F` whiskered by an equivalence `e` is a limit cone, so is `s`.
-/
def ofWhiskerEquivalence {s : Cone F} (e : K ≌ J) (P : IsLimit (s.whisker e.functor)) : IsLimit s :=
equivIsoLimit ((Cones.whiskeringEquivalence e).unitIso.app s).symm
(ofRightAdjoint (Cones.whiskeringEquivalence e).toAdjunction P)
#align category_theory.limits.is_limit.of_whisker_equivalence CategoryTheory.Limits.IsLimit.ofWhiskerEquivalence
/-- Given an equivalence of diagrams `e`, `s` is a limit cone iff `s.whisker e.functor` is.
-/
def whiskerEquivalenceEquiv {s : Cone F} (e : K ≌ J) : IsLimit s ≃ IsLimit (s.whisker e.functor) :=
⟨fun h => h.whiskerEquivalence e, ofWhiskerEquivalence e, by aesop_cat, by aesop_cat⟩
#align category_theory.limits.is_limit.whisker_equivalence_equiv CategoryTheory.Limits.IsLimit.whiskerEquivalenceEquiv
/-- A limit cone extended by an isomorphism is a limit cone. -/
def extendIso {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] (hs : IsLimit s) :
IsLimit (s.extend i) :=
IsLimit.ofIsoLimit hs (Cones.extendIso s (asIso i)).symm
/-- A cone is a limit cone if its extension by an isomorphism is. -/
def ofExtendIso {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] (hs : IsLimit (s.extend i)) :
IsLimit s :=
IsLimit.ofIsoLimit hs (Cones.extendIso s (asIso i))
/-- A cone is a limit cone iff its extension by an isomorphism is. -/
def extendIsoEquiv {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] :
IsLimit s ≃ IsLimit (s.extend i) :=
equivOfSubsingletonOfSubsingleton (extendIso i) (ofExtendIso i)
/-- We can prove two cone points `(s : Cone F).pt` and `(t : Cone G).pt` are isomorphic if
* both cones are limit cones
* their indexing categories are equivalent via some `e : J ≌ K`,
* the triangle of functors commutes up to a natural isomorphism: `e.functor ⋙ G ≅ F`.
This is the most general form of uniqueness of cone points,
allowing relabelling of both the indexing category (up to equivalence)
and the functor (up to natural isomorphism).
-/
@[simps]
def conePointsIsoOfEquivalence {F : J ⥤ C} {s : Cone F} {G : K ⥤ C} {t : Cone G} (P : IsLimit s)
(Q : IsLimit t) (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : s.pt ≅ t.pt :=
let w' : e.inverse ⋙ F ≅ G := (isoWhiskerLeft e.inverse w).symm ≪≫ invFunIdAssoc e G
{ hom := Q.lift ((Cones.equivalenceOfReindexing e.symm w').functor.obj s)
inv := P.lift ((Cones.equivalenceOfReindexing e w).functor.obj t)
hom_inv_id := by
apply hom_ext P; intro j
dsimp [w']
simp only [Limits.Cone.whisker_π, Limits.Cones.postcompose_obj_π, fac, whiskerLeft_app,
assoc, id_comp, invFunIdAssoc_hom_app, fac_assoc, NatTrans.comp_app]
rw [counit_app_functor, ← Functor.comp_map]
have l :
NatTrans.app w.hom j = NatTrans.app w.hom (Prefunctor.obj (𝟭 J).toPrefunctor j) := by dsimp
rw [l,w.hom.naturality]
simp
inv_hom_id := by
apply hom_ext Q
aesop_cat }
#align category_theory.limits.is_limit.cone_points_iso_of_equivalence CategoryTheory.Limits.IsLimit.conePointsIsoOfEquivalence
end Equivalence
/-- The universal property of a limit cone: a map `W ⟶ X` is the same as
a cone on `F` with cone point `W`. -/
def homIso (h : IsLimit t) (W : C) : ULift.{u₁} (W ⟶ t.pt : Type v₃) ≅ (const J).obj W ⟶ F where
hom f := (t.extend f.down).π
inv π := ⟨h.lift { pt := W, π }⟩
hom_inv_id := by
funext f; apply ULift.ext
apply h.hom_ext; intro j; simp
#align category_theory.limits.is_limit.hom_iso CategoryTheory.Limits.IsLimit.homIso
@[simp]
theorem homIso_hom (h : IsLimit t) {W : C} (f : ULift.{u₁} (W ⟶ t.pt)) :
(IsLimit.homIso h W).hom f = (t.extend f.down).π :=
rfl
#align category_theory.limits.is_limit.hom_iso_hom CategoryTheory.Limits.IsLimit.homIso_hom
/-- The limit of `F` represents the functor taking `W` to
the set of cones on `F` with cone point `W`. -/
def natIso (h : IsLimit t) : yoneda.obj t.pt ⋙ uliftFunctor.{u₁} ≅ F.cones :=
NatIso.ofComponents fun W => IsLimit.homIso h (unop W)
#align category_theory.limits.is_limit.nat_iso CategoryTheory.Limits.IsLimit.natIso
/-- Another, more explicit, formulation of the universal property of a limit cone.
See also `homIso`. -/
def homIso' (h : IsLimit t) (W : C) :
ULift.{u₁} (W ⟶ t.pt : Type v₃) ≅
{ p : ∀ j, W ⟶ F.obj j // ∀ {j j'} (f : j ⟶ j'), p j ≫ F.map f = p j' } :=
h.homIso W ≪≫
{ hom := fun π =>
⟨fun j => π.app j, fun f => by convert ← (π.naturality f).symm; apply id_comp⟩
inv := fun p =>
{ app := fun j => p.1 j
naturality := fun j j' f => by dsimp; rw [id_comp]; exact (p.2 f).symm } }
#align category_theory.limits.is_limit.hom_iso' CategoryTheory.Limits.IsLimit.homIso'
/-- If G : C → D is a faithful functor which sends t to a limit cone,
then it suffices to check that the induced maps for the image of t
can be lifted to maps of C. -/
def ofFaithful {t : Cone F} {D : Type u₄} [Category.{v₄} D] (G : C ⥤ D) [G.Faithful]
(ht : IsLimit (mapCone G t)) (lift : ∀ s : Cone F, s.pt ⟶ t.pt)
(h : ∀ s, G.map (lift s) = ht.lift (mapCone G s)) : IsLimit t :=
{ lift
fac := fun s j => by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac
uniq := fun s m w => by
apply G.map_injective; rw [h]
refine ht.uniq (mapCone G s) _ fun j => ?_
convert ← congrArg (fun f => G.map f) (w j)
apply G.map_comp }
#align category_theory.limits.is_limit.of_faithful CategoryTheory.Limits.IsLimit.ofFaithful
/-- If `F` and `G` are naturally isomorphic, then `F.mapCone c` being a limit implies
`G.mapCone c` is also a limit.
-/
def mapConeEquiv {D : Type u₄} [Category.{v₄} D] {K : J ⥤ C} {F G : C ⥤ D} (h : F ≅ G) {c : Cone K}
(t : IsLimit (mapCone F c)) : IsLimit (mapCone G c) := by
apply postcomposeInvEquiv (isoWhiskerLeft K h : _) (mapCone G c) _
apply t.ofIsoLimit (postcomposeWhiskerLeftMapCone h.symm c).symm
#align category_theory.limits.is_limit.map_cone_equiv CategoryTheory.Limits.IsLimit.mapConeEquiv
/-- A cone is a limit cone exactly if
there is a unique cone morphism from any other cone.
-/
def isoUniqueConeMorphism {t : Cone F} : IsLimit t ≅ ∀ s, Unique (s ⟶ t) where
hom h s :=
{ default := h.liftConeMorphism s
uniq := fun _ => h.uniq_cone_morphism }
inv h :=
{ lift := fun s => (h s).default.hom
uniq := fun s f w => congrArg ConeMorphism.hom ((h s).uniq ⟨f, w⟩) }
#align category_theory.limits.is_limit.iso_unique_cone_morphism CategoryTheory.Limits.IsLimit.isoUniqueConeMorphism
namespace OfNatIso
variable {X : C} (h : yoneda.obj X ⋙ uliftFunctor.{u₁} ≅ F.cones)
/-- If `F.cones` is represented by `X`, each morphism `f : Y ⟶ X` gives a cone with cone point
`Y`. -/
def coneOfHom {Y : C} (f : Y ⟶ X) : Cone F where
pt := Y
π := h.hom.app (op Y) ⟨f⟩
#align category_theory.limits.is_limit.of_nat_iso.cone_of_hom CategoryTheory.Limits.IsLimit.OfNatIso.coneOfHom
/-- If `F.cones` is represented by `X`, each cone `s` gives a morphism `s.pt ⟶ X`. -/
def homOfCone (s : Cone F) : s.pt ⟶ X :=
(h.inv.app (op s.pt) s.π).down
#align category_theory.limits.is_limit.of_nat_iso.hom_of_cone CategoryTheory.Limits.IsLimit.OfNatIso.homOfCone
@[simp]
theorem coneOfHom_homOfCone (s : Cone F) : coneOfHom h (homOfCone h s) = s := by
dsimp [coneOfHom, homOfCone]
match s with
| .mk s_pt s_π =>
congr; dsimp
convert congrFun (congrFun (congrArg NatTrans.app h.inv_hom_id) (op s_pt)) s_π using 1
#align category_theory.limits.is_limit.of_nat_iso.cone_of_hom_of_cone CategoryTheory.Limits.IsLimit.OfNatIso.coneOfHom_homOfCone
@[simp]
theorem homOfCone_coneOfHom {Y : C} (f : Y ⟶ X) : homOfCone h (coneOfHom h f) = f :=
congrArg ULift.down (congrFun (congrFun (congrArg NatTrans.app h.hom_inv_id) (op Y)) ⟨f⟩ : _)
#align category_theory.limits.is_limit.of_nat_iso.hom_of_cone_of_hom CategoryTheory.Limits.IsLimit.OfNatIso.homOfCone_coneOfHom
/-- If `F.cones` is represented by `X`, the cone corresponding to the identity morphism on `X`
will be a limit cone. -/
def limitCone : Cone F :=
coneOfHom h (𝟙 X)
#align category_theory.limits.is_limit.of_nat_iso.limit_cone CategoryTheory.Limits.IsLimit.OfNatIso.limitCone
/-- If `F.cones` is represented by `X`, the cone corresponding to a morphism `f : Y ⟶ X` is
the limit cone extended by `f`. -/
theorem coneOfHom_fac {Y : C} (f : Y ⟶ X) : coneOfHom h f = (limitCone h).extend f := by
dsimp [coneOfHom, limitCone, Cone.extend]
congr with j
have t := congrFun (h.hom.naturality f.op) ⟨𝟙 X⟩
dsimp at t
simp only [comp_id] at t
rw [congrFun (congrArg NatTrans.app t) j]
rfl
#align category_theory.limits.is_limit.of_nat_iso.cone_of_hom_fac CategoryTheory.Limits.IsLimit.OfNatIso.coneOfHom_fac
/-- If `F.cones` is represented by `X`, any cone is the extension of the limit cone by the
corresponding morphism. -/
theorem cone_fac (s : Cone F) : (limitCone h).extend (homOfCone h s) = s := by
rw [← coneOfHom_homOfCone h s]
conv_lhs => simp only [homOfCone_coneOfHom]
apply (coneOfHom_fac _ _).symm
#align category_theory.limits.is_limit.of_nat_iso.cone_fac CategoryTheory.Limits.IsLimit.OfNatIso.cone_fac
end OfNatIso
section
open OfNatIso
/-- If `F.cones` is representable, then the cone corresponding to the identity morphism on
the representing object is a limit cone.
-/
def ofNatIso {X : C} (h : yoneda.obj X ⋙ uliftFunctor.{u₁} ≅ F.cones) : IsLimit (limitCone h) where
lift s := homOfCone h s
fac s j := by
have h := cone_fac h s
cases s
injection h with h₁ h₂
simp only [heq_iff_eq] at h₂
conv_rhs => rw [← h₂]
rfl
uniq s m w := by
rw [← homOfCone_coneOfHom h m]
congr
rw [coneOfHom_fac]
dsimp [Cone.extend]; cases s; congr with j; exact w j
#align category_theory.limits.is_limit.of_nat_iso CategoryTheory.Limits.IsLimit.ofNatIso
end
end IsLimit
/-- A cocone `t` on `F` is a colimit cocone if each cocone on `F` admits a unique
cocone morphism from `t`.
See <https://stacks.math.columbia.edu/tag/002F>.
-/
-- Porting note(#5171): removed @[nolint has_nonempty_instance]
structure IsColimit (t : Cocone F) where
/-- `t.pt` maps to all other cocone covertices -/
desc : ∀ s : Cocone F, t.pt ⟶ s.pt
/-- The map `desc` makes the diagram with the natural transformations commute -/
fac : ∀ (s : Cocone F) (j : J), t.ι.app j ≫ desc s = s.ι.app j := by aesop_cat
/-- `desc` is the unique such map -/
uniq :
∀ (s : Cocone F) (m : t.pt ⟶ s.pt) (_ : ∀ j : J, t.ι.app j ≫ m = s.ι.app j), m = desc s := by
aesop_cat
#align category_theory.limits.is_colimit CategoryTheory.Limits.IsColimit
#align category_theory.limits.is_colimit.fac' CategoryTheory.Limits.IsColimit.fac
#align category_theory.limits.is_colimit.uniq' CategoryTheory.Limits.IsColimit.uniq
attribute [reassoc (attr := simp)] IsColimit.fac
-- Porting note (#10618): simp can prove this. Linter claims it still is tagged with simp
attribute [-simp, nolint simpNF] IsColimit.mk.injEq
namespace IsColimit
instance subsingleton {t : Cocone F} : Subsingleton (IsColimit t) :=
⟨by intro P Q; cases P; cases Q; congr; aesop_cat⟩
#align category_theory.limits.is_colimit.subsingleton CategoryTheory.Limits.IsColimit.subsingleton
/-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cocone point
of a colimit cocone over `F` to the cocone point of any cocone over `G`. -/
def map {F G : J ⥤ C} {s : Cocone F} (P : IsColimit s) (t : Cocone G) (α : F ⟶ G) : s.pt ⟶ t.pt :=
P.desc ((Cocones.precompose α).obj t)
#align category_theory.limits.is_colimit.map CategoryTheory.Limits.IsColimit.map
@[reassoc (attr := simp)]
theorem ι_map {F G : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (d : Cocone G) (α : F ⟶ G) (j : J) :
c.ι.app j ≫ IsColimit.map hc d α = α.app j ≫ d.ι.app j :=
fac _ _ _
#align category_theory.limits.is_colimit.ι_map CategoryTheory.Limits.IsColimit.ι_map
@[simp]
theorem desc_self {t : Cocone F} (h : IsColimit t) : h.desc t = 𝟙 t.pt :=
(h.uniq _ _ fun _ => comp_id _).symm
#align category_theory.limits.is_colimit.desc_self CategoryTheory.Limits.IsColimit.desc_self
-- Repackaging the definition in terms of cocone morphisms.
/-- The universal morphism from a colimit cocone to any other cocone. -/
@[simps]
def descCoconeMorphism {t : Cocone F} (h : IsColimit t) (s : Cocone F) : t ⟶ s where hom := h.desc s
#align category_theory.limits.is_colimit.desc_cocone_morphism CategoryTheory.Limits.IsColimit.descCoconeMorphism
theorem uniq_cocone_morphism {s t : Cocone F} (h : IsColimit t) {f f' : t ⟶ s} : f = f' :=
have : ∀ {g : t ⟶ s}, g = h.descCoconeMorphism s := by
intro g; ext; exact h.uniq _ _ g.w
this.trans this.symm
#align category_theory.limits.is_colimit.uniq_cocone_morphism CategoryTheory.Limits.IsColimit.uniq_cocone_morphism
/-- Restating the definition of a colimit cocone in terms of the ∃! operator. -/
theorem existsUnique {t : Cocone F} (h : IsColimit t) (s : Cocone F) :
∃! d : t.pt ⟶ s.pt, ∀ j, t.ι.app j ≫ d = s.ι.app j :=
⟨h.desc s, h.fac s, h.uniq s⟩
#align category_theory.limits.is_colimit.exists_unique CategoryTheory.Limits.IsColimit.existsUnique
/-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/
def ofExistsUnique {t : Cocone F}
(ht : ∀ s : Cocone F, ∃! d : t.pt ⟶ s.pt, ∀ j, t.ι.app j ≫ d = s.ι.app j) : IsColimit t := by
choose s hs hs' using ht
exact ⟨s, hs, hs'⟩
#align category_theory.limits.is_colimit.of_exists_unique CategoryTheory.Limits.IsColimit.ofExistsUnique
/-- Alternative constructor for `IsColimit`,
providing a morphism of cocones rather than a morphism between the cocone points
and separately the factorisation condition.
-/
@[simps]
def mkCoconeMorphism {t : Cocone F} (desc : ∀ s : Cocone F, t ⟶ s)
(uniq' : ∀ (s : Cocone F) (m : t ⟶ s), m = desc s) : IsColimit t where
desc s := (desc s).hom
uniq s m w :=
have : CoconeMorphism.mk m w = desc s := by apply uniq'
congrArg CoconeMorphism.hom this
#align category_theory.limits.is_colimit.mk_cocone_morphism CategoryTheory.Limits.IsColimit.mkCoconeMorphism
/-- Colimit cocones on `F` are unique up to isomorphism. -/
@[simps]
def uniqueUpToIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : s ≅ t where
hom := P.descCoconeMorphism t
inv := Q.descCoconeMorphism s
hom_inv_id := P.uniq_cocone_morphism
inv_hom_id := Q.uniq_cocone_morphism
#align category_theory.limits.is_colimit.unique_up_to_iso CategoryTheory.Limits.IsColimit.uniqueUpToIso
/-- Any cocone morphism between colimit cocones is an isomorphism. -/
theorem hom_isIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) (f : s ⟶ t) : IsIso f :=
⟨⟨Q.descCoconeMorphism s, ⟨P.uniq_cocone_morphism, Q.uniq_cocone_morphism⟩⟩⟩
#align category_theory.limits.is_colimit.hom_is_iso CategoryTheory.Limits.IsColimit.hom_isIso
/-- Colimits of `F` are unique up to isomorphism. -/
def coconePointUniqueUpToIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : s.pt ≅ t.pt :=
(Cocones.forget F).mapIso (uniqueUpToIso P Q)
#align category_theory.limits.is_colimit.cocone_point_unique_up_to_iso CategoryTheory.Limits.IsColimit.coconePointUniqueUpToIso
@[reassoc (attr := simp)]
theorem comp_coconePointUniqueUpToIso_hom {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t)
(j : J) : s.ι.app j ≫ (coconePointUniqueUpToIso P Q).hom = t.ι.app j :=
(uniqueUpToIso P Q).hom.w _
#align category_theory.limits.is_colimit.comp_cocone_point_unique_up_to_iso_hom CategoryTheory.Limits.IsColimit.comp_coconePointUniqueUpToIso_hom
@[reassoc (attr := simp)]
theorem comp_coconePointUniqueUpToIso_inv {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t)
(j : J) : t.ι.app j ≫ (coconePointUniqueUpToIso P Q).inv = s.ι.app j :=
(uniqueUpToIso P Q).inv.w _
#align category_theory.limits.is_colimit.comp_cocone_point_unique_up_to_iso_inv CategoryTheory.Limits.IsColimit.comp_coconePointUniqueUpToIso_inv
@[reassoc (attr := simp)]
theorem coconePointUniqueUpToIso_hom_desc {r s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) :
(coconePointUniqueUpToIso P Q).hom ≫ Q.desc r = P.desc r :=
P.uniq _ _ (by simp)
#align category_theory.limits.is_colimit.cocone_point_unique_up_to_iso_hom_desc CategoryTheory.Limits.IsColimit.coconePointUniqueUpToIso_hom_desc
@[reassoc (attr := simp)]
theorem coconePointUniqueUpToIso_inv_desc {r s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) :
(coconePointUniqueUpToIso P Q).inv ≫ P.desc r = Q.desc r :=
Q.uniq _ _ (by simp)
#align category_theory.limits.is_colimit.cocone_point_unique_up_to_iso_inv_desc CategoryTheory.Limits.IsColimit.coconePointUniqueUpToIso_inv_desc
/-- Transport evidence that a cocone is a colimit cocone across an isomorphism of cocones. -/
def ofIsoColimit {r t : Cocone F} (P : IsColimit r) (i : r ≅ t) : IsColimit t :=
IsColimit.mkCoconeMorphism (fun s => i.inv ≫ P.descCoconeMorphism s) fun s m => by
rw [i.eq_inv_comp]; apply P.uniq_cocone_morphism
#align category_theory.limits.is_colimit.of_iso_colimit CategoryTheory.Limits.IsColimit.ofIsoColimit
@[simp]
theorem ofIsoColimit_desc {r t : Cocone F} (P : IsColimit r) (i : r ≅ t) (s) :
(P.ofIsoColimit i).desc s = i.inv.hom ≫ P.desc s :=
rfl
#align category_theory.limits.is_colimit.of_iso_colimit_desc CategoryTheory.Limits.IsColimit.ofIsoColimit_desc
/-- Isomorphism of cocones preserves whether or not they are colimiting cocones. -/
def equivIsoColimit {r t : Cocone F} (i : r ≅ t) : IsColimit r ≃ IsColimit t where
toFun h := h.ofIsoColimit i
invFun h := h.ofIsoColimit i.symm
left_inv := by aesop_cat
right_inv := by aesop_cat
#align category_theory.limits.is_colimit.equiv_iso_colimit CategoryTheory.Limits.IsColimit.equivIsoColimit
@[simp]
theorem equivIsoColimit_apply {r t : Cocone F} (i : r ≅ t) (P : IsColimit r) :
equivIsoColimit i P = P.ofIsoColimit i :=
rfl
#align category_theory.limits.is_colimit.equiv_iso_colimit_apply CategoryTheory.Limits.IsColimit.equivIsoColimit_apply
@[simp]
theorem equivIsoColimit_symm_apply {r t : Cocone F} (i : r ≅ t) (P : IsColimit t) :
(equivIsoColimit i).symm P = P.ofIsoColimit i.symm :=
rfl
#align category_theory.limits.is_colimit.equiv_iso_colimit_symm_apply CategoryTheory.Limits.IsColimit.equivIsoColimit_symm_apply
/-- If the canonical morphism to a cocone point from a colimiting cocone point is an iso, then the
first cocone was colimiting also.
-/
def ofPointIso {r t : Cocone F} (P : IsColimit r) [i : IsIso (P.desc t)] : IsColimit t :=
ofIsoColimit P (by
haveI : IsIso (P.descCoconeMorphism t).hom := i
haveI : IsIso (P.descCoconeMorphism t) := Cocones.cocone_iso_of_hom_iso _
apply asIso (P.descCoconeMorphism t))
#align category_theory.limits.is_colimit.of_point_iso CategoryTheory.Limits.IsColimit.ofPointIso
variable {t : Cocone F}
| Mathlib/CategoryTheory/Limits/IsLimit.lean | 732 | 744 | theorem hom_desc (h : IsColimit t) {W : C} (m : t.pt ⟶ W) :
m =
h.desc
{ pt := W
ι :=
{ app := fun b => t.ι.app b ≫ m
naturality := by | intros; erw [← assoc, t.ι.naturality, comp_id, comp_id] } } :=
h.uniq
{ pt := W
ι :=
{ app := fun b => t.ι.app b ≫ m
naturality := _ } }
m fun _ => rfl
|
/-
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]
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
#align lagrange.eval_basis_self Lagrange.eval_basis_self
@[simp]
theorem eval_basis_of_ne (hij : i ≠ j) (hj : j ∈ s) : (Lagrange.basis s v i).eval (v j) = 0 := by
simp_rw [Lagrange.basis, eval_prod, prod_eq_zero_iff]
exact ⟨j, ⟨mem_erase.mpr ⟨hij.symm, hj⟩, eval_basisDivisor_right⟩⟩
#align lagrange.eval_basis_of_ne Lagrange.eval_basis_of_ne
@[simp]
theorem natDegree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) :
(Lagrange.basis s v i).natDegree = s.card - 1 := by
have H : ∀ j, j ∈ s.erase i → basisDivisor (v i) (v j) ≠ 0 := by
simp_rw [Ne, mem_erase, basisDivisor_eq_zero_iff]
exact fun j ⟨hij₁, hj⟩ hij₂ => hij₁ (hvs hj hi hij₂.symm)
rw [← card_erase_of_mem hi, card_eq_sum_ones]
convert natDegree_prod _ _ H using 1
refine sum_congr rfl fun j hj => (natDegree_basisDivisor_of_ne ?_).symm
rw [Ne, ← basisDivisor_eq_zero_iff]
exact H _ hj
#align lagrange.nat_degree_basis Lagrange.natDegree_basis
theorem degree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) :
(Lagrange.basis s v i).degree = ↑(s.card - 1) := by
rw [degree_eq_natDegree (basis_ne_zero hvs hi), natDegree_basis hvs hi]
#align lagrange.degree_basis Lagrange.degree_basis
-- Porting note: Added `Nat.cast_withBot` rewrites
theorem sum_basis (hvs : Set.InjOn v s) (hs : s.Nonempty) :
∑ j ∈ s, Lagrange.basis s v j = 1 := by
refine eq_of_degrees_lt_of_eval_index_eq s hvs (lt_of_le_of_lt (degree_sum_le _ _) ?_) ?_ ?_
· rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe s.card)]
intro i hi
rw [degree_basis hvs hi, Nat.cast_withBot, WithBot.coe_lt_coe]
exact Nat.pred_lt (card_ne_zero_of_mem hi)
· rw [degree_one, ← WithBot.coe_zero, Nat.cast_withBot, WithBot.coe_lt_coe]
exact Nonempty.card_pos hs
· intro i hi
rw [eval_finset_sum, eval_one, ← add_sum_erase _ _ hi, eval_basis_self hvs hi,
add_right_eq_self]
refine sum_eq_zero fun j hj => ?_
rcases mem_erase.mp hj with ⟨hij, _⟩
rw [eval_basis_of_ne hij hi]
#align lagrange.sum_basis Lagrange.sum_basis
theorem basisDivisor_add_symm {x y : F} (hxy : x ≠ y) :
basisDivisor x y + basisDivisor y x = 1 := by
classical
rw [ ← sum_basis Function.injective_id.injOn ⟨x, mem_insert_self _ {y}⟩,
sum_insert (not_mem_singleton.mpr hxy), sum_singleton, basis_pair_left hxy,
basis_pair_right hxy, id, id]
#align lagrange.basis_divisor_add_symm Lagrange.basisDivisor_add_symm
end Basis
section Interpolate
variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι]
variable {s t : Finset ι} {i j : ι} {v : ι → F} (r r' : ι → F)
open Finset
/-- Lagrange interpolation: given a finset `s : Finset ι`, a nodal map `v : ι → F` injective on
`s` and a value function `r : ι → F`, `interpolate s v r` is the unique
polynomial of degree `< s.card` that takes value `r i` on `v i` for all `i` in `s`. -/
@[simps]
def interpolate (s : Finset ι) (v : ι → F) : (ι → F) →ₗ[F] F[X] where
toFun r := ∑ i ∈ s, C (r i) * Lagrange.basis s v i
map_add' f g := by
simp_rw [← Finset.sum_add_distrib]
have h : (fun x => C (f x) * Lagrange.basis s v x + C (g x) * Lagrange.basis s v x) =
(fun x => C ((f + g) x) * Lagrange.basis s v x) := by
simp_rw [← add_mul, ← C_add, Pi.add_apply]
rw [h]
map_smul' c f := by
simp_rw [Finset.smul_sum, C_mul', smul_smul, Pi.smul_apply, RingHom.id_apply, smul_eq_mul]
#align lagrange.interpolate Lagrange.interpolate
-- Porting note (#10618): There was originally '@[simp]' on this line but it was removed because
-- 'simp' could prove 'interpolate_empty'
theorem interpolate_empty : interpolate ∅ v r = 0 := by rw [interpolate_apply, sum_empty]
#align lagrange.interpolate_empty Lagrange.interpolate_empty
-- Porting note (#10618): There was originally '@[simp]' on this line but it was removed because
-- 'simp' could prove 'interpolate_singleton'
theorem interpolate_singleton : interpolate {i} v r = C (r i) := by
rw [interpolate_apply, sum_singleton, basis_singleton, mul_one]
#align lagrange.interpolate_singleton Lagrange.interpolate_singleton
theorem interpolate_one (hvs : Set.InjOn v s) (hs : s.Nonempty) : interpolate s v 1 = 1 := by
simp_rw [interpolate_apply, Pi.one_apply, map_one, one_mul]
exact sum_basis hvs hs
#align lagrange.interpolate_one Lagrange.interpolate_one
theorem eval_interpolate_at_node (hvs : Set.InjOn v s) (hi : i ∈ s) :
eval (v i) (interpolate s v r) = r i := by
rw [interpolate_apply, eval_finset_sum, ← add_sum_erase _ _ hi]
simp_rw [eval_mul, eval_C, eval_basis_self hvs hi, mul_one, add_right_eq_self]
refine sum_eq_zero fun j H => ?_
rw [eval_basis_of_ne (mem_erase.mp H).1 hi, mul_zero]
#align lagrange.eval_interpolate_at_node Lagrange.eval_interpolate_at_node
theorem degree_interpolate_le (hvs : Set.InjOn v s) :
(interpolate s v r).degree ≤ ↑(s.card - 1) := by
refine (degree_sum_le _ _).trans ?_
rw [Finset.sup_le_iff]
intro i hi
rw [degree_mul, degree_basis hvs hi]
by_cases hr : r i = 0
· simpa only [hr, map_zero, degree_zero, WithBot.bot_add] using bot_le
· rw [degree_C hr, zero_add]
#align lagrange.degree_interpolate_le Lagrange.degree_interpolate_le
-- Porting note: Added `Nat.cast_withBot` rewrites
theorem degree_interpolate_lt (hvs : Set.InjOn v s) : (interpolate s v r).degree < s.card := by
rw [Nat.cast_withBot]
rcases eq_empty_or_nonempty s with (rfl | h)
· rw [interpolate_empty, degree_zero, card_empty]
exact WithBot.bot_lt_coe _
· refine lt_of_le_of_lt (degree_interpolate_le _ hvs) ?_
rw [Nat.cast_withBot, WithBot.coe_lt_coe]
exact Nat.sub_lt (Nonempty.card_pos h) zero_lt_one
#align lagrange.degree_interpolate_lt Lagrange.degree_interpolate_lt
theorem degree_interpolate_erase_lt (hvs : Set.InjOn v s) (hi : i ∈ s) :
(interpolate (s.erase i) v r).degree < ↑(s.card - 1) := by
rw [← Finset.card_erase_of_mem hi]
exact degree_interpolate_lt _ (Set.InjOn.mono (coe_subset.mpr (erase_subset _ _)) hvs)
#align lagrange.degree_interpolate_erase_lt Lagrange.degree_interpolate_erase_lt
theorem values_eq_on_of_interpolate_eq (hvs : Set.InjOn v s)
(hrr' : interpolate s v r = interpolate s v r') : ∀ i ∈ s, r i = r' i := fun _ hi => by
rw [← eval_interpolate_at_node r hvs hi, hrr', eval_interpolate_at_node r' hvs hi]
#align lagrange.values_eq_on_of_interpolate_eq Lagrange.values_eq_on_of_interpolate_eq
theorem interpolate_eq_of_values_eq_on (hrr' : ∀ i ∈ s, r i = r' i) :
interpolate s v r = interpolate s v r' :=
sum_congr rfl fun i hi => by rw [hrr' _ hi]
#align lagrange.interpolate_eq_of_values_eq_on Lagrange.interpolate_eq_of_values_eq_on
theorem interpolate_eq_iff_values_eq_on (hvs : Set.InjOn v s) :
interpolate s v r = interpolate s v r' ↔ ∀ i ∈ s, r i = r' i :=
⟨values_eq_on_of_interpolate_eq _ _ hvs, interpolate_eq_of_values_eq_on _ _⟩
#align lagrange.interpolate_eq_iff_values_eq_on Lagrange.interpolate_eq_iff_values_eq_on
theorem eq_interpolate {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < s.card) :
f = interpolate s v fun i => f.eval (v i) :=
eq_of_degrees_lt_of_eval_index_eq _ hvs degree_f_lt (degree_interpolate_lt _ hvs) fun _ hi =>
(eval_interpolate_at_node (fun x ↦ eval (v x) f) hvs hi).symm
#align lagrange.eq_interpolate Lagrange.eq_interpolate
theorem eq_interpolate_of_eval_eq {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < s.card)
(eval_f : ∀ i ∈ s, f.eval (v i) = r i) : f = interpolate s v r := by
rw [eq_interpolate hvs degree_f_lt]
exact interpolate_eq_of_values_eq_on _ _ eval_f
#align lagrange.eq_interpolate_of_eval_eq Lagrange.eq_interpolate_of_eval_eq
/-- This is the characteristic property of the interpolation: the interpolation is the
unique polynomial of `degree < Fintype.card ι` which takes the value of the `r i` on the `v i`.
-/
theorem eq_interpolate_iff {f : F[X]} (hvs : Set.InjOn v s) :
(f.degree < s.card ∧ ∀ i ∈ s, eval (v i) f = r i) ↔ f = interpolate s v r := by
constructor <;> intro h
· exact eq_interpolate_of_eval_eq _ hvs h.1 h.2
· rw [h]
exact ⟨degree_interpolate_lt _ hvs, fun _ hi => eval_interpolate_at_node _ hvs hi⟩
#align lagrange.eq_interpolate_iff Lagrange.eq_interpolate_iff
/-- Lagrange interpolation induces isomorphism between functions from `s`
and polynomials of degree less than `Fintype.card ι`. -/
def funEquivDegreeLT (hvs : Set.InjOn v s) : degreeLT F s.card ≃ₗ[F] s → F where
toFun f i := f.1.eval (v i)
map_add' f g := funext fun v => eval_add
map_smul' c f := funext <| by simp
invFun r :=
⟨interpolate s v fun x => if hx : x ∈ s then r ⟨x, hx⟩ else 0,
mem_degreeLT.2 <| degree_interpolate_lt _ hvs⟩
left_inv := by
rintro ⟨f, hf⟩
simp only [Subtype.mk_eq_mk, Subtype.coe_mk, dite_eq_ite]
rw [mem_degreeLT] at hf
conv => rhs; rw [eq_interpolate hvs hf]
exact interpolate_eq_of_values_eq_on _ _ fun _ hi => if_pos hi
right_inv := by
intro f
ext ⟨i, hi⟩
simp only [Subtype.coe_mk, eval_interpolate_at_node _ hvs hi]
exact dif_pos hi
#align lagrange.fun_equiv_degree_lt Lagrange.funEquivDegreeLT
-- Porting note: Added `Nat.cast_withBot` rewrites
theorem interpolate_eq_sum_interpolate_insert_sdiff (hvt : Set.InjOn v t) (hs : s.Nonempty)
(hst : s ⊆ t) :
interpolate t v r = ∑ i ∈ s, interpolate (insert i (t \ s)) v r * Lagrange.basis s v i := by
symm
refine eq_interpolate_of_eval_eq _ hvt (lt_of_le_of_lt (degree_sum_le _ _) ?_) fun i hi => ?_
· simp_rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe t.card), degree_mul]
intro i hi
have hs : 1 ≤ s.card := Nonempty.card_pos ⟨_, hi⟩
have hst' : s.card ≤ t.card := card_le_card hst
have H : t.card = 1 + (t.card - s.card) + (s.card - 1) := by
rw [add_assoc, tsub_add_tsub_cancel hst' hs, ← add_tsub_assoc_of_le (hs.trans hst'),
Nat.succ_add_sub_one, zero_add]
rw [degree_basis (Set.InjOn.mono hst hvt) hi, H, WithBot.coe_add, Nat.cast_withBot,
WithBot.add_lt_add_iff_right (@WithBot.coe_ne_bot _ (s.card - 1))]
convert degree_interpolate_lt _
(hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hst hi, sdiff_subset⟩)))
rw [card_insert_of_not_mem (not_mem_sdiff_of_mem_right hi), card_sdiff hst, add_comm]
· simp_rw [eval_finset_sum, eval_mul]
by_cases hi' : i ∈ s
· rw [← add_sum_erase _ _ hi', eval_basis_self (hvt.mono hst) hi',
eval_interpolate_at_node _
(hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hi, sdiff_subset⟩)))
(mem_insert_self _ _),
mul_one, add_right_eq_self]
refine sum_eq_zero fun j hj => ?_
rcases mem_erase.mp hj with ⟨hij, _⟩
rw [eval_basis_of_ne hij hi', mul_zero]
· have H : (∑ j ∈ s, eval (v i) (Lagrange.basis s v j)) = 1 := by
rw [← eval_finset_sum, sum_basis (hvt.mono hst) hs, eval_one]
rw [← mul_one (r i), ← H, mul_sum]
refine sum_congr rfl fun j hj => ?_
congr
exact
eval_interpolate_at_node _ (hvt.mono (insert_subset_iff.mpr ⟨hst hj, sdiff_subset⟩))
(mem_insert.mpr (Or.inr (mem_sdiff.mpr ⟨hi, hi'⟩)))
#align lagrange.interpolate_eq_sum_interpolate_insert_sdiff Lagrange.interpolate_eq_sum_interpolate_insert_sdiff
theorem interpolate_eq_add_interpolate_erase (hvs : Set.InjOn v s) (hi : i ∈ s) (hj : j ∈ s)
(hij : i ≠ j) :
interpolate s v r =
interpolate (s.erase j) v r * basisDivisor (v i) (v j) +
interpolate (s.erase i) v r * basisDivisor (v j) (v i) := by
rw [interpolate_eq_sum_interpolate_insert_sdiff _ hvs ⟨i, mem_insert_self i {j}⟩ _,
sum_insert (not_mem_singleton.mpr hij), sum_singleton, basis_pair_left hij,
basis_pair_right hij, sdiff_insert_insert_of_mem_of_not_mem hi (not_mem_singleton.mpr hij),
sdiff_singleton_eq_erase, pair_comm,
sdiff_insert_insert_of_mem_of_not_mem hj (not_mem_singleton.mpr hij.symm),
sdiff_singleton_eq_erase]
exact insert_subset_iff.mpr ⟨hi, singleton_subset_iff.mpr hj⟩
#align lagrange.interpolate_eq_add_interpolate_erase Lagrange.interpolate_eq_add_interpolate_erase
end Interpolate
section Nodal
variable {R : Type*} [CommRing R] {ι : Type*}
variable {s : Finset ι} {v : ι → R}
open Finset Polynomial
/-- `nodal s v` is the unique monic polynomial whose roots are the nodes defined by `v` and `s`.
That is, the roots of `nodal s v` are exactly the image of `v` on `s`,
with appropriate multiplicity.
We can use `nodal` to define the barycentric forms of the evaluated interpolant.
-/
def nodal (s : Finset ι) (v : ι → R) : R[X] :=
∏ i ∈ s, (X - C (v i))
#align lagrange.nodal Lagrange.nodal
theorem nodal_eq (s : Finset ι) (v : ι → R) : nodal s v = ∏ i ∈ s, (X - C (v i)) :=
rfl
#align lagrange.nodal_eq Lagrange.nodal_eq
@[simp]
theorem nodal_empty : nodal ∅ v = 1 := by
rfl
#align lagrange.nodal_empty Lagrange.nodal_empty
@[simp]
theorem natDegree_nodal [Nontrivial R] : (nodal s v).natDegree = s.card := by
simp_rw [nodal, natDegree_prod_of_monic (h := fun i _ => monic_X_sub_C (v i)),
natDegree_X_sub_C, sum_const, smul_eq_mul, mul_one]
theorem nodal_ne_zero [Nontrivial R] : nodal s v ≠ 0 := by
rcases s.eq_empty_or_nonempty with (rfl | h)
· exact one_ne_zero
· apply ne_zero_of_natDegree_gt (n := 0)
simp only [natDegree_nodal, h.card_pos]
@[simp]
theorem degree_nodal [Nontrivial R] : (nodal s v).degree = s.card := by
simp_rw [degree_eq_natDegree nodal_ne_zero, natDegree_nodal]
#align lagrange.degree_nodal Lagrange.degree_nodal
theorem nodal_monic : (nodal s v).Monic :=
monic_prod_of_monic s (fun i ↦ X - C (v i)) fun i _ ↦ monic_X_sub_C (v i)
theorem eval_nodal {x : R} : (nodal s v).eval x = ∏ i ∈ s, (x - v i) := by
simp_rw [nodal, eval_prod, eval_sub, eval_X, eval_C]
#align lagrange.eval_nodal Lagrange.eval_nodal
theorem eval_nodal_at_node {i : ι} (hi : i ∈ s) : eval (v i) (nodal s v) = 0 := by
rw [eval_nodal]
exact s.prod_eq_zero hi (sub_self (v i))
#align lagrange.eval_nodal_at_node Lagrange.eval_nodal_at_node
theorem eval_nodal_not_at_node [Nontrivial R] [NoZeroDivisors R] {x : R}
(hx : ∀ i ∈ s, x ≠ v i) : eval x (nodal s v) ≠ 0 := by
simp_rw [nodal, eval_prod, prod_ne_zero_iff, eval_sub, eval_X, eval_C, sub_ne_zero]
exact hx
#align lagrange.eval_nodal_not_at_node Lagrange.eval_nodal_not_at_node
theorem nodal_eq_mul_nodal_erase [DecidableEq ι] {i : ι} (hi : i ∈ s) :
nodal s v = (X - C (v i)) * nodal (s.erase i) v := by
simp_rw [nodal, Finset.mul_prod_erase _ (fun x => X - C (v x)) hi]
#align lagrange.nodal_eq_mul_nodal_erase Lagrange.nodal_eq_mul_nodal_erase
theorem X_sub_C_dvd_nodal (v : ι → R) {i : ι} (hi : i ∈ s) : X - C (v i) ∣ nodal s v :=
⟨_, by classical exact nodal_eq_mul_nodal_erase hi⟩
set_option linter.uppercaseLean3 false in
#align lagrange.X_sub_C_dvd_nodal Lagrange.X_sub_C_dvd_nodal
theorem nodal_insert_eq_nodal [DecidableEq ι] {i : ι} (hi : i ∉ s) :
nodal (insert i s) v = (X - C (v i)) * nodal s v := by
simp_rw [nodal, prod_insert hi]
#align lagrange.nodal_insert_eq_nodal Lagrange.nodal_insert_eq_nodal
theorem derivative_nodal [DecidableEq ι] :
derivative (nodal s v) = ∑ i ∈ s, nodal (s.erase i) v := by
refine s.induction_on ?_ fun i t hit IH => ?_
· rw [nodal_empty, derivative_one, sum_empty]
· rw [nodal_insert_eq_nodal hit, derivative_mul, IH, derivative_sub, derivative_X, derivative_C,
sub_zero, one_mul, sum_insert hit, mul_sum, erase_insert hit, add_right_inj]
refine sum_congr rfl fun j hjt => ?_
rw [t.erase_insert_of_ne (ne_of_mem_of_not_mem hjt hit).symm,
nodal_insert_eq_nodal (mem_of_mem_erase.mt hit)]
#align lagrange.derivative_nodal Lagrange.derivative_nodal
| Mathlib/LinearAlgebra/Lagrange.lean | 585 | 588 | theorem eval_nodal_derivative_eval_node_eq [DecidableEq ι] {i : ι} (hi : i ∈ s) :
eval (v i) (derivative (nodal s v)) = eval (v i) (nodal (s.erase i) v) := by |
rw [derivative_nodal, eval_finset_sum, ← add_sum_erase _ _ hi, add_right_eq_self]
exact sum_eq_zero fun j hj => (eval_nodal_at_node (mem_erase.mpr ⟨(mem_erase.mp hj).1.symm, hi⟩))
|
/-
Copyright (c) 2021 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer
-/
import Mathlib.CategoryTheory.Monoidal.Free.Coherence
import Mathlib.Tactic.CategoryTheory.Coherence
import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.Tactic.ApplyFun
#align_import category_theory.monoidal.rigid.basic from "leanprover-community/mathlib"@"3d7987cda72abc473c7cdbbb075170e9ac620042"
/-!
# Rigid (autonomous) monoidal categories
This file defines rigid (autonomous) monoidal categories and the necessary theory about
exact pairings and duals.
## Main definitions
* `ExactPairing` of two objects of a monoidal category
* Type classes `HasLeftDual` and `HasRightDual` that capture that a pairing exists
* The `rightAdjointMate f` as a morphism `fᘁ : Yᘁ ⟶ Xᘁ` for a morphism `f : X ⟶ Y`
* The classes of `RightRigidCategory`, `LeftRigidCategory` and `RigidCategory`
## Main statements
* `comp_rightAdjointMate`: The adjoint mates of the composition is the composition of
adjoint mates.
## Notations
* `η_` and `ε_` denote the coevaluation and evaluation morphism of an exact pairing.
* `Xᘁ` and `ᘁX` denote the right and left dual of an object, as well as the adjoint
mate of a morphism.
## Future work
* Show that `X ⊗ Y` and `Yᘁ ⊗ Xᘁ` form an exact pairing.
* Show that the left adjoint mate of the right adjoint mate of a morphism is the morphism itself.
* Simplify constructions in the case where a symmetry or braiding is present.
* Show that `ᘁ` gives an equivalence of categories `C ≅ (Cᵒᵖ)ᴹᵒᵖ`.
* Define pivotal categories (rigid categories equipped with a natural isomorphism `ᘁᘁ ≅ 𝟙 C`).
## Notes
Although we construct the adjunction `tensorLeft Y ⊣ tensorLeft X` from `ExactPairing X Y`,
this is not a bijective correspondence.
I think the correct statement is that `tensorLeft Y` and `tensorLeft X` are
module endofunctors of `C` as a right `C` module category,
and `ExactPairing X Y` is in bijection with adjunctions compatible with this right `C` action.
## References
* <https://ncatlab.org/nlab/show/rigid+monoidal+category>
## Tags
rigid category, monoidal category
-/
open CategoryTheory MonoidalCategory
universe v v₁ v₂ v₃ u u₁ u₂ u₃
noncomputable section
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C]
/-- An exact pairing is a pair of objects `X Y : C` which admit
a coevaluation and evaluation morphism which fulfill two triangle equalities. -/
class ExactPairing (X Y : C) where
/-- Coevaluation of an exact pairing.
Do not use directly. Use `ExactPairing.coevaluation` instead. -/
coevaluation' : 𝟙_ C ⟶ X ⊗ Y
/-- Evaluation of an exact pairing.
Do not use directly. Use `ExactPairing.evaluation` instead. -/
evaluation' : Y ⊗ X ⟶ 𝟙_ C
coevaluation_evaluation' :
Y ◁ coevaluation' ≫ (α_ _ _ _).inv ≫ evaluation' ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := by
aesop_cat
evaluation_coevaluation' :
coevaluation' ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ evaluation' = (λ_ X).hom ≫ (ρ_ X).inv := by
aesop_cat
#align category_theory.exact_pairing CategoryTheory.ExactPairing
namespace ExactPairing
-- Porting note: as there is no mechanism equivalent to `[]` in Lean 3 to make
-- arguments for class fields explicit,
-- we now repeat all the fields without primes.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Making.20variable.20in.20class.20field.20explicit
variable (X Y : C)
variable [ExactPairing X Y]
/-- Coevaluation of an exact pairing. -/
def coevaluation : 𝟙_ C ⟶ X ⊗ Y := @coevaluation' _ _ _ X Y _
/-- Evaluation of an exact pairing. -/
def evaluation : Y ⊗ X ⟶ 𝟙_ C := @evaluation' _ _ _ X Y _
@[inherit_doc] notation "η_" => ExactPairing.coevaluation
@[inherit_doc] notation "ε_" => ExactPairing.evaluation
lemma coevaluation_evaluation :
Y ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ ε_ X _ ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv :=
coevaluation_evaluation'
lemma evaluation_coevaluation :
η_ _ _ ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ ε_ _ Y = (λ_ X).hom ≫ (ρ_ X).inv :=
evaluation_coevaluation'
lemma coevaluation_evaluation'' :
Y ◁ η_ X Y ⊗≫ ε_ X Y ▷ Y = ⊗𝟙 := by
convert coevaluation_evaluation X Y <;> simp [monoidalComp]
lemma evaluation_coevaluation'' :
η_ X Y ▷ X ⊗≫ X ◁ ε_ X Y = ⊗𝟙 := by
convert evaluation_coevaluation X Y <;> simp [monoidalComp]
end ExactPairing
attribute [reassoc (attr := simp)] ExactPairing.coevaluation_evaluation
attribute [reassoc (attr := simp)] ExactPairing.evaluation_coevaluation
instance exactPairingUnit : ExactPairing (𝟙_ C) (𝟙_ C) where
coevaluation' := (ρ_ _).inv
evaluation' := (ρ_ _).hom
coevaluation_evaluation' := by rw [← id_tensorHom, ← tensorHom_id]; coherence
evaluation_coevaluation' := by rw [← id_tensorHom, ← tensorHom_id]; coherence
#align category_theory.exact_pairing_unit CategoryTheory.exactPairingUnit
/-- A class of objects which have a right dual. -/
class HasRightDual (X : C) where
/-- The right dual of the object `X`. -/
rightDual : C
[exact : ExactPairing X rightDual]
#align category_theory.has_right_dual CategoryTheory.HasRightDual
/-- A class of objects which have a left dual. -/
class HasLeftDual (Y : C) where
/-- The left dual of the object `X`. -/
leftDual : C
[exact : ExactPairing leftDual Y]
#align category_theory.has_left_dual CategoryTheory.HasLeftDual
attribute [instance] HasRightDual.exact
attribute [instance] HasLeftDual.exact
open ExactPairing HasRightDual HasLeftDual MonoidalCategory
@[inherit_doc] prefix:1024 "ᘁ" => leftDual
@[inherit_doc] postfix:1024 "ᘁ" => rightDual
instance hasRightDualUnit : HasRightDual (𝟙_ C) where
rightDual := 𝟙_ C
#align category_theory.has_right_dual_unit CategoryTheory.hasRightDualUnit
instance hasLeftDualUnit : HasLeftDual (𝟙_ C) where
leftDual := 𝟙_ C
#align category_theory.has_left_dual_unit CategoryTheory.hasLeftDualUnit
instance hasRightDualLeftDual {X : C} [HasLeftDual X] : HasRightDual ᘁX where
rightDual := X
#align category_theory.has_right_dual_left_dual CategoryTheory.hasRightDualLeftDual
instance hasLeftDualRightDual {X : C} [HasRightDual X] : HasLeftDual Xᘁ where
leftDual := X
#align category_theory.has_left_dual_right_dual CategoryTheory.hasLeftDualRightDual
@[simp]
theorem leftDual_rightDual {X : C} [HasRightDual X] : ᘁXᘁ = X :=
rfl
#align category_theory.left_dual_right_dual CategoryTheory.leftDual_rightDual
@[simp]
theorem rightDual_leftDual {X : C} [HasLeftDual X] : (ᘁX)ᘁ = X :=
rfl
#align category_theory.right_dual_left_dual CategoryTheory.rightDual_leftDual
/-- The right adjoint mate `fᘁ : Xᘁ ⟶ Yᘁ` of a morphism `f : X ⟶ Y`. -/
def rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : Yᘁ ⟶ Xᘁ :=
(ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ _ ◁ f ▷ _ ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom
#align category_theory.right_adjoint_mate CategoryTheory.rightAdjointMate
/-- The left adjoint mate `ᘁf : ᘁY ⟶ ᘁX` of a morphism `f : X ⟶ Y`. -/
def leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : ᘁY ⟶ ᘁX :=
(λ_ _).inv ≫ η_ (ᘁX) X ▷ _ ≫ (_ ◁ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom
#align category_theory.left_adjoint_mate CategoryTheory.leftAdjointMate
@[inherit_doc] notation f "ᘁ" => rightAdjointMate f
@[inherit_doc] notation "ᘁ" f => leftAdjointMate f
@[simp]
theorem rightAdjointMate_id {X : C} [HasRightDual X] : (𝟙 X)ᘁ = 𝟙 (Xᘁ) := by
simp [rightAdjointMate]
#align category_theory.right_adjoint_mate_id CategoryTheory.rightAdjointMate_id
@[simp]
theorem leftAdjointMate_id {X : C} [HasLeftDual X] : (ᘁ(𝟙 X)) = 𝟙 (ᘁX) := by
simp [leftAdjointMate]
#align category_theory.left_adjoint_mate_id CategoryTheory.leftAdjointMate_id
theorem rightAdjointMate_comp {X Y Z : C} [HasRightDual X] [HasRightDual Y] {f : X ⟶ Y}
{g : Xᘁ ⟶ Z} :
fᘁ ≫ g =
(ρ_ (Yᘁ)).inv ≫
_ ◁ η_ X (Xᘁ) ≫ _ ◁ (f ⊗ g) ≫ (α_ (Yᘁ) Y Z).inv ≫ ε_ Y (Yᘁ) ▷ _ ≫ (λ_ Z).hom :=
calc
_ = 𝟙 _ ⊗≫ Yᘁ ◁ η_ X Xᘁ ≫ Yᘁ ◁ f ▷ Xᘁ ⊗≫ (ε_ Y Yᘁ ▷ Xᘁ ≫ 𝟙_ C ◁ g) ⊗≫ 𝟙 _ := by
dsimp only [rightAdjointMate]; coherence
_ = _ := by
rw [← whisker_exchange, tensorHom_def]; coherence
#align category_theory.right_adjoint_mate_comp CategoryTheory.rightAdjointMate_comp
theorem leftAdjointMate_comp {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] {f : X ⟶ Y}
{g : (ᘁX) ⟶ Z} :
(ᘁf) ≫ g =
(λ_ _).inv ≫
η_ (ᘁX) X ▷ _ ≫ (g ⊗ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom :=
calc
_ = 𝟙 _ ⊗≫ η_ (ᘁX) X ▷ (ᘁY) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ⊗≫ ((ᘁX) ◁ ε_ (ᘁY) Y ≫ g ▷ 𝟙_ C) ⊗≫ 𝟙 _ := by
dsimp only [leftAdjointMate]; coherence
_ = _ := by
rw [whisker_exchange, tensorHom_def']; coherence
#align category_theory.left_adjoint_mate_comp CategoryTheory.leftAdjointMate_comp
/-- The composition of right adjoint mates is the adjoint mate of the composition. -/
@[reassoc]
theorem comp_rightAdjointMate {X Y Z : C} [HasRightDual X] [HasRightDual Y] [HasRightDual Z]
{f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g)ᘁ = gᘁ ≫ fᘁ := by
rw [rightAdjointMate_comp]
simp only [rightAdjointMate, comp_whiskerRight]
simp only [← Category.assoc]; congr 3; simp only [Category.assoc]
simp only [← MonoidalCategory.whiskerLeft_comp]; congr 2
symm
calc
_ = 𝟙 _ ⊗≫ (η_ Y Yᘁ ▷ 𝟙_ C ≫ (Y ⊗ Yᘁ) ◁ η_ X Xᘁ) ⊗≫ Y ◁ Yᘁ ◁ f ▷ Xᘁ ⊗≫
Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by
rw [tensorHom_def']; coherence
_ = η_ X Xᘁ ⊗≫ (η_ Y Yᘁ ▷ (X ⊗ Xᘁ) ≫ (Y ⊗ Yᘁ) ◁ f ▷ Xᘁ) ⊗≫
Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by
rw [← whisker_exchange]; coherence
_ = η_ X Xᘁ ⊗≫ f ▷ Xᘁ ⊗≫ (η_ Y Yᘁ ▷ Y ⊗≫ Y ◁ ε_ Y Yᘁ) ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by
rw [← whisker_exchange]; coherence
_ = η_ X Xᘁ ≫ f ▷ Xᘁ ≫ g ▷ Xᘁ := by
rw [evaluation_coevaluation'']; coherence
#align category_theory.comp_right_adjoint_mate CategoryTheory.comp_rightAdjointMate
/-- The composition of left adjoint mates is the adjoint mate of the composition. -/
@[reassoc]
theorem comp_leftAdjointMate {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] [HasLeftDual Z] {f : X ⟶ Y}
{g : Y ⟶ Z} : (ᘁf ≫ g) = (ᘁg) ≫ ᘁf := by
rw [leftAdjointMate_comp]
simp only [leftAdjointMate, MonoidalCategory.whiskerLeft_comp]
simp only [← Category.assoc]; congr 3; simp only [Category.assoc]
simp only [← comp_whiskerRight]; congr 2
symm
calc
_ = 𝟙 _ ⊗≫ ((𝟙_ C) ◁ η_ (ᘁY) Y ≫ η_ (ᘁX) X ▷ ((ᘁY) ⊗ Y)) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ▷ Y ⊗≫
(ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by
rw [tensorHom_def]; coherence
_ = η_ (ᘁX) X ⊗≫ (((ᘁX) ⊗ X) ◁ η_ (ᘁY) Y ≫ ((ᘁX) ◁ f) ▷ ((ᘁY) ⊗ Y)) ⊗≫
(ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by
rw [whisker_exchange]; coherence
_ = η_ (ᘁX) X ⊗≫ ((ᘁX) ◁ f) ⊗≫ (ᘁX) ◁ (Y ◁ η_ (ᘁY) Y ⊗≫ ε_ (ᘁY) Y ▷ Y) ⊗≫ (ᘁX) ◁ g := by
rw [whisker_exchange]; coherence
_ = η_ (ᘁX) X ≫ (ᘁX) ◁ f ≫ (ᘁX) ◁ g := by
rw [coevaluation_evaluation'']; coherence
#align category_theory.comp_left_adjoint_mate CategoryTheory.comp_leftAdjointMate
/-- Given an exact pairing on `Y Y'`,
we get a bijection on hom-sets `(Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z)`
by "pulling the string on the left" up or down.
This gives the adjunction `tensorLeftAdjunction Y Y' : tensorLeft Y' ⊣ tensorLeft Y`.
This adjunction is often referred to as "Frobenius reciprocity" in the
fusion categories / planar algebras / subfactors literature.
-/
def tensorLeftHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z) where
toFun f := (λ_ _).inv ≫ η_ _ _ ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ f
invFun f := Y' ◁ f ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom
left_inv f := by
calc
_ = 𝟙 _ ⊗≫ Y' ◁ η_ Y Y' ▷ X ⊗≫ ((Y' ⊗ Y) ◁ f ≫ ε_ Y Y' ▷ Z) ⊗≫ 𝟙 _ := by
coherence
_ = 𝟙 _ ⊗≫ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ▷ X ⊗≫ f := by
rw [whisker_exchange]; coherence
_ = f := by
rw [coevaluation_evaluation'']; coherence
right_inv f := by
calc
_ = 𝟙 _ ⊗≫ (η_ Y Y' ▷ X ≫ (Y ⊗ Y') ◁ f) ⊗≫ Y ◁ ε_ Y Y' ▷ Z ⊗≫ 𝟙 _ := by
coherence
_ = f ⊗≫ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ▷ Z ⊗≫ 𝟙 _ := by
rw [← whisker_exchange]; coherence
_ = f := by
rw [evaluation_coevaluation'']; coherence
#align category_theory.tensor_left_hom_equiv CategoryTheory.tensorLeftHomEquiv
/-- Given an exact pairing on `Y Y'`,
we get a bijection on hom-sets `(X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y')`
by "pulling the string on the right" up or down.
-/
def tensorRightHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y') where
toFun f := (ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ f ▷ _
invFun f := f ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom
left_inv f := by
calc
_ = 𝟙 _ ⊗≫ X ◁ η_ Y Y' ▷ Y ⊗≫ (f ▷ (Y' ⊗ Y) ≫ Z ◁ ε_ Y Y') ⊗≫ 𝟙 _ := by
coherence
_ = 𝟙 _ ⊗≫ X ◁ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ⊗≫ f := by
rw [← whisker_exchange]; coherence
_ = f := by
rw [evaluation_coevaluation'']; coherence
right_inv f := by
calc
_ = 𝟙 _ ⊗≫ (X ◁ η_ Y Y' ≫ f ▷ (Y ⊗ Y')) ⊗≫ Z ◁ ε_ Y Y' ▷ Y' ⊗≫ 𝟙 _ := by
coherence
_ = f ⊗≫ Z ◁ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ⊗≫ 𝟙 _ := by
rw [whisker_exchange]; coherence
_ = f := by
rw [coevaluation_evaluation'']; coherence
#align category_theory.tensor_right_hom_equiv CategoryTheory.tensorRightHomEquiv
theorem tensorLeftHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : Y' ⊗ X ⟶ Z)
(g : Z ⟶ Z') :
(tensorLeftHomEquiv X Y Y' Z') (f ≫ g) = (tensorLeftHomEquiv X Y Y' Z) f ≫ Y ◁ g := by
simp [tensorLeftHomEquiv]
#align category_theory.tensor_left_hom_equiv_naturality CategoryTheory.tensorLeftHomEquiv_naturality
theorem tensorLeftHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X')
(g : X' ⟶ Y ⊗ Z) :
(tensorLeftHomEquiv X Y Y' Z).symm (f ≫ g) =
_ ◁ f ≫ (tensorLeftHomEquiv X' Y Y' Z).symm g := by
simp [tensorLeftHomEquiv]
#align category_theory.tensor_left_hom_equiv_symm_naturality CategoryTheory.tensorLeftHomEquiv_symm_naturality
theorem tensorRightHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⊗ Y ⟶ Z)
(g : Z ⟶ Z') :
(tensorRightHomEquiv X Y Y' Z') (f ≫ g) = (tensorRightHomEquiv X Y Y' Z) f ≫ g ▷ Y' := by
simp [tensorRightHomEquiv]
#align category_theory.tensor_right_hom_equiv_naturality CategoryTheory.tensorRightHomEquiv_naturality
theorem tensorRightHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X')
(g : X' ⟶ Z ⊗ Y') :
(tensorRightHomEquiv X Y Y' Z).symm (f ≫ g) =
f ▷ Y ≫ (tensorRightHomEquiv X' Y Y' Z).symm g := by
simp [tensorRightHomEquiv]
#align category_theory.tensor_right_hom_equiv_symm_naturality CategoryTheory.tensorRightHomEquiv_symm_naturality
/-- If `Y Y'` have an exact pairing,
then the functor `tensorLeft Y'` is left adjoint to `tensorLeft Y`.
-/
def tensorLeftAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorLeft Y' ⊣ tensorLeft Y :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Z => tensorLeftHomEquiv X Y Y' Z
homEquiv_naturality_left_symm := fun f g => tensorLeftHomEquiv_symm_naturality f g
homEquiv_naturality_right := fun f g => tensorLeftHomEquiv_naturality f g }
#align category_theory.tensor_left_adjunction CategoryTheory.tensorLeftAdjunction
/-- If `Y Y'` have an exact pairing,
then the functor `tensor_right Y` is left adjoint to `tensor_right Y'`.
-/
def tensorRightAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorRight Y ⊣ tensorRight Y' :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Z => tensorRightHomEquiv X Y Y' Z
homEquiv_naturality_left_symm := fun f g => tensorRightHomEquiv_symm_naturality f g
homEquiv_naturality_right := fun f g => tensorRightHomEquiv_naturality f g }
#align category_theory.tensor_right_adjunction CategoryTheory.tensorRightAdjunction
/--
If `Y` has a left dual `ᘁY`, then it is a closed object, with the internal hom functor `Y ⟶[C] -`
given by left tensoring by `ᘁY`.
This has to be a definition rather than an instance to avoid diamonds, for example between
`category_theory.monoidal_closed.functor_closed` and
`CategoryTheory.Monoidal.functorHasLeftDual`. Moreover, in concrete applications there is often
a more useful definition of the internal hom object than `ᘁY ⊗ X`, in which case the closed
structure shouldn't come from `has_left_dual` (e.g. in the category `FinVect k`, it is more
convenient to define the internal hom as `Y →ₗ[k] X` rather than `ᘁY ⊗ X` even though these are
naturally isomorphic).
-/
def closedOfHasLeftDual (Y : C) [HasLeftDual Y] : Closed Y where
adj := tensorLeftAdjunction (ᘁY) Y
#align category_theory.closed_of_has_left_dual CategoryTheory.closedOfHasLeftDual
/-- `tensorLeftHomEquiv` commutes with tensoring on the right -/
theorem tensorLeftHomEquiv_tensor {X X' Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⟶ Y ⊗ Z)
(g : X' ⟶ Z') :
(tensorLeftHomEquiv (X ⊗ X') Y Y' (Z ⊗ Z')).symm ((f ⊗ g) ≫ (α_ _ _ _).hom) =
(α_ _ _ _).inv ≫ ((tensorLeftHomEquiv X Y Y' Z).symm f ⊗ g) := by
simp [tensorLeftHomEquiv, tensorHom_def']
#align category_theory.tensor_left_hom_equiv_tensor CategoryTheory.tensorLeftHomEquiv_tensor
/-- `tensorRightHomEquiv` commutes with tensoring on the left -/
theorem tensorRightHomEquiv_tensor {X X' Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⟶ Z ⊗ Y')
(g : X' ⟶ Z') :
(tensorRightHomEquiv (X' ⊗ X) Y Y' (Z' ⊗ Z)).symm ((g ⊗ f) ≫ (α_ _ _ _).inv) =
(α_ _ _ _).hom ≫ (g ⊗ (tensorRightHomEquiv X Y Y' Z).symm f) := by
simp [tensorRightHomEquiv, tensorHom_def]
#align category_theory.tensor_right_hom_equiv_tensor CategoryTheory.tensorRightHomEquiv_tensor
@[simp]
theorem tensorLeftHomEquiv_symm_coevaluation_comp_whiskerLeft {Y Y' Z : C} [ExactPairing Y Y']
(f : Y' ⟶ Z) : (tensorLeftHomEquiv _ _ _ _).symm (η_ _ _ ≫ Y ◁ f) = (ρ_ _).hom ≫ f := by
calc
_ = Y' ◁ η_ Y Y' ⊗≫ ((Y' ⊗ Y) ◁ f ≫ ε_ Y Y' ▷ Z) ⊗≫ 𝟙 _ := by
dsimp [tensorLeftHomEquiv]; coherence
_ = (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ⊗≫ f := by
rw [whisker_exchange]; coherence
_ = _ := by rw [coevaluation_evaluation'']; coherence
#align category_theory.tensor_left_hom_equiv_symm_coevaluation_comp_id_tensor CategoryTheory.tensorLeftHomEquiv_symm_coevaluation_comp_whiskerLeft
@[simp]
theorem tensorLeftHomEquiv_symm_coevaluation_comp_whiskerRight {X Y : C} [HasRightDual X]
[HasRightDual Y] (f : X ⟶ Y) :
(tensorLeftHomEquiv _ _ _ _).symm (η_ _ _ ≫ f ▷ (Xᘁ)) = (ρ_ _).hom ≫ fᘁ := by
dsimp [tensorLeftHomEquiv, rightAdjointMate]
simp
#align category_theory.tensor_left_hom_equiv_symm_coevaluation_comp_tensor_id CategoryTheory.tensorLeftHomEquiv_symm_coevaluation_comp_whiskerRight
@[simp]
theorem tensorRightHomEquiv_symm_coevaluation_comp_whiskerLeft {X Y : C} [HasLeftDual X]
[HasLeftDual Y] (f : X ⟶ Y) :
(tensorRightHomEquiv _ (ᘁY) _ _).symm (η_ (ᘁX) X ≫ (ᘁX) ◁ f) = (λ_ _).hom ≫ ᘁf := by
dsimp [tensorRightHomEquiv, leftAdjointMate]
simp
#align category_theory.tensor_right_hom_equiv_symm_coevaluation_comp_id_tensor CategoryTheory.tensorRightHomEquiv_symm_coevaluation_comp_whiskerLeft
@[simp]
theorem tensorRightHomEquiv_symm_coevaluation_comp_whiskerRight {Y Y' Z : C} [ExactPairing Y Y']
(f : Y ⟶ Z) : (tensorRightHomEquiv _ Y _ _).symm (η_ Y Y' ≫ f ▷ Y') = (λ_ _).hom ≫ f :=
calc
_ = η_ Y Y' ▷ Y ⊗≫ (f ▷ (Y' ⊗ Y) ≫ Z ◁ ε_ Y Y') ⊗≫ 𝟙 _ := by
dsimp [tensorRightHomEquiv]; coherence
_ = (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ⊗≫ f := by
rw [← whisker_exchange]; coherence
_ = _ := by
rw [evaluation_coevaluation'']; coherence
#align category_theory.tensor_right_hom_equiv_symm_coevaluation_comp_tensor_id CategoryTheory.tensorRightHomEquiv_symm_coevaluation_comp_whiskerRight
@[simp]
theorem tensorLeftHomEquiv_whiskerLeft_comp_evaluation {Y Z : C} [HasLeftDual Z] (f : Y ⟶ ᘁZ) :
(tensorLeftHomEquiv _ _ _ _) (Z ◁ f ≫ ε_ _ _) = f ≫ (ρ_ _).inv :=
calc
_ = 𝟙 _ ⊗≫ (η_ (ᘁZ) Z ▷ Y ≫ ((ᘁZ) ⊗ Z) ◁ f) ⊗≫ (ᘁZ) ◁ ε_ (ᘁZ) Z := by
dsimp [tensorLeftHomEquiv]; coherence
_ = f ⊗≫ (η_ (ᘁZ) Z ▷ (ᘁZ) ⊗≫ (ᘁZ) ◁ ε_ (ᘁZ) Z) := by
rw [← whisker_exchange]; coherence
_ = _ := by
rw [evaluation_coevaluation'']; coherence
#align category_theory.tensor_left_hom_equiv_id_tensor_comp_evaluation CategoryTheory.tensorLeftHomEquiv_whiskerLeft_comp_evaluation
@[simp]
theorem tensorLeftHomEquiv_whiskerRight_comp_evaluation {X Y : C} [HasLeftDual X] [HasLeftDual Y]
(f : X ⟶ Y) : (tensorLeftHomEquiv _ _ _ _) (f ▷ _ ≫ ε_ _ _) = (ᘁf) ≫ (ρ_ _).inv := by
dsimp [tensorLeftHomEquiv, leftAdjointMate]
simp
#align category_theory.tensor_left_hom_equiv_tensor_id_comp_evaluation CategoryTheory.tensorLeftHomEquiv_whiskerRight_comp_evaluation
@[simp]
theorem tensorRightHomEquiv_whiskerLeft_comp_evaluation {X Y : C} [HasRightDual X] [HasRightDual Y]
(f : X ⟶ Y) : (tensorRightHomEquiv _ _ _ _) ((Yᘁ) ◁ f ≫ ε_ _ _) = fᘁ ≫ (λ_ _).inv := by
dsimp [tensorRightHomEquiv, rightAdjointMate]
simp
#align category_theory.tensor_right_hom_equiv_id_tensor_comp_evaluation CategoryTheory.tensorRightHomEquiv_whiskerLeft_comp_evaluation
@[simp]
theorem tensorRightHomEquiv_whiskerRight_comp_evaluation {X Y : C} [HasRightDual X] (f : Y ⟶ Xᘁ) :
(tensorRightHomEquiv _ _ _ _) (f ▷ X ≫ ε_ X (Xᘁ)) = f ≫ (λ_ _).inv :=
calc
_ = 𝟙 _ ⊗≫ (Y ◁ η_ X Xᘁ ≫ f ▷ (X ⊗ Xᘁ)) ⊗≫ ε_ X Xᘁ ▷ Xᘁ := by
dsimp [tensorRightHomEquiv]; coherence
_ = f ⊗≫ (Xᘁ ◁ η_ X Xᘁ ⊗≫ ε_ X Xᘁ ▷ Xᘁ) := by
rw [whisker_exchange]; coherence
_ = _ := by
rw [coevaluation_evaluation'']; coherence
#align category_theory.tensor_right_hom_equiv_tensor_id_comp_evaluation CategoryTheory.tensorRightHomEquiv_whiskerRight_comp_evaluation
-- Next four lemmas passing `fᘁ` or `ᘁf` through (co)evaluations.
@[reassoc]
theorem coevaluation_comp_rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) :
η_ Y (Yᘁ) ≫ _ ◁ (fᘁ) = η_ _ _ ≫ f ▷ _ := by
apply_fun (tensorLeftHomEquiv _ Y (Yᘁ) _).symm
simp
#align category_theory.coevaluation_comp_right_adjoint_mate CategoryTheory.coevaluation_comp_rightAdjointMate
@[reassoc]
theorem leftAdjointMate_comp_evaluation {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) :
X ◁ (ᘁf) ≫ ε_ _ _ = f ▷ _ ≫ ε_ _ _ := by
apply_fun tensorLeftHomEquiv _ (ᘁX) X _
simp
#align category_theory.left_adjoint_mate_comp_evaluation CategoryTheory.leftAdjointMate_comp_evaluation
@[reassoc]
theorem coevaluation_comp_leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) :
η_ (ᘁY) Y ≫ (ᘁf) ▷ Y = η_ (ᘁX) X ≫ (ᘁX) ◁ f := by
apply_fun (tensorRightHomEquiv _ (ᘁY) Y _).symm
simp
#align category_theory.coevaluation_comp_left_adjoint_mate CategoryTheory.coevaluation_comp_leftAdjointMate
@[reassoc]
| Mathlib/CategoryTheory/Monoidal/Rigid/Basic.lean | 510 | 513 | theorem rightAdjointMate_comp_evaluation {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) :
(fᘁ ▷ X) ≫ ε_ X (Xᘁ) = ((Yᘁ) ◁ f) ≫ ε_ Y (Yᘁ) := by |
apply_fun tensorRightHomEquiv _ X (Xᘁ) _
simp
|
/-
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, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland, Aaron Anderson
-/
import Mathlib.Algebra.Divisibility.Basic
import Mathlib.Algebra.Group.Units
#align_import algebra.divisibility.units from "leanprover-community/mathlib"@"e574b1a4e891376b0ef974b926da39e05da12a06"
/-!
# Divisibility and units
## Main definition
* `IsRelPrime x y`: that `x` and `y` are relatively prime, defined to mean that the only common
divisors of `x` and `y` are the units.
-/
variable {α : Type*}
namespace Units
section Monoid
variable [Monoid α] {a b : α} {u : αˣ}
/-- Elements of the unit group of a monoid represented as elements of the monoid
divide any element of the monoid. -/
theorem coe_dvd : ↑u ∣ a :=
⟨↑u⁻¹ * a, by simp⟩
#align units.coe_dvd Units.coe_dvd
/-- In a monoid, an element `a` divides an element `b` iff `a` divides all
associates of `b`. -/
theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b :=
Iff.intro (fun ⟨c, Eq⟩ ↦ ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← Eq, Units.mul_inv_cancel_right]⟩)
fun ⟨c, Eq⟩ ↦ Eq.symm ▸ (_root_.dvd_mul_right _ _).mul_right _
#align units.dvd_mul_right Units.dvd_mul_right
/-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/
theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b :=
Iff.intro (fun ⟨c, Eq⟩ => ⟨↑u * c, Eq.trans (mul_assoc _ _ _)⟩) fun h =>
dvd_trans (Dvd.intro (↑u⁻¹) (by rw [mul_assoc, u.mul_inv, mul_one])) h
#align units.mul_right_dvd Units.mul_right_dvd
end Monoid
section CommMonoid
variable [CommMonoid α] {a b : α} {u : αˣ}
/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left
associates of `b`. -/
theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by
rw [mul_comm]
apply dvd_mul_right
#align units.dvd_mul_left Units.dvd_mul_left
/-- In a commutative monoid, an element `a` divides an element `b` iff all
left associates of `a` divide `b`. -/
theorem mul_left_dvd : ↑u * a ∣ b ↔ a ∣ b := by
rw [mul_comm]
apply mul_right_dvd
#align units.mul_left_dvd Units.mul_left_dvd
end CommMonoid
end Units
namespace IsUnit
section Monoid
variable [Monoid α] {a b u : α} (hu : IsUnit u)
/-- Units of a monoid divide any element of the monoid. -/
@[simp]
theorem dvd : u ∣ a := by
rcases hu with ⟨u, rfl⟩
apply Units.coe_dvd
#align is_unit.dvd IsUnit.dvd
@[simp]
theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := by
rcases hu with ⟨u, rfl⟩
apply Units.dvd_mul_right
#align is_unit.dvd_mul_right IsUnit.dvd_mul_right
/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`. -/
@[simp]
| Mathlib/Algebra/Divisibility/Units.lean | 94 | 96 | theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := by |
rcases hu with ⟨u, rfl⟩
apply Units.mul_right_dvd
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.SetToL1
#align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
/-!
# Bochner integral
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined through the extension process described in the file `SetToL1`,
which follows these steps:
1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`.
`weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive`
(defined in the file `SetToL1`) with respect to the set `s`.
2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`)
where `E` is a real normed space. (See `SimpleFunc.integral` for details.)
3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation :
`α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear
map from `α →₁ₛ[μ] E` to `E`.
4. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of
`α →₁ₛ[μ] E` into `α →₁[μ] E` is dense.
5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1
space, if it is in L1, and 0 otherwise.
The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to
`setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral
(like linearity) are particular cases of the properties of `setToFun` (which are described in the
file `SetToL1`).
## Main statements
1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure
space and `E` is a real normed space.
* `integral_zero` : `∫ 0 ∂μ = 0`
* `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ`
* `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ`
* `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ`
* `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ`
* `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ`
* `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ`
2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure
space.
* `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
* `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions,
which is called `lintegral` and has the notation `∫⁻`.
* `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` :
`∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`,
where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ`
4. (In the file `DominatedConvergence`)
`tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
5. (In the file `SetIntegral`) integration commutes with continuous linear maps.
* `ContinuousLinearMap.integral_comp_comm`
* `LinearIsometry.integral_comp_comm`
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one
of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove
something for an arbitrary integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves
that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued
function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part`
is scattered in sections with the name `posPart`.
Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all
functions :
1. First go to the `L¹` space.
For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of
`f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`.
3. Show that the property holds for all simple functions `s` in `L¹` space.
Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas
like `L1.integral_coe_eq_integral`.
4. Since simple functions are dense in `L¹`,
```
univ = closure {s simple}
= closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions
⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}
= {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself
```
Use `isClosed_property` or `DenseRange.induction_on` for this argument.
## Notations
* `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`)
* `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`MeasureTheory/LpSpace`)
* `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple
functions (defined in `MeasureTheory/SimpleFuncDense`)
* `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ`
* `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type
We also define notations for integral on a set, which are described in the file
`MeasureTheory/SetIntegral`.
Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
assert_not_exists Differentiable
noncomputable section
open scoped Topology NNReal ENNReal MeasureTheory
open Set Filter TopologicalSpace ENNReal EMetric
namespace MeasureTheory
variable {α E F 𝕜 : Type*}
section WeightedSMul
open ContinuousLinearMap
variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α}
/-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension
of that set function through `setToL1` gives the Bochner integral of L1 functions. -/
def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F :=
(μ s).toReal • ContinuousLinearMap.id ℝ F
#align measure_theory.weighted_smul MeasureTheory.weightedSMul
theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) :
weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul]
#align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply
@[simp]
theorem weightedSMul_zero_measure {m : MeasurableSpace α} :
weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul]
#align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure
@[simp]
theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) :
weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp
#align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty
theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α}
(hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) :
(weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by
ext1 x
push_cast
simp_rw [Pi.add_apply, weightedSMul_apply]
push_cast
rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul]
#align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure
theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} :
(weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by
ext1 x
push_cast
simp_rw [Pi.smul_apply, weightedSMul_apply]
push_cast
simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul]
#align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure
theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) :
(weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by
ext1 x; simp_rw [weightedSMul_apply]; congr 2
#align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr
theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by
ext1 x; rw [weightedSMul_apply, h_zero]; simp
#align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null
theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞)
(ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by
ext1 x
simp_rw [add_apply, weightedSMul_apply,
measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht,
ENNReal.toReal_add hs_finite ht_finite, add_smul]
#align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union'
@[nolint unusedArguments]
theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t :=
weightedSMul_union' s t ht hs_finite ht_finite h_inter
#align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union
theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜)
(s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by
simp_rw [weightedSMul_apply, smul_comm]
#align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul
theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal :=
calc
‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ :=
norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F)
_ ≤ ‖(μ s).toReal‖ :=
((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le)
_ = abs (μ s).toReal := Real.norm_eq_abs _
_ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg
#align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le
theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) :
DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 :=
⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩
#align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul
theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by
simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply]
exact mul_nonneg toReal_nonneg hx
#align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg
end WeightedSMul
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
section PosPart
variable [LinearOrder E] [Zero E] [MeasurableSpace α]
/-- Positive part of a simple function. -/
def posPart (f : α →ₛ E) : α →ₛ E :=
f.map fun b => max b 0
#align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart
/-- Negative part of a simple function. -/
def negPart [Neg E] (f : α →ₛ E) : α →ₛ E :=
posPart (-f)
#align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart
theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by
ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _
#align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm
theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by
rw [negPart]; exact posPart_map_norm _
#align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm
theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by
simp only [posPart, negPart]
ext a
rw [coe_sub]
exact max_zero_sub_eq_self (f a)
#align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart
end PosPart
section Integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group,
and prove basic property of this integral.
-/
open Finset
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*}
[NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α}
{μ : Measure α}
/-- Bochner integral of simple functions whose codomain is a real `NormedSpace`.
This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/
def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F :=
f.setToSimpleFunc (weightedSMul μ)
#align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral
theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl
#align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def
theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by
simp [integral, setToSimpleFunc, weightedSMul_apply]
#align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq
theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α}
(f : α →ₛ F) (μ : Measure α) :
f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by
rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr
#align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter
/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/
theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F}
(hs : (f.range.filter fun x => x ≠ 0) ⊆ s) :
f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by
rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs]
rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx
-- Porting note: reordered for clarity
rcases hx.symm with (rfl | hx)
· simp
rw [SimpleFunc.mem_range] at hx
-- Porting note: added
simp only [Set.mem_range, not_exists] at hx
rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx]
#align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset
@[simp]
theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) :
(const α y).integral μ = (μ univ).toReal • y := by
classical
calc
(const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z :=
integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _)
_ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage`
#align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const
@[simp]
theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α}
(hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by
classical
refine (integral_eq_sum_of_subset ?_).trans
((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm)
· intro y hy
simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,
mem_range_indicator] at *
rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩
exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩]
· dsimp
rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem,
Measure.restrict_apply (f.measurableSet_preimage _)]
exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀)
#align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero
/-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/
theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) :
(f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x :=
map_setToSimpleFunc _ weightedSMul_union hf hg
#align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral
/-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0)
(ht : ∀ b, g b ≠ ∞) :
(f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by
have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf
simp only [← map_apply g f, lintegral_eq_lintegral]
rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum]
· refine Finset.sum_congr rfl fun b _ => ?_
-- Porting note: added `Function.comp_apply`
rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply]
· rintro a -
by_cases a0 : a = 0
· rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top
· apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne
· simp [hg0]
#align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral'
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E]
theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) :
f.integral μ = g.integral μ :=
setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h
#align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr
/-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/
theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) :
f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by
have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) :=
h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm
rw [← integral_eq_lintegral' hf]
exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top]
#align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral
theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f + g) = integral μ f + integral μ g :=
setToSimpleFunc_add _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add
theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f :=
setToSimpleFunc_neg _ weightedSMul_union hf
#align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg
theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f - g) = integral μ f - integral μ g :=
setToSimpleFunc_sub _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub
theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) :
integral μ (c • f) = c • integral μ f :=
setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf
#align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul
theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E}
(hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ :=
calc
‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ :=
norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf
_ = C * (f.map norm).integral μ := by
rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul]
#align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm
theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) :
‖f.integral μ‖ ≤ (f.map norm).integral μ := by
refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le
exact (norm_weightedSMul_le s).trans (one_mul _).symm.le
#align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm
theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) :
f.integral (μ + ν) = f.integral μ + f.integral ν := by
simp_rw [integral_def]
refine setToSimpleFunc_add_left'
(weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf
rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs
rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2]
#align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure
end Integral
end SimpleFunc
namespace L1
set_option linter.uppercaseLean3 false -- `L1`
open AEEqFun Lp.simpleFunc Lp
variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α}
namespace SimpleFunc
theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by
rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero]
simp_rw [smul_eq_mul]
#align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral
section PosPart
/-- Positive part of a simple function in L1 space. -/
nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
⟨Lp.posPart (f : α →₁[μ] ℝ), by
rcases f with ⟨f, s, hsf⟩
use s.posPart
simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk,
SimpleFunc.coe_map, mk_eq_mk]
-- Porting note: added
simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩
#align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart
/-- Negative part of a simple function in L1 space. -/
def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
posPart (-f)
#align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart
@[norm_cast]
theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart
@[norm_cast]
theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart
end PosPart
section SimpleFuncIntegral
/-!
### The Bochner integral of `L1`
Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`,
and prove basic properties of this integral. -/
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*}
[NormedAddCommGroup F'] [NormedSpace ℝ F']
attribute [local instance] simpleFunc.normedSpace
/-- The Bochner integral over simple functions in L1 space. -/
def integral (f : α →₁ₛ[μ] E) : E :=
(toSimpleFunc f).integral μ
#align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral
theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl
#align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral
nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) :
integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by
rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos]
#align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral
theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl
#align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S
nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
integral f = integral g :=
SimpleFunc.integral_congr (SimpleFunc.integrable f) h
#align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr
theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g :=
setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _
#align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add
theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f :=
setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f
#align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul
theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by
rw [integral, norm_eq_integral]
exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f)
#align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm
variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E']
variable (α E μ 𝕜)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/
def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E :=
LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f =>
le_trans (norm_integral_le_norm _) <| by rw [one_mul]
#align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM'
/-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E :=
integralCLM' α E ℝ μ
#align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM
variable {α E μ 𝕜}
local notation "Integral" => integralCLM α E μ
open ContinuousLinearMap
theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 :=
-- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _`
LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by
rw [one_mul]
exact norm_integral_le_norm f)
#align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one
section PosPart
theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by
have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl
have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by
filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ),
toSimpleFunc_eq_toFun f] with _ _ h₂ h₃
convert h₂ using 1
-- Porting note: added
rw [h₃]
refine ae_eq.mono fun a h => ?_
rw [h, eq]
#align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc
theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by
rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart]
filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f]
intro a h₁ h₂
rw [h₁]
show max _ _ = max _ _
rw [h₂]
rfl
#align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc
theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by
filter_upwards [posPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply]
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by
filter_upwards [negPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply]
rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub]
· show (toSimpleFunc f).integral μ =
((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ
apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f)
filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂
show _ = _ - _
rw [← h₁, ← h₂]
have := (toSimpleFunc f).posPart_sub_negPart
conv_lhs => rw [← this]
rfl
· exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁
· exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂
#align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub
end PosPart
end SimpleFuncIntegral
end SimpleFunc
open SimpleFunc
local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _
variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E]
[NormedSpace ℝ F] [CompleteSpace E]
section IntegrationInL1
attribute [local instance] simpleFunc.normedSpace
open ContinuousLinearMap
variable (𝕜)
/-- The Bochner integral in L1 space as a continuous linear map. -/
nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E :=
(integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.uniformInducing
#align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM'
variable {𝕜}
/-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁[μ] E) →L[ℝ] E :=
integralCLM' ℝ
#align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM
-- Porting note: added `(E := E)` in several places below.
/-- The Bochner integral in L1 space -/
irreducible_def integral (f : α →₁[μ] E) : E :=
integralCLM (E := E) f
#align measure_theory.L1.integral MeasureTheory.L1.integral
theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by
simp only [integral]
#align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq
theorem integral_eq_setToL1 (f : α →₁[μ] E) :
integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral]; rfl
#align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1
@[norm_cast]
theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) :
L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by
simp only [integral, L1.integral]
exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f
#align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral
variable (α E)
@[simp]
theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by
simp only [integral]
exact map_zero integralCLM
#align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero
variable {α E}
@[integral_simps]
theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by
simp only [integral]
exact map_add integralCLM f g
#align measure_theory.L1.integral_add MeasureTheory.L1.integral_add
@[integral_simps]
theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by
simp only [integral]
exact map_neg integralCLM f
#align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg
@[integral_simps]
theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by
simp only [integral]
exact map_sub integralCLM f g
#align measure_theory.L1.integral_sub MeasureTheory.L1.integral_sub
@[integral_simps]
theorem integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := by
simp only [integral]
show (integralCLM' (E := E) 𝕜) (c • f) = c • (integralCLM' (E := E) 𝕜) f
exact map_smul (integralCLM' (E := E) 𝕜) c f
#align measure_theory.L1.integral_smul MeasureTheory.L1.integral_smul
local notation "Integral" => @integralCLM α E _ _ μ _ _
local notation "sIntegral" => @SimpleFunc.integralCLM α E _ _ μ _
theorem norm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖ ≤ 1 :=
norm_setToL1_le (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one
#align measure_theory.L1.norm_Integral_le_one MeasureTheory.L1.norm_Integral_le_one
theorem nnnorm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖₊ ≤ 1 :=
norm_Integral_le_one
theorem norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ :=
calc
‖integral f‖ = ‖integralCLM (E := E) f‖ := by simp only [integral]
_ ≤ ‖integralCLM (α := α) (E := E) (μ := μ)‖ * ‖f‖ := le_opNorm _ _
_ ≤ 1 * ‖f‖ := mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _
_ = ‖f‖ := one_mul _
#align measure_theory.L1.norm_integral_le MeasureTheory.L1.norm_integral_le
theorem nnnorm_integral_le (f : α →₁[μ] E) : ‖integral f‖₊ ≤ ‖f‖₊ :=
norm_integral_le f
@[continuity]
theorem continuous_integral : Continuous fun f : α →₁[μ] E => integral f := by
simp only [integral]
exact L1.integralCLM.continuous
#align measure_theory.L1.continuous_integral MeasureTheory.L1.continuous_integral
section PosPart
theorem integral_eq_norm_posPart_sub (f : α →₁[μ] ℝ) :
integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖ := by
-- Use `isClosed_property` and `isClosed_eq`
refine @isClosed_property _ _ _ ((↑) : (α →₁ₛ[μ] ℝ) → α →₁[μ] ℝ)
(fun f : α →₁[μ] ℝ => integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖)
(simpleFunc.denseRange one_ne_top) (isClosed_eq ?_ ?_) ?_ f
· simp only [integral]
exact cont _
· refine Continuous.sub (continuous_norm.comp Lp.continuous_posPart)
(continuous_norm.comp Lp.continuous_negPart)
-- Show that the property holds for all simple functions in the `L¹` space.
· intro s
norm_cast
exact SimpleFunc.integral_eq_norm_posPart_sub _
#align measure_theory.L1.integral_eq_norm_pos_part_sub MeasureTheory.L1.integral_eq_norm_posPart_sub
end PosPart
end IntegrationInL1
end L1
/-!
## The Bochner integral on functions
Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable
functions, and 0 otherwise; prove its basic properties.
-/
variable [NormedAddCommGroup E] [NormedSpace ℝ E] [hE : CompleteSpace E] [NontriviallyNormedField 𝕜]
[NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F]
{G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G]
section
open scoped Classical
/-- The Bochner integral -/
irreducible_def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α → G) : G :=
if _ : CompleteSpace G then
if hf : Integrable f μ then L1.integral (hf.toL1 f) else 0
else 0
#align measure_theory.integral MeasureTheory.integral
end
/-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly,
and needs parentheses. We do not set the binding power of `r` to `0`, because then
`∫ x, f x = 0` will be parsed incorrectly. -/
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => integral μ r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)", "r:60:(scoped f => integral volume f) => r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => integral (Measure.restrict μ s) r
@[inherit_doc MeasureTheory.integral]
notation3 "∫ "(...)" in "s", "r:60:(scoped f => integral (Measure.restrict volume s) f) => r
section Properties
open ContinuousLinearMap MeasureTheory.SimpleFunc
variable {f g : α → E} {m : MeasurableSpace α} {μ : Measure α}
theorem integral_eq (f : α → E) (hf : Integrable f μ) : ∫ a, f a ∂μ = L1.integral (hf.toL1 f) := by
simp [integral, hE, hf]
#align measure_theory.integral_eq MeasureTheory.integral_eq
theorem integral_eq_setToFun (f : α → E) :
∫ a, f a ∂μ = setToFun μ (weightedSMul μ) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral, hE, L1.integral]; rfl
#align measure_theory.integral_eq_set_to_fun MeasureTheory.integral_eq_setToFun
theorem L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ := by
simp only [integral, L1.integral, integral_eq_setToFun]
exact (L1.setToFun_eq_setToL1 (dominatedFinMeasAdditive_weightedSMul μ) f).symm
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.integral_eq_integral MeasureTheory.L1.integral_eq_integral
theorem integral_undef {f : α → G} (h : ¬Integrable f μ) : ∫ a, f a ∂μ = 0 := by
by_cases hG : CompleteSpace G
· simp [integral, hG, h]
· simp [integral, hG]
#align measure_theory.integral_undef MeasureTheory.integral_undef
theorem Integrable.of_integral_ne_zero {f : α → G} (h : ∫ a, f a ∂μ ≠ 0) : Integrable f μ :=
Not.imp_symm integral_undef h
theorem integral_non_aestronglyMeasurable {f : α → G} (h : ¬AEStronglyMeasurable f μ) :
∫ a, f a ∂μ = 0 :=
integral_undef <| not_and_of_not_left _ h
#align measure_theory.integral_non_ae_strongly_measurable MeasureTheory.integral_non_aestronglyMeasurable
variable (α G)
@[simp]
theorem integral_zero : ∫ _ : α, (0 : G) ∂μ = 0 := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_zero (dominatedFinMeasAdditive_weightedSMul μ)
· simp [integral, hG]
#align measure_theory.integral_zero MeasureTheory.integral_zero
@[simp]
theorem integral_zero' : integral μ (0 : α → G) = 0 :=
integral_zero α G
#align measure_theory.integral_zero' MeasureTheory.integral_zero'
variable {α G}
theorem integrable_of_integral_eq_one {f : α → ℝ} (h : ∫ x, f x ∂μ = 1) : Integrable f μ :=
.of_integral_ne_zero <| h ▸ one_ne_zero
#align measure_theory.integrable_of_integral_eq_one MeasureTheory.integrable_of_integral_eq_one
theorem integral_add {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_add (dominatedFinMeasAdditive_weightedSMul μ) hf hg
· simp [integral, hG]
#align measure_theory.integral_add MeasureTheory.integral_add
theorem integral_add' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
integral_add hf hg
#align measure_theory.integral_add' MeasureTheory.integral_add'
theorem integral_finset_sum {ι} (s : Finset ι) {f : ι → α → G} (hf : ∀ i ∈ s, Integrable (f i) μ) :
∫ a, ∑ i ∈ s, f i a ∂μ = ∑ i ∈ s, ∫ a, f i a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_finset_sum (dominatedFinMeasAdditive_weightedSMul _) s hf
· simp [integral, hG]
#align measure_theory.integral_finset_sum MeasureTheory.integral_finset_sum
@[integral_simps]
theorem integral_neg (f : α → G) : ∫ a, -f a ∂μ = -∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_neg (dominatedFinMeasAdditive_weightedSMul μ) f
· simp [integral, hG]
#align measure_theory.integral_neg MeasureTheory.integral_neg
theorem integral_neg' (f : α → G) : ∫ a, (-f) a ∂μ = -∫ a, f a ∂μ :=
integral_neg f
#align measure_theory.integral_neg' MeasureTheory.integral_neg'
theorem integral_sub {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, f a - g a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_sub (dominatedFinMeasAdditive_weightedSMul μ) hf hg
· simp [integral, hG]
#align measure_theory.integral_sub MeasureTheory.integral_sub
theorem integral_sub' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) :
∫ a, (f - g) a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ :=
integral_sub hf hg
#align measure_theory.integral_sub' MeasureTheory.integral_sub'
@[integral_simps]
theorem integral_smul [NormedSpace 𝕜 G] [SMulCommClass ℝ 𝕜 G] (c : 𝕜) (f : α → G) :
∫ a, c • f a ∂μ = c • ∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_smul (dominatedFinMeasAdditive_weightedSMul μ) weightedSMul_smul c f
· simp [integral, hG]
#align measure_theory.integral_smul MeasureTheory.integral_smul
theorem integral_mul_left {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, r * f a ∂μ = r * ∫ a, f a ∂μ :=
integral_smul r f
#align measure_theory.integral_mul_left MeasureTheory.integral_mul_left
theorem integral_mul_right {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, f a * r ∂μ = (∫ a, f a ∂μ) * r := by
simp only [mul_comm]; exact integral_mul_left r f
#align measure_theory.integral_mul_right MeasureTheory.integral_mul_right
theorem integral_div {L : Type*} [RCLike L] (r : L) (f : α → L) :
∫ a, f a / r ∂μ = (∫ a, f a ∂μ) / r := by
simpa only [← div_eq_mul_inv] using integral_mul_right r⁻¹ f
#align measure_theory.integral_div MeasureTheory.integral_div
theorem integral_congr_ae {f g : α → G} (h : f =ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_congr_ae (dominatedFinMeasAdditive_weightedSMul μ) h
· simp [integral, hG]
#align measure_theory.integral_congr_ae MeasureTheory.integral_congr_ae
-- Porting note: `nolint simpNF` added because simplify fails on left-hand side
@[simp, nolint simpNF]
theorem L1.integral_of_fun_eq_integral {f : α → G} (hf : Integrable f μ) :
∫ a, (hf.toL1 f) a ∂μ = ∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [MeasureTheory.integral, hG, L1.integral]
exact setToFun_toL1 (dominatedFinMeasAdditive_weightedSMul μ) hf
· simp [MeasureTheory.integral, hG]
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.integral_of_fun_eq_integral MeasureTheory.L1.integral_of_fun_eq_integral
@[continuity]
theorem continuous_integral : Continuous fun f : α →₁[μ] G => ∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuous_setToFun (dominatedFinMeasAdditive_weightedSMul μ)
· simp [integral, hG, continuous_const]
#align measure_theory.continuous_integral MeasureTheory.continuous_integral
theorem norm_integral_le_lintegral_norm (f : α → G) :
‖∫ a, f a ∂μ‖ ≤ ENNReal.toReal (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) := by
by_cases hG : CompleteSpace G
· by_cases hf : Integrable f μ
· rw [integral_eq f hf, ← Integrable.norm_toL1_eq_lintegral_norm f hf]
exact L1.norm_integral_le _
· rw [integral_undef hf, norm_zero]; exact toReal_nonneg
· simp [integral, hG]
#align measure_theory.norm_integral_le_lintegral_norm MeasureTheory.norm_integral_le_lintegral_norm
theorem ennnorm_integral_le_lintegral_ennnorm (f : α → G) :
(‖∫ a, f a ∂μ‖₊ : ℝ≥0∞) ≤ ∫⁻ a, ‖f a‖₊ ∂μ := by
simp_rw [← ofReal_norm_eq_coe_nnnorm]
apply ENNReal.ofReal_le_of_le_toReal
exact norm_integral_le_lintegral_norm f
#align measure_theory.ennnorm_integral_le_lintegral_ennnorm MeasureTheory.ennnorm_integral_le_lintegral_ennnorm
theorem integral_eq_zero_of_ae {f : α → G} (hf : f =ᵐ[μ] 0) : ∫ a, f a ∂μ = 0 := by
simp [integral_congr_ae hf, integral_zero]
#align measure_theory.integral_eq_zero_of_ae MeasureTheory.integral_eq_zero_of_ae
/-- 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 HasFiniteIntegral.tendsto_setIntegral_nhds_zero {ι} {f : α → G}
(hf : HasFiniteIntegral f μ) {l : Filter ι} {s : ι → Set α} (hs : Tendsto (μ ∘ s) l (𝓝 0)) :
Tendsto (fun i => ∫ x in s i, f x ∂μ) l (𝓝 0) := by
rw [tendsto_zero_iff_norm_tendsto_zero]
simp_rw [← coe_nnnorm, ← NNReal.coe_zero, NNReal.tendsto_coe, ← ENNReal.tendsto_coe,
ENNReal.coe_zero]
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
(tendsto_set_lintegral_zero (ne_of_lt hf) hs) (fun i => zero_le _)
fun i => ennnorm_integral_le_lintegral_ennnorm _
#align measure_theory.has_finite_integral.tendsto_set_integral_nhds_zero MeasureTheory.HasFiniteIntegral.tendsto_setIntegral_nhds_zero
@[deprecated (since := "2024-04-17")]
alias HasFiniteIntegral.tendsto_set_integral_nhds_zero :=
HasFiniteIntegral.tendsto_setIntegral_nhds_zero
/-- If `f` is integrable, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
theorem Integrable.tendsto_setIntegral_nhds_zero {ι} {f : α → G} (hf : Integrable f μ)
{l : Filter ι} {s : ι → Set α} (hs : Tendsto (μ ∘ s) l (𝓝 0)) :
Tendsto (fun i => ∫ x in s i, f x ∂μ) l (𝓝 0) :=
hf.2.tendsto_setIntegral_nhds_zero hs
#align measure_theory.integrable.tendsto_set_integral_nhds_zero MeasureTheory.Integrable.tendsto_setIntegral_nhds_zero
@[deprecated (since := "2024-04-17")]
alias Integrable.tendsto_set_integral_nhds_zero :=
Integrable.tendsto_setIntegral_nhds_zero
/-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/
theorem tendsto_integral_of_L1 {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ)
(hF : Tendsto (fun i => ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0)) :
Tendsto (fun i => ∫ x, F i x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact tendsto_setToFun_of_L1 (dominatedFinMeasAdditive_weightedSMul μ) f hfi hFi hF
· simp [integral, hG, tendsto_const_nhds]
set_option linter.uppercaseLean3 false in
#align measure_theory.tendsto_integral_of_L1 MeasureTheory.tendsto_integral_of_L1
/-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/
lemma tendsto_integral_of_L1' {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ snorm (F i - f) 1 μ) l (𝓝 0)) :
Tendsto (fun i ↦ ∫ x, F i x ∂μ) l (𝓝 (∫ x, f x ∂μ)) := by
refine tendsto_integral_of_L1 f hfi hFi ?_
simp_rw [snorm_one_eq_lintegral_nnnorm, Pi.sub_apply] at hF
exact hF
/-- If `F i → f` in `L1`, then `∫ x in s, F i x ∂μ → ∫ x in s, f x ∂μ`. -/
lemma tendsto_setIntegral_of_L1 {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G}
{l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0))
(s : Set α) :
Tendsto (fun i ↦ ∫ x in s, F i x ∂μ) l (𝓝 (∫ x in s, f x ∂μ)) := by
refine tendsto_integral_of_L1 f hfi.restrict ?_ ?_
· filter_upwards [hFi] with i hi using hi.restrict
· simp_rw [← snorm_one_eq_lintegral_nnnorm] at hF ⊢
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hF (fun _ ↦ zero_le')
(fun _ ↦ snorm_mono_measure _ Measure.restrict_le_self)
@[deprecated (since := "2024-04-17")]
alias tendsto_set_integral_of_L1 := tendsto_setIntegral_of_L1
/-- If `F i → f` in `L1`, then `∫ x in s, F i x ∂μ → ∫ x in s, f x ∂μ`. -/
lemma tendsto_setIntegral_of_L1' {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G}
{l : Filter ι}
(hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ snorm (F i - f) 1 μ) l (𝓝 0))
(s : Set α) :
Tendsto (fun i ↦ ∫ x in s, F i x ∂μ) l (𝓝 (∫ x in s, f x ∂μ)) := by
refine tendsto_setIntegral_of_L1 f hfi hFi ?_ s
simp_rw [snorm_one_eq_lintegral_nnnorm, Pi.sub_apply] at hF
exact hF
@[deprecated (since := "2024-04-17")]
alias tendsto_set_integral_of_L1' := tendsto_setIntegral_of_L1'
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
theorem continuousWithinAt_of_dominated {F : X → α → G} {x₀ : X} {bound : α → ℝ} {s : Set X}
(hF_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (F x) μ)
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousWithinAt (fun x => F x a) s x₀) :
ContinuousWithinAt (fun x => ∫ a, F x a ∂μ) s x₀ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuousWithinAt_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuousWithinAt_const]
#align measure_theory.continuous_within_at_of_dominated MeasureTheory.continuousWithinAt_of_dominated
theorem continuousAt_of_dominated {F : X → α → G} {x₀ : X} {bound : α → ℝ}
(hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousAt (fun x => F x a) x₀) :
ContinuousAt (fun x => ∫ a, F x a ∂μ) x₀ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuousAt_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuousAt_const]
#align measure_theory.continuous_at_of_dominated MeasureTheory.continuousAt_of_dominated
theorem continuousOn_of_dominated {F : X → α → G} {bound : α → ℝ} {s : Set X}
(hF_meas : ∀ x ∈ s, AEStronglyMeasurable (F x) μ)
(h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousOn (fun x => F x a) s) :
ContinuousOn (fun x => ∫ a, F x a ∂μ) s := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuousOn_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuousOn_const]
#align measure_theory.continuous_on_of_dominated MeasureTheory.continuousOn_of_dominated
theorem continuous_of_dominated {F : X → α → G} {bound : α → ℝ}
(hF_meas : ∀ x, AEStronglyMeasurable (F x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a)
(bound_integrable : Integrable bound μ) (h_cont : ∀ᵐ a ∂μ, Continuous fun x => F x a) :
Continuous fun x => ∫ a, F x a ∂μ := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact continuous_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ)
hF_meas h_bound bound_integrable h_cont
· simp [integral, hG, continuous_const]
#align measure_theory.continuous_of_dominated MeasureTheory.continuous_of_dominated
/-- The Bochner integral of a real-valued function `f : α → ℝ` is the difference between the
integral of the positive part of `f` and the integral of the negative part of `f`. -/
theorem integral_eq_lintegral_pos_part_sub_lintegral_neg_part {f : α → ℝ} (hf : Integrable f μ) :
∫ a, f a ∂μ =
ENNReal.toReal (∫⁻ a, .ofReal (f a) ∂μ) - ENNReal.toReal (∫⁻ a, .ofReal (-f a) ∂μ) := by
let f₁ := hf.toL1 f
-- Go to the `L¹` space
have eq₁ : ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) = ‖Lp.posPart f₁‖ := by
rw [L1.norm_def]
congr 1
apply lintegral_congr_ae
filter_upwards [Lp.coeFn_posPart f₁, hf.coeFn_toL1] with _ h₁ h₂
rw [h₁, h₂, ENNReal.ofReal]
congr 1
apply NNReal.eq
rw [Real.nnnorm_of_nonneg (le_max_right _ _)]
rw [Real.coe_toNNReal', NNReal.coe_mk]
-- Go to the `L¹` space
have eq₂ : ENNReal.toReal (∫⁻ a, ENNReal.ofReal (-f a) ∂μ) = ‖Lp.negPart f₁‖ := by
rw [L1.norm_def]
congr 1
apply lintegral_congr_ae
filter_upwards [Lp.coeFn_negPart f₁, hf.coeFn_toL1] with _ h₁ h₂
rw [h₁, h₂, ENNReal.ofReal]
congr 1
apply NNReal.eq
simp only [Real.coe_toNNReal', coe_nnnorm, nnnorm_neg]
rw [Real.norm_of_nonpos (min_le_right _ _), ← max_neg_neg, neg_zero]
rw [eq₁, eq₂, integral, dif_pos, dif_pos]
exact L1.integral_eq_norm_posPart_sub _
#align measure_theory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part MeasureTheory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part
theorem integral_eq_lintegral_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f)
(hfm : AEStronglyMeasurable f μ) :
∫ a, f a ∂μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by
by_cases hfi : Integrable f μ
· rw [integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi]
have h_min : ∫⁻ a, ENNReal.ofReal (-f a) ∂μ = 0 := by
rw [lintegral_eq_zero_iff']
· refine hf.mono ?_
simp only [Pi.zero_apply]
intro a h
simp only [h, neg_nonpos, ofReal_eq_zero]
· exact measurable_ofReal.comp_aemeasurable hfm.aemeasurable.neg
rw [h_min, zero_toReal, _root_.sub_zero]
· rw [integral_undef hfi]
simp_rw [Integrable, hfm, hasFiniteIntegral_iff_norm, lt_top_iff_ne_top, Ne, true_and_iff,
Classical.not_not] at hfi
have : ∫⁻ a : α, ENNReal.ofReal (f a) ∂μ = ∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ := by
refine lintegral_congr_ae (hf.mono fun a h => ?_)
dsimp only
rw [Real.norm_eq_abs, abs_of_nonneg h]
rw [this, hfi]; rfl
#align measure_theory.integral_eq_lintegral_of_nonneg_ae MeasureTheory.integral_eq_lintegral_of_nonneg_ae
theorem integral_norm_eq_lintegral_nnnorm {P : Type*} [NormedAddCommGroup P] {f : α → P}
(hf : AEStronglyMeasurable f μ) : ∫ x, ‖f x‖ ∂μ = ENNReal.toReal (∫⁻ x, ‖f x‖₊ ∂μ) := by
rw [integral_eq_lintegral_of_nonneg_ae _ hf.norm]
· simp_rw [ofReal_norm_eq_coe_nnnorm]
· filter_upwards; simp_rw [Pi.zero_apply, norm_nonneg, imp_true_iff]
#align measure_theory.integral_norm_eq_lintegral_nnnorm MeasureTheory.integral_norm_eq_lintegral_nnnorm
theorem ofReal_integral_norm_eq_lintegral_nnnorm {P : Type*} [NormedAddCommGroup P] {f : α → P}
(hf : Integrable f μ) : ENNReal.ofReal (∫ x, ‖f x‖ ∂μ) = ∫⁻ x, ‖f x‖₊ ∂μ := by
rw [integral_norm_eq_lintegral_nnnorm hf.aestronglyMeasurable,
ENNReal.ofReal_toReal (lt_top_iff_ne_top.mp hf.2)]
#align measure_theory.of_real_integral_norm_eq_lintegral_nnnorm MeasureTheory.ofReal_integral_norm_eq_lintegral_nnnorm
theorem integral_eq_integral_pos_part_sub_integral_neg_part {f : α → ℝ} (hf : Integrable f μ) :
∫ a, f a ∂μ = ∫ a, (Real.toNNReal (f a) : ℝ) ∂μ - ∫ a, (Real.toNNReal (-f a) : ℝ) ∂μ := by
rw [← integral_sub hf.real_toNNReal]
· simp
· exact hf.neg.real_toNNReal
#align measure_theory.integral_eq_integral_pos_part_sub_integral_neg_part MeasureTheory.integral_eq_integral_pos_part_sub_integral_neg_part
theorem integral_nonneg_of_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ a, f a ∂μ := by
have A : CompleteSpace ℝ := by infer_instance
simp only [integral_def, A, L1.integral_def, dite_true, ge_iff_le]
exact setToFun_nonneg (dominatedFinMeasAdditive_weightedSMul μ)
(fun s _ _ => weightedSMul_nonneg s) hf
#align measure_theory.integral_nonneg_of_ae MeasureTheory.integral_nonneg_of_ae
theorem lintegral_coe_eq_integral (f : α → ℝ≥0) (hfi : Integrable (fun x => (f x : ℝ)) μ) :
∫⁻ a, f a ∂μ = ENNReal.ofReal (∫ a, f a ∂μ) := by
simp_rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall fun x => (f x).coe_nonneg)
hfi.aestronglyMeasurable, ← ENNReal.coe_nnreal_eq]
rw [ENNReal.ofReal_toReal]
rw [← lt_top_iff_ne_top]
convert hfi.hasFiniteIntegral
-- Porting note: `convert` no longer unfolds `HasFiniteIntegral`
simp_rw [HasFiniteIntegral, NNReal.nnnorm_eq]
#align measure_theory.lintegral_coe_eq_integral MeasureTheory.lintegral_coe_eq_integral
theorem ofReal_integral_eq_lintegral_ofReal {f : α → ℝ} (hfi : Integrable f μ) (f_nn : 0 ≤ᵐ[μ] f) :
ENNReal.ofReal (∫ x, f x ∂μ) = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by
have : f =ᵐ[μ] (‖f ·‖) := f_nn.mono fun _x hx ↦ (abs_of_nonneg hx).symm
simp_rw [integral_congr_ae this, ofReal_integral_norm_eq_lintegral_nnnorm hfi,
← ofReal_norm_eq_coe_nnnorm]
exact lintegral_congr_ae (this.symm.fun_comp ENNReal.ofReal)
#align measure_theory.of_real_integral_eq_lintegral_of_real MeasureTheory.ofReal_integral_eq_lintegral_ofReal
theorem integral_toReal {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) (hf : ∀ᵐ x ∂μ, f x < ∞) :
∫ a, (f a).toReal ∂μ = (∫⁻ a, f a ∂μ).toReal := by
rw [integral_eq_lintegral_of_nonneg_ae _ hfm.ennreal_toReal.aestronglyMeasurable,
lintegral_congr_ae (ofReal_toReal_ae_eq hf)]
exact eventually_of_forall fun x => ENNReal.toReal_nonneg
#align measure_theory.integral_to_real MeasureTheory.integral_toReal
theorem lintegral_coe_le_coe_iff_integral_le {f : α → ℝ≥0} (hfi : Integrable (fun x => (f x : ℝ)) μ)
{b : ℝ≥0} : ∫⁻ a, f a ∂μ ≤ b ↔ ∫ a, (f a : ℝ) ∂μ ≤ b := by
rw [lintegral_coe_eq_integral f hfi, ENNReal.ofReal, ENNReal.coe_le_coe,
Real.toNNReal_le_iff_le_coe]
#align measure_theory.lintegral_coe_le_coe_iff_integral_le MeasureTheory.lintegral_coe_le_coe_iff_integral_le
theorem integral_coe_le_of_lintegral_coe_le {f : α → ℝ≥0} {b : ℝ≥0} (h : ∫⁻ a, f a ∂μ ≤ b) :
∫ a, (f a : ℝ) ∂μ ≤ b := by
by_cases hf : Integrable (fun a => (f a : ℝ)) μ
· exact (lintegral_coe_le_coe_iff_integral_le hf).1 h
· rw [integral_undef hf]; exact b.2
#align measure_theory.integral_coe_le_of_lintegral_coe_le MeasureTheory.integral_coe_le_of_lintegral_coe_le
theorem integral_nonneg {f : α → ℝ} (hf : 0 ≤ f) : 0 ≤ ∫ a, f a ∂μ :=
integral_nonneg_of_ae <| eventually_of_forall hf
#align measure_theory.integral_nonneg MeasureTheory.integral_nonneg
theorem integral_nonpos_of_ae {f : α → ℝ} (hf : f ≤ᵐ[μ] 0) : ∫ a, f a ∂μ ≤ 0 := by
have hf : 0 ≤ᵐ[μ] -f := hf.mono fun a h => by rwa [Pi.neg_apply, Pi.zero_apply, neg_nonneg]
have : 0 ≤ ∫ a, -f a ∂μ := integral_nonneg_of_ae hf
rwa [integral_neg, neg_nonneg] at this
#align measure_theory.integral_nonpos_of_ae MeasureTheory.integral_nonpos_of_ae
theorem integral_nonpos {f : α → ℝ} (hf : f ≤ 0) : ∫ a, f a ∂μ ≤ 0 :=
integral_nonpos_of_ae <| eventually_of_forall hf
#align measure_theory.integral_nonpos MeasureTheory.integral_nonpos
theorem integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : Integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 := by
simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ENNReal.toReal_eq_zero_iff,
← ENNReal.not_lt_top, ← hasFiniteIntegral_iff_ofReal hf, hfi.2, not_true_eq_false, or_false_iff]
-- Porting note: split into parts, to make `rw` and `simp` work
rw [lintegral_eq_zero_iff']
· rw [← hf.le_iff_eq, Filter.EventuallyEq, Filter.EventuallyLE]
simp only [Pi.zero_apply, ofReal_eq_zero]
· exact (ENNReal.measurable_ofReal.comp_aemeasurable hfi.1.aemeasurable)
#align measure_theory.integral_eq_zero_iff_of_nonneg_ae MeasureTheory.integral_eq_zero_iff_of_nonneg_ae
theorem integral_eq_zero_iff_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : Integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 :=
integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi
#align measure_theory.integral_eq_zero_iff_of_nonneg MeasureTheory.integral_eq_zero_iff_of_nonneg
lemma integral_eq_iff_of_ae_le {f g : α → ℝ}
(hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) :
∫ a, f a ∂μ = ∫ a, g a ∂μ ↔ f =ᵐ[μ] g := by
refine ⟨fun h_le ↦ EventuallyEq.symm ?_, fun h ↦ integral_congr_ae h⟩
rw [← sub_ae_eq_zero,
← integral_eq_zero_iff_of_nonneg_ae ((sub_nonneg_ae _ _).mpr hfg) (hg.sub hf)]
simpa [Pi.sub_apply, integral_sub hg hf, sub_eq_zero, eq_comm]
theorem integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : Integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (Function.support f) := by
simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, pos_iff_ne_zero, Ne, @eq_comm ℝ 0,
integral_eq_zero_iff_of_nonneg_ae hf hfi, Filter.EventuallyEq, ae_iff, Pi.zero_apply,
Function.support]
#align measure_theory.integral_pos_iff_support_of_nonneg_ae MeasureTheory.integral_pos_iff_support_of_nonneg_ae
theorem integral_pos_iff_support_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : Integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (Function.support f) :=
integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi
#align measure_theory.integral_pos_iff_support_of_nonneg MeasureTheory.integral_pos_iff_support_of_nonneg
lemma integral_exp_pos {μ : Measure α} {f : α → ℝ} [hμ : NeZero μ]
(hf : Integrable (fun x ↦ Real.exp (f x)) μ) :
0 < ∫ x, Real.exp (f x) ∂μ := by
rw [integral_pos_iff_support_of_nonneg (fun x ↦ (Real.exp_pos _).le) hf]
suffices (Function.support fun x ↦ Real.exp (f x)) = Set.univ by simp [this, hμ.out]
ext1 x
simp only [Function.mem_support, ne_eq, (Real.exp_pos _).ne', not_false_eq_true, Set.mem_univ]
/-- Monotone convergence theorem for real-valued functions and Bochner integrals -/
lemma integral_tendsto_of_tendsto_of_monotone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf : ∀ n, Integrable (f n) μ) (hF : Integrable F μ) (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
-- switch from the Bochner to the Lebesgue integral
let f' := fun n x ↦ f n x - f 0 x
have hf'_nonneg : ∀ᵐ x ∂μ, ∀ n, 0 ≤ f' n x := by
filter_upwards [h_mono] with a ha n
simp [f', ha (zero_le n)]
have hf'_meas : ∀ n, Integrable (f' n) μ := fun n ↦ (hf n).sub (hf 0)
suffices Tendsto (fun n ↦ ∫ x, f' n x ∂μ) atTop (𝓝 (∫ x, (F - f 0) x ∂μ)) by
simp_rw [integral_sub (hf _) (hf _), integral_sub' hF (hf 0), tendsto_sub_const_iff] at this
exact this
have hF_ge : 0 ≤ᵐ[μ] fun x ↦ (F - f 0) x := by
filter_upwards [h_tendsto, h_mono] with x hx_tendsto hx_mono
simp only [Pi.zero_apply, Pi.sub_apply, sub_nonneg]
exact ge_of_tendsto' hx_tendsto (fun n ↦ hx_mono (zero_le _))
rw [ae_all_iff] at hf'_nonneg
simp_rw [integral_eq_lintegral_of_nonneg_ae (hf'_nonneg _) (hf'_meas _).1]
rw [integral_eq_lintegral_of_nonneg_ae hF_ge (hF.1.sub (hf 0).1)]
have h_cont := ENNReal.continuousAt_toReal (x := ∫⁻ a, ENNReal.ofReal ((F - f 0) a) ∂μ) ?_
swap
· rw [← ofReal_integral_eq_lintegral_ofReal (hF.sub (hf 0)) hF_ge]
exact ENNReal.ofReal_ne_top
refine h_cont.tendsto.comp ?_
-- use the result for the Lebesgue integral
refine lintegral_tendsto_of_tendsto_of_monotone ?_ ?_ ?_
· exact fun n ↦ ((hf n).sub (hf 0)).aemeasurable.ennreal_ofReal
· filter_upwards [h_mono] with x hx n m hnm
refine ENNReal.ofReal_le_ofReal ?_
simp only [f', tsub_le_iff_right, sub_add_cancel]
exact hx hnm
· filter_upwards [h_tendsto] with x hx
refine (ENNReal.continuous_ofReal.tendsto _).comp ?_
simp only [Pi.sub_apply]
exact Tendsto.sub hx tendsto_const_nhds
/-- Monotone convergence theorem for real-valued functions and Bochner integrals -/
lemma integral_tendsto_of_tendsto_of_antitone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf : ∀ n, Integrable (f n) μ) (hF : Integrable F μ) (h_mono : ∀ᵐ x ∂μ, Antitone 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
suffices Tendsto (fun n ↦ ∫ x, -f n x ∂μ) atTop (𝓝 (∫ x, -F x ∂μ)) by
suffices Tendsto (fun n ↦ ∫ x, - -f n x ∂μ) atTop (𝓝 (∫ x, - -F x ∂μ)) by
simpa [neg_neg] using this
convert this.neg <;> rw [integral_neg]
refine integral_tendsto_of_tendsto_of_monotone (fun n ↦ (hf n).neg) hF.neg ?_ ?_
· filter_upwards [h_mono] with x hx n m hnm using neg_le_neg_iff.mpr <| hx hnm
· filter_upwards [h_tendsto] with x hx using hx.neg
/-- If a monotone sequence of functions has an upper bound and the sequence of integrals of these
functions tends to the integral of the upper bound, then the sequence of functions converges
almost everywhere to the upper bound. -/
lemma tendsto_of_integral_tendsto_of_monotone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf_int : ∀ n, Integrable (f n) μ) (hF_int : Integrable F μ)
(hf_tendsto : Tendsto (fun i ↦ ∫ a, f i a ∂μ) atTop (𝓝 (∫ a, F a ∂μ)))
(hf_mono : ∀ᵐ a ∂μ, Monotone (fun i ↦ f i a))
(hf_bound : ∀ᵐ a ∂μ, ∀ i, f i a ≤ F a) :
∀ᵐ a ∂μ, Tendsto (fun i ↦ f i a) atTop (𝓝 (F a)) := by
-- reduce to the `ℝ≥0∞` case
let f' : ℕ → α → ℝ≥0∞ := fun n a ↦ ENNReal.ofReal (f n a - f 0 a)
let F' : α → ℝ≥0∞ := fun a ↦ ENNReal.ofReal (F a - f 0 a)
have hf'_int_eq : ∀ i, ∫⁻ a, f' i a ∂μ = ENNReal.ofReal (∫ a, f i a ∂μ - ∫ a, f 0 a ∂μ) := by
intro i
unfold_let f'
rw [← ofReal_integral_eq_lintegral_ofReal, integral_sub (hf_int i) (hf_int 0)]
· exact (hf_int i).sub (hf_int 0)
· filter_upwards [hf_mono] with a h_mono
simp [h_mono (zero_le i)]
have hF'_int_eq : ∫⁻ a, F' a ∂μ = ENNReal.ofReal (∫ a, F a ∂μ - ∫ a, f 0 a ∂μ) := by
unfold_let F'
rw [← ofReal_integral_eq_lintegral_ofReal, integral_sub hF_int (hf_int 0)]
· exact hF_int.sub (hf_int 0)
· filter_upwards [hf_bound] with a h_bound
simp [h_bound 0]
have h_tendsto : Tendsto (fun i ↦ ∫⁻ a, f' i a ∂μ) atTop (𝓝 (∫⁻ a, F' a ∂μ)) := by
simp_rw [hf'_int_eq, hF'_int_eq]
refine (ENNReal.continuous_ofReal.tendsto _).comp ?_
rwa [tendsto_sub_const_iff]
have h_mono : ∀ᵐ a ∂μ, Monotone (fun i ↦ f' i a) := by
filter_upwards [hf_mono] with a ha_mono i j hij
refine ENNReal.ofReal_le_ofReal ?_
simp [ha_mono hij]
have h_bound : ∀ᵐ a ∂μ, ∀ i, f' i a ≤ F' a := by
filter_upwards [hf_bound] with a ha_bound i
refine ENNReal.ofReal_le_ofReal ?_
simp only [tsub_le_iff_right, sub_add_cancel, ha_bound i]
-- use the corresponding lemma for `ℝ≥0∞`
have h := tendsto_of_lintegral_tendsto_of_monotone ?_ h_tendsto h_mono h_bound ?_
rotate_left
· exact (hF_int.1.aemeasurable.sub (hf_int 0).1.aemeasurable).ennreal_ofReal
· exact ((lintegral_ofReal_le_lintegral_nnnorm _).trans_lt (hF_int.sub (hf_int 0)).2).ne
filter_upwards [h, hf_mono, hf_bound] with a ha ha_mono ha_bound
have h1 : (fun i ↦ f i a) = fun i ↦ (f' i a).toReal + f 0 a := by
unfold_let f'
ext i
rw [ENNReal.toReal_ofReal]
· abel
· simp [ha_mono (zero_le i)]
have h2 : F a = (F' a).toReal + f 0 a := by
unfold_let F'
rw [ENNReal.toReal_ofReal]
· abel
· simp [ha_bound 0]
rw [h1, h2]
refine Filter.Tendsto.add ?_ tendsto_const_nhds
exact (ENNReal.continuousAt_toReal ENNReal.ofReal_ne_top).tendsto.comp ha
/-- If an antitone sequence of functions has a lower bound and the sequence of integrals of these
functions tends to the integral of the lower bound, then the sequence of functions converges
almost everywhere to the lower bound. -/
lemma tendsto_of_integral_tendsto_of_antitone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ}
(hf_int : ∀ n, Integrable (f n) μ) (hF_int : Integrable F μ)
(hf_tendsto : Tendsto (fun i ↦ ∫ a, f i a ∂μ) atTop (𝓝 (∫ a, F a ∂μ)))
(hf_mono : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a))
(hf_bound : ∀ᵐ a ∂μ, ∀ i, F a ≤ f i a) :
∀ᵐ a ∂μ, Tendsto (fun i ↦ f i a) atTop (𝓝 (F a)) := by
let f' : ℕ → α → ℝ := fun i a ↦ - f i a
let F' : α → ℝ := fun a ↦ - F a
suffices ∀ᵐ a ∂μ, Tendsto (fun i ↦ f' i a) atTop (𝓝 (F' a)) by
filter_upwards [this] with a ha_tendsto
convert ha_tendsto.neg
· simp [f']
· simp [F']
refine tendsto_of_integral_tendsto_of_monotone (fun n ↦ (hf_int n).neg) hF_int.neg ?_ ?_ ?_
· convert hf_tendsto.neg
· rw [integral_neg]
· rw [integral_neg]
· filter_upwards [hf_mono] with a ha i j hij
simp [f', ha hij]
· filter_upwards [hf_bound] with a ha i
simp [f', F', ha i]
section NormedAddCommGroup
variable {H : Type*} [NormedAddCommGroup H]
theorem L1.norm_eq_integral_norm (f : α →₁[μ] H) : ‖f‖ = ∫ a, ‖f a‖ ∂μ := by
simp only [snorm, snorm', ENNReal.one_toReal, ENNReal.rpow_one, Lp.norm_def, if_false,
ENNReal.one_ne_top, one_ne_zero, _root_.div_one]
rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (by simp [norm_nonneg]))
(Lp.aestronglyMeasurable f).norm]
simp [ofReal_norm_eq_coe_nnnorm]
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.norm_eq_integral_norm MeasureTheory.L1.norm_eq_integral_norm
theorem L1.dist_eq_integral_dist (f g : α →₁[μ] H) : dist f g = ∫ a, dist (f a) (g a) ∂μ := by
simp only [dist_eq_norm, L1.norm_eq_integral_norm]
exact integral_congr_ae <| (Lp.coeFn_sub _ _).fun_comp norm
theorem L1.norm_of_fun_eq_integral_norm {f : α → H} (hf : Integrable f μ) :
‖hf.toL1 f‖ = ∫ a, ‖f a‖ ∂μ := by
rw [L1.norm_eq_integral_norm]
exact integral_congr_ae <| hf.coeFn_toL1.fun_comp _
set_option linter.uppercaseLean3 false in
#align measure_theory.L1.norm_of_fun_eq_integral_norm MeasureTheory.L1.norm_of_fun_eq_integral_norm
theorem Memℒp.snorm_eq_integral_rpow_norm {f : α → H} {p : ℝ≥0∞} (hp1 : p ≠ 0) (hp2 : p ≠ ∞)
(hf : Memℒp f p μ) :
snorm f p μ = ENNReal.ofReal ((∫ a, ‖f a‖ ^ p.toReal ∂μ) ^ p.toReal⁻¹) := by
have A : ∫⁻ a : α, ENNReal.ofReal (‖f a‖ ^ p.toReal) ∂μ = ∫⁻ a : α, ‖f a‖₊ ^ p.toReal ∂μ := by
simp_rw [← ofReal_rpow_of_nonneg (norm_nonneg _) toReal_nonneg, ofReal_norm_eq_coe_nnnorm]
simp only [snorm_eq_lintegral_rpow_nnnorm hp1 hp2, one_div]
rw [integral_eq_lintegral_of_nonneg_ae]; rotate_left
· exact ae_of_all _ fun x => by positivity
· exact (hf.aestronglyMeasurable.norm.aemeasurable.pow_const _).aestronglyMeasurable
rw [A, ← ofReal_rpow_of_nonneg toReal_nonneg (inv_nonneg.2 toReal_nonneg), ofReal_toReal]
exact (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp1 hp2 hf.2).ne
#align measure_theory.mem_ℒp.snorm_eq_integral_rpow_norm MeasureTheory.Memℒp.snorm_eq_integral_rpow_norm
end NormedAddCommGroup
theorem integral_mono_ae {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (h : f ≤ᵐ[μ] g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := by
have A : CompleteSpace ℝ := by infer_instance
simp only [integral, A, L1.integral]
exact setToFun_mono (dominatedFinMeasAdditive_weightedSMul μ)
(fun s _ _ => weightedSMul_nonneg s) hf hg h
#align measure_theory.integral_mono_ae MeasureTheory.integral_mono_ae
@[mono]
theorem integral_mono {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (h : f ≤ g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
integral_mono_ae hf hg <| eventually_of_forall h
#align measure_theory.integral_mono MeasureTheory.integral_mono
theorem integral_mono_of_nonneg {f g : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hgi : Integrable g μ)
(h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := by
by_cases hfm : AEStronglyMeasurable f μ
· refine integral_mono_ae ⟨hfm, ?_⟩ hgi h
refine hgi.hasFiniteIntegral.mono <| h.mp <| hf.mono fun x hf hfg => ?_
simpa [abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)]
· rw [integral_non_aestronglyMeasurable hfm]
exact integral_nonneg_of_ae (hf.trans h)
#align measure_theory.integral_mono_of_nonneg MeasureTheory.integral_mono_of_nonneg
theorem integral_mono_measure {f : α → ℝ} {ν} (hle : μ ≤ ν) (hf : 0 ≤ᵐ[ν] f)
(hfi : Integrable f ν) : ∫ a, f a ∂μ ≤ ∫ a, f a ∂ν := by
have hfi' : Integrable f μ := hfi.mono_measure hle
have hf' : 0 ≤ᵐ[μ] f := hle.absolutelyContinuous hf
rw [integral_eq_lintegral_of_nonneg_ae hf' hfi'.1, integral_eq_lintegral_of_nonneg_ae hf hfi.1,
ENNReal.toReal_le_toReal]
exacts [lintegral_mono' hle le_rfl, ((hasFiniteIntegral_iff_ofReal hf').1 hfi'.2).ne,
((hasFiniteIntegral_iff_ofReal hf).1 hfi.2).ne]
#align measure_theory.integral_mono_measure MeasureTheory.integral_mono_measure
theorem norm_integral_le_integral_norm (f : α → G) : ‖∫ a, f a ∂μ‖ ≤ ∫ a, ‖f a‖ ∂μ := by
have le_ae : ∀ᵐ a ∂μ, 0 ≤ ‖f a‖ := eventually_of_forall fun a => norm_nonneg _
by_cases h : AEStronglyMeasurable f μ
· calc
‖∫ a, f a ∂μ‖ ≤ ENNReal.toReal (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) :=
norm_integral_le_lintegral_norm _
_ = ∫ a, ‖f a‖ ∂μ := (integral_eq_lintegral_of_nonneg_ae le_ae <| h.norm).symm
· rw [integral_non_aestronglyMeasurable h, norm_zero]
exact integral_nonneg_of_ae le_ae
#align measure_theory.norm_integral_le_integral_norm MeasureTheory.norm_integral_le_integral_norm
theorem norm_integral_le_of_norm_le {f : α → G} {g : α → ℝ} (hg : Integrable g μ)
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : ‖∫ x, f x ∂μ‖ ≤ ∫ x, g x ∂μ :=
calc
‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ := norm_integral_le_integral_norm f
_ ≤ ∫ x, g x ∂μ := integral_mono_of_nonneg (eventually_of_forall fun _ => norm_nonneg _) hg h
#align measure_theory.norm_integral_le_of_norm_le MeasureTheory.norm_integral_le_of_norm_le
theorem SimpleFunc.integral_eq_integral (f : α →ₛ E) (hfi : Integrable f μ) :
f.integral μ = ∫ x, f x ∂μ := by
rw [MeasureTheory.integral_eq f hfi, ← L1.SimpleFunc.toLp_one_eq_toL1,
L1.SimpleFunc.integral_L1_eq_integral, L1.SimpleFunc.integral_eq_integral]
exact SimpleFunc.integral_congr hfi (Lp.simpleFunc.toSimpleFunc_toLp _ _).symm
#align measure_theory.simple_func.integral_eq_integral MeasureTheory.SimpleFunc.integral_eq_integral
theorem SimpleFunc.integral_eq_sum (f : α →ₛ E) (hfi : Integrable f μ) :
∫ x, f x ∂μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • x := by
rw [← f.integral_eq_integral hfi, SimpleFunc.integral, ← SimpleFunc.integral_eq]; rfl
#align measure_theory.simple_func.integral_eq_sum MeasureTheory.SimpleFunc.integral_eq_sum
@[simp]
theorem integral_const (c : E) : ∫ _ : α, c ∂μ = (μ univ).toReal • c := by
cases' (@le_top _ _ _ (μ univ)).lt_or_eq with hμ hμ
· haveI : IsFiniteMeasure μ := ⟨hμ⟩
simp only [integral, hE, L1.integral]
exact setToFun_const (dominatedFinMeasAdditive_weightedSMul _) _
· by_cases hc : c = 0
· simp [hc, integral_zero]
· have : ¬Integrable (fun _ : α => c) μ := by
simp only [integrable_const_iff, not_or]
exact ⟨hc, hμ.not_lt⟩
simp [integral_undef, *]
#align measure_theory.integral_const MeasureTheory.integral_const
theorem norm_integral_le_of_norm_le_const [IsFiniteMeasure μ] {f : α → G} {C : ℝ}
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖∫ x, f x ∂μ‖ ≤ C * (μ univ).toReal :=
calc
‖∫ x, f x ∂μ‖ ≤ ∫ _, C ∂μ := norm_integral_le_of_norm_le (integrable_const C) h
_ = C * (μ univ).toReal := by rw [integral_const, smul_eq_mul, mul_comm]
#align measure_theory.norm_integral_le_of_norm_le_const MeasureTheory.norm_integral_le_of_norm_le_const
theorem tendsto_integral_approxOn_of_measurable [MeasurableSpace E] [BorelSpace E] {f : α → E}
{s : Set E} [SeparableSpace s] (hfi : Integrable f μ) (hfm : Measurable f)
(hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s) (h₀i : Integrable (fun _ => y₀) μ) :
Tendsto (fun n => (SimpleFunc.approxOn f hfm s y₀ h₀ n).integral μ)
atTop (𝓝 <| ∫ x, f x ∂μ) := by
have hfi' := SimpleFunc.integrable_approxOn hfm hfi h₀ h₀i
simp only [SimpleFunc.integral_eq_integral _ (hfi' _), integral, hE, L1.integral]
exact tendsto_setToFun_approxOn_of_measurable (dominatedFinMeasAdditive_weightedSMul μ)
hfi hfm hs h₀ h₀i
#align measure_theory.tendsto_integral_approx_on_of_measurable MeasureTheory.tendsto_integral_approxOn_of_measurable
theorem tendsto_integral_approxOn_of_measurable_of_range_subset [MeasurableSpace E] [BorelSpace E]
{f : α → E} (fmeas : Measurable f) (hf : Integrable f μ) (s : Set E) [SeparableSpace s]
(hs : range f ∪ {0} ⊆ s) :
Tendsto (fun n => (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n).integral μ) atTop
(𝓝 <| ∫ x, f x ∂μ) := by
apply tendsto_integral_approxOn_of_measurable hf fmeas _ _ (integrable_zero _ _ _)
exact eventually_of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _)))
#align measure_theory.tendsto_integral_approx_on_of_measurable_of_range_subset MeasureTheory.tendsto_integral_approxOn_of_measurable_of_range_subset
theorem tendsto_integral_norm_approxOn_sub [MeasurableSpace E] [BorelSpace E] {f : α → E}
(fmeas : Measurable f) (hf : Integrable f μ) [SeparableSpace (range f ∪ {0} : Set E)] :
Tendsto (fun n ↦ ∫ x, ‖SimpleFunc.approxOn f fmeas (range f ∪ {0}) 0 (by simp) n x - f x‖ ∂μ)
atTop (𝓝 0) := by
convert (tendsto_toReal zero_ne_top).comp (tendsto_approxOn_range_L1_nnnorm fmeas hf) with n
rw [integral_norm_eq_lintegral_nnnorm]
· simp
· apply (SimpleFunc.aestronglyMeasurable _).sub
apply (stronglyMeasurable_iff_measurable_separable.2 ⟨fmeas, ?_⟩ ).aestronglyMeasurable
exact .mono (.of_subtype (range f ∪ {0})) subset_union_left
variable {ν : Measure α}
theorem integral_add_measure {f : α → G} (hμ : Integrable f μ) (hν : Integrable f ν) :
∫ x, f x ∂(μ + ν) = ∫ x, f x ∂μ + ∫ x, f x ∂ν := by
by_cases hG : CompleteSpace G; swap
· simp [integral, hG]
have hfi := hμ.add_measure hν
simp_rw [integral_eq_setToFun]
have hμ_dfma : DominatedFinMeasAdditive (μ + ν) (weightedSMul μ : Set α → G →L[ℝ] G) 1 :=
DominatedFinMeasAdditive.add_measure_right μ ν (dominatedFinMeasAdditive_weightedSMul μ)
zero_le_one
have hν_dfma : DominatedFinMeasAdditive (μ + ν) (weightedSMul ν : Set α → G →L[ℝ] G) 1 :=
DominatedFinMeasAdditive.add_measure_left μ ν (dominatedFinMeasAdditive_weightedSMul ν)
zero_le_one
rw [← setToFun_congr_measure_of_add_right hμ_dfma
(dominatedFinMeasAdditive_weightedSMul μ) f hfi,
← setToFun_congr_measure_of_add_left hν_dfma (dominatedFinMeasAdditive_weightedSMul ν) f hfi]
refine setToFun_add_left' _ _ _ (fun s _ hμνs => ?_) f
rw [Measure.coe_add, Pi.add_apply, add_lt_top] at hμνs
rw [weightedSMul, weightedSMul, weightedSMul, ← add_smul, Measure.coe_add, Pi.add_apply,
toReal_add hμνs.1.ne hμνs.2.ne]
#align measure_theory.integral_add_measure MeasureTheory.integral_add_measure
@[simp]
theorem integral_zero_measure {m : MeasurableSpace α} (f : α → G) :
(∫ x, f x ∂(0 : Measure α)) = 0 := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact setToFun_measure_zero (dominatedFinMeasAdditive_weightedSMul _) rfl
· simp [integral, hG]
#align measure_theory.integral_zero_measure MeasureTheory.integral_zero_measure
theorem integral_finset_sum_measure {ι} {m : MeasurableSpace α} {f : α → G} {μ : ι → Measure α}
{s : Finset ι} (hf : ∀ i ∈ s, Integrable f (μ i)) :
∫ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫ a, f a ∂μ i := by
induction s using Finset.cons_induction_on with
| h₁ => simp
| h₂ h ih =>
rw [Finset.forall_mem_cons] at hf
rw [Finset.sum_cons, Finset.sum_cons, ← ih hf.2]
exact integral_add_measure hf.1 (integrable_finset_sum_measure.2 hf.2)
#align measure_theory.integral_finset_sum_measure MeasureTheory.integral_finset_sum_measure
theorem nndist_integral_add_measure_le_lintegral
{f : α → G} (h₁ : Integrable f μ) (h₂ : Integrable f ν) :
(nndist (∫ x, f x ∂μ) (∫ x, f x ∂(μ + ν)) : ℝ≥0∞) ≤ ∫⁻ x, ‖f x‖₊ ∂ν := by
rw [integral_add_measure h₁ h₂, nndist_comm, nndist_eq_nnnorm, add_sub_cancel_left]
exact ennnorm_integral_le_lintegral_ennnorm _
#align measure_theory.nndist_integral_add_measure_le_lintegral MeasureTheory.nndist_integral_add_measure_le_lintegral
theorem hasSum_integral_measure {ι} {m : MeasurableSpace α} {f : α → G} {μ : ι → Measure α}
(hf : Integrable f (Measure.sum μ)) :
HasSum (fun i => ∫ a, f a ∂μ i) (∫ a, f a ∂Measure.sum μ) := by
have hfi : ∀ i, Integrable f (μ i) := fun i => hf.mono_measure (Measure.le_sum _ _)
simp only [HasSum, ← integral_finset_sum_measure fun i _ => hfi i]
refine Metric.nhds_basis_ball.tendsto_right_iff.mpr fun ε ε0 => ?_
lift ε to ℝ≥0 using ε0.le
have hf_lt : (∫⁻ x, ‖f x‖₊ ∂Measure.sum μ) < ∞ := hf.2
have hmem : ∀ᶠ y in 𝓝 (∫⁻ x, ‖f x‖₊ ∂Measure.sum μ), (∫⁻ x, ‖f x‖₊ ∂Measure.sum μ) < y + ε := by
refine tendsto_id.add tendsto_const_nhds (lt_mem_nhds (α := ℝ≥0∞) <| ENNReal.lt_add_right ?_ ?_)
exacts [hf_lt.ne, ENNReal.coe_ne_zero.2 (NNReal.coe_ne_zero.1 ε0.ne')]
refine ((hasSum_lintegral_measure (fun x => ‖f x‖₊) μ).eventually hmem).mono fun s hs => ?_
obtain ⟨ν, hν⟩ : ∃ ν, (∑ i ∈ s, μ i) + ν = Measure.sum μ := by
refine ⟨Measure.sum fun i : ↥(sᶜ : Set ι) => μ i, ?_⟩
simpa only [← Measure.sum_coe_finset] using Measure.sum_add_sum_compl (s : Set ι) μ
rw [Metric.mem_ball, ← coe_nndist, NNReal.coe_lt_coe, ← ENNReal.coe_lt_coe, ← hν]
rw [← hν, integrable_add_measure] at hf
refine (nndist_integral_add_measure_le_lintegral hf.1 hf.2).trans_lt ?_
rw [← hν, lintegral_add_measure, lintegral_finset_sum_measure] at hs
exact lt_of_add_lt_add_left hs
#align measure_theory.has_sum_integral_measure MeasureTheory.hasSum_integral_measure
theorem integral_sum_measure {ι} {_ : MeasurableSpace α} {f : α → G} {μ : ι → Measure α}
(hf : Integrable f (Measure.sum μ)) : ∫ a, f a ∂Measure.sum μ = ∑' i, ∫ a, f a ∂μ i :=
(hasSum_integral_measure hf).tsum_eq.symm
#align measure_theory.integral_sum_measure MeasureTheory.integral_sum_measure
@[simp]
| Mathlib/MeasureTheory/Integral/Bochner.lean | 1,657 | 1,670 | theorem integral_smul_measure (f : α → G) (c : ℝ≥0∞) :
∫ x, f x ∂c • μ = c.toReal • ∫ x, f x ∂μ := by |
by_cases hG : CompleteSpace G; swap
· simp [integral, hG]
-- First we consider the “degenerate” case `c = ∞`
rcases eq_or_ne c ∞ with (rfl | hc)
· rw [ENNReal.top_toReal, zero_smul, integral_eq_setToFun, setToFun_top_smul_measure]
-- Main case: `c ≠ ∞`
simp_rw [integral_eq_setToFun, ← setToFun_smul_left]
have hdfma : DominatedFinMeasAdditive μ (weightedSMul (c • μ) : Set α → G →L[ℝ] G) c.toReal :=
mul_one c.toReal ▸ (dominatedFinMeasAdditive_weightedSMul (c • μ)).of_smul_measure c hc
have hdfma_smul := dominatedFinMeasAdditive_weightedSMul (F := G) (c • μ)
rw [← setToFun_congr_smul_measure c hc hdfma hdfma_smul f]
exact setToFun_congr_left' _ _ (fun s _ _ => weightedSMul_smul_measure μ c) f
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Order.Filter.Basic
import Mathlib.Topology.Bases
import Mathlib.Data.Set.Accumulate
import Mathlib.Topology.Bornology.Basic
import Mathlib.Topology.LocallyFinite
/-!
# Compact sets and compact spaces
## Main definitions
We define the following properties for sets in a topological space:
* `IsCompact`: a set such that each open cover has a finite subcover. This is defined in mathlib
using filters. The main property of a compact set is `IsCompact.elim_finite_subcover`.
* `CompactSpace`: typeclass stating that the whole space is a compact set.
* `NoncompactSpace`: a space that is not a compact space.
## Main results
* `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets
is compact.
-/
open Set Filter Topology TopologicalSpace Classical Function
universe u v
variable {X : Type u} {Y : Type v} {ι : Type*}
variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X}
-- compact sets
section Compact
lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) :
∃ x ∈ s, ClusterPt x f := hs hf
lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f]
{u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) :
∃ x ∈ s, MapClusterPt x f u := hs hf
/-- The complement to a compact set belongs to a filter `f` if it belongs to each filter
`𝓝 x ⊓ f`, `x ∈ s`. -/
theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) :
sᶜ ∈ f := by
contrapose! hf
simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢
exact @hs _ hf inf_le_right
#align is_compact.compl_mem_sets IsCompact.compl_mem_sets
/-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t`
within `s` such that `tᶜ` belongs to `f`. -/
theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X}
(hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by
refine hs.compl_mem_sets fun x hx => ?_
rcases hf x hx with ⟨t, ht, hst⟩
replace ht := mem_inf_principal.1 ht
apply mem_inf_of_inter ht hst
rintro x ⟨h₁, h₂⟩ hs
exact h₂ (h₁ hs)
#align is_compact.compl_mem_sets_of_nhds_within IsCompact.compl_mem_sets_of_nhdsWithin
/-- If `p : Set X → Prop` is stable under restriction and union, and each point `x`
of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/
@[elab_as_elim]
theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅)
(hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t))
(hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by
let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht)
have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds)
rwa [← compl_compl s]
#align is_compact.induction_on IsCompact.induction_on
/-- The intersection of a compact set and a closed set is a compact set. -/
theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by
intro f hnf hstf
obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f :=
hs (le_trans hstf (le_principal_iff.2 inter_subset_left))
have : x ∈ t := ht.mem_of_nhdsWithin_neBot <|
hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right)
exact ⟨x, ⟨hsx, this⟩, hx⟩
#align is_compact.inter_right IsCompact.inter_right
/-- The intersection of a closed set and a compact set is a compact set. -/
theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
#align is_compact.inter_left IsCompact.inter_left
/-- The set difference of a compact set and an open set is a compact set. -/
theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) :=
hs.inter_right (isClosed_compl_iff.mpr ht)
#align is_compact.diff IsCompact.diff
/-- A closed subset of a compact set is a compact set. -/
theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) :
IsCompact t :=
inter_eq_self_of_subset_right h ▸ hs.inter_right ht
#align is_compact_of_is_closed_subset IsCompact.of_isClosed_subset
theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) :
IsCompact (f '' s) := by
intro l lne ls
have : NeBot (l.comap f ⊓ 𝓟 s) :=
comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls)
obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this inf_le_right
haveI := hx.neBot
use f x, mem_image_of_mem f hxs
have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by
convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1
rw [nhdsWithin]
ac_rfl
exact this.neBot
#align is_compact.image_of_continuous_on IsCompact.image_of_continuousOn
theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) :=
hs.image_of_continuousOn hf.continuousOn
#align is_compact.image IsCompact.image
theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s)
(ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f :=
Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) =>
let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂
have : x ∈ t := ht₂ x hx hfx.of_inf_left
have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ this)
have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this
have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne
absurd A this
#align is_compact.adherence_nhdset IsCompact.adherence_nhdset
theorem isCompact_iff_ultrafilter_le_nhds :
IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by
refine (forall_neBot_le_iff ?_).trans ?_
· rintro f g hle ⟨x, hxs, hxf⟩
exact ⟨x, hxs, hxf.mono hle⟩
· simp only [Ultrafilter.clusterPt_iff]
#align is_compact_iff_ultrafilter_le_nhds isCompact_iff_ultrafilter_le_nhds
alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds
#align is_compact.ultrafilter_le_nhds IsCompact.ultrafilter_le_nhds
theorem isCompact_iff_ultrafilter_le_nhds' :
IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by
simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe]
alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds'
/-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set,
then the filter is less than or equal to `𝓝 y`. -/
lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X}
(hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by
refine le_iff_ultrafilter.2 fun f hf ↦ ?_
rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩
convert ← hx
exact h x hxs (.mono (.of_le_nhds hx) hf)
/-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l`
and `y` is a unique `MapClusterPt` for `f` along `l` in `s`,
then `f` tends to `𝓝 y` along `l`. -/
lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {l : Filter Y} {y : X} {f : Y → X}
(hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) :
Tendsto f l (𝓝 y) :=
hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h
/-- For every open directed cover of a compact set, there exists a single element of the
cover which itself includes the set. -/
theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s)
(U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) :
∃ i, s ⊆ U i :=
hι.elim fun i₀ =>
IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩)
(fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ =>
let ⟨k, hki, hkj⟩ := hdU i j
⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩)
fun _x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx)
⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩
#align is_compact.elim_directed_cover IsCompact.elim_directed_cover
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X)
(hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i :=
hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i)
(iUnion_eq_iUnion_finset U ▸ hsU)
(directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h)
#align is_compact.elim_finite_subcover IsCompact.elim_finite_subcover
lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by
rcases hs.elim_finite_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior)
fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ with ⟨t, hst⟩
refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩
rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩
refine mem_of_superset ?_ (subset_biUnion_of_mem hyt)
exact mem_interior_iff_mem_nhds.1 hy
lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X}
(hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s :=
let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU
⟨t.image (↑), fun x hx =>
let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx
hyx ▸ y.2,
by rwa [Finset.set_biUnion_finset_image]⟩
theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 :=
(hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet
#align is_compact.elim_nhds_subcover' IsCompact.elim_nhds_subcover'
theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) :
∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x :=
(hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet
#align is_compact.elim_nhds_subcover IsCompact.elim_nhds_subcover
/-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the
neighborhood filter of each point of this set is disjoint with `l`. -/
theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact s) :
Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by
refine ⟨fun h x hx => h.mono_left <| nhds_le_nhdsSet hx, fun H => ?_⟩
choose! U hxU hUl using fun x hx => (nhds_basis_opens x).disjoint_iff_left.1 (H x hx)
choose hxU hUo using hxU
rcases hs.elim_nhds_subcover U fun x hx => (hUo x hx).mem_nhds (hxU x hx) with ⟨t, hts, hst⟩
refine (hasBasis_nhdsSet _).disjoint_iff_left.2
⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx => hUo x (hts x hx), hst⟩, ?_⟩
rw [compl_iUnion₂, biInter_finset_mem]
exact fun x hx => hUl x (hts x hx)
#align is_compact.disjoint_nhds_set_left IsCompact.disjoint_nhdsSet_left
/-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is
disjoint with the neighborhood filter of each point of this set. -/
theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) :
Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by
simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left
#align is_compact.disjoint_nhds_set_right IsCompact.disjoint_nhdsSet_right
-- Porting note (#11215): TODO: reformulate using `Disjoint`
/-- For every directed family of closed sets whose intersection avoids a compact set,
there exists a single element of the family which itself avoids this compact set. -/
theorem IsCompact.elim_directed_family_closed {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅)
(hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ :=
let ⟨t, ht⟩ :=
hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl)
(by
simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop,
mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using hst)
(hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr)
⟨t, by
simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop,
mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using ht⟩
#align is_compact.elim_directed_family_closed IsCompact.elim_directed_family_closed
-- Porting note (#11215): TODO: reformulate using `Disjoint`
/-- For every family of closed sets whose intersection avoids a compact set,
there exists a finite subfamily whose intersection avoids this compact set. -/
theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) :
∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ :=
hs.elim_directed_family_closed _ (fun t ↦ isClosed_biInter fun _ _ ↦ htc _)
(by rwa [← iInter_eq_iInter_finset])
(directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h)
#align is_compact.elim_finite_subfamily_closed IsCompact.elim_finite_subfamily_closed
/-- If `s` is a compact set in a topological space `X` and `f : ι → Set X` is a locally finite
family of sets, then `f i ∩ s` is nonempty only for a finitely many `i`. -/
theorem LocallyFinite.finite_nonempty_inter_compact {f : ι → Set X}
(hf : LocallyFinite f) (hs : IsCompact s) : { i | (f i ∩ s).Nonempty }.Finite := by
choose U hxU hUf using hf
rcases hs.elim_nhds_subcover U fun x _ => hxU x with ⟨t, -, hsU⟩
refine (t.finite_toSet.biUnion fun x _ => hUf x).subset ?_
rintro i ⟨x, hx⟩
rcases mem_iUnion₂.1 (hsU hx.2) with ⟨c, hct, hcx⟩
exact mem_biUnion hct ⟨x, hx.1, hcx⟩
#align locally_finite.finite_nonempty_inter_compact LocallyFinite.finite_nonempty_inter_compact
/-- To show that a compact set intersects the intersection of a family of closed sets,
it is sufficient to show that it intersects every finite subfamily. -/
theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X)
(htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) :
(s ∩ ⋂ i, t i).Nonempty := by
contrapose! hst
exact hs.elim_finite_subfamily_closed t htc hst
#align is_compact.inter_Inter_nonempty IsCompact.inter_iInter_nonempty
/-- Cantor's intersection theorem for `iInter`:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
{ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t)
(htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) :
(⋂ i, t i).Nonempty := by
let i₀ := hι.some
suffices (t i₀ ∩ ⋂ i, t i).Nonempty by
rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this
simp only [nonempty_iff_ne_empty] at htn ⊢
apply mt ((htc i₀).elim_directed_family_closed t htcl)
push_neg
simp only [← nonempty_iff_ne_empty] at htn ⊢
refine ⟨htd, fun i => ?_⟩
rcases htd i₀ i with ⟨j, hji₀, hji⟩
exact (htn j).mono (subset_inter hji₀ hji)
#align is_compact.nonempty_Inter_of_directed_nonempty_compact_closed IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
@[deprecated (since := "2024-02-28")]
alias IsCompact.nonempty_iInter_of_directed_nonempty_compact_closed :=
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
/-- Cantor's intersection theorem for `sInter`:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed
{S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty)
(hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by
rw [sInter_eq_iInter]
exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _
(DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2)
/-- Cantor's intersection theorem for sequences indexed by `ℕ`:
the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X)
(htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0))
(htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty :=
have tmono : Antitone t := antitone_nat_of_succ_le htd
have htd : Directed (· ⊇ ·) t := tmono.directed_ge
have : ∀ i, t i ⊆ t 0 := fun i => tmono <| zero_le i
have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i)
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl
#align is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed
@[deprecated (since := "2024-02-28")]
alias IsCompact.nonempty_iInter_of_sequence_nonempty_compact_closed :=
IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s)
(hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) :
∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by
simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂
rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩
refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩
· simp
· rwa [biUnion_image]
#align is_compact.elim_finite_subcover_image IsCompact.elim_finite_subcover_imageₓ
/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/
theorem isCompact_of_finite_subcover
(h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) →
∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) :
IsCompact s := fun f hf hfs => by
contrapose! h
simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall',
(nhds_basis_opens _).disjoint_iff_left] at h
choose U hU hUf using h
refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩
refine compl_not_mem (le_principal_iff.1 hfs) ?_
refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_
rw [subset_compl_comm, compl_iInter₂]
simpa only [compl_compl]
#align is_compact_of_finite_subcover isCompact_of_finite_subcover
-- Porting note (#11215): TODO: reformulate using `Disjoint`
/-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem isCompact_of_finite_subfamily_closed
(h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ →
∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) :
IsCompact s :=
isCompact_of_finite_subcover fun U hUo hsU => by
rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU
rcases h (fun i => (U i)ᶜ) (fun i => (hUo _).isClosed_compl) hsU with ⟨t, ht⟩
refine ⟨t, ?_⟩
rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff]
#align is_compact_of_finite_subfamily_closed isCompact_of_finite_subfamily_closed
/-- A set `s` is compact if and only if
for every open cover of `s`, there exists a finite subcover. -/
theorem isCompact_iff_finite_subcover :
IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X),
(∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i :=
⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩
#align is_compact_iff_finite_subcover isCompact_iff_finite_subcover
/-- A set `s` is compact if and only if
for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem isCompact_iff_finite_subfamily_closed :
IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X),
(∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ :=
⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩
#align is_compact_iff_finite_subfamily_closed isCompact_iff_finite_subfamily_closed
/-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`,
then it belongs to `(𝓝ˢ K) ×ˢ l`,
i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/
theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {l : Filter Y} {s : Set (X × Y)}
(hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by
refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_
· exact prod_mono (nhdsSet_mono ht) le_rfl hs
· simp [sup_prod, *]
· rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx)
with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩
refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩
exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv
theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter Y) :
(𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l :=
le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs)
(iSup₂_le fun x hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl)
theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) (l : Filter X) :
l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by
simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup]
/-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`,
then it belongs to `l ×ˢ (𝓝ˢ K)`,
i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/
theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {l : Filter X} {s : Set (X × Y)}
(hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K :=
(hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs
-- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ?
-- That would seem a bit more natural.
theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) :
(𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by
have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by
simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm
simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup]
theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) :
l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by
simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup]
/-- If `s : Set X` belongs to `𝓝 x ⊓ l` for all `x` from a compact set `K`,
then it belongs to `(𝓝ˢ K) ⊓ l`,
i.e., there exist an open `U ⊇ K` and `T ∈ l` such that `U ∩ T ⊆ s`. -/
theorem IsCompact.mem_nhdsSet_inf_of_forall {K : Set X} {l : Filter X} {s : Set X}
(hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ⊓ l) : s ∈ (𝓝ˢ K) ⊓ l :=
(hK.nhdsSet_inf_eq_biSup l).symm ▸ by simpa using hs
/-- If `s : Set S` belongs to `l ⊓ 𝓝 x` for all `x` from a compact set `K`,
then it belongs to `l ⊓ (𝓝ˢ K)`,
i.e., there exist `T ∈ l` and an open `U ⊇ K` such that `T ∩ U ⊆ s`. -/
theorem IsCompact.mem_inf_nhdsSet_of_forall {K : Set X} {l : Filter X} {s : Set X}
(hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ⊓ 𝓝 y) : s ∈ l ⊓ 𝓝ˢ K :=
(hK.inf_nhdsSet_eq_biSup l).symm ▸ by simpa using hs
/-- To show that `∀ y ∈ K, P x y` holds for `x` close enough to `x₀` when `K` is compact,
it is sufficient to show that for all `y₀ ∈ K` there `P x y` holds for `(x, y)` close enough
to `(x₀, y₀)`.
Provided for backwards compatibility,
see `IsCompact.mem_prod_nhdsSet_of_forall` for a stronger statement.
-/
theorem IsCompact.eventually_forall_of_forall_eventually {x₀ : X} {K : Set Y} (hK : IsCompact K)
{P : X → Y → Prop} (hP : ∀ y ∈ K, ∀ᶠ z : X × Y in 𝓝 (x₀, y), P z.1 z.2) :
∀ᶠ x in 𝓝 x₀, ∀ y ∈ K, P x y := by
simp only [nhds_prod_eq, ← eventually_iSup, ← hK.prod_nhdsSet_eq_biSup] at hP
exact hP.curry.mono fun _ h ↦ h.self_of_nhdsSet
#align is_compact.eventually_forall_of_forall_eventually IsCompact.eventually_forall_of_forall_eventually
@[simp]
theorem isCompact_empty : IsCompact (∅ : Set X) := fun _f hnf hsf =>
Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf
#align is_compact_empty isCompact_empty
@[simp]
theorem isCompact_singleton {x : X} : IsCompact ({x} : Set X) := fun f hf hfa =>
⟨x, rfl, ClusterPt.of_le_nhds'
(hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩
#align is_compact_singleton isCompact_singleton
theorem Set.Subsingleton.isCompact (hs : s.Subsingleton) : IsCompact s :=
Subsingleton.induction_on hs isCompact_empty fun _ => isCompact_singleton
#align set.subsingleton.is_compact Set.Subsingleton.isCompact
-- Porting note: golfed a proof instead of fixing it
theorem Set.Finite.isCompact_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite)
(hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) :=
isCompact_iff_ultrafilter_le_nhds'.2 fun l hl => by
rw [Ultrafilter.finite_biUnion_mem_iff hs] at hl
rcases hl with ⟨i, his, hi⟩
rcases (hf i his).ultrafilter_le_nhds _ (le_principal_iff.2 hi) with ⟨x, hxi, hlx⟩
exact ⟨x, mem_iUnion₂.2 ⟨i, his, hxi⟩, hlx⟩
#align set.finite.is_compact_bUnion Set.Finite.isCompact_biUnion
theorem Finset.isCompact_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsCompact (f i)) :
IsCompact (⋃ i ∈ s, f i) :=
s.finite_toSet.isCompact_biUnion hf
#align finset.is_compact_bUnion Finset.isCompact_biUnion
theorem isCompact_accumulate {K : ℕ → Set X} (hK : ∀ n, IsCompact (K n)) (n : ℕ) :
IsCompact (Accumulate K n) :=
(finite_le_nat n).isCompact_biUnion fun k _ => hK k
#align is_compact_accumulate isCompact_accumulate
-- Porting note (#10756): new lemma
theorem Set.Finite.isCompact_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsCompact s) :
IsCompact (⋃₀ S) := by
rw [sUnion_eq_biUnion]; exact hf.isCompact_biUnion hc
-- Porting note: generalized to `ι : Sort*`
theorem isCompact_iUnion {ι : Sort*} {f : ι → Set X} [Finite ι] (h : ∀ i, IsCompact (f i)) :
IsCompact (⋃ i, f i) :=
(finite_range f).isCompact_sUnion <| forall_mem_range.2 h
#align is_compact_Union isCompact_iUnion
theorem Set.Finite.isCompact (hs : s.Finite) : IsCompact s :=
biUnion_of_singleton s ▸ hs.isCompact_biUnion fun _ _ => isCompact_singleton
#align set.finite.is_compact Set.Finite.isCompact
theorem IsCompact.finite_of_discrete [DiscreteTopology X] (hs : IsCompact s) : s.Finite := by
have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete]
rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, _, hst⟩
simp only [← t.set_biUnion_coe, biUnion_of_singleton] at hst
exact t.finite_toSet.subset hst
#align is_compact.finite_of_discrete IsCompact.finite_of_discrete
theorem isCompact_iff_finite [DiscreteTopology X] : IsCompact s ↔ s.Finite :=
⟨fun h => h.finite_of_discrete, fun h => h.isCompact⟩
#align is_compact_iff_finite isCompact_iff_finite
theorem IsCompact.union (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∪ t) := by
rw [union_eq_iUnion]; exact isCompact_iUnion fun b => by cases b <;> assumption
#align is_compact.union IsCompact.union
protected theorem IsCompact.insert (hs : IsCompact s) (a) : IsCompact (insert a s) :=
isCompact_singleton.union hs
#align is_compact.insert IsCompact.insert
-- Porting note (#11215): TODO: reformulate using `𝓝ˢ`
/-- If `V : ι → Set X` is a decreasing family of closed compact sets then any neighborhood of
`⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `X` is
not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/
theorem exists_subset_nhds_of_isCompact' [Nonempty ι] {V : ι → Set X}
(hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) (hV_closed : ∀ i, IsClosed (V i))
{U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := by
obtain ⟨W, hsubW, W_op, hWU⟩ := exists_open_set_nhds hU
suffices ∃ i, V i ⊆ W from this.imp fun i hi => hi.trans hWU
by_contra! H
replace H : ∀ i, (V i ∩ Wᶜ).Nonempty := fun i => Set.inter_compl_nonempty_iff.mpr (H i)
have : (⋂ i, V i ∩ Wᶜ).Nonempty := by
refine
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun i j => ?_) H
(fun i => (hV_cpct i).inter_right W_op.isClosed_compl) fun i =>
(hV_closed i).inter W_op.isClosed_compl
rcases hV i j with ⟨k, hki, hkj⟩
refine ⟨k, ⟨fun x => ?_, fun x => ?_⟩⟩ <;> simp only [and_imp, mem_inter_iff, mem_compl_iff] <;>
tauto
have : ¬⋂ i : ι, V i ⊆ W := by simpa [← iInter_inter, inter_compl_nonempty_iff]
contradiction
#align exists_subset_nhds_of_is_compact' exists_subset_nhds_of_isCompact'
lemma eq_finite_iUnion_of_isTopologicalBasis_of_isCompact_open (b : ι → Set X)
(hb : IsTopologicalBasis (Set.range b)) (U : Set X) (hUc : IsCompact U) (hUo : IsOpen U) :
∃ s : Set ι, s.Finite ∧ U = ⋃ i ∈ s, b i := by
obtain ⟨Y, f, e, hf⟩ := hb.open_eq_iUnion hUo
choose f' hf' using hf
have : b ∘ f' = f := funext hf'
subst this
obtain ⟨t, ht⟩ :=
hUc.elim_finite_subcover (b ∘ f') (fun i => hb.isOpen (Set.mem_range_self _)) (by rw [e])
refine ⟨t.image f', Set.toFinite _, le_antisymm ?_ ?_⟩
· refine Set.Subset.trans ht ?_
simp only [Set.iUnion_subset_iff]
intro i hi
erw [← Set.iUnion_subtype (fun x : ι => x ∈ t.image f') fun i => b i.1]
exact Set.subset_iUnion (fun i : t.image f' => b i) ⟨_, Finset.mem_image_of_mem _ hi⟩
· apply Set.iUnion₂_subset
rintro i hi
obtain ⟨j, -, rfl⟩ := Finset.mem_image.mp hi
rw [e]
exact Set.subset_iUnion (b ∘ f') j
lemma eq_sUnion_finset_of_isTopologicalBasis_of_isCompact_open (b : Set (Set X))
(hb : IsTopologicalBasis b) (U : Set X) (hUc : IsCompact U) (hUo : IsOpen U) :
∃ s : Finset b, U = s.toSet.sUnion := by
have hb' : b = range (fun i ↦ i : b → Set X) := by simp
rw [hb'] at hb
choose s hs hU using eq_finite_iUnion_of_isTopologicalBasis_of_isCompact_open _ hb U hUc hUo
have : Finite s := hs
let _ : Fintype s := Fintype.ofFinite _
use s.toFinset
simp [hU]
/-- If `X` has a basis consisting of compact opens, then an open set in `X` is compact open iff
it is a finite union of some elements in the basis -/
theorem isCompact_open_iff_eq_finite_iUnion_of_isTopologicalBasis (b : ι → Set X)
(hb : IsTopologicalBasis (Set.range b)) (hb' : ∀ i, IsCompact (b i)) (U : Set X) :
IsCompact U ∧ IsOpen U ↔ ∃ s : Set ι, s.Finite ∧ U = ⋃ i ∈ s, b i := by
constructor
· exact fun ⟨h₁, h₂⟩ ↦ eq_finite_iUnion_of_isTopologicalBasis_of_isCompact_open _ hb U h₁ h₂
· rintro ⟨s, hs, rfl⟩
constructor
· exact hs.isCompact_biUnion fun i _ => hb' i
· exact isOpen_biUnion fun i _ => hb.isOpen (Set.mem_range_self _)
#align is_compact_open_iff_eq_finite_Union_of_is_topological_basis isCompact_open_iff_eq_finite_iUnion_of_isTopologicalBasis
namespace Filter
theorem hasBasis_cocompact : (cocompact X).HasBasis IsCompact compl :=
hasBasis_biInf_principal'
(fun s hs t ht =>
⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩)
⟨∅, isCompact_empty⟩
#align filter.has_basis_cocompact Filter.hasBasis_cocompact
theorem mem_cocompact : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ tᶜ ⊆ s :=
hasBasis_cocompact.mem_iff
#align filter.mem_cocompact Filter.mem_cocompact
theorem mem_cocompact' : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ sᶜ ⊆ t :=
mem_cocompact.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm
#align filter.mem_cocompact' Filter.mem_cocompact'
theorem _root_.IsCompact.compl_mem_cocompact (hs : IsCompact s) : sᶜ ∈ Filter.cocompact X :=
hasBasis_cocompact.mem_of_mem hs
#align is_compact.compl_mem_cocompact IsCompact.compl_mem_cocompact
theorem cocompact_le_cofinite : cocompact X ≤ cofinite := fun s hs =>
compl_compl s ▸ hs.isCompact.compl_mem_cocompact
#align filter.cocompact_le_cofinite Filter.cocompact_le_cofinite
theorem cocompact_eq_cofinite (X : Type*) [TopologicalSpace X] [DiscreteTopology X] :
cocompact X = cofinite := by
simp only [cocompact, hasBasis_cofinite.eq_biInf, isCompact_iff_finite]
#align filter.cocompact_eq_cofinite Filter.cocompact_eq_cofinite
/-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/
theorem disjoint_cocompact_left (f : Filter X) :
Disjoint (Filter.cocompact X) f ↔ ∃ K ∈ f, IsCompact K := by
simp_rw [hasBasis_cocompact.disjoint_iff_left, compl_compl]
tauto
/-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/
theorem disjoint_cocompact_right (f : Filter X) :
Disjoint f (Filter.cocompact X) ↔ ∃ K ∈ f, IsCompact K := by
simp_rw [hasBasis_cocompact.disjoint_iff_right, compl_compl]
tauto
@[deprecated "see `cocompact_eq_atTop` with `import Mathlib.Topology.Instances.Nat`"
(since := "2024-02-07")]
theorem _root_.Nat.cocompact_eq : cocompact ℕ = atTop :=
(cocompact_eq_cofinite ℕ).trans Nat.cofinite_eq_atTop
#align nat.cocompact_eq Nat.cocompact_eq
theorem Tendsto.isCompact_insert_range_of_cocompact {f : X → Y} {y}
(hf : Tendsto f (cocompact X) (𝓝 y)) (hfc : Continuous f) : IsCompact (insert y (range f)) := by
intro l hne hle
by_cases hy : ClusterPt y l
· exact ⟨y, Or.inl rfl, hy⟩
simp only [clusterPt_iff, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy
rcases hy with ⟨s, hsy, t, htl, hd⟩
rcases mem_cocompact.1 (hf hsy) with ⟨K, hKc, hKs⟩
have : f '' K ∈ l := by
filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf
rcases hyf with (rfl | ⟨x, rfl⟩)
exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim,
mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)]
rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩
exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩
#align filter.tendsto.is_compact_insert_range_of_cocompact Filter.Tendsto.isCompact_insert_range_of_cocompact
theorem Tendsto.isCompact_insert_range_of_cofinite {f : ι → X} {x} (hf : Tendsto f cofinite (𝓝 x)) :
IsCompact (insert x (range f)) := by
letI : TopologicalSpace ι := ⊥; haveI h : DiscreteTopology ι := ⟨rfl⟩
rw [← cocompact_eq_cofinite ι] at hf
exact hf.isCompact_insert_range_of_cocompact continuous_of_discreteTopology
#align filter.tendsto.is_compact_insert_range_of_cofinite Filter.Tendsto.isCompact_insert_range_of_cofinite
theorem Tendsto.isCompact_insert_range {f : ℕ → X} {x} (hf : Tendsto f atTop (𝓝 x)) :
IsCompact (insert x (range f)) :=
Filter.Tendsto.isCompact_insert_range_of_cofinite <| Nat.cofinite_eq_atTop.symm ▸ hf
#align filter.tendsto.is_compact_insert_range Filter.Tendsto.isCompact_insert_range
theorem hasBasis_coclosedCompact :
(Filter.coclosedCompact X).HasBasis (fun s => IsClosed s ∧ IsCompact s) compl := by
simp only [Filter.coclosedCompact, iInf_and']
refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isCompact_empty⟩
rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩
exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩⟩
#align filter.has_basis_coclosed_compact Filter.hasBasis_coclosedCompact
/-- A set belongs to `coclosedCompact` if and only if the closure of its complement is compact. -/
theorem mem_coclosedCompact_iff :
s ∈ coclosedCompact X ↔ IsCompact (closure sᶜ) := by
refine hasBasis_coclosedCompact.mem_iff.trans ⟨?_, fun h ↦ ?_⟩
· rintro ⟨t, ⟨htcl, htco⟩, hst⟩
exact htco.of_isClosed_subset isClosed_closure <|
closure_minimal (compl_subset_comm.2 hst) htcl
· exact ⟨closure sᶜ, ⟨isClosed_closure, h⟩, compl_subset_comm.2 subset_closure⟩
@[deprecated mem_coclosedCompact_iff (since := "2024-02-16")]
theorem mem_coclosedCompact : s ∈ coclosedCompact X ↔ ∃ t, IsClosed t ∧ IsCompact t ∧ tᶜ ⊆ s := by
simp only [hasBasis_coclosedCompact.mem_iff, and_assoc]
#align filter.mem_coclosed_compact Filter.mem_coclosedCompact
@[deprecated mem_coclosedCompact_iff (since := "2024-02-16")]
theorem mem_coclosed_compact' : s ∈ coclosedCompact X ↔ ∃ t, IsClosed t ∧ IsCompact t ∧ sᶜ ⊆ t := by
simp only [hasBasis_coclosedCompact.mem_iff, compl_subset_comm, and_assoc]
#align filter.mem_coclosed_compact' Filter.mem_coclosed_compact'
/-- Complement of a set belongs to `coclosedCompact` if and only if its closure is compact. -/
theorem compl_mem_coclosedCompact : sᶜ ∈ coclosedCompact X ↔ IsCompact (closure s) := by
rw [mem_coclosedCompact_iff, compl_compl]
theorem cocompact_le_coclosedCompact : cocompact X ≤ coclosedCompact X :=
iInf_mono fun _ => le_iInf fun _ => le_rfl
#align filter.cocompact_le_coclosed_compact Filter.cocompact_le_coclosedCompact
end Filter
theorem IsCompact.compl_mem_coclosedCompact_of_isClosed (hs : IsCompact s) (hs' : IsClosed s) :
sᶜ ∈ Filter.coclosedCompact X :=
hasBasis_coclosedCompact.mem_of_mem ⟨hs', hs⟩
#align is_compact.compl_mem_coclosed_compact_of_is_closed IsCompact.compl_mem_coclosedCompact_of_isClosed
namespace Bornology
variable (X) in
/-- Sets that are contained in a compact set form a bornology. Its `cobounded` filter is
`Filter.cocompact`. See also `Bornology.relativelyCompact` the bornology of sets with compact
closure. -/
def inCompact : Bornology X where
cobounded' := Filter.cocompact X
le_cofinite' := Filter.cocompact_le_cofinite
#align bornology.in_compact Bornology.inCompact
theorem inCompact.isBounded_iff : @IsBounded _ (inCompact X) s ↔ ∃ t, IsCompact t ∧ s ⊆ t := by
change sᶜ ∈ Filter.cocompact X ↔ _
rw [Filter.mem_cocompact]
simp
#align bornology.in_compact.is_bounded_iff Bornology.inCompact.isBounded_iff
end Bornology
#noalign nhds_contain_boxes
#noalign nhds_contain_boxes.symm
#noalign nhds_contain_boxes.comm
#noalign nhds_contain_boxes_of_singleton
#noalign nhds_contain_boxes_of_compact
/-- If `s` and `t` are compact sets, then the set neighborhoods filter of `s ×ˢ t`
is the product of set neighborhoods filters for `s` and `t`.
For general sets, only the `≤` inequality holds, see `nhdsSet_prod_le`. -/
theorem IsCompact.nhdsSet_prod_eq {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) :
𝓝ˢ (s ×ˢ t) = 𝓝ˢ s ×ˢ 𝓝ˢ t := by
simp_rw [hs.nhdsSet_prod_eq_biSup, ht.prod_nhdsSet_eq_biSup, nhdsSet, sSup_image, biSup_prod,
nhds_prod_eq]
theorem nhdsSet_prod_le_of_disjoint_cocompact {f : Filter Y} (hs : IsCompact s)
(hf : Disjoint f (Filter.cocompact Y)) :
𝓝ˢ s ×ˢ f ≤ 𝓝ˢ (s ×ˢ Set.univ) := by
obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf
calc
𝓝ˢ s ×ˢ f
_ ≤ 𝓝ˢ s ×ˢ 𝓟 K := Filter.prod_mono_right _ (Filter.le_principal_iff.mpr hKf)
_ ≤ 𝓝ˢ s ×ˢ 𝓝ˢ K := Filter.prod_mono_right _ principal_le_nhdsSet
_ = 𝓝ˢ (s ×ˢ K) := (hs.nhdsSet_prod_eq hK).symm
_ ≤ 𝓝ˢ (s ×ˢ Set.univ) := nhdsSet_mono (prod_mono_right le_top)
theorem prod_nhdsSet_le_of_disjoint_cocompact {f : Filter X} (ht : IsCompact t)
(hf : Disjoint f (Filter.cocompact X)) :
f ×ˢ 𝓝ˢ t ≤ 𝓝ˢ (Set.univ ×ˢ t) := by
obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf
calc
f ×ˢ 𝓝ˢ t
_ ≤ (𝓟 K) ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ (Filter.le_principal_iff.mpr hKf)
_ ≤ 𝓝ˢ K ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ principal_le_nhdsSet
_ = 𝓝ˢ (K ×ˢ t) := (hK.nhdsSet_prod_eq ht).symm
_ ≤ 𝓝ˢ (Set.univ ×ˢ t) := nhdsSet_mono (prod_mono_left le_top)
/-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist
open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`.
See also `IsCompact.nhdsSet_prod_eq`. -/
| Mathlib/Topology/Compactness/Compact.lean | 780 | 786 | theorem generalized_tube_lemma (hs : IsCompact s) {t : Set Y} (ht : IsCompact t)
{n : Set (X × Y)} (hn : IsOpen n) (hp : s ×ˢ t ⊆ n) :
∃ (u : Set X) (v : Set Y), IsOpen u ∧ IsOpen v ∧ s ⊆ u ∧ t ⊆ v ∧ u ×ˢ v ⊆ n := by |
rw [← hn.mem_nhdsSet, hs.nhdsSet_prod_eq ht,
((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).mem_iff] at hp
rcases hp with ⟨⟨u, v⟩, ⟨⟨huo, hsu⟩, hvo, htv⟩, hn⟩
exact ⟨u, v, huo, hvo, hsu, htv, hn⟩
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Topology.Maps
import Mathlib.Topology.NhdsSet
#align_import topology.constructions from "leanprover-community/mathlib"@"f7ebde7ee0d1505dfccac8644ae12371aa3c1c9f"
/-!
# Constructions of new topological spaces from old ones
This file constructs products, sums, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, sum, disjoint union, subspace, quotient space
-/
noncomputable section
open scoped Classical
open Topology TopologicalSpace Set Filter Function
universe u v
variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*}
section Constructions
instance instTopologicalSpaceSubtype {p : X → Prop} [t : TopologicalSpace X] :
TopologicalSpace (Subtype p) :=
induced (↑) t
instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) :=
coinduced (Quot.mk r) t
instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] :
TopologicalSpace (Quotient s) :=
coinduced Quotient.mk' t
instance instTopologicalSpaceProd [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] :
TopologicalSpace (X × Y) :=
induced Prod.fst t₁ ⊓ induced Prod.snd t₂
instance instTopologicalSpaceSum [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] :
TopologicalSpace (X ⊕ Y) :=
coinduced Sum.inl t₁ ⊔ coinduced Sum.inr t₂
instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] :
TopologicalSpace (Sigma X) :=
⨆ i, coinduced (Sigma.mk i) (t₂ i)
instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] :
TopologicalSpace ((i : ι) → Y i) :=
⨅ i, induced (fun f => f i) (t₂ i)
#align Pi.topological_space Pi.topologicalSpace
instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) :=
t.induced ULift.down
#align ulift.topological_space ULift.topologicalSpace
/-!
### `Additive`, `Multiplicative`
The topology on those type synonyms is inherited without change.
-/
section
variable [TopologicalSpace X]
open Additive Multiplicative
instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X›
instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X›
instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X›
instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X›
theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id
#align continuous_of_mul continuous_ofMul
theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id
#align continuous_to_mul continuous_toMul
theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id
#align continuous_of_add continuous_ofAdd
theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id
#align continuous_to_add continuous_toAdd
theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id
#align is_open_map_of_mul isOpenMap_ofMul
theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id
#align is_open_map_to_mul isOpenMap_toMul
theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id
#align is_open_map_of_add isOpenMap_ofAdd
theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id
#align is_open_map_to_add isOpenMap_toAdd
theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id
#align is_closed_map_of_mul isClosedMap_ofMul
theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id
#align is_closed_map_to_mul isClosedMap_toMul
theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id
#align is_closed_map_of_add isClosedMap_ofAdd
theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id
#align is_closed_map_to_add isClosedMap_toAdd
theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl
#align nhds_of_mul nhds_ofMul
theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl
#align nhds_of_add nhds_ofAdd
theorem nhds_toMul (x : Additive X) : 𝓝 (toMul x) = map toMul (𝓝 x) := rfl
#align nhds_to_mul nhds_toMul
theorem nhds_toAdd (x : Multiplicative X) : 𝓝 (toAdd x) = map toAdd (𝓝 x) := rfl
#align nhds_to_add nhds_toAdd
end
/-!
### Order dual
The topology on this type synonym is inherited without change.
-/
section
variable [TopologicalSpace X]
open OrderDual
instance : TopologicalSpace Xᵒᵈ := ‹TopologicalSpace X›
instance [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹DiscreteTopology X›
theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id
#align continuous_to_dual continuous_toDual
theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id
#align continuous_of_dual continuous_ofDual
theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id
#align is_open_map_to_dual isOpenMap_toDual
theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id
#align is_open_map_of_dual isOpenMap_ofDual
theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id
#align is_closed_map_to_dual isClosedMap_toDual
theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id
#align is_closed_map_of_dual isClosedMap_ofDual
theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl
#align nhds_to_dual nhds_toDual
theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl
#align nhds_of_dual nhds_ofDual
end
theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s}
{x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x :=
preimage_nhds_coinduced hs
#align quotient.preimage_mem_nhds Quotient.preimage_mem_nhds
/-- The image of a dense set under `Quotient.mk'` is a dense set. -/
theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) :
Dense (Quotient.mk' '' s) :=
Quotient.surjective_Quotient_mk''.denseRange.dense_image continuous_coinduced_rng H
#align dense.quotient Dense.quotient
/-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/
theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) :
DenseRange (Quotient.mk' ∘ f) :=
Quotient.surjective_Quotient_mk''.denseRange.comp hf continuous_coinduced_rng
#align dense_range.quotient DenseRange.quotient
theorem continuous_map_of_le {α : Type*} [TopologicalSpace α]
{s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) :=
continuous_coinduced_rng
theorem continuous_map_sInf {α : Type*} [TopologicalSpace α]
{S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) :=
continuous_coinduced_rng
instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) :=
⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩
instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X]
[hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) :=
⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩
#align sum.discrete_topology Sum.discreteTopology
instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)]
[h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) :=
⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩
#align sigma.discrete_topology Sigma.discreteTopology
section Top
variable [TopologicalSpace X]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) :
t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t :=
mem_nhds_induced _ x t
#align mem_nhds_subtype mem_nhds_subtype
theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) :=
nhds_induced _ x
#align nhds_subtype nhds_subtype
theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} :
𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by
rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal,
nhds_induced]
#align nhds_within_subtype_eq_bot_iff nhdsWithin_subtype_eq_bot_iff
theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} :
𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by
rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton,
Subtype.coe_injective.preimage_image]
#align nhds_ne_subtype_eq_bot_iff nhds_ne_subtype_eq_bot_iff
theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} :
(𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by
rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff]
#align nhds_ne_subtype_ne_bot_iff nhds_ne_subtype_neBot_iff
| Mathlib/Topology/Constructions.lean | 260 | 262 | theorem discreteTopology_subtype_iff {S : Set X} :
DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by |
simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff]
|
/-
Copyright (c) 2020 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Data.Countable.Basic
import Mathlib.Data.Set.Image
import Mathlib.Data.Set.Subsingleton
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.GroupTheory.Subgroup.Centralizer
#align_import group_theory.subgroup.zpowers from "leanprover-community/mathlib"@"4be589053caf347b899a494da75410deb55fb3ef"
/-!
# Subgroups generated by an element
## Tags
subgroup, subgroups
-/
variable {G : Type*} [Group G]
variable {A : Type*} [AddGroup A]
variable {N : Type*} [Group N]
namespace Subgroup
/-- The subgroup generated by an element. -/
def zpowers (g : G) : Subgroup G :=
Subgroup.copy (zpowersHom G g).range (Set.range (g ^ · : ℤ → G)) rfl
#align subgroup.zpowers Subgroup.zpowers
theorem mem_zpowers (g : G) : g ∈ zpowers g :=
⟨1, zpow_one _⟩
#align subgroup.mem_zpowers Subgroup.mem_zpowers
theorem coe_zpowers (g : G) : ↑(zpowers g) = Set.range (g ^ · : ℤ → G) :=
rfl
#align subgroup.coe_zpowers Subgroup.coe_zpowers
noncomputable instance decidableMemZPowers {a : G} : DecidablePred (· ∈ Subgroup.zpowers a) :=
Classical.decPred _
#align decidable_zpowers Subgroup.decidableMemZPowers
theorem zpowers_eq_closure (g : G) : zpowers g = closure {g} := by
ext
exact mem_closure_singleton.symm
#align subgroup.zpowers_eq_closure Subgroup.zpowers_eq_closure
theorem range_zpowersHom (g : G) : (zpowersHom G g).range = zpowers g :=
rfl
#align subgroup.range_zpowers_hom Subgroup.range_zpowersHom
theorem mem_zpowers_iff {g h : G} : h ∈ zpowers g ↔ ∃ k : ℤ, g ^ k = h :=
Iff.rfl
#align subgroup.mem_zpowers_iff Subgroup.mem_zpowers_iff
theorem zpow_mem_zpowers (g : G) (k : ℤ) : g ^ k ∈ zpowers g :=
mem_zpowers_iff.mpr ⟨k, rfl⟩
#align subgroup.zpow_mem_zpowers Subgroup.zpow_mem_zpowers
theorem npow_mem_zpowers (g : G) (k : ℕ) : g ^ k ∈ zpowers g :=
zpow_natCast g k ▸ zpow_mem_zpowers g k
#align subgroup.npow_mem_zpowers Subgroup.npow_mem_zpowers
theorem forall_zpowers {x : G} {p : zpowers x → Prop} : (∀ g, p g) ↔ ∀ m : ℤ, p ⟨x ^ m, m, rfl⟩ :=
Set.forall_subtype_range_iff
#align subgroup.forall_zpowers Subgroup.forall_zpowers
theorem exists_zpowers {x : G} {p : zpowers x → Prop} : (∃ g, p g) ↔ ∃ m : ℤ, p ⟨x ^ m, m, rfl⟩ :=
Set.exists_subtype_range_iff
#align subgroup.exists_zpowers Subgroup.exists_zpowers
theorem forall_mem_zpowers {x : G} {p : G → Prop} : (∀ g ∈ zpowers x, p g) ↔ ∀ m : ℤ, p (x ^ m) :=
Set.forall_mem_range
#align subgroup.forall_mem_zpowers Subgroup.forall_mem_zpowers
theorem exists_mem_zpowers {x : G} {p : G → Prop} : (∃ g ∈ zpowers x, p g) ↔ ∃ m : ℤ, p (x ^ m) :=
Set.exists_range_iff
#align subgroup.exists_mem_zpowers Subgroup.exists_mem_zpowers
instance (a : G) : Countable (zpowers a) :=
((zpowersHom G a).rangeRestrict_surjective.comp Multiplicative.ofAdd.surjective).countable
end Subgroup
namespace AddSubgroup
/-- The subgroup generated by an element. -/
def zmultiples (a : A) : AddSubgroup A :=
AddSubgroup.copy (zmultiplesHom A a).range (Set.range ((· • a) : ℤ → A)) rfl
#align add_subgroup.zmultiples AddSubgroup.zmultiples
@[simp]
theorem range_zmultiplesHom (a : A) : (zmultiplesHom A a).range = zmultiples a :=
rfl
#align add_subgroup.range_zmultiples_hom AddSubgroup.range_zmultiplesHom
attribute [to_additive existing] Subgroup.zpowers
attribute [to_additive (attr := simp)] Subgroup.mem_zpowers
#align add_subgroup.mem_zmultiples AddSubgroup.mem_zmultiples
attribute [to_additive (attr := norm_cast)] Subgroup.coe_zpowers
attribute [to_additive] Subgroup.decidableMemZPowers
#align decidable_zmultiples AddSubgroup.decidableMemZMultiples
attribute [to_additive] Subgroup.zpowers_eq_closure
#align add_subgroup.zmultiples_eq_closure AddSubgroup.zmultiples_eq_closure
attribute [to_additive existing (attr := simp)]
Subgroup.range_zpowersHom
attribute [to_additive] Subgroup.mem_zpowers_iff
#align add_subgroup.mem_zmultiples_iff AddSubgroup.mem_zmultiples_iff
attribute [to_additive (attr := simp)] Subgroup.zpow_mem_zpowers
#align add_subgroup.zsmul_mem_zmultiples AddSubgroup.zsmul_mem_zmultiples
attribute [to_additive (attr := simp)] Subgroup.npow_mem_zpowers
#align add_subgroup.nsmul_mem_zmultiples AddSubgroup.nsmul_mem_zmultiples
-- Porting note: increasing simp priority. Better lemma than `Subtype.forall`
attribute [to_additive (attr := simp 1100)] Subgroup.forall_zpowers
#align add_subgroup.forall_zmultiples AddSubgroup.forall_zmultiples
attribute [to_additive] Subgroup.forall_mem_zpowers
#align add_subgroup.forall_mem_zmultiples AddSubgroup.forall_mem_zmultiples
-- Porting note: increasing simp priority. Better lemma than `Subtype.exists`
attribute [to_additive (attr := simp 1100)] Subgroup.exists_zpowers
#align add_subgroup.exists_zmultiples AddSubgroup.exists_zmultiples
attribute [to_additive] Subgroup.exists_mem_zpowers
#align add_subgroup.exists_mem_zmultiples AddSubgroup.exists_mem_zmultiples
instance (a : A) : Countable (zmultiples a) :=
(zmultiplesHom A a).rangeRestrict_surjective.countable
section Ring
variable {R : Type*} [Ring R] (r : R) (k : ℤ)
@[simp]
theorem intCast_mul_mem_zmultiples : ↑(k : ℤ) * r ∈ zmultiples r := by
simpa only [← zsmul_eq_mul] using zsmul_mem_zmultiples r k
#align add_subgroup.int_cast_mul_mem_zmultiples AddSubgroup.intCast_mul_mem_zmultiples
@[deprecated (since := "2024-04-17")]
alias int_cast_mul_mem_zmultiples := intCast_mul_mem_zmultiples
@[simp]
theorem intCast_mem_zmultiples_one : ↑(k : ℤ) ∈ zmultiples (1 : R) :=
mem_zmultiples_iff.mp ⟨k, by simp⟩
#align add_subgroup.int_cast_mem_zmultiples_one AddSubgroup.intCast_mem_zmultiples_one
@[deprecated (since := "2024-04-17")]
alias int_cast_mem_zmultiples_one := intCast_mem_zmultiples_one
end Ring
end AddSubgroup
@[simp] lemma Int.range_castAddHom {A : Type*} [AddGroupWithOne A] :
(Int.castAddHom A).range = AddSubgroup.zmultiples 1 := by
ext a
simp_rw [AddMonoidHom.mem_range, Int.coe_castAddHom, AddSubgroup.mem_zmultiples_iff, zsmul_one]
@[to_additive (attr := simp)]
theorem MonoidHom.map_zpowers (f : G →* N) (x : G) :
(Subgroup.zpowers x).map f = Subgroup.zpowers (f x) := by
rw [Subgroup.zpowers_eq_closure, Subgroup.zpowers_eq_closure, f.map_closure, Set.image_singleton]
#align monoid_hom.map_zpowers MonoidHom.map_zpowers
#align add_monoid_hom.map_zmultiples AddMonoidHom.map_zmultiples
theorem Int.mem_zmultiples_iff {a b : ℤ} : b ∈ AddSubgroup.zmultiples a ↔ a ∣ b :=
exists_congr fun k => by rw [mul_comm, eq_comm, ← smul_eq_mul]
#align int.mem_zmultiples_iff Int.mem_zmultiples_iff
@[simp]
lemma Int.zmultiples_one : AddSubgroup.zmultiples (1 : ℤ) = ⊤ := by
ext z
simpa only [AddSubgroup.mem_top, iff_true] using ⟨z, zsmul_int_one z⟩
theorem ofMul_image_zpowers_eq_zmultiples_ofMul {x : G} :
Additive.ofMul '' (Subgroup.zpowers x : Set G) = AddSubgroup.zmultiples (Additive.ofMul x) := by
ext y
constructor
· rintro ⟨z, ⟨m, hm⟩, hz2⟩
use m
simp only at *
rwa [← ofMul_zpow, hm]
· rintro ⟨n, hn⟩
refine ⟨x ^ n, ⟨n, rfl⟩, ?_⟩
rwa [ofMul_zpow]
#align of_mul_image_zpowers_eq_zmultiples_of_mul ofMul_image_zpowers_eq_zmultiples_ofMul
theorem ofAdd_image_zmultiples_eq_zpowers_ofAdd {x : A} :
Multiplicative.ofAdd '' (AddSubgroup.zmultiples x : Set A) =
Subgroup.zpowers (Multiplicative.ofAdd x) := by
symm
rw [Equiv.eq_image_iff_symm_image_eq]
exact ofMul_image_zpowers_eq_zmultiples_ofMul
#align of_add_image_zmultiples_eq_zpowers_of_add ofAdd_image_zmultiples_eq_zpowers_ofAdd
namespace Subgroup
variable {s : Set G} {g : G}
@[to_additive]
instance zpowers_isCommutative (g : G) : (zpowers g).IsCommutative :=
⟨⟨fun ⟨_, _, h₁⟩ ⟨_, _, h₂⟩ => by
rw [Subtype.ext_iff, coe_mul, coe_mul, Subtype.coe_mk, Subtype.coe_mk, ← h₁, ← h₂,
zpow_mul_comm]⟩⟩
#align subgroup.zpowers_is_commutative Subgroup.zpowers_isCommutative
#align add_subgroup.zmultiples_is_commutative AddSubgroup.zmultiples_isCommutative
@[to_additive (attr := simp)]
theorem zpowers_le {g : G} {H : Subgroup G} : zpowers g ≤ H ↔ g ∈ H := by
rw [zpowers_eq_closure, closure_le, Set.singleton_subset_iff, SetLike.mem_coe]
#align subgroup.zpowers_le Subgroup.zpowers_le
#align add_subgroup.zmultiples_le AddSubgroup.zmultiples_le
alias ⟨_, zpowers_le_of_mem⟩ := zpowers_le
#align subgroup.zpowers_le_of_mem Subgroup.zpowers_le_of_mem
alias ⟨_, _root_.AddSubgroup.zmultiples_le_of_mem⟩ := AddSubgroup.zmultiples_le
#align add_subgroup.zmultiples_le_of_mem AddSubgroup.zmultiples_le_of_mem
attribute [to_additive existing] zpowers_le_of_mem
@[to_additive (attr := simp)]
theorem zpowers_eq_bot {g : G} : zpowers g = ⊥ ↔ g = 1 := by rw [eq_bot_iff, zpowers_le, mem_bot]
#align subgroup.zpowers_eq_bot Subgroup.zpowers_eq_bot
#align add_subgroup.zmultiples_eq_bot AddSubgroup.zmultiples_eq_bot
@[to_additive]
theorem zpowers_ne_bot : zpowers g ≠ ⊥ ↔ g ≠ 1 :=
zpowers_eq_bot.not
#align subgroup.zpowers_ne_bot Subgroup.zpowers_ne_bot
#align add_subgroup.zmultiples_ne_bot AddSubgroup.zmultiples_ne_bot
@[to_additive (attr := simp)]
theorem zpowers_one_eq_bot : Subgroup.zpowers (1 : G) = ⊥ :=
Subgroup.zpowers_eq_bot.mpr rfl
#align subgroup.zpowers_one_eq_bot Subgroup.zpowers_one_eq_bot
#align add_subgroup.zmultiples_zero_eq_bot AddSubgroup.zmultiples_zero_eq_bot
@[to_additive]
theorem centralizer_closure (S : Set G) :
centralizer (closure S : Set G) = ⨅ g ∈ S, centralizer (zpowers g : Set G) :=
le_antisymm
(le_iInf fun _ => le_iInf fun hg => centralizer_le <| zpowers_le.2 <| subset_closure hg) <|
le_centralizer_iff.1 <|
(closure_le _).2 fun g =>
SetLike.mem_coe.2 ∘ zpowers_le.1 ∘ le_centralizer_iff.1 ∘ iInf_le_of_le g ∘ iInf_le _
#align subgroup.centralizer_closure Subgroup.centralizer_closure
#align add_subgroup.centralizer_closure AddSubgroup.centralizer_closure
@[to_additive]
| Mathlib/Algebra/Group/Subgroup/ZPowers.lean | 264 | 266 | theorem center_eq_iInf (S : Set G) (hS : closure S = ⊤) :
center G = ⨅ g ∈ S, centralizer (zpowers g) := by |
rw [← centralizer_univ, ← coe_top, ← hS, centralizer_closure]
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Analysis.Convex.Between
import Mathlib.Analysis.Convex.Normed
import Mathlib.Analysis.Normed.Group.AddTorsor
#align_import analysis.convex.side from "leanprover-community/mathlib"@"a63928c34ec358b5edcda2bf7513c50052a5230f"
/-!
# Sides of affine subspaces
This file defines notions of two points being on the same or opposite sides of an affine subspace.
## Main definitions
* `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine
subspace `s`.
* `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine
subspace `s`.
* `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine
subspace `s`.
* `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine
subspace `s`.
-/
variable {R V V' P P' : Type*}
open AffineEquiv AffineMap
namespace AffineSubspace
section StrictOrderedCommRing
variable [StrictOrderedCommRing R] [AddCommGroup V] [Module R V] [AddTorsor V P]
variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
/-- The points `x` and `y` are weakly on the same side of `s`. -/
def WSameSide (s : AffineSubspace R P) (x y : P) : Prop :=
∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂)
#align affine_subspace.w_same_side AffineSubspace.WSameSide
/-- The points `x` and `y` are strictly on the same side of `s`. -/
def SSameSide (s : AffineSubspace R P) (x y : P) : Prop :=
s.WSameSide x y ∧ x ∉ s ∧ y ∉ s
#align affine_subspace.s_same_side AffineSubspace.SSameSide
/-- The points `x` and `y` are weakly on opposite sides of `s`. -/
def WOppSide (s : AffineSubspace R P) (x y : P) : Prop :=
∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y)
#align affine_subspace.w_opp_side AffineSubspace.WOppSide
/-- The points `x` and `y` are strictly on opposite sides of `s`. -/
def SOppSide (s : AffineSubspace R P) (x y : P) : Prop :=
s.WOppSide x y ∧ x ∉ s ∧ y ∉ s
#align affine_subspace.s_opp_side AffineSubspace.SOppSide
theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') :
(s.map f).WSameSide (f x) (f y) := by
rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩
simp_rw [← linearMap_vsub]
exact h.map f.linear
#align affine_subspace.w_same_side.map AffineSubspace.WSameSide.map
theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩
rw [mem_map] at hfp₁ hfp₂
rcases hfp₁ with ⟨p₁, hp₁, rfl⟩
rcases hfp₂ with ⟨p₂, hp₂, rfl⟩
refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩
simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h
exact h
#align function.injective.w_same_side_map_iff Function.Injective.wSameSide_map_iff
theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by
simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf]
#align function.injective.s_same_side_map_iff Function.Injective.sSameSide_map_iff
@[simp]
theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y :=
(show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff
#align affine_equiv.w_same_side_map_iff AffineEquiv.wSameSide_map_iff
@[simp]
theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y :=
(show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff
#align affine_equiv.s_same_side_map_iff AffineEquiv.sSameSide_map_iff
theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') :
(s.map f).WOppSide (f x) (f y) := by
rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩
simp_rw [← linearMap_vsub]
exact h.map f.linear
#align affine_subspace.w_opp_side.map AffineSubspace.WOppSide.map
theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩
rw [mem_map] at hfp₁ hfp₂
rcases hfp₁ with ⟨p₁, hp₁, rfl⟩
rcases hfp₂ with ⟨p₂, hp₂, rfl⟩
refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩
simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h
exact h
#align function.injective.w_opp_side_map_iff Function.Injective.wOppSide_map_iff
theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by
simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf]
#align function.injective.s_opp_side_map_iff Function.Injective.sOppSide_map_iff
@[simp]
theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y :=
(show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff
#align affine_equiv.w_opp_side_map_iff AffineEquiv.wOppSide_map_iff
@[simp]
theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y :=
(show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff
#align affine_equiv.s_opp_side_map_iff AffineEquiv.sOppSide_map_iff
theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) :
(s : Set P).Nonempty :=
⟨h.choose, h.choose_spec.left⟩
#align affine_subspace.w_same_side.nonempty AffineSubspace.WSameSide.nonempty
theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) :
(s : Set P).Nonempty :=
⟨h.1.choose, h.1.choose_spec.left⟩
#align affine_subspace.s_same_side.nonempty AffineSubspace.SSameSide.nonempty
theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) :
(s : Set P).Nonempty :=
⟨h.choose, h.choose_spec.left⟩
#align affine_subspace.w_opp_side.nonempty AffineSubspace.WOppSide.nonempty
theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) :
(s : Set P).Nonempty :=
⟨h.1.choose, h.1.choose_spec.left⟩
#align affine_subspace.s_opp_side.nonempty AffineSubspace.SOppSide.nonempty
theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) :
s.WSameSide x y :=
h.1
#align affine_subspace.s_same_side.w_same_side AffineSubspace.SSameSide.wSameSide
theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x ∉ s :=
h.2.1
#align affine_subspace.s_same_side.left_not_mem AffineSubspace.SSameSide.left_not_mem
theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y ∉ s :=
h.2.2
#align affine_subspace.s_same_side.right_not_mem AffineSubspace.SSameSide.right_not_mem
theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) :
s.WOppSide x y :=
h.1
#align affine_subspace.s_opp_side.w_opp_side AffineSubspace.SOppSide.wOppSide
theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x ∉ s :=
h.2.1
#align affine_subspace.s_opp_side.left_not_mem AffineSubspace.SOppSide.left_not_mem
theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y ∉ s :=
h.2.2
#align affine_subspace.s_opp_side.right_not_mem AffineSubspace.SOppSide.right_not_mem
theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x :=
⟨fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩,
fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩⟩
#align affine_subspace.w_same_side_comm AffineSubspace.wSameSide_comm
alias ⟨WSameSide.symm, _⟩ := wSameSide_comm
#align affine_subspace.w_same_side.symm AffineSubspace.WSameSide.symm
| Mathlib/Analysis/Convex/Side.lean | 194 | 195 | theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by |
rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x ∉ s)]
|
/-
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, Hunter Monroe
-/
import Mathlib.Combinatorics.SimpleGraph.Init
import Mathlib.Data.Rel
import Mathlib.Data.Set.Finite
import Mathlib.Data.Sym.Sym2
#align_import combinatorics.simple_graph.basic from "leanprover-community/mathlib"@"3365b20c2ffa7c35e47e5209b89ba9abdddf3ffe"
/-!
# Simple graphs
This module defines simple graphs on a vertex type `V` as an irreflexive symmetric relation.
## Main definitions
* `SimpleGraph` is a structure for symmetric, irreflexive relations
* `SimpleGraph.neighborSet` is the `Set` of vertices adjacent to a given vertex
* `SimpleGraph.commonNeighbors` is the intersection of the neighbor sets of two given vertices
* `SimpleGraph.incidenceSet` is the `Set` of edges containing a given vertex
* `CompleteAtomicBooleanAlgebra` instance: Under the subgraph relation, `SimpleGraph` forms a
`CompleteAtomicBooleanAlgebra`. In other words, this is the complete lattice of spanning subgraphs
of the complete graph.
## Todo
* This is the simplest notion of an unoriented graph. This should
eventually fit into a more complete combinatorics hierarchy which
includes multigraphs and directed graphs. We begin with simple graphs
in order to start learning what the combinatorics hierarchy should
look like.
-/
-- Porting note: using `aesop` for automation
-- Porting note: These attributes are needed to use `aesop` as a replacement for `obviously`
attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Symmetric
attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Irreflexive
-- Porting note: a thin wrapper around `aesop` for graph lemmas, modelled on `aesop_cat`
/--
A variant of the `aesop` tactic for use in the graph library. Changes relative
to standard `aesop`:
- We use the `SimpleGraph` rule set in addition to the default rule sets.
- We instruct Aesop's `intro` rule to unfold with `default` transparency.
- We instruct Aesop to fail if it can't fully solve the goal. This allows us to
use `aesop_graph` for auto-params.
-/
macro (name := aesop_graph) "aesop_graph" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c*
(config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `SimpleGraph):ident]))
/--
Use `aesop_graph?` to pass along a `Try this` suggestion when using `aesop_graph`
-/
macro (name := aesop_graph?) "aesop_graph?" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c*
(config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `SimpleGraph):ident]))
/--
A variant of `aesop_graph` which does not fail if it is unable to solve the
goal. Use this only for exploration! Nonterminal Aesop is even worse than
nonterminal `simp`.
-/
macro (name := aesop_graph_nonterminal) "aesop_graph_nonterminal" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c*
(config := { introsTransparency? := some .default, warnOnNonterminal := false })
(rule_sets := [$(Lean.mkIdent `SimpleGraph):ident]))
open Finset Function
universe u v w
/-- A simple graph is an irreflexive symmetric relation `Adj` on a vertex type `V`.
The relation describes which pairs of vertices are adjacent.
There is exactly one edge for every pair of adjacent vertices;
see `SimpleGraph.edgeSet` for the corresponding edge set.
-/
@[ext, aesop safe constructors (rule_sets := [SimpleGraph])]
structure SimpleGraph (V : Type u) where
/-- The adjacency relation of a simple graph. -/
Adj : V → V → Prop
symm : Symmetric Adj := by aesop_graph
loopless : Irreflexive Adj := by aesop_graph
#align simple_graph SimpleGraph
-- Porting note: changed `obviously` to `aesop` in the `structure`
initialize_simps_projections SimpleGraph (Adj → adj)
/-- Constructor for simple graphs using a symmetric irreflexive boolean function. -/
@[simps]
def SimpleGraph.mk' {V : Type u} :
{adj : V → V → Bool // (∀ x y, adj x y = adj y x) ∧ (∀ x, ¬ adj x x)} ↪ SimpleGraph V where
toFun x := ⟨fun v w ↦ x.1 v w, fun v w ↦ by simp [x.2.1], fun v ↦ by simp [x.2.2]⟩
inj' := by
rintro ⟨adj, _⟩ ⟨adj', _⟩
simp only [mk.injEq, Subtype.mk.injEq]
intro h
funext v w
simpa [Bool.coe_iff_coe] using congr_fun₂ h v w
/-- We can enumerate simple graphs by enumerating all functions `V → V → Bool`
and filtering on whether they are symmetric and irreflexive. -/
instance {V : Type u} [Fintype V] [DecidableEq V] : Fintype (SimpleGraph V) where
elems := Finset.univ.map SimpleGraph.mk'
complete := by
classical
rintro ⟨Adj, hs, hi⟩
simp only [mem_map, mem_univ, true_and, Subtype.exists, Bool.not_eq_true]
refine ⟨fun v w ↦ Adj v w, ⟨?_, ?_⟩, ?_⟩
· simp [hs.iff]
· intro v; simp [hi v]
· ext
simp
/-- Construct the simple graph induced by the given relation. It
symmetrizes the relation and makes it irreflexive. -/
def SimpleGraph.fromRel {V : Type u} (r : V → V → Prop) : SimpleGraph V where
Adj a b := a ≠ b ∧ (r a b ∨ r b a)
symm := fun _ _ ⟨hn, hr⟩ => ⟨hn.symm, hr.symm⟩
loopless := fun _ ⟨hn, _⟩ => hn rfl
#align simple_graph.from_rel SimpleGraph.fromRel
@[simp]
theorem SimpleGraph.fromRel_adj {V : Type u} (r : V → V → Prop) (v w : V) :
(SimpleGraph.fromRel r).Adj v w ↔ v ≠ w ∧ (r v w ∨ r w v) :=
Iff.rfl
#align simple_graph.from_rel_adj SimpleGraph.fromRel_adj
-- Porting note: attributes needed for `completeGraph`
attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.symm
attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.irrefl
/-- The complete graph on a type `V` is the simple graph with all pairs of distinct vertices
adjacent. In `Mathlib`, this is usually referred to as `⊤`. -/
def completeGraph (V : Type u) : SimpleGraph V where Adj := Ne
#align complete_graph completeGraph
/-- The graph with no edges on a given vertex type `V`. `Mathlib` prefers the notation `⊥`. -/
def emptyGraph (V : Type u) : SimpleGraph V where Adj _ _ := False
#align empty_graph emptyGraph
/-- Two vertices are adjacent in the complete bipartite graph on two vertex types
if and only if they are not from the same side.
Any bipartite graph may be regarded as a subgraph of one of these. -/
@[simps]
def completeBipartiteGraph (V W : Type*) : SimpleGraph (Sum V W) where
Adj v w := v.isLeft ∧ w.isRight ∨ v.isRight ∧ w.isLeft
symm v w := by cases v <;> cases w <;> simp
loopless v := by cases v <;> simp
#align complete_bipartite_graph completeBipartiteGraph
namespace SimpleGraph
variable {ι : Sort*} {V : Type u} (G : SimpleGraph V) {a b c u v w : V} {e : Sym2 V}
@[simp]
protected theorem irrefl {v : V} : ¬G.Adj v v :=
G.loopless v
#align simple_graph.irrefl SimpleGraph.irrefl
theorem adj_comm (u v : V) : G.Adj u v ↔ G.Adj v u :=
⟨fun x => G.symm x, fun x => G.symm x⟩
#align simple_graph.adj_comm SimpleGraph.adj_comm
@[symm]
theorem adj_symm (h : G.Adj u v) : G.Adj v u :=
G.symm h
#align simple_graph.adj_symm SimpleGraph.adj_symm
theorem Adj.symm {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Adj v u :=
G.symm h
#align simple_graph.adj.symm SimpleGraph.Adj.symm
theorem ne_of_adj (h : G.Adj a b) : a ≠ b := by
rintro rfl
exact G.irrefl h
#align simple_graph.ne_of_adj SimpleGraph.ne_of_adj
protected theorem Adj.ne {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : a ≠ b :=
G.ne_of_adj h
#align simple_graph.adj.ne SimpleGraph.Adj.ne
protected theorem Adj.ne' {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : b ≠ a :=
h.ne.symm
#align simple_graph.adj.ne' SimpleGraph.Adj.ne'
theorem ne_of_adj_of_not_adj {v w x : V} (h : G.Adj v x) (hn : ¬G.Adj w x) : v ≠ w := fun h' =>
hn (h' ▸ h)
#align simple_graph.ne_of_adj_of_not_adj SimpleGraph.ne_of_adj_of_not_adj
theorem adj_injective : Injective (Adj : SimpleGraph V → V → V → Prop) :=
SimpleGraph.ext
#align simple_graph.adj_injective SimpleGraph.adj_injective
@[simp]
theorem adj_inj {G H : SimpleGraph V} : G.Adj = H.Adj ↔ G = H :=
adj_injective.eq_iff
#align simple_graph.adj_inj SimpleGraph.adj_inj
section Order
/-- The relation that one `SimpleGraph` is a subgraph of another.
Note that this should be spelled `≤`. -/
def IsSubgraph (x y : SimpleGraph V) : Prop :=
∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w
#align simple_graph.is_subgraph SimpleGraph.IsSubgraph
instance : LE (SimpleGraph V) :=
⟨IsSubgraph⟩
@[simp]
theorem isSubgraph_eq_le : (IsSubgraph : SimpleGraph V → SimpleGraph V → Prop) = (· ≤ ·) :=
rfl
#align simple_graph.is_subgraph_eq_le SimpleGraph.isSubgraph_eq_le
/-- The supremum of two graphs `x ⊔ y` has edges where either `x` or `y` have edges. -/
instance : Sup (SimpleGraph V) where
sup x y :=
{ Adj := x.Adj ⊔ y.Adj
symm := fun v w h => by rwa [Pi.sup_apply, Pi.sup_apply, x.adj_comm, y.adj_comm] }
@[simp]
theorem sup_adj (x y : SimpleGraph V) (v w : V) : (x ⊔ y).Adj v w ↔ x.Adj v w ∨ y.Adj v w :=
Iff.rfl
#align simple_graph.sup_adj SimpleGraph.sup_adj
/-- The infimum of two graphs `x ⊓ y` has edges where both `x` and `y` have edges. -/
instance : Inf (SimpleGraph V) where
inf x y :=
{ Adj := x.Adj ⊓ y.Adj
symm := fun v w h => by rwa [Pi.inf_apply, Pi.inf_apply, x.adj_comm, y.adj_comm] }
@[simp]
theorem inf_adj (x y : SimpleGraph V) (v w : V) : (x ⊓ y).Adj v w ↔ x.Adj v w ∧ y.Adj v w :=
Iff.rfl
#align simple_graph.inf_adj SimpleGraph.inf_adj
/-- We define `Gᶜ` to be the `SimpleGraph V` such that no two adjacent vertices in `G`
are adjacent in the complement, and every nonadjacent pair of vertices is adjacent
(still ensuring that vertices are not adjacent to themselves). -/
instance hasCompl : HasCompl (SimpleGraph V) where
compl G :=
{ Adj := fun v w => v ≠ w ∧ ¬G.Adj v w
symm := fun v w ⟨hne, _⟩ => ⟨hne.symm, by rwa [adj_comm]⟩
loopless := fun v ⟨hne, _⟩ => (hne rfl).elim }
@[simp]
theorem compl_adj (G : SimpleGraph V) (v w : V) : Gᶜ.Adj v w ↔ v ≠ w ∧ ¬G.Adj v w :=
Iff.rfl
#align simple_graph.compl_adj SimpleGraph.compl_adj
/-- The difference of two graphs `x \ y` has the edges of `x` with the edges of `y` removed. -/
instance sdiff : SDiff (SimpleGraph V) where
sdiff x y :=
{ Adj := x.Adj \ y.Adj
symm := fun v w h => by change x.Adj w v ∧ ¬y.Adj w v; rwa [x.adj_comm, y.adj_comm] }
@[simp]
theorem sdiff_adj (x y : SimpleGraph V) (v w : V) : (x \ y).Adj v w ↔ x.Adj v w ∧ ¬y.Adj v w :=
Iff.rfl
#align simple_graph.sdiff_adj SimpleGraph.sdiff_adj
instance supSet : SupSet (SimpleGraph V) where
sSup s :=
{ Adj := fun a b => ∃ G ∈ s, Adj G a b
symm := fun a b => Exists.imp fun _ => And.imp_right Adj.symm
loopless := by
rintro a ⟨G, _, ha⟩
exact ha.ne rfl }
instance infSet : InfSet (SimpleGraph V) where
sInf s :=
{ Adj := fun a b => (∀ ⦃G⦄, G ∈ s → Adj G a b) ∧ a ≠ b
symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) Ne.symm
loopless := fun _ h => h.2 rfl }
@[simp]
theorem sSup_adj {s : Set (SimpleGraph V)} {a b : V} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b :=
Iff.rfl
#align simple_graph.Sup_adj SimpleGraph.sSup_adj
@[simp]
theorem sInf_adj {s : Set (SimpleGraph V)} : (sInf s).Adj a b ↔ (∀ G ∈ s, Adj G a b) ∧ a ≠ b :=
Iff.rfl
#align simple_graph.Inf_adj SimpleGraph.sInf_adj
@[simp]
theorem iSup_adj {f : ι → SimpleGraph V} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup]
#align simple_graph.supr_adj SimpleGraph.iSup_adj
@[simp]
theorem iInf_adj {f : ι → SimpleGraph V} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ a ≠ b := by
simp [iInf]
#align simple_graph.infi_adj SimpleGraph.iInf_adj
theorem sInf_adj_of_nonempty {s : Set (SimpleGraph V)} (hs : s.Nonempty) :
(sInf s).Adj a b ↔ ∀ G ∈ s, Adj G a b :=
sInf_adj.trans <|
and_iff_left_of_imp <| by
obtain ⟨G, hG⟩ := hs
exact fun h => (h _ hG).ne
#align simple_graph.Inf_adj_of_nonempty SimpleGraph.sInf_adj_of_nonempty
theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → SimpleGraph V} :
(⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by
rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _), Set.forall_mem_range]
#align simple_graph.infi_adj_of_nonempty SimpleGraph.iInf_adj_of_nonempty
/-- For graphs `G`, `H`, `G ≤ H` iff `∀ a b, G.Adj a b → H.Adj a b`. -/
instance distribLattice : DistribLattice (SimpleGraph V) :=
{ show DistribLattice (SimpleGraph V) from
adj_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with
le := fun G H => ∀ ⦃a b⦄, G.Adj a b → H.Adj a b }
instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (SimpleGraph V) :=
{ SimpleGraph.distribLattice with
le := (· ≤ ·)
sup := (· ⊔ ·)
inf := (· ⊓ ·)
compl := HasCompl.compl
sdiff := (· \ ·)
top := completeGraph V
bot := emptyGraph V
le_top := fun x v w h => x.ne_of_adj h
bot_le := fun x v w h => h.elim
sdiff_eq := fun x y => by
ext v w
refine ⟨fun h => ⟨h.1, ⟨?_, h.2⟩⟩, fun h => ⟨h.1, h.2.2⟩⟩
rintro rfl
exact x.irrefl h.1
inf_compl_le_bot := fun G v w h => False.elim <| h.2.2 h.1
top_le_sup_compl := fun G v w hvw => by
by_cases h : G.Adj v w
· exact Or.inl h
· exact Or.inr ⟨hvw, h⟩
sSup := sSup
le_sSup := fun s G hG a b hab => ⟨G, hG, hab⟩
sSup_le := fun s G hG a b => by
rintro ⟨H, hH, hab⟩
exact hG _ hH hab
sInf := sInf
sInf_le := fun s G hG a b hab => hab.1 hG
le_sInf := fun s G hG a b hab => ⟨fun H hH => hG _ hH hab, hab.ne⟩
iInf_iSup_eq := fun f => by ext; simp [Classical.skolem] }
@[simp]
theorem top_adj (v w : V) : (⊤ : SimpleGraph V).Adj v w ↔ v ≠ w :=
Iff.rfl
#align simple_graph.top_adj SimpleGraph.top_adj
@[simp]
theorem bot_adj (v w : V) : (⊥ : SimpleGraph V).Adj v w ↔ False :=
Iff.rfl
#align simple_graph.bot_adj SimpleGraph.bot_adj
@[simp]
theorem completeGraph_eq_top (V : Type u) : completeGraph V = ⊤ :=
rfl
#align simple_graph.complete_graph_eq_top SimpleGraph.completeGraph_eq_top
@[simp]
theorem emptyGraph_eq_bot (V : Type u) : emptyGraph V = ⊥ :=
rfl
#align simple_graph.empty_graph_eq_bot SimpleGraph.emptyGraph_eq_bot
@[simps]
instance (V : Type u) : Inhabited (SimpleGraph V) :=
⟨⊥⟩
instance [Subsingleton V] : Unique (SimpleGraph V) where
default := ⊥
uniq G := by ext a b; have := Subsingleton.elim a b; simp [this]
instance [Nontrivial V] : Nontrivial (SimpleGraph V) :=
⟨⟨⊥, ⊤, fun h ↦ not_subsingleton V ⟨by simpa only [← adj_inj, Function.funext_iff, bot_adj,
top_adj, ne_eq, eq_iff_iff, false_iff, not_not] using h⟩⟩⟩
section Decidable
variable (V) (H : SimpleGraph V) [DecidableRel G.Adj] [DecidableRel H.Adj]
instance Bot.adjDecidable : DecidableRel (⊥ : SimpleGraph V).Adj :=
inferInstanceAs <| DecidableRel fun _ _ => False
#align simple_graph.bot.adj_decidable SimpleGraph.Bot.adjDecidable
instance Sup.adjDecidable : DecidableRel (G ⊔ H).Adj :=
inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∨ H.Adj v w
#align simple_graph.sup.adj_decidable SimpleGraph.Sup.adjDecidable
instance Inf.adjDecidable : DecidableRel (G ⊓ H).Adj :=
inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ H.Adj v w
#align simple_graph.inf.adj_decidable SimpleGraph.Inf.adjDecidable
instance Sdiff.adjDecidable : DecidableRel (G \ H).Adj :=
inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ ¬H.Adj v w
#align simple_graph.sdiff.adj_decidable SimpleGraph.Sdiff.adjDecidable
variable [DecidableEq V]
instance Top.adjDecidable : DecidableRel (⊤ : SimpleGraph V).Adj :=
inferInstanceAs <| DecidableRel fun v w => v ≠ w
#align simple_graph.top.adj_decidable SimpleGraph.Top.adjDecidable
instance Compl.adjDecidable : DecidableRel (Gᶜ.Adj) :=
inferInstanceAs <| DecidableRel fun v w => v ≠ w ∧ ¬G.Adj v w
#align simple_graph.compl.adj_decidable SimpleGraph.Compl.adjDecidable
end Decidable
end Order
/-- `G.support` is the set of vertices that form edges in `G`. -/
def support : Set V :=
Rel.dom G.Adj
#align simple_graph.support SimpleGraph.support
theorem mem_support {v : V} : v ∈ G.support ↔ ∃ w, G.Adj v w :=
Iff.rfl
#align simple_graph.mem_support SimpleGraph.mem_support
theorem support_mono {G G' : SimpleGraph V} (h : G ≤ G') : G.support ⊆ G'.support :=
Rel.dom_mono h
#align simple_graph.support_mono SimpleGraph.support_mono
/-- `G.neighborSet v` is the set of vertices adjacent to `v` in `G`. -/
def neighborSet (v : V) : Set V := {w | G.Adj v w}
#align simple_graph.neighbor_set SimpleGraph.neighborSet
instance neighborSet.memDecidable (v : V) [DecidableRel G.Adj] :
DecidablePred (· ∈ G.neighborSet v) :=
inferInstanceAs <| DecidablePred (Adj G v)
#align simple_graph.neighbor_set.mem_decidable SimpleGraph.neighborSet.memDecidable
section EdgeSet
variable {G₁ G₂ : SimpleGraph V}
/-- The edges of G consist of the unordered pairs of vertices related by
`G.Adj`. This is the order embedding; for the edge set of a particular graph, see
`SimpleGraph.edgeSet`.
The way `edgeSet` is defined is such that `mem_edgeSet` is proved by `Iff.rfl`.
(That is, `s(v, w) ∈ G.edgeSet` is definitionally equal to `G.Adj v w`.)
-/
-- Porting note: We need a separate definition so that dot notation works.
def edgeSetEmbedding (V : Type*) : SimpleGraph V ↪o Set (Sym2 V) :=
OrderEmbedding.ofMapLEIff (fun G => Sym2.fromRel G.symm) fun _ _ =>
⟨fun h a b => @h s(a, b), fun h e => Sym2.ind @h e⟩
/-- `G.edgeSet` is the edge set for `G`.
This is an abbreviation for `edgeSetEmbedding G` that permits dot notation. -/
abbrev edgeSet (G : SimpleGraph V) : Set (Sym2 V) := edgeSetEmbedding V G
#align simple_graph.edge_set SimpleGraph.edgeSetEmbedding
@[simp]
theorem mem_edgeSet : s(v, w) ∈ G.edgeSet ↔ G.Adj v w :=
Iff.rfl
#align simple_graph.mem_edge_set SimpleGraph.mem_edgeSet
theorem not_isDiag_of_mem_edgeSet : e ∈ edgeSet G → ¬e.IsDiag :=
Sym2.ind (fun _ _ => Adj.ne) e
#align simple_graph.not_is_diag_of_mem_edge_set SimpleGraph.not_isDiag_of_mem_edgeSet
theorem edgeSet_inj : G₁.edgeSet = G₂.edgeSet ↔ G₁ = G₂ := (edgeSetEmbedding V).eq_iff_eq
#align simple_graph.edge_set_inj SimpleGraph.edgeSet_inj
@[simp]
theorem edgeSet_subset_edgeSet : edgeSet G₁ ⊆ edgeSet G₂ ↔ G₁ ≤ G₂ :=
(edgeSetEmbedding V).le_iff_le
#align simple_graph.edge_set_subset_edge_set SimpleGraph.edgeSet_subset_edgeSet
@[simp]
theorem edgeSet_ssubset_edgeSet : edgeSet G₁ ⊂ edgeSet G₂ ↔ G₁ < G₂ :=
(edgeSetEmbedding V).lt_iff_lt
#align simple_graph.edge_set_ssubset_edge_set SimpleGraph.edgeSet_ssubset_edgeSet
theorem edgeSet_injective : Injective (edgeSet : SimpleGraph V → Set (Sym2 V)) :=
(edgeSetEmbedding V).injective
#align simple_graph.edge_set_injective SimpleGraph.edgeSet_injective
alias ⟨_, edgeSet_mono⟩ := edgeSet_subset_edgeSet
#align simple_graph.edge_set_mono SimpleGraph.edgeSet_mono
alias ⟨_, edgeSet_strict_mono⟩ := edgeSet_ssubset_edgeSet
#align simple_graph.edge_set_strict_mono SimpleGraph.edgeSet_strict_mono
attribute [mono] edgeSet_mono edgeSet_strict_mono
variable (G₁ G₂)
@[simp]
theorem edgeSet_bot : (⊥ : SimpleGraph V).edgeSet = ∅ :=
Sym2.fromRel_bot
#align simple_graph.edge_set_bot SimpleGraph.edgeSet_bot
@[simp]
theorem edgeSet_top : (⊤ : SimpleGraph V).edgeSet = {e | ¬e.IsDiag} :=
Sym2.fromRel_ne
@[simp]
theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet ⊆ {e | ¬e.IsDiag} :=
fun _ h => (Sym2.fromRel_irreflexive (sym := G.symm)).mp G.loopless h
@[simp]
theorem edgeSet_sup : (G₁ ⊔ G₂).edgeSet = G₁.edgeSet ∪ G₂.edgeSet := by
ext ⟨x, y⟩
rfl
#align simple_graph.edge_set_sup SimpleGraph.edgeSet_sup
@[simp]
theorem edgeSet_inf : (G₁ ⊓ G₂).edgeSet = G₁.edgeSet ∩ G₂.edgeSet := by
ext ⟨x, y⟩
rfl
#align simple_graph.edge_set_inf SimpleGraph.edgeSet_inf
@[simp]
theorem edgeSet_sdiff : (G₁ \ G₂).edgeSet = G₁.edgeSet \ G₂.edgeSet := by
ext ⟨x, y⟩
rfl
#align simple_graph.edge_set_sdiff SimpleGraph.edgeSet_sdiff
variable {G G₁ G₂}
@[simp] lemma disjoint_edgeSet : Disjoint G₁.edgeSet G₂.edgeSet ↔ Disjoint G₁ G₂ := by
rw [Set.disjoint_iff, disjoint_iff_inf_le, ← edgeSet_inf, ← edgeSet_bot, ← Set.le_iff_subset,
OrderEmbedding.le_iff_le]
#align simple_graph.disjoint_edge_set SimpleGraph.disjoint_edgeSet
@[simp] lemma edgeSet_eq_empty : G.edgeSet = ∅ ↔ G = ⊥ := by rw [← edgeSet_bot, edgeSet_inj]
#align simple_graph.edge_set_eq_empty SimpleGraph.edgeSet_eq_empty
@[simp] lemma edgeSet_nonempty : G.edgeSet.Nonempty ↔ G ≠ ⊥ := by
rw [Set.nonempty_iff_ne_empty, edgeSet_eq_empty.ne]
#align simple_graph.edge_set_nonempty SimpleGraph.edgeSet_nonempty
/-- This lemma, combined with `edgeSet_sdiff` and `edgeSet_from_edgeSet`,
allows proving `(G \ from_edgeSet s).edge_set = G.edgeSet \ s` by `simp`. -/
@[simp]
theorem edgeSet_sdiff_sdiff_isDiag (G : SimpleGraph V) (s : Set (Sym2 V)) :
G.edgeSet \ (s \ { e | e.IsDiag }) = G.edgeSet \ s := by
ext e
simp only [Set.mem_diff, Set.mem_setOf_eq, not_and, not_not, and_congr_right_iff]
intro h
simp only [G.not_isDiag_of_mem_edgeSet h, imp_false]
#align simple_graph.edge_set_sdiff_sdiff_is_diag SimpleGraph.edgeSet_sdiff_sdiff_isDiag
/-- Two vertices are adjacent iff there is an edge between them. The
condition `v ≠ w` ensures they are different endpoints of the edge,
which is necessary since when `v = w` the existential
`∃ (e ∈ G.edgeSet), v ∈ e ∧ w ∈ e` is satisfied by every edge
incident to `v`. -/
theorem adj_iff_exists_edge {v w : V} : G.Adj v w ↔ v ≠ w ∧ ∃ e ∈ G.edgeSet, v ∈ e ∧ w ∈ e := by
refine ⟨fun _ => ⟨G.ne_of_adj ‹_›, s(v, w), by simpa⟩, ?_⟩
rintro ⟨hne, e, he, hv⟩
rw [Sym2.mem_and_mem_iff hne] at hv
subst e
rwa [mem_edgeSet] at he
#align simple_graph.adj_iff_exists_edge SimpleGraph.adj_iff_exists_edge
theorem adj_iff_exists_edge_coe : G.Adj a b ↔ ∃ e : G.edgeSet, e.val = s(a, b) := by
simp only [mem_edgeSet, exists_prop, SetCoe.exists, exists_eq_right, Subtype.coe_mk]
#align simple_graph.adj_iff_exists_edge_coe SimpleGraph.adj_iff_exists_edge_coe
variable (G G₁ G₂)
theorem edge_other_ne {e : Sym2 V} (he : e ∈ G.edgeSet) {v : V} (h : v ∈ e) :
Sym2.Mem.other h ≠ v := by
erw [← Sym2.other_spec h, Sym2.eq_swap] at he
exact G.ne_of_adj he
#align simple_graph.edge_other_ne SimpleGraph.edge_other_ne
instance decidableMemEdgeSet [DecidableRel G.Adj] : DecidablePred (· ∈ G.edgeSet) :=
Sym2.fromRel.decidablePred G.symm
#align simple_graph.decidable_mem_edge_set SimpleGraph.decidableMemEdgeSet
instance fintypeEdgeSet [Fintype (Sym2 V)] [DecidableRel G.Adj] : Fintype G.edgeSet :=
Subtype.fintype _
#align simple_graph.fintype_edge_set SimpleGraph.fintypeEdgeSet
instance fintypeEdgeSetBot : Fintype (⊥ : SimpleGraph V).edgeSet := by
rw [edgeSet_bot]
infer_instance
#align simple_graph.fintype_edge_set_bot SimpleGraph.fintypeEdgeSetBot
instance fintypeEdgeSetSup [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
Fintype (G₁ ⊔ G₂).edgeSet := by
rw [edgeSet_sup]
infer_instance
#align simple_graph.fintype_edge_set_sup SimpleGraph.fintypeEdgeSetSup
instance fintypeEdgeSetInf [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
Fintype (G₁ ⊓ G₂).edgeSet := by
rw [edgeSet_inf]
exact Set.fintypeInter _ _
#align simple_graph.fintype_edge_set_inf SimpleGraph.fintypeEdgeSetInf
instance fintypeEdgeSetSdiff [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] :
Fintype (G₁ \ G₂).edgeSet := by
rw [edgeSet_sdiff]
exact Set.fintypeDiff _ _
#align simple_graph.fintype_edge_set_sdiff SimpleGraph.fintypeEdgeSetSdiff
end EdgeSet
section FromEdgeSet
variable (s : Set (Sym2 V))
/-- `fromEdgeSet` constructs a `SimpleGraph` from a set of edges, without loops. -/
def fromEdgeSet : SimpleGraph V where
Adj := Sym2.ToRel s ⊓ Ne
symm v w h := ⟨Sym2.toRel_symmetric s h.1, h.2.symm⟩
#align simple_graph.from_edge_set SimpleGraph.fromEdgeSet
@[simp]
theorem fromEdgeSet_adj : (fromEdgeSet s).Adj v w ↔ s(v, w) ∈ s ∧ v ≠ w :=
Iff.rfl
#align simple_graph.from_edge_set_adj SimpleGraph.fromEdgeSet_adj
-- Note: we need to make sure `fromEdgeSet_adj` and this lemma are confluent.
-- In particular, both yield `s(u, v) ∈ (fromEdgeSet s).edgeSet` ==> `s(v, w) ∈ s ∧ v ≠ w`.
@[simp]
theorem edgeSet_fromEdgeSet : (fromEdgeSet s).edgeSet = s \ { e | e.IsDiag } := by
ext e
exact Sym2.ind (by simp) e
#align simple_graph.edge_set_from_edge_set SimpleGraph.edgeSet_fromEdgeSet
@[simp]
theorem fromEdgeSet_edgeSet : fromEdgeSet G.edgeSet = G := by
ext v w
exact ⟨fun h => h.1, fun h => ⟨h, G.ne_of_adj h⟩⟩
#align simple_graph.from_edge_set_edge_set SimpleGraph.fromEdgeSet_edgeSet
@[simp]
theorem fromEdgeSet_empty : fromEdgeSet (∅ : Set (Sym2 V)) = ⊥ := by
ext v w
simp only [fromEdgeSet_adj, Set.mem_empty_iff_false, false_and_iff, bot_adj]
#align simple_graph.from_edge_set_empty SimpleGraph.fromEdgeSet_empty
@[simp]
theorem fromEdgeSet_univ : fromEdgeSet (Set.univ : Set (Sym2 V)) = ⊤ := by
ext v w
simp only [fromEdgeSet_adj, Set.mem_univ, true_and_iff, top_adj]
#align simple_graph.from_edge_set_univ SimpleGraph.fromEdgeSet_univ
@[simp]
theorem fromEdgeSet_inter (s t : Set (Sym2 V)) :
fromEdgeSet (s ∩ t) = fromEdgeSet s ⊓ fromEdgeSet t := by
ext v w
simp only [fromEdgeSet_adj, Set.mem_inter_iff, Ne, inf_adj]
tauto
#align simple_graph.from_edge_set_inf SimpleGraph.fromEdgeSet_inter
@[simp]
theorem fromEdgeSet_union (s t : Set (Sym2 V)) :
fromEdgeSet (s ∪ t) = fromEdgeSet s ⊔ fromEdgeSet t := by
ext v w
simp [Set.mem_union, or_and_right]
#align simple_graph.from_edge_set_sup SimpleGraph.fromEdgeSet_union
@[simp]
theorem fromEdgeSet_sdiff (s t : Set (Sym2 V)) :
fromEdgeSet (s \ t) = fromEdgeSet s \ fromEdgeSet t := by
ext v w
constructor <;> simp (config := { contextual := true })
#align simple_graph.from_edge_set_sdiff SimpleGraph.fromEdgeSet_sdiff
@[mono]
theorem fromEdgeSet_mono {s t : Set (Sym2 V)} (h : s ⊆ t) : fromEdgeSet s ≤ fromEdgeSet t := by
rintro v w
simp (config := { contextual := true }) only [fromEdgeSet_adj, Ne, not_false_iff,
and_true_iff, and_imp]
exact fun vws _ => h vws
#align simple_graph.from_edge_set_mono SimpleGraph.fromEdgeSet_mono
@[simp] lemma disjoint_fromEdgeSet : Disjoint G (fromEdgeSet s) ↔ Disjoint G.edgeSet s := by
conv_rhs => rw [← Set.diff_union_inter s {e : Sym2 V | e.IsDiag}]
rw [← disjoint_edgeSet, edgeSet_fromEdgeSet, Set.disjoint_union_right, and_iff_left]
exact Set.disjoint_left.2 fun e he he' ↦ not_isDiag_of_mem_edgeSet _ he he'.2
#align simple_graph.disjoint_from_edge_set SimpleGraph.disjoint_fromEdgeSet
@[simp] lemma fromEdgeSet_disjoint : Disjoint (fromEdgeSet s) G ↔ Disjoint s G.edgeSet := by
rw [disjoint_comm, disjoint_fromEdgeSet, disjoint_comm]
#align simple_graph.from_edge_set_disjoint SimpleGraph.fromEdgeSet_disjoint
instance [DecidableEq V] [Fintype s] : Fintype (fromEdgeSet s).edgeSet := by
rw [edgeSet_fromEdgeSet s]
infer_instance
end FromEdgeSet
/-! ### Incidence set -/
/-- Set of edges incident to a given vertex, aka incidence set. -/
def incidenceSet (v : V) : Set (Sym2 V) :=
{ e ∈ G.edgeSet | v ∈ e }
#align simple_graph.incidence_set SimpleGraph.incidenceSet
theorem incidenceSet_subset (v : V) : G.incidenceSet v ⊆ G.edgeSet := fun _ h => h.1
#align simple_graph.incidence_set_subset SimpleGraph.incidenceSet_subset
theorem mk'_mem_incidenceSet_iff : s(b, c) ∈ G.incidenceSet a ↔ G.Adj b c ∧ (a = b ∨ a = c) :=
and_congr_right' Sym2.mem_iff
#align simple_graph.mk_mem_incidence_set_iff SimpleGraph.mk'_mem_incidenceSet_iff
theorem mk'_mem_incidenceSet_left_iff : s(a, b) ∈ G.incidenceSet a ↔ G.Adj a b :=
and_iff_left <| Sym2.mem_mk_left _ _
#align simple_graph.mk_mem_incidence_set_left_iff SimpleGraph.mk'_mem_incidenceSet_left_iff
theorem mk'_mem_incidenceSet_right_iff : s(a, b) ∈ G.incidenceSet b ↔ G.Adj a b :=
and_iff_left <| Sym2.mem_mk_right _ _
#align simple_graph.mk_mem_incidence_set_right_iff SimpleGraph.mk'_mem_incidenceSet_right_iff
theorem edge_mem_incidenceSet_iff {e : G.edgeSet} : ↑e ∈ G.incidenceSet a ↔ a ∈ (e : Sym2 V) :=
and_iff_right e.2
#align simple_graph.edge_mem_incidence_set_iff SimpleGraph.edge_mem_incidenceSet_iff
theorem incidenceSet_inter_incidenceSet_subset (h : a ≠ b) :
G.incidenceSet a ∩ G.incidenceSet b ⊆ {s(a, b)} := fun _e he =>
(Sym2.mem_and_mem_iff h).1 ⟨he.1.2, he.2.2⟩
#align simple_graph.incidence_set_inter_incidence_set_subset SimpleGraph.incidenceSet_inter_incidenceSet_subset
theorem incidenceSet_inter_incidenceSet_of_adj (h : G.Adj a b) :
G.incidenceSet a ∩ G.incidenceSet b = {s(a, b)} := by
refine (G.incidenceSet_inter_incidenceSet_subset <| h.ne).antisymm ?_
rintro _ (rfl : _ = s(a, b))
exact ⟨G.mk'_mem_incidenceSet_left_iff.2 h, G.mk'_mem_incidenceSet_right_iff.2 h⟩
#align simple_graph.incidence_set_inter_incidence_set_of_adj SimpleGraph.incidenceSet_inter_incidenceSet_of_adj
theorem adj_of_mem_incidenceSet (h : a ≠ b) (ha : e ∈ G.incidenceSet a)
(hb : e ∈ G.incidenceSet b) : G.Adj a b := by
rwa [← mk'_mem_incidenceSet_left_iff, ←
Set.mem_singleton_iff.1 <| G.incidenceSet_inter_incidenceSet_subset h ⟨ha, hb⟩]
#align simple_graph.adj_of_mem_incidence_set SimpleGraph.adj_of_mem_incidenceSet
theorem incidenceSet_inter_incidenceSet_of_not_adj (h : ¬G.Adj a b) (hn : a ≠ b) :
G.incidenceSet a ∩ G.incidenceSet b = ∅ := by
simp_rw [Set.eq_empty_iff_forall_not_mem, Set.mem_inter_iff, not_and]
intro u ha hb
exact h (G.adj_of_mem_incidenceSet hn ha hb)
#align simple_graph.incidence_set_inter_incidence_set_of_not_adj SimpleGraph.incidenceSet_inter_incidenceSet_of_not_adj
instance decidableMemIncidenceSet [DecidableEq V] [DecidableRel G.Adj] (v : V) :
DecidablePred (· ∈ G.incidenceSet v) :=
inferInstanceAs <| DecidablePred fun e => e ∈ G.edgeSet ∧ v ∈ e
#align simple_graph.decidable_mem_incidence_set SimpleGraph.decidableMemIncidenceSet
@[simp]
theorem mem_neighborSet (v w : V) : w ∈ G.neighborSet v ↔ G.Adj v w :=
Iff.rfl
#align simple_graph.mem_neighbor_set SimpleGraph.mem_neighborSet
lemma not_mem_neighborSet_self : a ∉ G.neighborSet a := by simp
#align simple_graph.not_mem_neighbor_set_self SimpleGraph.not_mem_neighborSet_self
@[simp]
theorem mem_incidenceSet (v w : V) : s(v, w) ∈ G.incidenceSet v ↔ G.Adj v w := by
simp [incidenceSet]
#align simple_graph.mem_incidence_set SimpleGraph.mem_incidenceSet
theorem mem_incidence_iff_neighbor {v w : V} :
s(v, w) ∈ G.incidenceSet v ↔ w ∈ G.neighborSet v := by
simp only [mem_incidenceSet, mem_neighborSet]
#align simple_graph.mem_incidence_iff_neighbor SimpleGraph.mem_incidence_iff_neighbor
theorem adj_incidenceSet_inter {v : V} {e : Sym2 V} (he : e ∈ G.edgeSet) (h : v ∈ e) :
G.incidenceSet v ∩ G.incidenceSet (Sym2.Mem.other h) = {e} := by
ext e'
simp only [incidenceSet, Set.mem_sep_iff, Set.mem_inter_iff, Set.mem_singleton_iff]
refine ⟨fun h' => ?_, ?_⟩
· rw [← Sym2.other_spec h]
exact (Sym2.mem_and_mem_iff (edge_other_ne G he h).symm).mp ⟨h'.1.2, h'.2.2⟩
· rintro rfl
exact ⟨⟨he, h⟩, he, Sym2.other_mem _⟩
#align simple_graph.adj_incidence_set_inter SimpleGraph.adj_incidenceSet_inter
theorem compl_neighborSet_disjoint (G : SimpleGraph V) (v : V) :
Disjoint (G.neighborSet v) (Gᶜ.neighborSet v) := by
rw [Set.disjoint_iff]
rintro w ⟨h, h'⟩
rw [mem_neighborSet, compl_adj] at h'
exact h'.2 h
#align simple_graph.compl_neighbor_set_disjoint SimpleGraph.compl_neighborSet_disjoint
theorem neighborSet_union_compl_neighborSet_eq (G : SimpleGraph V) (v : V) :
G.neighborSet v ∪ Gᶜ.neighborSet v = {v}ᶜ := by
ext w
have h := @ne_of_adj _ G
simp_rw [Set.mem_union, mem_neighborSet, compl_adj, Set.mem_compl_iff, Set.mem_singleton_iff]
tauto
#align simple_graph.neighbor_set_union_compl_neighbor_set_eq SimpleGraph.neighborSet_union_compl_neighborSet_eq
theorem card_neighborSet_union_compl_neighborSet [Fintype V] (G : SimpleGraph V) (v : V)
[Fintype (G.neighborSet v ∪ Gᶜ.neighborSet v : Set V)] :
(Set.toFinset (G.neighborSet v ∪ Gᶜ.neighborSet v)).card = Fintype.card V - 1 := by
classical simp_rw [neighborSet_union_compl_neighborSet_eq, Set.toFinset_compl,
Finset.card_compl, Set.toFinset_card, Set.card_singleton]
#align simple_graph.card_neighbor_set_union_compl_neighbor_set SimpleGraph.card_neighborSet_union_compl_neighborSet
theorem neighborSet_compl (G : SimpleGraph V) (v : V) :
Gᶜ.neighborSet v = (G.neighborSet v)ᶜ \ {v} := by
ext w
simp [and_comm, eq_comm]
#align simple_graph.neighbor_set_compl SimpleGraph.neighborSet_compl
/-- The set of common neighbors between two vertices `v` and `w` in a graph `G` is the
intersection of the neighbor sets of `v` and `w`. -/
def commonNeighbors (v w : V) : Set V :=
G.neighborSet v ∩ G.neighborSet w
#align simple_graph.common_neighbors SimpleGraph.commonNeighbors
theorem commonNeighbors_eq (v w : V) : G.commonNeighbors v w = G.neighborSet v ∩ G.neighborSet w :=
rfl
#align simple_graph.common_neighbors_eq SimpleGraph.commonNeighbors_eq
theorem mem_commonNeighbors {u v w : V} : u ∈ G.commonNeighbors v w ↔ G.Adj v u ∧ G.Adj w u :=
Iff.rfl
#align simple_graph.mem_common_neighbors SimpleGraph.mem_commonNeighbors
theorem commonNeighbors_symm (v w : V) : G.commonNeighbors v w = G.commonNeighbors w v :=
Set.inter_comm _ _
#align simple_graph.common_neighbors_symm SimpleGraph.commonNeighbors_symm
theorem not_mem_commonNeighbors_left (v w : V) : v ∉ G.commonNeighbors v w := fun h =>
ne_of_adj G h.1 rfl
#align simple_graph.not_mem_common_neighbors_left SimpleGraph.not_mem_commonNeighbors_left
theorem not_mem_commonNeighbors_right (v w : V) : w ∉ G.commonNeighbors v w := fun h =>
ne_of_adj G h.2 rfl
#align simple_graph.not_mem_common_neighbors_right SimpleGraph.not_mem_commonNeighbors_right
theorem commonNeighbors_subset_neighborSet_left (v w : V) :
G.commonNeighbors v w ⊆ G.neighborSet v :=
Set.inter_subset_left
#align simple_graph.common_neighbors_subset_neighbor_set_left SimpleGraph.commonNeighbors_subset_neighborSet_left
theorem commonNeighbors_subset_neighborSet_right (v w : V) :
G.commonNeighbors v w ⊆ G.neighborSet w :=
Set.inter_subset_right
#align simple_graph.common_neighbors_subset_neighbor_set_right SimpleGraph.commonNeighbors_subset_neighborSet_right
instance decidableMemCommonNeighbors [DecidableRel G.Adj] (v w : V) :
DecidablePred (· ∈ G.commonNeighbors v w) :=
inferInstanceAs <| DecidablePred fun u => u ∈ G.neighborSet v ∧ u ∈ G.neighborSet w
#align simple_graph.decidable_mem_common_neighbors SimpleGraph.decidableMemCommonNeighbors
theorem commonNeighbors_top_eq {v w : V} :
(⊤ : SimpleGraph V).commonNeighbors v w = Set.univ \ {v, w} := by
ext u
simp [commonNeighbors, eq_comm, not_or]
#align simple_graph.common_neighbors_top_eq SimpleGraph.commonNeighbors_top_eq
section Incidence
variable [DecidableEq V]
/-- Given an edge incident to a particular vertex, get the other vertex on the edge. -/
def otherVertexOfIncident {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) : V :=
Sym2.Mem.other' h.2
#align simple_graph.other_vertex_of_incident SimpleGraph.otherVertexOfIncident
theorem edge_other_incident_set {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) :
e ∈ G.incidenceSet (G.otherVertexOfIncident h) := by
use h.1
simp [otherVertexOfIncident, Sym2.other_mem']
#align simple_graph.edge_other_incident_set SimpleGraph.edge_other_incident_set
theorem incidence_other_prop {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) :
G.otherVertexOfIncident h ∈ G.neighborSet v := by
cases' h with he hv
rwa [← Sym2.other_spec' hv, mem_edgeSet] at he
#align simple_graph.incidence_other_prop SimpleGraph.incidence_other_prop
-- Porting note: as a simp lemma this does not apply even to itself
theorem incidence_other_neighbor_edge {v w : V} (h : w ∈ G.neighborSet v) :
G.otherVertexOfIncident (G.mem_incidence_iff_neighbor.mpr h) = w :=
Sym2.congr_right.mp (Sym2.other_spec' (G.mem_incidence_iff_neighbor.mpr h).right)
#align simple_graph.incidence_other_neighbor_edge SimpleGraph.incidence_other_neighbor_edge
/-- There is an equivalence between the set of edges incident to a given
vertex and the set of vertices adjacent to the vertex. -/
@[simps]
def incidenceSetEquivNeighborSet (v : V) : G.incidenceSet v ≃ G.neighborSet v where
toFun e := ⟨G.otherVertexOfIncident e.2, G.incidence_other_prop e.2⟩
invFun w := ⟨s(v, w.1), G.mem_incidence_iff_neighbor.mpr w.2⟩
left_inv x := by simp [otherVertexOfIncident]
right_inv := fun ⟨w, hw⟩ => by
simp only [mem_neighborSet, Subtype.mk.injEq]
exact incidence_other_neighbor_edge _ hw
#align simple_graph.incidence_set_equiv_neighbor_set SimpleGraph.incidenceSetEquivNeighborSet
end Incidence
/-! ## Edge deletion -/
section deleteEdges
/-- Given a set of vertex pairs, remove all of the corresponding edges from the
graph's edge set, if present.
See also: `SimpleGraph.Subgraph.deleteEdges`. -/
def deleteEdges (s : Set (Sym2 V)) : SimpleGraph V := G \ fromEdgeSet s
#align simple_graph.delete_edges SimpleGraph.deleteEdges
#align simple_graph.delete_edges_eq_sdiff_from_edge_set SimpleGraph.deleteEdges
#align simple_graph.sdiff_eq_delete_edges SimpleGraph.deleteEdges
#align simple_graph.compl_eq_delete_edges SimpleGraph.deleteEdges
variable {G} {H : SimpleGraph V} {s s₁ s₂ : Set (Sym2 V)}
@[simp] lemma deleteEdges_adj : (G.deleteEdges s).Adj v w ↔ G.Adj v w ∧ ¬s(v, w) ∈ s :=
and_congr_right fun h ↦ (and_iff_left h.ne).not
#align simple_graph.delete_edges_adj SimpleGraph.deleteEdges_adj
@[simp] lemma deleteEdges_edgeSet (G G' : SimpleGraph V) : G.deleteEdges G'.edgeSet = G \ G' := by
ext; simp
@[simp]
theorem deleteEdges_deleteEdges (s s' : Set (Sym2 V)) :
(G.deleteEdges s).deleteEdges s' = G.deleteEdges (s ∪ s') := by simp [deleteEdges, sdiff_sdiff]
#align simple_graph.delete_edges_delete_edges SimpleGraph.deleteEdges_deleteEdges
@[simp] lemma deleteEdges_empty : G.deleteEdges ∅ = G := by simp [deleteEdges]
@[simp] lemma deleteEdges_univ : G.deleteEdges Set.univ = ⊥ := by simp [deleteEdges]
#align simple_graph.delete_edges_empty_eq SimpleGraph.deleteEdges_empty
#align simple_graph.delete_edges_univ_eq SimpleGraph.deleteEdges_univ
lemma deleteEdges_le (s : Set (Sym2 V)) : G.deleteEdges s ≤ G := sdiff_le
#align simple_graph.delete_edges_le SimpleGraph.deleteEdges_le
lemma deleteEdges_anti (h : s₁ ⊆ s₂) : G.deleteEdges s₂ ≤ G.deleteEdges s₁ :=
sdiff_le_sdiff_left $ fromEdgeSet_mono h
#align simple_graph.delete_edges_le_of_le SimpleGraph.deleteEdges_anti
lemma deleteEdges_mono (h : G ≤ H) : G.deleteEdges s ≤ H.deleteEdges s := sdiff_le_sdiff_right h
theorem deleteEdges_eq_inter_edgeSet (s : Set (Sym2 V)) :
G.deleteEdges s = G.deleteEdges (s ∩ G.edgeSet) := by
ext
simp (config := { contextual := true }) [imp_false]
#align simple_graph.delete_edges_eq_inter_edge_set SimpleGraph.deleteEdges_eq_inter_edgeSet
| Mathlib/Combinatorics/SimpleGraph/Basic.lean | 958 | 960 | theorem deleteEdges_sdiff_eq_of_le {H : SimpleGraph V} (h : H ≤ G) :
G.deleteEdges (G.edgeSet \ H.edgeSet) = H := by |
rw [← edgeSet_sdiff, deleteEdges_edgeSet, sdiff_sdiff_eq_self h]
|
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Init.Data.List.Basic
import Mathlib.Init.Data.List.Instances
import Mathlib.Init.Data.List.Lemmas
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
#align_import data.list.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83"
/-!
# Basic properties of lists
-/
assert_not_exists Set.range
assert_not_exists GroupWithZero
assert_not_exists Ring
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
-- Porting note: Delete this attribute
-- attribute [inline] List.head!
/-- There is only one list of an empty type -/
instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) :=
{ instInhabitedList with
uniq := fun l =>
match l with
| [] => rfl
| a :: _ => isEmptyElim a }
#align list.unique_of_is_empty List.uniqueOfIsEmpty
instance : Std.LawfulIdentity (α := List α) Append.append [] where
left_id := nil_append
right_id := append_nil
instance : Std.Associative (α := List α) Append.append where
assoc := append_assoc
#align list.cons_ne_nil List.cons_ne_nil
#align list.cons_ne_self List.cons_ne_self
#align list.head_eq_of_cons_eq List.head_eq_of_cons_eqₓ -- implicits order
#align list.tail_eq_of_cons_eq List.tail_eq_of_cons_eqₓ -- implicits order
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
#align list.cons_injective List.cons_injective
#align list.cons_inj List.cons_inj
#align list.cons_eq_cons List.cons_eq_cons
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
#align list.singleton_injective List.singleton_injective
theorem singleton_inj {a b : α} : [a] = [b] ↔ a = b :=
singleton_injective.eq_iff
#align list.singleton_inj List.singleton_inj
#align list.exists_cons_of_ne_nil List.exists_cons_of_ne_nil
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
#align list.set_of_mem_cons List.set_of_mem_cons
/-! ### mem -/
#align list.mem_singleton_self List.mem_singleton_self
#align list.eq_of_mem_singleton List.eq_of_mem_singleton
#align list.mem_singleton List.mem_singleton
#align list.mem_of_mem_cons_of_mem List.mem_of_mem_cons_of_mem
theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α]
{a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by
by_cases hab : a = b
· exact Or.inl hab
· exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩))
#align decidable.list.eq_or_ne_mem_of_mem Decidable.List.eq_or_ne_mem_of_mem
#align list.eq_or_ne_mem_of_mem List.eq_or_ne_mem_of_mem
#align list.not_mem_append List.not_mem_append
#align list.ne_nil_of_mem List.ne_nil_of_mem
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
@[deprecated (since := "2024-03-23")] alias mem_split := append_of_mem
#align list.mem_split List.append_of_mem
#align list.mem_of_ne_of_mem List.mem_of_ne_of_mem
#align list.ne_of_not_mem_cons List.ne_of_not_mem_cons
#align list.not_mem_of_not_mem_cons List.not_mem_of_not_mem_cons
#align list.not_mem_cons_of_ne_of_not_mem List.not_mem_cons_of_ne_of_not_mem
#align list.ne_and_not_mem_of_not_mem_cons List.ne_and_not_mem_of_not_mem_cons
#align list.mem_map List.mem_map
#align list.exists_of_mem_map List.exists_of_mem_map
#align list.mem_map_of_mem List.mem_map_of_memₓ -- implicits order
-- The simpNF linter says that the LHS can be simplified via `List.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 : Injective f) {a : α} {l : List α} :
f a ∈ map f l ↔ a ∈ l :=
⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem _⟩
#align list.mem_map_of_injective List.mem_map_of_injective
@[simp]
theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α}
(hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l :=
⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩
#align function.involutive.exists_mem_and_apply_eq_iff Function.Involutive.exists_mem_and_apply_eq_iff
theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} :
a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff]
#align list.mem_map_of_involutive List.mem_map_of_involutive
#align list.forall_mem_map_iff List.forall_mem_map_iffₓ -- universe order
#align list.map_eq_nil List.map_eq_nilₓ -- universe order
attribute [simp] List.mem_join
#align list.mem_join List.mem_join
#align list.exists_of_mem_join List.exists_of_mem_join
#align list.mem_join_of_mem List.mem_join_of_memₓ -- implicits order
attribute [simp] List.mem_bind
#align list.mem_bind List.mem_bindₓ -- implicits order
-- Porting note: bExists in Lean3, And in Lean4
#align list.exists_of_mem_bind List.exists_of_mem_bindₓ -- implicits order
#align list.mem_bind_of_mem List.mem_bind_of_memₓ -- implicits order
#align list.bind_map List.bind_mapₓ -- implicits order
theorem map_bind (g : β → List γ) (f : α → β) :
∀ l : List α, (List.map f l).bind g = l.bind fun a => g (f a)
| [] => rfl
| a :: l => by simp only [cons_bind, map_cons, map_bind _ _ l]
#align list.map_bind List.map_bind
/-! ### length -/
#align list.length_eq_zero List.length_eq_zero
#align list.length_singleton List.length_singleton
#align list.length_pos_of_mem List.length_pos_of_mem
#align list.exists_mem_of_length_pos List.exists_mem_of_length_pos
#align list.length_pos_iff_exists_mem List.length_pos_iff_exists_mem
alias ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ := length_pos
#align list.ne_nil_of_length_pos List.ne_nil_of_length_pos
#align list.length_pos_of_ne_nil List.length_pos_of_ne_nil
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
#align list.length_pos_iff_ne_nil List.length_pos_iff_ne_nil
#align list.exists_mem_of_ne_nil List.exists_mem_of_ne_nil
#align list.length_eq_one List.length_eq_one
theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t
| [], H => absurd H.symm <| succ_ne_zero n
| h :: t, _ => ⟨h, t, rfl⟩
#align list.exists_of_length_succ List.exists_of_length_succ
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
constructor
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl
· intros hα l1 l2 hl
induction l1 generalizing l2 <;> cases l2
· rfl
· cases hl
· cases hl
· next ih _ _ =>
congr
· exact Subsingleton.elim _ _
· apply ih; simpa using hl
#align list.length_injective_iff List.length_injective_iff
@[simp default+1] -- Porting note: this used to be just @[simp]
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
#align list.length_injective List.length_injective
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
#align list.length_eq_two List.length_eq_two
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
#align list.length_eq_three List.length_eq_three
#align list.sublist.length_le List.Sublist.length_le
/-! ### set-theoretic notation of lists -/
-- ADHOC Porting note: instance from Lean3 core
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
#align list.has_singleton List.instSingletonList
-- ADHOC Porting note: instance from Lean3 core
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
-- ADHOC Porting note: instance from Lean3 core
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_emptyc_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg (not_mem_nil _) }
#align list.empty_eq List.empty_eq
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
#align list.singleton_eq List.singleton_eq
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
#align list.insert_neg List.insert_neg
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
#align list.insert_pos List.insert_pos
theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by
rw [insert_neg, singleton_eq]
rwa [singleton_eq, mem_singleton]
#align list.doubleton_eq List.doubleton_eq
/-! ### bounded quantifiers over lists -/
#align list.forall_mem_nil List.forall_mem_nil
#align list.forall_mem_cons List.forall_mem_cons
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x := (forall_mem_cons.1 h).2
#align list.forall_mem_of_forall_mem_cons List.forall_mem_of_forall_mem_cons
#align list.forall_mem_singleton List.forall_mem_singleton
#align list.forall_mem_append List.forall_mem_append
#align list.not_exists_mem_nil List.not_exists_mem_nilₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self _ _, h⟩
#align list.exists_mem_cons_of List.exists_mem_cons_ofₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) →
∃ x ∈ a :: l, p x :=
fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩
#align list.exists_mem_cons_of_exists List.exists_mem_cons_of_existsₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) →
p a ∨ ∃ x ∈ l, p x :=
fun ⟨x, xal, px⟩ =>
Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px)
fun h : x ∈ l => Or.inr ⟨x, h, px⟩
#align list.or_exists_of_exists_mem_cons List.or_exists_of_exists_mem_consₓ -- bExists change
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
Iff.intro or_exists_of_exists_mem_cons fun h =>
Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists
#align list.exists_mem_cons_iff List.exists_mem_cons_iff
/-! ### list subset -/
instance : IsTrans (List α) Subset where
trans := fun _ _ _ => List.Subset.trans
#align list.subset_def List.subset_def
#align list.subset_append_of_subset_left List.subset_append_of_subset_left
#align list.subset_append_of_subset_right List.subset_append_of_subset_right
#align list.cons_subset List.cons_subset
theorem cons_subset_of_subset_of_mem {a : α} {l m : List α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
#align list.cons_subset_of_subset_of_mem List.cons_subset_of_subset_of_mem
theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
#align list.append_subset_of_subset_of_subset List.append_subset_of_subset_of_subset
-- Porting note: in Batteries
#align list.append_subset_iff List.append_subset
alias ⟨eq_nil_of_subset_nil, _⟩ := subset_nil
#align list.eq_nil_of_subset_nil List.eq_nil_of_subset_nil
#align list.eq_nil_iff_forall_not_mem List.eq_nil_iff_forall_not_mem
#align list.map_subset List.map_subset
theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by
refine ⟨?_, map_subset f⟩; intro h2 x hx
rcases mem_map.1 (h2 (mem_map_of_mem f hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
#align list.map_subset_iff List.map_subset_iff
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
#align list.append_eq_has_append List.append_eq_has_append
#align list.singleton_append List.singleton_append
#align list.append_ne_nil_of_ne_nil_left List.append_ne_nil_of_ne_nil_left
#align list.append_ne_nil_of_ne_nil_right List.append_ne_nil_of_ne_nil_right
#align list.append_eq_nil List.append_eq_nil
-- Porting note: in Batteries
#align list.nil_eq_append_iff List.nil_eq_append
@[deprecated (since := "2024-03-24")] alias append_eq_cons_iff := append_eq_cons
#align list.append_eq_cons_iff List.append_eq_cons
@[deprecated (since := "2024-03-24")] alias cons_eq_append_iff := cons_eq_append
#align list.cons_eq_append_iff List.cons_eq_append
#align list.append_eq_append_iff List.append_eq_append_iff
#align list.take_append_drop List.take_append_drop
#align list.append_inj List.append_inj
#align list.append_inj_right List.append_inj_rightₓ -- implicits order
#align list.append_inj_left List.append_inj_leftₓ -- implicits order
#align list.append_inj' List.append_inj'ₓ -- implicits order
#align list.append_inj_right' List.append_inj_right'ₓ -- implicits order
#align list.append_inj_left' List.append_inj_left'ₓ -- implicits order
@[deprecated (since := "2024-01-18")] alias append_left_cancel := append_cancel_left
#align list.append_left_cancel List.append_cancel_left
@[deprecated (since := "2024-01-18")] alias append_right_cancel := append_cancel_right
#align list.append_right_cancel List.append_cancel_right
@[simp] theorem append_left_eq_self {x y : List α} : x ++ y = y ↔ x = [] := by
rw [← append_left_inj (s₁ := x), nil_append]
@[simp] theorem self_eq_append_left {x y : List α} : y = x ++ y ↔ x = [] := by
rw [eq_comm, append_left_eq_self]
@[simp] theorem append_right_eq_self {x y : List α} : x ++ y = x ↔ y = [] := by
rw [← append_right_inj (t₁ := y), append_nil]
@[simp] theorem self_eq_append_right {x y : List α} : x = x ++ y ↔ y = [] := by
rw [eq_comm, append_right_eq_self]
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
#align list.append_right_injective List.append_right_injective
#align list.append_right_inj List.append_right_inj
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
#align list.append_left_injective List.append_left_injective
#align list.append_left_inj List.append_left_inj
#align list.map_eq_append_split List.map_eq_append_split
/-! ### replicate -/
@[simp] lemma replicate_zero (a : α) : replicate 0 a = [] := rfl
#align list.replicate_zero List.replicate_zero
attribute [simp] replicate_succ
#align list.replicate_succ List.replicate_succ
lemma replicate_one (a : α) : replicate 1 a = [a] := rfl
#align list.replicate_one List.replicate_one
#align list.length_replicate List.length_replicate
#align list.mem_replicate List.mem_replicate
#align list.eq_of_mem_replicate List.eq_of_mem_replicate
theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a
| [] => by simp
| (b :: l) => by simp [eq_replicate_length]
#align list.eq_replicate_length List.eq_replicate_length
#align list.eq_replicate_of_mem List.eq_replicate_of_mem
#align list.eq_replicate List.eq_replicate
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
induction m <;> simp [*, succ_add, replicate]
#align list.replicate_add List.replicate_add
theorem replicate_succ' (n) (a : α) : replicate (n + 1) a = replicate n a ++ [a] :=
replicate_add n 1 a
#align list.replicate_succ' List.replicate_succ'
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
#align list.replicate_subset_singleton List.replicate_subset_singleton
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate, subset_def, mem_singleton, exists_eq_left']
#align list.subset_singleton_iff List.subset_singleton_iff
@[simp] theorem map_replicate (f : α → β) (n) (a : α) :
map f (replicate n a) = replicate n (f a) := by
induction n <;> [rfl; simp only [*, replicate, map]]
#align list.map_replicate List.map_replicate
@[simp] theorem tail_replicate (a : α) (n) :
tail (replicate n a) = replicate (n - 1) a := by cases n <;> rfl
#align list.tail_replicate List.tail_replicate
@[simp] theorem join_replicate_nil (n : ℕ) : join (replicate n []) = @nil α := by
induction n <;> [rfl; simp only [*, replicate, join, append_nil]]
#align list.join_replicate_nil List.join_replicate_nil
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
#align list.replicate_right_injective List.replicate_right_injective
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
#align list.replicate_right_inj List.replicate_right_inj
@[simp] theorem replicate_right_inj' {a b : α} : ∀ {n},
replicate n a = replicate n b ↔ n = 0 ∨ a = b
| 0 => by simp
| n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or]
#align list.replicate_right_inj' List.replicate_right_inj'
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate · a)
#align list.replicate_left_injective List.replicate_left_injective
@[simp] theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
#align list.replicate_left_inj List.replicate_left_inj
@[simp] theorem head_replicate (n : ℕ) (a : α) (h) : head (replicate n a) h = a := by
cases n <;> simp at h ⊢
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
#align list.mem_pure List.mem_pure
/-! ### bind -/
@[simp]
theorem bind_eq_bind {α β} (f : α → List β) (l : List α) : l >>= f = l.bind f :=
rfl
#align list.bind_eq_bind List.bind_eq_bind
#align list.bind_append List.append_bind
/-! ### concat -/
#align list.concat_nil List.concat_nil
#align list.concat_cons List.concat_cons
#align list.concat_eq_append List.concat_eq_append
#align list.init_eq_of_concat_eq List.init_eq_of_concat_eq
#align list.last_eq_of_concat_eq List.last_eq_of_concat_eq
#align list.concat_ne_nil List.concat_ne_nil
#align list.concat_append List.concat_append
#align list.length_concat List.length_concat
#align list.append_concat List.append_concat
/-! ### reverse -/
#align list.reverse_nil List.reverse_nil
#align list.reverse_core List.reverseAux
-- Porting note: Do we need this?
attribute [local simp] reverseAux
#align list.reverse_cons List.reverse_cons
#align list.reverse_core_eq List.reverseAux_eq
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
#align list.reverse_cons' List.reverse_cons'
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
#align list.reverse_singleton List.reverse_singleton
#align list.reverse_append List.reverse_append
#align list.reverse_concat List.reverse_concat
#align list.reverse_reverse List.reverse_reverse
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
#align list.reverse_involutive List.reverse_involutive
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
#align list.reverse_injective List.reverse_injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
#align list.reverse_surjective List.reverse_surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
#align list.reverse_bijective List.reverse_bijective
@[simp]
theorem reverse_inj {l₁ l₂ : List α} : reverse l₁ = reverse l₂ ↔ l₁ = l₂ :=
reverse_injective.eq_iff
#align list.reverse_inj List.reverse_inj
theorem reverse_eq_iff {l l' : List α} : l.reverse = l' ↔ l = l'.reverse :=
reverse_involutive.eq_iff
#align list.reverse_eq_iff List.reverse_eq_iff
#align list.reverse_eq_nil List.reverse_eq_nil_iff
theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by
simp only [concat_eq_append, reverse_cons, reverse_reverse]
#align list.concat_eq_reverse_cons List.concat_eq_reverse_cons
#align list.length_reverse List.length_reverse
-- Porting note: This one was @[simp] in mathlib 3,
-- but Lean contains a competing simp lemma reverse_map.
-- For now we remove @[simp] to avoid simplification loops.
-- TODO: Change Lean lemma to match mathlib 3?
theorem map_reverse (f : α → β) (l : List α) : map f (reverse l) = reverse (map f l) :=
(reverse_map f l).symm
#align list.map_reverse List.map_reverse
theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) :
map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by
simp only [reverseAux_eq, map_append, map_reverse]
#align list.map_reverse_core List.map_reverseAux
#align list.mem_reverse List.mem_reverse
@[simp] theorem reverse_replicate (n) (a : α) : reverse (replicate n a) = replicate n a :=
eq_replicate.2
⟨by rw [length_reverse, length_replicate],
fun b h => eq_of_mem_replicate (mem_reverse.1 h)⟩
#align list.reverse_replicate List.reverse_replicate
/-! ### empty -/
-- Porting note: this does not work as desired
-- attribute [simp] List.isEmpty
theorem isEmpty_iff_eq_nil {l : List α} : l.isEmpty ↔ l = [] := by cases l <;> simp [isEmpty]
#align list.empty_iff_eq_nil List.isEmpty_iff_eq_nil
/-! ### dropLast -/
#align list.length_init List.length_dropLast
/-! ### getLast -/
@[simp]
theorem getLast_cons {a : α} {l : List α} :
∀ h : l ≠ nil, getLast (a :: l) (cons_ne_nil a l) = getLast l h := by
induction l <;> intros
· contradiction
· rfl
#align list.last_cons List.getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_ne_nil_right l _ (cons_ne_nil a _)) = a := by
simp only [getLast_append]
#align list.last_append_singleton List.getLast_append_singleton
-- Porting note: name should be fixed upstream
theorem getLast_append' (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_ne_nil_right l₁ l₂ h) = getLast l₂ h := by
induction' l₁ with _ _ ih
· simp
· simp only [cons_append]
rw [List.getLast_cons]
exact ih
#align list.last_append List.getLast_append'
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (concat_ne_nil a l) = a :=
getLast_concat ..
#align list.last_concat List.getLast_concat'
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
#align list.last_singleton List.getLast_singleton'
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) :
getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) :=
rfl
#align list.last_cons_cons List.getLast_cons_cons
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [a], h => rfl
| a :: b :: l, h => by
rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)]
congr
exact dropLast_append_getLast (cons_ne_nil b l)
#align list.init_append_last List.dropLast_append_getLast
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
#align list.last_congr List.getLast_congr
#align list.last_mem List.getLast_mem
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_succ (length_replicate _ _)) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
#align list.last_replicate_succ List.getLast_replicate_succ
/-! ### getLast? -/
-- Porting note: Moved earlier in file, for use in subsequent lemmas.
@[simp]
theorem getLast?_cons_cons (a b : α) (l : List α) :
getLast? (a :: b :: l) = getLast? (b :: l) := rfl
@[simp]
theorem getLast?_isNone : ∀ {l : List α}, (getLast? l).isNone ↔ l = []
| [] => by simp
| [a] => by simp
| a :: b :: l => by simp [@getLast?_isNone (b :: l)]
#align list.last'_is_none List.getLast?_isNone
@[simp]
theorem getLast?_isSome : ∀ {l : List α}, l.getLast?.isSome ↔ l ≠ []
| [] => by simp
| [a] => by simp
| a :: b :: l => by simp [@getLast?_isSome (b :: l)]
#align list.last'_is_some List.getLast?_isSome
theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h
| [], x, hx => False.elim <| by simp at hx
| [a], x, hx =>
have : a = x := by simpa using hx
this ▸ ⟨cons_ne_nil a [], rfl⟩
| a :: b :: l, x, hx => by
rw [getLast?_cons_cons] at hx
rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩
use cons_ne_nil _ _
assumption
#align list.mem_last'_eq_last List.mem_getLast?_eq_getLast
theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
| [], h => (h rfl).elim
| [_], _ => rfl
| _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _)
#align list.last'_eq_last_of_ne_nil List.getLast?_eq_getLast_of_ne_nil
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
#align list.mem_last'_cons List.mem_getLast?_cons
theorem mem_of_mem_getLast? {l : List α} {a : α} (ha : a ∈ l.getLast?) : a ∈ l :=
let ⟨_, h₂⟩ := mem_getLast?_eq_getLast ha
h₂.symm ▸ getLast_mem _
#align list.mem_of_mem_last' List.mem_of_mem_getLast?
theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l
| [], a, ha => (Option.not_mem_none a ha).elim
| [a], _, rfl => rfl
| a :: b :: l, c, hc => by
rw [getLast?_cons_cons] at hc
rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc]
#align list.init_append_last' List.dropLast_append_getLast?
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [a] => rfl
| [a, b] => rfl
| [a, b, c] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
#align list.ilast_eq_last' List.getLastI_eq_getLast?
@[simp]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], a, l₂ => rfl
| [b], a, l₂ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
#align list.last'_append_cons List.getLast?_append_cons
#align list.last'_cons_cons List.getLast?_cons_cons
theorem getLast?_append_of_ne_nil (l₁ : List α) :
∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂
| [], hl₂ => by contradiction
| b :: l₂, _ => getLast?_append_cons l₁ b l₂
#align list.last'_append_of_ne_nil List.getLast?_append_of_ne_nil
theorem getLast?_append {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
#align list.last'_append List.getLast?_append
/-! ### head(!?) and tail -/
@[simp]
theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl
@[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by
cases x <;> simp at h ⊢
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
#align list.head_eq_head' List.head!_eq_head?
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
#align list.surjective_head List.surjective_head!
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
#align list.surjective_head' List.surjective_head?
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
#align list.surjective_tail List.surjective_tail
theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l
| [], h => (Option.not_mem_none _ h).elim
| a :: l, h => by
simp only [head?, Option.mem_def, Option.some_inj] at h
exact h ▸ rfl
#align list.eq_cons_of_mem_head' List.eq_cons_of_mem_head?
theorem mem_of_mem_head? {x : α} {l : List α} (h : x ∈ l.head?) : x ∈ l :=
(eq_cons_of_mem_head? h).symm ▸ mem_cons_self _ _
#align list.mem_of_mem_head' List.mem_of_mem_head?
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
#align list.head_cons List.head!_cons
#align list.tail_nil List.tail_nil
#align list.tail_cons List.tail_cons
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
#align list.head_append List.head!_append
theorem head?_append {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
#align list.head'_append List.head?_append
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
#align list.head'_append_of_ne_nil List.head?_append_of_ne_nil
theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] := by
induction l
· contradiction
· rw [tail, cons_append, tail]
#align list.tail_append_singleton_of_ne_nil List.tail_append_singleton_of_ne_nil
theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l
| [], a, h => by contradiction
| b :: l, a, h => by
simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h
simp [h]
#align list.cons_head'_tail List.cons_head?_tail
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| a :: l, _ => rfl
#align list.head_mem_head' List.head!_mem_head?
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
#align list.cons_head_tail List.cons_head!_tail
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' := mem_cons_self l.head! l.tail
rwa [cons_head!_tail h] at h'
#align list.head_mem_self List.head!_mem_self
theorem head_mem {l : List α} : ∀ (h : l ≠ nil), l.head h ∈ l := by
cases l <;> simp
@[simp]
theorem head?_map (f : α → β) (l) : head? (map f l) = (head? l).map f := by cases l <;> rfl
#align list.head'_map List.head?_map
theorem tail_append_of_ne_nil (l l' : List α) (h : l ≠ []) : (l ++ l').tail = l.tail ++ l' := by
cases l
· contradiction
· simp
#align list.tail_append_of_ne_nil List.tail_append_of_ne_nil
#align list.nth_le_eq_iff List.get_eq_iff
theorem get_eq_get? (l : List α) (i : Fin l.length) :
l.get i = (l.get? i).get (by simp [get?_eq_get]) := by
simp [get_eq_iff]
#align list.some_nth_le_eq List.get?_eq_get
section deprecated
set_option linter.deprecated false -- TODO(Mario): make replacements for theorems in this section
/-- nth element of a list `l` given `n < l.length`. -/
@[deprecated get (since := "2023-01-05")]
def nthLe (l : List α) (n) (h : n < l.length) : α := get l ⟨n, h⟩
#align list.nth_le List.nthLe
@[simp] theorem nthLe_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.nthLe i h = l.nthLe (i + 1) h' := by
cases l <;> [cases h; rfl]
#align list.nth_le_tail List.nthLe_tail
theorem nthLe_cons_aux {l : List α} {a : α} {n} (hn : n ≠ 0) (h : n < (a :: l).length) :
n - 1 < l.length := by
contrapose! h
rw [length_cons]
omega
#align list.nth_le_cons_aux List.nthLe_cons_aux
theorem nthLe_cons {l : List α} {a : α} {n} (hl) :
(a :: l).nthLe n hl = if hn : n = 0 then a else l.nthLe (n - 1) (nthLe_cons_aux hn hl) := by
split_ifs with h
· simp [nthLe, h]
cases l
· rw [length_singleton, Nat.lt_succ_iff] at hl
omega
cases n
· contradiction
rfl
#align list.nth_le_cons List.nthLe_cons
end deprecated
-- Porting note: List.modifyHead has @[simp], and Lean 4 treats this as
-- an invitation to unfold modifyHead in any context,
-- not just use the equational lemmas.
-- @[simp]
@[simp 1100, nolint simpNF]
theorem modifyHead_modifyHead (l : List α) (f g : α → α) :
(l.modifyHead f).modifyHead g = l.modifyHead (g ∘ f) := by cases l <;> simp
#align list.modify_head_modify_head List.modifyHead_modifyHead
/-! ### Induction from the right -/
/-- Induction principle from the right for lists: if a property holds for the empty list, and
for `l ++ [a]` if it holds for `l`, then it holds for all lists. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
@[elab_as_elim]
def reverseRecOn {motive : List α → Sort*} (l : List α) (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) : motive l :=
match h : reverse l with
| [] => cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <|
nil
| head :: tail =>
cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <|
append_singleton _ head <| reverseRecOn (reverse tail) nil append_singleton
termination_by l.length
decreasing_by
simp_wf
rw [← length_reverse l, h, length_cons]
simp [Nat.lt_succ]
#align list.reverse_rec_on List.reverseRecOn
@[simp]
theorem reverseRecOn_nil {motive : List α → Sort*} (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) :
reverseRecOn [] nil append_singleton = nil := reverseRecOn.eq_1 ..
-- `unusedHavesSuffices` is getting confused by the unfolding of `reverseRecOn`
@[simp, nolint unusedHavesSuffices]
theorem reverseRecOn_concat {motive : List α → Sort*} (x : α) (xs : List α) (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) :
reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton =
append_singleton _ _ (reverseRecOn (motive := motive) xs nil append_singleton) := by
suffices ∀ ys (h : reverse (reverse xs) = ys),
reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton =
cast (by simp [(reverse_reverse _).symm.trans h])
(append_singleton _ x (reverseRecOn (motive := motive) ys nil append_singleton)) by
exact this _ (reverse_reverse xs)
intros ys hy
conv_lhs => unfold reverseRecOn
split
next h => simp at h
next heq =>
revert heq
simp only [reverse_append, reverse_cons, reverse_nil, nil_append, singleton_append, cons.injEq]
rintro ⟨rfl, rfl⟩
subst ys
rfl
/-- Bidirectional induction principle for lists: if a property holds for the empty list, the
singleton list, and `a :: (l ++ [b])` from `l`, then it holds for all lists. This can be used to
prove statements about palindromes. The principle is given for a `Sort`-valued predicate, i.e., it
can also be used to construct data. -/
@[elab_as_elim]
def bidirectionalRec {motive : List α → Sort*} (nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) :
∀ l, motive l
| [] => nil
| [a] => singleton a
| a :: b :: l =>
let l' := dropLast (b :: l)
let b' := getLast (b :: l) (cons_ne_nil _ _)
cast (by rw [← dropLast_append_getLast (cons_ne_nil b l)]) <|
cons_append a l' b' (bidirectionalRec nil singleton cons_append l')
termination_by l => l.length
#align list.bidirectional_rec List.bidirectionalRecₓ -- universe order
@[simp]
theorem bidirectionalRec_nil {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) :
bidirectionalRec nil singleton cons_append [] = nil := bidirectionalRec.eq_1 ..
@[simp]
theorem bidirectionalRec_singleton {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) (a : α):
bidirectionalRec nil singleton cons_append [a] = singleton a := by
simp [bidirectionalRec]
@[simp]
theorem bidirectionalRec_cons_append {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b])))
(a : α) (l : List α) (b : α) :
bidirectionalRec nil singleton cons_append (a :: (l ++ [b])) =
cons_append a l b (bidirectionalRec nil singleton cons_append l) := by
conv_lhs => unfold bidirectionalRec
cases l with
| nil => rfl
| cons x xs =>
simp only [List.cons_append]
dsimp only [← List.cons_append]
suffices ∀ (ys init : List α) (hinit : init = ys) (last : α) (hlast : last = b),
(cons_append a init last
(bidirectionalRec nil singleton cons_append init)) =
cast (congr_arg motive <| by simp [hinit, hlast])
(cons_append a ys b (bidirectionalRec nil singleton cons_append ys)) by
rw [this (x :: xs) _ (by rw [dropLast_append_cons, dropLast_single, append_nil]) _ (by simp)]
simp
rintro ys init rfl last rfl
rfl
/-- Like `bidirectionalRec`, but with the list parameter placed first. -/
@[elab_as_elim]
abbrev bidirectionalRecOn {C : List α → Sort*} (l : List α) (H0 : C []) (H1 : ∀ a : α, C [a])
(Hn : ∀ (a : α) (l : List α) (b : α), C l → C (a :: (l ++ [b]))) : C l :=
bidirectionalRec H0 H1 Hn l
#align list.bidirectional_rec_on List.bidirectionalRecOn
/-! ### sublists -/
attribute [refl] List.Sublist.refl
#align list.nil_sublist List.nil_sublist
#align list.sublist.refl List.Sublist.refl
#align list.sublist.trans List.Sublist.trans
#align list.sublist_cons List.sublist_cons
#align list.sublist_of_cons_sublist List.sublist_of_cons_sublist
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
#align list.sublist.cons_cons List.Sublist.cons_cons
#align list.sublist_append_left List.sublist_append_left
#align list.sublist_append_right List.sublist_append_right
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
#align list.sublist_cons_of_sublist List.sublist_cons_of_sublist
#align list.sublist_append_of_sublist_left List.sublist_append_of_sublist_left
#align list.sublist_append_of_sublist_right List.sublist_append_of_sublist_right
theorem tail_sublist : ∀ l : List α, tail l <+ l
| [] => .slnil
| a::l => sublist_cons a l
#align list.tail_sublist List.tail_sublist
@[gcongr] protected theorem Sublist.tail : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → tail l₁ <+ tail l₂
| _, _, slnil => .slnil
| _, _, Sublist.cons _ h => (tail_sublist _).trans h
| _, _, Sublist.cons₂ _ h => h
theorem Sublist.of_cons_cons {l₁ l₂ : List α} {a b : α} (h : a :: l₁ <+ b :: l₂) : l₁ <+ l₂ :=
h.tail
#align list.sublist_of_cons_sublist_cons List.Sublist.of_cons_cons
@[deprecated (since := "2024-04-07")]
theorem sublist_of_cons_sublist_cons {a} (h : a :: l₁ <+ a :: l₂) : l₁ <+ l₂ := h.of_cons_cons
attribute [simp] cons_sublist_cons
@[deprecated (since := "2024-04-07")] alias cons_sublist_cons_iff := cons_sublist_cons
#align list.cons_sublist_cons_iff List.cons_sublist_cons_iff
#align list.append_sublist_append_left List.append_sublist_append_left
#align list.sublist.append_right List.Sublist.append_right
#align list.sublist_or_mem_of_sublist List.sublist_or_mem_of_sublist
#align list.sublist.reverse List.Sublist.reverse
#align list.reverse_sublist_iff List.reverse_sublist
#align list.append_sublist_append_right List.append_sublist_append_right
#align list.sublist.append List.Sublist.append
#align list.sublist.subset List.Sublist.subset
#align list.singleton_sublist List.singleton_sublist
theorem eq_nil_of_sublist_nil {l : List α} (s : l <+ []) : l = [] :=
eq_nil_of_subset_nil <| s.subset
#align list.eq_nil_of_sublist_nil List.eq_nil_of_sublist_nil
-- Porting note: this lemma seems to have been renamed on the occasion of its move to Batteries
alias sublist_nil_iff_eq_nil := sublist_nil
#align list.sublist_nil_iff_eq_nil List.sublist_nil_iff_eq_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
#align list.replicate_sublist_replicate List.replicate_sublist_replicate
theorem sublist_replicate_iff {l : List α} {a : α} {n : ℕ} :
l <+ replicate n a ↔ ∃ k ≤ n, l = replicate k a :=
⟨fun h =>
⟨l.length, h.length_le.trans_eq (length_replicate _ _),
eq_replicate_length.mpr fun b hb => eq_of_mem_replicate (h.subset hb)⟩,
by rintro ⟨k, h, rfl⟩; exact (replicate_sublist_replicate _).mpr h⟩
#align list.sublist_replicate_iff List.sublist_replicate_iff
#align list.sublist.eq_of_length List.Sublist.eq_of_length
#align list.sublist.eq_of_length_le List.Sublist.eq_of_length_le
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
#align list.sublist.antisymm List.Sublist.antisymm
instance decidableSublist [DecidableEq α] : ∀ l₁ l₂ : List α, Decidable (l₁ <+ l₂)
| [], _ => isTrue <| nil_sublist _
| _ :: _, [] => isFalse fun h => List.noConfusion <| eq_nil_of_sublist_nil h
| a :: l₁, b :: l₂ =>
if h : a = b then
@decidable_of_decidable_of_iff _ _ (decidableSublist l₁ l₂) <| h ▸ cons_sublist_cons.symm
else
@decidable_of_decidable_of_iff _ _ (decidableSublist (a :: l₁) l₂)
⟨sublist_cons_of_sublist _, fun s =>
match a, l₁, s, h with
| _, _, Sublist.cons _ s', h => s'
| _, _, Sublist.cons₂ t _, h => absurd rfl h⟩
#align list.decidable_sublist List.decidableSublist
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
#align list.index_of_nil List.indexOf_nil
/-
Porting note: The following proofs were simpler prior to the port. These proofs use the low-level
`findIdx.go`.
* `indexOf_cons_self`
* `indexOf_cons_eq`
* `indexOf_cons_ne`
* `indexOf_cons`
The ported versions of the earlier proofs are given in comments.
-/
-- indexOf_cons_eq _ rfl
@[simp]
theorem indexOf_cons_self (a : α) (l : List α) : indexOf a (a :: l) = 0 := by
rw [indexOf, findIdx_cons, beq_self_eq_true, cond]
#align list.index_of_cons_self List.indexOf_cons_self
-- fun e => if_pos e
theorem indexOf_cons_eq {a b : α} (l : List α) : b = a → indexOf a (b :: l) = 0
| e => by rw [← e]; exact indexOf_cons_self b l
#align list.index_of_cons_eq List.indexOf_cons_eq
-- fun n => if_neg n
@[simp]
theorem indexOf_cons_ne {a b : α} (l : List α) : b ≠ a → indexOf a (b :: l) = succ (indexOf a l)
| h => by simp only [indexOf, findIdx_cons, Bool.cond_eq_ite, beq_iff_eq, h, ite_false]
#align list.index_of_cons_ne List.indexOf_cons_ne
#align list.index_of_cons List.indexOf_cons
theorem indexOf_eq_length {a : α} {l : List α} : indexOf a l = length l ↔ a ∉ l := by
induction' l with b l ih
· exact iff_of_true rfl (not_mem_nil _)
simp only [length, mem_cons, indexOf_cons, eq_comm]
rw [cond_eq_if]
split_ifs with h <;> simp at h
· exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm
· simp only [Ne.symm h, false_or_iff]
rw [← ih]
exact succ_inj'
#align list.index_of_eq_length List.indexOf_eq_length
@[simp]
theorem indexOf_of_not_mem {l : List α} {a : α} : a ∉ l → indexOf a l = length l :=
indexOf_eq_length.2
#align list.index_of_of_not_mem List.indexOf_of_not_mem
theorem indexOf_le_length {a : α} {l : List α} : indexOf a l ≤ length l := by
induction' l with b l ih; · rfl
simp only [length, indexOf_cons, cond_eq_if, beq_iff_eq]
by_cases h : b = a
· rw [if_pos h]; exact Nat.zero_le _
· rw [if_neg h]; exact succ_le_succ ih
#align list.index_of_le_length List.indexOf_le_length
theorem indexOf_lt_length {a} {l : List α} : indexOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.by_contradiction fun al => Nat.ne_of_lt h <| indexOf_eq_length.2 al,
fun al => (lt_of_le_of_ne indexOf_le_length) fun h => indexOf_eq_length.1 h al⟩
#align list.index_of_lt_length List.indexOf_lt_length
theorem indexOf_append_of_mem {a : α} (h : a ∈ l₁) : indexOf a (l₁ ++ l₂) = indexOf a l₁ := by
induction' l₁ with d₁ t₁ ih
· exfalso
exact not_mem_nil a h
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [indexOf_cons_eq _ hh]
rw [indexOf_cons_ne _ hh, indexOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
#align list.index_of_append_of_mem List.indexOf_append_of_mem
theorem indexOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
indexOf a (l₁ ++ l₂) = l₁.length + indexOf a l₂ := by
induction' l₁ with d₁ t₁ ih
· rw [List.nil_append, List.length, Nat.zero_add]
rw [List.cons_append, indexOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
#align list.index_of_append_of_not_mem List.indexOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
set_option linter.deprecated false
@[deprecated get_of_mem (since := "2023-01-05")]
theorem nthLe_of_mem {a} {l : List α} (h : a ∈ l) : ∃ n h, nthLe l n h = a :=
let ⟨i, h⟩ := get_of_mem h; ⟨i.1, i.2, h⟩
#align list.nth_le_of_mem List.nthLe_of_mem
@[deprecated get?_eq_get (since := "2023-01-05")]
theorem nthLe_get? {l : List α} {n} (h) : get? l n = some (nthLe l n h) := get?_eq_get _
#align list.nth_le_nth List.nthLe_get?
#align list.nth_len_le List.get?_len_le
@[simp]
theorem get?_length (l : List α) : l.get? l.length = none := get?_len_le le_rfl
#align list.nth_length List.get?_length
#align list.nth_eq_some List.get?_eq_some
#align list.nth_eq_none_iff List.get?_eq_none
#align list.nth_of_mem List.get?_of_mem
@[deprecated get_mem (since := "2023-01-05")]
theorem nthLe_mem (l : List α) (n h) : nthLe l n h ∈ l := get_mem ..
#align list.nth_le_mem List.nthLe_mem
#align list.nth_mem List.get?_mem
@[deprecated mem_iff_get (since := "2023-01-05")]
theorem mem_iff_nthLe {a} {l : List α} : a ∈ l ↔ ∃ n h, nthLe l n h = a :=
mem_iff_get.trans ⟨fun ⟨⟨n, h⟩, e⟩ => ⟨n, h, e⟩, fun ⟨n, h, e⟩ => ⟨⟨n, h⟩, e⟩⟩
#align list.mem_iff_nth_le List.mem_iff_nthLe
#align list.mem_iff_nth List.mem_iff_get?
#align list.nth_zero List.get?_zero
@[deprecated (since := "2024-05-03")] alias get?_injective := get?_inj
#align list.nth_injective List.get?_inj
#align list.nth_map List.get?_map
@[deprecated get_map (since := "2023-01-05")]
theorem nthLe_map (f : α → β) {l n} (H1 H2) : nthLe (map f l) n H1 = f (nthLe l n H2) := get_map ..
#align list.nth_le_map List.nthLe_map
/-- A version of `get_map` that can be used for rewriting. -/
theorem get_map_rev (f : α → β) {l n} :
f (get l n) = get (map f l) ⟨n.1, (l.length_map f).symm ▸ n.2⟩ := Eq.symm (get_map _)
/-- A version of `nthLe_map` that can be used for rewriting. -/
@[deprecated get_map_rev (since := "2023-01-05")]
theorem nthLe_map_rev (f : α → β) {l n} (H) :
f (nthLe l n H) = nthLe (map f l) n ((l.length_map f).symm ▸ H) :=
(nthLe_map f _ _).symm
#align list.nth_le_map_rev List.nthLe_map_rev
@[simp, deprecated get_map (since := "2023-01-05")]
theorem nthLe_map' (f : α → β) {l n} (H) :
nthLe (map f l) n H = f (nthLe l n (l.length_map f ▸ H)) := nthLe_map f _ _
#align list.nth_le_map' List.nthLe_map'
#align list.nth_le_of_eq List.get_of_eq
@[simp, deprecated get_singleton (since := "2023-01-05")]
theorem nthLe_singleton (a : α) {n : ℕ} (hn : n < 1) : nthLe [a] n hn = a := get_singleton ..
#align list.nth_le_singleton List.get_singleton
#align list.nth_le_zero List.get_mk_zero
#align list.nth_le_append List.get_append
@[deprecated get_append_right' (since := "2023-01-05")]
theorem nthLe_append_right {l₁ l₂ : List α} {n : ℕ} (h₁ : l₁.length ≤ n) (h₂) :
(l₁ ++ l₂).nthLe n h₂ = l₂.nthLe (n - l₁.length) (get_append_right_aux h₁ h₂) :=
get_append_right' h₁ h₂
#align list.nth_le_append_right_aux List.get_append_right_aux
#align list.nth_le_append_right List.nthLe_append_right
#align list.nth_le_replicate List.get_replicate
#align list.nth_append List.get?_append
#align list.nth_append_right List.get?_append_right
#align list.last_eq_nth_le List.getLast_eq_get
theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) :
l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) :=
(getLast_eq_get l _).symm
#align list.nth_le_length_sub_one List.get_length_sub_one
#align list.nth_concat_length List.get?_concat_length
@[deprecated get_cons_length (since := "2023-01-05")]
theorem nthLe_cons_length : ∀ (x : α) (xs : List α) (n : ℕ) (h : n = xs.length),
(x :: xs).nthLe n (by simp [h]) = (x :: xs).getLast (cons_ne_nil x xs) := get_cons_length
#align list.nth_le_cons_length List.nthLe_cons_length
theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) :
(l.drop n).take 1 = [l.get ⟨n, h⟩] := by
rw [drop_eq_get_cons h, take, take]
#align list.take_one_drop_eq_of_lt_length List.take_one_drop_eq_of_lt_length
#align list.ext List.ext
-- TODO one may rename ext in the standard library, and it is also not clear
-- which of ext_get?, ext_get?', ext_get should be @[ext], if any
alias ext_get? := ext
theorem ext_get?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n) :
l₁ = l₂ := by
apply ext
intro n
rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn
· exact h' n hn
· simp_all [Nat.max_le, get?_eq_none.mpr]
theorem ext_get?_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n, l₁.get? n = l₂.get? n :=
⟨by rintro rfl _; rfl, ext_get?⟩
theorem ext_get_iff {l₁ l₂ : List α} :
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by
constructor
· rintro rfl
exact ⟨rfl, fun _ _ _ ↦ rfl⟩
· intro ⟨h₁, h₂⟩
exact ext_get h₁ h₂
theorem ext_get?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n :=
⟨by rintro rfl _ _; rfl, ext_get?'⟩
@[deprecated ext_get (since := "2023-01-05")]
theorem ext_nthLe {l₁ l₂ : List α} (hl : length l₁ = length l₂)
(h : ∀ n h₁ h₂, nthLe l₁ n h₁ = nthLe l₂ n h₂) : l₁ = l₂ :=
ext_get hl h
#align list.ext_le List.ext_nthLe
@[simp]
theorem indexOf_get [DecidableEq α] {a : α} : ∀ {l : List α} (h), get l ⟨indexOf a l, h⟩ = a
| b :: l, h => by
by_cases h' : b = a <;>
simp only [h', if_pos, if_false, indexOf_cons, get, @indexOf_get _ _ l, cond_eq_if, beq_iff_eq]
#align list.index_of_nth_le List.indexOf_get
@[simp]
theorem indexOf_get? [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
get? l (indexOf a l) = some a := by rw [get?_eq_get, indexOf_get (indexOf_lt_length.2 h)]
#align list.index_of_nth List.indexOf_get?
@[deprecated (since := "2023-01-05")]
theorem get_reverse_aux₁ :
∀ (l r : List α) (i h1 h2), get (reverseAux l r) ⟨i + length l, h1⟩ = get r ⟨i, h2⟩
| [], r, i => fun h1 _ => rfl
| a :: l, r, i => by
rw [show i + length (a :: l) = i + 1 + length l from Nat.add_right_comm i (length l) 1]
exact fun h1 h2 => get_reverse_aux₁ l (a :: r) (i + 1) h1 (succ_lt_succ h2)
#align list.nth_le_reverse_aux1 List.get_reverse_aux₁
theorem indexOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
indexOf x l = indexOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨indexOf x l, indexOf_lt_length.2 hx⟩ =
get l ⟨indexOf y l, indexOf_lt_length.2 hy⟩ := by
simp only [h]
simp only [indexOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
#align list.index_of_inj List.indexOf_inj
theorem get_reverse_aux₂ :
∀ (l r : List α) (i : Nat) (h1) (h2),
get (reverseAux l r) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩
| [], r, i, h1, h2 => absurd h2 (Nat.not_lt_zero _)
| a :: l, r, 0, h1, _ => by
have aux := get_reverse_aux₁ l (a :: r) 0
rw [Nat.zero_add] at aux
exact aux _ (zero_lt_succ _)
| a :: l, r, i + 1, h1, h2 => by
have aux := get_reverse_aux₂ l (a :: r) i
have heq : length (a :: l) - 1 - (i + 1) = length l - 1 - i := by rw [length]; omega
rw [← heq] at aux
apply aux
#align list.nth_le_reverse_aux2 List.get_reverse_aux₂
@[simp] theorem get_reverse (l : List α) (i : Nat) (h1 h2) :
get (reverse l) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩ :=
get_reverse_aux₂ _ _ _ _ _
@[simp, deprecated get_reverse (since := "2023-01-05")]
theorem nthLe_reverse (l : List α) (i : Nat) (h1 h2) :
nthLe (reverse l) (length l - 1 - i) h1 = nthLe l i h2 :=
get_reverse ..
#align list.nth_le_reverse List.nthLe_reverse
theorem nthLe_reverse' (l : List α) (n : ℕ) (hn : n < l.reverse.length) (hn') :
l.reverse.nthLe n hn = l.nthLe (l.length - 1 - n) hn' := by
rw [eq_comm]
convert nthLe_reverse l.reverse n (by simpa) hn using 1
simp
#align list.nth_le_reverse' List.nthLe_reverse'
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := nthLe_reverse' ..
-- FIXME: prove it the other way around
attribute [deprecated get_reverse' (since := "2023-01-05")] nthLe_reverse'
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) :
l = [l.nthLe 0 (by omega)] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp only [get_singleton]
congr
omega
#align list.eq_cons_of_length_one List.eq_cons_of_length_one
end deprecated
theorem modifyNthTail_modifyNthTail {f g : List α → List α} (m : ℕ) :
∀ (n) (l : List α),
(l.modifyNthTail f n).modifyNthTail g (m + n) =
l.modifyNthTail (fun l => (f l).modifyNthTail g m) n
| 0, _ => rfl
| _ + 1, [] => rfl
| n + 1, a :: l => congr_arg (List.cons a) (modifyNthTail_modifyNthTail m n l)
#align list.modify_nth_tail_modify_nth_tail List.modifyNthTail_modifyNthTail
theorem modifyNthTail_modifyNthTail_le {f g : List α → List α} (m n : ℕ) (l : List α)
(h : n ≤ m) :
(l.modifyNthTail f n).modifyNthTail g m =
l.modifyNthTail (fun l => (f l).modifyNthTail g (m - n)) n := by
rcases Nat.exists_eq_add_of_le h with ⟨m, rfl⟩
rw [Nat.add_comm, modifyNthTail_modifyNthTail, Nat.add_sub_cancel]
#align list.modify_nth_tail_modify_nth_tail_le List.modifyNthTail_modifyNthTail_le
theorem modifyNthTail_modifyNthTail_same {f g : List α → List α} (n : ℕ) (l : List α) :
(l.modifyNthTail f n).modifyNthTail g n = l.modifyNthTail (g ∘ f) n := by
rw [modifyNthTail_modifyNthTail_le n n l (le_refl n), Nat.sub_self]; rfl
#align list.modify_nth_tail_modify_nth_tail_same List.modifyNthTail_modifyNthTail_same
#align list.modify_nth_tail_id List.modifyNthTail_id
#align list.remove_nth_eq_nth_tail List.eraseIdx_eq_modifyNthTail
#align list.update_nth_eq_modify_nth List.set_eq_modifyNth
@[deprecated (since := "2024-05-04")] alias removeNth_eq_nthTail := eraseIdx_eq_modifyNthTail
theorem modifyNth_eq_set (f : α → α) :
∀ (n) (l : List α), modifyNth f n l = ((fun a => set l n (f a)) <$> get? l n).getD l
| 0, l => by cases l <;> rfl
| n + 1, [] => rfl
| n + 1, b :: l =>
(congr_arg (cons b) (modifyNth_eq_set f n l)).trans <| by cases h : get? l n <;> simp [h]
#align list.modify_nth_eq_update_nth List.modifyNth_eq_set
#align list.nth_modify_nth List.get?_modifyNth
theorem length_modifyNthTail (f : List α → List α) (H : ∀ l, length (f l) = length l) :
∀ n l, length (modifyNthTail f n l) = length l
| 0, _ => H _
| _ + 1, [] => rfl
| _ + 1, _ :: _ => @congr_arg _ _ _ _ (· + 1) (length_modifyNthTail _ H _ _)
#align list.modify_nth_tail_length List.length_modifyNthTail
-- Porting note: Duplicate of `modify_get?_length`
-- (but with a substantially better name?)
-- @[simp]
theorem length_modifyNth (f : α → α) : ∀ n l, length (modifyNth f n l) = length l :=
modify_get?_length f
#align list.modify_nth_length List.length_modifyNth
#align list.update_nth_length List.length_set
#align list.nth_modify_nth_eq List.get?_modifyNth_eq
#align list.nth_modify_nth_ne List.get?_modifyNth_ne
#align list.nth_update_nth_eq List.get?_set_eq
#align list.nth_update_nth_of_lt List.get?_set_eq_of_lt
#align list.nth_update_nth_ne List.get?_set_ne
#align list.update_nth_nil List.set_nil
#align list.update_nth_succ List.set_succ
#align list.update_nth_comm List.set_comm
#align list.nth_le_update_nth_eq List.get_set_eq
@[simp]
theorem get_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a).get ⟨j, hj⟩ = l.get ⟨j, by simpa using hj⟩ := by
rw [← Option.some_inj, ← List.get?_eq_get, List.get?_set_ne _ _ h, List.get?_eq_get]
#align list.nth_le_update_nth_of_ne List.get_set_of_ne
#align list.mem_or_eq_of_mem_update_nth List.mem_or_eq_of_mem_set
/-! ### map -/
#align list.map_nil List.map_nil
theorem map_eq_foldr (f : α → β) (l : List α) : map f l = foldr (fun a bs => f a :: bs) [] l := by
induction l <;> simp [*]
#align list.map_eq_foldr List.map_eq_foldr
theorem map_congr {f g : α → β} : ∀ {l : List α}, (∀ x ∈ l, f x = g x) → map f l = map g l
| [], _ => rfl
| a :: l, h => by
let ⟨h₁, h₂⟩ := forall_mem_cons.1 h
rw [map, map, h₁, map_congr h₂]
#align list.map_congr List.map_congr
theorem map_eq_map_iff {f g : α → β} {l : List α} : map f l = map g l ↔ ∀ x ∈ l, f x = g x := by
refine ⟨?_, map_congr⟩; intro h x hx
rw [mem_iff_get] at hx; rcases hx with ⟨n, hn, rfl⟩
rw [get_map_rev f, get_map_rev g]
congr!
#align list.map_eq_map_iff List.map_eq_map_iff
theorem map_concat (f : α → β) (a : α) (l : List α) :
map f (concat l a) = concat (map f l) (f a) := by
induction l <;> [rfl; simp only [*, concat_eq_append, cons_append, map, map_append]]
#align list.map_concat List.map_concat
#align list.map_id'' List.map_id'
theorem map_id'' {f : α → α} (h : ∀ x, f x = x) (l : List α) : map f l = l := by
simp [show f = id from funext h]
#align list.map_id' List.map_id''
theorem eq_nil_of_map_eq_nil {f : α → β} {l : List α} (h : map f l = nil) : l = nil :=
eq_nil_of_length_eq_zero <| by rw [← length_map l f, h]; rfl
#align list.eq_nil_of_map_eq_nil List.eq_nil_of_map_eq_nil
@[simp]
theorem map_join (f : α → β) (L : List (List α)) : map f (join L) = join (map (map f) L) := by
induction L <;> [rfl; simp only [*, join, map, map_append]]
#align list.map_join List.map_join
theorem bind_pure_eq_map (f : α → β) (l : List α) : l.bind (pure ∘ f) = map f l :=
.symm <| map_eq_bind ..
#align list.bind_ret_eq_map List.bind_pure_eq_map
set_option linter.deprecated false in
@[deprecated bind_pure_eq_map (since := "2024-03-24")]
theorem bind_ret_eq_map (f : α → β) (l : List α) : l.bind (List.ret ∘ f) = map f l :=
bind_pure_eq_map f l
theorem bind_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
List.bind l f = List.bind l g :=
(congr_arg List.join <| map_congr h : _)
#align list.bind_congr List.bind_congr
theorem infix_bind_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.bind f :=
List.infix_of_mem_join (List.mem_map_of_mem f h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
#align list.map_eq_map List.map_eq_map
@[simp]
theorem map_tail (f : α → β) (l) : map f (tail l) = tail (map f l) := by cases l <;> rfl
#align list.map_tail List.map_tail
/-- A single `List.map` of a composition of functions is equal to
composing a `List.map` with another `List.map`, fully applied.
This is the reverse direction of `List.map_map`.
-/
theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) :=
(map_map _ _ _).symm
#align list.comp_map List.comp_map
/-- Composing a `List.map` with another `List.map` is equal to
a single `List.map` of composed functions.
-/
@[simp]
theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by
ext l; rw [comp_map, Function.comp_apply]
#align list.map_comp_map List.map_comp_map
section map_bijectivity
theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) :
LeftInverse (map f) (map g)
| [] => by simp_rw [map_nil]
| x :: xs => by simp_rw [map_cons, h x, h.list_map xs]
nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α}
(h : RightInverse f g) : RightInverse (map f) (map g) :=
h.list_map
nonrec theorem _root_.Function.Involutive.list_map {f : α → α}
(h : Involutive f) : Involutive (map f) :=
Function.LeftInverse.list_map h
@[simp]
theorem map_leftInverse_iff {f : α → β} {g : β → α} :
LeftInverse (map f) (map g) ↔ LeftInverse f g :=
⟨fun h x => by injection h [x], (·.list_map)⟩
@[simp]
theorem map_rightInverse_iff {f : α → β} {g : β → α} :
RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff
@[simp]
theorem map_involutive_iff {f : α → α} :
Involutive (map f) ↔ Involutive f := map_leftInverse_iff
theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) :
Injective (map f)
| [], [], _ => rfl
| x :: xs, y :: ys, hxy => by
injection hxy with hxy hxys
rw [h hxy, h.list_map hxys]
@[simp]
theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by
refine ⟨fun h x y hxy => ?_, (·.list_map)⟩
suffices [x] = [y] by simpa using this
apply h
simp [hxy]
#align list.map_injective_iff List.map_injective_iff
theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) :
Surjective (map f) :=
let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective
@[simp]
theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by
refine ⟨fun h x => ?_, (·.list_map)⟩
let ⟨[y], hxy⟩ := h [x]
exact ⟨_, List.singleton_injective hxy⟩
theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) :=
⟨h.1.list_map, h.2.list_map⟩
@[simp]
theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by
simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff]
end map_bijectivity
theorem map_filter_eq_foldr (f : α → β) (p : α → Bool) (as : List α) :
map f (filter p as) = foldr (fun a bs => bif p a then f a :: bs else bs) [] as := by
induction' as with head tail
· rfl
· simp only [foldr]
cases hp : p head <;> simp [filter, *]
#align list.map_filter_eq_foldr List.map_filter_eq_foldr
theorem getLast_map (f : α → β) {l : List α} (hl : l ≠ []) :
(l.map f).getLast (mt eq_nil_of_map_eq_nil hl) = f (l.getLast hl) := by
induction' l with l_hd l_tl l_ih
· apply (hl rfl).elim
· cases l_tl
· simp
· simpa using l_ih _
#align list.last_map List.getLast_map
theorem map_eq_replicate_iff {l : List α} {f : α → β} {b : β} :
l.map f = replicate l.length b ↔ ∀ x ∈ l, f x = b := by
simp [eq_replicate]
#align list.map_eq_replicate_iff List.map_eq_replicate_iff
@[simp] theorem map_const (l : List α) (b : β) : map (const α b) l = replicate l.length b :=
map_eq_replicate_iff.mpr fun _ _ => rfl
#align list.map_const List.map_const
@[simp] theorem map_const' (l : List α) (b : β) : map (fun _ => b) l = replicate l.length b :=
map_const l b
#align list.map_const' List.map_const'
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) :
b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h
#align list.eq_of_mem_map_const List.eq_of_mem_map_const
/-! ### zipWith -/
theorem nil_zipWith (f : α → β → γ) (l : List β) : zipWith f [] l = [] := by cases l <;> rfl
#align list.nil_map₂ List.nil_zipWith
theorem zipWith_nil (f : α → β → γ) (l : List α) : zipWith f l [] = [] := by cases l <;> rfl
#align list.map₂_nil List.zipWith_nil
@[simp]
theorem zipWith_flip (f : α → β → γ) : ∀ as bs, zipWith (flip f) bs as = zipWith f as bs
| [], [] => rfl
| [], b :: bs => rfl
| a :: as, [] => rfl
| a :: as, b :: bs => by
simp! [zipWith_flip]
rfl
#align list.map₂_flip List.zipWith_flip
/-! ### take, drop -/
#align list.take_zero List.take_zero
#align list.take_nil List.take_nil
theorem take_cons (n) (a : α) (l : List α) : take (succ n) (a :: l) = a :: take n l :=
rfl
#align list.take_cons List.take_cons
#align list.take_length List.take_length
#align list.take_all_of_le List.take_all_of_le
#align list.take_left List.take_left
#align list.take_left' List.take_left'
#align list.take_take List.take_take
#align list.take_replicate List.take_replicate
#align list.map_take List.map_take
#align list.take_append_eq_append_take List.take_append_eq_append_take
#align list.take_append_of_le_length List.take_append_of_le_length
#align list.take_append List.take_append
#align list.nth_le_take List.get_take
#align list.nth_le_take' List.get_take'
#align list.nth_take List.get?_take
#align list.nth_take_of_succ List.nth_take_of_succ
#align list.take_succ List.take_succ
#align list.take_eq_nil_iff List.take_eq_nil_iff
#align list.take_eq_take List.take_eq_take
#align list.take_add List.take_add
#align list.init_eq_take List.dropLast_eq_take
#align list.init_take List.dropLast_take
#align list.init_cons_of_ne_nil List.dropLast_cons_of_ne_nil
#align list.init_append_of_ne_nil List.dropLast_append_of_ne_nil
#align list.drop_eq_nil_of_le List.drop_eq_nil_of_le
#align list.drop_eq_nil_iff_le List.drop_eq_nil_iff_le
#align list.tail_drop List.tail_drop
@[simp]
theorem drop_tail (l : List α) (n : ℕ) : l.tail.drop n = l.drop (n + 1) := by
rw [drop_add, drop_one]
theorem cons_get_drop_succ {l : List α} {n} :
l.get n :: l.drop (n.1 + 1) = l.drop n.1 :=
(drop_eq_get_cons n.2).symm
#align list.cons_nth_le_drop_succ List.cons_get_drop_succ
#align list.drop_nil List.drop_nil
#align list.drop_one List.drop_one
#align list.drop_add List.drop_add
#align list.drop_left List.drop_left
#align list.drop_left' List.drop_left'
#align list.drop_eq_nth_le_cons List.drop_eq_get_consₓ -- nth_le vs get
#align list.drop_length List.drop_length
#align list.drop_length_cons List.drop_length_cons
#align list.drop_append_eq_append_drop List.drop_append_eq_append_drop
#align list.drop_append_of_le_length List.drop_append_of_le_length
#align list.drop_append List.drop_append
#align list.drop_sizeof_le List.drop_sizeOf_le
#align list.nth_le_drop List.get_drop
#align list.nth_le_drop' List.get_drop'
#align list.nth_drop List.get?_drop
#align list.drop_drop List.drop_drop
#align list.drop_take List.drop_take
#align list.map_drop List.map_drop
#align list.modify_nth_tail_eq_take_drop List.modifyNthTail_eq_take_drop
#align list.modify_nth_eq_take_drop List.modifyNth_eq_take_drop
#align list.modify_nth_eq_take_cons_drop List.modifyNth_eq_take_cons_drop
#align list.update_nth_eq_take_cons_drop List.set_eq_take_cons_drop
#align list.reverse_take List.reverse_take
#align list.update_nth_eq_nil List.set_eq_nil
section TakeI
variable [Inhabited α]
@[simp]
theorem takeI_length : ∀ n l, length (@takeI α _ n l) = n
| 0, _ => rfl
| _ + 1, _ => congr_arg succ (takeI_length _ _)
#align list.take'_length List.takeI_length
@[simp]
theorem takeI_nil : ∀ n, takeI n (@nil α) = replicate n default
| 0 => rfl
| _ + 1 => congr_arg (cons _) (takeI_nil _)
#align list.take'_nil List.takeI_nil
theorem takeI_eq_take : ∀ {n} {l : List α}, n ≤ length l → takeI n l = take n l
| 0, _, _ => rfl
| _ + 1, _ :: _, h => congr_arg (cons _) <| takeI_eq_take <| le_of_succ_le_succ h
#align list.take'_eq_take List.takeI_eq_take
@[simp]
theorem takeI_left (l₁ l₂ : List α) : takeI (length l₁) (l₁ ++ l₂) = l₁ :=
(takeI_eq_take (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _)
#align list.take'_left List.takeI_left
theorem takeI_left' {l₁ l₂ : List α} {n} (h : length l₁ = n) : takeI n (l₁ ++ l₂) = l₁ := by
rw [← h]; apply takeI_left
#align list.take'_left' List.takeI_left'
end TakeI
/- Porting note: in mathlib3 we just had `take` and `take'`. Now we have `take`, `takeI`, and
`takeD`. The following section replicates the theorems above but for `takeD`. -/
section TakeD
@[simp]
theorem takeD_length : ∀ n l a, length (@takeD α n l a) = n
| 0, _, _ => rfl
| _ + 1, _, _ => congr_arg succ (takeD_length _ _ _)
-- Porting note: `takeD_nil` is already in std
theorem takeD_eq_take : ∀ {n} {l : List α} a, n ≤ length l → takeD n l a = take n l
| 0, _, _, _ => rfl
| _ + 1, _ :: _, a, h => congr_arg (cons _) <| takeD_eq_take a <| le_of_succ_le_succ h
@[simp]
theorem takeD_left (l₁ l₂ : List α) (a : α) : takeD (length l₁) (l₁ ++ l₂) a = l₁ :=
(takeD_eq_take a (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _)
theorem takeD_left' {l₁ l₂ : List α} {n} {a} (h : length l₁ = n) : takeD n (l₁ ++ l₂) a = l₁ := by
rw [← h]; apply takeD_left
end TakeD
/-! ### foldl, foldr -/
theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l := by
induction l generalizing a with
| nil => rfl
| cons hd tl ih =>
unfold foldl
rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd (mem_cons_self _ _)]
#align list.foldl_ext List.foldl_ext
theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l := by
induction' l with hd tl ih; · rfl
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
#align list.foldr_ext List.foldr_ext
#align list.foldl_nil List.foldl_nil
#align list.foldl_cons List.foldl_cons
#align list.foldr_nil List.foldr_nil
#align list.foldr_cons List.foldr_cons
#align list.foldl_append List.foldl_append
#align list.foldr_append List.foldr_append
theorem foldl_concat
(f : β → α → β) (b : β) (x : α) (xs : List α) :
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by
simp only [List.foldl_append, List.foldl]
theorem foldr_concat
(f : α → β → β) (b : β) (x : α) (xs : List α) :
List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by
simp only [List.foldr_append, List.foldr]
theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a
| [] => rfl
| b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l]
#align list.foldl_fixed' List.foldl_fixed'
theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b
| [] => rfl
| a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a]
#align list.foldr_fixed' List.foldr_fixed'
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
#align list.foldl_fixed List.foldl_fixed
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
#align list.foldr_fixed List.foldr_fixed
@[simp]
theorem foldl_join (f : α → β → α) :
∀ (a : α) (L : List (List β)), foldl f a (join L) = foldl (foldl f) a L
| a, [] => rfl
| a, l :: L => by simp only [join, foldl_append, foldl_cons, foldl_join f (foldl f a l) L]
#align list.foldl_join List.foldl_join
@[simp]
theorem foldr_join (f : α → β → β) :
∀ (b : β) (L : List (List α)), foldr f b (join L) = foldr (fun l b => foldr f b l) b L
| a, [] => rfl
| a, l :: L => by simp only [join, foldr_append, foldr_join f a L, foldr_cons]
#align list.foldr_join List.foldr_join
#align list.foldl_reverse List.foldl_reverse
#align list.foldr_reverse List.foldr_reverse
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem foldr_eta : ∀ l : List α, foldr cons [] l = l := by
simp only [foldr_self_append, append_nil, forall_const]
#align list.foldr_eta List.foldr_eta
@[simp]
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
rw [← foldr_reverse]; simp only [foldr_self_append, append_nil, reverse_reverse]
#align list.reverse_foldl List.reverse_foldl
#align list.foldl_map List.foldl_map
#align list.foldr_map List.foldr_map
theorem foldl_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α)
(h : ∀ x y, f' (g x) (g y) = g (f x y)) :
List.foldl f' (g a) (l.map g) = g (List.foldl f a l) := by
induction l generalizing a
· simp
· simp [*, h]
#align list.foldl_map' List.foldl_map'
theorem foldr_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α)
(h : ∀ x y, f' (g x) (g y) = g (f x y)) :
List.foldr f' (g a) (l.map g) = g (List.foldr f a l) := by
induction l generalizing a
· simp
· simp [*, h]
#align list.foldr_map' List.foldr_map'
#align list.foldl_hom List.foldl_hom
#align list.foldr_hom List.foldr_hom
theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) :
foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) :=
Eq.symm <| by
revert a b
induction l <;> intros <;> [rfl; simp only [*, foldl]]
#align list.foldl_hom₂ List.foldl_hom₂
theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) :
foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by
revert a
induction l <;> intros <;> [rfl; simp only [*, foldr]]
#align list.foldr_hom₂ List.foldr_hom₂
theorem injective_foldl_comp {l : List (α → α)} {f : α → α}
(hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) :
Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by
induction' l with lh lt l_ih generalizing f
· exact hf
· apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ (List.mem_cons_self _ _)
#align list.injective_foldl_comp List.injective_foldl_comp
/-- Induction principle for values produced by a `foldr`: if a property holds
for the seed element `b : β` and for all incremental `op : α → β → β`
performed on the elements `(a : α) ∈ l`. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
def foldrRecOn {C : β → Sort*} (l : List α) (op : α → β → β) (b : β) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ l, C (op a b)) : C (foldr op b l) := by
induction l with
| nil => exact hb
| cons hd tl IH =>
refine hl _ ?_ hd (mem_cons_self hd tl)
refine IH ?_
intro y hy x hx
exact hl y hy x (mem_cons_of_mem hd hx)
#align list.foldr_rec_on List.foldrRecOn
/-- Induction principle for values produced by a `foldl`: if a property holds
for the seed element `b : β` and for all incremental `op : β → α → β`
performed on the elements `(a : α) ∈ l`. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
def foldlRecOn {C : β → Sort*} (l : List α) (op : β → α → β) (b : β) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ l, C (op b a)) : C (foldl op b l) := by
induction l generalizing b with
| nil => exact hb
| cons hd tl IH =>
refine IH _ ?_ ?_
· exact hl b hb hd (mem_cons_self hd tl)
· intro y hy x hx
exact hl y hy x (mem_cons_of_mem hd hx)
#align list.foldl_rec_on List.foldlRecOn
@[simp]
theorem foldrRecOn_nil {C : β → Sort*} (op : α → β → β) (b) (hb : C b) (hl) :
foldrRecOn [] op b hb hl = hb :=
rfl
#align list.foldr_rec_on_nil List.foldrRecOn_nil
@[simp]
theorem foldrRecOn_cons {C : β → Sort*} (x : α) (l : List α) (op : α → β → β) (b) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ x :: l, C (op a b)) :
foldrRecOn (x :: l) op b hb hl =
hl _ (foldrRecOn l op b hb fun b hb a ha => hl b hb a (mem_cons_of_mem _ ha)) x
(mem_cons_self _ _) :=
rfl
#align list.foldr_rec_on_cons List.foldrRecOn_cons
@[simp]
theorem foldlRecOn_nil {C : β → Sort*} (op : β → α → β) (b) (hb : C b) (hl) :
foldlRecOn [] op b hb hl = hb :=
rfl
#align list.foldl_rec_on_nil List.foldlRecOn_nil
/-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them:
`l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`.
Assume the designated element `a₂` is present in neither `x₁` nor `z₁`.
We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal
(`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/
lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α}
(notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) :
x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by
constructor
· simp only [append_eq_append_iff, cons_eq_append, cons_eq_cons]
rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ |
⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all
· rintro ⟨rfl, rfl, rfl⟩
rfl
section Scanl
variable {f : β → α → β} {b : β} {a : α} {l : List α}
theorem length_scanl : ∀ a l, length (scanl f a l) = l.length + 1
| a, [] => rfl
| a, x :: l => by
rw [scanl, length_cons, length_cons, ← succ_eq_add_one, congr_arg succ]
exact length_scanl _ _
#align list.length_scanl List.length_scanl
@[simp]
theorem scanl_nil (b : β) : scanl f b nil = [b] :=
rfl
#align list.scanl_nil List.scanl_nil
@[simp]
theorem scanl_cons : scanl f b (a :: l) = [b] ++ scanl f (f b a) l := by
simp only [scanl, eq_self_iff_true, singleton_append, and_self_iff]
#align list.scanl_cons List.scanl_cons
@[simp]
| Mathlib/Data/List/Basic.lean | 2,052 | 2,055 | theorem get?_zero_scanl : (scanl f b l).get? 0 = some b := by |
cases l
· simp only [get?, scanl_nil]
· simp only [get?, scanl_cons, singleton_append]
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Finsupp.Basic
import Mathlib.Data.Finsupp.Order
#align_import data.finsupp.multiset from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf"
/-!
# Equivalence between `Multiset` and `ℕ`-valued finitely supported functions
This defines `Finsupp.toMultiset` the equivalence between `α →₀ ℕ` and `Multiset α`, along
with `Multiset.toFinsupp` the reverse equivalence and `Finsupp.orderIsoMultiset` the equivalence
promoted to an order isomorphism.
-/
open Finset
variable {α β ι : Type*}
namespace Finsupp
/-- Given `f : α →₀ ℕ`, `f.toMultiset` is the multiset with multiplicities given by the values of
`f` on the elements of `α`. We define this function as an `AddMonoidHom`.
Under the additional assumption of `[DecidableEq α]`, this is available as
`Multiset.toFinsupp : Multiset α ≃+ (α →₀ ℕ)`; the two declarations are separate as this assumption
is only needed for one direction. -/
def toMultiset : (α →₀ ℕ) →+ Multiset α where
toFun f := Finsupp.sum f fun a n => n • {a}
-- Porting note: times out if h is not specified
map_add' _f _g := sum_add_index' (h := fun a n => n • ({a} : Multiset α))
(fun _ ↦ zero_nsmul _) (fun _ ↦ add_nsmul _)
map_zero' := sum_zero_index
theorem toMultiset_zero : toMultiset (0 : α →₀ ℕ) = 0 :=
rfl
#align finsupp.to_multiset_zero Finsupp.toMultiset_zero
theorem toMultiset_add (m n : α →₀ ℕ) : toMultiset (m + n) = toMultiset m + toMultiset n :=
toMultiset.map_add m n
#align finsupp.to_multiset_add Finsupp.toMultiset_add
theorem toMultiset_apply (f : α →₀ ℕ) : toMultiset f = f.sum fun a n => n • {a} :=
rfl
#align finsupp.to_multiset_apply Finsupp.toMultiset_apply
@[simp]
theorem toMultiset_single (a : α) (n : ℕ) : toMultiset (single a n) = n • {a} := by
rw [toMultiset_apply, sum_single_index]; apply zero_nsmul
#align finsupp.to_multiset_single Finsupp.toMultiset_single
theorem toMultiset_sum {f : ι → α →₀ ℕ} (s : Finset ι) :
Finsupp.toMultiset (∑ i ∈ s, f i) = ∑ i ∈ s, Finsupp.toMultiset (f i) :=
map_sum Finsupp.toMultiset _ _
#align finsupp.to_multiset_sum Finsupp.toMultiset_sum
theorem toMultiset_sum_single (s : Finset ι) (n : ℕ) :
Finsupp.toMultiset (∑ i ∈ s, single i n) = n • s.val := by
simp_rw [toMultiset_sum, Finsupp.toMultiset_single, sum_nsmul, sum_multiset_singleton]
#align finsupp.to_multiset_sum_single Finsupp.toMultiset_sum_single
@[simp]
theorem card_toMultiset (f : α →₀ ℕ) : Multiset.card (toMultiset f) = f.sum fun _ => id := by
simp [toMultiset_apply, map_finsupp_sum, Function.id_def]
#align finsupp.card_to_multiset Finsupp.card_toMultiset
theorem toMultiset_map (f : α →₀ ℕ) (g : α → β) :
f.toMultiset.map g = toMultiset (f.mapDomain g) := by
refine f.induction ?_ ?_
· rw [toMultiset_zero, Multiset.map_zero, mapDomain_zero, toMultiset_zero]
· intro a n f _ _ ih
rw [toMultiset_add, Multiset.map_add, ih, mapDomain_add, mapDomain_single,
toMultiset_single, toMultiset_add, toMultiset_single, ← Multiset.coe_mapAddMonoidHom,
(Multiset.mapAddMonoidHom g).map_nsmul]
rfl
#align finsupp.to_multiset_map Finsupp.toMultiset_map
@[to_additive (attr := simp)]
| Mathlib/Data/Finsupp/Multiset.lean | 83 | 90 | theorem prod_toMultiset [CommMonoid α] (f : α →₀ ℕ) :
f.toMultiset.prod = f.prod fun a n => a ^ n := by |
refine f.induction ?_ ?_
· rw [toMultiset_zero, Multiset.prod_zero, Finsupp.prod_zero_index]
· intro a n f _ _ ih
rw [toMultiset_add, Multiset.prod_add, ih, toMultiset_single, Multiset.prod_nsmul,
Finsupp.prod_add_index' pow_zero pow_add, Finsupp.prod_single_index, Multiset.prod_singleton]
exact pow_zero a
|
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro,
Scott Morrison
-/
import Mathlib.Data.List.Basic
#align_import data.list.lattice from "leanprover-community/mathlib"@"dd71334db81d0bd444af1ee339a29298bef40734"
/-!
# Lattice structure of lists
This files prove basic properties about `List.disjoint`, `List.union`, `List.inter` and
`List.bagInter`, which are defined in core Lean and `Data.List.Defs`.
`l₁ ∪ l₂` is the list where all elements of `l₁` have been inserted in `l₂` in order. For example,
`[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [1, 2, 4, 3, 3, 0]`
`l₁ ∩ l₂` is the list of elements of `l₁` in order which are in `l₂`. For example,
`[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [0, 0, 3]`
`List.bagInter l₁ l₂` is the list of elements that are in both `l₁` and `l₂`,
counted with multiplicity and in the order they appear in `l₁`.
As opposed to `List.inter`, `List.bagInter` copes well with multiplicity. For example,
`bagInter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1]`
-/
open Nat
namespace List
variable {α : Type*} {l l₁ l₂ : List α} {p : α → Prop} {a : α}
/-! ### `Disjoint` -/
section Disjoint
@[symm]
theorem Disjoint.symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂
#align list.disjoint.symm List.Disjoint.symm
#align list.disjoint_comm List.disjoint_comm
#align list.disjoint_left List.disjoint_left
#align list.disjoint_right List.disjoint_right
#align list.disjoint_iff_ne List.disjoint_iff_ne
#align list.disjoint_of_subset_left List.disjoint_of_subset_leftₓ
#align list.disjoint_of_subset_right List.disjoint_of_subset_right
#align list.disjoint_of_disjoint_cons_left List.disjoint_of_disjoint_cons_left
#align list.disjoint_of_disjoint_cons_right List.disjoint_of_disjoint_cons_right
#align list.disjoint_nil_left List.disjoint_nil_left
#align list.disjoint_nil_right List.disjoint_nil_right
#align list.singleton_disjoint List.singleton_disjointₓ
#align list.disjoint_singleton List.disjoint_singleton
#align list.disjoint_append_left List.disjoint_append_leftₓ
#align list.disjoint_append_right List.disjoint_append_right
#align list.disjoint_cons_left List.disjoint_cons_leftₓ
#align list.disjoint_cons_right List.disjoint_cons_right
#align list.disjoint_of_disjoint_append_left_left List.disjoint_of_disjoint_append_left_leftₓ
#align list.disjoint_of_disjoint_append_left_right List.disjoint_of_disjoint_append_left_rightₓ
#align list.disjoint_of_disjoint_append_right_left List.disjoint_of_disjoint_append_right_left
#align list.disjoint_of_disjoint_append_right_right List.disjoint_of_disjoint_append_right_right
#align list.disjoint_take_drop List.disjoint_take_dropₓ
end Disjoint
variable [DecidableEq α]
/-! ### `union` -/
section Union
#align list.nil_union List.nil_union
#align list.cons_union List.cons_unionₓ
#align list.mem_union List.mem_union_iff
theorem mem_union_left (h : a ∈ l₁) (l₂ : List α) : a ∈ l₁ ∪ l₂ :=
mem_union_iff.2 (Or.inl h)
#align list.mem_union_left List.mem_union_left
theorem mem_union_right (l₁ : List α) (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ :=
mem_union_iff.2 (Or.inr h)
#align list.mem_union_right List.mem_union_right
theorem sublist_suffix_of_union : ∀ l₁ l₂ : List α, ∃ t, t <+ l₁ ∧ t ++ l₂ = l₁ ∪ l₂
| [], l₂ => ⟨[], by rfl, rfl⟩
| a :: l₁, l₂ =>
let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂
if h : a ∈ l₁ ∪ l₂ then
⟨t, sublist_cons_of_sublist _ s, by
simp only [e, cons_union, insert_of_mem h]⟩
else
⟨a :: t, s.cons_cons _, by
simp only [cons_append, cons_union, e, insert_of_not_mem h]⟩
#align list.sublist_suffix_of_union List.sublist_suffix_of_union
theorem suffix_union_right (l₁ l₂ : List α) : l₂ <:+ l₁ ∪ l₂ :=
(sublist_suffix_of_union l₁ l₂).imp fun _ => And.right
#align list.suffix_union_right List.suffix_union_right
theorem union_sublist_append (l₁ l₂ : List α) : l₁ ∪ l₂ <+ l₁ ++ l₂ :=
let ⟨_, s, e⟩ := sublist_suffix_of_union l₁ l₂
e ▸ (append_sublist_append_right _).2 s
#align list.union_sublist_append List.union_sublist_append
theorem forall_mem_union : (∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ ∀ x ∈ l₂, p x := by
simp only [mem_union_iff, or_imp, forall_and]
#align list.forall_mem_union List.forall_mem_union
theorem forall_mem_of_forall_mem_union_left (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x :=
(forall_mem_union.1 h).1
#align list.forall_mem_of_forall_mem_union_left List.forall_mem_of_forall_mem_union_left
theorem forall_mem_of_forall_mem_union_right (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x :=
(forall_mem_union.1 h).2
#align list.forall_mem_of_forall_mem_union_right List.forall_mem_of_forall_mem_union_right
end Union
/-! ### `inter` -/
section Inter
@[simp]
theorem inter_nil (l : List α) : [] ∩ l = [] :=
rfl
#align list.inter_nil List.inter_nil
@[simp]
theorem inter_cons_of_mem (l₁ : List α) (h : a ∈ l₂) : (a :: l₁) ∩ l₂ = a :: l₁ ∩ l₂ := by
simp [Inter.inter, List.inter, h]
#align list.inter_cons_of_mem List.inter_cons_of_mem
@[simp]
theorem inter_cons_of_not_mem (l₁ : List α) (h : a ∉ l₂) : (a :: l₁) ∩ l₂ = l₁ ∩ l₂ := by
simp [Inter.inter, List.inter, h]
#align list.inter_cons_of_not_mem List.inter_cons_of_not_mem
theorem mem_of_mem_inter_left : a ∈ l₁ ∩ l₂ → a ∈ l₁ :=
mem_of_mem_filter
#align list.mem_of_mem_inter_left List.mem_of_mem_inter_left
theorem mem_of_mem_inter_right (h : a ∈ l₁ ∩ l₂) : a ∈ l₂ := by simpa using of_mem_filter h
#align list.mem_of_mem_inter_right List.mem_of_mem_inter_right
theorem mem_inter_of_mem_of_mem (h₁ : a ∈ l₁) (h₂ : a ∈ l₂) : a ∈ l₁ ∩ l₂ :=
mem_filter_of_mem h₁ <| by simpa using h₂
#align list.mem_inter_of_mem_of_mem List.mem_inter_of_mem_of_mem
#align list.mem_inter List.mem_inter_iff
theorem inter_subset_left {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₁ :=
filter_subset _
#align list.inter_subset_left List.inter_subset_left
theorem inter_subset_right {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₂ := fun _ => mem_of_mem_inter_right
#align list.inter_subset_right List.inter_subset_right
theorem subset_inter {l l₁ l₂ : List α} (h₁ : l ⊆ l₁) (h₂ : l ⊆ l₂) : l ⊆ l₁ ∩ l₂ := fun _ h =>
mem_inter_iff.2 ⟨h₁ h, h₂ h⟩
#align list.subset_inter List.subset_inter
theorem inter_eq_nil_iff_disjoint : l₁ ∩ l₂ = [] ↔ Disjoint l₁ l₂ := by
simp only [eq_nil_iff_forall_not_mem, mem_inter_iff, not_and]
rfl
#align list.inter_eq_nil_iff_disjoint List.inter_eq_nil_iff_disjoint
theorem forall_mem_inter_of_forall_left (h : ∀ x ∈ l₁, p x) (l₂ : List α) :
∀ x, x ∈ l₁ ∩ l₂ → p x :=
BAll.imp_left (fun _ => mem_of_mem_inter_left) h
#align list.forall_mem_inter_of_forall_left List.forall_mem_inter_of_forall_left
theorem forall_mem_inter_of_forall_right (l₁ : List α) (h : ∀ x ∈ l₂, p x) :
∀ x, x ∈ l₁ ∩ l₂ → p x :=
BAll.imp_left (fun _ => mem_of_mem_inter_right) h
#align list.forall_mem_inter_of_forall_right List.forall_mem_inter_of_forall_right
@[simp]
theorem inter_reverse {xs ys : List α} : xs.inter ys.reverse = xs.inter ys := by
simp only [List.inter, elem_eq_mem, mem_reverse]
#align list.inter_reverse List.inter_reverse
end Inter
/-! ### `bagInter` -/
section BagInter
@[simp]
| Mathlib/Data/List/Lattice.lean | 195 | 195 | theorem nil_bagInter (l : List α) : [].bagInter l = [] := by | cases l <;> rfl
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yourong Zang
-/
import Mathlib.Analysis.Calculus.ContDiff.Basic
import Mathlib.Analysis.Calculus.Deriv.Linear
import Mathlib.Analysis.Complex.Conformal
import Mathlib.Analysis.Calculus.Conformal.NormedSpace
#align_import analysis.complex.real_deriv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-! # Real differentiability of complex-differentiable functions
`HasDerivAt.real_of_complex` expresses that, if a function on `ℂ` is differentiable (over `ℂ`),
then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the
complex derivative.
`DifferentiableAt.conformalAt` states that a real-differentiable function with a nonvanishing
differential from the complex plane into an arbitrary complex-normed space is conformal at a point
if it's holomorphic at that point. This is a version of Cauchy-Riemann equations.
`conformalAt_iff_differentiableAt_or_differentiableAt_comp_conj` proves that a real-differential
function with a nonvanishing differential between the complex plane is conformal at a point if and
only if it's holomorphic or antiholomorphic at that point.
## TODO
* The classical form of Cauchy-Riemann equations
* On a connected open set `u`, a function which is `ConformalAt` each point is either holomorphic
throughout or antiholomorphic throughout.
## Warning
We do NOT require conformal functions to be orientation-preserving in this file.
-/
section RealDerivOfComplex
/-! ### Differentiability of the restriction to `ℝ` of complex functions -/
open Complex
variable {e : ℂ → ℂ} {e' : ℂ} {z : ℝ}
/-- If a complex function is differentiable at a real point, then the induced real function is also
differentiable at this point, with a derivative equal to the real part of the complex derivative. -/
theorem HasStrictDerivAt.real_of_complex (h : HasStrictDerivAt e e' z) :
HasStrictDerivAt (fun x : ℝ => (e x).re) e'.re z := by
have A : HasStrictFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasStrictFDerivAt
have B :
HasStrictFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ)
(ofRealCLM z) :=
h.hasStrictFDerivAt.restrictScalars ℝ
have C : HasStrictFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasStrictFDerivAt
-- Porting note: this should be by:
-- simpa using (C.comp z (B.comp z A)).hasStrictDerivAt
-- but for some reason simp can not use `ContinuousLinearMap.comp_apply`
convert (C.comp z (B.comp z A)).hasStrictDerivAt
rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply]
simp
#align has_strict_deriv_at.real_of_complex HasStrictDerivAt.real_of_complex
/-- If a complex function `e` is differentiable at a real point, then the function `ℝ → ℝ` given by
the real part of `e` is also differentiable at this point, with a derivative equal to the real part
of the complex derivative. -/
theorem HasDerivAt.real_of_complex (h : HasDerivAt e e' z) :
HasDerivAt (fun x : ℝ => (e x).re) e'.re z := by
have A : HasFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasFDerivAt
have B :
HasFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ)
(ofRealCLM z) :=
h.hasFDerivAt.restrictScalars ℝ
have C : HasFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasFDerivAt
-- Porting note: this should be by:
-- simpa using (C.comp z (B.comp z A)).hasStrictDerivAt
-- but for some reason simp can not use `ContinuousLinearMap.comp_apply`
convert (C.comp z (B.comp z A)).hasDerivAt
rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply]
simp
#align has_deriv_at.real_of_complex HasDerivAt.real_of_complex
theorem ContDiffAt.real_of_complex {n : ℕ∞} (h : ContDiffAt ℂ n e z) :
ContDiffAt ℝ n (fun x : ℝ => (e x).re) z := by
have A : ContDiffAt ℝ n ((↑) : ℝ → ℂ) z := ofRealCLM.contDiff.contDiffAt
have B : ContDiffAt ℝ n e z := h.restrict_scalars ℝ
have C : ContDiffAt ℝ n re (e z) := reCLM.contDiff.contDiffAt
exact C.comp z (B.comp z A)
#align cont_diff_at.real_of_complex ContDiffAt.real_of_complex
theorem ContDiff.real_of_complex {n : ℕ∞} (h : ContDiff ℂ n e) :
ContDiff ℝ n fun x : ℝ => (e x).re :=
contDiff_iff_contDiffAt.2 fun _ => h.contDiffAt.real_of_complex
#align cont_diff.real_of_complex ContDiff.real_of_complex
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E]
theorem HasStrictDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E}
(h : HasStrictDerivAt f f' x) :
HasStrictFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by
simpa only [Complex.restrictScalars_one_smulRight'] using
h.hasStrictFDerivAt.restrictScalars ℝ
#align has_strict_deriv_at.complex_to_real_fderiv' HasStrictDerivAt.complexToReal_fderiv'
theorem HasDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasDerivAt f f' x) :
HasFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by
simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivAt.restrictScalars ℝ
#align has_deriv_at.complex_to_real_fderiv' HasDerivAt.complexToReal_fderiv'
theorem HasDerivWithinAt.complexToReal_fderiv' {f : ℂ → E} {s : Set ℂ} {x : ℂ} {f' : E}
(h : HasDerivWithinAt f f' s x) :
HasFDerivWithinAt f (reCLM.smulRight f' + I • imCLM.smulRight f') s x := by
simpa only [Complex.restrictScalars_one_smulRight'] using
h.hasFDerivWithinAt.restrictScalars ℝ
#align has_deriv_within_at.complex_to_real_fderiv' HasDerivWithinAt.complexToReal_fderiv'
theorem HasStrictDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasStrictDerivAt f f' x) :
HasStrictFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by
simpa only [Complex.restrictScalars_one_smulRight] using h.hasStrictFDerivAt.restrictScalars ℝ
#align has_strict_deriv_at.complex_to_real_fderiv HasStrictDerivAt.complexToReal_fderiv
theorem HasDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasDerivAt f f' x) :
HasFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by
simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivAt.restrictScalars ℝ
#align has_deriv_at.complex_to_real_fderiv HasDerivAt.complexToReal_fderiv
theorem HasDerivWithinAt.complexToReal_fderiv {f : ℂ → ℂ} {s : Set ℂ} {f' x : ℂ}
(h : HasDerivWithinAt f f' s x) : HasFDerivWithinAt f (f' • (1 : ℂ →L[ℝ] ℂ)) s x := by
simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivWithinAt.restrictScalars ℝ
#align has_deriv_within_at.complex_to_real_fderiv HasDerivWithinAt.complexToReal_fderiv
/-- If a complex function `e` is differentiable at a real point, then its restriction to `ℝ` is
differentiable there as a function `ℝ → ℂ`, with the same derivative. -/
theorem HasDerivAt.comp_ofReal (hf : HasDerivAt e e' ↑z) : HasDerivAt (fun y : ℝ => e ↑y) e' z := by
simpa only [ofRealCLM_apply, ofReal_one, mul_one] using hf.comp z ofRealCLM.hasDerivAt
#align has_deriv_at.comp_of_real HasDerivAt.comp_ofReal
/-- If a function `f : ℝ → ℝ` is differentiable at a (real) point `x`, then it is also
differentiable as a function `ℝ → ℂ`. -/
| Mathlib/Analysis/Complex/RealDeriv.lean | 141 | 144 | theorem HasDerivAt.ofReal_comp {f : ℝ → ℝ} {u : ℝ} (hf : HasDerivAt f u z) :
HasDerivAt (fun y : ℝ => ↑(f y) : ℝ → ℂ) u z := by |
simpa only [ofRealCLM_apply, ofReal_one, real_smul, mul_one] using
ofRealCLM.hasDerivAt.scomp z hf
|
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Order.CompleteLattice
import Mathlib.Order.GaloisConnection
import Mathlib.Data.Set.Lattice
import Mathlib.Tactic.AdaptationNote
#align_import data.rel from "leanprover-community/mathlib"@"706d88f2b8fdfeb0b22796433d7a6c1a010af9f2"
/-!
# Relations
This file defines bundled relations. A relation between `α` and `β` is a function `α → β → Prop`.
Relations are also known as set-valued functions, or partial multifunctions.
## Main declarations
* `Rel α β`: Relation between `α` and `β`.
* `Rel.inv`: `r.inv` is the `Rel β α` obtained by swapping the arguments of `r`.
* `Rel.dom`: Domain of a relation. `x ∈ r.dom` iff there exists `y` such that `r x y`.
* `Rel.codom`: Codomain, aka range, of a relation. `y ∈ r.codom` iff there exists `x` such that
`r x y`.
* `Rel.comp`: Relation composition. Note that the arguments order follows the `CategoryTheory/`
one, so `r.comp s x z ↔ ∃ y, r x y ∧ s y z`.
* `Rel.image`: Image of a set under a relation. `r.image s` is the set of `f x` over all `x ∈ s`.
* `Rel.preimage`: Preimage of a set under a relation. Note that `r.preimage = r.inv.image`.
* `Rel.core`: Core of a set. For `s : Set β`, `r.core s` is the set of `x : α` such that all `y`
related to `x` are in `s`.
* `Rel.restrict_domain`: Domain-restriction of a relation to a subtype.
* `Function.graph`: Graph of a function as a relation.
## TODOs
The `Rel.comp` function uses the notation `r • s`, rather than the more common `r ∘ s` for things
named `comp`. This is because the latter is already used for function composition, and causes a
clash. A better notation should be found, perhaps a variant of `r ∘r s` or `r; s`.
-/
variable {α β γ : Type*}
/-- A relation on `α` and `β`, aka a set-valued function, aka a partial multifunction -/
def Rel (α β : Type*) :=
α → β → Prop -- deriving CompleteLattice, Inhabited
#align rel Rel
-- Porting note: `deriving` above doesn't work.
instance : CompleteLattice (Rel α β) := show CompleteLattice (α → β → Prop) from inferInstance
instance : Inhabited (Rel α β) := show Inhabited (α → β → Prop) from inferInstance
namespace Rel
variable (r : Rel α β)
-- Porting note: required for later theorems.
@[ext] theorem ext {r s : Rel α β} : (∀ a, r a = s a) → r = s := funext
/-- The inverse relation : `r.inv x y ↔ r y x`. Note that this is *not* a groupoid inverse. -/
def inv : Rel β α :=
flip r
#align rel.inv Rel.inv
theorem inv_def (x : α) (y : β) : r.inv y x ↔ r x y :=
Iff.rfl
#align rel.inv_def Rel.inv_def
theorem inv_inv : inv (inv r) = r := by
ext x y
rfl
#align rel.inv_inv Rel.inv_inv
/-- Domain of a relation -/
def dom := { x | ∃ y, r x y }
#align rel.dom Rel.dom
theorem dom_mono {r s : Rel α β} (h : r ≤ s) : dom r ⊆ dom s := fun a ⟨b, hx⟩ => ⟨b, h a b hx⟩
#align rel.dom_mono Rel.dom_mono
/-- Codomain aka range of a relation -/
def codom := { y | ∃ x, r x y }
#align rel.codom Rel.codom
theorem codom_inv : r.inv.codom = r.dom := by
ext x
rfl
#align rel.codom_inv Rel.codom_inv
theorem dom_inv : r.inv.dom = r.codom := by
ext x
rfl
#align rel.dom_inv Rel.dom_inv
/-- Composition of relation; note that it follows the `CategoryTheory/` order of arguments. -/
def comp (r : Rel α β) (s : Rel β γ) : Rel α γ := fun x z => ∃ y, r x y ∧ s y z
#align rel.comp Rel.comp
-- Porting note: the original `∘` syntax can't be overloaded here, lean considers it ambiguous.
/-- Local syntax for composition of relations. -/
local infixr:90 " • " => Rel.comp
theorem comp_assoc {δ : Type*} (r : Rel α β) (s : Rel β γ) (t : Rel γ δ) :
(r • s) • t = r • (s • t) := by
unfold comp; ext (x w); constructor
· rintro ⟨z, ⟨y, rxy, syz⟩, tzw⟩; exact ⟨y, rxy, z, syz, tzw⟩
· rintro ⟨y, rxy, z, syz, tzw⟩; exact ⟨z, ⟨y, rxy, syz⟩, tzw⟩
#align rel.comp_assoc Rel.comp_assoc
@[simp]
theorem comp_right_id (r : Rel α β) : r • @Eq β = r := by
unfold comp
ext y
simp
#align rel.comp_right_id Rel.comp_right_id
@[simp]
theorem comp_left_id (r : Rel α β) : @Eq α • r = r := by
unfold comp
ext x
simp
#align rel.comp_left_id Rel.comp_left_id
@[simp]
theorem comp_right_bot (r : Rel α β) : r • (⊥ : Rel β γ) = ⊥ := by
ext x y
simp [comp, Bot.bot]
@[simp]
theorem comp_left_bot (r : Rel α β) : (⊥ : Rel γ α) • r = ⊥ := by
ext x y
simp [comp, Bot.bot]
@[simp]
theorem comp_right_top (r : Rel α β) : r • (⊤ : Rel β γ) = fun x _ ↦ x ∈ r.dom := by
ext x z
simp [comp, Top.top, dom]
@[simp]
theorem comp_left_top (r : Rel α β) : (⊤ : Rel γ α) • r = fun _ y ↦ y ∈ r.codom := by
ext x z
simp [comp, Top.top, codom]
theorem inv_id : inv (@Eq α) = @Eq α := by
ext x y
constructor <;> apply Eq.symm
#align rel.inv_id Rel.inv_id
theorem inv_comp (r : Rel α β) (s : Rel β γ) : inv (r • s) = inv s • inv r := by
ext x z
simp [comp, inv, flip, and_comm]
#align rel.inv_comp Rel.inv_comp
@[simp]
theorem inv_bot : (⊥ : Rel α β).inv = (⊥ : Rel β α) := by
#adaptation_note /-- nightly-2024-03-16: simp was `simp [Bot.bot, inv, flip]` -/
simp [Bot.bot, inv, Function.flip_def]
@[simp]
theorem inv_top : (⊤ : Rel α β).inv = (⊤ : Rel β α) := by
#adaptation_note /-- nightly-2024-03-16: simp was `simp [Top.top, inv, flip]` -/
simp [Top.top, inv, Function.flip_def]
/-- Image of a set under a relation -/
def image (s : Set α) : Set β := { y | ∃ x ∈ s, r x y }
#align rel.image Rel.image
theorem mem_image (y : β) (s : Set α) : y ∈ image r s ↔ ∃ x ∈ s, r x y :=
Iff.rfl
#align rel.mem_image Rel.mem_image
theorem image_subset : ((· ⊆ ·) ⇒ (· ⊆ ·)) r.image r.image := fun _ _ h _ ⟨x, xs, rxy⟩ =>
⟨x, h xs, rxy⟩
#align rel.image_subset Rel.image_subset
theorem image_mono : Monotone r.image :=
r.image_subset
#align rel.image_mono Rel.image_mono
theorem image_inter (s t : Set α) : r.image (s ∩ t) ⊆ r.image s ∩ r.image t :=
r.image_mono.map_inf_le s t
#align rel.image_inter Rel.image_inter
theorem image_union (s t : Set α) : r.image (s ∪ t) = r.image s ∪ r.image t :=
le_antisymm
(fun _y ⟨x, xst, rxy⟩ =>
xst.elim (fun xs => Or.inl ⟨x, ⟨xs, rxy⟩⟩) fun xt => Or.inr ⟨x, ⟨xt, rxy⟩⟩)
(r.image_mono.le_map_sup s t)
#align rel.image_union Rel.image_union
@[simp]
theorem image_id (s : Set α) : image (@Eq α) s = s := by
ext x
simp [mem_image]
#align rel.image_id Rel.image_id
| Mathlib/Data/Rel.lean | 198 | 201 | theorem image_comp (s : Rel β γ) (t : Set α) : image (r • s) t = image s (image r t) := by |
ext z; simp only [mem_image]; constructor
· rintro ⟨x, xt, y, rxy, syz⟩; exact ⟨y, ⟨x, xt, rxy⟩, syz⟩
· rintro ⟨y, ⟨x, xt, rxy⟩, syz⟩; exact ⟨x, xt, y, rxy, syz⟩
|
/-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Data.ZMod.Basic
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Polynomial.Chebyshev
import Mathlib.RingTheory.Ideal.LocalRing
#align_import ring_theory.polynomial.dickson from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a"
/-!
# Dickson polynomials
The (generalised) Dickson polynomials are a family of polynomials indexed by `ℕ × ℕ`,
with coefficients in a commutative ring `R` depending on an element `a∈R`. More precisely, the
they satisfy the recursion `dickson k a (n + 2) = X * (dickson k a n + 1) - a * (dickson k a n)`
with starting values `dickson k a 0 = 3 - k` and `dickson k a 1 = X`. In the literature,
`dickson k a n` is called the `n`-th Dickson polynomial of the `k`-th kind associated to the
parameter `a : R`. They are closely related to the Chebyshev polynomials in the case that `a=1`.
When `a=0` they are just the family of monomials `X ^ n`.
## Main definition
* `Polynomial.dickson`: the generalised Dickson polynomials.
## Main statements
* `Polynomial.dickson_one_one_mul`, the `(m * n)`-th Dickson polynomial of the first kind for
parameter `1 : R` is the composition of the `m`-th and `n`-th Dickson polynomials of the first
kind for `1 : R`.
* `Polynomial.dickson_one_one_charP`, for a prime number `p`, the `p`-th Dickson polynomial of the
first kind associated to parameter `1 : R` is congruent to `X ^ p` modulo `p`.
## References
* [R. Lidl, G. L. Mullen and G. Turnwald, _Dickson polynomials_][MR1237403]
## TODO
* Redefine `dickson` in terms of `LinearRecurrence`.
* Show that `dickson 2 1` is equal to the characteristic polynomial of the adjacency matrix of a
type A Dynkin diagram.
* Prove that the adjacency matrices of simply laced Dynkin diagrams are precisely the adjacency
matrices of simple connected graphs which annihilate `dickson 2 1`.
-/
noncomputable section
namespace Polynomial
open Polynomial
variable {R S : Type*} [CommRing R] [CommRing S] (k : ℕ) (a : R)
/-- `dickson` is the `n`-th (generalised) Dickson polynomial of the `k`-th kind associated to the
element `a ∈ R`. -/
noncomputable def dickson : ℕ → R[X]
| 0 => 3 - k
| 1 => X
| n + 2 => X * dickson (n + 1) - C a * dickson n
#align polynomial.dickson Polynomial.dickson
@[simp]
theorem dickson_zero : dickson k a 0 = 3 - k :=
rfl
#align polynomial.dickson_zero Polynomial.dickson_zero
@[simp]
theorem dickson_one : dickson k a 1 = X :=
rfl
#align polynomial.dickson_one Polynomial.dickson_one
theorem dickson_two : dickson k a 2 = X ^ 2 - C a * (3 - k : R[X]) := by
simp only [dickson, sq]
#align polynomial.dickson_two Polynomial.dickson_two
@[simp]
theorem dickson_add_two (n : ℕ) :
dickson k a (n + 2) = X * dickson k a (n + 1) - C a * dickson k a n := by rw [dickson]
#align polynomial.dickson_add_two Polynomial.dickson_add_two
| Mathlib/RingTheory/Polynomial/Dickson.lean | 86 | 90 | theorem dickson_of_two_le {n : ℕ} (h : 2 ≤ n) :
dickson k a n = X * dickson k a (n - 1) - C a * dickson k a (n - 2) := by |
obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h
rw [add_comm]
exact dickson_add_two k a n
|
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Measure.GiryMonad
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.MeasureTheory.Integral.Lebesgue
import Mathlib.MeasureTheory.Measure.OpenPos
#align_import measure_theory.constructions.prod.basic from "leanprover-community/mathlib"@"00abe0695d8767201e6d008afa22393978bb324d"
/-!
# The product measure
In this file we define and prove properties about the binary product measure. If `α` and `β` have
s-finite measures `μ` resp. `ν` then `α × β` can be equipped with a s-finite measure `μ.prod ν` that
satisfies `(μ.prod ν) s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ`.
We also have `(μ.prod ν) (s ×ˢ t) = μ s * ν t`, i.e. the measure of a rectangle is the product of
the measures of the sides.
We also prove Tonelli's theorem.
## Main definition
* `MeasureTheory.Measure.prod`: The product of two measures.
## Main results
* `MeasureTheory.Measure.prod_apply` states `μ.prod ν s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ`
for measurable `s`. `MeasureTheory.Measure.prod_apply_symm` is the reversed version.
* `MeasureTheory.Measure.prod_prod` states `μ.prod ν (s ×ˢ t) = μ s * ν t` for measurable sets
`s` and `t`.
* `MeasureTheory.lintegral_prod`: Tonelli's theorem. It states that for a measurable function
`α × β → ℝ≥0∞` we have `∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ`. The version
for functions `α → β → ℝ≥0∞` is reversed, and called `lintegral_lintegral`. Both versions have
a variant with `_symm` appended, where the order of integration is reversed.
The lemma `Measurable.lintegral_prod_right'` states that the inner integral of the right-hand side
is measurable.
## Implementation Notes
Many results are proven twice, once for functions in curried form (`α → β → γ`) and one for
functions in uncurried form (`α × β → γ`). The former often has an assumption
`Measurable (uncurry f)`, which could be inconvenient to discharge, but for the latter it is more
common that the function has to be given explicitly, since Lean cannot synthesize the function by
itself. We name the lemmas about the uncurried form with a prime.
Tonelli's theorem has a different naming scheme, since the version for the uncurried version is
reversed.
## Tags
product measure, Tonelli's theorem, Fubini-Tonelli theorem
-/
noncomputable section
open scoped Classical
open Topology ENNReal MeasureTheory
open Set Function Real ENNReal
open MeasureTheory MeasurableSpace MeasureTheory.Measure
open TopologicalSpace hiding generateFrom
open Filter hiding prod_eq map
variable {α α' β β' γ E : Type*}
/-- Rectangles formed by π-systems form a π-system. -/
theorem IsPiSystem.prod {C : Set (Set α)} {D : Set (Set β)} (hC : IsPiSystem C)
(hD : IsPiSystem D) : IsPiSystem (image2 (· ×ˢ ·) C D) := by
rintro _ ⟨s₁, hs₁, t₁, ht₁, rfl⟩ _ ⟨s₂, hs₂, t₂, ht₂, rfl⟩ hst
rw [prod_inter_prod] at hst ⊢; rw [prod_nonempty_iff] at hst
exact mem_image2_of_mem (hC _ hs₁ _ hs₂ hst.1) (hD _ ht₁ _ ht₂ hst.2)
#align is_pi_system.prod IsPiSystem.prod
/-- Rectangles of countably spanning sets are countably spanning. -/
theorem IsCountablySpanning.prod {C : Set (Set α)} {D : Set (Set β)} (hC : IsCountablySpanning C)
(hD : IsCountablySpanning D) : IsCountablySpanning (image2 (· ×ˢ ·) C D) := by
rcases hC, hD with ⟨⟨s, h1s, h2s⟩, t, h1t, h2t⟩
refine ⟨fun n => s n.unpair.1 ×ˢ t n.unpair.2, fun n => mem_image2_of_mem (h1s _) (h1t _), ?_⟩
rw [iUnion_unpair_prod, h2s, h2t, univ_prod_univ]
#align is_countably_spanning.prod IsCountablySpanning.prod
variable [MeasurableSpace α] [MeasurableSpace α'] [MeasurableSpace β] [MeasurableSpace β']
variable [MeasurableSpace γ]
variable {μ μ' : Measure α} {ν ν' : Measure β} {τ : Measure γ}
variable [NormedAddCommGroup E]
/-! ### Measurability
Before we define the product measure, we can talk about the measurability of operations on binary
functions. We show that if `f` is a binary measurable function, then the function that integrates
along one of the variables (using either the Lebesgue or Bochner integral) is measurable.
-/
/-- The product of generated σ-algebras is the one generated by rectangles, if both generating sets
are countably spanning. -/
theorem generateFrom_prod_eq {α β} {C : Set (Set α)} {D : Set (Set β)} (hC : IsCountablySpanning C)
(hD : IsCountablySpanning D) :
@Prod.instMeasurableSpace _ _ (generateFrom C) (generateFrom D) =
generateFrom (image2 (· ×ˢ ·) C D) := by
apply le_antisymm
· refine sup_le ?_ ?_ <;> rw [comap_generateFrom] <;> apply generateFrom_le <;>
rintro _ ⟨s, hs, rfl⟩
· rcases hD with ⟨t, h1t, h2t⟩
rw [← prod_univ, ← h2t, prod_iUnion]
apply MeasurableSet.iUnion
intro n
apply measurableSet_generateFrom
exact ⟨s, hs, t n, h1t n, rfl⟩
· rcases hC with ⟨t, h1t, h2t⟩
rw [← univ_prod, ← h2t, iUnion_prod_const]
apply MeasurableSet.iUnion
rintro n
apply measurableSet_generateFrom
exact mem_image2_of_mem (h1t n) hs
· apply generateFrom_le
rintro _ ⟨s, hs, t, ht, rfl⟩
dsimp only
rw [prod_eq]
apply (measurable_fst _).inter (measurable_snd _)
· exact measurableSet_generateFrom hs
· exact measurableSet_generateFrom ht
#align generate_from_prod_eq generateFrom_prod_eq
/-- If `C` and `D` generate the σ-algebras on `α` resp. `β`, then rectangles formed by `C` and `D`
generate the σ-algebra on `α × β`. -/
theorem generateFrom_eq_prod {C : Set (Set α)} {D : Set (Set β)} (hC : generateFrom C = ‹_›)
(hD : generateFrom D = ‹_›) (h2C : IsCountablySpanning C) (h2D : IsCountablySpanning D) :
generateFrom (image2 (· ×ˢ ·) C D) = Prod.instMeasurableSpace := by
rw [← hC, ← hD, generateFrom_prod_eq h2C h2D]
#align generate_from_eq_prod generateFrom_eq_prod
/-- The product σ-algebra is generated from boxes, i.e. `s ×ˢ t` for sets `s : Set α` and
`t : Set β`. -/
theorem generateFrom_prod :
generateFrom (image2 (· ×ˢ ·) { s : Set α | MeasurableSet s } { t : Set β | MeasurableSet t }) =
Prod.instMeasurableSpace :=
generateFrom_eq_prod generateFrom_measurableSet generateFrom_measurableSet
isCountablySpanning_measurableSet isCountablySpanning_measurableSet
#align generate_from_prod generateFrom_prod
/-- Rectangles form a π-system. -/
theorem isPiSystem_prod :
IsPiSystem (image2 (· ×ˢ ·) { s : Set α | MeasurableSet s } { t : Set β | MeasurableSet t }) :=
isPiSystem_measurableSet.prod isPiSystem_measurableSet
#align is_pi_system_prod isPiSystem_prod
/-- If `ν` is a finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }` is
a measurable function. `measurable_measure_prod_mk_left` is strictly more general. -/
theorem measurable_measure_prod_mk_left_finite [IsFiniteMeasure ν] {s : Set (α × β)}
(hs : MeasurableSet s) : Measurable fun x => ν (Prod.mk x ⁻¹' s) := by
refine induction_on_inter (C := fun s => Measurable fun x => ν (Prod.mk x ⁻¹' s))
generateFrom_prod.symm isPiSystem_prod ?_ ?_ ?_ ?_ hs
· simp
· rintro _ ⟨s, hs, t, _, rfl⟩
simp only [mk_preimage_prod_right_eq_if, measure_if]
exact measurable_const.indicator hs
· intro t ht h2t
simp_rw [preimage_compl, measure_compl (measurable_prod_mk_left ht) (measure_ne_top ν _)]
exact h2t.const_sub _
· intro f h1f h2f h3f
simp_rw [preimage_iUnion]
have : ∀ b, ν (⋃ i, Prod.mk b ⁻¹' f i) = ∑' i, ν (Prod.mk b ⁻¹' f i) := fun b =>
measure_iUnion (fun i j hij => Disjoint.preimage _ (h1f hij)) fun i =>
measurable_prod_mk_left (h2f i)
simp_rw [this]
apply Measurable.ennreal_tsum h3f
#align measurable_measure_prod_mk_left_finite measurable_measure_prod_mk_left_finite
/-- If `ν` is an s-finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }`
is a measurable function. -/
theorem measurable_measure_prod_mk_left [SFinite ν] {s : Set (α × β)} (hs : MeasurableSet s) :
Measurable fun x => ν (Prod.mk x ⁻¹' s) := by
rw [← sum_sFiniteSeq ν]
simp_rw [Measure.sum_apply_of_countable]
exact Measurable.ennreal_tsum (fun i ↦ measurable_measure_prod_mk_left_finite hs)
#align measurable_measure_prod_mk_left measurable_measure_prod_mk_left
/-- If `μ` is a σ-finite measure, and `s ⊆ α × β` is measurable, then `y ↦ μ { x | (x, y) ∈ s }` is
a measurable function. -/
theorem measurable_measure_prod_mk_right {μ : Measure α} [SFinite μ] {s : Set (α × β)}
(hs : MeasurableSet s) : Measurable fun y => μ ((fun x => (x, y)) ⁻¹' s) :=
measurable_measure_prod_mk_left (measurableSet_swap_iff.mpr hs)
#align measurable_measure_prod_mk_right measurable_measure_prod_mk_right
theorem Measurable.map_prod_mk_left [SFinite ν] :
Measurable fun x : α => map (Prod.mk x) ν := by
apply measurable_of_measurable_coe; intro s hs
simp_rw [map_apply measurable_prod_mk_left hs]
exact measurable_measure_prod_mk_left hs
#align measurable.map_prod_mk_left Measurable.map_prod_mk_left
theorem Measurable.map_prod_mk_right {μ : Measure α} [SFinite μ] :
Measurable fun y : β => map (fun x : α => (x, y)) μ := by
apply measurable_of_measurable_coe; intro s hs
simp_rw [map_apply measurable_prod_mk_right hs]
exact measurable_measure_prod_mk_right hs
#align measurable.map_prod_mk_right Measurable.map_prod_mk_right
theorem MeasurableEmbedding.prod_mk {α β γ δ : Type*} {mα : MeasurableSpace α}
{mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : α → β}
{g : γ → δ} (hg : MeasurableEmbedding g) (hf : MeasurableEmbedding f) :
MeasurableEmbedding fun x : γ × α => (g x.1, f x.2) := by
have h_inj : Function.Injective fun x : γ × α => (g x.fst, f x.snd) := by
intro x y hxy
rw [← @Prod.mk.eta _ _ x, ← @Prod.mk.eta _ _ y]
simp only [Prod.mk.inj_iff] at hxy ⊢
exact ⟨hg.injective hxy.1, hf.injective hxy.2⟩
refine ⟨h_inj, ?_, ?_⟩
· exact (hg.measurable.comp measurable_fst).prod_mk (hf.measurable.comp measurable_snd)
· -- Induction using the π-system of rectangles
refine fun s hs =>
@MeasurableSpace.induction_on_inter _
(fun s => MeasurableSet ((fun x : γ × α => (g x.fst, f x.snd)) '' s)) _ _
generateFrom_prod.symm isPiSystem_prod ?_ ?_ ?_ ?_ _ hs
· simp only [Set.image_empty, MeasurableSet.empty]
· rintro t ⟨t₁, ht₁, t₂, ht₂, rfl⟩
rw [← Set.prod_image_image_eq]
exact (hg.measurableSet_image.mpr ht₁).prod (hf.measurableSet_image.mpr ht₂)
· intro t _ ht_m
rw [← Set.range_diff_image h_inj, ← Set.prod_range_range_eq]
exact
MeasurableSet.diff (MeasurableSet.prod hg.measurableSet_range hf.measurableSet_range) ht_m
· intro g _ _ hg
simp_rw [Set.image_iUnion]
exact MeasurableSet.iUnion hg
#align measurable_embedding.prod_mk MeasurableEmbedding.prod_mk
lemma MeasurableEmbedding.prod_mk_left {β γ : Type*} [MeasurableSingletonClass α]
{mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
(x : α) {f : γ → β} (hf : MeasurableEmbedding f) :
MeasurableEmbedding (fun y ↦ (x, f y)) where
injective := by
intro y y'
simp only [Prod.mk.injEq, true_and]
exact fun h ↦ hf.injective h
measurable := Measurable.prod_mk measurable_const hf.measurable
measurableSet_image' := by
intro s hs
convert (MeasurableSet.singleton x).prod (hf.measurableSet_image.mpr hs)
ext x
simp
lemma measurableEmbedding_prod_mk_left [MeasurableSingletonClass α] (x : α) :
MeasurableEmbedding (Prod.mk x : β → α × β) :=
MeasurableEmbedding.prod_mk_left x MeasurableEmbedding.id
lemma MeasurableEmbedding.prod_mk_right {β γ : Type*} [MeasurableSingletonClass α]
{mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
{f : γ → β} (hf : MeasurableEmbedding f) (x : α) :
MeasurableEmbedding (fun y ↦ (f y, x)) where
injective := by
intro y y'
simp only [Prod.mk.injEq, and_true]
exact fun h ↦ hf.injective h
measurable := Measurable.prod_mk hf.measurable measurable_const
measurableSet_image' := by
intro s hs
convert (hf.measurableSet_image.mpr hs).prod (MeasurableSet.singleton x)
ext x
simp
lemma measurableEmbedding_prod_mk_right [MeasurableSingletonClass α] (x : α) :
MeasurableEmbedding (fun y ↦ (y, x) : β → β × α) :=
MeasurableEmbedding.prod_mk_right MeasurableEmbedding.id x
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable. -/
theorem Measurable.lintegral_prod_right' [SFinite ν] :
∀ {f : α × β → ℝ≥0∞}, Measurable f → Measurable fun x => ∫⁻ y, f (x, y) ∂ν := by
have m := @measurable_prod_mk_left
refine Measurable.ennreal_induction (P := fun f => Measurable fun (x : α) => ∫⁻ y, f (x, y) ∂ν)
?_ ?_ ?_
· intro c s hs
simp only [← indicator_comp_right]
suffices Measurable fun x => c * ν (Prod.mk x ⁻¹' s) by simpa [lintegral_indicator _ (m hs)]
exact (measurable_measure_prod_mk_left hs).const_mul _
· rintro f g - hf - h2f h2g
simp only [Pi.add_apply]
conv => enter [1, x]; erw [lintegral_add_left (hf.comp m)]
exact h2f.add h2g
· intro f hf h2f h3f
have := measurable_iSup h3f
have : ∀ x, Monotone fun n y => f n (x, y) := fun x i j hij y => h2f hij (x, y)
conv => enter [1, x]; erw [lintegral_iSup (fun n => (hf n).comp m) (this x)]
assumption
#align measurable.lintegral_prod_right' Measurable.lintegral_prod_right'
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
theorem Measurable.lintegral_prod_right [SFinite ν] {f : α → β → ℝ≥0∞}
(hf : Measurable (uncurry f)) : Measurable fun x => ∫⁻ y, f x y ∂ν :=
hf.lintegral_prod_right'
#align measurable.lintegral_prod_right Measurable.lintegral_prod_right
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable. -/
theorem Measurable.lintegral_prod_left' [SFinite μ] {f : α × β → ℝ≥0∞} (hf : Measurable f) :
Measurable fun y => ∫⁻ x, f (x, y) ∂μ :=
(measurable_swap_iff.mpr hf).lintegral_prod_right'
#align measurable.lintegral_prod_left' Measurable.lintegral_prod_left'
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
theorem Measurable.lintegral_prod_left [SFinite μ] {f : α → β → ℝ≥0∞}
(hf : Measurable (uncurry f)) : Measurable fun y => ∫⁻ x, f x y ∂μ :=
hf.lintegral_prod_left'
#align measurable.lintegral_prod_left Measurable.lintegral_prod_left
/-! ### The product measure -/
namespace MeasureTheory
namespace Measure
/-- The binary product of measures. They are defined for arbitrary measures, but we basically
prove all properties under the assumption that at least one of them is s-finite. -/
protected irreducible_def prod (μ : Measure α) (ν : Measure β) : Measure (α × β) :=
bind μ fun x : α => map (Prod.mk x) ν
#align measure_theory.measure.prod MeasureTheory.Measure.prod
instance prod.measureSpace {α β} [MeasureSpace α] [MeasureSpace β] : MeasureSpace (α × β) where
volume := volume.prod volume
#align measure_theory.measure.prod.measure_space MeasureTheory.Measure.prod.measureSpace
theorem volume_eq_prod (α β) [MeasureSpace α] [MeasureSpace β] :
(volume : Measure (α × β)) = (volume : Measure α).prod (volume : Measure β) :=
rfl
#align measure_theory.measure.volume_eq_prod MeasureTheory.Measure.volume_eq_prod
variable [SFinite ν]
theorem prod_apply {s : Set (α × β)} (hs : MeasurableSet s) :
μ.prod ν s = ∫⁻ x, ν (Prod.mk x ⁻¹' s) ∂μ := by
simp_rw [Measure.prod, bind_apply hs (Measurable.map_prod_mk_left (ν := ν)),
map_apply measurable_prod_mk_left hs]
#align measure_theory.measure.prod_apply MeasureTheory.Measure.prod_apply
/-- The product measure of the product of two sets is the product of their measures. Note that we
do not need the sets to be measurable. -/
@[simp]
theorem prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by
apply le_antisymm
· set S := toMeasurable μ s
set T := toMeasurable ν t
have hSTm : MeasurableSet (S ×ˢ T) :=
(measurableSet_toMeasurable _ _).prod (measurableSet_toMeasurable _ _)
calc
μ.prod ν (s ×ˢ t) ≤ μ.prod ν (S ×ˢ T) := by gcongr <;> apply subset_toMeasurable
_ = μ S * ν T := by
rw [prod_apply hSTm]
simp_rw [mk_preimage_prod_right_eq_if, measure_if,
lintegral_indicator _ (measurableSet_toMeasurable _ _), lintegral_const,
restrict_apply_univ, mul_comm]
_ = μ s * ν t := by rw [measure_toMeasurable, measure_toMeasurable]
· -- Formalization is based on https://mathoverflow.net/a/254134/136589
set ST := toMeasurable (μ.prod ν) (s ×ˢ t)
have hSTm : MeasurableSet ST := measurableSet_toMeasurable _ _
have hST : s ×ˢ t ⊆ ST := subset_toMeasurable _ _
set f : α → ℝ≥0∞ := fun x => ν (Prod.mk x ⁻¹' ST)
have hfm : Measurable f := measurable_measure_prod_mk_left hSTm
set s' : Set α := { x | ν t ≤ f x }
have hss' : s ⊆ s' := fun x hx => measure_mono fun y hy => hST <| mk_mem_prod hx hy
calc
μ s * ν t ≤ μ s' * ν t := by gcongr
_ = ∫⁻ _ in s', ν t ∂μ := by rw [set_lintegral_const, mul_comm]
_ ≤ ∫⁻ x in s', f x ∂μ := set_lintegral_mono measurable_const hfm fun x => id
_ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' restrict_le_self le_rfl
_ = μ.prod ν ST := (prod_apply hSTm).symm
_ = μ.prod ν (s ×ˢ t) := measure_toMeasurable _
#align measure_theory.measure.prod_prod MeasureTheory.Measure.prod_prod
@[simp] lemma map_fst_prod : Measure.map Prod.fst (μ.prod ν) = (ν univ) • μ := by
ext s hs
simp [Measure.map_apply measurable_fst hs, ← prod_univ, mul_comm]
@[simp] lemma map_snd_prod : Measure.map Prod.snd (μ.prod ν) = (μ univ) • ν := by
ext s hs
simp [Measure.map_apply measurable_snd hs, ← univ_prod]
instance prod.instIsOpenPosMeasure {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y]
{m : MeasurableSpace X} {μ : Measure X} [IsOpenPosMeasure μ] {m' : MeasurableSpace Y}
{ν : Measure Y} [IsOpenPosMeasure ν] [SFinite ν] : IsOpenPosMeasure (μ.prod ν) := by
constructor
rintro U U_open ⟨⟨x, y⟩, hxy⟩
rcases isOpen_prod_iff.1 U_open x y hxy with ⟨u, v, u_open, v_open, xu, yv, huv⟩
refine ne_of_gt (lt_of_lt_of_le ?_ (measure_mono huv))
simp only [prod_prod, CanonicallyOrderedCommSemiring.mul_pos]
constructor
· exact u_open.measure_pos μ ⟨x, xu⟩
· exact v_open.measure_pos ν ⟨y, yv⟩
#align measure_theory.measure.prod.is_open_pos_measure MeasureTheory.Measure.prod.instIsOpenPosMeasure
instance {X Y : Type*}
[TopologicalSpace X] [MeasureSpace X] [IsOpenPosMeasure (volume : Measure X)]
[TopologicalSpace Y] [MeasureSpace Y] [IsOpenPosMeasure (volume : Measure Y)]
[SFinite (volume : Measure Y)] : IsOpenPosMeasure (volume : Measure (X × Y)) :=
prod.instIsOpenPosMeasure
instance prod.instIsFiniteMeasure {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
(μ : Measure α) (ν : Measure β) [IsFiniteMeasure μ] [IsFiniteMeasure ν] :
IsFiniteMeasure (μ.prod ν) := by
constructor
rw [← univ_prod_univ, prod_prod]
exact mul_lt_top (measure_lt_top _ _).ne (measure_lt_top _ _).ne
#align measure_theory.measure.prod.measure_theory.is_finite_measure MeasureTheory.Measure.prod.instIsFiniteMeasure
instance {α β : Type*} [MeasureSpace α] [MeasureSpace β] [IsFiniteMeasure (volume : Measure α)]
[IsFiniteMeasure (volume : Measure β)] : IsFiniteMeasure (volume : Measure (α × β)) :=
prod.instIsFiniteMeasure _ _
instance prod.instIsProbabilityMeasure {α β : Type*} {mα : MeasurableSpace α}
{mβ : MeasurableSpace β} (μ : Measure α) (ν : Measure β) [IsProbabilityMeasure μ]
[IsProbabilityMeasure ν] : IsProbabilityMeasure (μ.prod ν) :=
⟨by rw [← univ_prod_univ, prod_prod, measure_univ, measure_univ, mul_one]⟩
#align measure_theory.measure.prod.measure_theory.is_probability_measure MeasureTheory.Measure.prod.instIsProbabilityMeasure
instance {α β : Type*} [MeasureSpace α] [MeasureSpace β]
[IsProbabilityMeasure (volume : Measure α)] [IsProbabilityMeasure (volume : Measure β)] :
IsProbabilityMeasure (volume : Measure (α × β)) :=
prod.instIsProbabilityMeasure _ _
instance prod.instIsFiniteMeasureOnCompacts {α β : Type*} [TopologicalSpace α] [TopologicalSpace β]
{mα : MeasurableSpace α} {mβ : MeasurableSpace β} (μ : Measure α) (ν : Measure β)
[IsFiniteMeasureOnCompacts μ] [IsFiniteMeasureOnCompacts ν] [SFinite ν] :
IsFiniteMeasureOnCompacts (μ.prod ν) := by
refine ⟨fun K hK => ?_⟩
set L := (Prod.fst '' K) ×ˢ (Prod.snd '' K) with hL
have : K ⊆ L := by
rintro ⟨x, y⟩ hxy
simp only [L, prod_mk_mem_set_prod_eq, mem_image, Prod.exists, exists_and_right,
exists_eq_right]
exact ⟨⟨y, hxy⟩, ⟨x, hxy⟩⟩
apply lt_of_le_of_lt (measure_mono this)
rw [hL, prod_prod]
exact
mul_lt_top (IsCompact.measure_lt_top (hK.image continuous_fst)).ne
(IsCompact.measure_lt_top (hK.image continuous_snd)).ne
#align measure_theory.measure.prod.measure_theory.is_finite_measure_on_compacts MeasureTheory.Measure.prod.instIsFiniteMeasureOnCompacts
instance {X Y : Type*}
[TopologicalSpace X] [MeasureSpace X] [IsFiniteMeasureOnCompacts (volume : Measure X)]
[TopologicalSpace Y] [MeasureSpace Y] [IsFiniteMeasureOnCompacts (volume : Measure Y)]
[SFinite (volume : Measure Y)] : IsFiniteMeasureOnCompacts (volume : Measure (X × Y)) :=
prod.instIsFiniteMeasureOnCompacts _ _
instance prod.instNoAtoms_fst [NoAtoms μ] :
NoAtoms (Measure.prod μ ν) := by
refine NoAtoms.mk (fun x => ?_)
rw [← Set.singleton_prod_singleton, Measure.prod_prod, measure_singleton, zero_mul]
instance prod.instNoAtoms_snd [NoAtoms ν] :
NoAtoms (Measure.prod μ ν) := by
refine NoAtoms.mk (fun x => ?_)
rw [← Set.singleton_prod_singleton, Measure.prod_prod, measure_singleton (μ := ν), mul_zero]
theorem ae_measure_lt_top {s : Set (α × β)} (hs : MeasurableSet s) (h2s : (μ.prod ν) s ≠ ∞) :
∀ᵐ x ∂μ, ν (Prod.mk x ⁻¹' s) < ∞ := by
rw [prod_apply hs] at h2s
exact ae_lt_top (measurable_measure_prod_mk_left hs) h2s
#align measure_theory.measure.ae_measure_lt_top MeasureTheory.Measure.ae_measure_lt_top
/-- Note: the assumption `hs` cannot be dropped. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
theorem measure_prod_null {s : Set (α × β)} (hs : MeasurableSet s) :
μ.prod ν s = 0 ↔ (fun x => ν (Prod.mk x ⁻¹' s)) =ᵐ[μ] 0 := by
rw [prod_apply hs, lintegral_eq_zero_iff (measurable_measure_prod_mk_left hs)]
#align measure_theory.measure.measure_prod_null MeasureTheory.Measure.measure_prod_null
/-- Note: the converse is not true without assuming that `s` is measurable. For a counterexample,
see Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
theorem measure_ae_null_of_prod_null {s : Set (α × β)} (h : μ.prod ν s = 0) :
(fun x => ν (Prod.mk x ⁻¹' s)) =ᵐ[μ] 0 := by
obtain ⟨t, hst, mt, ht⟩ := exists_measurable_superset_of_null h
rw [measure_prod_null mt] at ht
rw [eventuallyLE_antisymm_iff]
exact
⟨EventuallyLE.trans_eq (eventually_of_forall fun x => (measure_mono (preimage_mono hst) : _))
ht,
eventually_of_forall fun x => zero_le _⟩
#align measure_theory.measure.measure_ae_null_of_prod_null MeasureTheory.Measure.measure_ae_null_of_prod_null
theorem AbsolutelyContinuous.prod [SFinite ν'] (h1 : μ ≪ μ') (h2 : ν ≪ ν') :
μ.prod ν ≪ μ'.prod ν' := by
refine AbsolutelyContinuous.mk fun s hs h2s => ?_
rw [measure_prod_null hs] at h2s ⊢
exact (h2s.filter_mono h1.ae_le).mono fun _ h => h2 h
#align measure_theory.measure.absolutely_continuous.prod MeasureTheory.Measure.AbsolutelyContinuous.prod
/-- Note: the converse is not true. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. It is true if the set is
measurable, see `ae_prod_mem_iff_ae_ae_mem`. -/
theorem ae_ae_of_ae_prod {p : α × β → Prop} (h : ∀ᵐ z ∂μ.prod ν, p z) :
∀ᵐ x ∂μ, ∀ᵐ y ∂ν, p (x, y) :=
measure_ae_null_of_prod_null h
#align measure_theory.measure.ae_ae_of_ae_prod MeasureTheory.Measure.ae_ae_of_ae_prod
theorem ae_ae_eq_curry_of_prod {f g : α × β → γ} (h : f =ᵐ[μ.prod ν] g) :
∀ᵐ x ∂μ, curry f x =ᵐ[ν] curry g x :=
ae_ae_of_ae_prod h
theorem ae_ae_eq_of_ae_eq_uncurry {f g : α → β → γ} (h : uncurry f =ᵐ[μ.prod ν] uncurry g) :
∀ᵐ x ∂μ, f x =ᵐ[ν] g x :=
ae_ae_eq_curry_of_prod h
theorem ae_prod_mem_iff_ae_ae_mem {s : Set (α × β)} (hs : MeasurableSet s) :
(∀ᵐ z ∂μ.prod ν, z ∈ s) ↔ ∀ᵐ x ∂μ, ∀ᵐ y ∂ν, (x, y) ∈ s :=
measure_prod_null hs.compl
theorem quasiMeasurePreserving_fst : QuasiMeasurePreserving Prod.fst (μ.prod ν) μ := by
refine ⟨measurable_fst, AbsolutelyContinuous.mk fun s hs h2s => ?_⟩
rw [map_apply measurable_fst hs, ← prod_univ, prod_prod, h2s, zero_mul]
#align measure_theory.measure.quasi_measure_preserving_fst MeasureTheory.Measure.quasiMeasurePreserving_fst
theorem quasiMeasurePreserving_snd : QuasiMeasurePreserving Prod.snd (μ.prod ν) ν := by
refine ⟨measurable_snd, AbsolutelyContinuous.mk fun s hs h2s => ?_⟩
rw [map_apply measurable_snd hs, ← univ_prod, prod_prod, h2s, mul_zero]
#align measure_theory.measure.quasi_measure_preserving_snd MeasureTheory.Measure.quasiMeasurePreserving_snd
lemma set_prod_ae_eq {s s' : Set α} {t t' : Set β} (hs : s =ᵐ[μ] s') (ht : t =ᵐ[ν] t') :
(s ×ˢ t : Set (α × β)) =ᵐ[μ.prod ν] (s' ×ˢ t' : Set (α × β)) :=
(quasiMeasurePreserving_fst.preimage_ae_eq hs).inter
(quasiMeasurePreserving_snd.preimage_ae_eq ht)
lemma measure_prod_compl_eq_zero {s : Set α} {t : Set β}
(s_ae_univ : μ sᶜ = 0) (t_ae_univ : ν tᶜ = 0) :
μ.prod ν (s ×ˢ t)ᶜ = 0 := by
rw [Set.compl_prod_eq_union, measure_union_null_iff]
simp [s_ae_univ, t_ae_univ]
lemma _root_.MeasureTheory.NullMeasurableSet.prod {s : Set α} {t : Set β}
(s_mble : NullMeasurableSet s μ) (t_mble : NullMeasurableSet t ν) :
NullMeasurableSet (s ×ˢ t) (μ.prod ν) :=
let ⟨s₀, mble_s₀, s_aeeq_s₀⟩ := s_mble
let ⟨t₀, mble_t₀, t_aeeq_t₀⟩ := t_mble
⟨s₀ ×ˢ t₀, ⟨mble_s₀.prod mble_t₀, set_prod_ae_eq s_aeeq_s₀ t_aeeq_t₀⟩⟩
/-- If `s ×ˢ t` is a null measurable set and `μ s ≠ 0`, then `t` is a null measurable set. -/
lemma _root_.MeasureTheory.NullMeasurableSet.right_of_prod {s : Set α} {t : Set β}
(h : NullMeasurableSet (s ×ˢ t) (μ.prod ν)) (hs : μ s ≠ 0) : NullMeasurableSet t ν := by
rcases h with ⟨u, hum, hu⟩
obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, (Prod.mk x ⁻¹' (s ×ˢ t)) =ᵐ[ν] (Prod.mk x ⁻¹' u) :=
((frequently_ae_iff.2 hs).and_eventually (ae_ae_eq_curry_of_prod hu)).exists
refine ⟨Prod.mk x ⁻¹' u, measurable_prod_mk_left hum, ?_⟩
rwa [mk_preimage_prod_right hxs] at hx
/-- If `Prod.snd ⁻¹' t` is a null measurable set and `μ ≠ 0`, then `t` is a null measurable set. -/
lemma _root_.MeasureTheory.NullMeasurableSet.of_preimage_snd [NeZero μ] {t : Set β}
(h : NullMeasurableSet (Prod.snd ⁻¹' t) (μ.prod ν)) : NullMeasurableSet t ν :=
.right_of_prod (by rwa [univ_prod]) (NeZero.ne _)
/-- `Prod.snd ⁻¹' t` is null measurable w.r.t. `μ.prod ν` iff `t` is null measurable w.r.t. `ν`
provided that `μ ≠ 0`. -/
lemma nullMeasurableSet_preimage_snd [NeZero μ] {t : Set β} :
NullMeasurableSet (Prod.snd ⁻¹' t) (μ.prod ν) ↔ NullMeasurableSet t ν :=
⟨.of_preimage_snd, (.preimage · quasiMeasurePreserving_snd)⟩
lemma nullMeasurable_comp_snd [NeZero μ] {f : β → γ} :
NullMeasurable (f ∘ Prod.snd) (μ.prod ν) ↔ NullMeasurable f ν :=
forall₂_congr fun s _ ↦ nullMeasurableSet_preimage_snd (t := f ⁻¹' s)
/-- `μ.prod ν` has finite spanning sets in rectangles of finite spanning sets. -/
noncomputable def FiniteSpanningSetsIn.prod {ν : Measure β} {C : Set (Set α)} {D : Set (Set β)}
(hμ : μ.FiniteSpanningSetsIn C) (hν : ν.FiniteSpanningSetsIn D) :
(μ.prod ν).FiniteSpanningSetsIn (image2 (· ×ˢ ·) C D) := by
haveI := hν.sigmaFinite
refine
⟨fun n => hμ.set n.unpair.1 ×ˢ hν.set n.unpair.2, fun n =>
mem_image2_of_mem (hμ.set_mem _) (hν.set_mem _), fun n => ?_, ?_⟩
· rw [prod_prod]
exact mul_lt_top (hμ.finite _).ne (hν.finite _).ne
· simp_rw [iUnion_unpair_prod, hμ.spanning, hν.spanning, univ_prod_univ]
#align measure_theory.measure.finite_spanning_sets_in.prod MeasureTheory.Measure.FiniteSpanningSetsIn.prod
lemma prod_sum_left {ι : Type*} (m : ι → Measure α) (μ : Measure β) [SFinite μ] :
(Measure.sum m).prod μ = Measure.sum (fun i ↦ (m i).prod μ) := by
ext s hs
simp only [prod_apply hs, lintegral_sum_measure, hs, sum_apply, ENNReal.tsum_prod']
#align measure_theory.measure.sum_prod MeasureTheory.Measure.prod_sum_left
lemma prod_sum_right {ι' : Type*} [Countable ι'] (m : Measure α) (m' : ι' → Measure β)
[∀ n, SFinite (m' n)] :
m.prod (Measure.sum m') = Measure.sum (fun p ↦ m.prod (m' p)) := by
ext s hs
simp only [prod_apply hs, lintegral_sum_measure, hs, sum_apply, ENNReal.tsum_prod']
have M : ∀ x, MeasurableSet (Prod.mk x ⁻¹' s) := fun x => measurable_prod_mk_left hs
simp_rw [Measure.sum_apply _ (M _)]
rw [lintegral_tsum (fun i ↦ (measurable_measure_prod_mk_left hs).aemeasurable)]
#align measure_theory.measure.prod_sum MeasureTheory.Measure.prod_sum_right
lemma prod_sum {ι ι' : Type*} [Countable ι'] (m : ι → Measure α) (m' : ι' → Measure β)
[∀ n, SFinite (m' n)] :
(Measure.sum m).prod (Measure.sum m') =
Measure.sum (fun (p : ι × ι') ↦ (m p.1).prod (m' p.2)) := by
simp_rw [prod_sum_left, prod_sum_right, sum_sum]
instance prod.instSigmaFinite {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SigmaFinite μ] {_ : MeasurableSpace β} {ν : Measure β} [SigmaFinite ν] :
SigmaFinite (μ.prod ν) :=
(μ.toFiniteSpanningSetsIn.prod ν.toFiniteSpanningSetsIn).sigmaFinite
#align measure_theory.measure.prod.sigma_finite MeasureTheory.Measure.prod.instSigmaFinite
instance prod.instSFinite {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] {_ : MeasurableSpace β} {ν : Measure β} [SFinite ν] :
SFinite (μ.prod ν) := by
have : μ.prod ν =
Measure.sum (fun (p : ℕ × ℕ) ↦ (sFiniteSeq μ p.1).prod (sFiniteSeq ν p.2)) := by
conv_lhs => rw [← sum_sFiniteSeq μ, ← sum_sFiniteSeq ν]
apply prod_sum
rw [this]
infer_instance
instance {α β} [MeasureSpace α] [SigmaFinite (volume : Measure α)]
[MeasureSpace β] [SigmaFinite (volume : Measure β)] : SigmaFinite (volume : Measure (α × β)) :=
prod.instSigmaFinite
instance {α β} [MeasureSpace α] [SFinite (volume : Measure α)]
[MeasureSpace β] [SFinite (volume : Measure β)] : SFinite (volume : Measure (α × β)) :=
prod.instSFinite
/-- A measure on a product space equals the product measure if they are equal on rectangles
with as sides sets that generate the corresponding σ-algebras. -/
theorem prod_eq_generateFrom {μ : Measure α} {ν : Measure β} {C : Set (Set α)} {D : Set (Set β)}
(hC : generateFrom C = ‹_›) (hD : generateFrom D = ‹_›) (h2C : IsPiSystem C)
(h2D : IsPiSystem D) (h3C : μ.FiniteSpanningSetsIn C) (h3D : ν.FiniteSpanningSetsIn D)
{μν : Measure (α × β)} (h₁ : ∀ s ∈ C, ∀ t ∈ D, μν (s ×ˢ t) = μ s * ν t) : μ.prod ν = μν := by
refine
(h3C.prod h3D).ext
(generateFrom_eq_prod hC hD h3C.isCountablySpanning h3D.isCountablySpanning).symm
(h2C.prod h2D) ?_
rintro _ ⟨s, hs, t, ht, rfl⟩
haveI := h3D.sigmaFinite
rw [h₁ s hs t ht, prod_prod]
#align measure_theory.measure.prod_eq_generate_from MeasureTheory.Measure.prod_eq_generateFrom
/- Note that the next theorem is not true for s-finite measures: let `μ = ν = ∞ • Leb` on `[0,1]`
(they are s-finite as countable sums of the finite Lebesgue measure), and let `μν = μ.prod ν + λ`
where `λ` is Lebesgue measure on the diagonal. Then both measures give infinite mass to rectangles
`s × t` whose sides have positive Lebesgue measure, and `0` measure when one of the sides has zero
Lebesgue measure. And yet they do not coincide, as the first one gives zero mass to the diagonal,
and the second one gives mass one.
-/
/-- A measure on a product space equals the product measure of sigma-finite measures if they are
equal on rectangles. -/
theorem prod_eq {μ : Measure α} [SigmaFinite μ] {ν : Measure β} [SigmaFinite ν]
{μν : Measure (α × β)}
(h : ∀ s t, MeasurableSet s → MeasurableSet t → μν (s ×ˢ t) = μ s * ν t) : μ.prod ν = μν :=
prod_eq_generateFrom generateFrom_measurableSet generateFrom_measurableSet
isPiSystem_measurableSet isPiSystem_measurableSet μ.toFiniteSpanningSetsIn
ν.toFiniteSpanningSetsIn fun s hs t ht => h s t hs ht
#align measure_theory.measure.prod_eq MeasureTheory.Measure.prod_eq
variable [SFinite μ]
theorem prod_swap : map Prod.swap (μ.prod ν) = ν.prod μ := by
have : sum (fun (i : ℕ × ℕ) ↦ map Prod.swap ((sFiniteSeq μ i.1).prod (sFiniteSeq ν i.2)))
= sum (fun (i : ℕ × ℕ) ↦ map Prod.swap ((sFiniteSeq μ i.2).prod (sFiniteSeq ν i.1))) := by
ext s hs
rw [sum_apply _ hs, sum_apply _ hs]
exact ((Equiv.prodComm ℕ ℕ).tsum_eq _).symm
rw [← sum_sFiniteSeq μ, ← sum_sFiniteSeq ν, prod_sum, prod_sum,
map_sum measurable_swap.aemeasurable, this]
congr 1
ext1 i
refine (prod_eq ?_).symm
intro s t hs ht
simp_rw [map_apply measurable_swap (hs.prod ht), preimage_swap_prod, prod_prod, mul_comm]
#align measure_theory.measure.prod_swap MeasureTheory.Measure.prod_swap
theorem measurePreserving_swap : MeasurePreserving Prod.swap (μ.prod ν) (ν.prod μ) :=
⟨measurable_swap, prod_swap⟩
#align measure_theory.measure.measure_preserving_swap MeasureTheory.Measure.measurePreserving_swap
theorem prod_apply_symm {s : Set (α × β)} (hs : MeasurableSet s) :
μ.prod ν s = ∫⁻ y, μ ((fun x => (x, y)) ⁻¹' s) ∂ν := by
rw [← prod_swap, map_apply measurable_swap hs, prod_apply (measurable_swap hs)]
rfl
#align measure_theory.measure.prod_apply_symm MeasureTheory.Measure.prod_apply_symm
/-- If `s ×ˢ t` is a null measurable set and `ν t ≠ 0`, then `s` is a null measurable set. -/
lemma _root_.MeasureTheory.NullMeasurableSet.left_of_prod {s : Set α} {t : Set β}
(h : NullMeasurableSet (s ×ˢ t) (μ.prod ν)) (ht : ν t ≠ 0) : NullMeasurableSet s μ := by
refine .right_of_prod ?_ ht
rw [← preimage_swap_prod]
exact h.preimage measurePreserving_swap.quasiMeasurePreserving
/-- If `Prod.fst ⁻¹' s` is a null measurable set and `ν ≠ 0`, then `s` is a null measurable set. -/
lemma _root_.MeasureTheory.NullMeasurableSet.of_preimage_fst [NeZero ν] {s : Set α}
(h : NullMeasurableSet (Prod.fst ⁻¹' s) (μ.prod ν)) : NullMeasurableSet s μ :=
.left_of_prod (by rwa [prod_univ]) (NeZero.ne _)
/-- `Prod.fst ⁻¹' s` is null measurable w.r.t. `μ.prod ν` iff `s` is null measurable w.r.t. `μ`
provided that `ν ≠ 0`. -/
lemma nullMeasurableSet_preimage_fst [NeZero ν] {s : Set α} :
NullMeasurableSet (Prod.fst ⁻¹' s) (μ.prod ν) ↔ NullMeasurableSet s μ :=
⟨.of_preimage_fst, (.preimage · quasiMeasurePreserving_fst)⟩
lemma nullMeasurable_comp_fst [NeZero ν] {f : α → γ} :
NullMeasurable (f ∘ Prod.fst) (μ.prod ν) ↔ NullMeasurable f μ :=
forall₂_congr fun s _ ↦ nullMeasurableSet_preimage_fst (s := f ⁻¹' s)
/-- The product of two non-null sets is null measurable
if and only if both of them are null measurable. -/
lemma nullMeasurableSet_prod_of_ne_zero {s : Set α} {t : Set β} (hs : μ s ≠ 0) (ht : ν t ≠ 0) :
NullMeasurableSet (s ×ˢ t) (μ.prod ν) ↔ NullMeasurableSet s μ ∧ NullMeasurableSet t ν :=
⟨fun h ↦ ⟨h.left_of_prod ht, h.right_of_prod hs⟩, fun ⟨hs, ht⟩ ↦ hs.prod ht⟩
/-- The product of two sets is null measurable
if and only if both of them are null measurable or one of them has measure zero. -/
lemma nullMeasurableSet_prod {s : Set α} {t : Set β} :
NullMeasurableSet (s ×ˢ t) (μ.prod ν) ↔
NullMeasurableSet s μ ∧ NullMeasurableSet t ν ∨ μ s = 0 ∨ ν t = 0 := by
rcases eq_or_ne (μ s) 0 with hs | hs; · simp [NullMeasurableSet.of_null, *]
rcases eq_or_ne (ν t) 0 with ht | ht; · simp [NullMeasurableSet.of_null, *]
simp [*, nullMeasurableSet_prod_of_ne_zero]
theorem prodAssoc_prod [SFinite τ] :
map MeasurableEquiv.prodAssoc ((μ.prod ν).prod τ) = μ.prod (ν.prod τ) := by
have : sum (fun (p : ℕ × ℕ × ℕ) ↦
(sFiniteSeq μ p.1).prod ((sFiniteSeq ν p.2.1).prod (sFiniteSeq τ p.2.2)))
= sum (fun (p : (ℕ × ℕ) × ℕ) ↦
(sFiniteSeq μ p.1.1).prod ((sFiniteSeq ν p.1.2).prod (sFiniteSeq τ p.2))) := by
ext s hs
rw [sum_apply _ hs, sum_apply _ hs, ← (Equiv.prodAssoc _ _ _).tsum_eq]
simp only [Equiv.prodAssoc_apply]
rw [← sum_sFiniteSeq μ, ← sum_sFiniteSeq ν, ← sum_sFiniteSeq τ, prod_sum, prod_sum,
map_sum MeasurableEquiv.prodAssoc.measurable.aemeasurable, prod_sum, prod_sum, this]
congr
ext1 i
refine (prod_eq_generateFrom generateFrom_measurableSet generateFrom_prod
isPiSystem_measurableSet isPiSystem_prod ((sFiniteSeq μ i.1.1)).toFiniteSpanningSetsIn
((sFiniteSeq ν i.1.2).toFiniteSpanningSetsIn.prod (sFiniteSeq τ i.2).toFiniteSpanningSetsIn)
?_).symm
rintro s hs _ ⟨t, ht, u, hu, rfl⟩; rw [mem_setOf_eq] at hs ht hu
simp_rw [map_apply (MeasurableEquiv.measurable _) (hs.prod (ht.prod hu)),
MeasurableEquiv.prodAssoc, MeasurableEquiv.coe_mk, Equiv.prod_assoc_preimage, prod_prod,
mul_assoc]
#align measure_theory.measure.prod_assoc_prod MeasureTheory.Measure.prodAssoc_prod
/-! ### The product of specific measures -/
theorem prod_restrict (s : Set α) (t : Set β) :
(μ.restrict s).prod (ν.restrict t) = (μ.prod ν).restrict (s ×ˢ t) := by
rw [← sum_sFiniteSeq μ, ← sum_sFiniteSeq ν, restrict_sum_of_countable, restrict_sum_of_countable,
prod_sum, prod_sum, restrict_sum_of_countable]
congr 1
ext1 i
refine prod_eq fun s' t' hs' ht' => ?_
rw [restrict_apply (hs'.prod ht'), prod_inter_prod, prod_prod, restrict_apply hs',
restrict_apply ht']
#align measure_theory.measure.prod_restrict MeasureTheory.Measure.prod_restrict
theorem restrict_prod_eq_prod_univ (s : Set α) :
(μ.restrict s).prod ν = (μ.prod ν).restrict (s ×ˢ univ) := by
have : ν = ν.restrict Set.univ := Measure.restrict_univ.symm
rw [this, Measure.prod_restrict, ← this]
#align measure_theory.measure.restrict_prod_eq_prod_univ MeasureTheory.Measure.restrict_prod_eq_prod_univ
theorem prod_dirac (y : β) : μ.prod (dirac y) = map (fun x => (x, y)) μ := by
rw [← sum_sFiniteSeq μ, prod_sum_left, map_sum measurable_prod_mk_right.aemeasurable]
congr
ext1 i
refine prod_eq fun s t hs ht => ?_
simp_rw [map_apply measurable_prod_mk_right (hs.prod ht), mk_preimage_prod_left_eq_if, measure_if,
dirac_apply' _ ht, ← indicator_mul_right _ fun _ => sFiniteSeq μ i s, Pi.one_apply, mul_one]
#align measure_theory.measure.prod_dirac MeasureTheory.Measure.prod_dirac
theorem dirac_prod (x : α) : (dirac x).prod ν = map (Prod.mk x) ν := by
rw [← sum_sFiniteSeq ν, prod_sum_right, map_sum measurable_prod_mk_left.aemeasurable]
congr
ext1 i
refine prod_eq fun s t hs ht => ?_
simp_rw [map_apply measurable_prod_mk_left (hs.prod ht), mk_preimage_prod_right_eq_if, measure_if,
dirac_apply' _ hs, ← indicator_mul_left _ _ fun _ => sFiniteSeq ν i t, Pi.one_apply, one_mul]
#align measure_theory.measure.dirac_prod MeasureTheory.Measure.dirac_prod
theorem dirac_prod_dirac {x : α} {y : β} : (dirac x).prod (dirac y) = dirac (x, y) := by
rw [prod_dirac, map_dirac measurable_prod_mk_right]
#align measure_theory.measure.dirac_prod_dirac MeasureTheory.Measure.dirac_prod_dirac
theorem prod_add (ν' : Measure β) [SFinite ν'] : μ.prod (ν + ν') = μ.prod ν + μ.prod ν' := by
simp_rw [← sum_sFiniteSeq ν, ← sum_sFiniteSeq ν', sum_add_sum, ← sum_sFiniteSeq μ, prod_sum,
sum_add_sum]
congr
ext1 i
refine prod_eq fun s t _ _ => ?_
simp_rw [add_apply, prod_prod, left_distrib]
#align measure_theory.measure.prod_add MeasureTheory.Measure.prod_add
theorem add_prod (μ' : Measure α) [SFinite μ'] : (μ + μ').prod ν = μ.prod ν + μ'.prod ν := by
simp_rw [← sum_sFiniteSeq μ, ← sum_sFiniteSeq μ', sum_add_sum, ← sum_sFiniteSeq ν, prod_sum,
sum_add_sum]
congr
ext1 i
refine prod_eq fun s t _ _ => ?_
simp_rw [add_apply, prod_prod, right_distrib]
#align measure_theory.measure.add_prod MeasureTheory.Measure.add_prod
@[simp]
theorem zero_prod (ν : Measure β) : (0 : Measure α).prod ν = 0 := by
rw [Measure.prod]
exact bind_zero_left _
#align measure_theory.measure.zero_prod MeasureTheory.Measure.zero_prod
@[simp]
theorem prod_zero (μ : Measure α) : μ.prod (0 : Measure β) = 0 := by simp [Measure.prod]
#align measure_theory.measure.prod_zero MeasureTheory.Measure.prod_zero
theorem map_prod_map {δ} [MeasurableSpace δ] {f : α → β} {g : γ → δ} (μa : Measure α)
(μc : Measure γ) [SFinite μa] [SFinite μc] (hf : Measurable f) (hg : Measurable g) :
(map f μa).prod (map g μc) = map (Prod.map f g) (μa.prod μc) := by
simp_rw [← sum_sFiniteSeq μa, ← sum_sFiniteSeq μc, map_sum hf.aemeasurable,
map_sum hg.aemeasurable, prod_sum, map_sum (hf.prod_map hg).aemeasurable]
congr
ext1 i
refine prod_eq fun s t hs ht => ?_
rw [map_apply (hf.prod_map hg) (hs.prod ht), map_apply hf hs, map_apply hg ht]
exact prod_prod (f ⁻¹' s) (g ⁻¹' t)
#align measure_theory.measure.map_prod_map MeasureTheory.Measure.map_prod_map
end Measure
open Measure
namespace MeasurePreserving
variable {δ : Type*} [MeasurableSpace δ] {μa : Measure α} {μb : Measure β} {μc : Measure γ}
{μd : Measure δ}
theorem skew_product [SFinite μa] [SFinite μc] {f : α → β} (hf : MeasurePreserving f μa μb)
{g : α → γ → δ} (hgm : Measurable (uncurry g)) (hg : ∀ᵐ x ∂μa, map (g x) μc = μd) :
MeasurePreserving (fun p : α × γ => (f p.1, g p.1 p.2)) (μa.prod μc) (μb.prod μd) := by
classical
have : Measurable fun p : α × γ => (f p.1, g p.1 p.2) := (hf.1.comp measurable_fst).prod_mk hgm
/- if `μa = 0`, then the lemma is trivial, otherwise we can use `hg`
to deduce `SFinite μd`. -/
rcases eq_or_ne μa 0 with (rfl | ha)
· rw [← hf.map_eq, zero_prod, Measure.map_zero, zero_prod]
exact ⟨this, by simp only [Measure.map_zero]⟩
have sf : SFinite μd := by
rcases (ae_neBot.2 ha).nonempty_of_mem hg with ⟨x, hx : map (g x) μc = μd⟩
rw [← hx]
infer_instance
-- Thus we can use the integral formula for the product measure, and compute things explicitly
refine ⟨this, ?_⟩
ext s hs
rw [map_apply this hs, prod_apply (this hs), prod_apply hs,
← hf.lintegral_comp (measurable_measure_prod_mk_left hs)]
apply lintegral_congr_ae
filter_upwards [hg] with a ha
rw [← ha, map_apply hgm.of_uncurry_left (measurable_prod_mk_left hs), preimage_preimage,
preimage_preimage]
#align measure_theory.measure_preserving.skew_product MeasureTheory.MeasurePreserving.skew_product
/-- If `f : α → β` sends the measure `μa` to `μb` and `g : γ → δ` sends the measure `μc` to `μd`,
then `Prod.map f g` sends `μa.prod μc` to `μb.prod μd`. -/
protected theorem prod [SFinite μa] [SFinite μc] {f : α → β} {g : γ → δ}
(hf : MeasurePreserving f μa μb) (hg : MeasurePreserving g μc μd) :
MeasurePreserving (Prod.map f g) (μa.prod μc) (μb.prod μd) :=
have : Measurable (uncurry fun _ : α => g) := hg.1.comp measurable_snd
hf.skew_product this <| Filter.eventually_of_forall fun _ => hg.map_eq
#align measure_theory.measure_preserving.prod MeasureTheory.MeasurePreserving.prod
end MeasurePreserving
namespace QuasiMeasurePreserving
theorem prod_of_right {f : α × β → γ} {μ : Measure α} {ν : Measure β} {τ : Measure γ}
(hf : Measurable f) [SFinite ν]
(h2f : ∀ᵐ x ∂μ, QuasiMeasurePreserving (fun y => f (x, y)) ν τ) :
QuasiMeasurePreserving f (μ.prod ν) τ := by
refine ⟨hf, ?_⟩
refine AbsolutelyContinuous.mk fun s hs h2s => ?_
rw [map_apply hf hs, prod_apply (hf hs)]; simp_rw [preimage_preimage]
rw [lintegral_congr_ae (h2f.mono fun x hx => hx.preimage_null h2s), lintegral_zero]
#align measure_theory.quasi_measure_preserving.prod_of_right MeasureTheory.QuasiMeasurePreserving.prod_of_right
theorem prod_of_left {α β γ} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
{f : α × β → γ} {μ : Measure α} {ν : Measure β} {τ : Measure γ} (hf : Measurable f)
[SFinite μ] [SFinite ν]
(h2f : ∀ᵐ y ∂ν, QuasiMeasurePreserving (fun x => f (x, y)) μ τ) :
QuasiMeasurePreserving f (μ.prod ν) τ := by
rw [← prod_swap]
convert (QuasiMeasurePreserving.prod_of_right (hf.comp measurable_swap) h2f).comp
((measurable_swap.measurePreserving (ν.prod μ)).symm
MeasurableEquiv.prodComm).quasiMeasurePreserving
#align measure_theory.quasi_measure_preserving.prod_of_left MeasureTheory.QuasiMeasurePreserving.prod_of_left
end QuasiMeasurePreserving
end MeasureTheory
open MeasureTheory.Measure
section
theorem AEMeasurable.prod_swap [SFinite μ] [SFinite ν] {f : β × α → γ}
(hf : AEMeasurable f (ν.prod μ)) : AEMeasurable (fun z : α × β => f z.swap) (μ.prod ν) := by
rw [← Measure.prod_swap] at hf
exact hf.comp_measurable measurable_swap
#align ae_measurable.prod_swap AEMeasurable.prod_swap
theorem AEMeasurable.fst [SFinite ν] {f : α → γ} (hf : AEMeasurable f μ) :
AEMeasurable (fun z : α × β => f z.1) (μ.prod ν) :=
hf.comp_quasiMeasurePreserving quasiMeasurePreserving_fst
#align ae_measurable.fst AEMeasurable.fst
theorem AEMeasurable.snd [SFinite ν] {f : β → γ} (hf : AEMeasurable f ν) :
AEMeasurable (fun z : α × β => f z.2) (μ.prod ν) :=
hf.comp_quasiMeasurePreserving quasiMeasurePreserving_snd
#align ae_measurable.snd AEMeasurable.snd
end
namespace MeasureTheory
/-! ### The Lebesgue integral on a product -/
variable [SFinite ν]
theorem lintegral_prod_swap [SFinite μ] (f : α × β → ℝ≥0∞) :
∫⁻ z, f z.swap ∂ν.prod μ = ∫⁻ z, f z ∂μ.prod ν :=
measurePreserving_swap.lintegral_comp_emb MeasurableEquiv.prodComm.measurableEmbedding f
#align measure_theory.lintegral_prod_swap MeasureTheory.lintegral_prod_swap
/-- **Tonelli's Theorem**: For `ℝ≥0∞`-valued measurable functions on `α × β`,
the integral of `f` is equal to the iterated integral. -/
theorem lintegral_prod_of_measurable :
∀ (f : α × β → ℝ≥0∞), Measurable f → ∫⁻ z, f z ∂μ.prod ν = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ := by
have m := @measurable_prod_mk_left
refine Measurable.ennreal_induction
(P := fun f => ∫⁻ z, f z ∂μ.prod ν = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ) ?_ ?_ ?_
· intro c s hs
conv_rhs =>
enter [2, x, 2, y]
rw [← indicator_comp_right, const_def, const_comp, ← const_def]
conv_rhs =>
enter [2, x]
rw [lintegral_indicator _ (m (x := x) hs), lintegral_const,
Measure.restrict_apply MeasurableSet.univ, univ_inter]
simp [hs, lintegral_const_mul, measurable_measure_prod_mk_left (ν := ν) hs, prod_apply]
· rintro f g - hf _ h2f h2g
simp only [Pi.add_apply]
conv_lhs => rw [lintegral_add_left hf]
conv_rhs => enter [2, x]; erw [lintegral_add_left (hf.comp (m (x := x)))]
simp [lintegral_add_left, Measurable.lintegral_prod_right', hf, h2f, h2g]
· intro f hf h2f h3f
have kf : ∀ x n, Measurable fun y => f n (x, y) := fun x n => (hf n).comp m
have k2f : ∀ x, Monotone fun n y => f n (x, y) := fun x i j hij y => h2f hij (x, y)
have lf : ∀ n, Measurable fun x => ∫⁻ y, f n (x, y) ∂ν := fun n => (hf n).lintegral_prod_right'
have l2f : Monotone fun n x => ∫⁻ y, f n (x, y) ∂ν := fun i j hij x =>
lintegral_mono (k2f x hij)
simp only [lintegral_iSup hf h2f, lintegral_iSup (kf _), k2f, lintegral_iSup lf l2f, h3f]
#align measure_theory.lintegral_prod_of_measurable MeasureTheory.lintegral_prod_of_measurable
/-- **Tonelli's Theorem**: For `ℝ≥0∞`-valued almost everywhere measurable functions on `α × β`,
the integral of `f` is equal to the iterated integral. -/
theorem lintegral_prod (f : α × β → ℝ≥0∞) (hf : AEMeasurable f (μ.prod ν)) :
∫⁻ z, f z ∂μ.prod ν = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ := by
have A : ∫⁻ z, f z ∂μ.prod ν = ∫⁻ z, hf.mk f z ∂μ.prod ν := lintegral_congr_ae hf.ae_eq_mk
have B : (∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ) = ∫⁻ x, ∫⁻ y, hf.mk f (x, y) ∂ν ∂μ := by
apply lintegral_congr_ae
filter_upwards [ae_ae_of_ae_prod hf.ae_eq_mk] with _ ha using lintegral_congr_ae ha
rw [A, B, lintegral_prod_of_measurable _ hf.measurable_mk]
#align measure_theory.lintegral_prod MeasureTheory.lintegral_prod
/-- The symmetric version of Tonelli's Theorem: For `ℝ≥0∞`-valued almost everywhere measurable
functions on `α × β`, the integral of `f` is equal to the iterated integral, in reverse order. -/
theorem lintegral_prod_symm [SFinite μ] (f : α × β → ℝ≥0∞) (hf : AEMeasurable f (μ.prod ν)) :
∫⁻ z, f z ∂μ.prod ν = ∫⁻ y, ∫⁻ x, f (x, y) ∂μ ∂ν := by
simp_rw [← lintegral_prod_swap f]
exact lintegral_prod _ hf.prod_swap
#align measure_theory.lintegral_prod_symm MeasureTheory.lintegral_prod_symm
/-- The symmetric version of Tonelli's Theorem: For `ℝ≥0∞`-valued measurable
functions on `α × β`, the integral of `f` is equal to the iterated integral, in reverse order. -/
theorem lintegral_prod_symm' [SFinite μ] (f : α × β → ℝ≥0∞) (hf : Measurable f) :
∫⁻ z, f z ∂μ.prod ν = ∫⁻ y, ∫⁻ x, f (x, y) ∂μ ∂ν :=
lintegral_prod_symm f hf.aemeasurable
#align measure_theory.lintegral_prod_symm' MeasureTheory.lintegral_prod_symm'
/-- The reversed version of **Tonelli's Theorem**. In this version `f` is in curried form, which
makes it easier for the elaborator to figure out `f` automatically. -/
theorem lintegral_lintegral ⦃f : α → β → ℝ≥0∞⦄ (hf : AEMeasurable (uncurry f) (μ.prod ν)) :
∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ = ∫⁻ z, f z.1 z.2 ∂μ.prod ν :=
(lintegral_prod _ hf).symm
#align measure_theory.lintegral_lintegral MeasureTheory.lintegral_lintegral
/-- The reversed version of **Tonelli's Theorem** (symmetric version). In this version `f` is in
curried form, which makes it easier for the elaborator to figure out `f` automatically. -/
theorem lintegral_lintegral_symm [SFinite μ] ⦃f : α → β → ℝ≥0∞⦄
(hf : AEMeasurable (uncurry f) (μ.prod ν)) :
∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ = ∫⁻ z, f z.2 z.1 ∂ν.prod μ :=
(lintegral_prod_symm _ hf.prod_swap).symm
#align measure_theory.lintegral_lintegral_symm MeasureTheory.lintegral_lintegral_symm
/-- Change the order of Lebesgue integration. -/
theorem lintegral_lintegral_swap [SFinite μ] ⦃f : α → β → ℝ≥0∞⦄
(hf : AEMeasurable (uncurry f) (μ.prod ν)) :
∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ = ∫⁻ y, ∫⁻ x, f x y ∂μ ∂ν :=
(lintegral_lintegral hf).trans (lintegral_prod_symm _ hf)
#align measure_theory.lintegral_lintegral_swap MeasureTheory.lintegral_lintegral_swap
| Mathlib/MeasureTheory/Constructions/Prod/Basic.lean | 1,013 | 1,015 | theorem lintegral_prod_mul {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (hf : AEMeasurable f μ)
(hg : AEMeasurable g ν) : ∫⁻ z, f z.1 * g z.2 ∂μ.prod ν = (∫⁻ x, f x ∂μ) * ∫⁻ y, g y ∂ν := by |
simp [lintegral_prod _ (hf.fst.mul hg.snd), lintegral_lintegral_mul hf hg]
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Joey van Langen, Casper Putz
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Data.Nat.Multiplicity
import Mathlib.Data.Nat.Choose.Sum
#align_import algebra.char_p.basic from "leanprover-community/mathlib"@"47a1a73351de8dd6c8d3d32b569c8e434b03ca47"
/-!
# Characteristic of semirings
-/
assert_not_exists orderOf
universe u v
open Finset
variable {R : Type*}
namespace Commute
variable [Semiring R] {p : ℕ} {x y : R}
protected theorem add_pow_prime_pow_eq (hp : p.Prime) (h : Commute x y) (n : ℕ) :
(x + y) ^ p ^ n =
x ^ p ^ n + y ^ p ^ n +
p * ∑ k ∈ Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * ↑((p ^ n).choose k / p) := by
trans x ^ p ^ n + y ^ p ^ n + ∑ k ∈ Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * (p ^ n).choose k
· simp_rw [h.add_pow, ← Nat.Ico_zero_eq_range, Nat.Ico_succ_right, Icc_eq_cons_Ico (zero_le _),
Finset.sum_cons, Ico_eq_cons_Ioo (pow_pos hp.pos _), Finset.sum_cons, tsub_self, tsub_zero,
pow_zero, Nat.choose_zero_right, Nat.choose_self, Nat.cast_one, mul_one, one_mul, ← add_assoc]
· congr 1
simp_rw [Finset.mul_sum, Nat.cast_comm, mul_assoc _ _ (p : R), ← Nat.cast_mul]
refine Finset.sum_congr rfl fun i hi => ?_
rw [mem_Ioo] at hi
rw [Nat.div_mul_cancel (hp.dvd_choose_pow hi.1.ne' hi.2.ne)]
#align commute.add_pow_prime_pow_eq Commute.add_pow_prime_pow_eq
protected theorem add_pow_prime_eq (hp : p.Prime) (h : Commute x y) :
(x + y) ^ p =
x ^ p + y ^ p + p * ∑ k ∈ Finset.Ioo 0 p, x ^ k * y ^ (p - k) * ↑(p.choose k / p) := by
simpa using h.add_pow_prime_pow_eq hp 1
#align commute.add_pow_prime_eq Commute.add_pow_prime_eq
protected theorem exists_add_pow_prime_pow_eq (hp : p.Prime) (h : Commute x y) (n : ℕ) :
∃ r, (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n + p * r :=
⟨_, h.add_pow_prime_pow_eq hp n⟩
#align commute.exists_add_pow_prime_pow_eq Commute.exists_add_pow_prime_pow_eq
protected theorem exists_add_pow_prime_eq (hp : p.Prime) (h : Commute x y) :
∃ r, (x + y) ^ p = x ^ p + y ^ p + p * r :=
⟨_, h.add_pow_prime_eq hp⟩
#align commute.exists_add_pow_prime_eq Commute.exists_add_pow_prime_eq
end Commute
section CommSemiring
variable [CommSemiring R] {p : ℕ} {x y : R}
theorem add_pow_prime_pow_eq (hp : p.Prime) (x y : R) (n : ℕ) :
(x + y) ^ p ^ n =
x ^ p ^ n + y ^ p ^ n +
p * ∑ k ∈ Finset.Ioo 0 (p ^ n), x ^ k * y ^ (p ^ n - k) * ↑((p ^ n).choose k / p) :=
(Commute.all x y).add_pow_prime_pow_eq hp n
#align add_pow_prime_pow_eq add_pow_prime_pow_eq
theorem add_pow_prime_eq (hp : p.Prime) (x y : R) :
(x + y) ^ p =
x ^ p + y ^ p + p * ∑ k ∈ Finset.Ioo 0 p, x ^ k * y ^ (p - k) * ↑(p.choose k / p) :=
(Commute.all x y).add_pow_prime_eq hp
#align add_pow_prime_eq add_pow_prime_eq
theorem exists_add_pow_prime_pow_eq (hp : p.Prime) (x y : R) (n : ℕ) :
∃ r, (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n + p * r :=
(Commute.all x y).exists_add_pow_prime_pow_eq hp n
#align exists_add_pow_prime_pow_eq exists_add_pow_prime_pow_eq
theorem exists_add_pow_prime_eq (hp : p.Prime) (x y : R) :
∃ r, (x + y) ^ p = x ^ p + y ^ p + p * r :=
(Commute.all x y).exists_add_pow_prime_eq hp
#align exists_add_pow_prime_eq exists_add_pow_prime_eq
end CommSemiring
variable (R)
theorem add_pow_char_of_commute [Semiring R] {p : ℕ} [hp : Fact p.Prime] [CharP R p] (x y : R)
(h : Commute x y) : (x + y) ^ p = x ^ p + y ^ p := by
let ⟨r, hr⟩ := h.exists_add_pow_prime_eq hp.out
simp [hr]
#align add_pow_char_of_commute add_pow_char_of_commute
theorem add_pow_char_pow_of_commute [Semiring R] {p n : ℕ} [hp : Fact p.Prime] [CharP R p]
(x y : R) (h : Commute x y) : (x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n := by
let ⟨r, hr⟩ := h.exists_add_pow_prime_pow_eq hp.out n
simp [hr]
#align add_pow_char_pow_of_commute add_pow_char_pow_of_commute
theorem sub_pow_char_of_commute [Ring R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R)
(h : Commute x y) : (x - y) ^ p = x ^ p - y ^ p := by
rw [eq_sub_iff_add_eq, ← add_pow_char_of_commute _ _ _ (Commute.sub_left h rfl)]
simp
#align sub_pow_char_of_commute sub_pow_char_of_commute
theorem sub_pow_char_pow_of_commute [Ring R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R)
(h : Commute x y) : (x - y) ^ p ^ n = x ^ p ^ n - y ^ p ^ n := by
induction n with
| zero => simp
| succ n n_ih =>
rw [pow_succ, pow_mul, pow_mul, pow_mul, n_ih]
apply sub_pow_char_of_commute; apply Commute.pow_pow h
#align sub_pow_char_pow_of_commute sub_pow_char_pow_of_commute
theorem add_pow_char [CommSemiring R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R) :
(x + y) ^ p = x ^ p + y ^ p :=
add_pow_char_of_commute _ _ _ (Commute.all _ _)
#align add_pow_char add_pow_char
theorem add_pow_char_pow [CommSemiring R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R) :
(x + y) ^ p ^ n = x ^ p ^ n + y ^ p ^ n :=
add_pow_char_pow_of_commute _ _ _ (Commute.all _ _)
#align add_pow_char_pow add_pow_char_pow
theorem sub_pow_char [CommRing R] {p : ℕ} [Fact p.Prime] [CharP R p] (x y : R) :
(x - y) ^ p = x ^ p - y ^ p :=
sub_pow_char_of_commute _ _ _ (Commute.all _ _)
#align sub_pow_char sub_pow_char
theorem sub_pow_char_pow [CommRing R] {p : ℕ} [Fact p.Prime] [CharP R p] {n : ℕ} (x y : R) :
(x - y) ^ p ^ n = x ^ p ^ n - y ^ p ^ n :=
sub_pow_char_pow_of_commute _ _ _ (Commute.all _ _)
#align sub_pow_char_pow sub_pow_char_pow
theorem CharP.neg_one_pow_char [Ring R] (p : ℕ) [CharP R p] [Fact p.Prime] :
(-1 : R) ^ p = -1 := by
rw [eq_neg_iff_add_eq_zero]
nth_rw 2 [← one_pow p]
rw [← add_pow_char_of_commute R _ _ (Commute.one_right _), add_left_neg,
zero_pow (Fact.out (p := Nat.Prime p)).ne_zero]
#align char_p.neg_one_pow_char CharP.neg_one_pow_char
theorem CharP.neg_one_pow_char_pow [Ring R] (p n : ℕ) [CharP R p] [Fact p.Prime] :
(-1 : R) ^ p ^ n = -1 := by
rw [eq_neg_iff_add_eq_zero]
nth_rw 2 [← one_pow (p ^ n)]
rw [← add_pow_char_pow_of_commute R _ _ (Commute.one_right _), add_left_neg,
zero_pow (pow_ne_zero _ (Fact.out (p := Nat.Prime p)).ne_zero)]
#align char_p.neg_one_pow_char_pow CharP.neg_one_pow_char_pow
namespace CharP
section
variable [NonAssocRing R]
/-- The characteristic of a finite ring cannot be zero. -/
| Mathlib/Algebra/CharP/Basic.lean | 162 | 166 | theorem char_ne_zero_of_finite (p : ℕ) [CharP R p] [Finite R] : p ≠ 0 := by |
rintro rfl
haveI : CharZero R := charP_to_charZero R
cases nonempty_fintype R
exact absurd Nat.cast_injective (not_injective_infinite_finite ((↑) : ℕ → R))
|
/-
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.ExteriorAlgebra.Basic
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.Dual
#align_import linear_algebra.clifford_algebra.contraction from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a"
/-!
# Contraction in Clifford Algebras
This file contains some of the results from [grinberg_clifford_2016][].
The key result is `CliffordAlgebra.equivExterior`.
## Main definitions
* `CliffordAlgebra.contractLeft`: contract a multivector by a `Module.Dual R M` on the left.
* `CliffordAlgebra.contractRight`: contract a multivector by a `Module.Dual R M` on the right.
* `CliffordAlgebra.changeForm`: convert between two algebras of different quadratic form, sending
vectors to vectors. The difference of the quadratic forms must be a bilinear form.
* `CliffordAlgebra.equivExterior`: in characteristic not-two, the `CliffordAlgebra Q` is
isomorphic as a module to the exterior algebra.
## Implementation notes
This file somewhat follows [grinberg_clifford_2016][], although we are missing some of the induction
principles needed to prove many of the results. Here, we avoid the quotient-based approach described
in [grinberg_clifford_2016][], instead directly constructing our objects using the universal
property.
Note that [grinberg_clifford_2016][] concludes that its contents are not novel, and are in fact just
a rehash of parts of [bourbaki2007][]; we should at some point consider swapping our references to
refer to the latter.
Within this file, we use the local notation
* `x ⌊ d` for `contractRight x d`
* `d ⌋ x` for `contractLeft d x`
-/
open LinearMap (BilinForm)
universe u1 u2 u3
variable {R : Type u1} [CommRing R]
variable {M : Type u2} [AddCommGroup M] [Module R M]
variable (Q : QuadraticForm R M)
namespace CliffordAlgebra
section contractLeft
variable (d d' : Module.Dual R M)
/-- Auxiliary construction for `CliffordAlgebra.contractLeft` -/
@[simps!]
def contractLeftAux (d : Module.Dual R M) :
M →ₗ[R] CliffordAlgebra Q × CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q :=
haveI v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q
d.smulRight (LinearMap.fst _ (CliffordAlgebra Q) (CliffordAlgebra Q)) -
v_mul.compl₂ (LinearMap.snd _ (CliffordAlgebra Q) _)
#align clifford_algebra.contract_left_aux CliffordAlgebra.contractLeftAux
theorem contractLeftAux_contractLeftAux (v : M) (x : CliffordAlgebra Q) (fx : CliffordAlgebra Q) :
contractLeftAux Q d v (ι Q v * x, contractLeftAux Q d v (x, fx)) = Q v • fx := by
simp only [contractLeftAux_apply_apply]
rw [mul_sub, ← mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← sub_add, mul_smul_comm, sub_self,
zero_add]
#align clifford_algebra.contract_left_aux_contract_left_aux CliffordAlgebra.contractLeftAux_contractLeftAux
variable {Q}
/-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the left.
Note that $v ⌋ x$ is spelt `contractLeft (Q.associated v) x`.
This includes [grinberg_clifford_2016][] Theorem 10.75 -/
def contractLeft : Module.Dual R M →ₗ[R] CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q where
toFun d := foldr' Q (contractLeftAux Q d) (contractLeftAux_contractLeftAux Q d) 0
map_add' d₁ d₂ :=
LinearMap.ext fun x => by
dsimp only
rw [LinearMap.add_apply]
induction' x using CliffordAlgebra.left_induction with r x y hx hy m x hx
· simp_rw [foldr'_algebraMap, smul_zero, zero_add]
· rw [map_add, map_add, map_add, add_add_add_comm, hx, hy]
· rw [foldr'_ι_mul, foldr'_ι_mul, foldr'_ι_mul, hx]
dsimp only [contractLeftAux_apply_apply]
rw [sub_add_sub_comm, mul_add, LinearMap.add_apply, add_smul]
map_smul' c d :=
LinearMap.ext fun x => by
dsimp only
rw [LinearMap.smul_apply, RingHom.id_apply]
induction' x using CliffordAlgebra.left_induction with r x y hx hy m x hx
· simp_rw [foldr'_algebraMap, smul_zero]
· rw [map_add, map_add, smul_add, hx, hy]
· rw [foldr'_ι_mul, foldr'_ι_mul, hx]
dsimp only [contractLeftAux_apply_apply]
rw [LinearMap.smul_apply, smul_assoc, mul_smul_comm, smul_sub]
#align clifford_algebra.contract_left CliffordAlgebra.contractLeft
/-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the
right.
Note that $x ⌊ v$ is spelt `contractRight x (Q.associated v)`.
This includes [grinberg_clifford_2016][] Theorem 16.75 -/
def contractRight : CliffordAlgebra Q →ₗ[R] Module.Dual R M →ₗ[R] CliffordAlgebra Q :=
LinearMap.flip (LinearMap.compl₂ (LinearMap.compr₂ contractLeft reverse) reverse)
#align clifford_algebra.contract_right CliffordAlgebra.contractRight
theorem contractRight_eq (x : CliffordAlgebra Q) :
contractRight (Q := Q) x d = reverse (contractLeft (R := R) (M := M) d <| reverse x) :=
rfl
#align clifford_algebra.contract_right_eq CliffordAlgebra.contractRight_eq
local infixl:70 "⌋" => contractLeft (R := R) (M := M)
local infixl:70 "⌊" => contractRight (R := R) (M := M) (Q := Q)
-- Porting note: Lean needs to be reminded of this instance otherwise the statement of the
-- next result times out
instance : SMul R (CliffordAlgebra Q) := inferInstance
/-- This is [grinberg_clifford_2016][] Theorem 6 -/
theorem contractLeft_ι_mul (a : M) (b : CliffordAlgebra Q) :
d⌋(ι Q a * b) = d a • b - ι Q a * (d⌋b) := by
-- Porting note: Lean cannot figure out anymore the third argument
refine foldr'_ι_mul _ _ ?_ _ _ _
exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx
#align clifford_algebra.contract_left_ι_mul CliffordAlgebra.contractLeft_ι_mul
/-- This is [grinberg_clifford_2016][] Theorem 12 -/
theorem contractRight_mul_ι (a : M) (b : CliffordAlgebra Q) :
b * ι Q a⌊d = d a • b - b⌊d * ι Q a := by
rw [contractRight_eq, reverse.map_mul, reverse_ι, contractLeft_ι_mul, map_sub, map_smul,
reverse_reverse, reverse.map_mul, reverse_ι, contractRight_eq]
#align clifford_algebra.contract_right_mul_ι CliffordAlgebra.contractRight_mul_ι
theorem contractLeft_algebraMap_mul (r : R) (b : CliffordAlgebra Q) :
d⌋(algebraMap _ _ r * b) = algebraMap _ _ r * (d⌋b) := by
rw [← Algebra.smul_def, map_smul, Algebra.smul_def]
#align clifford_algebra.contract_left_algebra_map_mul CliffordAlgebra.contractLeft_algebraMap_mul
theorem contractLeft_mul_algebraMap (a : CliffordAlgebra Q) (r : R) :
d⌋(a * algebraMap _ _ r) = d⌋a * algebraMap _ _ r := by
rw [← Algebra.commutes, contractLeft_algebraMap_mul, Algebra.commutes]
#align clifford_algebra.contract_left_mul_algebra_map CliffordAlgebra.contractLeft_mul_algebraMap
theorem contractRight_algebraMap_mul (r : R) (b : CliffordAlgebra Q) :
algebraMap _ _ r * b⌊d = algebraMap _ _ r * (b⌊d) := by
rw [← Algebra.smul_def, LinearMap.map_smul₂, Algebra.smul_def]
#align clifford_algebra.contract_right_algebra_map_mul CliffordAlgebra.contractRight_algebraMap_mul
theorem contractRight_mul_algebraMap (a : CliffordAlgebra Q) (r : R) :
a * algebraMap _ _ r⌊d = a⌊d * algebraMap _ _ r := by
rw [← Algebra.commutes, contractRight_algebraMap_mul, Algebra.commutes]
#align clifford_algebra.contract_right_mul_algebra_map CliffordAlgebra.contractRight_mul_algebraMap
variable (Q)
@[simp]
theorem contractLeft_ι (x : M) : d⌋ι Q x = algebraMap R _ (d x) := by
-- Porting note: Lean cannot figure out anymore the third argument
refine (foldr'_ι _ _ ?_ _ _).trans <| by
simp_rw [contractLeftAux_apply_apply, mul_zero, sub_zero,
Algebra.algebraMap_eq_smul_one]
exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx
#align clifford_algebra.contract_left_ι CliffordAlgebra.contractLeft_ι
@[simp]
theorem contractRight_ι (x : M) : ι Q x⌊d = algebraMap R _ (d x) := by
rw [contractRight_eq, reverse_ι, contractLeft_ι, reverse.commutes]
#align clifford_algebra.contract_right_ι CliffordAlgebra.contractRight_ι
@[simp]
theorem contractLeft_algebraMap (r : R) : d⌋algebraMap R (CliffordAlgebra Q) r = 0 := by
-- Porting note: Lean cannot figure out anymore the third argument
refine (foldr'_algebraMap _ _ ?_ _ _).trans <| smul_zero _
exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx
#align clifford_algebra.contract_left_algebra_map CliffordAlgebra.contractLeft_algebraMap
@[simp]
theorem contractRight_algebraMap (r : R) : algebraMap R (CliffordAlgebra Q) r⌊d = 0 := by
rw [contractRight_eq, reverse.commutes, contractLeft_algebraMap, map_zero]
#align clifford_algebra.contract_right_algebra_map CliffordAlgebra.contractRight_algebraMap
@[simp]
theorem contractLeft_one : d⌋(1 : CliffordAlgebra Q) = 0 := by
simpa only [map_one] using contractLeft_algebraMap Q d 1
#align clifford_algebra.contract_left_one CliffordAlgebra.contractLeft_one
@[simp]
theorem contractRight_one : (1 : CliffordAlgebra Q)⌊d = 0 := by
simpa only [map_one] using contractRight_algebraMap Q d 1
#align clifford_algebra.contract_right_one CliffordAlgebra.contractRight_one
variable {Q}
/-- This is [grinberg_clifford_2016][] Theorem 7 -/
theorem contractLeft_contractLeft (x : CliffordAlgebra Q) : d⌋(d⌋x) = 0 := by
induction' x using CliffordAlgebra.left_induction with r x y hx hy m x hx
· simp_rw [contractLeft_algebraMap, map_zero]
· rw [map_add, map_add, hx, hy, add_zero]
· rw [contractLeft_ι_mul, map_sub, contractLeft_ι_mul, hx, LinearMap.map_smul,
mul_zero, sub_zero, sub_self]
#align clifford_algebra.contract_left_contract_left CliffordAlgebra.contractLeft_contractLeft
/-- This is [grinberg_clifford_2016][] Theorem 13 -/
theorem contractRight_contractRight (x : CliffordAlgebra Q) : x⌊d⌊d = 0 := by
rw [contractRight_eq, contractRight_eq, reverse_reverse, contractLeft_contractLeft, map_zero]
#align clifford_algebra.contract_right_contract_right CliffordAlgebra.contractRight_contractRight
/-- This is [grinberg_clifford_2016][] Theorem 8 -/
theorem contractLeft_comm (x : CliffordAlgebra Q) : d⌋(d'⌋x) = -(d'⌋(d⌋x)) := by
induction' x using CliffordAlgebra.left_induction with r x y hx hy m x hx
· simp_rw [contractLeft_algebraMap, map_zero, neg_zero]
· rw [map_add, map_add, map_add, map_add, hx, hy, neg_add]
· simp only [contractLeft_ι_mul, map_sub, LinearMap.map_smul]
rw [neg_sub, sub_sub_eq_add_sub, hx, mul_neg, ← sub_eq_add_neg]
#align clifford_algebra.contract_left_comm CliffordAlgebra.contractLeft_comm
/-- This is [grinberg_clifford_2016][] Theorem 14 -/
theorem contractRight_comm (x : CliffordAlgebra Q) : x⌊d⌊d' = -(x⌊d'⌊d) := by
rw [contractRight_eq, contractRight_eq, contractRight_eq, contractRight_eq, reverse_reverse,
reverse_reverse, contractLeft_comm, map_neg]
#align clifford_algebra.contract_right_comm CliffordAlgebra.contractRight_comm
/- TODO:
lemma contractRight_contractLeft (x : CliffordAlgebra Q) : (d ⌋ x) ⌊ d' = d ⌋ (x ⌊ d') :=
-/
end contractLeft
local infixl:70 "⌋" => contractLeft
local infixl:70 "⌊" => contractRight
/-- Auxiliary construction for `CliffordAlgebra.changeForm` -/
@[simps!]
def changeFormAux (B : BilinForm R M) : M →ₗ[R] CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q :=
haveI v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q
v_mul - contractLeft ∘ₗ B
#align clifford_algebra.change_form_aux CliffordAlgebra.changeFormAux
theorem changeFormAux_changeFormAux (B : BilinForm R M) (v : M) (x : CliffordAlgebra Q) :
changeFormAux Q B v (changeFormAux Q B v x) = (Q v - B v v) • x := by
simp only [changeFormAux_apply_apply]
rw [mul_sub, ← mul_assoc, ι_sq_scalar, map_sub, contractLeft_ι_mul, ← sub_add, sub_sub_sub_comm,
← Algebra.smul_def, sub_self, sub_zero, contractLeft_contractLeft, add_zero, sub_smul]
#align clifford_algebra.change_form_aux_change_form_aux CliffordAlgebra.changeFormAux_changeFormAux
variable {Q}
variable {Q' Q'' : QuadraticForm R M} {B B' : BilinForm R M}
variable (h : B.toQuadraticForm = Q' - Q) (h' : B'.toQuadraticForm = Q'' - Q')
/-- Convert between two algebras of different quadratic form, sending vector to vectors, scalars to
scalars, and adjusting products by a contraction term.
This is $\lambda_B$ from [bourbaki2007][] $9 Lemma 2. -/
def changeForm (h : B.toQuadraticForm = Q' - Q) : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q' :=
foldr Q (changeFormAux Q' B)
(fun m x =>
(changeFormAux_changeFormAux Q' B m x).trans <| by
dsimp only [← BilinForm.toQuadraticForm_apply]
rw [h, QuadraticForm.sub_apply, sub_sub_cancel])
1
#align clifford_algebra.change_form CliffordAlgebra.changeForm
/-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/
theorem changeForm.zero_proof : (0 : BilinForm R M).toQuadraticForm = Q - Q :=
(sub_self _).symm
#align clifford_algebra.change_form.zero_proof CliffordAlgebra.changeForm.zero_proof
/-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/
theorem changeForm.add_proof : (B + B').toQuadraticForm = Q'' - Q :=
(congr_arg₂ (· + ·) h h').trans <| sub_add_sub_cancel' _ _ _
#align clifford_algebra.change_form.add_proof CliffordAlgebra.changeForm.add_proof
/-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/
theorem changeForm.neg_proof : (-B).toQuadraticForm = Q - Q' :=
(congr_arg Neg.neg h).trans <| neg_sub _ _
#align clifford_algebra.change_form.neg_proof CliffordAlgebra.changeForm.neg_proof
theorem changeForm.associated_neg_proof [Invertible (2 : R)] :
(QuadraticForm.associated (R := R) (M := M) (-Q)).toQuadraticForm = 0 - Q := by
simp [QuadraticForm.toQuadraticForm_associated]
#align clifford_algebra.change_form.associated_neg_proof CliffordAlgebra.changeForm.associated_neg_proof
@[simp]
theorem changeForm_algebraMap (r : R) : changeForm h (algebraMap R _ r) = algebraMap R _ r :=
(foldr_algebraMap _ _ _ _ _).trans <| Eq.symm <| Algebra.algebraMap_eq_smul_one r
#align clifford_algebra.change_form_algebra_map CliffordAlgebra.changeForm_algebraMap
@[simp]
theorem changeForm_one : changeForm h (1 : CliffordAlgebra Q) = 1 := by
simpa using changeForm_algebraMap h (1 : R)
#align clifford_algebra.change_form_one CliffordAlgebra.changeForm_one
@[simp]
theorem changeForm_ι (m : M) : changeForm h (ι (M := M) Q m) = ι (M := M) Q' m :=
(foldr_ι _ _ _ _ _).trans <|
Eq.symm <| by rw [changeFormAux_apply_apply, mul_one, contractLeft_one, sub_zero]
#align clifford_algebra.change_form_ι CliffordAlgebra.changeForm_ι
theorem changeForm_ι_mul (m : M) (x : CliffordAlgebra Q) :
changeForm h (ι (M := M) Q m * x) = ι (M := M) Q' m * changeForm h x
- contractLeft (Q := Q') (B m) (changeForm h x) :=
-- Porting note: original statement
-- - BilinForm.toLin B m⌋changeForm h x :=
(foldr_mul _ _ _ _ _ _).trans <| by rw [foldr_ι]; rfl
#align clifford_algebra.change_form_ι_mul CliffordAlgebra.changeForm_ι_mul
| Mathlib/LinearAlgebra/CliffordAlgebra/Contraction.lean | 317 | 319 | theorem changeForm_ι_mul_ι (m₁ m₂ : M) :
changeForm h (ι Q m₁ * ι Q m₂) = ι Q' m₁ * ι Q' m₂ - algebraMap _ _ (B m₁ m₂) := by |
rw [changeForm_ι_mul, changeForm_ι, contractLeft_ι]
|
/-
Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu
-/
import Mathlib.Data.Fintype.Parity
import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup
import Mathlib.Analysis.Complex.Basic
import Mathlib.GroupTheory.GroupAction.Defs
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup
import Mathlib.Tactic.AdaptationNote
import Mathlib.Tactic.LinearCombination
#align_import analysis.complex.upper_half_plane.basic from "leanprover-community/mathlib"@"34d3797325d202bd7250431275bb871133cdb611"
/-!
# The upper half plane and its automorphisms
This file defines `UpperHalfPlane` to be the upper half plane in `ℂ`.
We furthermore equip it with the structure of a `GLPos 2 ℝ` action by
fractional linear transformations.
We define the notation `ℍ` for the upper half plane available in the locale
`UpperHalfPlane` so as not to conflict with the quaternions.
-/
set_option linter.uppercaseLean3 false
noncomputable section
open Matrix Matrix.SpecialLinearGroup
open scoped Classical MatrixGroups
/- Disable these instances as they are not the simp-normal form, and having them disabled ensures
we state lemmas in this file without spurious `coe_fn` terms. -/
attribute [-instance] Matrix.SpecialLinearGroup.instCoeFun
attribute [-instance] Matrix.GeneralLinearGroup.instCoeFun
local notation "GL(" n ", " R ")" "⁺" => Matrix.GLPos (Fin n) R
local notation:1024 "↑ₘ" A:1024 =>
(((A : GL(2, ℝ)⁺) : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) _)
local notation:1024 "↑ₘ[" R "]" A:1024 =>
((A : GL (Fin 2) R) : Matrix (Fin 2) (Fin 2) R)
/-- The open upper half plane -/
def UpperHalfPlane :=
{ point : ℂ // 0 < point.im }
#align upper_half_plane UpperHalfPlane
@[inherit_doc] scoped[UpperHalfPlane] notation "ℍ" => UpperHalfPlane
open UpperHalfPlane
namespace UpperHalfPlane
/-- Canonical embedding of the upper half-plane into `ℂ`. -/
@[coe] protected def coe (z : ℍ) : ℂ := z.1
-- Porting note: added to replace `deriving`
instance : CoeOut ℍ ℂ := ⟨UpperHalfPlane.coe⟩
instance : Inhabited ℍ :=
⟨⟨Complex.I, by simp⟩⟩
@[ext] theorem ext {a b : ℍ} (h : (a : ℂ) = b) : a = b := Subtype.eq h
@[simp, norm_cast] theorem ext_iff {a b : ℍ} : (a : ℂ) = b ↔ a = b := Subtype.coe_inj
instance canLift : CanLift ℂ ℍ ((↑) : ℍ → ℂ) fun z => 0 < z.im :=
Subtype.canLift fun (z : ℂ) => 0 < z.im
#align upper_half_plane.can_lift UpperHalfPlane.canLift
/-- Imaginary part -/
def im (z : ℍ) :=
(z : ℂ).im
#align upper_half_plane.im UpperHalfPlane.im
/-- Real part -/
def re (z : ℍ) :=
(z : ℂ).re
#align upper_half_plane.re UpperHalfPlane.re
/-- Extensionality lemma in terms of `UpperHalfPlane.re` and `UpperHalfPlane.im`. -/
theorem ext' {a b : ℍ} (hre : a.re = b.re) (him : a.im = b.im) : a = b :=
ext <| Complex.ext hre him
/-- Constructor for `UpperHalfPlane`. It is useful if `⟨z, h⟩` makes Lean use a wrong
typeclass instance. -/
def mk (z : ℂ) (h : 0 < z.im) : ℍ :=
⟨z, h⟩
#align upper_half_plane.mk UpperHalfPlane.mk
@[simp]
theorem coe_im (z : ℍ) : (z : ℂ).im = z.im :=
rfl
#align upper_half_plane.coe_im UpperHalfPlane.coe_im
@[simp]
theorem coe_re (z : ℍ) : (z : ℂ).re = z.re :=
rfl
#align upper_half_plane.coe_re UpperHalfPlane.coe_re
@[simp]
theorem mk_re (z : ℂ) (h : 0 < z.im) : (mk z h).re = z.re :=
rfl
#align upper_half_plane.mk_re UpperHalfPlane.mk_re
@[simp]
theorem mk_im (z : ℂ) (h : 0 < z.im) : (mk z h).im = z.im :=
rfl
#align upper_half_plane.mk_im UpperHalfPlane.mk_im
@[simp]
theorem coe_mk (z : ℂ) (h : 0 < z.im) : (mk z h : ℂ) = z :=
rfl
#align upper_half_plane.coe_mk UpperHalfPlane.coe_mk
@[simp]
theorem mk_coe (z : ℍ) (h : 0 < (z : ℂ).im := z.2) : mk z h = z :=
rfl
#align upper_half_plane.mk_coe UpperHalfPlane.mk_coe
theorem re_add_im (z : ℍ) : (z.re + z.im * Complex.I : ℂ) = z :=
Complex.re_add_im z
#align upper_half_plane.re_add_im UpperHalfPlane.re_add_im
theorem im_pos (z : ℍ) : 0 < z.im :=
z.2
#align upper_half_plane.im_pos UpperHalfPlane.im_pos
theorem im_ne_zero (z : ℍ) : z.im ≠ 0 :=
z.im_pos.ne'
#align upper_half_plane.im_ne_zero UpperHalfPlane.im_ne_zero
theorem ne_zero (z : ℍ) : (z : ℂ) ≠ 0 :=
mt (congr_arg Complex.im) z.im_ne_zero
#align upper_half_plane.ne_zero UpperHalfPlane.ne_zero
/-- Define I := √-1 as an element on the upper half plane. -/
def I : ℍ := ⟨Complex.I, by simp⟩
@[simp]
lemma I_im : I.im = 1 := rfl
@[simp]
lemma I_re : I.re = 0 := rfl
@[simp, norm_cast]
lemma coe_I : I = Complex.I := rfl
end UpperHalfPlane
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
/-- Extension for the `positivity` tactic: `UpperHalfPlane.im`. -/
@[positivity UpperHalfPlane.im _]
def evalUpperHalfPlaneIm : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(UpperHalfPlane.im $a) =>
assertInstancesCommute
pure (.positive q(@UpperHalfPlane.im_pos $a))
| _, _, _ => throwError "not UpperHalfPlane.im"
/-- Extension for the `positivity` tactic: `UpperHalfPlane.coe`. -/
@[positivity UpperHalfPlane.coe _]
def evalUpperHalfPlaneCoe : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℂ), ~q(UpperHalfPlane.coe $a) =>
assertInstancesCommute
pure (.nonzero q(@UpperHalfPlane.ne_zero $a))
| _, _, _ => throwError "not UpperHalfPlane.coe"
end Mathlib.Meta.Positivity
namespace UpperHalfPlane
| Mathlib/Analysis/Complex/UpperHalfPlane/Basic.lean | 181 | 182 | theorem normSq_pos (z : ℍ) : 0 < Complex.normSq (z : ℂ) := by |
rw [Complex.normSq_pos]; exact z.ne_zero
|
/-
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
| .lake/packages/batteries/Batteries/Data/List/Lemmas.lean | 564 | 567 | 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'
|
/-
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.BoxIntegral.Basic
import Mathlib.MeasureTheory.Integral.SetIntegral
import Mathlib.Tactic.Generalize
#align_import analysis.box_integral.integrability from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844"
/-!
# McShane integrability vs Bochner integrability
In this file we prove that any Bochner integrable function is McShane integrable (hence, it is
Henstock and `GP` integrable) with the same integral. The proof is based on
[Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55].
We deduce that the same is true for the Riemann integral for continuous functions.
## Tags
integral, McShane integral, Bochner integral
-/
open scoped Classical NNReal ENNReal Topology
universe u v
variable {ι : Type u} {E : Type v} [Fintype ι] [NormedAddCommGroup E] [NormedSpace ℝ E]
open MeasureTheory Metric Set Finset Filter BoxIntegral
namespace BoxIntegral
/-- The indicator function of a measurable set is McShane integrable with respect to any
locally-finite measure. -/
| Mathlib/Analysis/BoxIntegral/Integrability.lean | 39 | 99 | theorem hasIntegralIndicatorConst (l : IntegrationParams) (hl : l.bRiemann = false)
{s : Set (ι → ℝ)} (hs : MeasurableSet s) (I : Box ι) (y : E) (μ : Measure (ι → ℝ))
[IsLocallyFiniteMeasure μ] :
HasIntegral.{u, v, v} I l (s.indicator fun _ => y) μ.toBoxAdditive.toSMul
((μ (s ∩ I)).toReal • y) := by |
refine HasIntegral.of_mul ‖y‖ fun ε ε0 => ?_
lift ε to ℝ≥0 using ε0.le; rw [NNReal.coe_pos] at ε0
/- First we choose a closed set `F ⊆ s ∩ I.Icc` and an open set `U ⊇ s` such that
both `(s ∩ I.Icc) \ F` and `U \ s` have measure less than `ε`. -/
have A : μ (s ∩ Box.Icc I) ≠ ∞ :=
((measure_mono Set.inter_subset_right).trans_lt (I.measure_Icc_lt_top μ)).ne
have B : μ (s ∩ I) ≠ ∞ :=
((measure_mono Set.inter_subset_right).trans_lt (I.measure_coe_lt_top μ)).ne
obtain ⟨F, hFs, hFc, hμF⟩ : ∃ F, F ⊆ s ∩ Box.Icc I ∧ IsClosed F ∧ μ ((s ∩ Box.Icc I) \ F) < ε :=
(hs.inter I.measurableSet_Icc).exists_isClosed_diff_lt A (ENNReal.coe_pos.2 ε0).ne'
obtain ⟨U, hsU, hUo, hUt, hμU⟩ :
∃ U, s ∩ Box.Icc I ⊆ U ∧ IsOpen U ∧ μ U < ∞ ∧ μ (U \ (s ∩ Box.Icc I)) < ε :=
(hs.inter I.measurableSet_Icc).exists_isOpen_diff_lt A (ENNReal.coe_pos.2 ε0).ne'
/- Then we choose `r` so that `closed_ball x (r x) ⊆ U` whenever `x ∈ s ∩ I.Icc` and
`closed_ball x (r x)` is disjoint with `F` otherwise. -/
have : ∀ x ∈ s ∩ Box.Icc I, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ U := fun x hx => by
rcases nhds_basis_closedBall.mem_iff.1 (hUo.mem_nhds <| hsU hx) with ⟨r, hr₀, hr⟩
exact ⟨⟨r, hr₀⟩, hr⟩
choose! rs hrsU using this
have : ∀ x ∈ Box.Icc I \ s, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ Fᶜ := fun x hx => by
obtain ⟨r, hr₀, hr⟩ :=
nhds_basis_closedBall.mem_iff.1 (hFc.isOpen_compl.mem_nhds fun hx' => hx.2 (hFs hx').1)
exact ⟨⟨r, hr₀⟩, hr⟩
choose! rs' hrs'F using this
set r : (ι → ℝ) → Ioi (0 : ℝ) := s.piecewise rs rs'
refine ⟨fun _ => r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c π hπ hπp => ?_⟩; rw [mul_comm]
/- Then the union of boxes `J ∈ π` such that `π.tag ∈ s` includes `F` and is included by `U`,
hence its measure is `ε`-close to the measure of `s`. -/
dsimp [integralSum]
simp only [mem_closedBall, dist_eq_norm, ← indicator_const_smul_apply,
sum_indicator_eq_sum_filter, ← sum_smul, ← sub_smul, norm_smul, Real.norm_eq_abs, ←
Prepartition.filter_boxes, ← Prepartition.measure_iUnion_toReal]
gcongr
set t := (π.filter (π.tag · ∈ s)).iUnion
change abs ((μ t).toReal - (μ (s ∩ I)).toReal) ≤ ε
have htU : t ⊆ U ∩ I := by
simp only [t, TaggedPrepartition.iUnion_def, iUnion_subset_iff, TaggedPrepartition.mem_filter,
and_imp]
refine fun J hJ hJs x hx => ⟨hrsU _ ⟨hJs, π.tag_mem_Icc J⟩ ?_, π.le_of_mem' J hJ hx⟩
simpa only [r, s.piecewise_eq_of_mem _ _ hJs] using hπ.1 J hJ (Box.coe_subset_Icc hx)
refine abs_sub_le_iff.2 ⟨?_, ?_⟩
· refine (ENNReal.le_toReal_sub B).trans (ENNReal.toReal_le_coe_of_le_coe ?_)
refine (tsub_le_tsub (measure_mono htU) le_rfl).trans (le_measure_diff.trans ?_)
refine (measure_mono fun x hx => ?_).trans hμU.le
exact ⟨hx.1.1, fun hx' => hx.2 ⟨hx'.1, hx.1.2⟩⟩
· have hμt : μ t ≠ ∞ := ((measure_mono (htU.trans inter_subset_left)).trans_lt hUt).ne
refine (ENNReal.le_toReal_sub hμt).trans (ENNReal.toReal_le_coe_of_le_coe ?_)
refine le_measure_diff.trans ((measure_mono ?_).trans hμF.le)
rintro x ⟨⟨hxs, hxI⟩, hxt⟩
refine ⟨⟨hxs, Box.coe_subset_Icc hxI⟩, fun hxF => hxt ?_⟩
simp only [t, TaggedPrepartition.iUnion_def, TaggedPrepartition.mem_filter, Set.mem_iUnion]
rcases hπp x hxI with ⟨J, hJπ, hxJ⟩
refine ⟨J, ⟨hJπ, ?_⟩, hxJ⟩
contrapose hxF
refine hrs'F _ ⟨π.tag_mem_Icc J, hxF⟩ ?_
simpa only [r, s.piecewise_eq_of_not_mem _ _ hxF] using hπ.1 J hJπ (Box.coe_subset_Icc hxJ)
|
/-
Copyright (c) 2024 Raghuram Sundararajan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Raghuram Sundararajan
-/
import Mathlib.Algebra.Ring.Defs
import Mathlib.Algebra.Group.Ext
/-!
# Extensionality lemmas for rings and similar structures
In this file we prove extensionality lemmas for the ring-like structures defined in
`Mathlib/Algebra/Ring/Defs.lean`, ranging from `NonUnitalNonAssocSemiring` to `CommRing`. These
extensionality lemmas take the form of asserting that two algebraic structures on a type are equal
whenever the addition and multiplication defined by them are both the same.
## Implementation details
We follow `Mathlib/Algebra/Group/Ext.lean` in using the term `(letI := i; HMul.hMul : R → R → R)` to
refer to the multiplication specified by a typeclass instance `i` on a type `R` (and similarly for
addition). We abbreviate these using some local notations.
Since `Mathlib/Algebra/Group/Ext.lean` proved several injectivity lemmas, we do so as well — even if
sometimes we don't need them to prove extensionality.
## Tags
semiring, ring, extensionality
-/
local macro:max "local_hAdd[" type:term ", " inst:term "]" : term =>
`(term| (letI := $inst; HAdd.hAdd : $type → $type → $type))
local macro:max "local_hMul[" type:term ", " inst:term "]" : term =>
`(term| (letI := $inst; HMul.hMul : $type → $type → $type))
universe u
variable {R : Type u}
/-! ### Distrib -/
namespace Distrib
@[ext] theorem ext ⦃inst₁ inst₂ : Distrib R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) :
inst₁ = inst₂ := by
-- Split into `add` and `mul` functions and properties.
rcases inst₁ with @⟨⟨⟩, ⟨⟩⟩
rcases inst₂ with @⟨⟨⟩, ⟨⟩⟩
-- Prove equality of parts using function extensionality.
congr
theorem ext_iff {inst₁ inst₂ : Distrib R} :
inst₁ = inst₂ ↔
(local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧
(local_hMul[R, inst₁] = local_hMul[R, inst₂]) :=
⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩
end Distrib
/-! ### NonUnitalNonAssocSemiring -/
namespace NonUnitalNonAssocSemiring
@[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocSemiring R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) :
inst₁ = inst₂ := by
-- Split into `AddMonoid` instance, `mul` function and properties.
rcases inst₁ with @⟨_, ⟨⟩⟩
rcases inst₂ with @⟨_, ⟨⟩⟩
-- Prove equality of parts using already-proved extensionality lemmas.
congr; ext : 1; assumption
theorem toDistrib_injective : Function.Injective (@toDistrib R) := by
intro _ _ h
ext x y
· exact congrArg (·.toAdd.add x y) h
· exact congrArg (·.toMul.mul x y) h
theorem ext_iff {inst₁ inst₂ : NonUnitalNonAssocSemiring R} :
inst₁ = inst₂ ↔
(local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧
(local_hMul[R, inst₁] = local_hMul[R, inst₂]) :=
⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩
end NonUnitalNonAssocSemiring
/-! ### NonUnitalSemiring -/
namespace NonUnitalSemiring
theorem toNonUnitalNonAssocSemiring_injective :
Function.Injective (@toNonUnitalNonAssocSemiring R) := by
rintro ⟨⟩ ⟨⟩ _; congr
@[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalSemiring R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) :
inst₁ = inst₂ :=
toNonUnitalNonAssocSemiring_injective <|
NonUnitalNonAssocSemiring.ext h_add h_mul
theorem ext_iff {inst₁ inst₂ : NonUnitalSemiring R} :
inst₁ = inst₂ ↔
(local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧
(local_hMul[R, inst₁] = local_hMul[R, inst₂]) :=
⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩
end NonUnitalSemiring
/-! ### NonAssocSemiring and its ancestors
This section also includes results for `AddMonoidWithOne`, `AddCommMonoidWithOne`, etc.
as these are considered implementation detail of the ring classes.
TODO consider relocating these lemmas.
-/
/- TODO consider relocating these lemmas. -/
@[ext] theorem AddMonoidWithOne.ext ⦃inst₁ inst₂ : AddMonoidWithOne R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) :
inst₁ = inst₂ := by
have h_monoid : inst₁.toAddMonoid = inst₂.toAddMonoid := by ext : 1; exact h_add
have h_zero' : inst₁.toZero = inst₂.toZero := congrArg (·.toZero) h_monoid
have h_one' : inst₁.toOne = inst₂.toOne :=
congrArg One.mk h_one
have h_natCast : inst₁.toNatCast.natCast = inst₂.toNatCast.natCast := by
funext n; induction n with
| zero => rewrite [inst₁.natCast_zero, inst₂.natCast_zero]
exact congrArg (@Zero.zero R) h_zero'
| succ n h => rw [inst₁.natCast_succ, inst₂.natCast_succ, h_add]
exact congrArg₂ _ h h_one
rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩
congr
theorem AddCommMonoidWithOne.toAddMonoidWithOne_injective :
Function.Injective (@AddCommMonoidWithOne.toAddMonoidWithOne R) := by
rintro ⟨⟩ ⟨⟩ _; congr
@[ext] theorem AddCommMonoidWithOne.ext ⦃inst₁ inst₂ : AddCommMonoidWithOne R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) :
inst₁ = inst₂ :=
AddCommMonoidWithOne.toAddMonoidWithOne_injective <|
AddMonoidWithOne.ext h_add h_one
namespace NonAssocSemiring
/- The best place to prove that the `NatCast` is determined by the other operations is probably in
an extensionality lemma for `AddMonoidWithOne`, in which case we may as well do the typeclasses
defined in `Mathlib/Algebra/GroupWithZero/Defs.lean` as well. -/
@[ext] theorem ext ⦃inst₁ inst₂ : NonAssocSemiring R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) :
inst₁ = inst₂ := by
have h : inst₁.toNonUnitalNonAssocSemiring = inst₂.toNonUnitalNonAssocSemiring := by
ext : 1 <;> assumption
have h_zero : (inst₁.toMulZeroClass).toZero.zero = (inst₂.toMulZeroClass).toZero.zero :=
congrArg (fun inst => (inst.toMulZeroClass).toZero.zero) h
have h_one' : (inst₁.toMulZeroOneClass).toMulOneClass.toOne
= (inst₂.toMulZeroOneClass).toMulOneClass.toOne :=
congrArg (@MulOneClass.toOne R) <| by ext : 1; exact h_mul
have h_one : (inst₁.toMulZeroOneClass).toMulOneClass.toOne.one
= (inst₂.toMulZeroOneClass).toMulOneClass.toOne.one :=
congrArg (@One.one R) h_one'
have : inst₁.toAddCommMonoidWithOne = inst₂.toAddCommMonoidWithOne := by
ext : 1 <;> assumption
have : inst₁.toNatCast = inst₂.toNatCast :=
congrArg (·.toNatCast) this
-- Split into `NonUnitalNonAssocSemiring`, `One` and `natCast` instances.
cases inst₁; cases inst₂
congr
theorem toNonUnitalNonAssocSemiring_injective :
Function.Injective (@toNonUnitalNonAssocSemiring R) := by
intro _ _ _
ext <;> congr
theorem ext_iff {inst₁ inst₂ : NonAssocSemiring R} :
inst₁ = inst₂ ↔
(local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧
(local_hMul[R, inst₁] = local_hMul[R, inst₂]) :=
⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩
end NonAssocSemiring
/-! ### NonUnitalNonAssocRing -/
namespace NonUnitalNonAssocRing
@[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocRing R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) :
inst₁ = inst₂ := by
-- Split into `AddCommGroup` instance, `mul` function and properties.
rcases inst₁ with @⟨_, ⟨⟩⟩; rcases inst₂ with @⟨_, ⟨⟩⟩
congr; (ext : 1; assumption)
theorem toNonUnitalNonAssocSemiring_injective :
Function.Injective (@toNonUnitalNonAssocSemiring R) := by
intro _ _ h
-- Use above extensionality lemma to prove injectivity by showing that `h_add` and `h_mul` hold.
ext x y
· exact congrArg (·.toAdd.add x y) h
· exact congrArg (·.toMul.mul x y) h
theorem ext_iff {inst₁ inst₂ : NonUnitalNonAssocRing R} :
inst₁ = inst₂ ↔
(local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧
(local_hMul[R, inst₁] = local_hMul[R, inst₂]) :=
⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩
end NonUnitalNonAssocRing
/-! ### NonUnitalRing -/
namespace NonUnitalRing
@[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalRing R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) :
inst₁ = inst₂ := by
have : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by
ext : 1 <;> assumption
-- Split into fields and prove they are equal using the above.
cases inst₁; cases inst₂
congr
theorem toNonUnitalSemiring_injective :
Function.Injective (@toNonUnitalSemiring R) := by
intro _ _ h
ext x y
· exact congrArg (·.toAdd.add x y) h
· exact congrArg (·.toMul.mul x y) h
theorem toNonUnitalNonAssocring_injective :
Function.Injective (@toNonUnitalNonAssocRing R) := by
intro _ _ _
ext <;> congr
theorem ext_iff {inst₁ inst₂ : NonUnitalRing R} :
inst₁ = inst₂ ↔
(local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧
(local_hMul[R, inst₁] = local_hMul[R, inst₂]) :=
⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩
end NonUnitalRing
/-! ### NonAssocRing and its ancestors
This section also includes results for `AddGroupWithOne`, `AddCommGroupWithOne`, etc.
as these are considered implementation detail of the ring classes.
TODO consider relocating these lemmas. -/
@[ext] theorem AddGroupWithOne.ext ⦃inst₁ inst₂ : AddGroupWithOne R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) :
inst₁ = inst₂ := by
have : inst₁.toAddMonoidWithOne = inst₂.toAddMonoidWithOne :=
AddMonoidWithOne.ext h_add h_one
have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this
have h_group : inst₁.toAddGroup = inst₂.toAddGroup := by ext : 1; exact h_add
-- Extract equality of necessary substructures from h_group
injection h_group with h_group; injection h_group
have : inst₁.toIntCast.intCast = inst₂.toIntCast.intCast := by
funext n; cases n with
| ofNat n => rewrite [Int.ofNat_eq_coe, inst₁.intCast_ofNat, inst₂.intCast_ofNat]; congr
| negSucc n => rewrite [inst₁.intCast_negSucc, inst₂.intCast_negSucc]; congr
rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩
congr
@[ext] theorem AddCommGroupWithOne.ext ⦃inst₁ inst₂ : AddCommGroupWithOne R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) :
inst₁ = inst₂ := by
have : inst₁.toAddCommGroup = inst₂.toAddCommGroup :=
AddCommGroup.ext h_add
have : inst₁.toAddGroupWithOne = inst₂.toAddGroupWithOne :=
AddGroupWithOne.ext h_add h_one
injection this with _ h_addMonoidWithOne; injection h_addMonoidWithOne
cases inst₁; cases inst₂
congr
namespace NonAssocRing
@[ext] theorem ext ⦃inst₁ inst₂ : NonAssocRing R⦄
(h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
(h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) :
inst₁ = inst₂ := by
have h₁ : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by
ext : 1 <;> assumption
have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by
ext : 1 <;> assumption
-- Mathematically non-trivial fact: `intCast` is determined by the rest.
have h₃ : inst₁.toAddCommGroupWithOne = inst₂.toAddCommGroupWithOne :=
AddCommGroupWithOne.ext h_add (congrArg (·.toOne.one) h₂)
cases inst₁; cases inst₂
congr <;> solve| injection h₁ | injection h₂ | injection h₃
| Mathlib/Algebra/Ring/Ext.lean | 294 | 299 | theorem toNonAssocSemiring_injective :
Function.Injective (@toNonAssocSemiring R) := by |
intro _ _ h
ext x y
· exact congrArg (·.toAdd.add x y) h
· exact congrArg (·.toMul.mul x y) h
|
/-
Copyright (c) 2023 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Analysis.Normed.Field.InfiniteSum
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.NumberTheory.ArithmeticFunction
import Mathlib.NumberTheory.SmoothNumbers
/-!
# Euler Products
The main result in this file is `EulerProduct.eulerProduct_hasProd`, which says that
if `f : ℕ → R` is norm-summable, where `R` is a complete normed commutative ring and `f` is
multiplicative on coprime arguments with `f 0 = 0`, then
`∏' p : Primes, ∑' e : ℕ, f (p^e)` converges to `∑' n, f n`.
`ArithmeticFunction.IsMultiplicative.eulerProduct_hasProd` is a version
for multiplicative arithmetic functions in the sense of
`ArithmeticFunction.IsMultiplicative`.
There is also a version `EulerProduct.eulerProduct_completely_multiplicative_hasProd`,
which states that `∏' p : Primes, (1 - f p)⁻¹` converges to `∑' n, f n`
when `f` is completely multiplicative with values in a complete normed field `F`
(implemented as `f : ℕ →*₀ F`).
There are variants stating the equality of the infinite product and the infinite sum
(`EulerProduct.eulerProduct_tprod`, `ArithmeticFunction.IsMultiplicative.eulerProduct_tprod`,
`EulerProduct.eulerProduct_completely_multiplicative_tprod`) and also variants stating
the convergence of the sequence of partial products over primes `< n`
(`EulerProduct.eulerProduct`, `ArithmeticFunction.IsMultiplicative.eulerProduct`,
`EulerProduct.eulerProduct_completely_multiplicative`.)
An intermediate step is `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum`
(and its variant `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric`),
which relates the finite product over primes `p ∈ s` to the sum of `f n` over `s`-factored `n`,
for `s : Finset ℕ`.
## Tags
Euler product, multiplicative function
-/
/-- If `f` is multiplicative and summable, then its values at natural numbers `> 1`
have norm strictly less than `1`. -/
lemma Summable.norm_lt_one {F : Type*} [NormedField F] [CompleteSpace F] {f : ℕ →* F}
(hsum : Summable f) {p : ℕ} (hp : 1 < p) :
‖f p‖ < 1 := by
refine summable_geometric_iff_norm_lt_one.mp ?_
simp_rw [← map_pow]
exact hsum.comp_injective <| Nat.pow_right_injective hp
open scoped Topology
open Nat Finset
section General
/-!
### General Euler Products
In this section we consider multiplicative (on coprime arguments) functions `f : ℕ → R`,
where `R` is a complete normed commutative ring. The main result is `EulerProduct.eulerProduct`.
-/
variable {R : Type*} [NormedCommRing R] [CompleteSpace R] {f : ℕ → R}
variable (hf₁ : f 1 = 1) (hmul : ∀ {m n}, Nat.Coprime m n → f (m * n) = f m * f n)
-- local instance to speed up typeclass search
@[local instance] private lemma instT0Space : T0Space R := MetricSpace.instT0Space
namespace EulerProduct
/-- We relate a finite product over primes in `s` to an infinite sum over `s`-factored numbers. -/
lemma summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum
(hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (s : Finset ℕ) :
Summable (fun m : factoredNumbers s ↦ ‖f m‖) ∧
HasSum (fun m : factoredNumbers s ↦ f m)
(∏ p ∈ s.filter Nat.Prime, ∑' n : ℕ, f (p ^ n)) := by
induction' s using Finset.induction with p s hp ih
· rw [factoredNumbers_empty]
simp only [not_mem_empty, IsEmpty.forall_iff, forall_const, filter_true_of_mem, prod_empty]
exact ⟨(Set.finite_singleton 1).summable (‖f ·‖), hf₁ ▸ hasSum_singleton 1 f⟩
· rw [filter_insert]
split_ifs with hpp
· constructor
· simp only [← (equivProdNatFactoredNumbers hpp hp).summable_iff, Function.comp_def,
equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp]
refine Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_mul_le ..) ?_
apply Summable.mul_of_nonneg (hsum hpp) ih.1 <;> exact fun n ↦ norm_nonneg _
· have hp' : p ∉ s.filter Nat.Prime := mt (mem_of_mem_filter p) hp
rw [prod_insert hp', ← (equivProdNatFactoredNumbers hpp hp).hasSum_iff, Function.comp_def]
conv =>
enter [1, x]
rw [equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp]
have : T3Space R := instT3Space -- speeds up the following
apply (hsum hpp).of_norm.hasSum.mul ih.2
-- `exact summable_mul_of_summable_norm (hsum hpp) ih.1` gives a time-out
apply summable_mul_of_summable_norm (hsum hpp) ih.1
· rwa [factoredNumbers_insert s hpp]
/-- A version of `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum`
in terms of the value of the series. -/
lemma prod_filter_prime_tsum_eq_tsum_factoredNumbers (hsum : Summable (‖f ·‖)) (s : Finset ℕ) :
∏ p ∈ s.filter Nat.Prime, ∑' n : ℕ, f (p ^ n) = ∑' m : factoredNumbers s, f m :=
(summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul
(fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm
/-- The following statement says that summing over `s`-factored numbers such that
`s` contains `primesBelow N` for large enough `N` gets us arbitrarily close to the sum
over all natural numbers (assuming `f` is summable and `f 0 = 0`; the latter since
`0` is not `s`-factored). -/
lemma norm_tsum_factoredNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0) {ε : ℝ}
(εpos : 0 < ε) :
∃ N : ℕ, ∀ s : Finset ℕ, primesBelow N ≤ s →
‖(∑' m : ℕ, f m) - ∑' m : factoredNumbers s, f m‖ < ε := by
obtain ⟨N, hN⟩ :=
summable_iff_nat_tsum_vanishing.mp hsum (Metric.ball 0 ε) <| Metric.ball_mem_nhds 0 εpos
simp_rw [mem_ball_zero_iff] at hN
refine ⟨N, fun s hs ↦ ?_⟩
have := hN _ <| factoredNumbers_compl hs
rwa [← tsum_subtype_add_tsum_subtype_compl hsum (factoredNumbers s),
add_sub_cancel_left, tsum_eq_tsum_diff_singleton (factoredNumbers s)ᶜ hf₀]
-- Versions of the three lemmas above for `smoothNumbers N`
/-- We relate a finite product over primes to an infinite sum over smooth numbers. -/
lemma summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum
(hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (N : ℕ) :
Summable (fun m : N.smoothNumbers ↦ ‖f m‖) ∧
HasSum (fun m : N.smoothNumbers ↦ f m) (∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n)) := by
rw [smoothNumbers_eq_factoredNumbers, primesBelow]
exact summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul hsum _
/-- A version of `EulerProduct.summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum`
in terms of the value of the series. -/
lemma prod_primesBelow_tsum_eq_tsum_smoothNumbers (hsum : Summable (‖f ·‖)) (N : ℕ) :
∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n) = ∑' m : N.smoothNumbers, f m :=
(summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum hf₁ hmul
(fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm
/-- The following statement says that summing over `N`-smooth numbers
for large enough `N` gets us arbitrarily close to the sum over all natural numbers
(assuming `f` is norm-summable and `f 0 = 0`; the latter since `0` is not smooth). -/
lemma norm_tsum_smoothNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0)
{ε : ℝ} (εpos : 0 < ε) :
∃ N₀ : ℕ, ∀ N ≥ N₀, ‖(∑' m : ℕ, f m) - ∑' m : N.smoothNumbers, f m‖ < ε := by
conv => enter [1, N₀, N]; rw [smoothNumbers_eq_factoredNumbers]
obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum hf₀ εpos
refine ⟨N₀, fun N hN ↦ hN₀ (range N) fun p hp ↦ ?_⟩
exact mem_range.mpr <| (lt_of_mem_primesBelow hp).trans_le hN
/-- The *Euler Product* for multiplicative (on coprime arguments) functions.
If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is
multiplicative on coprime arguments, and `‖f ·‖` is summable, then
`∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated using `HasProd`. -/
theorem eulerProduct_hasProd (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) :
HasProd (fun p : Primes ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by
let F : ℕ → R := fun n ↦ ∑' e, f (n ^ e)
change HasProd (F ∘ Subtype.val) _
rw [hasProd_subtype_iff_mulIndicator,
show Set.mulIndicator (fun p : ℕ ↦ Irreducible p) = {p | Nat.Prime p}.mulIndicator from rfl,
HasProd, Metric.tendsto_atTop]
intro ε hε
obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum.of_norm hf₀ hε
refine ⟨range N₀, fun s hs ↦ ?_⟩
have : ∏ p ∈ s, {p | Nat.Prime p}.mulIndicator F p = ∏ p ∈ s.filter Nat.Prime, F p :=
prod_mulIndicator_eq_prod_filter s (fun _ ↦ F) _ id
rw [this, dist_eq_norm, prod_filter_prime_tsum_eq_tsum_factoredNumbers hf₁ hmul hsum,
norm_sub_rev]
exact hN₀ s fun p hp ↦ hs <| mem_range.mpr <| lt_of_mem_primesBelow hp
/-- The *Euler Product* for multiplicative (on coprime arguments) functions.
If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` i
multiplicative on coprime arguments, and `‖f ·‖` is summable, then
`∏' p : ℕ, if p.Prime then ∑' e, f (p ^ e) else 1 = ∑' n, f n`.
This version is stated using `HasProd` and `Set.mulIndicator`. -/
| Mathlib/NumberTheory/EulerProduct/Basic.lean | 182 | 185 | theorem eulerProduct_hasProd_mulIndicator (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) :
HasProd (Set.mulIndicator {p | Nat.Prime p} fun p ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by |
rw [← hasProd_subtype_iff_mulIndicator]
exact eulerProduct_hasProd hf₁ hmul hsum hf₀
|
/-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics
import Mathlib.NumberTheory.Liouville.Basic
import Mathlib.Topology.Instances.Irrational
#align_import number_theory.liouville.liouville_with from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8"
/-!
# Liouville numbers with a given exponent
We say that a real number `x` is a Liouville number with exponent `p : ℝ` if there exists a real
number `C` such that for infinitely many denominators `n` there exists a numerator `m` such that
`x ≠ m / n` and `|x - m / n| < C / n ^ p`. A number is a Liouville number in the sense of
`Liouville` if it is `LiouvilleWith` any real exponent, see `forall_liouvilleWith_iff`.
* If `p ≤ 1`, then this condition is trivial.
* If `1 < p ≤ 2`, then this condition is equivalent to `Irrational x`. The forward implication
does not require `p ≤ 2` and is formalized as `LiouvilleWith.irrational`; the other implication
follows from approximations by continued fractions and is not formalized yet.
* If `p > 2`, then this is a non-trivial condition on irrational numbers. In particular,
[Thue–Siegel–Roth theorem](https://en.wikipedia.org/wiki/Roth's_theorem) states that such numbers
must be transcendental.
In this file we define the predicate `LiouvilleWith` and prove some basic facts about this
predicate.
## Tags
Liouville number, irrational, irrationality exponent
-/
open Filter Metric Real Set
open scoped Filter Topology
/-- We say that a real number `x` is a Liouville number with exponent `p : ℝ` if there exists a real
number `C` such that for infinitely many denominators `n` there exists a numerator `m` such that
`x ≠ m / n` and `|x - m / n| < C / n ^ p`.
A number is a Liouville number in the sense of `Liouville` if it is `LiouvilleWith` any real
exponent. -/
def LiouvilleWith (p x : ℝ) : Prop :=
∃ C, ∃ᶠ n : ℕ in atTop, ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < C / n ^ p
#align liouville_with LiouvilleWith
/-- For `p = 1` (hence, for any `p ≤ 1`), the condition `LiouvilleWith p x` is trivial. -/
theorem liouvilleWith_one (x : ℝ) : LiouvilleWith 1 x := by
use 2
refine ((eventually_gt_atTop 0).mono fun n hn => ?_).frequently
have hn' : (0 : ℝ) < n := by simpa
have : x < ↑(⌊x * ↑n⌋ + 1) / ↑n := by
rw [lt_div_iff hn', Int.cast_add, Int.cast_one];
exact Int.lt_floor_add_one _
refine ⟨⌊x * n⌋ + 1, this.ne, ?_⟩
rw [abs_sub_comm, abs_of_pos (sub_pos.2 this), rpow_one, sub_lt_iff_lt_add',
add_div_eq_mul_add_div _ _ hn'.ne']
gcongr
calc _ ≤ x * n + 1 := by push_cast; gcongr; apply Int.floor_le
_ < x * n + 2 := by linarith
#align liouville_with_one liouvilleWith_one
namespace LiouvilleWith
variable {p q x y : ℝ} {r : ℚ} {m : ℤ} {n : ℕ}
/-- The constant `C` provided by the definition of `LiouvilleWith` can be made positive.
We also add `1 ≤ n` to the list of assumptions about the denominator. While it is equivalent to
the original statement, the case `n = 0` breaks many arguments. -/
theorem exists_pos (h : LiouvilleWith p x) :
∃ (C : ℝ) (_h₀ : 0 < C),
∃ᶠ n : ℕ in atTop, 1 ≤ n ∧ ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < C / n ^ p := by
rcases h with ⟨C, hC⟩
refine ⟨max C 1, zero_lt_one.trans_le <| le_max_right _ _, ?_⟩
refine ((eventually_ge_atTop 1).and_frequently hC).mono ?_
rintro n ⟨hle, m, hne, hlt⟩
refine ⟨hle, m, hne, hlt.trans_le ?_⟩
gcongr
apply le_max_left
#align liouville_with.exists_pos LiouvilleWith.exists_pos
/-- If a number is Liouville with exponent `p`, then it is Liouville with any smaller exponent. -/
theorem mono (h : LiouvilleWith p x) (hle : q ≤ p) : LiouvilleWith q x := by
rcases h.exists_pos with ⟨C, hC₀, hC⟩
refine ⟨C, hC.mono ?_⟩; rintro n ⟨hn, m, hne, hlt⟩
refine ⟨m, hne, hlt.trans_le <| ?_⟩
gcongr
exact_mod_cast hn
#align liouville_with.mono LiouvilleWith.mono
/-- If `x` satisfies Liouville condition with exponent `p` and `q < p`, then `x`
satisfies Liouville condition with exponent `q` and constant `1`. -/
theorem frequently_lt_rpow_neg (h : LiouvilleWith p x) (hlt : q < p) :
∃ᶠ n : ℕ in atTop, ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < n ^ (-q) := by
rcases h.exists_pos with ⟨C, _hC₀, hC⟩
have : ∀ᶠ n : ℕ in atTop, C < n ^ (p - q) := by
simpa only [(· ∘ ·), neg_sub, one_div] using
((tendsto_rpow_atTop (sub_pos.2 hlt)).comp tendsto_natCast_atTop_atTop).eventually
(eventually_gt_atTop C)
refine (this.and_frequently hC).mono ?_
rintro n ⟨hnC, hn, m, hne, hlt⟩
replace hn : (0 : ℝ) < n := Nat.cast_pos.2 hn
refine ⟨m, hne, hlt.trans <| (div_lt_iff <| rpow_pos_of_pos hn _).2 ?_⟩
rwa [mul_comm, ← rpow_add hn, ← sub_eq_add_neg]
#align liouville_with.frequently_lt_rpow_neg LiouvilleWith.frequently_lt_rpow_neg
/-- The product of a Liouville number and a nonzero rational number is again a Liouville number. -/
theorem mul_rat (h : LiouvilleWith p x) (hr : r ≠ 0) : LiouvilleWith p (x * r) := by
rcases h.exists_pos with ⟨C, _hC₀, hC⟩
refine ⟨r.den ^ p * (|r| * C), (tendsto_id.nsmul_atTop r.pos).frequently (hC.mono ?_)⟩
rintro n ⟨_hn, m, hne, hlt⟩
have A : (↑(r.num * m) : ℝ) / ↑(r.den • id n) = m / n * r := by
simp [← div_mul_div_comm, ← r.cast_def, mul_comm]
refine ⟨r.num * m, ?_, ?_⟩
· rw [A]; simp [hne, hr]
· rw [A, ← sub_mul, abs_mul]
simp only [smul_eq_mul, id, Nat.cast_mul]
calc _ < C / ↑n ^ p * |↑r| := by gcongr
_ = ↑r.den ^ p * (↑|r| * C) / (↑r.den * ↑n) ^ p := ?_
rw [mul_rpow, mul_div_mul_left, mul_comm, mul_div_assoc]
· simp only [Rat.cast_abs, le_refl]
all_goals positivity
#align liouville_with.mul_rat LiouvilleWith.mul_rat
/-- The product `x * r`, `r : ℚ`, `r ≠ 0`, is a Liouville number with exponent `p` if and only if
`x` satisfies the same condition. -/
theorem mul_rat_iff (hr : r ≠ 0) : LiouvilleWith p (x * r) ↔ LiouvilleWith p x :=
⟨fun h => by
simpa only [mul_assoc, ← Rat.cast_mul, mul_inv_cancel hr, Rat.cast_one, mul_one] using
h.mul_rat (inv_ne_zero hr),
fun h => h.mul_rat hr⟩
#align liouville_with.mul_rat_iff LiouvilleWith.mul_rat_iff
/-- The product `r * x`, `r : ℚ`, `r ≠ 0`, is a Liouville number with exponent `p` if and only if
`x` satisfies the same condition. -/
| Mathlib/NumberTheory/Liouville/LiouvilleWith.lean | 142 | 143 | theorem rat_mul_iff (hr : r ≠ 0) : LiouvilleWith p (r * x) ↔ LiouvilleWith p x := by |
rw [mul_comm, mul_rat_iff hr]
|
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.Constructions
#align_import topology.continuous_on from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494"
/-!
# Neighborhoods and continuity relative to a subset
This file defines relative versions
* `nhdsWithin` of `nhds`
* `ContinuousOn` of `Continuous`
* `ContinuousWithinAt` of `ContinuousAt`
and proves their basic properties, including the relationships between
these restricted notions and the corresponding notions for the subtype
equipped with the subspace topology.
## Notation
* `𝓝 x`: the filter of neighborhoods of a point `x`;
* `𝓟 s`: the principal filter of a set `s`;
* `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`.
-/
open Set Filter Function Topology Filter
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variable [TopologicalSpace α]
@[simp]
theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a :=
bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl
#align nhds_bind_nhds_within nhds_bind_nhdsWithin
@[simp]
theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x :=
Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x }
#align eventually_nhds_nhds_within eventually_nhds_nhdsWithin
theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x :=
eventually_inf_principal
#align eventually_nhds_within_iff eventually_nhdsWithin_iff
theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s :=
frequently_inf_principal.trans <| by simp only [and_comm]
#align frequently_nhds_within_iff frequently_nhdsWithin_iff
theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} :
z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by
simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff]
#align mem_closure_ne_iff_frequently_within mem_closure_ne_iff_frequently_within
@[simp]
theorem eventually_nhdsWithin_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by
refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩
simp only [eventually_nhdsWithin_iff] at h ⊢
exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs
#align eventually_nhds_within_nhds_within eventually_nhdsWithin_nhdsWithin
theorem nhdsWithin_eq (a : α) (s : Set α) :
𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) :=
((nhds_basis_opens a).inf_principal s).eq_biInf
#align nhds_within_eq nhdsWithin_eq
theorem nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by
rw [nhdsWithin, principal_univ, inf_top_eq]
#align nhds_within_univ nhdsWithin_univ
theorem nhdsWithin_hasBasis {p : β → Prop} {s : β → Set α} {a : α} (h : (𝓝 a).HasBasis p s)
(t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t :=
h.inf_principal t
#align nhds_within_has_basis nhdsWithin_hasBasis
theorem nhdsWithin_basis_open (a : α) (t : Set α) :
(𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t :=
nhdsWithin_hasBasis (nhds_basis_opens a) t
#align nhds_within_basis_open nhdsWithin_basis_open
theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by
simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff
#align mem_nhds_within mem_nhdsWithin
theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t :=
(nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff
#align mem_nhds_within_iff_exists_mem_nhds_inter mem_nhdsWithin_iff_exists_mem_nhds_inter
theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) :
s \ t ∈ 𝓝[tᶜ] x :=
diff_mem_inf_principal_compl hs t
#align diff_mem_nhds_within_compl diff_mem_nhdsWithin_compl
theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) :
s \ t' ∈ 𝓝[t \ t'] x := by
rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc]
exact inter_mem_inf hs (mem_principal_self _)
#align diff_mem_nhds_within_diff diff_mem_nhdsWithin_diff
theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) :
t ∈ 𝓝 a := by
rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩
exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw
#align nhds_of_nhds_within_of_nhds nhds_of_nhdsWithin_of_nhds
theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} :
t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t :=
eventually_inf_principal
#align mem_nhds_within_iff_eventually mem_nhdsWithin_iff_eventually
theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} :
t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by
simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and]
#align mem_nhds_within_iff_eventually_eq mem_nhdsWithin_iff_eventuallyEq
theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t :=
set_eventuallyEq_iff_inf_principal.symm
#align nhds_within_eq_iff_eventually_eq nhdsWithin_eq_iff_eventuallyEq
theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x :=
set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal
#align nhds_within_le_iff nhdsWithin_le_iff
-- Porting note: golfed, dropped an unneeded assumption
theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t)
(hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) :
π ⁻¹' s ∈ 𝓝[t] a := by
lift a to t using h
replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs
rwa [← map_nhds_subtype_val, mem_map]
#align preimage_nhds_within_coinduced' preimage_nhdsWithin_coinduced'ₓ
theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a :=
mem_inf_of_left h
#align mem_nhds_within_of_mem_nhds mem_nhdsWithin_of_mem_nhds
theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a :=
mem_inf_of_right (mem_principal_self s)
#align self_mem_nhds_within self_mem_nhdsWithin
theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s :=
self_mem_nhdsWithin
#align eventually_mem_nhds_within eventually_mem_nhdsWithin
theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a :=
inter_mem self_mem_nhdsWithin (mem_inf_of_left h)
#align inter_mem_nhds_within inter_mem_nhdsWithin
theorem nhdsWithin_mono (a : α) {s t : Set α} (h : s ⊆ t) : 𝓝[s] a ≤ 𝓝[t] a :=
inf_le_inf_left _ (principal_mono.mpr h)
#align nhds_within_mono nhdsWithin_mono
theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a :=
le_inf (pure_le_nhds a) (le_principal_iff.2 ha)
#align pure_le_nhds_within pure_le_nhdsWithin
theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t :=
pure_le_nhdsWithin ha ht
#align mem_of_mem_nhds_within mem_of_mem_nhdsWithin
theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α}
(h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x :=
mem_of_mem_nhdsWithin hx h
#align filter.eventually.self_of_nhds_within Filter.Eventually.self_of_nhdsWithin
theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) :
Tendsto (fun _ : β => a) l (𝓝[s] a) :=
tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha
#align tendsto_const_nhds_within tendsto_const_nhdsWithin
theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) :
𝓝[s] a = 𝓝[s ∩ t] a :=
le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h)))
(inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left))
#align nhds_within_restrict'' nhdsWithin_restrict''
theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a :=
nhdsWithin_restrict'' s <| mem_inf_of_left h
#align nhds_within_restrict' nhdsWithin_restrict'
theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) :
𝓝[s] a = 𝓝[s ∩ t] a :=
nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀)
#align nhds_within_restrict nhdsWithin_restrict
theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a :=
nhdsWithin_le_iff.mpr h
#align nhds_within_le_of_mem nhdsWithin_le_of_mem
theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by
rw [← nhdsWithin_univ]
apply nhdsWithin_le_of_mem
exact univ_mem
#align nhds_within_le_nhds nhdsWithin_le_nhds
theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) :
𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂]
#align nhds_within_eq_nhds_within' nhdsWithin_eq_nhdsWithin'
theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s)
(h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by
rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂]
#align nhds_within_eq_nhds_within nhdsWithin_eq_nhdsWithin
@[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a :=
inf_eq_left.trans le_principal_iff
#align nhds_within_eq_nhds nhdsWithin_eq_nhds
theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a :=
nhdsWithin_eq_nhds.2 <| h.mem_nhds ha
#align is_open.nhds_within_eq IsOpen.nhdsWithin_eq
theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t)
(ht : IsOpen t)
(hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) :
π ⁻¹' s ∈ 𝓝 a := by
rw [← ht.nhdsWithin_eq h]
exact preimage_nhdsWithin_coinduced' h hs
#align preimage_nhds_within_coinduced preimage_nhds_within_coinduced
@[simp]
theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq]
#align nhds_within_empty nhdsWithin_empty
theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by
delta nhdsWithin
rw [← inf_sup_left, sup_principal]
#align nhds_within_union nhdsWithin_union
theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) :
𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a :=
Set.Finite.induction_on hI (by simp) fun _ _ hT ↦ by
simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert]
#align nhds_within_bUnion nhdsWithin_biUnion
theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) :
𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by
rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS]
#align nhds_within_sUnion nhdsWithin_sUnion
theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) :
𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by
rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range]
#align nhds_within_Union nhdsWithin_iUnion
theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by
delta nhdsWithin
rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem]
#align nhds_within_inter nhdsWithin_inter
theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by
delta nhdsWithin
rw [← inf_principal, inf_assoc]
#align nhds_within_inter' nhdsWithin_inter'
theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by
rw [nhdsWithin_inter, inf_eq_right]
exact nhdsWithin_le_of_mem h
#align nhds_within_inter_of_mem nhdsWithin_inter_of_mem
theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by
rw [inter_comm, nhdsWithin_inter_of_mem h]
#align nhds_within_inter_of_mem' nhdsWithin_inter_of_mem'
@[simp]
theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by
rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)]
#align nhds_within_singleton nhdsWithin_singleton
@[simp]
theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by
rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton]
#align nhds_within_insert nhdsWithin_insert
theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by
simp
#align mem_nhds_within_insert mem_nhdsWithin_insert
theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) :
insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h]
#align insert_mem_nhds_within_insert insert_mem_nhdsWithin_insert
theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by
simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left,
insert_def]
#align insert_mem_nhds_iff insert_mem_nhds_iff
@[simp]
theorem nhdsWithin_compl_singleton_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by
rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ]
#align nhds_within_compl_singleton_sup_pure nhdsWithin_compl_singleton_sup_pure
theorem nhdsWithin_prod {α : Type*} [TopologicalSpace α] {β : Type*} [TopologicalSpace β]
{s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) :
u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by
rw [nhdsWithin_prod_eq]
exact prod_mem_prod hu hv
#align nhds_within_prod nhdsWithin_prod
theorem nhdsWithin_pi_eq' {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
(hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) :
𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by
simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ←
iInf_principal_finite hI, ← iInf_inf_eq]
#align nhds_within_pi_eq' nhdsWithin_pi_eq'
theorem nhdsWithin_pi_eq {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
(hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) :
𝓝[pi I s] x =
(⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓
⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by
simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf,
comap_principal, eval]
rw [iInf_split _ fun i => i ∈ I, inf_right_comm]
simp only [iInf_inf_eq]
#align nhds_within_pi_eq nhdsWithin_pi_eq
theorem nhdsWithin_pi_univ_eq {ι : Type*} {α : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (α i)]
(s : ∀ i, Set (α i)) (x : ∀ i, α i) :
𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by
simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x
#align nhds_within_pi_univ_eq nhdsWithin_pi_univ_eq
theorem nhdsWithin_pi_eq_bot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
{s : ∀ i, Set (α i)} {x : ∀ i, α i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by
simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot]
#align nhds_within_pi_eq_bot nhdsWithin_pi_eq_bot
theorem nhdsWithin_pi_neBot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
{s : ∀ i, Set (α i)} {x : ∀ i, α i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by
simp [neBot_iff, nhdsWithin_pi_eq_bot]
#align nhds_within_pi_ne_bot nhdsWithin_pi_neBot
theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)]
{a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l)
(h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by
apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter']
#align filter.tendsto.piecewise_nhds_within Filter.Tendsto.piecewise_nhdsWithin
theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α}
{s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l)
(h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) :
Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l :=
h₀.piecewise_nhdsWithin h₁
#align filter.tendsto.if_nhds_within Filter.Tendsto.if_nhdsWithin
theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) :
map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) :=
((nhdsWithin_basis_open a s).map f).eq_biInf
#align map_nhds_within map_nhdsWithin
theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t)
(h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l :=
h.mono_left <| nhdsWithin_mono a hst
#align tendsto_nhds_within_mono_left tendsto_nhdsWithin_mono_left
theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t)
(h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) :=
h.mono_right (nhdsWithin_mono a hst)
#align tendsto_nhds_within_mono_right tendsto_nhdsWithin_mono_right
theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β}
(h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l :=
h.mono_left inf_le_left
#align tendsto_nhds_within_of_tendsto_nhds tendsto_nhdsWithin_of_tendsto_nhds
theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β}
(h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by
simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff,
eventually_and] at h
exact (h univ ⟨mem_univ a, isOpen_univ⟩).2
#align eventually_mem_of_tendsto_nhds_within eventually_mem_of_tendsto_nhdsWithin
theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β}
(h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) :=
h.mono_right nhdsWithin_le_nhds
#align tendsto_nhds_of_tendsto_nhds_within tendsto_nhds_of_tendsto_nhdsWithin
theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) :=
mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx
#align nhds_within_ne_bot_of_mem nhdsWithin_neBot_of_mem
theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α}
(hx : NeBot <| 𝓝[s] x) : x ∈ s :=
hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx
#align is_closed.mem_of_nhds_within_ne_bot IsClosed.mem_of_nhdsWithin_neBot
theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) :
NeBot (𝓝[range f] x) :=
mem_closure_iff_clusterPt.1 (h x)
#align dense_range.nhds_within_ne_bot DenseRange.nhdsWithin_neBot
theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
{s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by
simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot]
#align mem_closure_pi mem_closure_pi
theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι)
(s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) :=
Set.ext fun _ => mem_closure_pi
#align closure_pi_set closure_pi_set
theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)}
(I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by
simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq,
pi_univ]
#align dense_pi dense_pi
theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} :
f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x :=
mem_inf_principal
#align eventually_eq_nhds_within_iff eventuallyEq_nhdsWithin_iff
theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) :
f =ᶠ[𝓝[s] a] g :=
mem_inf_of_right h
#align eventually_eq_nhds_within_of_eq_on eventuallyEq_nhdsWithin_of_eqOn
theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) :
f =ᶠ[𝓝[s] a] g :=
eventuallyEq_nhdsWithin_of_eqOn h
#align set.eq_on.eventually_eq_nhds_within Set.EqOn.eventuallyEq_nhdsWithin
theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β}
(hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l :=
(tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf
#align tendsto_nhds_within_congr tendsto_nhdsWithin_congr
theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) :
∀ᶠ x in 𝓝[s] a, p x :=
mem_inf_of_right h
#align eventually_nhds_within_of_forall eventually_nhdsWithin_of_forall
theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α}
(f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) :=
tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩
#align tendsto_nhds_within_of_tendsto_nhds_of_eventually_within tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} :
Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s :=
⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h =>
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩
#align tendsto_nhds_within_iff tendsto_nhdsWithin_iff
@[simp]
theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} :
Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) :=
⟨fun h => h.mono_right inf_le_left, fun h =>
tendsto_inf.2 ⟨h, tendsto_principal.2 <| eventually_of_forall mem_range_self⟩⟩
#align tendsto_nhds_within_range tendsto_nhdsWithin_range
theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g)
(hmem : a ∈ s) : f a = g a :=
h.self_of_nhdsWithin hmem
#align filter.eventually_eq.eq_of_nhds_within Filter.EventuallyEq.eq_of_nhdsWithin
theorem eventually_nhdsWithin_of_eventually_nhds {α : Type*} [TopologicalSpace α] {s : Set α}
{a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x :=
mem_nhdsWithin_of_mem_nhds h
#align eventually_nhds_within_of_eventually_nhds eventually_nhdsWithin_of_eventually_nhds
/-!
### `nhdsWithin` and subtypes
-/
theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} :
t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by
rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin]
#align mem_nhds_within_subtype mem_nhdsWithin_subtype
theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) :
𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) :=
Filter.ext fun _ => mem_nhdsWithin_subtype
#align nhds_within_subtype nhdsWithin_subtype
theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) :
𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) :=
(map_nhds_subtype_val ⟨a, h⟩).symm
#align nhds_within_eq_map_subtype_coe nhdsWithin_eq_map_subtype_coe
theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} :
t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by
rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective]
#align mem_nhds_subtype_iff_nhds_within mem_nhds_subtype_iff_nhdsWithin
theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by
rw [← map_nhds_subtype_val, mem_map]
#align preimage_coe_mem_nhds_subtype preimage_coe_mem_nhds_subtype
theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) :
(∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x :=
preimage_coe_mem_nhds_subtype
theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) :
(∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x :=
eventually_nhds_subtype_iff s a (¬ P ·) |>.not
theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) :
Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by
rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl
#align tendsto_nhds_within_iff_subtype tendsto_nhdsWithin_iff_subtype
variable [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ]
/-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition.
We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as
`ContinuousWithinAt.comp` will have a different meaning. -/
theorem ContinuousWithinAt.tendsto {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) :
Tendsto f (𝓝[s] x) (𝓝 (f x)) :=
h
#align continuous_within_at.tendsto ContinuousWithinAt.tendsto
theorem ContinuousOn.continuousWithinAt {f : α → β} {s : Set α} {x : α} (hf : ContinuousOn f s)
(hx : x ∈ s) : ContinuousWithinAt f s x :=
hf x hx
#align continuous_on.continuous_within_at ContinuousOn.continuousWithinAt
theorem continuousWithinAt_univ (f : α → β) (x : α) :
ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by
rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ]
#align continuous_within_at_univ continuousWithinAt_univ
theorem continuous_iff_continuousOn_univ {f : α → β} : Continuous f ↔ ContinuousOn f univ := by
simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt,
nhdsWithin_univ]
#align continuous_iff_continuous_on_univ continuous_iff_continuousOn_univ
theorem continuousWithinAt_iff_continuousAt_restrict (f : α → β) {x : α} {s : Set α} (h : x ∈ s) :
ContinuousWithinAt f s x ↔ ContinuousAt (s.restrict f) ⟨x, h⟩ :=
tendsto_nhdsWithin_iff_subtype h f _
#align continuous_within_at_iff_continuous_at_restrict continuousWithinAt_iff_continuousAt_restrict
theorem ContinuousWithinAt.tendsto_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β}
(h : ContinuousWithinAt f s x) (ht : MapsTo f s t) : Tendsto f (𝓝[s] x) (𝓝[t] f x) :=
tendsto_inf.2 ⟨h, tendsto_principal.2 <| mem_inf_of_right <| mem_principal.2 <| ht⟩
#align continuous_within_at.tendsto_nhds_within ContinuousWithinAt.tendsto_nhdsWithin
theorem ContinuousWithinAt.tendsto_nhdsWithin_image {f : α → β} {x : α} {s : Set α}
(h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝[f '' s] f x) :=
h.tendsto_nhdsWithin (mapsTo_image _ _)
#align continuous_within_at.tendsto_nhds_within_image ContinuousWithinAt.tendsto_nhdsWithin_image
theorem ContinuousWithinAt.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} {x : α} {y : β}
(hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g t y) :
ContinuousWithinAt (Prod.map f g) (s ×ˢ t) (x, y) := by
unfold ContinuousWithinAt at *
rw [nhdsWithin_prod_eq, Prod.map, nhds_prod_eq]
exact hf.prod_map hg
#align continuous_within_at.prod_map ContinuousWithinAt.prod_map
theorem continuousWithinAt_prod_of_discrete_left [DiscreteTopology α]
{f : α × β → γ} {s : Set (α × β)} {x : α × β} :
ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨x.1, ·⟩) {b | (x.1, b) ∈ s} x.2 := by
rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, pure_prod,
← map_inf_principal_preimage]; rfl
theorem continuousWithinAt_prod_of_discrete_right [DiscreteTopology β]
{f : α × β → γ} {s : Set (α × β)} {x : α × β} :
ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨·, x.2⟩) {a | (a, x.2) ∈ s} x.1 := by
rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, prod_pure,
← map_inf_principal_preimage]; rfl
theorem continuousAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {x : α × β} :
ContinuousAt f x ↔ ContinuousAt (f ⟨x.1, ·⟩) x.2 := by
simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_left
theorem continuousAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {x : α × β} :
ContinuousAt f x ↔ ContinuousAt (f ⟨·, x.2⟩) x.1 := by
simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_right
theorem continuousOn_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} :
ContinuousOn f s ↔ ∀ a, ContinuousOn (f ⟨a, ·⟩) {b | (a, b) ∈ s} := by
simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_left]; rfl
theorem continuousOn_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} :
ContinuousOn f s ↔ ∀ b, ContinuousOn (f ⟨·, b⟩) {a | (a, b) ∈ s} := by
simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_right]; apply forall_swap
/-- If a function `f a b` is such that `y ↦ f a b` is continuous for all `a`, and `a` lives in a
discrete space, then `f` is continuous, and vice versa. -/
theorem continuous_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} :
Continuous f ↔ ∀ a, Continuous (f ⟨a, ·⟩) := by
simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_left
theorem continuous_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} :
Continuous f ↔ ∀ b, Continuous (f ⟨·, b⟩) := by
simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_right
theorem isOpenMap_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} :
IsOpenMap f ↔ ∀ a, IsOpenMap (f ⟨a, ·⟩) := by
simp_rw [isOpenMap_iff_nhds_le, Prod.forall, nhds_prod_eq, nhds_discrete, pure_prod, map_map]
rfl
theorem isOpenMap_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} :
IsOpenMap f ↔ ∀ b, IsOpenMap (f ⟨·, b⟩) := by
simp_rw [isOpenMap_iff_nhds_le, Prod.forall, forall_swap (α := α) (β := β), nhds_prod_eq,
nhds_discrete, prod_pure, map_map]; rfl
theorem continuousWithinAt_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)]
{f : α → ∀ i, π i} {s : Set α} {x : α} :
ContinuousWithinAt f s x ↔ ∀ i, ContinuousWithinAt (fun y => f y i) s x :=
tendsto_pi_nhds
#align continuous_within_at_pi continuousWithinAt_pi
theorem continuousOn_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)]
{f : α → ∀ i, π i} {s : Set α} : ContinuousOn f s ↔ ∀ i, ContinuousOn (fun y => f y i) s :=
⟨fun h i x hx => tendsto_pi_nhds.1 (h x hx) i, fun h x hx => tendsto_pi_nhds.2 fun i => h i x hx⟩
#align continuous_on_pi continuousOn_pi
@[fun_prop]
theorem continuousOn_pi' {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)]
{f : α → ∀ i, π i} {s : Set α} (hf : ∀ i, ContinuousOn (fun y => f y i) s) :
ContinuousOn f s :=
continuousOn_pi.2 hf
theorem ContinuousWithinAt.fin_insertNth {n} {π : Fin (n + 1) → Type*}
[∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {a : α} {s : Set α}
(hf : ContinuousWithinAt f s a) {g : α → ∀ j : Fin n, π (i.succAbove j)}
(hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => i.insertNth (f a) (g a)) s a :=
hf.tendsto.fin_insertNth i hg
#align continuous_within_at.fin_insert_nth ContinuousWithinAt.fin_insertNth
nonrec theorem ContinuousOn.fin_insertNth {n} {π : Fin (n + 1) → Type*}
[∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {s : Set α}
(hf : ContinuousOn f s) {g : α → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousOn g s) :
ContinuousOn (fun a => i.insertNth (f a) (g a)) s := fun a ha =>
(hf a ha).fin_insertNth i (hg a ha)
#align continuous_on.fin_insert_nth ContinuousOn.fin_insertNth
theorem continuousOn_iff {f : α → β} {s : Set α} :
ContinuousOn f s ↔
∀ x ∈ s, ∀ t : Set β, IsOpen t → f x ∈ t → ∃ u, IsOpen u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by
simp only [ContinuousOn, ContinuousWithinAt, tendsto_nhds, mem_nhdsWithin]
#align continuous_on_iff continuousOn_iff
theorem continuousOn_iff_continuous_restrict {f : α → β} {s : Set α} :
ContinuousOn f s ↔ Continuous (s.restrict f) := by
rw [ContinuousOn, continuous_iff_continuousAt]; constructor
· rintro h ⟨x, xs⟩
exact (continuousWithinAt_iff_continuousAt_restrict f xs).mp (h x xs)
intro h x xs
exact (continuousWithinAt_iff_continuousAt_restrict f xs).mpr (h ⟨x, xs⟩)
#align continuous_on_iff_continuous_restrict continuousOn_iff_continuous_restrict
-- Porting note: 2 new lemmas
alias ⟨ContinuousOn.restrict, _⟩ := continuousOn_iff_continuous_restrict
theorem ContinuousOn.restrict_mapsTo {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s)
(ht : MapsTo f s t) : Continuous (ht.restrict f s t) :=
hf.restrict.codRestrict _
theorem continuousOn_iff' {f : α → β} {s : Set α} :
ContinuousOn f s ↔ ∀ t : Set β, IsOpen t → ∃ u, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by
have : ∀ t, IsOpen (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by
intro t
rw [isOpen_induced_iff, Set.restrict_eq, Set.preimage_comp]
simp only [Subtype.preimage_coe_eq_preimage_coe_iff]
constructor <;>
· rintro ⟨u, ou, useq⟩
exact ⟨u, ou, by simpa only [Set.inter_comm, eq_comm] using useq⟩
rw [continuousOn_iff_continuous_restrict, continuous_def]; simp only [this]
#align continuous_on_iff' continuousOn_iff'
/-- If a function is continuous on a set for some topologies, then it is
continuous on the same set with respect to any finer topology on the source space. -/
theorem ContinuousOn.mono_dom {α β : Type*} {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β}
(h₁ : t₂ ≤ t₁) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₃ f s) :
@ContinuousOn α β t₂ t₃ f s := fun x hx _u hu =>
map_mono (inf_le_inf_right _ <| nhds_mono h₁) (h₂ x hx hu)
#align continuous_on.mono_dom ContinuousOn.mono_dom
/-- If a function is continuous on a set for some topologies, then it is
continuous on the same set with respect to any coarser topology on the target space. -/
theorem ContinuousOn.mono_rng {α β : Type*} {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β}
(h₁ : t₂ ≤ t₃) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₂ f s) :
@ContinuousOn α β t₁ t₃ f s := fun x hx _u hu =>
h₂ x hx <| nhds_mono h₁ hu
#align continuous_on.mono_rng ContinuousOn.mono_rng
theorem continuousOn_iff_isClosed {f : α → β} {s : Set α} :
ContinuousOn f s ↔ ∀ t : Set β, IsClosed t → ∃ u, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by
have : ∀ t, IsClosed (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by
intro t
rw [isClosed_induced_iff, Set.restrict_eq, Set.preimage_comp]
simp only [Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm, Set.inter_comm s]
rw [continuousOn_iff_continuous_restrict, continuous_iff_isClosed]; simp only [this]
#align continuous_on_iff_is_closed continuousOn_iff_isClosed
theorem ContinuousOn.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β}
(hf : ContinuousOn f s) (hg : ContinuousOn g t) : ContinuousOn (Prod.map f g) (s ×ˢ t) :=
fun ⟨x, y⟩ ⟨hx, hy⟩ => ContinuousWithinAt.prod_map (hf x hx) (hg y hy)
#align continuous_on.prod_map ContinuousOn.prod_map
theorem continuous_of_cover_nhds {ι : Sort*} {f : α → β} {s : ι → Set α}
(hs : ∀ x : α, ∃ i, s i ∈ 𝓝 x) (hf : ∀ i, ContinuousOn f (s i)) :
Continuous f :=
continuous_iff_continuousAt.mpr fun x ↦ let ⟨i, hi⟩ := hs x; by
rw [ContinuousAt, ← nhdsWithin_eq_nhds.2 hi]
exact hf _ _ (mem_of_mem_nhds hi)
#align continuous_of_cover_nhds continuous_of_cover_nhds
theorem continuousOn_empty (f : α → β) : ContinuousOn f ∅ := fun _ => False.elim
#align continuous_on_empty continuousOn_empty
@[simp]
theorem continuousOn_singleton (f : α → β) (a : α) : ContinuousOn f {a} :=
forall_eq.2 <| by
simpa only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_left] using fun s =>
mem_of_mem_nhds
#align continuous_on_singleton continuousOn_singleton
theorem Set.Subsingleton.continuousOn {s : Set α} (hs : s.Subsingleton) (f : α → β) :
ContinuousOn f s :=
hs.induction_on (continuousOn_empty f) (continuousOn_singleton f)
#align set.subsingleton.continuous_on Set.Subsingleton.continuousOn
theorem nhdsWithin_le_comap {x : α} {s : Set α} {f : α → β} (ctsf : ContinuousWithinAt f s x) :
𝓝[s] x ≤ comap f (𝓝[f '' s] f x) :=
ctsf.tendsto_nhdsWithin_image.le_comap
#align nhds_within_le_comap nhdsWithin_le_comap
@[simp]
theorem comap_nhdsWithin_range {α} (f : α → β) (y : β) : comap f (𝓝[range f] y) = comap f (𝓝 y) :=
comap_inf_principal_range
#align comap_nhds_within_range comap_nhdsWithin_range
theorem ContinuousWithinAt.mono {f : α → β} {s t : Set α} {x : α} (h : ContinuousWithinAt f t x)
(hs : s ⊆ t) : ContinuousWithinAt f s x :=
h.mono_left (nhdsWithin_mono x hs)
#align continuous_within_at.mono ContinuousWithinAt.mono
theorem ContinuousWithinAt.mono_of_mem {f : α → β} {s t : Set α} {x : α}
(h : ContinuousWithinAt f t x) (hs : t ∈ 𝓝[s] x) : ContinuousWithinAt f s x :=
h.mono_left (nhdsWithin_le_of_mem hs)
#align continuous_within_at.mono_of_mem ContinuousWithinAt.mono_of_mem
theorem continuousWithinAt_congr_nhds {f : α → β} {s t : Set α} {x : α} (h : 𝓝[s] x = 𝓝[t] x) :
ContinuousWithinAt f s x ↔ ContinuousWithinAt f t x := by
simp only [ContinuousWithinAt, h]
theorem continuousWithinAt_inter' {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝[s] x) :
ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by
simp [ContinuousWithinAt, nhdsWithin_restrict'' s h]
#align continuous_within_at_inter' continuousWithinAt_inter'
theorem continuousWithinAt_inter {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝 x) :
ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by
simp [ContinuousWithinAt, nhdsWithin_restrict' s h]
#align continuous_within_at_inter continuousWithinAt_inter
theorem continuousWithinAt_union {f : α → β} {s t : Set α} {x : α} :
ContinuousWithinAt f (s ∪ t) x ↔ ContinuousWithinAt f s x ∧ ContinuousWithinAt f t x := by
simp only [ContinuousWithinAt, nhdsWithin_union, tendsto_sup]
#align continuous_within_at_union continuousWithinAt_union
theorem ContinuousWithinAt.union {f : α → β} {s t : Set α} {x : α} (hs : ContinuousWithinAt f s x)
(ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s ∪ t) x :=
continuousWithinAt_union.2 ⟨hs, ht⟩
#align continuous_within_at.union ContinuousWithinAt.union
theorem ContinuousWithinAt.mem_closure_image {f : α → β} {s : Set α} {x : α}
(h : ContinuousWithinAt f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) :=
haveI := mem_closure_iff_nhdsWithin_neBot.1 hx
mem_closure_of_tendsto h <| mem_of_superset self_mem_nhdsWithin (subset_preimage_image f s)
#align continuous_within_at.mem_closure_image ContinuousWithinAt.mem_closure_image
theorem ContinuousWithinAt.mem_closure {f : α → β} {s : Set α} {x : α} {A : Set β}
(h : ContinuousWithinAt f s x) (hx : x ∈ closure s) (hA : MapsTo f s A) : f x ∈ closure A :=
closure_mono (image_subset_iff.2 hA) (h.mem_closure_image hx)
#align continuous_within_at.mem_closure ContinuousWithinAt.mem_closure
theorem Set.MapsTo.closure_of_continuousWithinAt {f : α → β} {s : Set α} {t : Set β}
(h : MapsTo f s t) (hc : ∀ x ∈ closure s, ContinuousWithinAt f s x) :
MapsTo f (closure s) (closure t) := fun x hx => (hc x hx).mem_closure hx h
#align set.maps_to.closure_of_continuous_within_at Set.MapsTo.closure_of_continuousWithinAt
theorem Set.MapsTo.closure_of_continuousOn {f : α → β} {s : Set α} {t : Set β} (h : MapsTo f s t)
(hc : ContinuousOn f (closure s)) : MapsTo f (closure s) (closure t) :=
h.closure_of_continuousWithinAt fun x hx => (hc x hx).mono subset_closure
#align set.maps_to.closure_of_continuous_on Set.MapsTo.closure_of_continuousOn
theorem ContinuousWithinAt.image_closure {f : α → β} {s : Set α}
(hf : ∀ x ∈ closure s, ContinuousWithinAt f s x) : f '' closure s ⊆ closure (f '' s) :=
((mapsTo_image f s).closure_of_continuousWithinAt hf).image_subset
#align continuous_within_at.image_closure ContinuousWithinAt.image_closure
theorem ContinuousOn.image_closure {f : α → β} {s : Set α} (hf : ContinuousOn f (closure s)) :
f '' closure s ⊆ closure (f '' s) :=
ContinuousWithinAt.image_closure fun x hx => (hf x hx).mono subset_closure
#align continuous_on.image_closure ContinuousOn.image_closure
@[simp]
theorem continuousWithinAt_singleton {f : α → β} {x : α} : ContinuousWithinAt f {x} x := by
simp only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_nhds]
#align continuous_within_at_singleton continuousWithinAt_singleton
@[simp]
theorem continuousWithinAt_insert_self {f : α → β} {x : α} {s : Set α} :
ContinuousWithinAt f (insert x s) x ↔ ContinuousWithinAt f s x := by
simp only [← singleton_union, continuousWithinAt_union, continuousWithinAt_singleton,
true_and_iff]
#align continuous_within_at_insert_self continuousWithinAt_insert_self
alias ⟨_, ContinuousWithinAt.insert_self⟩ := continuousWithinAt_insert_self
#align continuous_within_at.insert_self ContinuousWithinAt.insert_self
theorem ContinuousWithinAt.diff_iff {f : α → β} {s t : Set α} {x : α}
(ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s \ t) x ↔ ContinuousWithinAt f s x :=
⟨fun h => (h.union ht).mono <| by simp only [diff_union_self, subset_union_left], fun h =>
h.mono diff_subset⟩
#align continuous_within_at.diff_iff ContinuousWithinAt.diff_iff
@[simp]
theorem continuousWithinAt_diff_self {f : α → β} {s : Set α} {x : α} :
ContinuousWithinAt f (s \ {x}) x ↔ ContinuousWithinAt f s x :=
continuousWithinAt_singleton.diff_iff
#align continuous_within_at_diff_self continuousWithinAt_diff_self
@[simp]
theorem continuousWithinAt_compl_self {f : α → β} {a : α} :
ContinuousWithinAt f {a}ᶜ a ↔ ContinuousAt f a := by
rw [compl_eq_univ_diff, continuousWithinAt_diff_self, continuousWithinAt_univ]
#align continuous_within_at_compl_self continuousWithinAt_compl_self
@[simp]
theorem continuousWithinAt_update_same [DecidableEq α] {f : α → β} {s : Set α} {x : α} {y : β} :
ContinuousWithinAt (update f x y) s x ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) :=
calc
ContinuousWithinAt (update f x y) s x ↔ Tendsto (update f x y) (𝓝[s \ {x}] x) (𝓝 y) := by
{ rw [← continuousWithinAt_diff_self, ContinuousWithinAt, update_same] }
_ ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) :=
tendsto_congr' <| eventually_nhdsWithin_iff.2 <| eventually_of_forall
fun z hz => update_noteq hz.2 _ _
#align continuous_within_at_update_same continuousWithinAt_update_same
@[simp]
theorem continuousAt_update_same [DecidableEq α] {f : α → β} {x : α} {y : β} :
ContinuousAt (Function.update f x y) x ↔ Tendsto f (𝓝[≠] x) (𝓝 y) := by
rw [← continuousWithinAt_univ, continuousWithinAt_update_same, compl_eq_univ_diff]
#align continuous_at_update_same continuousAt_update_same
theorem IsOpenMap.continuousOn_image_of_leftInvOn {f : α → β} {s : Set α}
(h : IsOpenMap (s.restrict f)) {finv : β → α} (hleft : LeftInvOn finv f s) :
ContinuousOn finv (f '' s) := by
refine continuousOn_iff'.2 fun t ht => ⟨f '' (t ∩ s), ?_, ?_⟩
· rw [← image_restrict]
exact h _ (ht.preimage continuous_subtype_val)
· rw [inter_eq_self_of_subset_left (image_subset f inter_subset_right), hleft.image_inter']
#align is_open_map.continuous_on_image_of_left_inv_on IsOpenMap.continuousOn_image_of_leftInvOn
theorem IsOpenMap.continuousOn_range_of_leftInverse {f : α → β} (hf : IsOpenMap f) {finv : β → α}
(hleft : Function.LeftInverse finv f) : ContinuousOn finv (range f) := by
rw [← image_univ]
exact (hf.restrict isOpen_univ).continuousOn_image_of_leftInvOn fun x _ => hleft x
#align is_open_map.continuous_on_range_of_left_inverse IsOpenMap.continuousOn_range_of_leftInverse
theorem ContinuousOn.congr_mono {f g : α → β} {s s₁ : Set α} (h : ContinuousOn f s)
(h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) : ContinuousOn g s₁ := by
intro x hx
unfold ContinuousWithinAt
have A := (h x (h₁ hx)).mono h₁
unfold ContinuousWithinAt at A
rw [← h' hx] at A
exact A.congr' h'.eventuallyEq_nhdsWithin.symm
#align continuous_on.congr_mono ContinuousOn.congr_mono
theorem ContinuousOn.congr {f g : α → β} {s : Set α} (h : ContinuousOn f s) (h' : EqOn g f s) :
ContinuousOn g s :=
h.congr_mono h' (Subset.refl _)
#align continuous_on.congr ContinuousOn.congr
theorem continuousOn_congr {f g : α → β} {s : Set α} (h' : EqOn g f s) :
ContinuousOn g s ↔ ContinuousOn f s :=
⟨fun h => ContinuousOn.congr h h'.symm, fun h => h.congr h'⟩
#align continuous_on_congr continuousOn_congr
theorem ContinuousAt.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : ContinuousAt f x) :
ContinuousWithinAt f s x :=
ContinuousWithinAt.mono ((continuousWithinAt_univ f x).2 h) (subset_univ _)
#align continuous_at.continuous_within_at ContinuousAt.continuousWithinAt
theorem continuousWithinAt_iff_continuousAt {f : α → β} {s : Set α} {x : α} (h : s ∈ 𝓝 x) :
ContinuousWithinAt f s x ↔ ContinuousAt f x := by
rw [← univ_inter s, continuousWithinAt_inter h, continuousWithinAt_univ]
#align continuous_within_at_iff_continuous_at continuousWithinAt_iff_continuousAt
theorem ContinuousWithinAt.continuousAt {f : α → β} {s : Set α} {x : α}
(h : ContinuousWithinAt f s x) (hs : s ∈ 𝓝 x) : ContinuousAt f x :=
(continuousWithinAt_iff_continuousAt hs).mp h
#align continuous_within_at.continuous_at ContinuousWithinAt.continuousAt
theorem IsOpen.continuousOn_iff {f : α → β} {s : Set α} (hs : IsOpen s) :
ContinuousOn f s ↔ ∀ ⦃a⦄, a ∈ s → ContinuousAt f a :=
forall₂_congr fun _ => continuousWithinAt_iff_continuousAt ∘ hs.mem_nhds
#align is_open.continuous_on_iff IsOpen.continuousOn_iff
theorem ContinuousOn.continuousAt {f : α → β} {s : Set α} {x : α} (h : ContinuousOn f s)
(hx : s ∈ 𝓝 x) : ContinuousAt f x :=
(h x (mem_of_mem_nhds hx)).continuousAt hx
#align continuous_on.continuous_at ContinuousOn.continuousAt
theorem ContinuousAt.continuousOn {f : α → β} {s : Set α} (hcont : ∀ x ∈ s, ContinuousAt f x) :
ContinuousOn f s := fun x hx => (hcont x hx).continuousWithinAt
#align continuous_at.continuous_on ContinuousAt.continuousOn
theorem ContinuousWithinAt.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α}
(hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) :
ContinuousWithinAt (g ∘ f) s x :=
hg.tendsto.comp (hf.tendsto_nhdsWithin h)
#align continuous_within_at.comp ContinuousWithinAt.comp
theorem ContinuousWithinAt.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α}
(hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) :
ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x :=
hg.comp (hf.mono inter_subset_left) inter_subset_right
#align continuous_within_at.comp' ContinuousWithinAt.comp'
theorem ContinuousAt.comp_continuousWithinAt {g : β → γ} {f : α → β} {s : Set α} {x : α}
(hg : ContinuousAt g (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) s x :=
hg.continuousWithinAt.comp hf (mapsTo_univ _ _)
#align continuous_at.comp_continuous_within_at ContinuousAt.comp_continuousWithinAt
theorem ContinuousOn.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t)
(hf : ContinuousOn f s) (h : MapsTo f s t) : ContinuousOn (g ∘ f) s := fun x hx =>
ContinuousWithinAt.comp (hg _ (h hx)) (hf x hx) h
#align continuous_on.comp ContinuousOn.comp
@[fun_prop]
theorem ContinuousOn.comp'' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t)
(hf : ContinuousOn f s) (h : Set.MapsTo f s t) : ContinuousOn (fun x => g (f x)) s :=
ContinuousOn.comp hg hf h
theorem ContinuousOn.mono {f : α → β} {s t : Set α} (hf : ContinuousOn f s) (h : t ⊆ s) :
ContinuousOn f t := fun x hx => (hf x (h hx)).mono_left (nhdsWithin_mono _ h)
#align continuous_on.mono ContinuousOn.mono
theorem antitone_continuousOn {f : α → β} : Antitone (ContinuousOn f) := fun _s _t hst hf =>
hf.mono hst
#align antitone_continuous_on antitone_continuousOn
@[fun_prop]
theorem ContinuousOn.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t)
(hf : ContinuousOn f s) : ContinuousOn (g ∘ f) (s ∩ f ⁻¹' t) :=
hg.comp (hf.mono inter_subset_left) inter_subset_right
#align continuous_on.comp' ContinuousOn.comp'
@[fun_prop]
theorem Continuous.continuousOn {f : α → β} {s : Set α} (h : Continuous f) : ContinuousOn f s := by
rw [continuous_iff_continuousOn_univ] at h
exact h.mono (subset_univ _)
#align continuous.continuous_on Continuous.continuousOn
theorem Continuous.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : Continuous f) :
ContinuousWithinAt f s x :=
h.continuousAt.continuousWithinAt
#align continuous.continuous_within_at Continuous.continuousWithinAt
theorem Continuous.comp_continuousOn {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g)
(hf : ContinuousOn f s) : ContinuousOn (g ∘ f) s :=
hg.continuousOn.comp hf (mapsTo_univ _ _)
#align continuous.comp_continuous_on Continuous.comp_continuousOn
@[fun_prop]
theorem Continuous.comp_continuousOn'
{α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ}
{f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) :
ContinuousOn (fun x ↦ g (f x)) s :=
hg.comp_continuousOn hf
theorem ContinuousOn.comp_continuous {g : β → γ} {f : α → β} {s : Set β} (hg : ContinuousOn g s)
(hf : Continuous f) (hs : ∀ x, f x ∈ s) : Continuous (g ∘ f) := by
rw [continuous_iff_continuousOn_univ] at *
exact hg.comp hf fun x _ => hs x
#align continuous_on.comp_continuous ContinuousOn.comp_continuous
@[fun_prop]
theorem continuousOn_apply {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)]
(i : ι) (s) : ContinuousOn (fun p : ∀ i, π i => p i) s :=
Continuous.continuousOn (continuous_apply i)
theorem ContinuousWithinAt.preimage_mem_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β}
(h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝[s] x :=
h ht
#align continuous_within_at.preimage_mem_nhds_within ContinuousWithinAt.preimage_mem_nhdsWithin
theorem Set.LeftInvOn.map_nhdsWithin_eq {f : α → β} {g : β → α} {x : β} {s : Set β}
(h : LeftInvOn f g s) (hx : f (g x) = x) (hf : ContinuousWithinAt f (g '' s) (g x))
(hg : ContinuousWithinAt g s x) : map g (𝓝[s] x) = 𝓝[g '' s] g x := by
apply le_antisymm
· exact hg.tendsto_nhdsWithin (mapsTo_image _ _)
· have A : g ∘ f =ᶠ[𝓝[g '' s] g x] id :=
h.rightInvOn_image.eqOn.eventuallyEq_of_mem self_mem_nhdsWithin
refine le_map_of_right_inverse A ?_
simpa only [hx] using hf.tendsto_nhdsWithin (h.mapsTo (surjOn_image _ _))
#align set.left_inv_on.map_nhds_within_eq Set.LeftInvOn.map_nhdsWithin_eq
theorem Function.LeftInverse.map_nhds_eq {f : α → β} {g : β → α} {x : β}
(h : Function.LeftInverse f g) (hf : ContinuousWithinAt f (range g) (g x))
(hg : ContinuousAt g x) : map g (𝓝 x) = 𝓝[range g] g x := by
simpa only [nhdsWithin_univ, image_univ] using
(h.leftInvOn univ).map_nhdsWithin_eq (h x) (by rwa [image_univ]) hg.continuousWithinAt
#align function.left_inverse.map_nhds_eq Function.LeftInverse.map_nhds_eq
theorem ContinuousWithinAt.preimage_mem_nhdsWithin' {f : α → β} {x : α} {s : Set α} {t : Set β}
(h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝[f '' s] f x) : f ⁻¹' t ∈ 𝓝[s] x :=
h.tendsto_nhdsWithin (mapsTo_image _ _) ht
#align continuous_within_at.preimage_mem_nhds_within' ContinuousWithinAt.preimage_mem_nhdsWithin'
theorem ContinuousWithinAt.preimage_mem_nhdsWithin''
{f : α → β} {x : α} {y : β} {s t : Set β}
(h : ContinuousWithinAt f (f ⁻¹' s) x) (ht : t ∈ 𝓝[s] y) (hxy : y = f x) :
f ⁻¹' t ∈ 𝓝[f ⁻¹' s] x := by
rw [hxy] at ht
exact h.preimage_mem_nhdsWithin' (nhdsWithin_mono _ (image_preimage_subset f s) ht)
theorem Filter.EventuallyEq.congr_continuousWithinAt {f g : α → β} {s : Set α} {x : α}
(h : f =ᶠ[𝓝[s] x] g) (hx : f x = g x) :
ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := by
rw [ContinuousWithinAt, hx, tendsto_congr' h, ContinuousWithinAt]
#align filter.eventually_eq.congr_continuous_within_at Filter.EventuallyEq.congr_continuousWithinAt
theorem ContinuousWithinAt.congr_of_eventuallyEq {f f₁ : α → β} {s : Set α} {x : α}
(h : ContinuousWithinAt f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
ContinuousWithinAt f₁ s x :=
(h₁.congr_continuousWithinAt hx).2 h
#align continuous_within_at.congr_of_eventually_eq ContinuousWithinAt.congr_of_eventuallyEq
theorem ContinuousWithinAt.congr {f f₁ : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x)
(h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContinuousWithinAt f₁ s x :=
h.congr_of_eventuallyEq (mem_of_superset self_mem_nhdsWithin h₁) hx
#align continuous_within_at.congr ContinuousWithinAt.congr
theorem ContinuousWithinAt.congr_mono {f g : α → β} {s s₁ : Set α} {x : α}
(h : ContinuousWithinAt f s x) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) (hx : g x = f x) :
ContinuousWithinAt g s₁ x :=
(h.mono h₁).congr h' hx
#align continuous_within_at.congr_mono ContinuousWithinAt.congr_mono
@[fun_prop]
theorem continuousOn_const {s : Set α} {c : β} : ContinuousOn (fun _ => c) s :=
continuous_const.continuousOn
#align continuous_on_const continuousOn_const
theorem continuousWithinAt_const {b : β} {s : Set α} {x : α} :
ContinuousWithinAt (fun _ : α => b) s x :=
continuous_const.continuousWithinAt
#align continuous_within_at_const continuousWithinAt_const
theorem continuousOn_id {s : Set α} : ContinuousOn id s :=
continuous_id.continuousOn
#align continuous_on_id continuousOn_id
@[fun_prop]
theorem continuousOn_id' (s : Set α) : ContinuousOn (fun x : α => x) s := continuousOn_id
theorem continuousWithinAt_id {s : Set α} {x : α} : ContinuousWithinAt id s x :=
continuous_id.continuousWithinAt
#align continuous_within_at_id continuousWithinAt_id
| Mathlib/Topology/ContinuousOn.lean | 1,070 | 1,080 | theorem continuousOn_open_iff {f : α → β} {s : Set α} (hs : IsOpen s) :
ContinuousOn f s ↔ ∀ t, IsOpen t → IsOpen (s ∩ f ⁻¹' t) := by |
rw [continuousOn_iff']
constructor
· intro h t ht
rcases h t ht with ⟨u, u_open, hu⟩
rw [inter_comm, hu]
apply IsOpen.inter u_open hs
· intro h t ht
refine ⟨s ∩ f ⁻¹' t, h t ht, ?_⟩
rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self]
|
/-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne
-/
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.Hom.CompleteLattice
#align_import order.liminf_limsup from "leanprover-community/mathlib"@"ffde2d8a6e689149e44fd95fa862c23a57f8c780"
/-!
# liminfs and limsups of functions and filters
Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete
lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`.
Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ.
Then there is no guarantee that the quantity above really decreases (the value of the `sup`
beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything.
So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has
to use a less tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
set_option autoImplicit true
open Filter Set Function
variable {α β γ ι ι' : Type*}
namespace Filter
section Relation
/-- `f.IsBounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e.
eventually, it is bounded by some uniform bound.
`r` will be usually instantiated with `≤` or `≥`. -/
def IsBounded (r : α → α → Prop) (f : Filter α) :=
∃ b, ∀ᶠ x in f, r x b
#align filter.is_bounded Filter.IsBounded
/-- `f.IsBoundedUnder (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t.
the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/
def IsBoundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) :=
(map u f).IsBounded r
#align filter.is_bounded_under Filter.IsBoundedUnder
variable {r : α → α → Prop} {f g : Filter α}
/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is
bounded. -/
theorem isBounded_iff : f.IsBounded r ↔ ∃ s ∈ f.sets, ∃ b, s ⊆ { x | r x b } :=
Iff.intro (fun ⟨b, hb⟩ => ⟨{ a | r a b }, hb, b, Subset.refl _⟩) fun ⟨_, hs, b, hb⟩ =>
⟨b, mem_of_superset hs hb⟩
#align filter.is_bounded_iff Filter.isBounded_iff
/-- A bounded function `u` is in particular eventually bounded. -/
theorem isBoundedUnder_of {f : Filter β} {u : β → α} : (∃ b, ∀ x, r (u x) b) → f.IsBoundedUnder r u
| ⟨b, hb⟩ => ⟨b, show ∀ᶠ x in f, r (u x) b from eventually_of_forall hb⟩
#align filter.is_bounded_under_of Filter.isBoundedUnder_of
theorem isBounded_bot : IsBounded r ⊥ ↔ Nonempty α := by simp [IsBounded, exists_true_iff_nonempty]
#align filter.is_bounded_bot Filter.isBounded_bot
theorem isBounded_top : IsBounded r ⊤ ↔ ∃ t, ∀ x, r x t := by simp [IsBounded, eq_univ_iff_forall]
#align filter.is_bounded_top Filter.isBounded_top
theorem isBounded_principal (s : Set α) : IsBounded r (𝓟 s) ↔ ∃ t, ∀ x ∈ s, r x t := by
simp [IsBounded, subset_def]
#align filter.is_bounded_principal Filter.isBounded_principal
theorem isBounded_sup [IsTrans α r] [IsDirected α r] :
IsBounded r f → IsBounded r g → IsBounded r (f ⊔ g)
| ⟨b₁, h₁⟩, ⟨b₂, h₂⟩ =>
let ⟨b, rb₁b, rb₂b⟩ := directed_of r b₁ b₂
⟨b, eventually_sup.mpr
⟨h₁.mono fun _ h => _root_.trans h rb₁b, h₂.mono fun _ h => _root_.trans h rb₂b⟩⟩
#align filter.is_bounded_sup Filter.isBounded_sup
theorem IsBounded.mono (h : f ≤ g) : IsBounded r g → IsBounded r f
| ⟨b, hb⟩ => ⟨b, h hb⟩
#align filter.is_bounded.mono Filter.IsBounded.mono
theorem IsBoundedUnder.mono {f g : Filter β} {u : β → α} (h : f ≤ g) :
g.IsBoundedUnder r u → f.IsBoundedUnder r u := fun hg => IsBounded.mono (map_mono h) hg
#align filter.is_bounded_under.mono Filter.IsBoundedUnder.mono
theorem IsBoundedUnder.mono_le [Preorder β] {l : Filter α} {u v : α → β}
(hu : IsBoundedUnder (· ≤ ·) l u) (hv : v ≤ᶠ[l] u) : IsBoundedUnder (· ≤ ·) l v := by
apply hu.imp
exact fun b hb => (eventually_map.1 hb).mp <| hv.mono fun x => le_trans
#align filter.is_bounded_under.mono_le Filter.IsBoundedUnder.mono_le
theorem IsBoundedUnder.mono_ge [Preorder β] {l : Filter α} {u v : α → β}
(hu : IsBoundedUnder (· ≥ ·) l u) (hv : u ≤ᶠ[l] v) : IsBoundedUnder (· ≥ ·) l v :=
IsBoundedUnder.mono_le (β := βᵒᵈ) hu hv
#align filter.is_bounded_under.mono_ge Filter.IsBoundedUnder.mono_ge
theorem isBoundedUnder_const [IsRefl α r] {l : Filter β} {a : α} : IsBoundedUnder r l fun _ => a :=
⟨a, eventually_map.2 <| eventually_of_forall fun _ => refl _⟩
#align filter.is_bounded_under_const Filter.isBoundedUnder_const
theorem IsBounded.isBoundedUnder {q : β → β → Prop} {u : α → β}
(hu : ∀ a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.IsBounded r → f.IsBoundedUnder q u
| ⟨b, h⟩ => ⟨u b, show ∀ᶠ x in f, q (u x) (u b) from h.mono fun x => hu x b⟩
#align filter.is_bounded.is_bounded_under Filter.IsBounded.isBoundedUnder
theorem IsBoundedUnder.comp {l : Filter γ} {q : β → β → Prop} {u : γ → α} {v : α → β}
(hv : ∀ a₀ a₁, r a₀ a₁ → q (v a₀) (v a₁)) : l.IsBoundedUnder r u → l.IsBoundedUnder q (v ∘ u)
| ⟨a, h⟩ => ⟨v a, show ∀ᶠ x in map u l, q (v x) (v a) from h.mono fun x => hv x a⟩
/-- A bounded above function `u` is in particular eventually bounded above. -/
lemma _root_.BddAbove.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} :
BddAbove (Set.range u) → f.IsBoundedUnder (· ≤ ·) u
| ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_upperBounds] using hb⟩
/-- A bounded below function `u` is in particular eventually bounded below. -/
lemma _root_.BddBelow.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} :
BddBelow (Set.range u) → f.IsBoundedUnder (· ≥ ·) u
| ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_lowerBounds] using hb⟩
theorem _root_.Monotone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≤ ·) u) :
l.IsBoundedUnder (· ≤ ·) (v ∘ u) :=
hl.comp hv
theorem _root_.Monotone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≥ ·) u) :
l.IsBoundedUnder (· ≥ ·) (v ∘ u) :=
hl.comp (swap hv)
theorem _root_.Antitone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≥ ·) u) :
l.IsBoundedUnder (· ≤ ·) (v ∘ u) :=
hl.comp (swap hv)
theorem _root_.Antitone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≤ ·) u) :
l.IsBoundedUnder (· ≥ ·) (v ∘ u) :=
hl.comp hv
theorem not_isBoundedUnder_of_tendsto_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α}
[l.NeBot] (hf : Tendsto f l atTop) : ¬IsBoundedUnder (· ≤ ·) l f := by
rintro ⟨b, hb⟩
rw [eventually_map] at hb
obtain ⟨b', h⟩ := exists_gt b
have hb' := (tendsto_atTop.mp hf) b'
have : { x : α | f x ≤ b } ∩ { x : α | b' ≤ f x } = ∅ :=
eq_empty_of_subset_empty fun x hx => (not_le_of_lt h) (le_trans hx.2 hx.1)
exact (nonempty_of_mem (hb.and hb')).ne_empty this
#align filter.not_is_bounded_under_of_tendsto_at_top Filter.not_isBoundedUnder_of_tendsto_atTop
theorem not_isBoundedUnder_of_tendsto_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α}
[l.NeBot] (hf : Tendsto f l atBot) : ¬IsBoundedUnder (· ≥ ·) l f :=
not_isBoundedUnder_of_tendsto_atTop (β := βᵒᵈ) hf
#align filter.not_is_bounded_under_of_tendsto_at_bot Filter.not_isBoundedUnder_of_tendsto_atBot
theorem IsBoundedUnder.bddAbove_range_of_cofinite [Preorder β] [IsDirected β (· ≤ ·)] {f : α → β}
(hf : IsBoundedUnder (· ≤ ·) cofinite f) : BddAbove (range f) := by
rcases hf with ⟨b, hb⟩
haveI : Nonempty β := ⟨b⟩
rw [← image_univ, ← union_compl_self { x | f x ≤ b }, image_union, bddAbove_union]
exact ⟨⟨b, forall_mem_image.2 fun x => id⟩, (hb.image f).bddAbove⟩
#align filter.is_bounded_under.bdd_above_range_of_cofinite Filter.IsBoundedUnder.bddAbove_range_of_cofinite
theorem IsBoundedUnder.bddBelow_range_of_cofinite [Preorder β] [IsDirected β (· ≥ ·)] {f : α → β}
(hf : IsBoundedUnder (· ≥ ·) cofinite f) : BddBelow (range f) :=
IsBoundedUnder.bddAbove_range_of_cofinite (β := βᵒᵈ) hf
#align filter.is_bounded_under.bdd_below_range_of_cofinite Filter.IsBoundedUnder.bddBelow_range_of_cofinite
theorem IsBoundedUnder.bddAbove_range [Preorder β] [IsDirected β (· ≤ ·)] {f : ℕ → β}
(hf : IsBoundedUnder (· ≤ ·) atTop f) : BddAbove (range f) := by
rw [← Nat.cofinite_eq_atTop] at hf
exact hf.bddAbove_range_of_cofinite
#align filter.is_bounded_under.bdd_above_range Filter.IsBoundedUnder.bddAbove_range
theorem IsBoundedUnder.bddBelow_range [Preorder β] [IsDirected β (· ≥ ·)] {f : ℕ → β}
(hf : IsBoundedUnder (· ≥ ·) atTop f) : BddBelow (range f) :=
IsBoundedUnder.bddAbove_range (β := βᵒᵈ) hf
#align filter.is_bounded_under.bdd_below_range Filter.IsBoundedUnder.bddBelow_range
/-- `IsCobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is
also called frequently bounded. Will be usually instantiated with `≤` or `≥`.
There is a subtlety in this definition: we want `f.IsCobounded` to hold for any `f` in the case of
complete lattices. This will be relevant to deduce theorems on complete lattices from their
versions on conditionally complete lattices with additional assumptions. We have to be careful in
the edge case of the trivial filter containing the empty set: the other natural definition
`¬ ∀ a, ∀ᶠ n in f, a ≤ n`
would not work as well in this case.
-/
def IsCobounded (r : α → α → Prop) (f : Filter α) :=
∃ b, ∀ a, (∀ᶠ x in f, r x a) → r b a
#align filter.is_cobounded Filter.IsCobounded
/-- `IsCoboundedUnder (≺) f u` states that the image of the filter `f` under the map `u` does not
tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated
with `≤` or `≥`. -/
def IsCoboundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) :=
(map u f).IsCobounded r
#align filter.is_cobounded_under Filter.IsCoboundedUnder
/-- To check that a filter is frequently bounded, it suffices to have a witness
which bounds `f` at some point for every admissible set.
This is only an implication, as the other direction is wrong for the trivial filter. -/
theorem IsCobounded.mk [IsTrans α r] (a : α) (h : ∀ s ∈ f, ∃ x ∈ s, r a x) : f.IsCobounded r :=
⟨a, fun _ s =>
let ⟨_, h₁, h₂⟩ := h _ s
_root_.trans h₂ h₁⟩
#align filter.is_cobounded.mk Filter.IsCobounded.mk
/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite
direction). At least if the filter is not trivial. -/
theorem IsBounded.isCobounded_flip [IsTrans α r] [NeBot f] : f.IsBounded r → f.IsCobounded (flip r)
| ⟨a, ha⟩ =>
⟨a, fun b hb =>
let ⟨_, rxa, rbx⟩ := (ha.and hb).exists
show r b a from _root_.trans rbx rxa⟩
#align filter.is_bounded.is_cobounded_flip Filter.IsBounded.isCobounded_flip
theorem IsBounded.isCobounded_ge [Preorder α] [NeBot f] (h : f.IsBounded (· ≤ ·)) :
f.IsCobounded (· ≥ ·) :=
h.isCobounded_flip
#align filter.is_bounded.is_cobounded_ge Filter.IsBounded.isCobounded_ge
theorem IsBounded.isCobounded_le [Preorder α] [NeBot f] (h : f.IsBounded (· ≥ ·)) :
f.IsCobounded (· ≤ ·) :=
h.isCobounded_flip
#align filter.is_bounded.is_cobounded_le Filter.IsBounded.isCobounded_le
theorem IsBoundedUnder.isCoboundedUnder_flip {l : Filter γ} [IsTrans α r] [NeBot l]
(h : l.IsBoundedUnder r u) : l.IsCoboundedUnder (flip r) u :=
h.isCobounded_flip
theorem IsBoundedUnder.isCoboundedUnder_le {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l]
(h : l.IsBoundedUnder (· ≥ ·) u) : l.IsCoboundedUnder (· ≤ ·) u :=
h.isCoboundedUnder_flip
theorem IsBoundedUnder.isCoboundedUnder_ge {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l]
(h : l.IsBoundedUnder (· ≤ ·) u) : l.IsCoboundedUnder (· ≥ ·) u :=
h.isCoboundedUnder_flip
lemma isCoboundedUnder_le_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ᶠ i in l, x ≤ f i) :
IsCoboundedUnder (· ≤ ·) l f :=
IsBoundedUnder.isCoboundedUnder_le ⟨x, hf⟩
lemma isCoboundedUnder_ge_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ᶠ i in l, f i ≤ x) :
IsCoboundedUnder (· ≥ ·) l f :=
IsBoundedUnder.isCoboundedUnder_ge ⟨x, hf⟩
lemma isCoboundedUnder_le_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ i, x ≤ f i) :
IsCoboundedUnder (· ≤ ·) l f :=
isCoboundedUnder_le_of_eventually_le l (eventually_of_forall hf)
lemma isCoboundedUnder_ge_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ i, f i ≤ x) :
IsCoboundedUnder (· ≥ ·) l f :=
isCoboundedUnder_ge_of_eventually_le l (eventually_of_forall hf)
theorem isCobounded_bot : IsCobounded r ⊥ ↔ ∃ b, ∀ x, r b x := by simp [IsCobounded]
#align filter.is_cobounded_bot Filter.isCobounded_bot
theorem isCobounded_top : IsCobounded r ⊤ ↔ Nonempty α := by
simp (config := { contextual := true }) [IsCobounded, eq_univ_iff_forall,
exists_true_iff_nonempty]
#align filter.is_cobounded_top Filter.isCobounded_top
theorem isCobounded_principal (s : Set α) :
(𝓟 s).IsCobounded r ↔ ∃ b, ∀ a, (∀ x ∈ s, r x a) → r b a := by simp [IsCobounded, subset_def]
#align filter.is_cobounded_principal Filter.isCobounded_principal
theorem IsCobounded.mono (h : f ≤ g) : f.IsCobounded r → g.IsCobounded r
| ⟨b, hb⟩ => ⟨b, fun a ha => hb a (h ha)⟩
#align filter.is_cobounded.mono Filter.IsCobounded.mono
end Relation
section Nonempty
variable [Preorder α] [Nonempty α] {f : Filter β} {u : β → α}
theorem isBounded_le_atBot : (atBot : Filter α).IsBounded (· ≤ ·) :=
‹Nonempty α›.elim fun a => ⟨a, eventually_le_atBot _⟩
#align filter.is_bounded_le_at_bot Filter.isBounded_le_atBot
theorem isBounded_ge_atTop : (atTop : Filter α).IsBounded (· ≥ ·) :=
‹Nonempty α›.elim fun a => ⟨a, eventually_ge_atTop _⟩
#align filter.is_bounded_ge_at_top Filter.isBounded_ge_atTop
theorem Tendsto.isBoundedUnder_le_atBot (h : Tendsto u f atBot) : f.IsBoundedUnder (· ≤ ·) u :=
isBounded_le_atBot.mono h
#align filter.tendsto.is_bounded_under_le_at_bot Filter.Tendsto.isBoundedUnder_le_atBot
theorem Tendsto.isBoundedUnder_ge_atTop (h : Tendsto u f atTop) : f.IsBoundedUnder (· ≥ ·) u :=
isBounded_ge_atTop.mono h
#align filter.tendsto.is_bounded_under_ge_at_top Filter.Tendsto.isBoundedUnder_ge_atTop
theorem bddAbove_range_of_tendsto_atTop_atBot [IsDirected α (· ≤ ·)] {u : ℕ → α}
(hx : Tendsto u atTop atBot) : BddAbove (Set.range u) :=
hx.isBoundedUnder_le_atBot.bddAbove_range
#align filter.bdd_above_range_of_tendsto_at_top_at_bot Filter.bddAbove_range_of_tendsto_atTop_atBot
theorem bddBelow_range_of_tendsto_atTop_atTop [IsDirected α (· ≥ ·)] {u : ℕ → α}
(hx : Tendsto u atTop atTop) : BddBelow (Set.range u) :=
hx.isBoundedUnder_ge_atTop.bddBelow_range
#align filter.bdd_below_range_of_tendsto_at_top_at_top Filter.bddBelow_range_of_tendsto_atTop_atTop
end Nonempty
theorem isCobounded_le_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsCobounded (· ≤ ·) :=
⟨⊥, fun _ _ => bot_le⟩
#align filter.is_cobounded_le_of_bot Filter.isCobounded_le_of_bot
theorem isCobounded_ge_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsCobounded (· ≥ ·) :=
⟨⊤, fun _ _ => le_top⟩
#align filter.is_cobounded_ge_of_top Filter.isCobounded_ge_of_top
theorem isBounded_le_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsBounded (· ≤ ·) :=
⟨⊤, eventually_of_forall fun _ => le_top⟩
#align filter.is_bounded_le_of_top Filter.isBounded_le_of_top
theorem isBounded_ge_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsBounded (· ≥ ·) :=
⟨⊥, eventually_of_forall fun _ => bot_le⟩
#align filter.is_bounded_ge_of_bot Filter.isBounded_ge_of_bot
@[simp]
theorem _root_.OrderIso.isBoundedUnder_le_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ}
{u : γ → α} : (IsBoundedUnder (· ≤ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≤ ·) l u :=
(Function.Surjective.exists e.surjective).trans <|
exists_congr fun a => by simp only [eventually_map, e.le_iff_le]
#align order_iso.is_bounded_under_le_comp OrderIso.isBoundedUnder_le_comp
@[simp]
theorem _root_.OrderIso.isBoundedUnder_ge_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ}
{u : γ → α} : (IsBoundedUnder (· ≥ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≥ ·) l u :=
OrderIso.isBoundedUnder_le_comp e.dual
#align order_iso.is_bounded_under_ge_comp OrderIso.isBoundedUnder_ge_comp
@[to_additive (attr := simp)]
theorem isBoundedUnder_le_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} :
(IsBoundedUnder (· ≤ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≥ ·) l u :=
(OrderIso.inv α).isBoundedUnder_ge_comp
#align filter.is_bounded_under_le_inv Filter.isBoundedUnder_le_inv
#align filter.is_bounded_under_le_neg Filter.isBoundedUnder_le_neg
@[to_additive (attr := simp)]
theorem isBoundedUnder_ge_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} :
(IsBoundedUnder (· ≥ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≤ ·) l u :=
(OrderIso.inv α).isBoundedUnder_le_comp
#align filter.is_bounded_under_ge_inv Filter.isBoundedUnder_ge_inv
#align filter.is_bounded_under_ge_neg Filter.isBoundedUnder_ge_neg
theorem IsBoundedUnder.sup [SemilatticeSup α] {f : Filter β} {u v : β → α} :
f.IsBoundedUnder (· ≤ ·) u →
f.IsBoundedUnder (· ≤ ·) v → f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a
| ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩, ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ =>
⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv
by filter_upwards [hu, hv] with _ using sup_le_sup⟩
#align filter.is_bounded_under.sup Filter.IsBoundedUnder.sup
@[simp]
theorem isBoundedUnder_le_sup [SemilatticeSup α] {f : Filter β} {u v : β → α} :
(f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a) ↔
f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≤ ·) v :=
⟨fun h =>
⟨h.mono_le <| eventually_of_forall fun _ => le_sup_left,
h.mono_le <| eventually_of_forall fun _ => le_sup_right⟩,
fun h => h.1.sup h.2⟩
#align filter.is_bounded_under_le_sup Filter.isBoundedUnder_le_sup
theorem IsBoundedUnder.inf [SemilatticeInf α] {f : Filter β} {u v : β → α} :
f.IsBoundedUnder (· ≥ ·) u →
f.IsBoundedUnder (· ≥ ·) v → f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a :=
IsBoundedUnder.sup (α := αᵒᵈ)
#align filter.is_bounded_under.inf Filter.IsBoundedUnder.inf
@[simp]
theorem isBoundedUnder_ge_inf [SemilatticeInf α] {f : Filter β} {u v : β → α} :
(f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a) ↔
f.IsBoundedUnder (· ≥ ·) u ∧ f.IsBoundedUnder (· ≥ ·) v :=
isBoundedUnder_le_sup (α := αᵒᵈ)
#align filter.is_bounded_under_ge_inf Filter.isBoundedUnder_ge_inf
theorem isBoundedUnder_le_abs [LinearOrderedAddCommGroup α] {f : Filter β} {u : β → α} :
(f.IsBoundedUnder (· ≤ ·) fun a => |u a|) ↔
f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≥ ·) u :=
isBoundedUnder_le_sup.trans <| and_congr Iff.rfl isBoundedUnder_le_neg
#align filter.is_bounded_under_le_abs Filter.isBoundedUnder_le_abs
/-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `isBoundedDefault` in the statements,
in the form `(hf : f.IsBounded (≥) := by isBoundedDefault)`. -/
macro "isBoundedDefault" : tactic =>
`(tactic| first
| apply isCobounded_le_of_bot
| apply isCobounded_ge_of_top
| apply isBounded_le_of_top
| apply isBounded_ge_of_bot)
-- Porting note: The above is a lean 4 reconstruction of (note that applyc is not available (yet?)):
-- unsafe def is_bounded_default : tactic Unit :=
-- tactic.applyc `` is_cobounded_le_of_bot <|>
-- tactic.applyc `` is_cobounded_ge_of_top <|>
-- tactic.applyc `` is_bounded_le_of_top <|> tactic.applyc `` is_bounded_ge_of_bot
-- #align filter.is_bounded_default filter.IsBounded_default
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α]
-- Porting note: Renamed from Limsup and Liminf to limsSup and limsInf
/-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def limsSup (f : Filter α) : α :=
sInf { a | ∀ᶠ n in f, n ≤ a }
set_option linter.uppercaseLean3 false in
#align filter.Limsup Filter.limsSup
set_option linter.uppercaseLean3 false in
/-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def limsInf (f : Filter α) : α :=
sSup { a | ∀ᶠ n in f, a ≤ n }
set_option linter.uppercaseLean3 false in
#align filter.Liminf Filter.limsInf
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (u : β → α) (f : Filter β) : α :=
limsSup (map u f)
#align filter.limsup Filter.limsup
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (u : β → α) (f : Filter β) : α :=
limsInf (map u f)
#align filter.liminf Filter.liminf
/-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum
of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/
def blimsup (u : β → α) (f : Filter β) (p : β → Prop) :=
sInf { a | ∀ᶠ x in f, p x → u x ≤ a }
#align filter.blimsup Filter.blimsup
/-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum
of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/
def bliminf (u : β → α) (f : Filter β) (p : β → Prop) :=
sSup { a | ∀ᶠ x in f, p x → a ≤ u x }
#align filter.bliminf Filter.bliminf
section
variable {f : Filter β} {u : β → α} {p : β → Prop}
theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } :=
rfl
#align filter.limsup_eq Filter.limsup_eq
theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } :=
rfl
#align filter.liminf_eq Filter.liminf_eq
theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } :=
rfl
#align filter.blimsup_eq Filter.blimsup_eq
theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } :=
rfl
#align filter.bliminf_eq Filter.bliminf_eq
lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) :
liminf (u ∘ v) f = liminf u (map v f) := rfl
lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) :
limsup (u ∘ v) f = limsup u (map v f) := rfl
end
@[simp]
theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by
simp [blimsup_eq, limsup_eq]
#align filter.blimsup_true Filter.blimsup_true
@[simp]
theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by
simp [bliminf_eq, liminf_eq]
#align filter.bliminf_true Filter.bliminf_true
lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by
simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq]
lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) :=
blimsup_eq_limsup (α := αᵒᵈ)
theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by
rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val]
#align filter.blimsup_eq_limsup_subtype Filter.blimsup_eq_limsup_subtype
theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) :=
blimsup_eq_limsup_subtype (α := αᵒᵈ)
#align filter.bliminf_eq_liminf_subtype Filter.bliminf_eq_liminf_subtype
theorem limsSup_le_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a :=
csInf_le hf h
set_option linter.uppercaseLean3 false in
#align filter.Limsup_le_of_le Filter.limsSup_le_of_le
theorem le_limsInf_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f :=
le_csSup hf h
set_option linter.uppercaseLean3 false in
#align filter.le_Liminf_of_le Filter.le_limsInf_of_le
theorem limsup_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a :=
csInf_le hf h
#align filter.limsup_le_of_le Filter.limsSup_le_of_le
theorem le_liminf_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f :=
le_csSup hf h
#align filter.le_liminf_of_le Filter.le_liminf_of_le
theorem le_limsSup_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f :=
le_csInf hf h
set_option linter.uppercaseLean3 false in
#align filter.le_Limsup_of_le Filter.le_limsSup_of_le
theorem limsInf_le_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a :=
csSup_le hf h
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_of_le Filter.limsInf_le_of_le
theorem le_limsup_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f :=
le_csInf hf h
#align filter.le_limsup_of_le Filter.le_limsup_of_le
theorem liminf_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a :=
csSup_le hf h
#align filter.liminf_le_of_le Filter.liminf_le_of_le
theorem limsInf_le_limsSup {f : Filter α} [NeBot f]
(h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault):
limsInf f ≤ limsSup f :=
liminf_le_of_le h₂ fun a₀ ha₀ =>
le_limsup_of_le h₁ fun a₁ ha₁ =>
show a₀ ≤ a₁ from
let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists
le_trans hb₀ hb₁
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_Limsup Filter.limsInf_le_limsSup
theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α}
(h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault):
liminf u f ≤ limsup u f :=
limsInf_le_limsSup h h'
#align filter.liminf_le_limsup Filter.liminf_le_limsup
theorem limsSup_le_limsSup {f g : Filter α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g :=
csInf_le_csInf hf hg h
set_option linter.uppercaseLean3 false in
#align filter.Limsup_le_Limsup Filter.limsSup_le_limsSup
theorem limsInf_le_limsInf {f g : Filter α}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g :=
csSup_le_csSup hg hf h
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_Liminf Filter.limsInf_le_limsInf
theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : u ≤ᶠ[f] v)
(hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) :
limsup u f ≤ limsup v f :=
limsSup_le_limsSup hu hv fun _ => h.trans
#align filter.limsup_le_limsup Filter.limsup_le_limsup
theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) :
liminf u f ≤ liminf v f :=
limsup_le_limsup (β := βᵒᵈ) h hv hu
#align filter.liminf_le_liminf Filter.liminf_le_liminf
theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g)
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) :
limsSup f ≤ limsSup g :=
limsSup_le_limsSup hf hg fun _ ha => h ha
set_option linter.uppercaseLean3 false in
#align filter.Limsup_le_Limsup_of_le Filter.limsSup_le_limsSup_of_le
theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f)
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsInf g :=
limsInf_le_limsInf hf hg fun _ ha => h ha
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_Liminf_of_le Filter.limsInf_le_limsInf_of_le
theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g)
{u : α → β}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
limsup u f ≤ limsup u g :=
limsSup_le_limsSup_of_le (map_mono h) hf hg
#align filter.limsup_le_limsup_of_le Filter.limsup_le_limsup_of_le
theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f)
{u : α → β}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ liminf u g :=
limsInf_le_limsInf_of_le (map_mono h) hf hg
#align filter.liminf_le_liminf_of_le Filter.liminf_le_liminf_of_le
theorem limsSup_principal {s : Set α} (h : BddAbove s) (hs : s.Nonempty) :
limsSup (𝓟 s) = sSup s := by
simp only [limsSup, eventually_principal]; exact csInf_upper_bounds_eq_csSup h hs
set_option linter.uppercaseLean3 false in
#align filter.Limsup_principal Filter.limsSup_principal
theorem limsInf_principal {s : Set α} (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s :=
limsSup_principal (α := αᵒᵈ) h hs
set_option linter.uppercaseLean3 false in
#align filter.Liminf_principal Filter.limsInf_principal
theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by
rw [limsup_eq]
congr with b
exact eventually_congr (h.mono fun x hx => by simp [hx])
#align filter.limsup_congr Filter.limsup_congr
theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
blimsup u f p = blimsup v f p := by
simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h
#align filter.blimsup_congr Filter.blimsup_congr
theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
bliminf u f p = bliminf v f p :=
blimsup_congr (α := αᵒᵈ) h
#align filter.bliminf_congr Filter.bliminf_congr
theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f :=
limsup_congr (β := βᵒᵈ) h
#align filter.liminf_congr Filter.liminf_congr
@[simp]
theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : limsup (fun _ => b) f = b := by
simpa only [limsup_eq, eventually_const] using csInf_Ici
#align filter.limsup_const Filter.limsup_const
@[simp]
theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : liminf (fun _ => b) f = b :=
limsup_const (β := βᵒᵈ) b
#align filter.liminf_const Filter.liminf_const
theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by
simp_rw [liminf_eq, hv.eventually_iff]
congr
ext x
simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists,
exists_prop]
theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
liminf f v = sSup univ := by
simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq]
theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) :=
HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv
theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
limsup f v = sInf univ :=
HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i
-- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself.
@[simp, nolint simpNF]
theorem liminf_nat_add (f : ℕ → α) (k : ℕ) :
liminf (fun i => f (i + k)) atTop = liminf f atTop := by
change liminf (f ∘ (· + k)) atTop = liminf f atTop
rw [liminf, liminf, ← map_map, map_add_atTop_eq_nat]
#align filter.liminf_nat_add Filter.liminf_nat_add
-- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself.
@[simp, nolint simpNF]
theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop :=
@liminf_nat_add αᵒᵈ _ f k
#align filter.limsup_nat_add Filter.limsup_nat_add
end ConditionallyCompleteLattice
section CompleteLattice
variable [CompleteLattice α]
@[simp]
theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ :=
bot_unique <| sInf_le <| by simp
set_option linter.uppercaseLean3 false in
#align filter.Limsup_bot Filter.limsSup_bot
@[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup]
@[simp]
theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ :=
top_unique <| le_sSup <| by simp
set_option linter.uppercaseLean3 false in
#align filter.Liminf_bot Filter.limsInf_bot
@[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf]
@[simp]
theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ :=
top_unique <| le_sInf <| by simp [eq_univ_iff_forall]; exact fun b hb => top_unique <| hb _
set_option linter.uppercaseLean3 false in
#align filter.Limsup_top Filter.limsSup_top
@[simp]
theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ :=
bot_unique <| sSup_le <| by simp [eq_univ_iff_forall]; exact fun b hb => bot_unique <| hb _
set_option linter.uppercaseLean3 false in
#align filter.Liminf_top Filter.limsInf_top
@[simp]
theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by
simp [blimsup_eq]
#align filter.blimsup_false Filter.blimsup_false
@[simp]
theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by
simp [bliminf_eq]
#align filter.bliminf_false Filter.bliminf_false
/-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/
@[simp]
theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by
rw [limsup_eq, eq_bot_iff]
exact sInf_le (eventually_of_forall fun _ => le_rfl)
#align filter.limsup_const_bot Filter.limsup_const_bot
/-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/
@[simp]
theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) :=
limsup_const_bot (α := αᵒᵈ)
#align filter.liminf_const_top Filter.liminf_const_top
theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) :
limsSup f = ⨅ (i) (_ : p i), sSup (s i) :=
le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩)
(le_sInf fun _ ha =>
let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha
iInf₂_le_of_le _ hi <| sSup_le ha)
set_option linter.uppercaseLean3 false in
#align filter.has_basis.Limsup_eq_infi_Sup Filter.HasBasis.limsSup_eq_iInf_sSup
theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α}
(h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) :=
HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h
set_option linter.uppercaseLean3 false in
#align filter.has_basis.Liminf_eq_supr_Inf Filter.HasBasis.limsInf_eq_iSup_sInf
theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s :=
f.basis_sets.limsSup_eq_iInf_sSup
set_option linter.uppercaseLean3 false in
#align filter.Limsup_eq_infi_Sup Filter.limsSup_eq_iInf_sSup
theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s :=
limsSup_eq_iInf_sSup (α := αᵒᵈ)
set_option linter.uppercaseLean3 false in
#align filter.Liminf_eq_supr_Inf Filter.limsInf_eq_iSup_sInf
theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n :=
limsup_le_of_le (by isBoundedDefault) (eventually_of_forall (le_iSup u))
#align filter.limsup_le_supr Filter.limsup_le_iSup
theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f :=
le_liminf_of_le (by isBoundedDefault) (eventually_of_forall (iInf_le u))
#align filter.infi_le_liminf Filter.iInf_le_liminf
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a :=
(f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
#align filter.limsup_eq_infi_supr Filter.limsup_eq_iInf_iSup
theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i :=
(atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl
#align filter.limsup_eq_infi_supr_of_nat Filter.limsup_eq_iInf_iSup_of_nat
theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by
simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add]
#align filter.limsup_eq_infi_supr_of_nat' Filter.limsup_eq_iInf_iSup_of_nat'
theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a :=
(h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
#align filter.has_basis.limsup_eq_infi_supr Filter.HasBasis.limsup_eq_iInf_iSup
theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by
simp only [blimsup_eq]
congr with a
refine eventually_congr (h.mono fun b hb => ?_)
rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu]
rw [hb hu]
#align filter.blimsup_congr' Filter.blimsup_congr'
theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q :=
blimsup_congr' (α := αᵒᵈ) h
#align filter.bliminf_congr' Filter.bliminf_congr'
lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(hf : f.HasBasis p s) {q : β → Prop} :
blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by
simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and,
mem_setOf_eq]
theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} :
blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by
simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm]
#align filter.blimsup_eq_infi_bsupr Filter.blimsup_eq_iInf_biSup
theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} :
blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by
simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true]
#align filter.blimsup_eq_infi_bsupr_of_nat Filter.blimsup_eq_iInf_biSup_of_nat
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a :=
limsup_eq_iInf_iSup (α := αᵒᵈ)
#align filter.liminf_eq_supr_infi Filter.liminf_eq_iSup_iInf
theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i :=
@limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u
#align filter.liminf_eq_supr_infi_of_nat Filter.liminf_eq_iSup_iInf_of_nat
theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) :=
@limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _
#align filter.liminf_eq_supr_infi_of_nat' Filter.liminf_eq_iSup_iInf_of_nat'
theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a :=
HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h
#align filter.has_basis.liminf_eq_supr_infi Filter.HasBasis.liminf_eq_iSup_iInf
theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} :
bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b :=
@blimsup_eq_iInf_biSup αᵒᵈ β _ f p u
#align filter.bliminf_eq_supr_binfi Filter.bliminf_eq_iSup_biInf
theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} :
bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j :=
@blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u
#align filter.bliminf_eq_supr_binfi_of_nat Filter.bliminf_eq_iSup_biInf_of_nat
theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by
apply le_antisymm
· rw [limsup_eq]
refine sInf_le_sInf fun x hx => ?_
rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩
filter_upwards [I_mem_F] with i hi
exact hI ▸ le_sSup (mem_image_of_mem _ hi)
· refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_
rintro _ ⟨_, h, rfl⟩
exact h
set_option linter.uppercaseLean3 false in
#align filter.limsup_eq_Inf_Sup Filter.limsup_eq_sInf_sSup
theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) :=
@Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a
set_option linter.uppercaseLean3 false in
#align filter.liminf_eq_Sup_Inf Filter.liminf_eq_sSup_sInf
theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by
rw [liminf_eq]
refine sSup_le fun b hb => ?_
have hbx : ∃ᶠ _ in f, b ≤ x := by
revert h
rw [← not_imp_not, not_frequently, not_frequently]
exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax))
exact hbx.exists.choose_spec
#align filter.liminf_le_of_frequently_le' Filter.liminf_le_of_frequently_le'
theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f :=
liminf_le_of_frequently_le' (β := βᵒᵈ) h
#align filter.le_limsup_of_frequently_le' Filter.le_limsup_of_frequently_le'
/-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any
`a : α` is a fixed point. -/
@[simp]
theorem CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) :
f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by
rw [limsup_eq_iInf_iSup_of_nat', map_iInf]
simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f,
← Nat.add_succ]
conv_rhs => rw [iInf_split _ (0 < ·)]
simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf]
refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_
simp only [zero_add, Function.comp_apply, iSup_le_iff]
exact fun i => le_iSup (fun i => f^[i] a) (i + 1)
#align filter.complete_lattice_hom.apply_limsup_iterate Filter.CompleteLatticeHom.apply_limsup_iterate
/-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any
`a : α` is a fixed point. -/
theorem CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) :
f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop :=
apply_limsup_iterate (CompleteLatticeHom.dual f) _
#align filter.complete_lattice_hom.apply_liminf_iterate Filter.CompleteLatticeHom.apply_liminf_iterate
variable {f g : Filter β} {p q : β → Prop} {u v : β → α}
theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q :=
sInf_le_sInf fun a ha => ha.mono <| by tauto
#align filter.blimsup_mono Filter.blimsup_mono
theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p :=
sSup_le_sSup fun a ha => ha.mono <| by tauto
#align filter.bliminf_antitone Filter.bliminf_antitone
theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx')
#align filter.mono_blimsup' Filter.mono_blimsup'
theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
mono_blimsup' <| eventually_of_forall h
#align filter.mono_blimsup Filter.mono_blimsup
theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx')
#align filter.mono_bliminf' Filter.mono_bliminf'
theorem mono_bliminf (h : ∀ x, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
mono_bliminf' <| eventually_of_forall h
#align filter.mono_bliminf Filter.mono_bliminf
theorem bliminf_antitone_filter (h : f ≤ g) : bliminf u g p ≤ bliminf u f p :=
sSup_le_sSup fun _ ha => ha.filter_mono h
#align filter.bliminf_antitone_filter Filter.bliminf_antitone_filter
theorem blimsup_monotone_filter (h : f ≤ g) : blimsup u f p ≤ blimsup u g p :=
sInf_le_sInf fun _ ha => ha.filter_mono h
#align filter.blimsup_monotone_filter Filter.blimsup_monotone_filter
-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux versions below
theorem blimsup_and_le_inf : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q :=
le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
#align filter.blimsup_and_le_inf Filter.blimsup_and_le_inf
@[simp]
theorem bliminf_sup_le_inf_aux_left :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p :=
blimsup_and_le_inf.trans inf_le_left
@[simp]
theorem bliminf_sup_le_inf_aux_right :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f q :=
blimsup_and_le_inf.trans inf_le_right
-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp version below
theorem bliminf_sup_le_and : bliminf u f p ⊔ bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
blimsup_and_le_inf (α := αᵒᵈ)
#align filter.bliminf_sup_le_and Filter.bliminf_sup_le_and
@[simp]
theorem bliminf_sup_le_and_aux_left : bliminf u f p ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_left.trans bliminf_sup_le_and
@[simp]
theorem bliminf_sup_le_and_aux_right : bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_right.trans bliminf_sup_le_and
/-- See also `Filter.blimsup_or_eq_sup`. -/
-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp versions below
theorem blimsup_sup_le_or : blimsup u f p ⊔ blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
#align filter.blimsup_sup_le_or Filter.blimsup_sup_le_or
@[simp]
theorem bliminf_sup_le_or_aux_left : blimsup u f p ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_left.trans blimsup_sup_le_or
@[simp]
theorem bliminf_sup_le_or_aux_right : blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_right.trans blimsup_sup_le_or
/-- See also `Filter.bliminf_or_eq_inf`. -/
--@[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp versions below
theorem bliminf_or_le_inf : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q :=
blimsup_sup_le_or (α := αᵒᵈ)
#align filter.bliminf_or_le_inf Filter.bliminf_or_le_inf
@[simp]
theorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p :=
bliminf_or_le_inf.trans inf_le_left
@[simp]
theorem bliminf_or_le_inf_aux_right : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f q :=
bliminf_or_le_inf.trans inf_le_right
/- Porting note: Replaced `e` with `DFunLike.coe e` to override the strange
coercion to `↑(RelIso.toRelEmbedding e).toEmbedding`. -/
theorem OrderIso.apply_blimsup [CompleteLattice γ] (e : α ≃o γ) :
DFunLike.coe e (blimsup u f p) = blimsup ((DFunLike.coe e) ∘ u) f p := by
simp only [blimsup_eq, map_sInf, Function.comp_apply]
congr
ext c
obtain ⟨a, rfl⟩ := e.surjective c
simp
#align filter.order_iso.apply_blimsup Filter.OrderIso.apply_blimsup
theorem OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) :
e (bliminf u f p) = bliminf (e ∘ u) f p :=
OrderIso.apply_blimsup (α := αᵒᵈ) (γ := γᵒᵈ) e.dual
#align filter.order_iso.apply_bliminf Filter.OrderIso.apply_bliminf
theorem SupHom.apply_blimsup_le [CompleteLattice γ] (g : sSupHom α γ) :
g (blimsup u f p) ≤ blimsup (g ∘ u) f p := by
simp only [blimsup_eq_iInf_biSup, Function.comp]
refine ((OrderHomClass.mono g).map_iInf₂_le _).trans ?_
simp only [_root_.map_iSup, le_refl]
#align filter.Sup_hom.apply_blimsup_le Filter.SupHom.apply_blimsup_le
theorem InfHom.le_apply_bliminf [CompleteLattice γ] (g : sInfHom α γ) :
bliminf (g ∘ u) f p ≤ g (bliminf u f p) :=
SupHom.apply_blimsup_le (α := αᵒᵈ) (γ := γᵒᵈ) (sInfHom.dual g)
#align filter.Inf_hom.le_apply_bliminf Filter.InfHom.le_apply_bliminf
end CompleteLattice
section CompleteDistribLattice
variable [CompleteDistribLattice α] {f : Filter β} {p q : β → Prop} {u : β → α}
lemma limsup_sup_filter {g} : limsup u (f ⊔ g) = limsup u f ⊔ limsup u g := by
refine le_antisymm ?_
(sup_le (limsup_le_limsup_of_le le_sup_left) (limsup_le_limsup_of_le le_sup_right))
simp_rw [limsup_eq, sInf_sup_eq, sup_sInf_eq, mem_setOf_eq, le_iInf₂_iff]
intro a ha b hb
exact sInf_le ⟨ha.mono fun _ h ↦ h.trans le_sup_left, hb.mono fun _ h ↦ h.trans le_sup_right⟩
lemma liminf_sup_filter {g} : liminf u (f ⊔ g) = liminf u f ⊓ liminf u g :=
limsup_sup_filter (α := αᵒᵈ)
@[simp]
theorem blimsup_or_eq_sup : (blimsup u f fun x => p x ∨ q x) = blimsup u f p ⊔ blimsup u f q := by
simp only [blimsup_eq_limsup, ← limsup_sup_filter, ← inf_sup_left, sup_principal, setOf_or]
#align filter.blimsup_or_eq_sup Filter.blimsup_or_eq_sup
@[simp]
theorem bliminf_or_eq_inf : (bliminf u f fun x => p x ∨ q x) = bliminf u f p ⊓ bliminf u f q :=
blimsup_or_eq_sup (α := αᵒᵈ)
#align filter.bliminf_or_eq_inf Filter.bliminf_or_eq_inf
@[simp]
lemma blimsup_sup_not : blimsup u f p ⊔ blimsup u f (¬p ·) = limsup u f := by
simp_rw [← blimsup_or_eq_sup, or_not, blimsup_true]
@[simp]
lemma bliminf_inf_not : bliminf u f p ⊓ bliminf u f (¬p ·) = liminf u f :=
blimsup_sup_not (α := αᵒᵈ)
@[simp]
lemma blimsup_not_sup : blimsup u f (¬p ·) ⊔ blimsup u f p = limsup u f := by
simpa only [not_not] using blimsup_sup_not (p := (¬p ·))
@[simp]
lemma bliminf_not_inf : bliminf u f (¬p ·) ⊓ bliminf u f p = liminf u f :=
blimsup_not_sup (α := αᵒᵈ)
lemma limsup_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
limsup (s.piecewise u v) f = blimsup u f (· ∈ s) ⊔ blimsup v f (· ∉ s) := by
rw [← blimsup_sup_not (p := (· ∈ s))]
refine congr_arg₂ _ (blimsup_congr ?_) (blimsup_congr ?_) <;>
filter_upwards with _ h using by simp [h]
lemma liminf_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
liminf (s.piecewise u v) f = bliminf u f (· ∈ s) ⊓ bliminf v f (· ∉ s) :=
limsup_piecewise (α := αᵒᵈ)
theorem sup_limsup [NeBot f] (a : α) : a ⊔ limsup u f = limsup (fun x => a ⊔ u x) f := by
simp only [limsup_eq_iInf_iSup, iSup_sup_eq, sup_iInf₂_eq]
congr; ext s; congr; ext hs; congr
exact (biSup_const (nonempty_of_mem hs)).symm
#align filter.sup_limsup Filter.sup_limsup
theorem inf_liminf [NeBot f] (a : α) : a ⊓ liminf u f = liminf (fun x => a ⊓ u x) f :=
sup_limsup (α := αᵒᵈ) a
#align filter.inf_liminf Filter.inf_liminf
theorem sup_liminf (a : α) : a ⊔ liminf u f = liminf (fun x => a ⊔ u x) f := by
simp only [liminf_eq_iSup_iInf]
rw [sup_comm, biSup_sup (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [iInf₂_sup_eq, sup_comm (a := a)]
#align filter.sup_liminf Filter.sup_liminf
theorem inf_limsup (a : α) : a ⊓ limsup u f = limsup (fun x => a ⊓ u x) f :=
sup_liminf (α := αᵒᵈ) a
#align filter.inf_limsup Filter.inf_limsup
end CompleteDistribLattice
section CompleteBooleanAlgebra
variable [CompleteBooleanAlgebra α] (f : Filter β) (u : β → α)
theorem limsup_compl : (limsup u f)ᶜ = liminf (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
#align filter.limsup_compl Filter.limsup_compl
theorem liminf_compl : (liminf u f)ᶜ = limsup (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
#align filter.liminf_compl Filter.liminf_compl
theorem limsup_sdiff (a : α) : limsup u f \ a = limsup (fun b => u b \ a) f := by
simp only [limsup_eq_iInf_iSup, sdiff_eq]
rw [biInf_inf (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [inf_comm, inf_iSup₂_eq, inf_comm]
#align filter.limsup_sdiff Filter.limsup_sdiff
theorem liminf_sdiff [NeBot f] (a : α) : liminf u f \ a = liminf (fun b => u b \ a) f := by
simp only [sdiff_eq, inf_comm _ aᶜ, inf_liminf]
#align filter.liminf_sdiff Filter.liminf_sdiff
theorem sdiff_limsup [NeBot f] (a : α) : a \ limsup u f = liminf (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, liminf_compl, (· ∘ ·), compl_inf, compl_compl, sup_limsup]
#align filter.sdiff_limsup Filter.sdiff_limsup
theorem sdiff_liminf (a : α) : a \ liminf u f = limsup (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, limsup_compl, (· ∘ ·), compl_inf, compl_compl, sup_liminf]
#align filter.sdiff_liminf Filter.sdiff_liminf
end CompleteBooleanAlgebra
section SetLattice
variable {p : ι → Prop} {s : ι → Set α} {𝓕 : Filter ι} {a : α}
lemma mem_liminf_iff_eventually_mem : (a ∈ liminf s 𝓕) ↔ (∀ᶠ i in 𝓕, a ∈ s i) := by
simpa only [liminf_eq_iSup_iInf, iSup_eq_iUnion, iInf_eq_iInter, mem_iUnion, mem_iInter]
using ⟨fun ⟨S, hS, hS'⟩ ↦ mem_of_superset hS (by tauto), fun h ↦ ⟨{i | a ∈ s i}, h, by tauto⟩⟩
lemma mem_limsup_iff_frequently_mem : (a ∈ limsup s 𝓕) ↔ (∃ᶠ i in 𝓕, a ∈ s i) := by
simp only [Filter.Frequently, iff_not_comm, ← mem_compl_iff, limsup_compl, comp_apply,
mem_liminf_iff_eventually_mem]
theorem cofinite.blimsup_set_eq :
blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.Infinite } := by
simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, sInf_eq_sInter, exists_prop]
ext x
refine ⟨fun h => ?_, fun hx t h => ?_⟩ <;> contrapose! h
· simp only [mem_sInter, mem_setOf_eq, not_forall, exists_prop]
exact ⟨{x}ᶜ, by simpa using h, by simp⟩
· exact hx.mono fun i hi => ⟨hi.1, fun hit => h (hit hi.2)⟩
#align filter.cofinite.blimsup_set_eq Filter.cofinite.blimsup_set_eq
theorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.Finite } := by
rw [← compl_inj_iff]
simp only [bliminf_eq_iSup_biInf, compl_iInf, compl_iSup, ← blimsup_eq_iInf_biSup,
cofinite.blimsup_set_eq]
rfl
#align filter.cofinite.bliminf_set_eq Filter.cofinite.bliminf_set_eq
/-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s`
infinitely often. -/
theorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x ∈ s n }.Infinite } := by
simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and_iff]
#align filter.cofinite.limsup_set_eq Filter.cofinite.limsup_set_eq
/-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s`
finitely often. -/
theorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x ∉ s n }.Finite } := by
simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and_iff]
#align filter.cofinite.liminf_set_eq Filter.cofinite.liminf_set_eq
theorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter β} {b : ι → Set β} {q : ι → Prop}
(hl : l.HasBasis q b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) :
∃ f : { i | q i } → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
rw [blimsup_eq_iInf_biSup] at hx
simp only [iSup_eq_iUnion, iInf_eq_iInter, mem_iInter, mem_iUnion, exists_prop] at hx
choose g hg hg' using hx
refine ⟨fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => ⟨?_, ?_⟩⟩
· exact hg' (b i) (hl.mem_of_mem i.2)
· exact hg (b i) (hl.mem_of_mem i.2)
#align filter.exists_forall_mem_of_has_basis_mem_blimsup Filter.exists_forall_mem_of_hasBasis_mem_blimsup
theorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter β} {b : ι → Set β}
(hl : l.HasBasis (fun _ => True) b) {u : β → Set α} {p : β → Prop} {x : α}
(hx : x ∈ blimsup u l p) : ∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
obtain ⟨f, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup hl hx
exact ⟨fun i => f ⟨i, trivial⟩, fun i => hf ⟨i, trivial⟩⟩
#align filter.exists_forall_mem_of_has_basis_mem_blimsup' Filter.exists_forall_mem_of_hasBasis_mem_blimsup'
end SetLattice
section ConditionallyCompleteLinearOrder
theorem frequently_lt_of_lt_limsSup {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : a < limsSup f) : ∃ᶠ n in f, a < n := by
contrapose! h
simp only [not_frequently, not_lt] at h
exact limsSup_le_of_le hf h
set_option linter.uppercaseLean3 false in
#align filter.frequently_lt_of_lt_Limsup Filter.frequently_lt_of_lt_limsSup
theorem frequently_lt_of_limsInf_lt {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : limsInf f < a) : ∃ᶠ n in f, n < a :=
frequently_lt_of_lt_limsSup (α := OrderDual α) hf h
set_option linter.uppercaseLean3 false in
#align filter.frequently_lt_of_Liminf_lt Filter.frequently_lt_of_limsInf_lt
theorem eventually_lt_of_lt_liminf {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : b < liminf u f)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
∀ᶠ a in f, b < u a := by
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (_ : c ∈ { c : β | ∀ᶠ n : α in f, c ≤ u n }), b < c := by
simp_rw [exists_prop]
exact exists_lt_of_lt_csSup hu h
exact hc.mono fun x hx => lt_of_lt_of_le hbc hx
#align filter.eventually_lt_of_lt_liminf Filter.eventually_lt_of_lt_liminf
theorem eventually_lt_of_limsup_lt {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : limsup u f < b)
(hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
∀ᶠ a in f, u a < b :=
eventually_lt_of_lt_liminf (β := βᵒᵈ) h hu
#align filter.eventually_lt_of_limsup_lt Filter.eventually_lt_of_limsup_lt
theorem le_limsup_of_frequently_le {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, b ≤ u x)
(hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
b ≤ limsup u f := by
revert hu_le
rw [← not_imp_not, not_frequently]
simp_rw [← lt_iff_not_ge]
exact fun h => eventually_lt_of_limsup_lt h hu
#align filter.le_limsup_of_frequently_le Filter.le_limsup_of_frequently_le
theorem liminf_le_of_frequently_le {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, u x ≤ b)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ b :=
le_limsup_of_frequently_le (β := βᵒᵈ) hu_le hu
#align filter.liminf_le_of_frequently_le Filter.liminf_le_of_frequently_le
theorem frequently_lt_of_lt_limsup {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β}
(hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : b < limsup u f) : ∃ᶠ x in f, b < u x := by
contrapose! h
apply limsSup_le_of_le hu
simpa using h
#align filter.frequently_lt_of_lt_limsup Filter.frequently_lt_of_lt_limsup
theorem frequently_lt_of_liminf_lt {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β}
(hu : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : liminf u f < b) : ∃ᶠ x in f, u x < b :=
frequently_lt_of_lt_limsup (β := βᵒᵈ) hu h
#align filter.frequently_lt_of_liminf_lt Filter.frequently_lt_of_liminf_lt
variable [ConditionallyCompleteLinearOrder α] {f : Filter α} {b : α}
-- The linter erroneously claims that I'm not referring to `c`
set_option linter.unusedVariables false in
theorem lt_mem_sets_of_limsSup_lt (h : f.IsBounded (· ≤ ·)) (l : f.limsSup < b) :
∀ᶠ a in f, a < b :=
let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_csInf_lt h l
mem_of_superset h fun _a => hcb.trans_le'
set_option linter.uppercaseLean3 false in
#align filter.lt_mem_sets_of_Limsup_lt Filter.lt_mem_sets_of_limsSup_lt
theorem gt_mem_sets_of_limsInf_gt : f.IsBounded (· ≥ ·) → b < f.limsInf → ∀ᶠ a in f, b < a :=
@lt_mem_sets_of_limsSup_lt αᵒᵈ _ _ _
set_option linter.uppercaseLean3 false in
#align filter.gt_mem_sets_of_Liminf_gt Filter.gt_mem_sets_of_limsInf_gt
section Classical
open scoped Classical
/-- Given an indexed family of sets `s j` over `j : Subtype p` and a function `f`, then
`liminf_reparam j` is equal to `j` if `f` is bounded below on `s j`, and otherwise to some
index `k` such that `f` is bounded below on `s k` (if there exists one).
To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index.
This function is used to write down a liminf in a measurable way,
in `Filter.HasBasis.liminf_eq_ciSup_ciInf` and `Filter.HasBasis.liminf_eq_ite`. -/
noncomputable def liminf_reparam
(f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)]
(j : Subtype p) : Subtype p :=
let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))}
let g : ℕ → Subtype p := (exists_surjective_nat _).choose
have Z : ∃ n, g n ∈ m ∨ ∀ j, j ∉ m := by
by_cases H : ∃ j, j ∈ m
· rcases H with ⟨j, hj⟩
rcases (exists_surjective_nat (Subtype p)).choose_spec j with ⟨n, rfl⟩
exact ⟨n, Or.inl hj⟩
· push_neg at H
exact ⟨0, Or.inr H⟩
if j ∈ m then j else g (Nat.find Z)
/-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete
linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are
not bounded below. -/
| Mathlib/Order/LiminfLimsup.lean | 1,370 | 1,404 | theorem HasBasis.liminf_eq_ciSup_ciInf {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)]
(hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty)
(H : ∃ (j : Subtype p), BddBelow (range (fun (i : s j) ↦ f i))) :
liminf f v = ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by |
rcases H with ⟨j0, hj0⟩
let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))}
have : ∀ (j : Subtype p), Nonempty (s j) := fun j ↦ Nonempty.coe_sort (hs j)
have A : ⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i) =
⋃ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) := by
apply Subset.antisymm
· apply iUnion_subset (fun j ↦ ?_)
by_cases hj : j ∈ m
· have : j = liminf_reparam f s p j := by simp only [liminf_reparam, hj, ite_true]
conv_lhs => rw [this]
apply subset_iUnion _ j
· simp only [m, mem_setOf_eq, ← nonempty_iInter_Iic_iff, not_nonempty_iff_eq_empty] at hj
simp only [hj, empty_subset]
· apply iUnion_subset (fun j ↦ ?_)
exact subset_iUnion (fun (k : Subtype p) ↦ (⋂ (i : s k), Iic (f i))) (liminf_reparam f s p j)
have B : ∀ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) =
Iic (⨅ (i : s (liminf_reparam f s p j)), f i) := by
intro j
apply (Iic_ciInf _).symm
change liminf_reparam f s p j ∈ m
by_cases Hj : j ∈ m
· simpa only [liminf_reparam, if_pos Hj] using Hj
· simp only [liminf_reparam, if_neg Hj]
have Z : ∃ n, (exists_surjective_nat (Subtype p)).choose n ∈ m ∨ ∀ j, j ∉ m := by
rcases (exists_surjective_nat (Subtype p)).choose_spec j0 with ⟨n, rfl⟩
exact ⟨n, Or.inl hj0⟩
rcases Nat.find_spec Z with hZ|hZ
· exact hZ
· exact (hZ j0 hj0).elim
simp_rw [hv.liminf_eq_sSup_iUnion_iInter, A, B, sSup_iUnion_Iic]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Topology.Maps
import Mathlib.Topology.NhdsSet
#align_import topology.constructions from "leanprover-community/mathlib"@"f7ebde7ee0d1505dfccac8644ae12371aa3c1c9f"
/-!
# Constructions of new topological spaces from old ones
This file constructs products, sums, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, sum, disjoint union, subspace, quotient space
-/
noncomputable section
open scoped Classical
open Topology TopologicalSpace Set Filter Function
universe u v
variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*}
section Constructions
instance instTopologicalSpaceSubtype {p : X → Prop} [t : TopologicalSpace X] :
TopologicalSpace (Subtype p) :=
induced (↑) t
instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) :=
coinduced (Quot.mk r) t
instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] :
TopologicalSpace (Quotient s) :=
coinduced Quotient.mk' t
instance instTopologicalSpaceProd [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] :
TopologicalSpace (X × Y) :=
induced Prod.fst t₁ ⊓ induced Prod.snd t₂
instance instTopologicalSpaceSum [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] :
TopologicalSpace (X ⊕ Y) :=
coinduced Sum.inl t₁ ⊔ coinduced Sum.inr t₂
instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] :
TopologicalSpace (Sigma X) :=
⨆ i, coinduced (Sigma.mk i) (t₂ i)
instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] :
TopologicalSpace ((i : ι) → Y i) :=
⨅ i, induced (fun f => f i) (t₂ i)
#align Pi.topological_space Pi.topologicalSpace
instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) :=
t.induced ULift.down
#align ulift.topological_space ULift.topologicalSpace
/-!
### `Additive`, `Multiplicative`
The topology on those type synonyms is inherited without change.
-/
section
variable [TopologicalSpace X]
open Additive Multiplicative
instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X›
instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X›
instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X›
instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X›
theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id
#align continuous_of_mul continuous_ofMul
theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id
#align continuous_to_mul continuous_toMul
theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id
#align continuous_of_add continuous_ofAdd
theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id
#align continuous_to_add continuous_toAdd
theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id
#align is_open_map_of_mul isOpenMap_ofMul
theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id
#align is_open_map_to_mul isOpenMap_toMul
theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id
#align is_open_map_of_add isOpenMap_ofAdd
theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id
#align is_open_map_to_add isOpenMap_toAdd
theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id
#align is_closed_map_of_mul isClosedMap_ofMul
theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id
#align is_closed_map_to_mul isClosedMap_toMul
theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id
#align is_closed_map_of_add isClosedMap_ofAdd
theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id
#align is_closed_map_to_add isClosedMap_toAdd
theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl
#align nhds_of_mul nhds_ofMul
theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl
#align nhds_of_add nhds_ofAdd
theorem nhds_toMul (x : Additive X) : 𝓝 (toMul x) = map toMul (𝓝 x) := rfl
#align nhds_to_mul nhds_toMul
theorem nhds_toAdd (x : Multiplicative X) : 𝓝 (toAdd x) = map toAdd (𝓝 x) := rfl
#align nhds_to_add nhds_toAdd
end
/-!
### Order dual
The topology on this type synonym is inherited without change.
-/
section
variable [TopologicalSpace X]
open OrderDual
instance : TopologicalSpace Xᵒᵈ := ‹TopologicalSpace X›
instance [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹DiscreteTopology X›
theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id
#align continuous_to_dual continuous_toDual
theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id
#align continuous_of_dual continuous_ofDual
theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id
#align is_open_map_to_dual isOpenMap_toDual
theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id
#align is_open_map_of_dual isOpenMap_ofDual
theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id
#align is_closed_map_to_dual isClosedMap_toDual
theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id
#align is_closed_map_of_dual isClosedMap_ofDual
theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl
#align nhds_to_dual nhds_toDual
theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl
#align nhds_of_dual nhds_ofDual
end
theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s}
{x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x :=
preimage_nhds_coinduced hs
#align quotient.preimage_mem_nhds Quotient.preimage_mem_nhds
/-- The image of a dense set under `Quotient.mk'` is a dense set. -/
theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) :
Dense (Quotient.mk' '' s) :=
Quotient.surjective_Quotient_mk''.denseRange.dense_image continuous_coinduced_rng H
#align dense.quotient Dense.quotient
/-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/
theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) :
DenseRange (Quotient.mk' ∘ f) :=
Quotient.surjective_Quotient_mk''.denseRange.comp hf continuous_coinduced_rng
#align dense_range.quotient DenseRange.quotient
theorem continuous_map_of_le {α : Type*} [TopologicalSpace α]
{s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) :=
continuous_coinduced_rng
theorem continuous_map_sInf {α : Type*} [TopologicalSpace α]
{S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) :=
continuous_coinduced_rng
instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) :=
⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩
instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X]
[hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) :=
⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩
#align sum.discrete_topology Sum.discreteTopology
instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)]
[h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) :=
⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩
#align sigma.discrete_topology Sigma.discreteTopology
section Top
variable [TopologicalSpace X]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) :
t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t :=
mem_nhds_induced _ x t
#align mem_nhds_subtype mem_nhds_subtype
theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) :=
nhds_induced _ x
#align nhds_subtype nhds_subtype
theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} :
𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by
rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal,
nhds_induced]
#align nhds_within_subtype_eq_bot_iff nhdsWithin_subtype_eq_bot_iff
theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} :
𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by
rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton,
Subtype.coe_injective.preimage_image]
#align nhds_ne_subtype_eq_bot_iff nhds_ne_subtype_eq_bot_iff
theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} :
(𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by
rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff]
#align nhds_ne_subtype_ne_bot_iff nhds_ne_subtype_neBot_iff
theorem discreteTopology_subtype_iff {S : Set X} :
DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by
simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff]
#align discrete_topology_subtype_iff discreteTopology_subtype_iff
end Top
/-- A type synonym equipped with the topology whose open sets are the empty set and the sets with
finite complements. -/
def CofiniteTopology (X : Type*) := X
#align cofinite_topology CofiniteTopology
namespace CofiniteTopology
/-- The identity equivalence between `` and `CofiniteTopology `. -/
def of : X ≃ CofiniteTopology X :=
Equiv.refl X
#align cofinite_topology.of CofiniteTopology.of
instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default
instance : TopologicalSpace (CofiniteTopology X) where
IsOpen s := s.Nonempty → Set.Finite sᶜ
isOpen_univ := by simp
isOpen_inter s t := by
rintro hs ht ⟨x, hxs, hxt⟩
rw [compl_inter]
exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩)
isOpen_sUnion := by
rintro s h ⟨x, t, hts, hzt⟩
rw [compl_sUnion]
exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩)
theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite :=
Iff.rfl
#align cofinite_topology.is_open_iff CofiniteTopology.isOpen_iff
theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by
simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left]
#align cofinite_topology.is_open_iff' CofiniteTopology.isOpen_iff'
theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by
simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff]
#align cofinite_topology.is_closed_iff CofiniteTopology.isClosed_iff
theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by
ext U
rw [mem_nhds_iff]
constructor
· rintro ⟨V, hVU, V_op, haV⟩
exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩
· rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩
exact ⟨U, Subset.rfl, fun _ => hU', hU⟩
#align cofinite_topology.nhds_eq CofiniteTopology.nhds_eq
theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} :
s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq]
#align cofinite_topology.mem_nhds_iff CofiniteTopology.mem_nhds_iff
end CofiniteTopology
end Constructions
section Prod
variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace W]
[TopologicalSpace ε] [TopologicalSpace ζ]
-- Porting note (#11215): TODO: Lean 4 fails to deduce implicit args
@[simp] theorem continuous_prod_mk {f : X → Y} {g : X → Z} :
(Continuous fun x => (f x, g x)) ↔ Continuous f ∧ Continuous g :=
(@continuous_inf_rng X (Y × Z) _ _ (TopologicalSpace.induced Prod.fst _)
(TopologicalSpace.induced Prod.snd _)).trans <|
continuous_induced_rng.and continuous_induced_rng
#align continuous_prod_mk continuous_prod_mk
@[continuity]
theorem continuous_fst : Continuous (@Prod.fst X Y) :=
(continuous_prod_mk.1 continuous_id).1
#align continuous_fst continuous_fst
/-- Postcomposing `f` with `Prod.fst` is continuous -/
@[fun_prop]
theorem Continuous.fst {f : X → Y × Z} (hf : Continuous f) : Continuous fun x : X => (f x).1 :=
continuous_fst.comp hf
#align continuous.fst Continuous.fst
/-- Precomposing `f` with `Prod.fst` is continuous -/
theorem Continuous.fst' {f : X → Z} (hf : Continuous f) : Continuous fun x : X × Y => f x.fst :=
hf.comp continuous_fst
#align continuous.fst' Continuous.fst'
theorem continuousAt_fst {p : X × Y} : ContinuousAt Prod.fst p :=
continuous_fst.continuousAt
#align continuous_at_fst continuousAt_fst
/-- Postcomposing `f` with `Prod.fst` is continuous at `x` -/
@[fun_prop]
theorem ContinuousAt.fst {f : X → Y × Z} {x : X} (hf : ContinuousAt f x) :
ContinuousAt (fun x : X => (f x).1) x :=
continuousAt_fst.comp hf
#align continuous_at.fst ContinuousAt.fst
/-- Precomposing `f` with `Prod.fst` is continuous at `(x, y)` -/
theorem ContinuousAt.fst' {f : X → Z} {x : X} {y : Y} (hf : ContinuousAt f x) :
ContinuousAt (fun x : X × Y => f x.fst) (x, y) :=
ContinuousAt.comp hf continuousAt_fst
#align continuous_at.fst' ContinuousAt.fst'
/-- Precomposing `f` with `Prod.fst` is continuous at `x : X × Y` -/
theorem ContinuousAt.fst'' {f : X → Z} {x : X × Y} (hf : ContinuousAt f x.fst) :
ContinuousAt (fun x : X × Y => f x.fst) x :=
hf.comp continuousAt_fst
#align continuous_at.fst'' ContinuousAt.fst''
theorem Filter.Tendsto.fst_nhds {l : Filter X} {f : X → Y × Z} {p : Y × Z}
(h : Tendsto f l (𝓝 p)) : Tendsto (fun a ↦ (f a).1) l (𝓝 <| p.1) :=
continuousAt_fst.tendsto.comp h
@[continuity]
theorem continuous_snd : Continuous (@Prod.snd X Y) :=
(continuous_prod_mk.1 continuous_id).2
#align continuous_snd continuous_snd
/-- Postcomposing `f` with `Prod.snd` is continuous -/
@[fun_prop]
theorem Continuous.snd {f : X → Y × Z} (hf : Continuous f) : Continuous fun x : X => (f x).2 :=
continuous_snd.comp hf
#align continuous.snd Continuous.snd
/-- Precomposing `f` with `Prod.snd` is continuous -/
theorem Continuous.snd' {f : Y → Z} (hf : Continuous f) : Continuous fun x : X × Y => f x.snd :=
hf.comp continuous_snd
#align continuous.snd' Continuous.snd'
theorem continuousAt_snd {p : X × Y} : ContinuousAt Prod.snd p :=
continuous_snd.continuousAt
#align continuous_at_snd continuousAt_snd
/-- Postcomposing `f` with `Prod.snd` is continuous at `x` -/
@[fun_prop]
theorem ContinuousAt.snd {f : X → Y × Z} {x : X} (hf : ContinuousAt f x) :
ContinuousAt (fun x : X => (f x).2) x :=
continuousAt_snd.comp hf
#align continuous_at.snd ContinuousAt.snd
/-- Precomposing `f` with `Prod.snd` is continuous at `(x, y)` -/
theorem ContinuousAt.snd' {f : Y → Z} {x : X} {y : Y} (hf : ContinuousAt f y) :
ContinuousAt (fun x : X × Y => f x.snd) (x, y) :=
ContinuousAt.comp hf continuousAt_snd
#align continuous_at.snd' ContinuousAt.snd'
/-- Precomposing `f` with `Prod.snd` is continuous at `x : X × Y` -/
theorem ContinuousAt.snd'' {f : Y → Z} {x : X × Y} (hf : ContinuousAt f x.snd) :
ContinuousAt (fun x : X × Y => f x.snd) x :=
hf.comp continuousAt_snd
#align continuous_at.snd'' ContinuousAt.snd''
theorem Filter.Tendsto.snd_nhds {l : Filter X} {f : X → Y × Z} {p : Y × Z}
(h : Tendsto f l (𝓝 p)) : Tendsto (fun a ↦ (f a).2) l (𝓝 <| p.2) :=
continuousAt_snd.tendsto.comp h
@[continuity, fun_prop]
theorem Continuous.prod_mk {f : Z → X} {g : Z → Y} (hf : Continuous f) (hg : Continuous g) :
Continuous fun x => (f x, g x) :=
continuous_prod_mk.2 ⟨hf, hg⟩
#align continuous.prod_mk Continuous.prod_mk
@[continuity]
theorem Continuous.Prod.mk (x : X) : Continuous fun y : Y => (x, y) :=
continuous_const.prod_mk continuous_id
#align continuous.prod.mk Continuous.Prod.mk
@[continuity]
theorem Continuous.Prod.mk_left (y : Y) : Continuous fun x : X => (x, y) :=
continuous_id.prod_mk continuous_const
#align continuous.prod.mk_left Continuous.Prod.mk_left
/-- If `f x y` is continuous in `x` for all `y ∈ s`,
then the set of `x` such that `f x` maps `s` to `t` is closed. -/
lemma IsClosed.setOf_mapsTo {α : Type*} {f : X → α → Z} {s : Set α} {t : Set Z} (ht : IsClosed t)
(hf : ∀ a ∈ s, Continuous (f · a)) : IsClosed {x | MapsTo (f x) s t} := by
simpa only [MapsTo, setOf_forall] using isClosed_biInter fun y hy ↦ ht.preimage (hf y hy)
theorem Continuous.comp₂ {g : X × Y → Z} (hg : Continuous g) {e : W → X} (he : Continuous e)
{f : W → Y} (hf : Continuous f) : Continuous fun w => g (e w, f w) :=
hg.comp <| he.prod_mk hf
#align continuous.comp₂ Continuous.comp₂
theorem Continuous.comp₃ {g : X × Y × Z → ε} (hg : Continuous g) {e : W → X} (he : Continuous e)
{f : W → Y} (hf : Continuous f) {k : W → Z} (hk : Continuous k) :
Continuous fun w => g (e w, f w, k w) :=
hg.comp₂ he <| hf.prod_mk hk
#align continuous.comp₃ Continuous.comp₃
theorem Continuous.comp₄ {g : X × Y × Z × ζ → ε} (hg : Continuous g) {e : W → X} (he : Continuous e)
{f : W → Y} (hf : Continuous f) {k : W → Z} (hk : Continuous k) {l : W → ζ}
(hl : Continuous l) : Continuous fun w => g (e w, f w, k w, l w) :=
hg.comp₃ he hf <| hk.prod_mk hl
#align continuous.comp₄ Continuous.comp₄
@[continuity]
theorem Continuous.prod_map {f : Z → X} {g : W → Y} (hf : Continuous f) (hg : Continuous g) :
Continuous fun p : Z × W => (f p.1, g p.2) :=
hf.fst'.prod_mk hg.snd'
#align continuous.prod_map Continuous.prod_map
/-- A version of `continuous_inf_dom_left` for binary functions -/
theorem continuous_inf_dom_left₂ {X Y Z} {f : X → Y → Z} {ta1 ta2 : TopologicalSpace X}
{tb1 tb2 : TopologicalSpace Y} {tc1 : TopologicalSpace Z}
(h : by haveI := ta1; haveI := tb1; exact Continuous fun p : X × Y => f p.1 p.2) : by
haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact Continuous fun p : X × Y => f p.1 p.2 := by
have ha := @continuous_inf_dom_left _ _ id ta1 ta2 ta1 (@continuous_id _ (id _))
have hb := @continuous_inf_dom_left _ _ id tb1 tb2 tb1 (@continuous_id _ (id _))
have h_continuous_id := @Continuous.prod_map _ _ _ _ ta1 tb1 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb
exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id
#align continuous_inf_dom_left₂ continuous_inf_dom_left₂
/-- A version of `continuous_inf_dom_right` for binary functions -/
theorem continuous_inf_dom_right₂ {X Y Z} {f : X → Y → Z} {ta1 ta2 : TopologicalSpace X}
{tb1 tb2 : TopologicalSpace Y} {tc1 : TopologicalSpace Z}
(h : by haveI := ta2; haveI := tb2; exact Continuous fun p : X × Y => f p.1 p.2) : by
haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact Continuous fun p : X × Y => f p.1 p.2 := by
have ha := @continuous_inf_dom_right _ _ id ta1 ta2 ta2 (@continuous_id _ (id _))
have hb := @continuous_inf_dom_right _ _ id tb1 tb2 tb2 (@continuous_id _ (id _))
have h_continuous_id := @Continuous.prod_map _ _ _ _ ta2 tb2 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb
exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id
#align continuous_inf_dom_right₂ continuous_inf_dom_right₂
/-- A version of `continuous_sInf_dom` for binary functions -/
theorem continuous_sInf_dom₂ {X Y Z} {f : X → Y → Z} {tas : Set (TopologicalSpace X)}
{tbs : Set (TopologicalSpace Y)} {tX : TopologicalSpace X} {tY : TopologicalSpace Y}
{tc : TopologicalSpace Z} (hX : tX ∈ tas) (hY : tY ∈ tbs)
(hf : Continuous fun p : X × Y => f p.1 p.2) : by
haveI := sInf tas; haveI := sInf tbs;
exact @Continuous _ _ _ tc fun p : X × Y => f p.1 p.2 := by
have hX := continuous_sInf_dom hX continuous_id
have hY := continuous_sInf_dom hY continuous_id
have h_continuous_id := @Continuous.prod_map _ _ _ _ tX tY (sInf tas) (sInf tbs) _ _ hX hY
exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ hf h_continuous_id
#align continuous_Inf_dom₂ continuous_sInf_dom₂
theorem Filter.Eventually.prod_inl_nhds {p : X → Prop} {x : X} (h : ∀ᶠ x in 𝓝 x, p x) (y : Y) :
∀ᶠ x in 𝓝 (x, y), p (x : X × Y).1 :=
continuousAt_fst h
#align filter.eventually.prod_inl_nhds Filter.Eventually.prod_inl_nhds
theorem Filter.Eventually.prod_inr_nhds {p : Y → Prop} {y : Y} (h : ∀ᶠ x in 𝓝 y, p x) (x : X) :
∀ᶠ x in 𝓝 (x, y), p (x : X × Y).2 :=
continuousAt_snd h
#align filter.eventually.prod_inr_nhds Filter.Eventually.prod_inr_nhds
theorem Filter.Eventually.prod_mk_nhds {px : X → Prop} {x} (hx : ∀ᶠ x in 𝓝 x, px x) {py : Y → Prop}
{y} (hy : ∀ᶠ y in 𝓝 y, py y) : ∀ᶠ p in 𝓝 (x, y), px (p : X × Y).1 ∧ py p.2 :=
(hx.prod_inl_nhds y).and (hy.prod_inr_nhds x)
#align filter.eventually.prod_mk_nhds Filter.Eventually.prod_mk_nhds
theorem continuous_swap : Continuous (Prod.swap : X × Y → Y × X) :=
continuous_snd.prod_mk continuous_fst
#align continuous_swap continuous_swap
lemma isClosedMap_swap : IsClosedMap (Prod.swap : X × Y → Y × X) := fun s hs ↦ by
rw [image_swap_eq_preimage_swap]
exact hs.preimage continuous_swap
theorem Continuous.uncurry_left {f : X → Y → Z} (x : X) (h : Continuous (uncurry f)) :
Continuous (f x) :=
h.comp (Continuous.Prod.mk _)
#align continuous_uncurry_left Continuous.uncurry_left
theorem Continuous.uncurry_right {f : X → Y → Z} (y : Y) (h : Continuous (uncurry f)) :
Continuous fun a => f a y :=
h.comp (Continuous.Prod.mk_left _)
#align continuous_uncurry_right Continuous.uncurry_right
-- 2024-03-09
@[deprecated] alias continuous_uncurry_left := Continuous.uncurry_left
@[deprecated] alias continuous_uncurry_right := Continuous.uncurry_right
theorem continuous_curry {g : X × Y → Z} (x : X) (h : Continuous g) : Continuous (curry g x) :=
Continuous.uncurry_left x h
#align continuous_curry continuous_curry
theorem IsOpen.prod {s : Set X} {t : Set Y} (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ×ˢ t) :=
(hs.preimage continuous_fst).inter (ht.preimage continuous_snd)
#align is_open.prod IsOpen.prod
-- Porting note (#11215): TODO: Lean fails to find `t₁` and `t₂` by unification
theorem nhds_prod_eq {x : X} {y : Y} : 𝓝 (x, y) = 𝓝 x ×ˢ 𝓝 y := by
dsimp only [SProd.sprod]
rw [Filter.prod, instTopologicalSpaceProd, nhds_inf (t₁ := TopologicalSpace.induced Prod.fst _)
(t₂ := TopologicalSpace.induced Prod.snd _), nhds_induced, nhds_induced]
#align nhds_prod_eq nhds_prod_eq
-- Porting note: moved from `Topology.ContinuousOn`
theorem nhdsWithin_prod_eq (x : X) (y : Y) (s : Set X) (t : Set Y) :
𝓝[s ×ˢ t] (x, y) = 𝓝[s] x ×ˢ 𝓝[t] y := by
simp only [nhdsWithin, nhds_prod_eq, ← prod_inf_prod, prod_principal_principal]
#align nhds_within_prod_eq nhdsWithin_prod_eq
#noalign continuous_uncurry_of_discrete_topology
theorem mem_nhds_prod_iff {x : X} {y : Y} {s : Set (X × Y)} :
s ∈ 𝓝 (x, y) ↔ ∃ u ∈ 𝓝 x, ∃ v ∈ 𝓝 y, u ×ˢ v ⊆ s := by rw [nhds_prod_eq, mem_prod_iff]
#align mem_nhds_prod_iff mem_nhds_prod_iff
theorem mem_nhdsWithin_prod_iff {x : X} {y : Y} {s : Set (X × Y)} {tx : Set X} {ty : Set Y} :
s ∈ 𝓝[tx ×ˢ ty] (x, y) ↔ ∃ u ∈ 𝓝[tx] x, ∃ v ∈ 𝓝[ty] y, u ×ˢ v ⊆ s := by
rw [nhdsWithin_prod_eq, mem_prod_iff]
-- Porting note: moved up
theorem Filter.HasBasis.prod_nhds {ιX ιY : Type*} {px : ιX → Prop} {py : ιY → Prop}
{sx : ιX → Set X} {sy : ιY → Set Y} {x : X} {y : Y} (hx : (𝓝 x).HasBasis px sx)
(hy : (𝓝 y).HasBasis py sy) :
(𝓝 (x, y)).HasBasis (fun i : ιX × ιY => px i.1 ∧ py i.2) fun i => sx i.1 ×ˢ sy i.2 := by
rw [nhds_prod_eq]
exact hx.prod hy
#align filter.has_basis.prod_nhds Filter.HasBasis.prod_nhds
-- Porting note: moved up
theorem Filter.HasBasis.prod_nhds' {ιX ιY : Type*} {pX : ιX → Prop} {pY : ιY → Prop}
{sx : ιX → Set X} {sy : ιY → Set Y} {p : X × Y} (hx : (𝓝 p.1).HasBasis pX sx)
(hy : (𝓝 p.2).HasBasis pY sy) :
(𝓝 p).HasBasis (fun i : ιX × ιY => pX i.1 ∧ pY i.2) fun i => sx i.1 ×ˢ sy i.2 :=
hx.prod_nhds hy
#align filter.has_basis.prod_nhds' Filter.HasBasis.prod_nhds'
theorem mem_nhds_prod_iff' {x : X} {y : Y} {s : Set (X × Y)} :
s ∈ 𝓝 (x, y) ↔ ∃ u v, IsOpen u ∧ x ∈ u ∧ IsOpen v ∧ y ∈ v ∧ u ×ˢ v ⊆ s :=
((nhds_basis_opens x).prod_nhds (nhds_basis_opens y)).mem_iff.trans <| by
simp only [Prod.exists, and_comm, and_assoc, and_left_comm]
#align mem_nhds_prod_iff' mem_nhds_prod_iff'
theorem Prod.tendsto_iff {X} (seq : X → Y × Z) {f : Filter X} (p : Y × Z) :
Tendsto seq f (𝓝 p) ↔
Tendsto (fun n => (seq n).fst) f (𝓝 p.fst) ∧ Tendsto (fun n => (seq n).snd) f (𝓝 p.snd) := by
rw [nhds_prod_eq, Filter.tendsto_prod_iff']
#align prod.tendsto_iff Prod.tendsto_iff
instance [DiscreteTopology X] [DiscreteTopology Y] : DiscreteTopology (X × Y) :=
discreteTopology_iff_nhds.2 fun (a, b) => by
rw [nhds_prod_eq, nhds_discrete X, nhds_discrete Y, prod_pure_pure]
theorem prod_mem_nhds_iff {s : Set X} {t : Set Y} {x : X} {y : Y} :
s ×ˢ t ∈ 𝓝 (x, y) ↔ s ∈ 𝓝 x ∧ t ∈ 𝓝 y := by rw [nhds_prod_eq, prod_mem_prod_iff]
#align prod_mem_nhds_iff prod_mem_nhds_iff
theorem prod_mem_nhds {s : Set X} {t : Set Y} {x : X} {y : Y} (hx : s ∈ 𝓝 x) (hy : t ∈ 𝓝 y) :
s ×ˢ t ∈ 𝓝 (x, y) :=
prod_mem_nhds_iff.2 ⟨hx, hy⟩
#align prod_mem_nhds prod_mem_nhds
theorem isOpen_setOf_disjoint_nhds_nhds : IsOpen { p : X × X | Disjoint (𝓝 p.1) (𝓝 p.2) } := by
simp only [isOpen_iff_mem_nhds, Prod.forall, mem_setOf_eq]
intro x y h
obtain ⟨U, hU, V, hV, hd⟩ := ((nhds_basis_opens x).disjoint_iff (nhds_basis_opens y)).mp h
exact mem_nhds_prod_iff'.mpr ⟨U, V, hU.2, hU.1, hV.2, hV.1, fun ⟨x', y'⟩ ⟨hx', hy'⟩ =>
disjoint_of_disjoint_of_mem hd (hU.2.mem_nhds hx') (hV.2.mem_nhds hy')⟩
#align is_open_set_of_disjoint_nhds_nhds isOpen_setOf_disjoint_nhds_nhds
theorem Filter.Eventually.prod_nhds {p : X → Prop} {q : Y → Prop} {x : X} {y : Y}
(hx : ∀ᶠ x in 𝓝 x, p x) (hy : ∀ᶠ y in 𝓝 y, q y) : ∀ᶠ z : X × Y in 𝓝 (x, y), p z.1 ∧ q z.2 :=
prod_mem_nhds hx hy
#align filter.eventually.prod_nhds Filter.Eventually.prod_nhds
theorem nhds_swap (x : X) (y : Y) : 𝓝 (x, y) = (𝓝 (y, x)).map Prod.swap := by
rw [nhds_prod_eq, Filter.prod_comm, nhds_prod_eq]; rfl
#align nhds_swap nhds_swap
theorem Filter.Tendsto.prod_mk_nhds {γ} {x : X} {y : Y} {f : Filter γ} {mx : γ → X} {my : γ → Y}
(hx : Tendsto mx f (𝓝 x)) (hy : Tendsto my f (𝓝 y)) :
Tendsto (fun c => (mx c, my c)) f (𝓝 (x, y)) := by
rw [nhds_prod_eq]; exact Filter.Tendsto.prod_mk hx hy
#align filter.tendsto.prod_mk_nhds Filter.Tendsto.prod_mk_nhds
theorem Filter.Eventually.curry_nhds {p : X × Y → Prop} {x : X} {y : Y}
(h : ∀ᶠ x in 𝓝 (x, y), p x) : ∀ᶠ x' in 𝓝 x, ∀ᶠ y' in 𝓝 y, p (x', y') := by
rw [nhds_prod_eq] at h
exact h.curry
#align filter.eventually.curry_nhds Filter.Eventually.curry_nhds
@[fun_prop]
theorem ContinuousAt.prod {f : X → Y} {g : X → Z} {x : X} (hf : ContinuousAt f x)
(hg : ContinuousAt g x) : ContinuousAt (fun x => (f x, g x)) x :=
hf.prod_mk_nhds hg
#align continuous_at.prod ContinuousAt.prod
theorem ContinuousAt.prod_map {f : X → Z} {g : Y → W} {p : X × Y} (hf : ContinuousAt f p.fst)
(hg : ContinuousAt g p.snd) : ContinuousAt (fun p : X × Y => (f p.1, g p.2)) p :=
hf.fst''.prod hg.snd''
#align continuous_at.prod_map ContinuousAt.prod_map
theorem ContinuousAt.prod_map' {f : X → Z} {g : Y → W} {x : X} {y : Y} (hf : ContinuousAt f x)
(hg : ContinuousAt g y) : ContinuousAt (fun p : X × Y => (f p.1, g p.2)) (x, y) :=
hf.fst'.prod hg.snd'
#align continuous_at.prod_map' ContinuousAt.prod_map'
theorem ContinuousAt.comp₂ {f : Y × Z → W} {g : X → Y} {h : X → Z} {x : X}
(hf : ContinuousAt f (g x, h x)) (hg : ContinuousAt g x) (hh : ContinuousAt h x) :
ContinuousAt (fun x ↦ f (g x, h x)) x :=
ContinuousAt.comp hf (hg.prod hh)
| Mathlib/Topology/Constructions.lean | 663 | 667 | theorem ContinuousAt.comp₂_of_eq {f : Y × Z → W} {g : X → Y} {h : X → Z} {x : X} {y : Y × Z}
(hf : ContinuousAt f y) (hg : ContinuousAt g x) (hh : ContinuousAt h x) (e : (g x, h x) = y) :
ContinuousAt (fun x ↦ f (g x, h x)) x := by |
rw [← e] at hf
exact hf.comp₂ hg hh
|
/-
Copyright (c) 2022 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.Polynomial.Mirror
import Mathlib.Analysis.Complex.Polynomial
#align_import data.polynomial.unit_trinomial from "leanprover-community/mathlib"@"302eab4f46abb63de520828de78c04cb0f9b5836"
/-!
# Unit Trinomials
This file defines irreducible trinomials and proves an irreducibility criterion.
## Main definitions
- `Polynomial.IsUnitTrinomial`
## Main results
- `Polynomial.IsUnitTrinomial.irreducible_of_coprime`: An irreducibility criterion for unit
trinomials.
-/
namespace Polynomial
open scoped Polynomial
open Finset
section Semiring
variable {R : Type*} [Semiring R] (k m n : ℕ) (u v w : R)
/-- Shorthand for a trinomial -/
noncomputable def trinomial :=
C u * X ^ k + C v * X ^ m + C w * X ^ n
#align polynomial.trinomial Polynomial.trinomial
theorem trinomial_def : trinomial k m n u v w = C u * X ^ k + C v * X ^ m + C w * X ^ n :=
rfl
#align polynomial.trinomial_def Polynomial.trinomial_def
variable {k m n u v w}
theorem trinomial_leading_coeff' (hkm : k < m) (hmn : m < n) :
(trinomial k m n u v w).coeff n = w := by
rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow,
if_neg (hkm.trans hmn).ne', if_neg hmn.ne', if_pos rfl, zero_add, zero_add]
#align polynomial.trinomial_leading_coeff' Polynomial.trinomial_leading_coeff'
theorem trinomial_middle_coeff (hkm : k < m) (hmn : m < n) :
(trinomial k m n u v w).coeff m = v := by
rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow,
if_neg hkm.ne', if_pos rfl, if_neg hmn.ne, zero_add, add_zero]
#align polynomial.trinomial_middle_coeff Polynomial.trinomial_middle_coeff
theorem trinomial_trailing_coeff' (hkm : k < m) (hmn : m < n) :
(trinomial k m n u v w).coeff k = u := by
rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow,
if_pos rfl, if_neg hkm.ne, if_neg (hkm.trans hmn).ne, add_zero, add_zero]
#align polynomial.trinomial_trailing_coeff' Polynomial.trinomial_trailing_coeff'
theorem trinomial_natDegree (hkm : k < m) (hmn : m < n) (hw : w ≠ 0) :
(trinomial k m n u v w).natDegree = n := by
refine
natDegree_eq_of_degree_eq_some
((Finset.sup_le fun i h => ?_).antisymm <|
le_degree_of_ne_zero <| by rwa [trinomial_leading_coeff' hkm hmn])
replace h := support_trinomial' k m n u v w h
rw [mem_insert, mem_insert, mem_singleton] at h
rcases h with (rfl | rfl | rfl)
· exact WithBot.coe_le_coe.mpr (hkm.trans hmn).le
· exact WithBot.coe_le_coe.mpr hmn.le
· exact le_rfl
#align polynomial.trinomial_nat_degree Polynomial.trinomial_natDegree
theorem trinomial_natTrailingDegree (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) :
(trinomial k m n u v w).natTrailingDegree = k := by
refine
natTrailingDegree_eq_of_trailingDegree_eq_some
((Finset.le_inf fun i h => ?_).antisymm <|
trailingDegree_le_of_ne_zero <| by rwa [trinomial_trailing_coeff' hkm hmn]).symm
replace h := support_trinomial' k m n u v w h
rw [mem_insert, mem_insert, mem_singleton] at h
rcases h with (rfl | rfl | rfl)
· exact le_rfl
· exact WithTop.coe_le_coe.mpr hkm.le
· exact WithTop.coe_le_coe.mpr (hkm.trans hmn).le
#align polynomial.trinomial_nat_trailing_degree Polynomial.trinomial_natTrailingDegree
theorem trinomial_leadingCoeff (hkm : k < m) (hmn : m < n) (hw : w ≠ 0) :
(trinomial k m n u v w).leadingCoeff = w := by
rw [leadingCoeff, trinomial_natDegree hkm hmn hw, trinomial_leading_coeff' hkm hmn]
#align polynomial.trinomial_leading_coeff Polynomial.trinomial_leadingCoeff
theorem trinomial_trailingCoeff (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) :
(trinomial k m n u v w).trailingCoeff = u := by
rw [trailingCoeff, trinomial_natTrailingDegree hkm hmn hu, trinomial_trailing_coeff' hkm hmn]
#align polynomial.trinomial_trailing_coeff Polynomial.trinomial_trailingCoeff
theorem trinomial_monic (hkm : k < m) (hmn : m < n) : (trinomial k m n u v 1).Monic := by
nontriviality R
exact trinomial_leadingCoeff hkm hmn one_ne_zero
#align polynomial.trinomial_monic Polynomial.trinomial_monic
theorem trinomial_mirror (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) (hw : w ≠ 0) :
(trinomial k m n u v w).mirror = trinomial k (n - m + k) n w v u := by
rw [mirror, trinomial_natTrailingDegree hkm hmn hu, reverse, trinomial_natDegree hkm hmn hw,
trinomial_def, reflect_add, reflect_add, reflect_C_mul_X_pow, reflect_C_mul_X_pow,
reflect_C_mul_X_pow, revAt_le (hkm.trans hmn).le, revAt_le hmn.le, revAt_le le_rfl, add_mul,
add_mul, mul_assoc, mul_assoc, mul_assoc, ← pow_add, ← pow_add, ← pow_add,
Nat.sub_add_cancel (hkm.trans hmn).le, Nat.sub_self, zero_add, add_comm, add_comm (C u * X ^ n),
← add_assoc, ← trinomial_def]
#align polynomial.trinomial_mirror Polynomial.trinomial_mirror
theorem trinomial_support (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) (hv : v ≠ 0) (hw : w ≠ 0) :
(trinomial k m n u v w).support = {k, m, n} :=
support_trinomial hkm hmn hu hv hw
#align polynomial.trinomial_support Polynomial.trinomial_support
end Semiring
variable (p q : ℤ[X])
/-- A unit trinomial is a trinomial with unit coefficients. -/
def IsUnitTrinomial :=
∃ (k m n : ℕ) (_ : k < m) (_ : m < n) (u v w : Units ℤ), p = trinomial k m n (u : ℤ) v w
#align polynomial.is_unit_trinomial Polynomial.IsUnitTrinomial
variable {p q}
namespace IsUnitTrinomial
theorem not_isUnit (hp : p.IsUnitTrinomial) : ¬IsUnit p := by
obtain ⟨k, m, n, hkm, hmn, u, v, w, rfl⟩ := hp
exact fun h =>
ne_zero_of_lt hmn
((trinomial_natDegree hkm hmn w.ne_zero).symm.trans
(natDegree_eq_of_degree_eq_some (degree_eq_zero_of_isUnit h)))
#align polynomial.is_unit_trinomial.not_is_unit Polynomial.IsUnitTrinomial.not_isUnit
theorem card_support_eq_three (hp : p.IsUnitTrinomial) : p.support.card = 3 := by
obtain ⟨k, m, n, hkm, hmn, u, v, w, rfl⟩ := hp
exact card_support_trinomial hkm hmn u.ne_zero v.ne_zero w.ne_zero
#align polynomial.is_unit_trinomial.card_support_eq_three Polynomial.IsUnitTrinomial.card_support_eq_three
theorem ne_zero (hp : p.IsUnitTrinomial) : p ≠ 0 := by
rintro rfl
exact Nat.zero_ne_bit1 1 hp.card_support_eq_three
#align polynomial.is_unit_trinomial.ne_zero Polynomial.IsUnitTrinomial.ne_zero
theorem coeff_isUnit (hp : p.IsUnitTrinomial) {k : ℕ} (hk : k ∈ p.support) :
IsUnit (p.coeff k) := by
obtain ⟨k, m, n, hkm, hmn, u, v, w, rfl⟩ := hp
have := support_trinomial' k m n (u : ℤ) v w hk
rw [mem_insert, mem_insert, mem_singleton] at this
rcases this with (rfl | rfl | rfl)
· refine ⟨u, by rw [trinomial_trailing_coeff' hkm hmn]⟩
· refine ⟨v, by rw [trinomial_middle_coeff hkm hmn]⟩
· refine ⟨w, by rw [trinomial_leading_coeff' hkm hmn]⟩
#align polynomial.is_unit_trinomial.coeff_is_unit Polynomial.IsUnitTrinomial.coeff_isUnit
theorem leadingCoeff_isUnit (hp : p.IsUnitTrinomial) : IsUnit p.leadingCoeff :=
hp.coeff_isUnit (natDegree_mem_support_of_nonzero hp.ne_zero)
#align polynomial.is_unit_trinomial.leading_coeff_is_unit Polynomial.IsUnitTrinomial.leadingCoeff_isUnit
theorem trailingCoeff_isUnit (hp : p.IsUnitTrinomial) : IsUnit p.trailingCoeff :=
hp.coeff_isUnit (natTrailingDegree_mem_support_of_nonzero hp.ne_zero)
#align polynomial.is_unit_trinomial.trailing_coeff_is_unit Polynomial.IsUnitTrinomial.trailingCoeff_isUnit
end IsUnitTrinomial
| Mathlib/Algebra/Polynomial/UnitTrinomial.lean | 177 | 190 | theorem isUnitTrinomial_iff :
p.IsUnitTrinomial ↔ p.support.card = 3 ∧ ∀ k ∈ p.support, IsUnit (p.coeff k) := by |
refine ⟨fun hp => ⟨hp.card_support_eq_three, fun k => hp.coeff_isUnit⟩, fun hp => ?_⟩
obtain ⟨k, m, n, hkm, hmn, x, y, z, hx, hy, hz, rfl⟩ := card_support_eq_three.mp hp.1
rw [support_trinomial hkm hmn hx hy hz] at hp
replace hx := hp.2 k (mem_insert_self k {m, n})
replace hy := hp.2 m (mem_insert_of_mem (mem_insert_self m {n}))
replace hz := hp.2 n (mem_insert_of_mem (mem_insert_of_mem (mem_singleton_self n)))
simp_rw [coeff_add, coeff_C_mul, coeff_X_pow_self, mul_one, coeff_X_pow] at hx hy hz
rw [if_neg hkm.ne, if_neg (hkm.trans hmn).ne] at hx
rw [if_neg hkm.ne', if_neg hmn.ne] at hy
rw [if_neg (hkm.trans hmn).ne', if_neg hmn.ne'] at hz
simp_rw [mul_zero, zero_add, add_zero] at hx hy hz
exact ⟨k, m, n, hkm, hmn, hx.unit, hy.unit, hz.unit, rfl⟩
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Polynomial.Eval
#align_import data.polynomial.degree.lemmas from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f"
/-!
# Theory of degrees of polynomials
Some of the main results include
- `natDegree_comp_le` : The degree of the composition is at most the product of degrees
-/
noncomputable section
open Polynomial
open Finsupp Finset
namespace Polynomial
universe u v w
variable {R : Type u} {S : Type v} {ι : Type w} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section Degree
theorem natDegree_comp_le : natDegree (p.comp q) ≤ natDegree p * natDegree q :=
letI := Classical.decEq R
if h0 : p.comp q = 0 then by rw [h0, natDegree_zero]; exact Nat.zero_le _
else
WithBot.coe_le_coe.1 <|
calc
↑(natDegree (p.comp q)) = degree (p.comp q) := (degree_eq_natDegree h0).symm
_ = _ := congr_arg degree comp_eq_sum_left
_ ≤ _ := degree_sum_le _ _
_ ≤ _ :=
Finset.sup_le fun n hn =>
calc
degree (C (coeff p n) * q ^ n) ≤ degree (C (coeff p n)) + degree (q ^ n) :=
degree_mul_le _ _
_ ≤ natDegree (C (coeff p n)) + n • degree q :=
(add_le_add degree_le_natDegree (degree_pow_le _ _))
_ ≤ natDegree (C (coeff p n)) + n • ↑(natDegree q) :=
(add_le_add_left (nsmul_le_nsmul_right (@degree_le_natDegree _ _ q) n) _)
_ = (n * natDegree q : ℕ) := by
rw [natDegree_C, Nat.cast_zero, zero_add, nsmul_eq_mul];
simp
_ ≤ (natDegree p * natDegree q : ℕ) :=
WithBot.coe_le_coe.2 <|
mul_le_mul_of_nonneg_right (le_natDegree_of_ne_zero (mem_support_iff.1 hn))
(Nat.zero_le _)
#align polynomial.nat_degree_comp_le Polynomial.natDegree_comp_le
theorem degree_pos_of_root {p : R[X]} (hp : p ≠ 0) (h : IsRoot p a) : 0 < degree p :=
lt_of_not_ge fun hlt => by
have := eq_C_of_degree_le_zero hlt
rw [IsRoot, this, eval_C] at h
simp only [h, RingHom.map_zero] at this
exact hp this
#align polynomial.degree_pos_of_root Polynomial.degree_pos_of_root
theorem natDegree_le_iff_coeff_eq_zero : p.natDegree ≤ n ↔ ∀ N : ℕ, n < N → p.coeff N = 0 := by
simp_rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero, Nat.cast_lt]
#align polynomial.nat_degree_le_iff_coeff_eq_zero Polynomial.natDegree_le_iff_coeff_eq_zero
theorem natDegree_add_le_iff_left {n : ℕ} (p q : R[X]) (qn : q.natDegree ≤ n) :
(p + q).natDegree ≤ n ↔ p.natDegree ≤ n := by
refine ⟨fun h => ?_, fun h => natDegree_add_le_of_degree_le h qn⟩
refine natDegree_le_iff_coeff_eq_zero.mpr fun m hm => ?_
convert natDegree_le_iff_coeff_eq_zero.mp h m hm using 1
rw [coeff_add, natDegree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero]
#align polynomial.nat_degree_add_le_iff_left Polynomial.natDegree_add_le_iff_left
theorem natDegree_add_le_iff_right {n : ℕ} (p q : R[X]) (pn : p.natDegree ≤ n) :
(p + q).natDegree ≤ n ↔ q.natDegree ≤ n := by
rw [add_comm]
exact natDegree_add_le_iff_left _ _ pn
#align polynomial.nat_degree_add_le_iff_right Polynomial.natDegree_add_le_iff_right
theorem natDegree_C_mul_le (a : R) (f : R[X]) : (C a * f).natDegree ≤ f.natDegree :=
calc
(C a * f).natDegree ≤ (C a).natDegree + f.natDegree := natDegree_mul_le
_ = 0 + f.natDegree := by rw [natDegree_C a]
_ = f.natDegree := zero_add _
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_C_mul_le Polynomial.natDegree_C_mul_le
theorem natDegree_mul_C_le (f : R[X]) (a : R) : (f * C a).natDegree ≤ f.natDegree :=
calc
(f * C a).natDegree ≤ f.natDegree + (C a).natDegree := natDegree_mul_le
_ = f.natDegree + 0 := by rw [natDegree_C a]
_ = f.natDegree := add_zero _
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_mul_C_le Polynomial.natDegree_mul_C_le
theorem eq_natDegree_of_le_mem_support (pn : p.natDegree ≤ n) (ns : n ∈ p.support) :
p.natDegree = n :=
le_antisymm pn (le_natDegree_of_mem_supp _ ns)
#align polynomial.eq_nat_degree_of_le_mem_support Polynomial.eq_natDegree_of_le_mem_support
theorem natDegree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) :
(C a * p).natDegree = p.natDegree :=
le_antisymm (natDegree_C_mul_le a p)
(calc
p.natDegree = (1 * p).natDegree := by nth_rw 1 [← one_mul p]
_ = (C ai * (C a * p)).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc]
_ ≤ (C a * p).natDegree := natDegree_C_mul_le ai (C a * p))
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_C_mul_eq_of_mul_eq_one Polynomial.natDegree_C_mul_eq_of_mul_eq_one
theorem natDegree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) :
(p * C a).natDegree = p.natDegree :=
le_antisymm (natDegree_mul_C_le p a)
(calc
p.natDegree = (p * 1).natDegree := by nth_rw 1 [← mul_one p]
_ = (p * C a * C ai).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc]
_ ≤ (p * C a).natDegree := natDegree_mul_C_le (p * C a) ai)
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_mul_C_eq_of_mul_eq_one Polynomial.natDegree_mul_C_eq_of_mul_eq_one
/-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero`
force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`.
-/
theorem natDegree_mul_C_eq_of_mul_ne_zero (h : p.leadingCoeff * a ≠ 0) :
(p * C a).natDegree = p.natDegree := by
refine eq_natDegree_of_le_mem_support (natDegree_mul_C_le p a) ?_
refine mem_support_iff.mpr ?_
rwa [coeff_mul_C]
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_mul_C_eq_of_mul_ne_zero Polynomial.natDegree_mul_C_eq_of_mul_ne_zero
/-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero`
force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`.
-/
theorem natDegree_C_mul_eq_of_mul_ne_zero (h : a * p.leadingCoeff ≠ 0) :
(C a * p).natDegree = p.natDegree := by
refine eq_natDegree_of_le_mem_support (natDegree_C_mul_le a p) ?_
refine mem_support_iff.mpr ?_
rwa [coeff_C_mul]
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_C_mul_eq_of_mul_ne_zero Polynomial.natDegree_C_mul_eq_of_mul_ne_zero
theorem natDegree_add_coeff_mul (f g : R[X]) :
(f * g).coeff (f.natDegree + g.natDegree) = f.coeff f.natDegree * g.coeff g.natDegree := by
simp only [coeff_natDegree, coeff_mul_degree_add_degree]
#align polynomial.nat_degree_add_coeff_mul Polynomial.natDegree_add_coeff_mul
theorem natDegree_lt_coeff_mul (h : p.natDegree + q.natDegree < m + n) :
(p * q).coeff (m + n) = 0 :=
coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt h)
#align polynomial.nat_degree_lt_coeff_mul Polynomial.natDegree_lt_coeff_mul
theorem coeff_mul_of_natDegree_le (pm : p.natDegree ≤ m) (qn : q.natDegree ≤ n) :
(p * q).coeff (m + n) = p.coeff m * q.coeff n := by
simp_rw [← Polynomial.toFinsupp_apply, toFinsupp_mul]
refine AddMonoidAlgebra.apply_add_of_supDegree_le ?_ Function.injective_id ?_ ?_
· simp
· rwa [supDegree_eq_natDegree, id_eq]
· rwa [supDegree_eq_natDegree, id_eq]
#align polynomial.coeff_mul_of_nat_degree_le Polynomial.coeff_mul_of_natDegree_le
theorem coeff_pow_of_natDegree_le (pn : p.natDegree ≤ n) :
(p ^ m).coeff (m * n) = p.coeff n ^ m := by
induction' m with m hm
· simp
· rw [pow_succ, pow_succ, ← hm, Nat.succ_mul, coeff_mul_of_natDegree_le _ pn]
refine natDegree_pow_le.trans (le_trans ?_ (le_refl _))
exact mul_le_mul_of_nonneg_left pn m.zero_le
#align polynomial.coeff_pow_of_nat_degree_le Polynomial.coeff_pow_of_natDegree_le
theorem coeff_pow_eq_ite_of_natDegree_le_of_le {o : ℕ}
(pn : natDegree p ≤ n) (mno : m * n ≤ o) :
coeff (p ^ m) o = if o = m * n then (coeff p n) ^ m else 0 := by
rcases eq_or_ne o (m * n) with rfl | h
· simpa only [ite_true] using coeff_pow_of_natDegree_le pn
· simpa only [h, ite_false] using coeff_eq_zero_of_natDegree_lt <|
lt_of_le_of_lt (natDegree_pow_le_of_le m pn) (lt_of_le_of_ne mno h.symm)
theorem coeff_add_eq_left_of_lt (qn : q.natDegree < n) : (p + q).coeff n = p.coeff n :=
(coeff_add _ _ _).trans <|
(congr_arg _ <| coeff_eq_zero_of_natDegree_lt <| qn).trans <| add_zero _
#align polynomial.coeff_add_eq_left_of_lt Polynomial.coeff_add_eq_left_of_lt
theorem coeff_add_eq_right_of_lt (pn : p.natDegree < n) : (p + q).coeff n = q.coeff n := by
rw [add_comm]
exact coeff_add_eq_left_of_lt pn
#align polynomial.coeff_add_eq_right_of_lt Polynomial.coeff_add_eq_right_of_lt
theorem degree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S)
(h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on degree ∘ f)) :
degree (s.sum f) = s.sup fun i => degree (f i) := by
classical
induction' s using Finset.induction_on with x s hx IH
· simp
· simp only [hx, Finset.sum_insert, not_false_iff, Finset.sup_insert]
specialize IH (h.mono fun _ => by simp (config := { contextual := true }))
rcases lt_trichotomy (degree (f x)) (degree (s.sum f)) with (H | H | H)
· rw [← IH, sup_eq_right.mpr H.le, degree_add_eq_right_of_degree_lt H]
· rcases s.eq_empty_or_nonempty with (rfl | hs)
· simp
obtain ⟨y, hy, hy'⟩ := Finset.exists_mem_eq_sup s hs fun i => degree (f i)
rw [IH, hy'] at H
by_cases hx0 : f x = 0
· simp [hx0, IH]
have hy0 : f y ≠ 0 := by
contrapose! H
simpa [H, degree_eq_bot] using hx0
refine absurd H (h ?_ ?_ fun H => hx ?_)
· simp [hx0]
· simp [hy, hy0]
· exact H.symm ▸ hy
· rw [← IH, sup_eq_left.mpr H.le, degree_add_eq_left_of_degree_lt H]
#align polynomial.degree_sum_eq_of_disjoint Polynomial.degree_sum_eq_of_disjoint
theorem natDegree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S)
(h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on natDegree ∘ f)) :
natDegree (s.sum f) = s.sup fun i => natDegree (f i) := by
by_cases H : ∃ x ∈ s, f x ≠ 0
· obtain ⟨x, hx, hx'⟩ := H
have hs : s.Nonempty := ⟨x, hx⟩
refine natDegree_eq_of_degree_eq_some ?_
rw [degree_sum_eq_of_disjoint]
· rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs,
Nat.cast_withBot, Finset.coe_sup' hs, ←
Finset.sup'_eq_sup hs]
refine le_antisymm ?_ ?_
· rw [Finset.sup'_le_iff]
intro b hb
by_cases hb' : f b = 0
· simpa [hb'] using hs
rw [degree_eq_natDegree hb', Nat.cast_withBot]
exact Finset.le_sup' (fun i : S => (natDegree (f i) : WithBot ℕ)) hb
· rw [Finset.sup'_le_iff]
intro b hb
simp only [Finset.le_sup'_iff, exists_prop, Function.comp_apply]
by_cases hb' : f b = 0
· refine ⟨x, hx, ?_⟩
contrapose! hx'
simpa [← Nat.cast_withBot, hb', degree_eq_bot] using hx'
exact ⟨b, hb, (degree_eq_natDegree hb').ge⟩
· exact h.imp fun x y hxy hxy' => hxy (natDegree_eq_of_degree_eq hxy')
· push_neg at H
rw [Finset.sum_eq_zero H, natDegree_zero, eq_comm, show 0 = ⊥ from rfl, Finset.sup_eq_bot_iff]
intro x hx
simp [H x hx]
#align polynomial.nat_degree_sum_eq_of_disjoint Polynomial.natDegree_sum_eq_of_disjoint
set_option linter.deprecated false in
theorem natDegree_bit0 (a : R[X]) : (bit0 a).natDegree ≤ a.natDegree :=
(natDegree_add_le _ _).trans (max_self _).le
#align polynomial.nat_degree_bit0 Polynomial.natDegree_bit0
set_option linter.deprecated false in
theorem natDegree_bit1 (a : R[X]) : (bit1 a).natDegree ≤ a.natDegree :=
(natDegree_add_le _ _).trans (by simp [natDegree_bit0])
#align polynomial.nat_degree_bit1 Polynomial.natDegree_bit1
variable [Semiring S]
theorem natDegree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S}
(hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < natDegree p :=
lt_of_not_ge fun hlt => by
have A : p = C (p.coeff 0) := eq_C_of_natDegree_le_zero hlt
rw [A, eval₂_C] at hz
simp only [inj (p.coeff 0) hz, RingHom.map_zero] at A
exact hp A
#align polynomial.nat_degree_pos_of_eval₂_root Polynomial.natDegree_pos_of_eval₂_root
theorem degree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S}
(hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < degree p :=
natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_eval₂_root hp f hz inj)
#align polynomial.degree_pos_of_eval₂_root Polynomial.degree_pos_of_eval₂_root
@[simp]
theorem coe_lt_degree {p : R[X]} {n : ℕ} : (n : WithBot ℕ) < degree p ↔ n < natDegree p := by
by_cases h : p = 0
· simp [h]
simp [degree_eq_natDegree h, Nat.cast_lt]
#align polynomial.coe_lt_degree Polynomial.coe_lt_degree
@[simp]
theorem degree_map_eq_iff {f : R →+* S} {p : Polynomial R} :
degree (map f p) = degree p ↔ f (leadingCoeff p) ≠ 0 ∨ p = 0 := by
rcases eq_or_ne p 0 with h|h
· simp [h]
simp only [h, or_false]
refine ⟨fun h2 ↦ ?_, degree_map_eq_of_leadingCoeff_ne_zero f⟩
have h3 : natDegree (map f p) = natDegree p := by simp_rw [natDegree, h2]
have h4 : map f p ≠ 0 := by
rwa [ne_eq, ← degree_eq_bot, h2, degree_eq_bot]
rwa [← coeff_natDegree, ← coeff_map, ← h3, coeff_natDegree, ne_eq, leadingCoeff_eq_zero]
@[simp]
theorem natDegree_map_eq_iff {f : R →+* S} {p : Polynomial R} :
natDegree (map f p) = natDegree p ↔ f (p.leadingCoeff) ≠ 0 ∨ natDegree p = 0 := by
rcases eq_or_ne (natDegree p) 0 with h|h
· simp_rw [h, ne_eq, or_true, iff_true, ← Nat.le_zero, ← h, natDegree_map_le f p]
have h2 : p ≠ 0 := by rintro rfl; simp at h
have h3 : degree p ≠ (0 : ℕ) := degree_ne_of_natDegree_ne h
simp_rw [h, or_false, natDegree, WithBot.unbot'_eq_unbot'_iff, degree_map_eq_iff]
simp [h, h2, h3] -- simp doesn't rewrite in the hypothesis for some reason
tauto
theorem natDegree_pos_of_nextCoeff_ne_zero (h : p.nextCoeff ≠ 0) : 0 < p.natDegree := by
rw [nextCoeff] at h
by_cases hpz : p.natDegree = 0
· simp_all only [ne_eq, zero_le, ite_true, not_true_eq_false]
· apply Nat.zero_lt_of_ne_zero hpz
end Degree
end Semiring
section Ring
variable [Ring R] {p q : R[X]}
theorem natDegree_sub : (p - q).natDegree = (q - p).natDegree := by rw [← natDegree_neg, neg_sub]
#align polynomial.nat_degree_sub Polynomial.natDegree_sub
theorem natDegree_sub_le_iff_left (qn : q.natDegree ≤ n) :
(p - q).natDegree ≤ n ↔ p.natDegree ≤ n := by
rw [← natDegree_neg] at qn
rw [sub_eq_add_neg, natDegree_add_le_iff_left _ _ qn]
#align polynomial.nat_degree_sub_le_iff_left Polynomial.natDegree_sub_le_iff_left
| Mathlib/Algebra/Polynomial/Degree/Lemmas.lean | 337 | 338 | theorem natDegree_sub_le_iff_right (pn : p.natDegree ≤ n) :
(p - q).natDegree ≤ n ↔ q.natDegree ≤ n := by | rwa [natDegree_sub, natDegree_sub_le_iff_left]
|
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Analysis.InnerProductSpace.Projection
import Mathlib.MeasureTheory.Function.ConditionalExpectation.Unique
import Mathlib.MeasureTheory.Function.L2Space
#align_import measure_theory.function.conditional_expectation.condexp_L2 from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e"
/-! # Conditional expectation in L2
This file contains one step of the construction of the conditional expectation, which is completed
in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the
full process.
We build the conditional expectation of an `L²` function, as an element of `L²`. This is the
orthogonal projection on the subspace of almost everywhere `m`-measurable functions.
## Main definitions
* `condexpL2`: Conditional expectation of a function in L2 with respect to a sigma-algebra: it is
the orthogonal projection on the subspace `lpMeas`.
## Implementation notes
Most of the results in this file are valid for a complete real normed space `F`.
However, some lemmas also use `𝕜 : RCLike`:
* `condexpL2` is defined only for an `InnerProductSpace` for now, and we use `𝕜` for its field.
* results about scalar multiplication are stated not only for `ℝ` but also for `𝕜` if we happen to
have `NormedSpace 𝕜 F`.
-/
set_option linter.uppercaseLean3 false
open TopologicalSpace Filter ContinuousLinearMap
open scoped ENNReal Topology MeasureTheory
namespace MeasureTheory
variable {α E E' F G G' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜]
-- 𝕜 for ℝ or ℂ
-- E for an inner product space
[NormedAddCommGroup E]
[InnerProductSpace 𝕜 E] [CompleteSpace E]
-- E' for an inner product space on which we compute integrals
[NormedAddCommGroup E']
[InnerProductSpace 𝕜 E'] [CompleteSpace E'] [NormedSpace ℝ E']
-- F for a Lp submodule
[NormedAddCommGroup F]
[NormedSpace 𝕜 F]
-- G for a Lp add_subgroup
[NormedAddCommGroup G]
-- G' for integrals on a Lp add_subgroup
[NormedAddCommGroup G']
[NormedSpace ℝ G'] [CompleteSpace G']
variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α}
local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y
local notation "⟪" x ", " y "⟫₂" => @inner 𝕜 (α →₂[μ] E) _ x y
-- Porting note: the argument `E` of `condexpL2` is not automatically filled in Lean 4.
-- To avoid typing `(E := _)` every time it is made explicit.
variable (E 𝕜)
/-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/
noncomputable def condexpL2 (hm : m ≤ m0) : (α →₂[μ] E) →L[𝕜] lpMeas E 𝕜 m 2 μ :=
@orthogonalProjection 𝕜 (α →₂[μ] E) _ _ _ (lpMeas E 𝕜 m 2 μ)
haveI : Fact (m ≤ m0) := ⟨hm⟩
inferInstance
#align measure_theory.condexp_L2 MeasureTheory.condexpL2
variable {E 𝕜}
theorem aeStronglyMeasurable'_condexpL2 (hm : m ≤ m0) (f : α →₂[μ] E) :
AEStronglyMeasurable' (β := E) m (condexpL2 E 𝕜 hm f) μ :=
lpMeas.aeStronglyMeasurable' _
#align measure_theory.ae_strongly_measurable'_condexp_L2 MeasureTheory.aeStronglyMeasurable'_condexpL2
theorem integrableOn_condexpL2_of_measure_ne_top (hm : m ≤ m0) (hμs : μ s ≠ ∞) (f : α →₂[μ] E) :
IntegrableOn (E := E) (condexpL2 E 𝕜 hm f) s μ :=
integrableOn_Lp_of_measure_ne_top (condexpL2 E 𝕜 hm f : α →₂[μ] E) fact_one_le_two_ennreal.elim
hμs
#align measure_theory.integrable_on_condexp_L2_of_measure_ne_top MeasureTheory.integrableOn_condexpL2_of_measure_ne_top
theorem integrable_condexpL2_of_isFiniteMeasure (hm : m ≤ m0) [IsFiniteMeasure μ] {f : α →₂[μ] E} :
Integrable (β := E) (condexpL2 E 𝕜 hm f) μ :=
integrableOn_univ.mp <| integrableOn_condexpL2_of_measure_ne_top hm (measure_ne_top _ _) f
#align measure_theory.integrable_condexp_L2_of_is_finite_measure MeasureTheory.integrable_condexpL2_of_isFiniteMeasure
theorem norm_condexpL2_le_one (hm : m ≤ m0) : ‖@condexpL2 α E 𝕜 _ _ _ _ _ _ μ hm‖ ≤ 1 :=
haveI : Fact (m ≤ m0) := ⟨hm⟩
orthogonalProjection_norm_le _
#align measure_theory.norm_condexp_L2_le_one MeasureTheory.norm_condexpL2_le_one
theorem norm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖condexpL2 E 𝕜 hm f‖ ≤ ‖f‖ :=
((@condexpL2 _ E 𝕜 _ _ _ _ _ _ μ hm).le_opNorm f).trans
(mul_le_of_le_one_left (norm_nonneg _) (norm_condexpL2_le_one hm))
#align measure_theory.norm_condexp_L2_le MeasureTheory.norm_condexpL2_le
theorem snorm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) :
snorm (F := E) (condexpL2 E 𝕜 hm f) 2 μ ≤ snorm f 2 μ := by
rw [lpMeas_coe, ← ENNReal.toReal_le_toReal (Lp.snorm_ne_top _) (Lp.snorm_ne_top _), ←
Lp.norm_def, ← Lp.norm_def, Submodule.norm_coe]
exact norm_condexpL2_le hm f
#align measure_theory.snorm_condexp_L2_le MeasureTheory.snorm_condexpL2_le
theorem norm_condexpL2_coe_le (hm : m ≤ m0) (f : α →₂[μ] E) :
‖(condexpL2 E 𝕜 hm f : α →₂[μ] E)‖ ≤ ‖f‖ := by
rw [Lp.norm_def, Lp.norm_def, ← lpMeas_coe]
refine (ENNReal.toReal_le_toReal ?_ (Lp.snorm_ne_top _)).mpr (snorm_condexpL2_le hm f)
exact Lp.snorm_ne_top _
#align measure_theory.norm_condexp_L2_coe_le MeasureTheory.norm_condexpL2_coe_le
theorem inner_condexpL2_left_eq_right (hm : m ≤ m0) {f g : α →₂[μ] E} :
⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, (condexpL2 E 𝕜 hm g : α →₂[μ] E)⟫₂ :=
haveI : Fact (m ≤ m0) := ⟨hm⟩
inner_orthogonalProjection_left_eq_right _ f g
#align measure_theory.inner_condexp_L2_left_eq_right MeasureTheory.inner_condexpL2_left_eq_right
theorem condexpL2_indicator_of_measurable (hm : m ≤ m0) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞)
(c : E) :
(condexpL2 E 𝕜 hm (indicatorConstLp 2 (hm s hs) hμs c) : α →₂[μ] E) =
indicatorConstLp 2 (hm s hs) hμs c := by
rw [condexpL2]
haveI : Fact (m ≤ m0) := ⟨hm⟩
have h_mem : indicatorConstLp 2 (hm s hs) hμs c ∈ lpMeas E 𝕜 m 2 μ :=
mem_lpMeas_indicatorConstLp hm hs hμs
let ind := (⟨indicatorConstLp 2 (hm s hs) hμs c, h_mem⟩ : lpMeas E 𝕜 m 2 μ)
have h_coe_ind : (ind : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := rfl
have h_orth_mem := orthogonalProjection_mem_subspace_eq_self ind
rw [← h_coe_ind, h_orth_mem]
#align measure_theory.condexp_L2_indicator_of_measurable MeasureTheory.condexpL2_indicator_of_measurable
theorem inner_condexpL2_eq_inner_fun (hm : m ≤ m0) (f g : α →₂[μ] E)
(hg : AEStronglyMeasurable' m g μ) :
⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, g⟫₂ := by
symm
rw [← sub_eq_zero, ← inner_sub_left, condexpL2]
simp only [mem_lpMeas_iff_aeStronglyMeasurable'.mpr hg, orthogonalProjection_inner_eq_zero f g]
#align measure_theory.inner_condexp_L2_eq_inner_fun MeasureTheory.inner_condexpL2_eq_inner_fun
section Real
variable {hm : m ≤ m0}
theorem integral_condexpL2_eq_of_fin_meas_real (f : Lp 𝕜 2 μ) (hs : MeasurableSet[m] s)
(hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = ∫ x in s, f x ∂μ := by
rw [← L2.inner_indicatorConstLp_one (𝕜 := 𝕜) (hm s hs) hμs f]
have h_eq_inner : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ =
inner (indicatorConstLp 2 (hm s hs) hμs (1 : 𝕜)) (condexpL2 𝕜 𝕜 hm f) := by
rw [L2.inner_indicatorConstLp_one (hm s hs) hμs]
rw [h_eq_inner, ← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable hm hs hμs]
#align measure_theory.integral_condexp_L2_eq_of_fin_meas_real MeasureTheory.integral_condexpL2_eq_of_fin_meas_real
theorem lintegral_nnnorm_condexpL2_le (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (f : Lp ℝ 2 μ) :
∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ ≤ ∫⁻ x in s, ‖f x‖₊ ∂μ := by
let h_meas := lpMeas.aeStronglyMeasurable' (condexpL2 ℝ ℝ hm f)
let g := h_meas.choose
have hg_meas : StronglyMeasurable[m] g := h_meas.choose_spec.1
have hg_eq : g =ᵐ[μ] condexpL2 ℝ ℝ hm f := h_meas.choose_spec.2.symm
have hg_eq_restrict : g =ᵐ[μ.restrict s] condexpL2 ℝ ℝ hm f := ae_restrict_of_ae hg_eq
have hg_nnnorm_eq : (fun x => (‖g x‖₊ : ℝ≥0∞)) =ᵐ[μ.restrict s] fun x =>
(‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ : ℝ≥0∞) := by
refine hg_eq_restrict.mono fun x hx => ?_
dsimp only
simp_rw [hx]
rw [lintegral_congr_ae hg_nnnorm_eq.symm]
refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq
hm (Lp.stronglyMeasurable f) ?_ ?_ ?_ ?_ hs hμs
· exact integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs
· exact hg_meas
· rw [IntegrableOn, integrable_congr hg_eq_restrict]
exact integrableOn_condexpL2_of_measure_ne_top hm hμs f
· intro t ht hμt
rw [← integral_condexpL2_eq_of_fin_meas_real f ht hμt.ne]
exact setIntegral_congr_ae (hm t ht) (hg_eq.mono fun x hx _ => hx)
#align measure_theory.lintegral_nnnorm_condexp_L2_le MeasureTheory.lintegral_nnnorm_condexpL2_le
theorem condexpL2_ae_eq_zero_of_ae_eq_zero (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) {f : Lp ℝ 2 μ}
(hf : f =ᵐ[μ.restrict s] 0) : condexpL2 ℝ ℝ hm f =ᵐ[μ.restrict s] (0 : α → ℝ) := by
suffices h_nnnorm_eq_zero : ∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ = 0 by
rw [lintegral_eq_zero_iff] at h_nnnorm_eq_zero
· refine h_nnnorm_eq_zero.mono fun x hx => ?_
dsimp only at hx
rw [Pi.zero_apply] at hx ⊢
· rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] at hx
· refine Measurable.coe_nnreal_ennreal (Measurable.nnnorm ?_)
rw [lpMeas_coe]
exact (Lp.stronglyMeasurable _).measurable
refine le_antisymm ?_ (zero_le _)
refine (lintegral_nnnorm_condexpL2_le hs hμs f).trans (le_of_eq ?_)
rw [lintegral_eq_zero_iff]
· refine hf.mono fun x hx => ?_
dsimp only
rw [hx]
simp
· exact (Lp.stronglyMeasurable _).ennnorm
#align measure_theory.condexp_L2_ae_eq_zero_of_ae_eq_zero MeasureTheory.condexpL2_ae_eq_zero_of_ae_eq_zero
theorem lintegral_nnnorm_condexpL2_indicator_le_real (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) :
∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ ≤ μ (s ∩ t) := by
refine (lintegral_nnnorm_condexpL2_le ht hμt _).trans (le_of_eq ?_)
have h_eq :
∫⁻ x in t, ‖(indicatorConstLp 2 hs hμs (1 : ℝ)) x‖₊ ∂μ =
∫⁻ x in t, s.indicator (fun _ => (1 : ℝ≥0∞)) x ∂μ := by
refine lintegral_congr_ae (ae_restrict_of_ae ?_)
refine (@indicatorConstLp_coeFn _ _ _ 2 _ _ _ hs hμs (1 : ℝ)).mono fun x hx => ?_
dsimp only
rw [hx]
classical
simp_rw [Set.indicator_apply]
split_ifs <;> simp
rw [h_eq, lintegral_indicator _ hs, lintegral_const, Measure.restrict_restrict hs]
simp only [one_mul, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply]
#align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le_real MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le_real
end Real
/-- `condexpL2` commutes with taking inner products with constants. See the lemma
`condexpL2_comp_continuousLinearMap` for a more general result about commuting with continuous
linear maps. -/
theorem condexpL2_const_inner (hm : m ≤ m0) (f : Lp E 2 μ) (c : E) :
condexpL2 𝕜 𝕜 hm (((Lp.memℒp f).const_inner c).toLp fun a => ⟪c, f a⟫) =ᵐ[μ]
fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ := by
rw [lpMeas_coe]
have h_mem_Lp : Memℒp (fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫) 2 μ := by
refine Memℒp.const_inner _ ?_; rw [lpMeas_coe]; exact Lp.memℒp _
have h_eq : h_mem_Lp.toLp _ =ᵐ[μ] fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ :=
h_mem_Lp.coeFn_toLp
refine EventuallyEq.trans ?_ h_eq
refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜 hm _ _ two_ne_zero ENNReal.coe_ne_top
(fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) ?_ ?_ ?_ ?_
· intro s _ hμs
rw [IntegrableOn, integrable_congr (ae_restrict_of_ae h_eq)]
exact (integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _).const_inner _
· intro s hs hμs
rw [← lpMeas_coe, integral_condexpL2_eq_of_fin_meas_real _ hs hμs.ne,
integral_congr_ae (ae_restrict_of_ae h_eq), lpMeas_coe, ←
L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 (↑(condexpL2 E 𝕜 hm f)) (hm s hs) c hμs.ne,
← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable _ hs,
L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 f (hm s hs) c hμs.ne,
setIntegral_congr_ae (hm s hs)
((Memℒp.coeFn_toLp ((Lp.memℒp f).const_inner c)).mono fun x hx _ => hx)]
· rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _
· refine AEStronglyMeasurable'.congr ?_ h_eq.symm
exact (lpMeas.aeStronglyMeasurable' _).const_inner _
#align measure_theory.condexp_L2_const_inner MeasureTheory.condexpL2_const_inner
/-- `condexpL2` verifies the equality of integrals defining the conditional expectation. -/
theorem integral_condexpL2_eq (hm : m ≤ m0) (f : Lp E' 2 μ) (hs : MeasurableSet[m] s)
(hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 E' 𝕜 hm f : α → E') x ∂μ = ∫ x in s, f x ∂μ := by
rw [← sub_eq_zero, lpMeas_coe, ←
integral_sub' (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)
(integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)]
refine integral_eq_zero_of_forall_integral_inner_eq_zero 𝕜 _ ?_ ?_
· rw [integrable_congr (ae_restrict_of_ae (Lp.coeFn_sub (↑(condexpL2 E' 𝕜 hm f)) f).symm)]
exact integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs
intro c
simp_rw [Pi.sub_apply, inner_sub_right]
rw [integral_sub
((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c)
((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c)]
have h_ae_eq_f := Memℒp.coeFn_toLp (E := 𝕜) ((Lp.memℒp f).const_inner c)
rw [← lpMeas_coe, sub_eq_zero, ←
setIntegral_congr_ae (hm s hs) ((condexpL2_const_inner hm f c).mono fun x hx _ => hx), ←
setIntegral_congr_ae (hm s hs) (h_ae_eq_f.mono fun x hx _ => hx)]
exact integral_condexpL2_eq_of_fin_meas_real _ hs hμs
#align measure_theory.integral_condexp_L2_eq MeasureTheory.integral_condexpL2_eq
variable {E'' 𝕜' : Type*} [RCLike 𝕜'] [NormedAddCommGroup E''] [InnerProductSpace 𝕜' E'']
[CompleteSpace E''] [NormedSpace ℝ E'']
variable (𝕜 𝕜')
theorem condexpL2_comp_continuousLinearMap (hm : m ≤ m0) (T : E' →L[ℝ] E'') (f : α →₂[μ] E') :
(condexpL2 E'' 𝕜' hm (T.compLp f) : α →₂[μ] E'') =ᵐ[μ]
T.compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E') := by
refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜' hm _ _ two_ne_zero ENNReal.coe_ne_top
(fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) (fun s _ hμs =>
integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne) ?_ ?_ ?_
· intro s hs hμs
rw [T.setIntegral_compLp _ (hm s hs),
T.integral_comp_comm
(integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne),
← lpMeas_coe, ← lpMeas_coe, integral_condexpL2_eq hm f hs hμs.ne,
integral_condexpL2_eq hm (T.compLp f) hs hμs.ne, T.setIntegral_compLp _ (hm s hs),
T.integral_comp_comm
(integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs.ne)]
· rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _
· have h_coe := T.coeFn_compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E')
rw [← EventuallyEq] at h_coe
refine AEStronglyMeasurable'.congr ?_ h_coe.symm
exact (lpMeas.aeStronglyMeasurable' (condexpL2 E' 𝕜 hm f)).continuous_comp T.continuous
#align measure_theory.condexp_L2_comp_continuous_linear_map MeasureTheory.condexpL2_comp_continuousLinearMap
variable {𝕜 𝕜'}
section CondexpL2Indicator
variable (𝕜)
theorem condexpL2_indicator_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(x : E') :
condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) =ᵐ[μ] fun a =>
(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ)) : α → ℝ) a • x := by
rw [indicatorConstLp_eq_toSpanSingleton_compLp hs hμs x]
have h_comp :=
condexpL2_comp_continuousLinearMap ℝ 𝕜 hm (toSpanSingleton ℝ x)
(indicatorConstLp 2 hs hμs (1 : ℝ))
rw [← lpMeas_coe] at h_comp
refine h_comp.trans ?_
exact (toSpanSingleton ℝ x).coeFn_compLp _
#align measure_theory.condexp_L2_indicator_ae_eq_smul MeasureTheory.condexpL2_indicator_ae_eq_smul
theorem condexpL2_indicator_eq_toSpanSingleton_comp (hm : m ≤ m0) (hs : MeasurableSet s)
(hμs : μ s ≠ ∞) (x : E') : (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α →₂[μ] E') =
(toSpanSingleton ℝ x).compLp (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) := by
ext1
rw [← lpMeas_coe]
refine (condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).trans ?_
have h_comp := (toSpanSingleton ℝ x).coeFn_compLp
(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α →₂[μ] ℝ)
rw [← EventuallyEq] at h_comp
refine EventuallyEq.trans ?_ h_comp.symm
filter_upwards with y using rfl
#align measure_theory.condexp_L2_indicator_eq_to_span_singleton_comp MeasureTheory.condexpL2_indicator_eq_toSpanSingleton_comp
variable {𝕜}
theorem set_lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s)
(hμs : μ s ≠ ∞) (x : E') {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) :
∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤
μ (s ∩ t) * ‖x‖₊ :=
calc
∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ =
∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ :=
set_lintegral_congr_fun (hm t ht)
((condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).mono fun a ha _ => by rw [ha])
_ = (∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by
simp_rw [nnnorm_smul, ENNReal.coe_mul]
rw [lintegral_mul_const, lpMeas_coe]
exact (Lp.stronglyMeasurable _).ennnorm
_ ≤ μ (s ∩ t) * ‖x‖₊ :=
mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs hμs ht hμt) _
#align measure_theory.set_lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.set_lintegral_nnnorm_condexpL2_indicator_le
theorem lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(x : E') [SigmaFinite (μ.trim hm)] :
∫⁻ a, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by
refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) ?_ fun t ht hμt => ?_
· rw [lpMeas_coe]
exact (Lp.aestronglyMeasurable _).ennnorm
refine (set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_
gcongr
apply Set.inter_subset_left
#align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le
/-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set
with finite measure is integrable. -/
theorem integrable_condexpL2_indicator (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') :
Integrable (β := E') (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x)) μ := by
refine integrable_of_forall_fin_meas_le' hm (μ s * ‖x‖₊)
(ENNReal.mul_lt_top hμs ENNReal.coe_ne_top) ?_ ?_
· rw [lpMeas_coe]; exact Lp.aestronglyMeasurable _
· refine fun t ht hμt =>
(set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_
gcongr
apply Set.inter_subset_left
#align measure_theory.integrable_condexp_L2_indicator MeasureTheory.integrable_condexpL2_indicator
end CondexpL2Indicator
section CondexpIndSMul
variable [NormedSpace ℝ G] {hm : m ≤ m0}
/-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/
noncomputable def condexpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) :
Lp G 2 μ :=
(toSpanSingleton ℝ x).compLpL 2 μ (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ)))
#align measure_theory.condexp_ind_smul MeasureTheory.condexpIndSMul
theorem aeStronglyMeasurable'_condexpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(x : G) : AEStronglyMeasurable' m (condexpIndSMul hm hs hμs x) μ := by
have h : AEStronglyMeasurable' m (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) μ :=
aeStronglyMeasurable'_condexpL2 _ _
rw [condexpIndSMul]
suffices AEStronglyMeasurable' m
(toSpanSingleton ℝ x ∘ condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) μ by
refine AEStronglyMeasurable'.congr this ?_
refine EventuallyEq.trans ?_ (coeFn_compLpL _ _).symm
rfl
exact AEStronglyMeasurable'.continuous_comp (toSpanSingleton ℝ x).continuous h
#align measure_theory.ae_strongly_measurable'_condexp_ind_smul MeasureTheory.aeStronglyMeasurable'_condexpIndSMul
theorem condexpIndSMul_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) :
condexpIndSMul hm hs hμs (x + y) = condexpIndSMul hm hs hμs x + condexpIndSMul hm hs hμs y := by
simp_rw [condexpIndSMul]; rw [toSpanSingleton_add, add_compLpL, add_apply]
#align measure_theory.condexp_ind_smul_add MeasureTheory.condexpIndSMul_add
theorem condexpIndSMul_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) :
condexpIndSMul hm hs hμs (c • x) = c • condexpIndSMul hm hs hμs x := by
simp_rw [condexpIndSMul]; rw [toSpanSingleton_smul, smul_compLpL, smul_apply]
#align measure_theory.condexp_ind_smul_smul MeasureTheory.condexpIndSMul_smul
theorem condexpIndSMul_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s)
(hμs : μ s ≠ ∞) (c : 𝕜) (x : F) :
condexpIndSMul hm hs hμs (c • x) = c • condexpIndSMul hm hs hμs x := by
rw [condexpIndSMul, condexpIndSMul, toSpanSingleton_smul',
(toSpanSingleton ℝ x).smul_compLpL c, smul_apply]
#align measure_theory.condexp_ind_smul_smul' MeasureTheory.condexpIndSMul_smul'
theorem condexpIndSMul_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) :
condexpIndSMul hm hs hμs x =ᵐ[μ] fun a =>
(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x :=
(toSpanSingleton ℝ x).coeFn_compLpL _
#align measure_theory.condexp_ind_smul_ae_eq_smul MeasureTheory.condexpIndSMul_ae_eq_smul
theorem set_lintegral_nnnorm_condexpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(x : G) {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) :
(∫⁻ a in t, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ) ≤ μ (s ∩ t) * ‖x‖₊ :=
calc
∫⁻ a in t, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ =
∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ :=
set_lintegral_congr_fun (hm t ht)
((condexpIndSMul_ae_eq_smul hm hs hμs x).mono fun a ha _ => by rw [ha])
_ = (∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by
simp_rw [nnnorm_smul, ENNReal.coe_mul]
rw [lintegral_mul_const, lpMeas_coe]
exact (Lp.stronglyMeasurable _).ennnorm
_ ≤ μ (s ∩ t) * ‖x‖₊ :=
mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs hμs ht hμt) _
#align measure_theory.set_lintegral_nnnorm_condexp_ind_smul_le MeasureTheory.set_lintegral_nnnorm_condexpIndSMul_le
| Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL2.lean | 443 | 449 | theorem lintegral_nnnorm_condexpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞)
(x : G) [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by |
refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) ?_ fun t ht hμt => ?_
· exact (Lp.aestronglyMeasurable _).ennnorm
refine (set_lintegral_nnnorm_condexpIndSMul_le hm hs hμs x ht hμt).trans ?_
gcongr
apply Set.inter_subset_left
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.TensorProduct.Graded.External
import Mathlib.RingTheory.GradedAlgebra.Basic
import Mathlib.GroupTheory.GroupAction.Ring
/-!
# Graded tensor products over graded algebras
The graded tensor product $A \hat\otimes_R B$ is imbued with a multiplication defined on homogeneous
tensors by:
$$(a \otimes b) \cdot (a' \otimes b') = (-1)^{\deg a' \deg b} (a \cdot a') \otimes (b \cdot b')$$
where $A$ and $B$ are algebras graded by `ℕ`, `ℤ`, or `ι` (or more generally, any index
that satisfies `Module ι (Additive ℤˣ)`).
## Main results
* `GradedTensorProduct R 𝒜 ℬ`: for families of submodules of `A` and `B` that form a graded algebra,
this is a type alias for `A ⊗[R] B` with the appropriate multiplication.
* `GradedTensorProduct.instAlgebra`: the ring structure induced by this multiplication.
* `GradedTensorProduct.liftEquiv`: a universal property for graded tensor products
## Notation
* `𝒜 ᵍ⊗[R] ℬ` is notation for `GradedTensorProduct R 𝒜 ℬ`.
* `a ᵍ⊗ₜ b` is notation for `GradedTensorProduct.tmul _ a b`.
## References
* https://math.stackexchange.com/q/202718/1896
* [*Algebra I*, Bourbaki : Chapter III, §4.7, example (2)][bourbaki1989]
## Implementation notes
We cannot put the multiplication on `A ⊗[R] B` directly as it would conflict with the existing
multiplication defined without the $(-1)^{\deg a' \deg b}$ term. Furthermore, the ring `A` may not
have a unique graduation, and so we need the chosen graduation `𝒜` to appear explicitly in the
type.
## TODO
* Show that the tensor product of graded algebras is itself a graded algebra.
* Determine if replacing the synonym with a single-field structure improves performance.
-/
suppress_compilation
open scoped TensorProduct
variable {R ι A B : Type*}
variable [CommSemiring ι] [Module ι (Additive ℤˣ)] [DecidableEq ι]
variable [CommRing R] [Ring A] [Ring B] [Algebra R A] [Algebra R B]
variable (𝒜 : ι → Submodule R A) (ℬ : ι → Submodule R B)
variable [GradedAlgebra 𝒜] [GradedAlgebra ℬ]
open DirectSum
variable (R) in
/-- A Type synonym for `A ⊗[R] B`, but with multiplication as `TensorProduct.gradedMul`.
This has notation `𝒜 ᵍ⊗[R] ℬ`. -/
@[nolint unusedArguments]
def GradedTensorProduct
(𝒜 : ι → Submodule R A) (ℬ : ι → Submodule R B)
[GradedAlgebra 𝒜] [GradedAlgebra ℬ] :
Type _ :=
A ⊗[R] B
namespace GradedTensorProduct
open TensorProduct
@[inherit_doc GradedTensorProduct]
scoped[TensorProduct] notation:100 𝒜 " ᵍ⊗[" R "] " ℬ:100 => GradedTensorProduct R 𝒜 ℬ
instance instAddCommGroupWithOne : AddCommGroupWithOne (𝒜 ᵍ⊗[R] ℬ) :=
Algebra.TensorProduct.instAddCommGroupWithOne
instance : Module R (𝒜 ᵍ⊗[R] ℬ) := TensorProduct.leftModule
variable (R) in
/-- The casting equivalence to move between regular and graded tensor products. -/
def of : A ⊗[R] B ≃ₗ[R] 𝒜 ᵍ⊗[R] ℬ := LinearEquiv.refl _ _
@[simp]
theorem of_one : of R 𝒜 ℬ 1 = 1 := rfl
@[simp]
theorem of_symm_one : (of R 𝒜 ℬ).symm 1 = 1 := rfl
-- for dsimp
@[simp, nolint simpNF]
theorem of_symm_of (x : A ⊗[R] B) : (of R 𝒜 ℬ).symm (of R 𝒜 ℬ x) = x := rfl
-- for dsimp
@[simp, nolint simpNF]
theorem symm_of_of (x : 𝒜 ᵍ⊗[R] ℬ) : of R 𝒜 ℬ ((of R 𝒜 ℬ).symm x) = x := rfl
/-- Two linear maps from the graded tensor product agree if they agree on the underlying tensor
product. -/
@[ext]
theorem hom_ext {M} [AddCommMonoid M] [Module R M] ⦃f g : 𝒜 ᵍ⊗[R] ℬ →ₗ[R] M⦄
(h : f ∘ₗ of R 𝒜 ℬ = (g ∘ₗ of R 𝒜 ℬ : A ⊗[R] B →ₗ[R] M)) :
f = g :=
h
variable (R) {𝒜 ℬ} in
/-- The graded tensor product of two elements of graded rings. -/
abbrev tmul (a : A) (b : B) : 𝒜 ᵍ⊗[R] ℬ := of R 𝒜 ℬ (a ⊗ₜ b)
@[inherit_doc]
notation:100 x " ᵍ⊗ₜ" y:100 => tmul _ x y
@[inherit_doc]
notation:100 x " ᵍ⊗ₜ[" R "] " y:100 => tmul R x y
variable (R) in
/-- An auxiliary construction to move between the graded tensor product of internally-graded objects
and the tensor product of direct sums. -/
noncomputable def auxEquiv : (𝒜 ᵍ⊗[R] ℬ) ≃ₗ[R] (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i) :=
let fA := (decomposeAlgEquiv 𝒜).toLinearEquiv
let fB := (decomposeAlgEquiv ℬ).toLinearEquiv
(of R 𝒜 ℬ).symm.trans (TensorProduct.congr fA fB)
theorem auxEquiv_tmul (a : A) (b : B) :
auxEquiv R 𝒜 ℬ (a ᵍ⊗ₜ b) = decompose 𝒜 a ⊗ₜ decompose ℬ b := rfl
theorem auxEquiv_one : auxEquiv R 𝒜 ℬ 1 = 1 := by
rw [← of_one, Algebra.TensorProduct.one_def, auxEquiv_tmul 𝒜 ℬ, DirectSum.decompose_one,
DirectSum.decompose_one, Algebra.TensorProduct.one_def]
theorem auxEquiv_symm_one : (auxEquiv R 𝒜 ℬ).symm 1 = 1 :=
(LinearEquiv.symm_apply_eq _).mpr (auxEquiv_one _ _).symm
/-- Auxiliary construction used to build the `Mul` instance and get distributivity of `+` and
`\smul`. -/
noncomputable def mulHom : (𝒜 ᵍ⊗[R] ℬ) →ₗ[R] (𝒜 ᵍ⊗[R] ℬ) →ₗ[R] (𝒜 ᵍ⊗[R] ℬ) := by
letI fAB1 := auxEquiv R 𝒜 ℬ
have := ((gradedMul R (𝒜 ·) (ℬ ·)).compl₁₂ fAB1.toLinearMap fAB1.toLinearMap).compr₂
fAB1.symm.toLinearMap
exact this
theorem mulHom_apply (x y : 𝒜 ᵍ⊗[R] ℬ) :
mulHom 𝒜 ℬ x y
= (auxEquiv R 𝒜 ℬ).symm (gradedMul R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) (auxEquiv R 𝒜 ℬ y)) :=
rfl
/-- The multipication on the graded tensor product.
See `GradedTensorProduct.coe_mul_coe` for a characterization on pure tensors. -/
instance : Mul (𝒜 ᵍ⊗[R] ℬ) where mul x y := mulHom 𝒜 ℬ x y
theorem mul_def (x y : 𝒜 ᵍ⊗[R] ℬ) : x * y = mulHom 𝒜 ℬ x y := rfl
-- Before #8386 this was `@[simp]` but it times out when we try to apply it.
theorem auxEquiv_mul (x y : 𝒜 ᵍ⊗[R] ℬ) :
auxEquiv R 𝒜 ℬ (x * y) = gradedMul R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) (auxEquiv R 𝒜 ℬ y) :=
LinearEquiv.eq_symm_apply _ |>.mp rfl
instance instMonoid : Monoid (𝒜 ᵍ⊗[R] ℬ) where
mul_one x := by
rw [mul_def, mulHom_apply, auxEquiv_one, gradedMul_one, LinearEquiv.symm_apply_apply]
one_mul x := by
rw [mul_def, mulHom_apply, auxEquiv_one, one_gradedMul, LinearEquiv.symm_apply_apply]
mul_assoc x y z := by
simp_rw [mul_def, mulHom_apply, LinearEquiv.apply_symm_apply]
rw [gradedMul_assoc]
instance instRing : Ring (𝒜 ᵍ⊗[R] ℬ) where
__ := instAddCommGroupWithOne 𝒜 ℬ
__ := instMonoid 𝒜 ℬ
right_distrib x y z := by simp_rw [mul_def, LinearMap.map_add₂]
left_distrib x y z := by simp_rw [mul_def, map_add]
mul_zero x := by simp_rw [mul_def, map_zero]
zero_mul x := by simp_rw [mul_def, LinearMap.map_zero₂]
/-- The characterization of this multiplication on partially homogenous elements. -/
theorem tmul_coe_mul_coe_tmul {j₁ i₂ : ι} (a₁ : A) (b₁ : ℬ j₁) (a₂ : 𝒜 i₂) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) =
(-1 : ℤˣ)^(j₁ * i₂) • ((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by
dsimp only [mul_def, mulHom_apply, of_symm_of]
dsimp [auxEquiv, tmul]
erw [decompose_coe, decompose_coe]
simp_rw [← lof_eq_of R]
rw [tmul_of_gradedMul_of_tmul]
simp_rw [lof_eq_of R]
rw [LinearEquiv.symm_symm]
-- Note: #8386 had to specialize `map_smul` to `LinearEquiv.map_smul`
rw [@Units.smul_def _ _ (_) (_), zsmul_eq_smul_cast R, LinearEquiv.map_smul, map_smul,
← zsmul_eq_smul_cast R, ← @Units.smul_def _ _ (_) (_)]
rw [congr_symm_tmul]
dsimp
simp_rw [decompose_symm_mul, decompose_symm_of, Equiv.symm_apply_apply]
/-- A special case for when `b₁` has grade 0. -/
theorem tmul_zero_coe_mul_coe_tmul {i₂ : ι} (a₁ : A) (b₁ : ℬ 0) (a₂ : 𝒜 i₂) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) =
((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by
rw [tmul_coe_mul_coe_tmul, zero_mul, uzpow_zero, one_smul]
/-- A special case for when `a₂` has grade 0. -/
| Mathlib/LinearAlgebra/TensorProduct/Graded/Internal.lean | 207 | 210 | theorem tmul_coe_mul_zero_coe_tmul {j₁ : ι} (a₁ : A) (b₁ : ℬ j₁) (a₂ : 𝒜 0) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) =
((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by |
rw [tmul_coe_mul_coe_tmul, mul_zero, uzpow_zero, one_smul]
|
/-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne
-/
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.Hom.CompleteLattice
#align_import order.liminf_limsup from "leanprover-community/mathlib"@"ffde2d8a6e689149e44fd95fa862c23a57f8c780"
/-!
# liminfs and limsups of functions and filters
Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete
lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`.
Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ.
Then there is no guarantee that the quantity above really decreases (the value of the `sup`
beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything.
So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has
to use a less tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
set_option autoImplicit true
open Filter Set Function
variable {α β γ ι ι' : Type*}
namespace Filter
section Relation
/-- `f.IsBounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e.
eventually, it is bounded by some uniform bound.
`r` will be usually instantiated with `≤` or `≥`. -/
def IsBounded (r : α → α → Prop) (f : Filter α) :=
∃ b, ∀ᶠ x in f, r x b
#align filter.is_bounded Filter.IsBounded
/-- `f.IsBoundedUnder (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t.
the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/
def IsBoundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) :=
(map u f).IsBounded r
#align filter.is_bounded_under Filter.IsBoundedUnder
variable {r : α → α → Prop} {f g : Filter α}
/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is
bounded. -/
theorem isBounded_iff : f.IsBounded r ↔ ∃ s ∈ f.sets, ∃ b, s ⊆ { x | r x b } :=
Iff.intro (fun ⟨b, hb⟩ => ⟨{ a | r a b }, hb, b, Subset.refl _⟩) fun ⟨_, hs, b, hb⟩ =>
⟨b, mem_of_superset hs hb⟩
#align filter.is_bounded_iff Filter.isBounded_iff
/-- A bounded function `u` is in particular eventually bounded. -/
theorem isBoundedUnder_of {f : Filter β} {u : β → α} : (∃ b, ∀ x, r (u x) b) → f.IsBoundedUnder r u
| ⟨b, hb⟩ => ⟨b, show ∀ᶠ x in f, r (u x) b from eventually_of_forall hb⟩
#align filter.is_bounded_under_of Filter.isBoundedUnder_of
theorem isBounded_bot : IsBounded r ⊥ ↔ Nonempty α := by simp [IsBounded, exists_true_iff_nonempty]
#align filter.is_bounded_bot Filter.isBounded_bot
theorem isBounded_top : IsBounded r ⊤ ↔ ∃ t, ∀ x, r x t := by simp [IsBounded, eq_univ_iff_forall]
#align filter.is_bounded_top Filter.isBounded_top
theorem isBounded_principal (s : Set α) : IsBounded r (𝓟 s) ↔ ∃ t, ∀ x ∈ s, r x t := by
simp [IsBounded, subset_def]
#align filter.is_bounded_principal Filter.isBounded_principal
theorem isBounded_sup [IsTrans α r] [IsDirected α r] :
IsBounded r f → IsBounded r g → IsBounded r (f ⊔ g)
| ⟨b₁, h₁⟩, ⟨b₂, h₂⟩ =>
let ⟨b, rb₁b, rb₂b⟩ := directed_of r b₁ b₂
⟨b, eventually_sup.mpr
⟨h₁.mono fun _ h => _root_.trans h rb₁b, h₂.mono fun _ h => _root_.trans h rb₂b⟩⟩
#align filter.is_bounded_sup Filter.isBounded_sup
theorem IsBounded.mono (h : f ≤ g) : IsBounded r g → IsBounded r f
| ⟨b, hb⟩ => ⟨b, h hb⟩
#align filter.is_bounded.mono Filter.IsBounded.mono
theorem IsBoundedUnder.mono {f g : Filter β} {u : β → α} (h : f ≤ g) :
g.IsBoundedUnder r u → f.IsBoundedUnder r u := fun hg => IsBounded.mono (map_mono h) hg
#align filter.is_bounded_under.mono Filter.IsBoundedUnder.mono
theorem IsBoundedUnder.mono_le [Preorder β] {l : Filter α} {u v : α → β}
(hu : IsBoundedUnder (· ≤ ·) l u) (hv : v ≤ᶠ[l] u) : IsBoundedUnder (· ≤ ·) l v := by
apply hu.imp
exact fun b hb => (eventually_map.1 hb).mp <| hv.mono fun x => le_trans
#align filter.is_bounded_under.mono_le Filter.IsBoundedUnder.mono_le
theorem IsBoundedUnder.mono_ge [Preorder β] {l : Filter α} {u v : α → β}
(hu : IsBoundedUnder (· ≥ ·) l u) (hv : u ≤ᶠ[l] v) : IsBoundedUnder (· ≥ ·) l v :=
IsBoundedUnder.mono_le (β := βᵒᵈ) hu hv
#align filter.is_bounded_under.mono_ge Filter.IsBoundedUnder.mono_ge
theorem isBoundedUnder_const [IsRefl α r] {l : Filter β} {a : α} : IsBoundedUnder r l fun _ => a :=
⟨a, eventually_map.2 <| eventually_of_forall fun _ => refl _⟩
#align filter.is_bounded_under_const Filter.isBoundedUnder_const
theorem IsBounded.isBoundedUnder {q : β → β → Prop} {u : α → β}
(hu : ∀ a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.IsBounded r → f.IsBoundedUnder q u
| ⟨b, h⟩ => ⟨u b, show ∀ᶠ x in f, q (u x) (u b) from h.mono fun x => hu x b⟩
#align filter.is_bounded.is_bounded_under Filter.IsBounded.isBoundedUnder
theorem IsBoundedUnder.comp {l : Filter γ} {q : β → β → Prop} {u : γ → α} {v : α → β}
(hv : ∀ a₀ a₁, r a₀ a₁ → q (v a₀) (v a₁)) : l.IsBoundedUnder r u → l.IsBoundedUnder q (v ∘ u)
| ⟨a, h⟩ => ⟨v a, show ∀ᶠ x in map u l, q (v x) (v a) from h.mono fun x => hv x a⟩
/-- A bounded above function `u` is in particular eventually bounded above. -/
lemma _root_.BddAbove.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} :
BddAbove (Set.range u) → f.IsBoundedUnder (· ≤ ·) u
| ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_upperBounds] using hb⟩
/-- A bounded below function `u` is in particular eventually bounded below. -/
lemma _root_.BddBelow.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} :
BddBelow (Set.range u) → f.IsBoundedUnder (· ≥ ·) u
| ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_lowerBounds] using hb⟩
theorem _root_.Monotone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≤ ·) u) :
l.IsBoundedUnder (· ≤ ·) (v ∘ u) :=
hl.comp hv
theorem _root_.Monotone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≥ ·) u) :
l.IsBoundedUnder (· ≥ ·) (v ∘ u) :=
hl.comp (swap hv)
theorem _root_.Antitone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≥ ·) u) :
l.IsBoundedUnder (· ≤ ·) (v ∘ u) :=
hl.comp (swap hv)
theorem _root_.Antitone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≤ ·) u) :
l.IsBoundedUnder (· ≥ ·) (v ∘ u) :=
hl.comp hv
theorem not_isBoundedUnder_of_tendsto_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α}
[l.NeBot] (hf : Tendsto f l atTop) : ¬IsBoundedUnder (· ≤ ·) l f := by
rintro ⟨b, hb⟩
rw [eventually_map] at hb
obtain ⟨b', h⟩ := exists_gt b
have hb' := (tendsto_atTop.mp hf) b'
have : { x : α | f x ≤ b } ∩ { x : α | b' ≤ f x } = ∅ :=
eq_empty_of_subset_empty fun x hx => (not_le_of_lt h) (le_trans hx.2 hx.1)
exact (nonempty_of_mem (hb.and hb')).ne_empty this
#align filter.not_is_bounded_under_of_tendsto_at_top Filter.not_isBoundedUnder_of_tendsto_atTop
theorem not_isBoundedUnder_of_tendsto_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α}
[l.NeBot] (hf : Tendsto f l atBot) : ¬IsBoundedUnder (· ≥ ·) l f :=
not_isBoundedUnder_of_tendsto_atTop (β := βᵒᵈ) hf
#align filter.not_is_bounded_under_of_tendsto_at_bot Filter.not_isBoundedUnder_of_tendsto_atBot
theorem IsBoundedUnder.bddAbove_range_of_cofinite [Preorder β] [IsDirected β (· ≤ ·)] {f : α → β}
(hf : IsBoundedUnder (· ≤ ·) cofinite f) : BddAbove (range f) := by
rcases hf with ⟨b, hb⟩
haveI : Nonempty β := ⟨b⟩
rw [← image_univ, ← union_compl_self { x | f x ≤ b }, image_union, bddAbove_union]
exact ⟨⟨b, forall_mem_image.2 fun x => id⟩, (hb.image f).bddAbove⟩
#align filter.is_bounded_under.bdd_above_range_of_cofinite Filter.IsBoundedUnder.bddAbove_range_of_cofinite
theorem IsBoundedUnder.bddBelow_range_of_cofinite [Preorder β] [IsDirected β (· ≥ ·)] {f : α → β}
(hf : IsBoundedUnder (· ≥ ·) cofinite f) : BddBelow (range f) :=
IsBoundedUnder.bddAbove_range_of_cofinite (β := βᵒᵈ) hf
#align filter.is_bounded_under.bdd_below_range_of_cofinite Filter.IsBoundedUnder.bddBelow_range_of_cofinite
theorem IsBoundedUnder.bddAbove_range [Preorder β] [IsDirected β (· ≤ ·)] {f : ℕ → β}
(hf : IsBoundedUnder (· ≤ ·) atTop f) : BddAbove (range f) := by
rw [← Nat.cofinite_eq_atTop] at hf
exact hf.bddAbove_range_of_cofinite
#align filter.is_bounded_under.bdd_above_range Filter.IsBoundedUnder.bddAbove_range
theorem IsBoundedUnder.bddBelow_range [Preorder β] [IsDirected β (· ≥ ·)] {f : ℕ → β}
(hf : IsBoundedUnder (· ≥ ·) atTop f) : BddBelow (range f) :=
IsBoundedUnder.bddAbove_range (β := βᵒᵈ) hf
#align filter.is_bounded_under.bdd_below_range Filter.IsBoundedUnder.bddBelow_range
/-- `IsCobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is
also called frequently bounded. Will be usually instantiated with `≤` or `≥`.
There is a subtlety in this definition: we want `f.IsCobounded` to hold for any `f` in the case of
complete lattices. This will be relevant to deduce theorems on complete lattices from their
versions on conditionally complete lattices with additional assumptions. We have to be careful in
the edge case of the trivial filter containing the empty set: the other natural definition
`¬ ∀ a, ∀ᶠ n in f, a ≤ n`
would not work as well in this case.
-/
def IsCobounded (r : α → α → Prop) (f : Filter α) :=
∃ b, ∀ a, (∀ᶠ x in f, r x a) → r b a
#align filter.is_cobounded Filter.IsCobounded
/-- `IsCoboundedUnder (≺) f u` states that the image of the filter `f` under the map `u` does not
tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated
with `≤` or `≥`. -/
def IsCoboundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) :=
(map u f).IsCobounded r
#align filter.is_cobounded_under Filter.IsCoboundedUnder
/-- To check that a filter is frequently bounded, it suffices to have a witness
which bounds `f` at some point for every admissible set.
This is only an implication, as the other direction is wrong for the trivial filter. -/
theorem IsCobounded.mk [IsTrans α r] (a : α) (h : ∀ s ∈ f, ∃ x ∈ s, r a x) : f.IsCobounded r :=
⟨a, fun _ s =>
let ⟨_, h₁, h₂⟩ := h _ s
_root_.trans h₂ h₁⟩
#align filter.is_cobounded.mk Filter.IsCobounded.mk
/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite
direction). At least if the filter is not trivial. -/
theorem IsBounded.isCobounded_flip [IsTrans α r] [NeBot f] : f.IsBounded r → f.IsCobounded (flip r)
| ⟨a, ha⟩ =>
⟨a, fun b hb =>
let ⟨_, rxa, rbx⟩ := (ha.and hb).exists
show r b a from _root_.trans rbx rxa⟩
#align filter.is_bounded.is_cobounded_flip Filter.IsBounded.isCobounded_flip
theorem IsBounded.isCobounded_ge [Preorder α] [NeBot f] (h : f.IsBounded (· ≤ ·)) :
f.IsCobounded (· ≥ ·) :=
h.isCobounded_flip
#align filter.is_bounded.is_cobounded_ge Filter.IsBounded.isCobounded_ge
theorem IsBounded.isCobounded_le [Preorder α] [NeBot f] (h : f.IsBounded (· ≥ ·)) :
f.IsCobounded (· ≤ ·) :=
h.isCobounded_flip
#align filter.is_bounded.is_cobounded_le Filter.IsBounded.isCobounded_le
theorem IsBoundedUnder.isCoboundedUnder_flip {l : Filter γ} [IsTrans α r] [NeBot l]
(h : l.IsBoundedUnder r u) : l.IsCoboundedUnder (flip r) u :=
h.isCobounded_flip
theorem IsBoundedUnder.isCoboundedUnder_le {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l]
(h : l.IsBoundedUnder (· ≥ ·) u) : l.IsCoboundedUnder (· ≤ ·) u :=
h.isCoboundedUnder_flip
theorem IsBoundedUnder.isCoboundedUnder_ge {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l]
(h : l.IsBoundedUnder (· ≤ ·) u) : l.IsCoboundedUnder (· ≥ ·) u :=
h.isCoboundedUnder_flip
lemma isCoboundedUnder_le_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ᶠ i in l, x ≤ f i) :
IsCoboundedUnder (· ≤ ·) l f :=
IsBoundedUnder.isCoboundedUnder_le ⟨x, hf⟩
lemma isCoboundedUnder_ge_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ᶠ i in l, f i ≤ x) :
IsCoboundedUnder (· ≥ ·) l f :=
IsBoundedUnder.isCoboundedUnder_ge ⟨x, hf⟩
lemma isCoboundedUnder_le_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ i, x ≤ f i) :
IsCoboundedUnder (· ≤ ·) l f :=
isCoboundedUnder_le_of_eventually_le l (eventually_of_forall hf)
lemma isCoboundedUnder_ge_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ i, f i ≤ x) :
IsCoboundedUnder (· ≥ ·) l f :=
isCoboundedUnder_ge_of_eventually_le l (eventually_of_forall hf)
theorem isCobounded_bot : IsCobounded r ⊥ ↔ ∃ b, ∀ x, r b x := by simp [IsCobounded]
#align filter.is_cobounded_bot Filter.isCobounded_bot
theorem isCobounded_top : IsCobounded r ⊤ ↔ Nonempty α := by
simp (config := { contextual := true }) [IsCobounded, eq_univ_iff_forall,
exists_true_iff_nonempty]
#align filter.is_cobounded_top Filter.isCobounded_top
theorem isCobounded_principal (s : Set α) :
(𝓟 s).IsCobounded r ↔ ∃ b, ∀ a, (∀ x ∈ s, r x a) → r b a := by simp [IsCobounded, subset_def]
#align filter.is_cobounded_principal Filter.isCobounded_principal
theorem IsCobounded.mono (h : f ≤ g) : f.IsCobounded r → g.IsCobounded r
| ⟨b, hb⟩ => ⟨b, fun a ha => hb a (h ha)⟩
#align filter.is_cobounded.mono Filter.IsCobounded.mono
end Relation
section Nonempty
variable [Preorder α] [Nonempty α] {f : Filter β} {u : β → α}
theorem isBounded_le_atBot : (atBot : Filter α).IsBounded (· ≤ ·) :=
‹Nonempty α›.elim fun a => ⟨a, eventually_le_atBot _⟩
#align filter.is_bounded_le_at_bot Filter.isBounded_le_atBot
theorem isBounded_ge_atTop : (atTop : Filter α).IsBounded (· ≥ ·) :=
‹Nonempty α›.elim fun a => ⟨a, eventually_ge_atTop _⟩
#align filter.is_bounded_ge_at_top Filter.isBounded_ge_atTop
theorem Tendsto.isBoundedUnder_le_atBot (h : Tendsto u f atBot) : f.IsBoundedUnder (· ≤ ·) u :=
isBounded_le_atBot.mono h
#align filter.tendsto.is_bounded_under_le_at_bot Filter.Tendsto.isBoundedUnder_le_atBot
theorem Tendsto.isBoundedUnder_ge_atTop (h : Tendsto u f atTop) : f.IsBoundedUnder (· ≥ ·) u :=
isBounded_ge_atTop.mono h
#align filter.tendsto.is_bounded_under_ge_at_top Filter.Tendsto.isBoundedUnder_ge_atTop
theorem bddAbove_range_of_tendsto_atTop_atBot [IsDirected α (· ≤ ·)] {u : ℕ → α}
(hx : Tendsto u atTop atBot) : BddAbove (Set.range u) :=
hx.isBoundedUnder_le_atBot.bddAbove_range
#align filter.bdd_above_range_of_tendsto_at_top_at_bot Filter.bddAbove_range_of_tendsto_atTop_atBot
theorem bddBelow_range_of_tendsto_atTop_atTop [IsDirected α (· ≥ ·)] {u : ℕ → α}
(hx : Tendsto u atTop atTop) : BddBelow (Set.range u) :=
hx.isBoundedUnder_ge_atTop.bddBelow_range
#align filter.bdd_below_range_of_tendsto_at_top_at_top Filter.bddBelow_range_of_tendsto_atTop_atTop
end Nonempty
theorem isCobounded_le_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsCobounded (· ≤ ·) :=
⟨⊥, fun _ _ => bot_le⟩
#align filter.is_cobounded_le_of_bot Filter.isCobounded_le_of_bot
theorem isCobounded_ge_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsCobounded (· ≥ ·) :=
⟨⊤, fun _ _ => le_top⟩
#align filter.is_cobounded_ge_of_top Filter.isCobounded_ge_of_top
theorem isBounded_le_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsBounded (· ≤ ·) :=
⟨⊤, eventually_of_forall fun _ => le_top⟩
#align filter.is_bounded_le_of_top Filter.isBounded_le_of_top
theorem isBounded_ge_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsBounded (· ≥ ·) :=
⟨⊥, eventually_of_forall fun _ => bot_le⟩
#align filter.is_bounded_ge_of_bot Filter.isBounded_ge_of_bot
@[simp]
theorem _root_.OrderIso.isBoundedUnder_le_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ}
{u : γ → α} : (IsBoundedUnder (· ≤ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≤ ·) l u :=
(Function.Surjective.exists e.surjective).trans <|
exists_congr fun a => by simp only [eventually_map, e.le_iff_le]
#align order_iso.is_bounded_under_le_comp OrderIso.isBoundedUnder_le_comp
@[simp]
theorem _root_.OrderIso.isBoundedUnder_ge_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ}
{u : γ → α} : (IsBoundedUnder (· ≥ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≥ ·) l u :=
OrderIso.isBoundedUnder_le_comp e.dual
#align order_iso.is_bounded_under_ge_comp OrderIso.isBoundedUnder_ge_comp
@[to_additive (attr := simp)]
theorem isBoundedUnder_le_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} :
(IsBoundedUnder (· ≤ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≥ ·) l u :=
(OrderIso.inv α).isBoundedUnder_ge_comp
#align filter.is_bounded_under_le_inv Filter.isBoundedUnder_le_inv
#align filter.is_bounded_under_le_neg Filter.isBoundedUnder_le_neg
@[to_additive (attr := simp)]
theorem isBoundedUnder_ge_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} :
(IsBoundedUnder (· ≥ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≤ ·) l u :=
(OrderIso.inv α).isBoundedUnder_le_comp
#align filter.is_bounded_under_ge_inv Filter.isBoundedUnder_ge_inv
#align filter.is_bounded_under_ge_neg Filter.isBoundedUnder_ge_neg
theorem IsBoundedUnder.sup [SemilatticeSup α] {f : Filter β} {u v : β → α} :
f.IsBoundedUnder (· ≤ ·) u →
f.IsBoundedUnder (· ≤ ·) v → f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a
| ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩, ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ =>
⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv
by filter_upwards [hu, hv] with _ using sup_le_sup⟩
#align filter.is_bounded_under.sup Filter.IsBoundedUnder.sup
@[simp]
theorem isBoundedUnder_le_sup [SemilatticeSup α] {f : Filter β} {u v : β → α} :
(f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a) ↔
f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≤ ·) v :=
⟨fun h =>
⟨h.mono_le <| eventually_of_forall fun _ => le_sup_left,
h.mono_le <| eventually_of_forall fun _ => le_sup_right⟩,
fun h => h.1.sup h.2⟩
#align filter.is_bounded_under_le_sup Filter.isBoundedUnder_le_sup
theorem IsBoundedUnder.inf [SemilatticeInf α] {f : Filter β} {u v : β → α} :
f.IsBoundedUnder (· ≥ ·) u →
f.IsBoundedUnder (· ≥ ·) v → f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a :=
IsBoundedUnder.sup (α := αᵒᵈ)
#align filter.is_bounded_under.inf Filter.IsBoundedUnder.inf
@[simp]
theorem isBoundedUnder_ge_inf [SemilatticeInf α] {f : Filter β} {u v : β → α} :
(f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a) ↔
f.IsBoundedUnder (· ≥ ·) u ∧ f.IsBoundedUnder (· ≥ ·) v :=
isBoundedUnder_le_sup (α := αᵒᵈ)
#align filter.is_bounded_under_ge_inf Filter.isBoundedUnder_ge_inf
theorem isBoundedUnder_le_abs [LinearOrderedAddCommGroup α] {f : Filter β} {u : β → α} :
(f.IsBoundedUnder (· ≤ ·) fun a => |u a|) ↔
f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≥ ·) u :=
isBoundedUnder_le_sup.trans <| and_congr Iff.rfl isBoundedUnder_le_neg
#align filter.is_bounded_under_le_abs Filter.isBoundedUnder_le_abs
/-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `isBoundedDefault` in the statements,
in the form `(hf : f.IsBounded (≥) := by isBoundedDefault)`. -/
macro "isBoundedDefault" : tactic =>
`(tactic| first
| apply isCobounded_le_of_bot
| apply isCobounded_ge_of_top
| apply isBounded_le_of_top
| apply isBounded_ge_of_bot)
-- Porting note: The above is a lean 4 reconstruction of (note that applyc is not available (yet?)):
-- unsafe def is_bounded_default : tactic Unit :=
-- tactic.applyc `` is_cobounded_le_of_bot <|>
-- tactic.applyc `` is_cobounded_ge_of_top <|>
-- tactic.applyc `` is_bounded_le_of_top <|> tactic.applyc `` is_bounded_ge_of_bot
-- #align filter.is_bounded_default filter.IsBounded_default
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α]
-- Porting note: Renamed from Limsup and Liminf to limsSup and limsInf
/-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def limsSup (f : Filter α) : α :=
sInf { a | ∀ᶠ n in f, n ≤ a }
set_option linter.uppercaseLean3 false in
#align filter.Limsup Filter.limsSup
set_option linter.uppercaseLean3 false in
/-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def limsInf (f : Filter α) : α :=
sSup { a | ∀ᶠ n in f, a ≤ n }
set_option linter.uppercaseLean3 false in
#align filter.Liminf Filter.limsInf
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (u : β → α) (f : Filter β) : α :=
limsSup (map u f)
#align filter.limsup Filter.limsup
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (u : β → α) (f : Filter β) : α :=
limsInf (map u f)
#align filter.liminf Filter.liminf
/-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum
of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/
def blimsup (u : β → α) (f : Filter β) (p : β → Prop) :=
sInf { a | ∀ᶠ x in f, p x → u x ≤ a }
#align filter.blimsup Filter.blimsup
/-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum
of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/
def bliminf (u : β → α) (f : Filter β) (p : β → Prop) :=
sSup { a | ∀ᶠ x in f, p x → a ≤ u x }
#align filter.bliminf Filter.bliminf
section
variable {f : Filter β} {u : β → α} {p : β → Prop}
theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } :=
rfl
#align filter.limsup_eq Filter.limsup_eq
theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } :=
rfl
#align filter.liminf_eq Filter.liminf_eq
theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } :=
rfl
#align filter.blimsup_eq Filter.blimsup_eq
theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } :=
rfl
#align filter.bliminf_eq Filter.bliminf_eq
lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) :
liminf (u ∘ v) f = liminf u (map v f) := rfl
lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) :
limsup (u ∘ v) f = limsup u (map v f) := rfl
end
@[simp]
theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by
simp [blimsup_eq, limsup_eq]
#align filter.blimsup_true Filter.blimsup_true
@[simp]
theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by
simp [bliminf_eq, liminf_eq]
#align filter.bliminf_true Filter.bliminf_true
lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by
simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq]
lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) :=
blimsup_eq_limsup (α := αᵒᵈ)
theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by
rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val]
#align filter.blimsup_eq_limsup_subtype Filter.blimsup_eq_limsup_subtype
theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) :=
blimsup_eq_limsup_subtype (α := αᵒᵈ)
#align filter.bliminf_eq_liminf_subtype Filter.bliminf_eq_liminf_subtype
theorem limsSup_le_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a :=
csInf_le hf h
set_option linter.uppercaseLean3 false in
#align filter.Limsup_le_of_le Filter.limsSup_le_of_le
theorem le_limsInf_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f :=
le_csSup hf h
set_option linter.uppercaseLean3 false in
#align filter.le_Liminf_of_le Filter.le_limsInf_of_le
theorem limsup_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a :=
csInf_le hf h
#align filter.limsup_le_of_le Filter.limsSup_le_of_le
theorem le_liminf_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f :=
le_csSup hf h
#align filter.le_liminf_of_le Filter.le_liminf_of_le
theorem le_limsSup_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f :=
le_csInf hf h
set_option linter.uppercaseLean3 false in
#align filter.le_Limsup_of_le Filter.le_limsSup_of_le
theorem limsInf_le_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a :=
csSup_le hf h
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_of_le Filter.limsInf_le_of_le
theorem le_limsup_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f :=
le_csInf hf h
#align filter.le_limsup_of_le Filter.le_limsup_of_le
theorem liminf_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a :=
csSup_le hf h
#align filter.liminf_le_of_le Filter.liminf_le_of_le
theorem limsInf_le_limsSup {f : Filter α} [NeBot f]
(h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault):
limsInf f ≤ limsSup f :=
liminf_le_of_le h₂ fun a₀ ha₀ =>
le_limsup_of_le h₁ fun a₁ ha₁ =>
show a₀ ≤ a₁ from
let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists
le_trans hb₀ hb₁
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_Limsup Filter.limsInf_le_limsSup
theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α}
(h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault):
liminf u f ≤ limsup u f :=
limsInf_le_limsSup h h'
#align filter.liminf_le_limsup Filter.liminf_le_limsup
theorem limsSup_le_limsSup {f g : Filter α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g :=
csInf_le_csInf hf hg h
set_option linter.uppercaseLean3 false in
#align filter.Limsup_le_Limsup Filter.limsSup_le_limsSup
theorem limsInf_le_limsInf {f g : Filter α}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g :=
csSup_le_csSup hg hf h
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_Liminf Filter.limsInf_le_limsInf
theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : u ≤ᶠ[f] v)
(hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) :
limsup u f ≤ limsup v f :=
limsSup_le_limsSup hu hv fun _ => h.trans
#align filter.limsup_le_limsup Filter.limsup_le_limsup
theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) :
liminf u f ≤ liminf v f :=
limsup_le_limsup (β := βᵒᵈ) h hv hu
#align filter.liminf_le_liminf Filter.liminf_le_liminf
theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g)
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) :
limsSup f ≤ limsSup g :=
limsSup_le_limsSup hf hg fun _ ha => h ha
set_option linter.uppercaseLean3 false in
#align filter.Limsup_le_Limsup_of_le Filter.limsSup_le_limsSup_of_le
theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f)
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsInf g :=
limsInf_le_limsInf hf hg fun _ ha => h ha
set_option linter.uppercaseLean3 false in
#align filter.Liminf_le_Liminf_of_le Filter.limsInf_le_limsInf_of_le
theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g)
{u : α → β}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
limsup u f ≤ limsup u g :=
limsSup_le_limsSup_of_le (map_mono h) hf hg
#align filter.limsup_le_limsup_of_le Filter.limsup_le_limsup_of_le
theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f)
{u : α → β}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ liminf u g :=
limsInf_le_limsInf_of_le (map_mono h) hf hg
#align filter.liminf_le_liminf_of_le Filter.liminf_le_liminf_of_le
theorem limsSup_principal {s : Set α} (h : BddAbove s) (hs : s.Nonempty) :
limsSup (𝓟 s) = sSup s := by
simp only [limsSup, eventually_principal]; exact csInf_upper_bounds_eq_csSup h hs
set_option linter.uppercaseLean3 false in
#align filter.Limsup_principal Filter.limsSup_principal
theorem limsInf_principal {s : Set α} (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s :=
limsSup_principal (α := αᵒᵈ) h hs
set_option linter.uppercaseLean3 false in
#align filter.Liminf_principal Filter.limsInf_principal
| Mathlib/Order/LiminfLimsup.lean | 674 | 678 | theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by |
rw [limsup_eq]
congr with b
exact eventually_congr (h.mono fun x hx => by simp [hx])
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Group.Defs
#align_import algebra.invertible from "leanprover-community/mathlib"@"722b3b152ddd5e0cf21c0a29787c76596cb6b422"
/-!
# Invertible elements
This file defines a typeclass `Invertible a` for elements `a` with a two-sided
multiplicative inverse.
The intent of the typeclass is to provide a way to write e.g. `⅟2` in a ring
like `ℤ[1/2]` where some inverses exist but there is no general `⁻¹` operator;
or to specify that a field has characteristic `≠ 2`.
It is the `Type`-valued analogue to the `Prop`-valued `IsUnit`.
For constructions of the invertible element given a characteristic, see
`Algebra/CharP/Invertible` and other lemmas in that file.
## Notation
* `⅟a` is `Invertible.invOf a`, the inverse of `a`
## Implementation notes
The `Invertible` class lives in `Type`, not `Prop`, to make computation easier.
If multiplication is associative, `Invertible` is a subsingleton anyway.
The `simp` normal form tries to normalize `⅟a` to `a ⁻¹`. Otherwise, it pushes
`⅟` inside the expression as much as possible.
Since `Invertible a` is not a `Prop` (but it is a `Subsingleton`), we have to be careful about
coherence issues: we should avoid having multiple non-defeq instances for `Invertible a` in the
same context. This file plays it safe and uses `def` rather than `instance` for most definitions,
users can choose which instances to use at the point of use.
For example, here's how you can use an `Invertible 1` instance:
```lean
variable {α : Type*} [Monoid α]
def something_that_needs_inverses (x : α) [Invertible x] := sorry
section
attribute [local instance] invertibleOne
def something_one := something_that_needs_inverses 1
end
```
### Typeclass search vs. unification for `simp` lemmas
Note that since typeclass search searches the local context first, an instance argument like
`[Invertible a]` might sometimes be filled by a different term than the one we'd find by
unification (i.e., the one that's used as an implicit argument to `⅟`).
This can cause issues with `simp`. Therefore, some lemmas are duplicated, with the `@[simp]`
versions using unification and the user-facing ones using typeclass search.
Since unification can make backwards rewriting (e.g. `rw [← mylemma]`) impractical, we still want
the instance-argument versions; therefore the user-facing versions retain the instance arguments
and the original lemma name, whereas the `@[simp]`/unification ones acquire a `'` at the end of
their name.
We modify this file according to the above pattern only as needed; therefore, most `@[simp]` lemmas
here are not part of such a duplicate pair. This is not (yet) intended as a permanent solution.
See Zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Invertible.201.20simps/near/320558233]
## Tags
invertible, inverse element, invOf, a half, one half, a third, one third, ½, ⅓
-/
assert_not_exists MonoidWithZero
assert_not_exists DenselyOrdered
universe u
variable {α : Type u}
/-- `Invertible a` gives a two-sided multiplicative inverse of `a`. -/
class Invertible [Mul α] [One α] (a : α) : Type u where
/-- The inverse of an `Invertible` element -/
invOf : α
/-- `invOf a` is a left inverse of `a` -/
invOf_mul_self : invOf * a = 1
/-- `invOf a` is a right inverse of `a` -/
mul_invOf_self : a * invOf = 1
#align invertible Invertible
/-- The inverse of an `Invertible` element -/
prefix:max
"⅟" =>-- This notation has the same precedence as `Inv.inv`.
Invertible.invOf
@[simp]
theorem invOf_mul_self' [Mul α] [One α] (a : α) {_ : Invertible a} : ⅟ a * a = 1 :=
Invertible.invOf_mul_self
theorem invOf_mul_self [Mul α] [One α] (a : α) [Invertible a] : ⅟ a * a = 1 :=
Invertible.invOf_mul_self
#align inv_of_mul_self invOf_mul_self
@[simp]
theorem mul_invOf_self' [Mul α] [One α] (a : α) {_ : Invertible a} : a * ⅟ a = 1 :=
Invertible.mul_invOf_self
theorem mul_invOf_self [Mul α] [One α] (a : α) [Invertible a] : a * ⅟ a = 1 :=
Invertible.mul_invOf_self
#align mul_inv_of_self mul_invOf_self
@[simp]
theorem invOf_mul_self_assoc' [Monoid α] (a b : α) {_ : Invertible a} : ⅟ a * (a * b) = b := by
rw [← mul_assoc, invOf_mul_self, one_mul]
theorem invOf_mul_self_assoc [Monoid α] (a b : α) [Invertible a] : ⅟ a * (a * b) = b := by
rw [← mul_assoc, invOf_mul_self, one_mul]
#align inv_of_mul_self_assoc invOf_mul_self_assoc
@[simp]
theorem mul_invOf_self_assoc' [Monoid α] (a b : α) {_ : Invertible a} : a * (⅟ a * b) = b := by
rw [← mul_assoc, mul_invOf_self, one_mul]
theorem mul_invOf_self_assoc [Monoid α] (a b : α) [Invertible a] : a * (⅟ a * b) = b := by
rw [← mul_assoc, mul_invOf_self, one_mul]
#align mul_inv_of_self_assoc mul_invOf_self_assoc
@[simp]
theorem mul_invOf_mul_self_cancel' [Monoid α] (a b : α) {_ : Invertible b} : a * ⅟ b * b = a := by
simp [mul_assoc]
theorem mul_invOf_mul_self_cancel [Monoid α] (a b : α) [Invertible b] : a * ⅟ b * b = a := by
simp [mul_assoc]
#align mul_inv_of_mul_self_cancel mul_invOf_mul_self_cancel
@[simp]
theorem mul_mul_invOf_self_cancel' [Monoid α] (a b : α) {_ : Invertible b} : a * b * ⅟ b = a := by
simp [mul_assoc]
theorem mul_mul_invOf_self_cancel [Monoid α] (a b : α) [Invertible b] : a * b * ⅟ b = a := by
simp [mul_assoc]
#align mul_mul_inv_of_self_cancel mul_mul_invOf_self_cancel
theorem invOf_eq_right_inv [Monoid α] {a b : α} [Invertible a] (hac : a * b = 1) : ⅟ a = b :=
left_inv_eq_right_inv (invOf_mul_self _) hac
#align inv_of_eq_right_inv invOf_eq_right_inv
theorem invOf_eq_left_inv [Monoid α] {a b : α} [Invertible a] (hac : b * a = 1) : ⅟ a = b :=
(left_inv_eq_right_inv hac (mul_invOf_self _)).symm
#align inv_of_eq_left_inv invOf_eq_left_inv
theorem invertible_unique {α : Type u} [Monoid α] (a b : α) [Invertible a] [Invertible b]
(h : a = b) : ⅟ a = ⅟ b := by
apply invOf_eq_right_inv
rw [h, mul_invOf_self]
#align invertible_unique invertible_unique
instance Invertible.subsingleton [Monoid α] (a : α) : Subsingleton (Invertible a) :=
⟨fun ⟨b, hba, hab⟩ ⟨c, _, hac⟩ => by
congr
exact left_inv_eq_right_inv hba hac⟩
#align invertible.subsingleton Invertible.subsingleton
/-- If `a` is invertible and `a = b`, then `⅟a = ⅟b`. -/
@[congr]
theorem Invertible.congr [Monoid α] (a b : α) [Invertible a] [Invertible b] (h : a = b) :
⅟a = ⅟b := by subst h; congr; apply Subsingleton.allEq
/-- If `r` is invertible and `s = r` and `si = ⅟r`, then `s` is invertible with `⅟s = si`. -/
def Invertible.copy' [MulOneClass α] {r : α} (hr : Invertible r) (s : α) (si : α) (hs : s = r)
(hsi : si = ⅟ r) : Invertible s where
invOf := si
invOf_mul_self := by rw [hs, hsi, invOf_mul_self]
mul_invOf_self := by rw [hs, hsi, mul_invOf_self]
#align invertible.copy' Invertible.copy'
/-- If `r` is invertible and `s = r`, then `s` is invertible. -/
abbrev Invertible.copy [MulOneClass α] {r : α} (hr : Invertible r) (s : α) (hs : s = r) :
Invertible s :=
hr.copy' _ _ hs rfl
#align invertible.copy Invertible.copy
/-- Each element of a group is invertible. -/
def invertibleOfGroup [Group α] (a : α) : Invertible a :=
⟨a⁻¹, inv_mul_self a, mul_inv_self a⟩
#align invertible_of_group invertibleOfGroup
@[simp]
theorem invOf_eq_group_inv [Group α] (a : α) [Invertible a] : ⅟ a = a⁻¹ :=
invOf_eq_right_inv (mul_inv_self a)
#align inv_of_eq_group_inv invOf_eq_group_inv
/-- `1` is the inverse of itself -/
def invertibleOne [Monoid α] : Invertible (1 : α) :=
⟨1, mul_one _, one_mul _⟩
#align invertible_one invertibleOne
@[simp]
theorem invOf_one' [Monoid α] {_ : Invertible (1 : α)} : ⅟ (1 : α) = 1 :=
invOf_eq_right_inv (mul_one _)
theorem invOf_one [Monoid α] [Invertible (1 : α)] : ⅟ (1 : α) = 1 :=
invOf_eq_right_inv (mul_one _)
#align inv_of_one invOf_one
/-- `a` is the inverse of `⅟a`. -/
instance invertibleInvOf [One α] [Mul α] {a : α} [Invertible a] : Invertible (⅟ a) :=
⟨a, mul_invOf_self a, invOf_mul_self a⟩
#align invertible_inv_of invertibleInvOf
@[simp]
theorem invOf_invOf [Monoid α] (a : α) [Invertible a] [Invertible (⅟ a)] : ⅟ (⅟ a) = a :=
invOf_eq_right_inv (invOf_mul_self _)
#align inv_of_inv_of invOf_invOf
@[simp]
theorem invOf_inj [Monoid α] {a b : α} [Invertible a] [Invertible b] : ⅟ a = ⅟ b ↔ a = b :=
⟨invertible_unique _ _, invertible_unique _ _⟩
#align inv_of_inj invOf_inj
/-- `⅟b * ⅟a` is the inverse of `a * b` -/
def invertibleMul [Monoid α] (a b : α) [Invertible a] [Invertible b] : Invertible (a * b) :=
⟨⅟ b * ⅟ a, by simp [← mul_assoc], by simp [← mul_assoc]⟩
#align invertible_mul invertibleMul
@[simp]
theorem invOf_mul [Monoid α] (a b : α) [Invertible a] [Invertible b] [Invertible (a * b)] :
⅟ (a * b) = ⅟ b * ⅟ a :=
invOf_eq_right_inv (by simp [← mul_assoc])
#align inv_of_mul invOf_mul
/-- A copy of `invertibleMul` for dot notation. -/
abbrev Invertible.mul [Monoid α] {a b : α} (_ : Invertible a) (_ : Invertible b) :
Invertible (a * b) :=
invertibleMul _ _
#align invertible.mul Invertible.mul
section
variable [Monoid α] {a b c : α} [Invertible c]
variable (c) in
theorem mul_right_inj_of_invertible : a * c = b * c ↔ a = b :=
⟨fun h => by simpa using congr_arg (· * ⅟c) h, congr_arg (· * _)⟩
variable (c) in
theorem mul_left_inj_of_invertible : c * a = c * b ↔ a = b :=
⟨fun h => by simpa using congr_arg (⅟c * ·) h, congr_arg (_ * ·)⟩
theorem invOf_mul_eq_iff_eq_mul_left : ⅟c * a = b ↔ a = c * b := by
rw [← mul_left_inj_of_invertible (c := c), mul_invOf_self_assoc]
theorem mul_left_eq_iff_eq_invOf_mul : c * a = b ↔ a = ⅟c * b := by
rw [← mul_left_inj_of_invertible (c := ⅟c), invOf_mul_self_assoc]
theorem mul_invOf_eq_iff_eq_mul_right : a * ⅟c = b ↔ a = b * c := by
rw [← mul_right_inj_of_invertible (c := c), mul_invOf_mul_self_cancel]
| Mathlib/Algebra/Group/Invertible/Defs.lean | 262 | 263 | theorem mul_right_eq_iff_eq_mul_invOf : a * c = b ↔ a = b * ⅟c := by |
rw [← mul_right_inj_of_invertible (c := ⅟c), mul_mul_invOf_self_cancel]
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Operations
import Mathlib.Data.Fintype.Lattice
import Mathlib.RingTheory.Coprime.Lemmas
#align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74"
/-!
# More operations on modules and ideals
-/
assert_not_exists Basis -- See `RingTheory.Ideal.Basis`
assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations`
universe u v w x
open Pointwise
namespace Submodule
variable {R : Type u} {M : Type v} {M' F G : Type*}
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
open Pointwise
instance hasSMul' : SMul (Ideal R) (Submodule R M) :=
⟨Submodule.map₂ (LinearMap.lsmul R M)⟩
#align submodule.has_smul' Submodule.hasSMul'
/-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to
apply. -/
protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J :=
rfl
#align ideal.smul_eq_mul Ideal.smul_eq_mul
variable (R M) in
/-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/
def _root_.Module.annihilator : Ideal R := LinearMap.ker (LinearMap.lsmul R M)
theorem _root_.Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 :=
⟨fun h ↦ (congr($h ·)), (LinearMap.ext ·)⟩
theorem _root_.LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) :
Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero])
theorem _root_.LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M')
(hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢
intro m; obtain ⟨m, rfl⟩ := hf m
rw [← map_smul, h, f.map_zero]
theorem _root_.LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') :
Module.annihilator R M = Module.annihilator R M' :=
(e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective)
/-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/
abbrev annihilator (N : Submodule R M) : Ideal R :=
Module.annihilator R N
#align submodule.annihilator Submodule.annihilator
theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M :=
topEquiv.annihilator_eq
variable {I J : Ideal R} {N P : Submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by
simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl
#align submodule.mem_annihilator Submodule.mem_annihilator
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ :=
mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩
#align submodule.mem_annihilator' Submodule.mem_annihilator'
theorem mem_annihilator_span (s : Set M) (r : R) :
r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by
rw [Submodule.mem_annihilator]
constructor
· intro h n
exact h _ (Submodule.subset_span n.prop)
· intro h n hn
refine Submodule.span_induction hn ?_ ?_ ?_ ?_
· intro x hx
exact h ⟨x, hx⟩
· exact smul_zero _
· intro x y hx hy
rw [smul_add, hx, hy, zero_add]
· intro a x hx
rw [smul_comm, hx, smul_zero]
#align submodule.mem_annihilator_span Submodule.mem_annihilator_span
theorem mem_annihilator_span_singleton (g : M) (r : R) :
r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span]
#align submodule.mem_annihilator_span_singleton Submodule.mem_annihilator_span_singleton
theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ :=
(Ideal.eq_top_iff_one _).2 <| mem_annihilator'.2 bot_le
#align submodule.annihilator_bot Submodule.annihilator_bot
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ :=
⟨fun H =>
eq_bot_iff.2 fun (n : M) hn =>
(mem_bot R).2 <| one_smul R n ▸ mem_annihilator.1 ((Ideal.eq_top_iff_one _).1 H) n hn,
fun H => H.symm ▸ annihilator_bot⟩
#align submodule.annihilator_eq_top_iff Submodule.annihilator_eq_top_iff
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp =>
mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn
#align submodule.annihilator_mono Submodule.annihilator_mono
theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) :
annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun _ H =>
mem_annihilator'.2 <|
iSup_le fun i =>
have := (mem_iInf _).1 H i
mem_annihilator'.1 this
#align submodule.annihilator_supr Submodule.annihilator_iSup
theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N :=
apply_mem_map₂ _ hr hn
#align submodule.smul_mem_smul Submodule.smul_mem_smul
theorem smul_le {P : Submodule R M} : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P :=
map₂_le
#align submodule.smul_le Submodule.smul_le
@[simp, norm_cast]
lemma coe_set_smul : (I : Set R) • N = I • N :=
Submodule.set_smul_eq_of_le _ _ _
(fun _ _ hr hx => smul_mem_smul hr hx)
(smul_le.mpr fun _ hr _ hx => mem_set_smul_of_mem_mem hr hx)
@[elab_as_elim]
theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n))
(add : ∀ x y, p x → p y → p (x + y)) : p x := by
have H0 : p 0 := by simpa only [zero_smul] using smul 0 I.zero_mem 0 N.zero_mem
refine Submodule.iSup_induction (x := x) _ H ?_ H0 add
rintro ⟨i, hi⟩ m ⟨j, hj, hj'⟩
rw [← hj']
exact smul _ hi _ hj
#align submodule.smul_induction_on Submodule.smul_induction_on
/-- Dependent version of `Submodule.smul_induction_on`. -/
@[elab_as_elim]
theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop}
(smul : ∀ (r : R) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) : p x hx := by
refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) => H
exact
smul_induction_on hx (fun a ha x hx => ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ =>
⟨_, add _ _ _ _ hx hy⟩
#align submodule.smul_induction_on' Submodule.smul_induction_on'
theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} :
x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x :=
⟨fun hx =>
smul_induction_on hx
(fun r hri n hnm =>
let ⟨s, hs⟩ := mem_span_singleton.1 hnm
⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩)
fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ =>
⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩,
fun ⟨y, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩
#align submodule.mem_smul_span_singleton Submodule.mem_smul_span_singleton
theorem smul_le_right : I • N ≤ N :=
smul_le.2 fun r _ _ => N.smul_mem r
#align submodule.smul_le_right Submodule.smul_le_right
theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P :=
map₂_le_map₂ hij hnp
#align submodule.smul_mono Submodule.smul_mono
theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N :=
map₂_le_map₂_left h
#align submodule.smul_mono_left Submodule.smul_mono_left
instance : CovariantClass (Ideal R) (Submodule R M) HSMul.hSMul LE.le :=
⟨fun _ _ => map₂_le_map₂_right⟩
@[deprecated smul_mono_right (since := "2024-03-31")]
protected theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P :=
_root_.smul_mono_right I h
#align submodule.smul_mono_right Submodule.smul_mono_right
theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) :
Submodule.map f I ≤ I • (⊤ : Submodule R M) := by
rintro _ ⟨y, hy, rfl⟩
rw [← mul_one y, ← smul_eq_mul, f.map_smul]
exact smul_mem_smul hy mem_top
#align submodule.map_le_smul_top Submodule.map_le_smul_top
@[simp]
theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ :=
eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1)
#align submodule.annihilator_smul Submodule.annihilator_smul
@[simp]
theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ :=
annihilator_smul I
#align submodule.annihilator_mul Submodule.annihilator_mul
@[simp]
theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul]
#align submodule.mul_annihilator Submodule.mul_annihilator
variable (I J N P)
@[simp]
theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ :=
map₂_bot_right _ _
#align submodule.smul_bot Submodule.smul_bot
@[simp]
theorem bot_smul : (⊥ : Ideal R) • N = ⊥ :=
map₂_bot_left _ _
#align submodule.bot_smul Submodule.bot_smul
@[simp]
theorem top_smul : (⊤ : Ideal R) • N = N :=
le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri
#align submodule.top_smul Submodule.top_smul
theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P :=
map₂_sup_right _ _ _ _
#align submodule.smul_sup Submodule.smul_sup
theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N :=
map₂_sup_left _ _ _ _
#align submodule.sup_smul Submodule.sup_smul
protected theorem smul_assoc : (I • J) • N = I • J • N :=
le_antisymm
(smul_le.2 fun _ hrsij t htn =>
smul_induction_on hrsij
(fun r hr s hs =>
(@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn))
fun x y => (add_smul x y t).symm ▸ Submodule.add_mem _)
(smul_le.2 fun r hr _ hsn =>
suffices J • N ≤ Submodule.comap (r • (LinearMap.id : M →ₗ[R] M)) ((I • J) • N) from this hsn
smul_le.2 fun s hs n hn =>
show r • s • n ∈ (I • J) • N from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn)
#align submodule.smul_assoc Submodule.smul_assoc
@[deprecated smul_inf_le (since := "2024-03-31")]
protected theorem smul_inf_le (M₁ M₂ : Submodule R M) :
I • (M₁ ⊓ M₂) ≤ I • M₁ ⊓ I • M₂ := smul_inf_le _ _ _
#align submodule.smul_inf_le Submodule.smul_inf_le
theorem smul_iSup {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iSup t = ⨆ i, I • t i :=
map₂_iSup_right _ _ _
#align submodule.smul_supr Submodule.smul_iSup
@[deprecated smul_iInf_le (since := "2024-03-31")]
protected theorem smul_iInf_le {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} :
I • iInf t ≤ ⨅ i, I • t i :=
smul_iInf_le
#align submodule.smul_infi_le Submodule.smul_iInf_le
variable (S : Set R) (T : Set M)
theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) :=
(map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _
#align submodule.span_smul_span Submodule.span_smul_span
theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) :
(Ideal.span {r} : Ideal R) • N = r • N := by
have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by
convert span_eq (r • N)
exact (Set.image_eq_iUnion _ (N : Set M)).symm
conv_lhs => rw [← span_eq N, span_smul_span]
simpa
#align submodule.ideal_span_singleton_smul Submodule.ideal_span_singleton_smul
theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M)
(H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by
suffices (⊤ : Ideal R) • span R ({x} : Set M) ≤ M' by
rw [top_smul] at this
exact this (subset_span (Set.mem_singleton x))
rw [← hs, span_smul_span, span_le]
simpa using H
#align submodule.mem_of_span_top_of_smul_mem Submodule.mem_of_span_top_of_smul_mem
/-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a
submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/
theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤)
(x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by
obtain ⟨s', hs₁, hs₂⟩ := (Ideal.span_eq_top_iff_finite _).mp hs
replace H : ∀ r : s', ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M' := fun r => H ⟨_, hs₁ r.2⟩
choose n₁ n₂ using H
let N := s'.attach.sup n₁
have hs' := Ideal.span_pow_eq_top (s' : Set R) hs₂ N
apply M'.mem_of_span_top_of_smul_mem _ hs'
rintro ⟨_, r, hr, rfl⟩
convert M'.smul_mem (r ^ (N - n₁ ⟨r, hr⟩)) (n₂ ⟨r, hr⟩) using 1
simp only [Subtype.coe_mk, smul_smul, ← pow_add]
rw [tsub_add_cancel_of_le (Finset.le_sup (s'.mem_attach _) : n₁ ⟨r, hr⟩ ≤ N)]
#align submodule.mem_of_span_eq_top_of_smul_pow_mem Submodule.mem_of_span_eq_top_of_smul_pow_mem
variable {M' : Type w} [AddCommMonoid M'] [Module R M']
@[simp]
theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f :=
le_antisymm
(map_le_iff_le_comap.2 <|
smul_le.2 fun r hr n hn =>
show f (r • n) ∈ I • N.map f from
(f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <|
smul_le.2 fun r hr _ hn =>
let ⟨p, hp, hfp⟩ := mem_map.1 hn
hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp)
#align submodule.map_smul'' Submodule.map_smul''
open Pointwise in
@[simp]
theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') :
(r • N).map f = r • N.map f := by
simp_rw [← ideal_span_singleton_smul, map_smul'']
variable {I}
theorem mem_smul_span {s : Set M} {x : M} :
x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by
rw [← I.span_eq, Submodule.span_smul_span, I.span_eq]
rfl
#align submodule.mem_smul_span Submodule.mem_smul_span
variable (I)
/-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`,
then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/
theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) :
x ∈ I • span R (Set.range f) ↔
∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
constructor; swap
· rintro ⟨a, ha, rfl⟩
exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _
refine fun hx => span_induction (mem_smul_span.mp hx) ?_ ?_ ?_ ?_
· simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff]
rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩
refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩
· letI := Classical.decEq ι
rw [Finsupp.single_apply]
split_ifs
· assumption
· exact I.zero_mem
refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_
simp
· exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩
· rintro x y ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩
refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;>
intros <;> simp only [zero_smul, add_smul]
· rintro c x ⟨a, ha, rfl⟩
refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩
rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul]
#align submodule.mem_ideal_smul_span_iff_exists_sum Submodule.mem_ideal_smul_span_iff_exists_sum
theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) :
x ∈ I • span R (f '' s) ↔
∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range]
#align submodule.mem_ideal_smul_span_iff_exists_sum' Submodule.mem_ideal_smul_span_iff_exists_sum'
theorem mem_smul_top_iff (N : Submodule R M) (x : N) :
x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by
change _ ↔ N.subtype x ∈ I • N
have : Submodule.map N.subtype (I • ⊤) = I • N := by
rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype]
rw [← this]
exact (Function.Injective.mem_set_image N.injective_subtype).symm
#align submodule.mem_smul_top_iff Submodule.mem_smul_top_iff
@[simp]
theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) :
I • S.comap f ≤ (I • S).comap f := by
refine Submodule.smul_le.mpr fun r hr x hx => ?_
rw [Submodule.mem_comap] at hx ⊢
rw [f.map_smul]
exact Submodule.smul_mem_smul hr hx
#align submodule.smul_comap_le_comap_smul Submodule.smul_comap_le_comap_smul
end CommSemiring
end Submodule
namespace Ideal
section Add
variable {R : Type u} [Semiring R]
@[simp]
theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J :=
rfl
#align ideal.add_eq_sup Ideal.add_eq_sup
@[simp]
theorem zero_eq_bot : (0 : Ideal R) = ⊥ :=
rfl
#align ideal.zero_eq_bot Ideal.zero_eq_bot
@[simp]
theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f :=
rfl
#align ideal.sum_eq_sup Ideal.sum_eq_sup
end Add
section MulAndRadical
variable {R : Type u} {ι : Type*} [CommSemiring R]
variable {I J K L : Ideal R}
instance : Mul (Ideal R) :=
⟨(· • ·)⟩
@[simp]
theorem one_eq_top : (1 : Ideal R) = ⊤ := by erw [Submodule.one_eq_range, LinearMap.range_id]
#align ideal.one_eq_top Ideal.one_eq_top
theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by
rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup]
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
Submodule.smul_mem_smul hr hs
#align ideal.mul_mem_mul Ideal.mul_mem_mul
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
#align ideal.mul_mem_mul_rev Ideal.mul_mem_mul_rev
theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n :=
Submodule.pow_mem_pow _ hx _
#align ideal.pow_mem_pow Ideal.pow_mem_pow
theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} :
(∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by
classical
refine Finset.induction_on s ?_ ?_
· intro
rw [Finset.prod_empty, Finset.prod_empty, one_eq_top]
exact Submodule.mem_top
· intro a s ha IH h
rw [Finset.prod_insert ha, Finset.prod_insert ha]
exact
mul_mem_mul (h a <| Finset.mem_insert_self a s)
(IH fun i hi => h i <| Finset.mem_insert_of_mem hi)
#align ideal.prod_mem_prod Ideal.prod_mem_prod
theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K :=
Submodule.smul_le
#align ideal.mul_le Ideal.mul_le
theorem mul_le_left : I * J ≤ J :=
Ideal.mul_le.2 fun _ _ _ => J.mul_mem_left _
#align ideal.mul_le_left Ideal.mul_le_left
theorem mul_le_right : I * J ≤ I :=
Ideal.mul_le.2 fun _ hr _ _ => I.mul_mem_right _ hr
#align ideal.mul_le_right Ideal.mul_le_right
@[simp]
theorem sup_mul_right_self : I ⊔ I * J = I :=
sup_eq_left.2 Ideal.mul_le_right
#align ideal.sup_mul_right_self Ideal.sup_mul_right_self
@[simp]
theorem sup_mul_left_self : I ⊔ J * I = I :=
sup_eq_left.2 Ideal.mul_le_left
#align ideal.sup_mul_left_self Ideal.sup_mul_left_self
@[simp]
theorem mul_right_self_sup : I * J ⊔ I = I :=
sup_eq_right.2 Ideal.mul_le_right
#align ideal.mul_right_self_sup Ideal.mul_right_self_sup
@[simp]
theorem mul_left_self_sup : J * I ⊔ I = I :=
sup_eq_right.2 Ideal.mul_le_left
#align ideal.mul_left_self_sup Ideal.mul_left_self_sup
variable (I J K)
protected theorem mul_comm : I * J = J * I :=
le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI)
(mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ)
#align ideal.mul_comm Ideal.mul_comm
protected theorem mul_assoc : I * J * K = I * (J * K) :=
Submodule.smul_assoc I J K
#align ideal.mul_assoc Ideal.mul_assoc
theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) :=
Submodule.span_smul_span S T
#align ideal.span_mul_span Ideal.span_mul_span
variable {I J K}
theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by
unfold span
rw [Submodule.span_mul_span]
#align ideal.span_mul_span' Ideal.span_mul_span'
theorem span_singleton_mul_span_singleton (r s : R) :
span {r} * span {s} = (span {r * s} : Ideal R) := by
unfold span
rw [Submodule.span_mul_span, Set.singleton_mul_singleton]
#align ideal.span_singleton_mul_span_singleton Ideal.span_singleton_mul_span_singleton
theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by
induction' n with n ih; · simp [Set.singleton_one]
simp only [pow_succ, ih, span_singleton_mul_span_singleton]
#align ideal.span_singleton_pow Ideal.span_singleton_pow
theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x :=
Submodule.mem_smul_span_singleton
#align ideal.mem_mul_span_singleton Ideal.mem_mul_span_singleton
theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by
simp only [mul_comm, mem_mul_span_singleton]
#align ideal.mem_span_singleton_mul Ideal.mem_span_singleton_mul
theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} :
I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI :=
show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by
simp only [mem_span_singleton_mul]
#align ideal.le_span_singleton_mul_iff Ideal.le_span_singleton_mul_iff
theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} :
span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by
simp only [mul_le, mem_span_singleton_mul, mem_span_singleton]
constructor
· intro h zI hzI
exact h x (dvd_refl x) zI hzI
· rintro h _ ⟨z, rfl⟩ zI hzI
rw [mul_comm x z, mul_assoc]
exact J.mul_mem_left _ (h zI hzI)
#align ideal.span_singleton_mul_le_iff Ideal.span_singleton_mul_le_iff
theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} :
span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by
simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm]
#align ideal.span_singleton_mul_le_span_singleton_mul Ideal.span_singleton_mul_le_span_singleton_mul
| Mathlib/RingTheory/Ideal/Operations.lean | 553 | 556 | theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) :
span {x} * I ≤ span {x} * J ↔ I ≤ J := by |
simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx,
exists_eq_right', SetLike.le_def]
|
/-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Analysis.SumOverResidueClass
#align_import analysis.p_series from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8"
/-!
# Convergence of `p`-series
In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`.
The proof is based on the
[Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k`
converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in
`NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove
`summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series.
## Tags
p-series, Cauchy condensation test
-/
/-!
### Schlömilch's generalization of the Cauchy condensation test
In this section we prove the Schlömilch's generalization of the Cauchy condensation test:
for a strictly increasing `u : ℕ → ℕ` with ratio of successive differences bounded and an
antitone `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`, `∑ k, f k` converges if and only if
so does `∑ k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it
into a series of lemmas with explicit estimates of partial sums of each series in terms of the
partial sums of the other series.
-/
/--
A sequence `u` has the property that its ratio of successive differences is bounded
when there is a positive real number `C` such that, for all n ∈ ℕ,
(u (n + 2) - u (n + 1)) ≤ C * (u (n + 1) - u n)
-/
def SuccDiffBounded (C : ℕ) (u : ℕ → ℕ) : Prop :=
∀ n : ℕ, u (n + 2) - u (n + 1) ≤ C • (u (n + 1) - u n)
namespace Finset
variable {M : Type*} [OrderedAddCommMonoid M] {f : ℕ → M} {u : ℕ → ℕ}
theorem le_sum_schlomilch' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ Ico (u 0) (u n), f k) ≤ ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by
induction' n with n ihn
· simp
suffices (∑ k ∈ Ico (u n) (u (n + 1)), f k) ≤ (u (n + 1) - u n) • f (u n) by
rw [sum_range_succ, ← sum_Ico_consecutive]
· exact add_le_add ihn this
exacts [hu n.zero_le, hu n.le_succ]
have : ∀ k ∈ Ico (u n) (u (n + 1)), f k ≤ f (u n) := fun k hk =>
hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem le_sum_condensed' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ Ico 1 (2 ^ n), f k) ≤ ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by
convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_le_pow_right one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
#align finset.le_sum_condensed' Finset.le_sum_condensed'
theorem le_sum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ range (u n), f k) ≤
∑ k ∈ range (u 0), f k + ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by
convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (∑ k ∈ range (u 0), f k)
rw [← sum_range_add_sum_Ico _ (hu n.zero_le)]
theorem le_sum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range (2 ^ n), f k) ≤ f 0 + ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by
convert add_le_add_left (le_sum_condensed' hf n) (f 0)
rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add]
#align finset.le_sum_condensed Finset.le_sum_condensed
theorem sum_schlomilch_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ range n, (u (k + 1) - u k) • f (u (k + 1))) ≤ ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by
induction' n with n ihn
· simp
suffices (u (n + 1) - u n) • f (u (n + 1)) ≤ ∑ k ∈ Ico (u n + 1) (u (n + 1) + 1), f k by
rw [sum_range_succ, ← sum_Ico_consecutive]
exacts [add_le_add ihn this,
(add_le_add_right (hu n.zero_le) _ : u 0 + 1 ≤ u n + 1),
add_le_add_right (hu n.le_succ) _]
have : ∀ k ∈ Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) ≤ f k := fun k hk =>
hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le
(mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2)
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem sum_condensed_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range n, 2 ^ k • f (2 ^ (k + 1))) ≤ ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by
convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_le_pow_right one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
#align finset.sum_condensed_le' Finset.sum_condensed_le'
theorem sum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : ℕ) :
∑ k ∈ range (n + 1), (u (k + 1) - u k) • f (u k) ≤
(u 1 - u 0) • f (u 0) + C • ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by
rw [sum_range_succ', add_comm]
gcongr
suffices ∑ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤
C • ∑ k ∈ range n, ((u (k + 1) - u k) • f (u (k + 1))) by
refine this.trans (nsmul_le_nsmul_right ?_ _)
exact sum_schlomilch_le' hf h_pos hu n
have : ∀ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤
C • ((u (k + 1) - u k) • f (u (k + 1))) := by
intro k _
rw [smul_smul]
gcongr
· exact h_nonneg (u (k + 1))
exact mod_cast h_succ_diff k
convert sum_le_sum this
simp [smul_sum]
theorem sum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range (n + 1), 2 ^ k • f (2 ^ k)) ≤ f 1 + 2 • ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by
convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1)
simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul]
#align finset.sum_condensed_le Finset.sum_condensed_le
end Finset
namespace ENNReal
open Filter Finset
variable {u : ℕ → ℕ} {f : ℕ → ℝ≥0∞}
open NNReal in
theorem le_tsum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : StrictMono u) :
∑' k , f k ≤ ∑ k ∈ range (u 0), f k + ∑' k : ℕ, (u (k + 1) - u k) * f (u k) := by
rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop]
refine iSup_le fun n =>
(Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _)
have (k : ℕ) : (u (k + 1) - u k : ℝ≥0∞) = (u (k + 1) - (u k : ℕ) : ℕ) := by
simp [NNReal.coe_sub (Nat.cast_le (α := ℝ≥0).mpr <| (hu k.lt_succ_self).le)]
simp only [nsmul_eq_mul, this]
apply ENNReal.sum_le_tsum
theorem le_tsum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
∑' k, f k ≤ f 0 + ∑' k : ℕ, 2 ^ k * f (2 ^ k) := by
rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)]
refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _)
simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two]
apply ENNReal.sum_le_tsum
#align ennreal.le_tsum_condensed ENNReal.le_tsum_condensed
theorem tsum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) :
∑' k : ℕ, (u (k + 1) - u k) * f (u k) ≤ (u 1 - u 0) * f (u 0) + C * ∑' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _)
simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n
exact zero_le _
theorem tsum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) :
(∑' k : ℕ, 2 ^ k * f (2 ^ k)) ≤ f 1 + 2 * ∑' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id), two_mul, ← two_nsmul]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(nsmul_le_nsmul_right (ENNReal.sum_le_tsum <| Finset.Ico 2 (2 ^ n + 1)) _) _)
simpa using Finset.sum_condensed_le hf n
#align ennreal.tsum_condensed_le ENNReal.tsum_condensed_le
end ENNReal
namespace NNReal
open Finset
open ENNReal in
/-- for a series of `NNReal` version. -/
theorem summable_schlomilch_iff {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ≥0}
(hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m)
(h_pos : ∀ n, 0 < u n) (hu_strict : StrictMono u)
(hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : ℕ => (u (k + 1) - (u k : ℝ≥0)) * f (u k)) ↔ Summable f := by
simp only [← tsum_coe_ne_top_iff_summable, Ne, not_iff_not, ENNReal.coe_mul]
constructor <;> intro h
· replace hf : ∀ m n, 1 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn)
have h_nonneg : ∀ n, 0 ≤ (f n : ℝ≥0∞) := fun n =>
ENNReal.coe_le_coe.2 (f n).2
obtain hC := tsum_schlomilch_le hf h_pos h_nonneg hu_strict.monotone h_succ_diff
simpa [add_eq_top, mul_ne_top, mul_eq_top, hC_nonzero] using eq_top_mono hC h
· replace hf : ∀ m n, 0 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf hm hmn)
have : ∑ k ∈ range (u 0), (f k : ℝ≥0∞) ≠ ∞ := (sum_lt_top fun a _ => coe_ne_top).ne
simpa [h, add_eq_top, this] using le_tsum_schlomilch hf h_pos hu_strict
open ENNReal in
theorem summable_condensed_iff {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
(Summable fun k : ℕ => (2 : ℝ≥0) ^ k * f (2 ^ k)) ↔ Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff hf (pow_pos zero_lt_two) (pow_right_strictMono _root_.one_lt_two)
two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
#align nnreal.summable_condensed_iff NNReal.summable_condensed_iff
end NNReal
open NNReal in
/-- for series of nonnegative real numbers. -/
theorem summable_schlomilch_iff_of_nonneg {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n)
(hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu_strict : StrictMono u) (hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : ℕ => (u (k + 1) - (u k : ℝ)) * f (u k)) ↔ Summable f := by
lift f to ℕ → ℝ≥0 using h_nonneg
simp only [NNReal.coe_le_coe] at *
have (k : ℕ) : (u (k + 1) - (u k : ℝ)) = ((u (k + 1) : ℝ≥0) - (u k : ℝ≥0) : ℝ≥0) := by
have := Nat.cast_le (α := ℝ≥0).mpr <| (hu_strict k.lt_succ_self).le
simp [NNReal.coe_sub this]
simp_rw [this]
exact_mod_cast NNReal.summable_schlomilch_iff hf h_pos hu_strict hC_nonzero h_succ_diff
/-- Cauchy condensation test for antitone series of nonnegative real numbers. -/
theorem summable_condensed_iff_of_nonneg {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n)
(h_mono : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
(Summable fun k : ℕ => (2 : ℝ) ^ k * f (2 ^ k)) ↔ Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff_of_nonneg h_nonneg h_mono (pow_pos zero_lt_two)
(pow_right_strictMono one_lt_two) two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
#align summable_condensed_iff_of_nonneg summable_condensed_iff_of_nonneg
section p_series
/-!
### Convergence of the `p`-series
In this section we prove that for a real number `p`, the series `∑' n : ℕ, 1 / (n ^ p)` converges if
and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the
Cauchy condensation test we formalized above. This test implies that `∑ n, 1 / (n ^ p)` converges if
and only if `∑ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with
common ratio `2 ^ {1 - p}`. -/
namespace Real
open Filter
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_rpow_inv {p : ℝ} :
Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by
rcases le_or_lt 0 p with hp | hp
/- Cauchy condensation test applies only to antitone sequences, so we consider the
cases `0 ≤ p` and `p < 0` separately. -/
· rw [← summable_condensed_iff_of_nonneg]
· simp_rw [Nat.cast_pow, Nat.cast_two, ← rpow_natCast, ← rpow_mul zero_lt_two.le, mul_comm _ p,
rpow_mul zero_lt_two.le, rpow_natCast, ← inv_pow, ← mul_pow,
summable_geometric_iff_norm_lt_one]
nth_rw 1 [← rpow_one 2]
rw [← division_def, ← rpow_sub zero_lt_two, norm_eq_abs,
abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le]
norm_num
· intro n
positivity
· intro m n hm hmn
gcongr
-- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges.
· suffices ¬Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) by
have : ¬1 < p := fun hp₁ => hp.not_le (zero_le_one.trans hp₁.le)
simpa only [this, iff_false]
intro h
obtain ⟨k : ℕ, hk₁ : ((k : ℝ) ^ p)⁻¹ < 1, hk₀ : k ≠ 0⟩ :=
((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and
(eventually_cofinite_ne 0)).exists
apply hk₀
rw [← pos_iff_ne_zero, ← @Nat.cast_pos ℝ] at hk₀
simpa [inv_lt_one_iff_of_pos (rpow_pos_of_pos hk₀ _), one_lt_rpow_iff_of_pos hk₀, hp,
hp.not_lt, hk₀] using hk₁
#align real.summable_nat_rpow_inv Real.summable_nat_rpow_inv
@[simp]
theorem summable_nat_rpow {p : ℝ} : Summable (fun n => (n : ℝ) ^ p : ℕ → ℝ) ↔ p < -1 := by
rcases neg_surjective p with ⟨p, rfl⟩
simp [rpow_neg]
#align real.summable_nat_rpow Real.summable_nat_rpow
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem summable_one_div_nat_rpow {p : ℝ} :
Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by
simp
#align real.summable_one_div_nat_rpow Real.summable_one_div_nat_rpow
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_pow_inv {p : ℕ} :
Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by
simp only [← rpow_natCast, summable_nat_rpow_inv, Nat.one_lt_cast]
#align real.summable_nat_pow_inv Real.summable_nat_pow_inv
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem summable_one_div_nat_pow {p : ℕ} :
Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by
simp only [one_div, Real.summable_nat_pow_inv]
#align real.summable_one_div_nat_pow Real.summable_one_div_nat_pow
/-- Summability of the `p`-series over `ℤ`. -/
theorem summable_one_div_int_pow {p : ℕ} :
(Summable fun n : ℤ ↦ 1 / (n : ℝ) ^ p) ↔ 1 < p := by
refine ⟨fun h ↦ summable_one_div_nat_pow.mp (h.comp_injective Nat.cast_injective),
fun h ↦ .of_nat_of_neg (summable_one_div_nat_pow.mpr h)
(((summable_one_div_nat_pow.mpr h).mul_left <| 1 / (-1 : ℝ) ^ p).congr fun n ↦ ?_)⟩
rw [Int.cast_neg, Int.cast_natCast, neg_eq_neg_one_mul (n : ℝ), mul_pow, mul_one_div, div_div]
#align real.summable_one_div_int_pow Real.summable_one_div_int_pow
theorem summable_abs_int_rpow {b : ℝ} (hb : 1 < b) :
Summable fun n : ℤ => |(n : ℝ)| ^ (-b) := by
apply Summable.of_nat_of_neg
on_goal 2 => simp_rw [Int.cast_neg, abs_neg]
all_goals
simp_rw [Int.cast_natCast, fun n : ℕ => abs_of_nonneg (n.cast_nonneg : 0 ≤ (n : ℝ))]
rwa [summable_nat_rpow, neg_lt_neg_iff]
#align real.summable_abs_int_rpow Real.summable_abs_int_rpow
/-- Harmonic series is not unconditionally summable. -/
theorem not_summable_natCast_inv : ¬Summable (fun n => n⁻¹ : ℕ → ℝ) := by
have : ¬Summable (fun n => ((n : ℝ) ^ 1)⁻¹ : ℕ → ℝ) :=
mt (summable_nat_pow_inv (p := 1)).1 (lt_irrefl 1)
simpa
#align real.not_summable_nat_cast_inv Real.not_summable_natCast_inv
@[deprecated (since := "2024-04-17")]
alias not_summable_nat_cast_inv := not_summable_natCast_inv
/-- Harmonic series is not unconditionally summable. -/
| Mathlib/Analysis/PSeries.lean | 355 | 356 | theorem not_summable_one_div_natCast : ¬Summable (fun n => 1 / n : ℕ → ℝ) := by |
simpa only [inv_eq_one_div] using not_summable_natCast_inv
|
/-
Copyright (c) 2024 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.Data.Matroid.Restrict
/-!
# Some constructions of matroids
This file defines some very elementary examples of matroids, namely those with at most one base.
## Main definitions
* `emptyOn α` is the matroid on `α` with empty ground set.
For `E : Set α`, ...
* `loopyOn E` is the matroid on `E` whose elements are all loops, or equivalently in which `∅`
is the only base.
* `freeOn E` is the 'free matroid' whose ground set `E` is the only base.
* For `I ⊆ E`, `uniqueBaseOn I E` is the matroid with ground set `E` in which `I` is the only base.
## Implementation details
To avoid the tedious process of certifying the matroid axioms for each of these easy examples,
we bootstrap the definitions starting with `emptyOn α` (which `simp` can prove is a matroid)
and then construct the other examples using duality and restriction.
-/
variable {α : Type*} {M : Matroid α} {E B I X R J : Set α}
namespace Matroid
open Set
section EmptyOn
/-- The `Matroid α` with empty ground set. -/
def emptyOn (α : Type*) : Matroid α where
E := ∅
Base := (· = ∅)
Indep := (· = ∅)
indep_iff' := by simp [subset_empty_iff]
exists_base := ⟨∅, rfl⟩
base_exchange := by rintro _ _ rfl; simp
maximality := by rintro _ _ _ rfl -; exact ⟨∅, by simp [mem_maximals_iff]⟩
subset_ground := by simp
@[simp] theorem emptyOn_ground : (emptyOn α).E = ∅ := rfl
@[simp] theorem emptyOn_base_iff : (emptyOn α).Base B ↔ B = ∅ := Iff.rfl
@[simp] theorem emptyOn_indep_iff : (emptyOn α).Indep I ↔ I = ∅ := Iff.rfl
theorem ground_eq_empty_iff : (M.E = ∅) ↔ M = emptyOn α := by
simp only [emptyOn, eq_iff_indep_iff_indep_forall, iff_self_and]
exact fun h ↦ by simp [h, subset_empty_iff]
@[simp] theorem emptyOn_dual_eq : (emptyOn α)✶ = emptyOn α := by
rw [← ground_eq_empty_iff]; rfl
@[simp] theorem restrict_empty (M : Matroid α) : M ↾ (∅ : Set α) = emptyOn α := by
simp [← ground_eq_empty_iff]
theorem eq_emptyOn_or_nonempty (M : Matroid α) : M = emptyOn α ∨ Matroid.Nonempty M := by
rw [← ground_eq_empty_iff]
exact M.E.eq_empty_or_nonempty.elim Or.inl (fun h ↦ Or.inr ⟨h⟩)
theorem eq_emptyOn [IsEmpty α] (M : Matroid α) : M = emptyOn α := by
rw [← ground_eq_empty_iff]
exact M.E.eq_empty_of_isEmpty
instance finite_emptyOn (α : Type*) : (emptyOn α).Finite :=
⟨finite_empty⟩
end EmptyOn
section LoopyOn
/-- The `Matroid α` with ground set `E` whose only base is `∅` -/
def loopyOn (E : Set α) : Matroid α := emptyOn α ↾ E
@[simp] theorem loopyOn_ground (E : Set α) : (loopyOn E).E = E := rfl
@[simp] theorem loopyOn_empty (α : Type*) : loopyOn (∅ : Set α) = emptyOn α := by
rw [← ground_eq_empty_iff, loopyOn_ground]
@[simp] theorem loopyOn_indep_iff : (loopyOn E).Indep I ↔ I = ∅ := by
simp only [loopyOn, restrict_indep_iff, emptyOn_indep_iff, and_iff_left_iff_imp]
rintro rfl; apply empty_subset
theorem eq_loopyOn_iff : M = loopyOn E ↔ M.E = E ∧ ∀ X ⊆ M.E, M.Indep X → X = ∅ := by
simp only [eq_iff_indep_iff_indep_forall, loopyOn_ground, loopyOn_indep_iff, and_congr_right_iff]
rintro rfl
refine ⟨fun h I hI ↦ (h I hI).1, fun h I hIE ↦ ⟨h I hIE, by rintro rfl; simp⟩⟩
@[simp] theorem loopyOn_base_iff : (loopyOn E).Base B ↔ B = ∅ := by
simp only [base_iff_maximal_indep, loopyOn_indep_iff, forall_eq, and_iff_left_iff_imp]
exact fun h _ ↦ h
@[simp] theorem loopyOn_basis_iff : (loopyOn E).Basis I X ↔ I = ∅ ∧ X ⊆ E :=
⟨fun h ↦ ⟨loopyOn_indep_iff.mp h.indep, h.subset_ground⟩,
by rintro ⟨rfl, hX⟩; rw [basis_iff]; simp⟩
instance : FiniteRk (loopyOn E) :=
⟨⟨∅, loopyOn_base_iff.2 rfl, finite_empty⟩⟩
theorem Finite.loopyOn_finite (hE : E.Finite) : Matroid.Finite (loopyOn E) :=
⟨hE⟩
@[simp] theorem loopyOn_restrict (E R : Set α) : (loopyOn E) ↾ R = loopyOn R := by
refine eq_of_indep_iff_indep_forall rfl ?_
simp only [restrict_ground_eq, restrict_indep_iff, loopyOn_indep_iff, and_iff_left_iff_imp]
exact fun _ h _ ↦ h
theorem empty_base_iff : M.Base ∅ ↔ M = loopyOn M.E := by
simp only [base_iff_maximal_indep, empty_indep, empty_subset, eq_comm (a := ∅), true_implies,
true_and, eq_iff_indep_iff_indep_forall, loopyOn_ground, loopyOn_indep_iff]
exact ⟨fun h I _ ↦ ⟨h I, by rintro rfl; simp⟩, fun h I hI ↦ (h I hI.subset_ground).1 hI⟩
theorem eq_loopyOn_or_rkPos (M : Matroid α) : M = loopyOn M.E ∨ RkPos M := by
rw [← empty_base_iff, rkPos_iff_empty_not_base]; apply em
theorem not_rkPos_iff : ¬RkPos M ↔ M = loopyOn M.E := by
rw [rkPos_iff_empty_not_base, not_iff_comm, empty_base_iff]
end LoopyOn
section FreeOn
/-- The `Matroid α` with ground set `E` whose only base is `E`. -/
def freeOn (E : Set α) : Matroid α := (loopyOn E)✶
@[simp] theorem freeOn_ground : (freeOn E).E = E := rfl
@[simp] theorem freeOn_dual_eq : (freeOn E)✶ = loopyOn E := by
rw [freeOn, dual_dual]
@[simp] theorem loopyOn_dual_eq : (loopyOn E)✶ = freeOn E := rfl
@[simp] theorem freeOn_empty (α : Type*) : freeOn (∅ : Set α) = emptyOn α := by
simp [freeOn]
@[simp] theorem freeOn_base_iff : (freeOn E).Base B ↔ B = E := by
simp only [freeOn, loopyOn_ground, dual_base_iff', loopyOn_base_iff, diff_eq_empty,
← subset_antisymm_iff, eq_comm (a := E)]
@[simp] theorem freeOn_indep_iff : (freeOn E).Indep I ↔ I ⊆ E := by
simp [indep_iff]
theorem freeOn_indep (hIE : I ⊆ E) : (freeOn E).Indep I :=
freeOn_indep_iff.2 hIE
@[simp] theorem freeOn_basis_iff : (freeOn E).Basis I X ↔ I = X ∧ X ⊆ E := by
use fun h ↦ ⟨(freeOn_indep h.subset_ground).eq_of_basis h ,h.subset_ground⟩
rintro ⟨rfl, hIE⟩
exact (freeOn_indep hIE).basis_self
@[simp] theorem freeOn_basis'_iff : (freeOn E).Basis' I X ↔ I = X ∩ E := by
rw [basis'_iff_basis_inter_ground, freeOn_basis_iff, freeOn_ground,
and_iff_left inter_subset_right]
theorem eq_freeOn_iff : M = freeOn E ↔ M.E = E ∧ M.Indep E := by
refine ⟨?_, fun h ↦ ?_⟩
· rintro rfl; simp [Subset.rfl]
simp only [eq_iff_indep_iff_indep_forall, freeOn_ground, freeOn_indep_iff, h.1, true_and]
exact fun I hIX ↦ iff_of_true (h.2.subset hIX) hIX
theorem ground_indep_iff_eq_freeOn : M.Indep M.E ↔ M = freeOn M.E := by
simp [eq_freeOn_iff]
theorem freeOn_restrict (h : R ⊆ E) : (freeOn E) ↾ R = freeOn R := by
simp [h, eq_freeOn_iff, Subset.rfl]
theorem restrict_eq_freeOn_iff : M ↾ I = freeOn I ↔ M.Indep I := by
rw [eq_freeOn_iff, and_iff_right M.restrict_ground_eq, restrict_indep_iff,
and_iff_left Subset.rfl]
theorem Indep.restrict_eq_freeOn (hI : M.Indep I) : M ↾ I = freeOn I := by
rwa [restrict_eq_freeOn_iff]
end FreeOn
section uniqueBaseOn
/-- The matroid on `E` whose unique base is the subset `I` of `E`.
Intended for use when `I ⊆ E`; if this not not the case, then the base is `I ∩ E`. -/
def uniqueBaseOn (I E : Set α) : Matroid α := freeOn I ↾ E
@[simp] theorem uniqueBaseOn_ground : (uniqueBaseOn I E).E = E :=
rfl
theorem uniqueBaseOn_base_iff (hIE : I ⊆ E) : (uniqueBaseOn I E).Base B ↔ B = I := by
rw [uniqueBaseOn, base_restrict_iff', freeOn_basis'_iff, inter_eq_self_of_subset_right hIE]
theorem uniqueBaseOn_inter_ground_eq (I E : Set α) :
uniqueBaseOn (I ∩ E) E = uniqueBaseOn I E := by
simp only [uniqueBaseOn, restrict_eq_restrict_iff, freeOn_indep_iff, subset_inter_iff,
iff_self_and]
tauto
@[simp] theorem uniqueBaseOn_indep_iff' : (uniqueBaseOn I E).Indep J ↔ J ⊆ I ∩ E := by
rw [uniqueBaseOn, restrict_indep_iff, freeOn_indep_iff, subset_inter_iff]
| Mathlib/Data/Matroid/Constructions.lean | 207 | 209 | theorem uniqueBaseOn_indep_iff (hIE : I ⊆ E) : (uniqueBaseOn I E).Indep J ↔ J ⊆ I := by |
rw [uniqueBaseOn, restrict_indep_iff, freeOn_indep_iff, and_iff_left_iff_imp]
exact fun h ↦ h.trans hIE
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.Algebra.Order.Group.MinMax
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Data.Finset.Preimage
import Mathlib.Order.Interval.Set.Disjoint
import Mathlib.Order.Interval.Set.OrderIso
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Filter.Bases
#align_import order.filter.at_top_bot from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58"
/-!
# `Filter.atTop` and `Filter.atBot` filters on preorders, monoids and groups.
In this file we define the filters
* `Filter.atTop`: corresponds to `n → +∞`;
* `Filter.atBot`: corresponds to `n → -∞`.
Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”.
-/
set_option autoImplicit true
variable {ι ι' α β γ : Type*}
open Set
namespace Filter
/-- `atTop` is the filter representing the limit `→ ∞` on an ordered set.
It is generated by the collection of up-sets `{b | a ≤ b}`.
(The preorder need not have a top element for this to be well defined,
and indeed is trivial when a top element exists.) -/
def atTop [Preorder α] : Filter α :=
⨅ a, 𝓟 (Ici a)
#align filter.at_top Filter.atTop
/-- `atBot` is the filter representing the limit `→ -∞` on an ordered set.
It is generated by the collection of down-sets `{b | b ≤ a}`.
(The preorder need not have a bottom element for this to be well defined,
and indeed is trivial when a bottom element exists.) -/
def atBot [Preorder α] : Filter α :=
⨅ a, 𝓟 (Iic a)
#align filter.at_bot Filter.atBot
theorem mem_atTop [Preorder α] (a : α) : { b : α | a ≤ b } ∈ @atTop α _ :=
mem_iInf_of_mem a <| Subset.refl _
#align filter.mem_at_top Filter.mem_atTop
theorem Ici_mem_atTop [Preorder α] (a : α) : Ici a ∈ (atTop : Filter α) :=
mem_atTop a
#align filter.Ici_mem_at_top Filter.Ici_mem_atTop
theorem Ioi_mem_atTop [Preorder α] [NoMaxOrder α] (x : α) : Ioi x ∈ (atTop : Filter α) :=
let ⟨z, hz⟩ := exists_gt x
mem_of_superset (mem_atTop z) fun _ h => lt_of_lt_of_le hz h
#align filter.Ioi_mem_at_top Filter.Ioi_mem_atTop
theorem mem_atBot [Preorder α] (a : α) : { b : α | b ≤ a } ∈ @atBot α _ :=
mem_iInf_of_mem a <| Subset.refl _
#align filter.mem_at_bot Filter.mem_atBot
theorem Iic_mem_atBot [Preorder α] (a : α) : Iic a ∈ (atBot : Filter α) :=
mem_atBot a
#align filter.Iic_mem_at_bot Filter.Iic_mem_atBot
theorem Iio_mem_atBot [Preorder α] [NoMinOrder α] (x : α) : Iio x ∈ (atBot : Filter α) :=
let ⟨z, hz⟩ := exists_lt x
mem_of_superset (mem_atBot z) fun _ h => lt_of_le_of_lt h hz
#align filter.Iio_mem_at_bot Filter.Iio_mem_atBot
theorem disjoint_atBot_principal_Ioi [Preorder α] (x : α) : Disjoint atBot (𝓟 (Ioi x)) :=
disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl) (Iic_mem_atBot x) (mem_principal_self _)
#align filter.disjoint_at_bot_principal_Ioi Filter.disjoint_atBot_principal_Ioi
theorem disjoint_atTop_principal_Iio [Preorder α] (x : α) : Disjoint atTop (𝓟 (Iio x)) :=
@disjoint_atBot_principal_Ioi αᵒᵈ _ _
#align filter.disjoint_at_top_principal_Iio Filter.disjoint_atTop_principal_Iio
theorem disjoint_atTop_principal_Iic [Preorder α] [NoMaxOrder α] (x : α) :
Disjoint atTop (𝓟 (Iic x)) :=
disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl).symm (Ioi_mem_atTop x)
(mem_principal_self _)
#align filter.disjoint_at_top_principal_Iic Filter.disjoint_atTop_principal_Iic
theorem disjoint_atBot_principal_Ici [Preorder α] [NoMinOrder α] (x : α) :
Disjoint atBot (𝓟 (Ici x)) :=
@disjoint_atTop_principal_Iic αᵒᵈ _ _ _
#align filter.disjoint_at_bot_principal_Ici Filter.disjoint_atBot_principal_Ici
theorem disjoint_pure_atTop [Preorder α] [NoMaxOrder α] (x : α) : Disjoint (pure x) atTop :=
Disjoint.symm <| (disjoint_atTop_principal_Iic x).mono_right <| le_principal_iff.2 <|
mem_pure.2 right_mem_Iic
#align filter.disjoint_pure_at_top Filter.disjoint_pure_atTop
theorem disjoint_pure_atBot [Preorder α] [NoMinOrder α] (x : α) : Disjoint (pure x) atBot :=
@disjoint_pure_atTop αᵒᵈ _ _ _
#align filter.disjoint_pure_at_bot Filter.disjoint_pure_atBot
theorem not_tendsto_const_atTop [Preorder α] [NoMaxOrder α] (x : α) (l : Filter β) [l.NeBot] :
¬Tendsto (fun _ => x) l atTop :=
tendsto_const_pure.not_tendsto (disjoint_pure_atTop x)
#align filter.not_tendsto_const_at_top Filter.not_tendsto_const_atTop
theorem not_tendsto_const_atBot [Preorder α] [NoMinOrder α] (x : α) (l : Filter β) [l.NeBot] :
¬Tendsto (fun _ => x) l atBot :=
tendsto_const_pure.not_tendsto (disjoint_pure_atBot x)
#align filter.not_tendsto_const_at_bot Filter.not_tendsto_const_atBot
theorem disjoint_atBot_atTop [PartialOrder α] [Nontrivial α] :
Disjoint (atBot : Filter α) atTop := by
rcases exists_pair_ne α with ⟨x, y, hne⟩
by_cases hle : x ≤ y
· refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot x) (Ici_mem_atTop y)
exact Iic_disjoint_Ici.2 (hle.lt_of_ne hne).not_le
· refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot y) (Ici_mem_atTop x)
exact Iic_disjoint_Ici.2 hle
#align filter.disjoint_at_bot_at_top Filter.disjoint_atBot_atTop
theorem disjoint_atTop_atBot [PartialOrder α] [Nontrivial α] : Disjoint (atTop : Filter α) atBot :=
disjoint_atBot_atTop.symm
#align filter.disjoint_at_top_at_bot Filter.disjoint_atTop_atBot
theorem hasAntitoneBasis_atTop [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] :
(@atTop α _).HasAntitoneBasis Ici :=
.iInf_principal fun _ _ ↦ Ici_subset_Ici.2
theorem atTop_basis [Nonempty α] [SemilatticeSup α] : (@atTop α _).HasBasis (fun _ => True) Ici :=
hasAntitoneBasis_atTop.1
#align filter.at_top_basis Filter.atTop_basis
theorem atTop_eq_generate_Ici [SemilatticeSup α] : atTop = generate (range (Ici (α := α))) := by
rcases isEmpty_or_nonempty α with hα|hα
· simp only [eq_iff_true_of_subsingleton]
· simp [(atTop_basis (α := α)).eq_generate, range]
theorem atTop_basis' [SemilatticeSup α] (a : α) : (@atTop α _).HasBasis (fun x => a ≤ x) Ici :=
⟨fun _ =>
(@atTop_basis α ⟨a⟩ _).mem_iff.trans
⟨fun ⟨x, _, hx⟩ => ⟨x ⊔ a, le_sup_right, fun _y hy => hx (le_trans le_sup_left hy)⟩,
fun ⟨x, _, hx⟩ => ⟨x, trivial, hx⟩⟩⟩
#align filter.at_top_basis' Filter.atTop_basis'
theorem atBot_basis [Nonempty α] [SemilatticeInf α] : (@atBot α _).HasBasis (fun _ => True) Iic :=
@atTop_basis αᵒᵈ _ _
#align filter.at_bot_basis Filter.atBot_basis
theorem atBot_basis' [SemilatticeInf α] (a : α) : (@atBot α _).HasBasis (fun x => x ≤ a) Iic :=
@atTop_basis' αᵒᵈ _ _
#align filter.at_bot_basis' Filter.atBot_basis'
@[instance]
theorem atTop_neBot [Nonempty α] [SemilatticeSup α] : NeBot (atTop : Filter α) :=
atTop_basis.neBot_iff.2 fun _ => nonempty_Ici
#align filter.at_top_ne_bot Filter.atTop_neBot
@[instance]
theorem atBot_neBot [Nonempty α] [SemilatticeInf α] : NeBot (atBot : Filter α) :=
@atTop_neBot αᵒᵈ _ _
#align filter.at_bot_ne_bot Filter.atBot_neBot
@[simp]
theorem mem_atTop_sets [Nonempty α] [SemilatticeSup α] {s : Set α} :
s ∈ (atTop : Filter α) ↔ ∃ a : α, ∀ b ≥ a, b ∈ s :=
atTop_basis.mem_iff.trans <| exists_congr fun _ => true_and_iff _
#align filter.mem_at_top_sets Filter.mem_atTop_sets
@[simp]
theorem mem_atBot_sets [Nonempty α] [SemilatticeInf α] {s : Set α} :
s ∈ (atBot : Filter α) ↔ ∃ a : α, ∀ b ≤ a, b ∈ s :=
@mem_atTop_sets αᵒᵈ _ _ _
#align filter.mem_at_bot_sets Filter.mem_atBot_sets
@[simp]
theorem eventually_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop} :
(∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ b ≥ a, p b :=
mem_atTop_sets
#align filter.eventually_at_top Filter.eventually_atTop
@[simp]
theorem eventually_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop} :
(∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ b ≤ a, p b :=
mem_atBot_sets
#align filter.eventually_at_bot Filter.eventually_atBot
theorem eventually_ge_atTop [Preorder α] (a : α) : ∀ᶠ x in atTop, a ≤ x :=
mem_atTop a
#align filter.eventually_ge_at_top Filter.eventually_ge_atTop
theorem eventually_le_atBot [Preorder α] (a : α) : ∀ᶠ x in atBot, x ≤ a :=
mem_atBot a
#align filter.eventually_le_at_bot Filter.eventually_le_atBot
theorem eventually_gt_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, a < x :=
Ioi_mem_atTop a
#align filter.eventually_gt_at_top Filter.eventually_gt_atTop
theorem eventually_ne_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, x ≠ a :=
(eventually_gt_atTop a).mono fun _ => ne_of_gt
#align filter.eventually_ne_at_top Filter.eventually_ne_atTop
protected theorem Tendsto.eventually_gt_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c < f x :=
hf.eventually (eventually_gt_atTop c)
#align filter.tendsto.eventually_gt_at_top Filter.Tendsto.eventually_gt_atTop
protected theorem Tendsto.eventually_ge_atTop [Preorder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c ≤ f x :=
hf.eventually (eventually_ge_atTop c)
#align filter.tendsto.eventually_ge_at_top Filter.Tendsto.eventually_ge_atTop
protected theorem Tendsto.eventually_ne_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, f x ≠ c :=
hf.eventually (eventually_ne_atTop c)
#align filter.tendsto.eventually_ne_at_top Filter.Tendsto.eventually_ne_atTop
protected theorem Tendsto.eventually_ne_atTop' [Preorder β] [NoMaxOrder β] {f : α → β}
{l : Filter α} (hf : Tendsto f l atTop) (c : α) : ∀ᶠ x in l, x ≠ c :=
(hf.eventually_ne_atTop (f c)).mono fun _ => ne_of_apply_ne f
#align filter.tendsto.eventually_ne_at_top' Filter.Tendsto.eventually_ne_atTop'
theorem eventually_lt_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x < a :=
Iio_mem_atBot a
#align filter.eventually_lt_at_bot Filter.eventually_lt_atBot
theorem eventually_ne_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x ≠ a :=
(eventually_lt_atBot a).mono fun _ => ne_of_lt
#align filter.eventually_ne_at_bot Filter.eventually_ne_atBot
protected theorem Tendsto.eventually_lt_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x < c :=
hf.eventually (eventually_lt_atBot c)
#align filter.tendsto.eventually_lt_at_bot Filter.Tendsto.eventually_lt_atBot
protected theorem Tendsto.eventually_le_atBot [Preorder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≤ c :=
hf.eventually (eventually_le_atBot c)
#align filter.tendsto.eventually_le_at_bot Filter.Tendsto.eventually_le_atBot
protected theorem Tendsto.eventually_ne_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≠ c :=
hf.eventually (eventually_ne_atBot c)
#align filter.tendsto.eventually_ne_at_bot Filter.Tendsto.eventually_ne_atBot
theorem eventually_forall_ge_atTop [Preorder α] {p : α → Prop} :
(∀ᶠ x in atTop, ∀ y, x ≤ y → p y) ↔ ∀ᶠ x in atTop, p x := by
refine ⟨fun h ↦ h.mono fun x hx ↦ hx x le_rfl, fun h ↦ ?_⟩
rcases (hasBasis_iInf_principal_finite _).eventually_iff.1 h with ⟨S, hSf, hS⟩
refine mem_iInf_of_iInter hSf (V := fun x ↦ Ici x.1) (fun _ ↦ Subset.rfl) fun x hx y hy ↦ ?_
simp only [mem_iInter] at hS hx
exact hS fun z hz ↦ le_trans (hx ⟨z, hz⟩) hy
theorem eventually_forall_le_atBot [Preorder α] {p : α → Prop} :
(∀ᶠ x in atBot, ∀ y, y ≤ x → p y) ↔ ∀ᶠ x in atBot, p x :=
eventually_forall_ge_atTop (α := αᵒᵈ)
theorem Tendsto.eventually_forall_ge_atTop {α β : Type*} [Preorder β] {l : Filter α}
{p : β → Prop} {f : α → β} (hf : Tendsto f l atTop) (h_evtl : ∀ᶠ x in atTop, p x) :
∀ᶠ x in l, ∀ y, f x ≤ y → p y := by
rw [← Filter.eventually_forall_ge_atTop] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap
theorem Tendsto.eventually_forall_le_atBot {α β : Type*} [Preorder β] {l : Filter α}
{p : β → Prop} {f : α → β} (hf : Tendsto f l atBot) (h_evtl : ∀ᶠ x in atBot, p x) :
∀ᶠ x in l, ∀ y, y ≤ f x → p y := by
rw [← Filter.eventually_forall_le_atBot] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap
theorem atTop_basis_Ioi [Nonempty α] [SemilatticeSup α] [NoMaxOrder α] :
(@atTop α _).HasBasis (fun _ => True) Ioi :=
atTop_basis.to_hasBasis (fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩) fun a ha =>
(exists_gt a).imp fun _b hb => ⟨ha, Ici_subset_Ioi.2 hb⟩
#align filter.at_top_basis_Ioi Filter.atTop_basis_Ioi
lemma atTop_basis_Ioi' [SemilatticeSup α] [NoMaxOrder α] (a : α) : atTop.HasBasis (a < ·) Ioi :=
have : Nonempty α := ⟨a⟩
atTop_basis_Ioi.to_hasBasis (fun b _ ↦
let ⟨c, hc⟩ := exists_gt (a ⊔ b)
⟨c, le_sup_left.trans_lt hc, Ioi_subset_Ioi <| le_sup_right.trans hc.le⟩) fun b _ ↦
⟨b, trivial, Subset.rfl⟩
theorem atTop_countable_basis [Nonempty α] [SemilatticeSup α] [Countable α] :
HasCountableBasis (atTop : Filter α) (fun _ => True) Ici :=
{ atTop_basis with countable := to_countable _ }
#align filter.at_top_countable_basis Filter.atTop_countable_basis
theorem atBot_countable_basis [Nonempty α] [SemilatticeInf α] [Countable α] :
HasCountableBasis (atBot : Filter α) (fun _ => True) Iic :=
{ atBot_basis with countable := to_countable _ }
#align filter.at_bot_countable_basis Filter.atBot_countable_basis
instance (priority := 200) atTop.isCountablyGenerated [Preorder α] [Countable α] :
(atTop : Filter <| α).IsCountablyGenerated :=
isCountablyGenerated_seq _
#align filter.at_top.is_countably_generated Filter.atTop.isCountablyGenerated
instance (priority := 200) atBot.isCountablyGenerated [Preorder α] [Countable α] :
(atBot : Filter <| α).IsCountablyGenerated :=
isCountablyGenerated_seq _
#align filter.at_bot.is_countably_generated Filter.atBot.isCountablyGenerated
theorem _root_.IsTop.atTop_eq [Preorder α] {a : α} (ha : IsTop a) : atTop = 𝓟 (Ici a) :=
(iInf_le _ _).antisymm <| le_iInf fun b ↦ principal_mono.2 <| Ici_subset_Ici.2 <| ha b
theorem _root_.IsBot.atBot_eq [Preorder α] {a : α} (ha : IsBot a) : atBot = 𝓟 (Iic a) :=
ha.toDual.atTop_eq
theorem OrderTop.atTop_eq (α) [PartialOrder α] [OrderTop α] : (atTop : Filter α) = pure ⊤ := by
rw [isTop_top.atTop_eq, Ici_top, principal_singleton]
#align filter.order_top.at_top_eq Filter.OrderTop.atTop_eq
theorem OrderBot.atBot_eq (α) [PartialOrder α] [OrderBot α] : (atBot : Filter α) = pure ⊥ :=
@OrderTop.atTop_eq αᵒᵈ _ _
#align filter.order_bot.at_bot_eq Filter.OrderBot.atBot_eq
@[nontriviality]
theorem Subsingleton.atTop_eq (α) [Subsingleton α] [Preorder α] : (atTop : Filter α) = ⊤ := by
refine top_unique fun s hs x => ?_
rw [atTop, ciInf_subsingleton x, mem_principal] at hs
exact hs left_mem_Ici
#align filter.subsingleton.at_top_eq Filter.Subsingleton.atTop_eq
@[nontriviality]
theorem Subsingleton.atBot_eq (α) [Subsingleton α] [Preorder α] : (atBot : Filter α) = ⊤ :=
@Subsingleton.atTop_eq αᵒᵈ _ _
#align filter.subsingleton.at_bot_eq Filter.Subsingleton.atBot_eq
theorem tendsto_atTop_pure [PartialOrder α] [OrderTop α] (f : α → β) :
Tendsto f atTop (pure <| f ⊤) :=
(OrderTop.atTop_eq α).symm ▸ tendsto_pure_pure _ _
#align filter.tendsto_at_top_pure Filter.tendsto_atTop_pure
theorem tendsto_atBot_pure [PartialOrder α] [OrderBot α] (f : α → β) :
Tendsto f atBot (pure <| f ⊥) :=
@tendsto_atTop_pure αᵒᵈ _ _ _ _
#align filter.tendsto_at_bot_pure Filter.tendsto_atBot_pure
theorem Eventually.exists_forall_of_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop}
(h : ∀ᶠ x in atTop, p x) : ∃ a, ∀ b ≥ a, p b :=
eventually_atTop.mp h
#align filter.eventually.exists_forall_of_at_top Filter.Eventually.exists_forall_of_atTop
theorem Eventually.exists_forall_of_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop}
(h : ∀ᶠ x in atBot, p x) : ∃ a, ∀ b ≤ a, p b :=
eventually_atBot.mp h
#align filter.eventually.exists_forall_of_at_bot Filter.Eventually.exists_forall_of_atBot
lemma exists_eventually_atTop [SemilatticeSup α] [Nonempty α] {r : α → β → Prop} :
(∃ b, ∀ᶠ a in atTop, r a b) ↔ ∀ᶠ a₀ in atTop, ∃ b, ∀ a ≥ a₀, r a b := by
simp_rw [eventually_atTop, ← exists_swap (α := α)]
exact exists_congr fun a ↦ .symm <| forall_ge_iff <| Monotone.exists fun _ _ _ hb H n hn ↦
H n (hb.trans hn)
lemma exists_eventually_atBot [SemilatticeInf α] [Nonempty α] {r : α → β → Prop} :
(∃ b, ∀ᶠ a in atBot, r a b) ↔ ∀ᶠ a₀ in atBot, ∃ b, ∀ a ≤ a₀, r a b := by
simp_rw [eventually_atBot, ← exists_swap (α := α)]
exact exists_congr fun a ↦ .symm <| forall_le_iff <| Antitone.exists fun _ _ _ hb H n hn ↦
H n (hn.trans hb)
theorem frequently_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop} :
(∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b ≥ a, p b :=
atTop_basis.frequently_iff.trans <| by simp
#align filter.frequently_at_top Filter.frequently_atTop
theorem frequently_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop} :
(∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b ≤ a, p b :=
@frequently_atTop αᵒᵈ _ _ _
#align filter.frequently_at_bot Filter.frequently_atBot
theorem frequently_atTop' [SemilatticeSup α] [Nonempty α] [NoMaxOrder α] {p : α → Prop} :
(∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b > a, p b :=
atTop_basis_Ioi.frequently_iff.trans <| by simp
#align filter.frequently_at_top' Filter.frequently_atTop'
theorem frequently_atBot' [SemilatticeInf α] [Nonempty α] [NoMinOrder α] {p : α → Prop} :
(∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b < a, p b :=
@frequently_atTop' αᵒᵈ _ _ _ _
#align filter.frequently_at_bot' Filter.frequently_atBot'
theorem Frequently.forall_exists_of_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop}
(h : ∃ᶠ x in atTop, p x) : ∀ a, ∃ b ≥ a, p b :=
frequently_atTop.mp h
#align filter.frequently.forall_exists_of_at_top Filter.Frequently.forall_exists_of_atTop
theorem Frequently.forall_exists_of_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop}
(h : ∃ᶠ x in atBot, p x) : ∀ a, ∃ b ≤ a, p b :=
frequently_atBot.mp h
#align filter.frequently.forall_exists_of_at_bot Filter.Frequently.forall_exists_of_atBot
theorem map_atTop_eq [Nonempty α] [SemilatticeSup α] {f : α → β} :
atTop.map f = ⨅ a, 𝓟 (f '' { a' | a ≤ a' }) :=
(atTop_basis.map f).eq_iInf
#align filter.map_at_top_eq Filter.map_atTop_eq
theorem map_atBot_eq [Nonempty α] [SemilatticeInf α] {f : α → β} :
atBot.map f = ⨅ a, 𝓟 (f '' { a' | a' ≤ a }) :=
@map_atTop_eq αᵒᵈ _ _ _ _
#align filter.map_at_bot_eq Filter.map_atBot_eq
theorem tendsto_atTop [Preorder β] {m : α → β} {f : Filter α} :
Tendsto m f atTop ↔ ∀ b, ∀ᶠ a in f, b ≤ m a := by
simp only [atTop, tendsto_iInf, tendsto_principal, mem_Ici]
#align filter.tendsto_at_top Filter.tendsto_atTop
theorem tendsto_atBot [Preorder β] {m : α → β} {f : Filter α} :
Tendsto m f atBot ↔ ∀ b, ∀ᶠ a in f, m a ≤ b :=
@tendsto_atTop α βᵒᵈ _ m f
#align filter.tendsto_at_bot Filter.tendsto_atBot
theorem tendsto_atTop_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂)
(h₁ : Tendsto f₁ l atTop) : Tendsto f₂ l atTop :=
tendsto_atTop.2 fun b => by filter_upwards [tendsto_atTop.1 h₁ b, h] with x using le_trans
#align filter.tendsto_at_top_mono' Filter.tendsto_atTop_mono'
theorem tendsto_atBot_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) :
Tendsto f₂ l atBot → Tendsto f₁ l atBot :=
@tendsto_atTop_mono' _ βᵒᵈ _ _ _ _ h
#align filter.tendsto_at_bot_mono' Filter.tendsto_atBot_mono'
theorem tendsto_atTop_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :
Tendsto f l atTop → Tendsto g l atTop :=
tendsto_atTop_mono' l <| eventually_of_forall h
#align filter.tendsto_at_top_mono Filter.tendsto_atTop_mono
theorem tendsto_atBot_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :
Tendsto g l atBot → Tendsto f l atBot :=
@tendsto_atTop_mono _ βᵒᵈ _ _ _ _ h
#align filter.tendsto_at_bot_mono Filter.tendsto_atBot_mono
lemma atTop_eq_generate_of_forall_exists_le [LinearOrder α] {s : Set α} (hs : ∀ x, ∃ y ∈ s, x ≤ y) :
(atTop : Filter α) = generate (Ici '' s) := by
rw [atTop_eq_generate_Ici]
apply le_antisymm
· rw [le_generate_iff]
rintro - ⟨y, -, rfl⟩
exact mem_generate_of_mem ⟨y, rfl⟩
· rw [le_generate_iff]
rintro - ⟨x, -, -, rfl⟩
rcases hs x with ⟨y, ys, hy⟩
have A : Ici y ∈ generate (Ici '' s) := mem_generate_of_mem (mem_image_of_mem _ ys)
have B : Ici y ⊆ Ici x := Ici_subset_Ici.2 hy
exact sets_of_superset (generate (Ici '' s)) A B
lemma atTop_eq_generate_of_not_bddAbove [LinearOrder α] {s : Set α} (hs : ¬ BddAbove s) :
(atTop : Filter α) = generate (Ici '' s) := by
refine atTop_eq_generate_of_forall_exists_le fun x ↦ ?_
obtain ⟨y, hy, hy'⟩ := not_bddAbove_iff.mp hs x
exact ⟨y, hy, hy'.le⟩
end Filter
namespace OrderIso
open Filter
variable [Preorder α] [Preorder β]
@[simp]
theorem comap_atTop (e : α ≃o β) : comap e atTop = atTop := by
simp [atTop, ← e.surjective.iInf_comp]
#align order_iso.comap_at_top OrderIso.comap_atTop
@[simp]
theorem comap_atBot (e : α ≃o β) : comap e atBot = atBot :=
e.dual.comap_atTop
#align order_iso.comap_at_bot OrderIso.comap_atBot
@[simp]
theorem map_atTop (e : α ≃o β) : map (e : α → β) atTop = atTop := by
rw [← e.comap_atTop, map_comap_of_surjective e.surjective]
#align order_iso.map_at_top OrderIso.map_atTop
@[simp]
theorem map_atBot (e : α ≃o β) : map (e : α → β) atBot = atBot :=
e.dual.map_atTop
#align order_iso.map_at_bot OrderIso.map_atBot
theorem tendsto_atTop (e : α ≃o β) : Tendsto e atTop atTop :=
e.map_atTop.le
#align order_iso.tendsto_at_top OrderIso.tendsto_atTop
theorem tendsto_atBot (e : α ≃o β) : Tendsto e atBot atBot :=
e.map_atBot.le
#align order_iso.tendsto_at_bot OrderIso.tendsto_atBot
@[simp]
theorem tendsto_atTop_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) :
Tendsto (fun x => e (f x)) l atTop ↔ Tendsto f l atTop := by
rw [← e.comap_atTop, tendsto_comap_iff, Function.comp_def]
#align order_iso.tendsto_at_top_iff OrderIso.tendsto_atTop_iff
@[simp]
theorem tendsto_atBot_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) :
Tendsto (fun x => e (f x)) l atBot ↔ Tendsto f l atBot :=
e.dual.tendsto_atTop_iff
#align order_iso.tendsto_at_bot_iff OrderIso.tendsto_atBot_iff
end OrderIso
namespace Filter
/-!
### Sequences
-/
theorem inf_map_atTop_neBot_iff [SemilatticeSup α] [Nonempty α] {F : Filter β} {u : α → β} :
NeBot (F ⊓ map u atTop) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U := by
simp_rw [inf_neBot_iff_frequently_left, frequently_map, frequently_atTop]; rfl
#align filter.inf_map_at_top_ne_bot_iff Filter.inf_map_atTop_neBot_iff
theorem inf_map_atBot_neBot_iff [SemilatticeInf α] [Nonempty α] {F : Filter β} {u : α → β} :
NeBot (F ⊓ map u atBot) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U :=
@inf_map_atTop_neBot_iff αᵒᵈ _ _ _ _ _
#align filter.inf_map_at_bot_ne_bot_iff Filter.inf_map_atBot_neBot_iff
theorem extraction_of_frequently_atTop' {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by
choose u hu hu' using h
refine ⟨fun n => u^[n + 1] 0, strictMono_nat_of_lt_succ fun n => ?_, fun n => ?_⟩
· exact Trans.trans (hu _) (Function.iterate_succ_apply' _ _ _).symm
· simpa only [Function.iterate_succ_apply'] using hu' _
#align filter.extraction_of_frequently_at_top' Filter.extraction_of_frequently_atTop'
theorem extraction_of_frequently_atTop {P : ℕ → Prop} (h : ∃ᶠ n in atTop, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by
rw [frequently_atTop'] at h
exact extraction_of_frequently_atTop' h
#align filter.extraction_of_frequently_at_top Filter.extraction_of_frequently_atTop
theorem extraction_of_eventually_atTop {P : ℕ → Prop} (h : ∀ᶠ n in atTop, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) :=
extraction_of_frequently_atTop h.frequently
#align filter.extraction_of_eventually_at_top Filter.extraction_of_eventually_atTop
theorem extraction_forall_of_frequently {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ᶠ k in atTop, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := by
simp only [frequently_atTop'] at h
choose u hu hu' using h
use (fun n => Nat.recOn n (u 0 0) fun n v => u (n + 1) v : ℕ → ℕ)
constructor
· apply strictMono_nat_of_lt_succ
intro n
apply hu
· intro n
cases n <;> simp [hu']
#align filter.extraction_forall_of_frequently Filter.extraction_forall_of_frequently
theorem extraction_forall_of_eventually {P : ℕ → ℕ → Prop} (h : ∀ n, ∀ᶠ k in atTop, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_frequently fun n => (h n).frequently
#align filter.extraction_forall_of_eventually Filter.extraction_forall_of_eventually
theorem extraction_forall_of_eventually' {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ N, ∀ k ≥ N, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_eventually (by simp [eventually_atTop, h])
#align filter.extraction_forall_of_eventually' Filter.extraction_forall_of_eventually'
theorem Eventually.atTop_of_arithmetic {p : ℕ → Prop} {n : ℕ} (hn : n ≠ 0)
(hp : ∀ k < n, ∀ᶠ a in atTop, p (n * a + k)) : ∀ᶠ a in atTop, p a := by
simp only [eventually_atTop] at hp ⊢
choose! N hN using hp
refine ⟨(Finset.range n).sup (n * N ·), fun b hb => ?_⟩
rw [← Nat.div_add_mod b n]
have hlt := Nat.mod_lt b hn.bot_lt
refine hN _ hlt _ ?_
rw [ge_iff_le, Nat.le_div_iff_mul_le hn.bot_lt, mul_comm]
exact (Finset.le_sup (f := (n * N ·)) (Finset.mem_range.2 hlt)).trans hb
theorem exists_le_of_tendsto_atTop [SemilatticeSup α] [Preorder β] {u : α → β}
(h : Tendsto u atTop atTop) (a : α) (b : β) : ∃ a' ≥ a, b ≤ u a' := by
have : Nonempty α := ⟨a⟩
have : ∀ᶠ x in atTop, a ≤ x ∧ b ≤ u x :=
(eventually_ge_atTop a).and (h.eventually <| eventually_ge_atTop b)
exact this.exists
#align filter.exists_le_of_tendsto_at_top Filter.exists_le_of_tendsto_atTop
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem exists_le_of_tendsto_atBot [SemilatticeSup α] [Preorder β] {u : α → β}
(h : Tendsto u atTop atBot) : ∀ a b, ∃ a' ≥ a, u a' ≤ b :=
@exists_le_of_tendsto_atTop _ βᵒᵈ _ _ _ h
#align filter.exists_le_of_tendsto_at_bot Filter.exists_le_of_tendsto_atBot
theorem exists_lt_of_tendsto_atTop [SemilatticeSup α] [Preorder β] [NoMaxOrder β] {u : α → β}
(h : Tendsto u atTop atTop) (a : α) (b : β) : ∃ a' ≥ a, b < u a' := by
cases' exists_gt b with b' hb'
rcases exists_le_of_tendsto_atTop h a b' with ⟨a', ha', ha''⟩
exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩
#align filter.exists_lt_of_tendsto_at_top Filter.exists_lt_of_tendsto_atTop
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem exists_lt_of_tendsto_atBot [SemilatticeSup α] [Preorder β] [NoMinOrder β] {u : α → β}
(h : Tendsto u atTop atBot) : ∀ a b, ∃ a' ≥ a, u a' < b :=
@exists_lt_of_tendsto_atTop _ βᵒᵈ _ _ _ _ h
#align filter.exists_lt_of_tendsto_at_bot Filter.exists_lt_of_tendsto_atBot
/-- If `u` is a sequence which is unbounded above,
then after any point, it reaches a value strictly greater than all previous values.
-/
theorem high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) :
∀ N, ∃ n ≥ N, ∀ k < n, u k < u n := by
intro N
obtain ⟨k : ℕ, - : k ≤ N, hku : ∀ l ≤ N, u l ≤ u k⟩ : ∃ k ≤ N, ∀ l ≤ N, u l ≤ u k :=
exists_max_image _ u (finite_le_nat N) ⟨N, le_refl N⟩
have ex : ∃ n ≥ N, u k < u n := exists_lt_of_tendsto_atTop hu _ _
obtain ⟨n : ℕ, hnN : n ≥ N, hnk : u k < u n, hn_min : ∀ m, m < n → N ≤ m → u m ≤ u k⟩ :
∃ n ≥ N, u k < u n ∧ ∀ m, m < n → N ≤ m → u m ≤ u k := by
rcases Nat.findX ex with ⟨n, ⟨hnN, hnk⟩, hn_min⟩
push_neg at hn_min
exact ⟨n, hnN, hnk, hn_min⟩
use n, hnN
rintro (l : ℕ) (hl : l < n)
have hlk : u l ≤ u k := by
cases' (le_total l N : l ≤ N ∨ N ≤ l) with H H
· exact hku l H
· exact hn_min l hl H
calc
u l ≤ u k := hlk
_ < u n := hnk
#align filter.high_scores Filter.high_scores
-- see Note [nolint_ge]
/-- If `u` is a sequence which is unbounded below,
then after any point, it reaches a value strictly smaller than all previous values.
-/
-- @[nolint ge_or_gt] Porting note: restore attribute
theorem low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β} (hu : Tendsto u atTop atBot) :
∀ N, ∃ n ≥ N, ∀ k < n, u n < u k :=
@high_scores βᵒᵈ _ _ _ hu
#align filter.low_scores Filter.low_scores
/-- If `u` is a sequence which is unbounded above,
then it `Frequently` reaches a value strictly greater than all previous values.
-/
theorem frequently_high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β}
(hu : Tendsto u atTop atTop) : ∃ᶠ n in atTop, ∀ k < n, u k < u n := by
simpa [frequently_atTop] using high_scores hu
#align filter.frequently_high_scores Filter.frequently_high_scores
/-- If `u` is a sequence which is unbounded below,
then it `Frequently` reaches a value strictly smaller than all previous values.
-/
theorem frequently_low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β}
(hu : Tendsto u atTop atBot) : ∃ᶠ n in atTop, ∀ k < n, u n < u k :=
@frequently_high_scores βᵒᵈ _ _ _ hu
#align filter.frequently_low_scores Filter.frequently_low_scores
theorem strictMono_subseq_of_tendsto_atTop {β : Type*} [LinearOrder β] [NoMaxOrder β] {u : ℕ → β}
(hu : Tendsto u atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) :=
let ⟨φ, h, h'⟩ := extraction_of_frequently_atTop (frequently_high_scores hu)
⟨φ, h, fun _ m hnm => h' m _ (h hnm)⟩
#align filter.strict_mono_subseq_of_tendsto_at_top Filter.strictMono_subseq_of_tendsto_atTop
theorem strictMono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) :=
strictMono_subseq_of_tendsto_atTop (tendsto_atTop_mono hu tendsto_id)
#align filter.strict_mono_subseq_of_id_le Filter.strictMono_subseq_of_id_le
theorem _root_.StrictMono.tendsto_atTop {φ : ℕ → ℕ} (h : StrictMono φ) : Tendsto φ atTop atTop :=
tendsto_atTop_mono h.id_le tendsto_id
#align strict_mono.tendsto_at_top StrictMono.tendsto_atTop
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid β] {l : Filter α} {f g : α → β}
theorem tendsto_atTop_add_nonneg_left' (hf : ∀ᶠ x in l, 0 ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_mono' l (hf.mono fun _ => le_add_of_nonneg_left) hg
#align filter.tendsto_at_top_add_nonneg_left' Filter.tendsto_atTop_add_nonneg_left'
theorem tendsto_atBot_add_nonpos_left' (hf : ∀ᶠ x in l, f x ≤ 0) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_left' _ βᵒᵈ _ _ _ _ hf hg
#align filter.tendsto_at_bot_add_nonpos_left' Filter.tendsto_atBot_add_nonpos_left'
theorem tendsto_atTop_add_nonneg_left (hf : ∀ x, 0 ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_nonneg_left' (eventually_of_forall hf) hg
#align filter.tendsto_at_top_add_nonneg_left Filter.tendsto_atTop_add_nonneg_left
theorem tendsto_atBot_add_nonpos_left (hf : ∀ x, f x ≤ 0) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_left _ βᵒᵈ _ _ _ _ hf hg
#align filter.tendsto_at_bot_add_nonpos_left Filter.tendsto_atBot_add_nonpos_left
theorem tendsto_atTop_add_nonneg_right' (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, 0 ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_mono' l (monotone_mem (fun _ => le_add_of_nonneg_right) hg) hf
#align filter.tendsto_at_top_add_nonneg_right' Filter.tendsto_atTop_add_nonneg_right'
theorem tendsto_atBot_add_nonpos_right' (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ 0) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_right' _ βᵒᵈ _ _ _ _ hf hg
#align filter.tendsto_at_bot_add_nonpos_right' Filter.tendsto_atBot_add_nonpos_right'
theorem tendsto_atTop_add_nonneg_right (hf : Tendsto f l atTop) (hg : ∀ x, 0 ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_nonneg_right' hf (eventually_of_forall hg)
#align filter.tendsto_at_top_add_nonneg_right Filter.tendsto_atTop_add_nonneg_right
theorem tendsto_atBot_add_nonpos_right (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ 0) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_right _ βᵒᵈ _ _ _ _ hf hg
#align filter.tendsto_at_bot_add_nonpos_right Filter.tendsto_atBot_add_nonpos_right
theorem tendsto_atTop_add (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_nonneg_left' (tendsto_atTop.mp hf 0) hg
#align filter.tendsto_at_top_add Filter.tendsto_atTop_add
theorem tendsto_atBot_add (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add _ βᵒᵈ _ _ _ _ hf hg
#align filter.tendsto_at_bot_add Filter.tendsto_atBot_add
theorem Tendsto.nsmul_atTop (hf : Tendsto f l atTop) {n : ℕ} (hn : 0 < n) :
Tendsto (fun x => n • f x) l atTop :=
tendsto_atTop.2 fun y =>
(tendsto_atTop.1 hf y).mp <|
(tendsto_atTop.1 hf 0).mono fun x h₀ hy =>
calc
y ≤ f x := hy
_ = 1 • f x := (one_nsmul _).symm
_ ≤ n • f x := nsmul_le_nsmul_left h₀ hn
#align filter.tendsto.nsmul_at_top Filter.Tendsto.nsmul_atTop
theorem Tendsto.nsmul_atBot (hf : Tendsto f l atBot) {n : ℕ} (hn : 0 < n) :
Tendsto (fun x => n • f x) l atBot :=
@Tendsto.nsmul_atTop α βᵒᵈ _ l f hf n hn
#align filter.tendsto.nsmul_at_bot Filter.Tendsto.nsmul_atBot
#noalign filter.tendsto_bit0_at_top
#noalign filter.tendsto_bit0_at_bot
end OrderedAddCommMonoid
section OrderedCancelAddCommMonoid
variable [OrderedCancelAddCommMonoid β] {l : Filter α} {f g : α → β}
theorem tendsto_atTop_of_add_const_left (C : β) (hf : Tendsto (fun x => C + f x) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (C + b)).mono fun _ => le_of_add_le_add_left
#align filter.tendsto_at_top_of_add_const_left Filter.tendsto_atTop_of_add_const_left
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_const_left (C : β) (hf : Tendsto (fun x => C + f x) l atBot) :
Tendsto f l atBot :=
tendsto_atBot.2 fun b => (tendsto_atBot.1 hf (C + b)).mono fun _ => le_of_add_le_add_left
#align filter.tendsto_at_bot_of_add_const_left Filter.tendsto_atBot_of_add_const_left
theorem tendsto_atTop_of_add_const_right (C : β) (hf : Tendsto (fun x => f x + C) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b + C)).mono fun _ => le_of_add_le_add_right
#align filter.tendsto_at_top_of_add_const_right Filter.tendsto_atTop_of_add_const_right
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_const_right (C : β) (hf : Tendsto (fun x => f x + C) l atBot) :
Tendsto f l atBot :=
tendsto_atBot.2 fun b => (tendsto_atBot.1 hf (b + C)).mono fun _ => le_of_add_le_add_right
#align filter.tendsto_at_bot_of_add_const_right Filter.tendsto_atBot_of_add_const_right
theorem tendsto_atTop_of_add_bdd_above_left' (C) (hC : ∀ᶠ x in l, f x ≤ C)
(h : Tendsto (fun x => f x + g x) l atTop) : Tendsto g l atTop :=
tendsto_atTop_of_add_const_left C
(tendsto_atTop_mono' l (hC.mono fun x hx => add_le_add_right hx (g x)) h)
#align filter.tendsto_at_top_of_add_bdd_above_left' Filter.tendsto_atTop_of_add_bdd_above_left'
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_left' (C) (hC : ∀ᶠ x in l, C ≤ f x)
(h : Tendsto (fun x => f x + g x) l atBot) : Tendsto g l atBot :=
tendsto_atBot_of_add_const_left C
(tendsto_atBot_mono' l (hC.mono fun x hx => add_le_add_right hx (g x)) h)
#align filter.tendsto_at_bot_of_add_bdd_below_left' Filter.tendsto_atBot_of_add_bdd_below_left'
theorem tendsto_atTop_of_add_bdd_above_left (C) (hC : ∀ x, f x ≤ C) :
Tendsto (fun x => f x + g x) l atTop → Tendsto g l atTop :=
tendsto_atTop_of_add_bdd_above_left' C (univ_mem' hC)
#align filter.tendsto_at_top_of_add_bdd_above_left Filter.tendsto_atTop_of_add_bdd_above_left
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_left (C) (hC : ∀ x, C ≤ f x) :
Tendsto (fun x => f x + g x) l atBot → Tendsto g l atBot :=
tendsto_atBot_of_add_bdd_below_left' C (univ_mem' hC)
#align filter.tendsto_at_bot_of_add_bdd_below_left Filter.tendsto_atBot_of_add_bdd_below_left
theorem tendsto_atTop_of_add_bdd_above_right' (C) (hC : ∀ᶠ x in l, g x ≤ C)
(h : Tendsto (fun x => f x + g x) l atTop) : Tendsto f l atTop :=
tendsto_atTop_of_add_const_right C
(tendsto_atTop_mono' l (hC.mono fun x hx => add_le_add_left hx (f x)) h)
#align filter.tendsto_at_top_of_add_bdd_above_right' Filter.tendsto_atTop_of_add_bdd_above_right'
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_right' (C) (hC : ∀ᶠ x in l, C ≤ g x)
(h : Tendsto (fun x => f x + g x) l atBot) : Tendsto f l atBot :=
tendsto_atBot_of_add_const_right C
(tendsto_atBot_mono' l (hC.mono fun x hx => add_le_add_left hx (f x)) h)
#align filter.tendsto_at_bot_of_add_bdd_below_right' Filter.tendsto_atBot_of_add_bdd_below_right'
theorem tendsto_atTop_of_add_bdd_above_right (C) (hC : ∀ x, g x ≤ C) :
Tendsto (fun x => f x + g x) l atTop → Tendsto f l atTop :=
tendsto_atTop_of_add_bdd_above_right' C (univ_mem' hC)
#align filter.tendsto_at_top_of_add_bdd_above_right Filter.tendsto_atTop_of_add_bdd_above_right
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_right (C) (hC : ∀ x, C ≤ g x) :
Tendsto (fun x => f x + g x) l atBot → Tendsto f l atBot :=
tendsto_atBot_of_add_bdd_below_right' C (univ_mem' hC)
#align filter.tendsto_at_bot_of_add_bdd_below_right Filter.tendsto_atBot_of_add_bdd_below_right
end OrderedCancelAddCommMonoid
section OrderedGroup
variable [OrderedAddCommGroup β] (l : Filter α) {f g : α → β}
theorem tendsto_atTop_add_left_of_le' (C : β) (hf : ∀ᶠ x in l, C ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
@tendsto_atTop_of_add_bdd_above_left' _ _ _ l (fun x => -f x) (fun x => f x + g x) (-C) (by simpa)
(by simpa)
#align filter.tendsto_at_top_add_left_of_le' Filter.tendsto_atTop_add_left_of_le'
theorem tendsto_atBot_add_left_of_ge' (C : β) (hf : ∀ᶠ x in l, f x ≤ C) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_left_of_le' _ βᵒᵈ _ _ _ _ C hf hg
#align filter.tendsto_at_bot_add_left_of_ge' Filter.tendsto_atBot_add_left_of_ge'
theorem tendsto_atTop_add_left_of_le (C : β) (hf : ∀ x, C ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_left_of_le' l C (univ_mem' hf) hg
#align filter.tendsto_at_top_add_left_of_le Filter.tendsto_atTop_add_left_of_le
theorem tendsto_atBot_add_left_of_ge (C : β) (hf : ∀ x, f x ≤ C) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_left_of_le _ βᵒᵈ _ _ _ _ C hf hg
#align filter.tendsto_at_bot_add_left_of_ge Filter.tendsto_atBot_add_left_of_ge
theorem tendsto_atTop_add_right_of_le' (C : β) (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, C ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
@tendsto_atTop_of_add_bdd_above_right' _ _ _ l (fun x => f x + g x) (fun x => -g x) (-C)
(by simp [hg]) (by simp [hf])
#align filter.tendsto_at_top_add_right_of_le' Filter.tendsto_atTop_add_right_of_le'
theorem tendsto_atBot_add_right_of_ge' (C : β) (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ C) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_right_of_le' _ βᵒᵈ _ _ _ _ C hf hg
#align filter.tendsto_at_bot_add_right_of_ge' Filter.tendsto_atBot_add_right_of_ge'
theorem tendsto_atTop_add_right_of_le (C : β) (hf : Tendsto f l atTop) (hg : ∀ x, C ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_right_of_le' l C hf (univ_mem' hg)
#align filter.tendsto_at_top_add_right_of_le Filter.tendsto_atTop_add_right_of_le
theorem tendsto_atBot_add_right_of_ge (C : β) (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ C) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_right_of_le _ βᵒᵈ _ _ _ _ C hf hg
#align filter.tendsto_at_bot_add_right_of_ge Filter.tendsto_atBot_add_right_of_ge
theorem tendsto_atTop_add_const_left (C : β) (hf : Tendsto f l atTop) :
Tendsto (fun x => C + f x) l atTop :=
tendsto_atTop_add_left_of_le' l C (univ_mem' fun _ => le_refl C) hf
#align filter.tendsto_at_top_add_const_left Filter.tendsto_atTop_add_const_left
theorem tendsto_atBot_add_const_left (C : β) (hf : Tendsto f l atBot) :
Tendsto (fun x => C + f x) l atBot :=
@tendsto_atTop_add_const_left _ βᵒᵈ _ _ _ C hf
#align filter.tendsto_at_bot_add_const_left Filter.tendsto_atBot_add_const_left
theorem tendsto_atTop_add_const_right (C : β) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x + C) l atTop :=
tendsto_atTop_add_right_of_le' l C hf (univ_mem' fun _ => le_refl C)
#align filter.tendsto_at_top_add_const_right Filter.tendsto_atTop_add_const_right
theorem tendsto_atBot_add_const_right (C : β) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x + C) l atBot :=
@tendsto_atTop_add_const_right _ βᵒᵈ _ _ _ C hf
#align filter.tendsto_at_bot_add_const_right Filter.tendsto_atBot_add_const_right
theorem map_neg_atBot : map (Neg.neg : β → β) atBot = atTop :=
(OrderIso.neg β).map_atBot
#align filter.map_neg_at_bot Filter.map_neg_atBot
theorem map_neg_atTop : map (Neg.neg : β → β) atTop = atBot :=
(OrderIso.neg β).map_atTop
#align filter.map_neg_at_top Filter.map_neg_atTop
theorem comap_neg_atBot : comap (Neg.neg : β → β) atBot = atTop :=
(OrderIso.neg β).comap_atTop
#align filter.comap_neg_at_bot Filter.comap_neg_atBot
theorem comap_neg_atTop : comap (Neg.neg : β → β) atTop = atBot :=
(OrderIso.neg β).comap_atBot
#align filter.comap_neg_at_top Filter.comap_neg_atTop
theorem tendsto_neg_atTop_atBot : Tendsto (Neg.neg : β → β) atTop atBot :=
(OrderIso.neg β).tendsto_atTop
#align filter.tendsto_neg_at_top_at_bot Filter.tendsto_neg_atTop_atBot
theorem tendsto_neg_atBot_atTop : Tendsto (Neg.neg : β → β) atBot atTop :=
@tendsto_neg_atTop_atBot βᵒᵈ _
#align filter.tendsto_neg_at_bot_at_top Filter.tendsto_neg_atBot_atTop
variable {l}
@[simp]
theorem tendsto_neg_atTop_iff : Tendsto (fun x => -f x) l atTop ↔ Tendsto f l atBot :=
(OrderIso.neg β).tendsto_atBot_iff
#align filter.tendsto_neg_at_top_iff Filter.tendsto_neg_atTop_iff
@[simp]
theorem tendsto_neg_atBot_iff : Tendsto (fun x => -f x) l atBot ↔ Tendsto f l atTop :=
(OrderIso.neg β).tendsto_atTop_iff
#align filter.tendsto_neg_at_bot_iff Filter.tendsto_neg_atBot_iff
end OrderedGroup
section OrderedSemiring
variable [OrderedSemiring α] {l : Filter β} {f g : β → α}
#noalign filter.tendsto_bit1_at_top
theorem Tendsto.atTop_mul_atTop (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x * g x) l atTop := by
refine tendsto_atTop_mono' _ ?_ hg
filter_upwards [hg.eventually (eventually_ge_atTop 0),
hf.eventually (eventually_ge_atTop 1)] with _ using le_mul_of_one_le_left
#align filter.tendsto.at_top_mul_at_top Filter.Tendsto.atTop_mul_atTop
theorem tendsto_mul_self_atTop : Tendsto (fun x : α => x * x) atTop atTop :=
tendsto_id.atTop_mul_atTop tendsto_id
#align filter.tendsto_mul_self_at_top Filter.tendsto_mul_self_atTop
/-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`.
A version for positive real powers exists as `tendsto_rpow_atTop`. -/
theorem tendsto_pow_atTop {n : ℕ} (hn : n ≠ 0) : Tendsto (fun x : α => x ^ n) atTop atTop :=
tendsto_atTop_mono' _ ((eventually_ge_atTop 1).mono fun _x hx => le_self_pow hx hn) tendsto_id
#align filter.tendsto_pow_at_top Filter.tendsto_pow_atTop
end OrderedSemiring
theorem zero_pow_eventuallyEq [MonoidWithZero α] :
(fun n : ℕ => (0 : α) ^ n) =ᶠ[atTop] fun _ => 0 :=
eventually_atTop.2 ⟨1, fun _n hn ↦ zero_pow $ Nat.one_le_iff_ne_zero.1 hn⟩
#align filter.zero_pow_eventually_eq Filter.zero_pow_eventuallyEq
section OrderedRing
variable [OrderedRing α] {l : Filter β} {f g : β → α}
theorem Tendsto.atTop_mul_atBot (hf : Tendsto f l atTop) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x * g x) l atBot := by
have := hf.atTop_mul_atTop <| tendsto_neg_atBot_atTop.comp hg
simpa only [(· ∘ ·), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_atTop_atBot.comp this
#align filter.tendsto.at_top_mul_at_bot Filter.Tendsto.atTop_mul_atBot
theorem Tendsto.atBot_mul_atTop (hf : Tendsto f l atBot) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x * g x) l atBot := by
have : Tendsto (fun x => -f x * g x) l atTop :=
(tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop hg
simpa only [(· ∘ ·), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_atTop_atBot.comp this
#align filter.tendsto.at_bot_mul_at_top Filter.Tendsto.atBot_mul_atTop
theorem Tendsto.atBot_mul_atBot (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x * g x) l atTop := by
have : Tendsto (fun x => -f x * -g x) l atTop :=
(tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop (tendsto_neg_atBot_atTop.comp hg)
simpa only [neg_mul_neg] using this
#align filter.tendsto.at_bot_mul_at_bot Filter.Tendsto.atBot_mul_atBot
end OrderedRing
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α]
/-- $\lim_{x\to+\infty}|x|=+\infty$ -/
theorem tendsto_abs_atTop_atTop : Tendsto (abs : α → α) atTop atTop :=
tendsto_atTop_mono le_abs_self tendsto_id
#align filter.tendsto_abs_at_top_at_top Filter.tendsto_abs_atTop_atTop
/-- $\lim_{x\to-\infty}|x|=+\infty$ -/
theorem tendsto_abs_atBot_atTop : Tendsto (abs : α → α) atBot atTop :=
tendsto_atTop_mono neg_le_abs tendsto_neg_atBot_atTop
#align filter.tendsto_abs_at_bot_at_top Filter.tendsto_abs_atBot_atTop
@[simp]
theorem comap_abs_atTop : comap (abs : α → α) atTop = atBot ⊔ atTop := by
refine
le_antisymm (((atTop_basis.comap _).le_basis_iff (atBot_basis.sup atTop_basis)).2 ?_)
(sup_le tendsto_abs_atBot_atTop.le_comap tendsto_abs_atTop_atTop.le_comap)
rintro ⟨a, b⟩ -
refine ⟨max (-a) b, trivial, fun x hx => ?_⟩
rw [mem_preimage, mem_Ici, le_abs', max_le_iff, ← min_neg_neg, le_min_iff, neg_neg] at hx
exact hx.imp And.left And.right
#align filter.comap_abs_at_top Filter.comap_abs_atTop
end LinearOrderedAddCommGroup
section LinearOrderedSemiring
variable [LinearOrderedSemiring α] {l : Filter β} {f : β → α}
theorem Tendsto.atTop_of_const_mul {c : α} (hc : 0 < c) (hf : Tendsto (fun x => c * f x) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (c * b)).mono
fun _x hx => le_of_mul_le_mul_left hx hc
#align filter.tendsto.at_top_of_const_mul Filter.Tendsto.atTop_of_const_mul
theorem Tendsto.atTop_of_mul_const {c : α} (hc : 0 < c) (hf : Tendsto (fun x => f x * c) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b * c)).mono
fun _x hx => le_of_mul_le_mul_right hx hc
#align filter.tendsto.at_top_of_mul_const Filter.Tendsto.atTop_of_mul_const
@[simp]
theorem tendsto_pow_atTop_iff {n : ℕ} : Tendsto (fun x : α => x ^ n) atTop atTop ↔ n ≠ 0 :=
⟨fun h hn => by simp only [hn, pow_zero, not_tendsto_const_atTop] at h, tendsto_pow_atTop⟩
#align filter.tendsto_pow_at_top_iff Filter.tendsto_pow_atTop_iff
end LinearOrderedSemiring
theorem not_tendsto_pow_atTop_atBot [LinearOrderedRing α] :
∀ {n : ℕ}, ¬Tendsto (fun x : α => x ^ n) atTop atBot
| 0 => by simp [not_tendsto_const_atBot]
| n + 1 => (tendsto_pow_atTop n.succ_ne_zero).not_tendsto disjoint_atTop_atBot
#align filter.not_tendsto_pow_at_top_at_bot Filter.not_tendsto_pow_atTop_atBot
section LinearOrderedSemifield
variable [LinearOrderedSemifield α] {l : Filter β} {f : β → α} {r c : α} {n : ℕ}
/-!
### Multiplication by constant: iff lemmas
-/
/-- If `r` is a positive constant, `fun x ↦ r * f x` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
theorem tendsto_const_mul_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atTop :=
⟨fun h => h.atTop_of_const_mul hr, fun h =>
Tendsto.atTop_of_const_mul (inv_pos.2 hr) <| by simpa only [inv_mul_cancel_left₀ hr.ne'] ⟩
#align filter.tendsto_const_mul_at_top_of_pos Filter.tendsto_const_mul_atTop_of_pos
/-- If `r` is a positive constant, `fun x ↦ f x * r` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
theorem tendsto_mul_const_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atTop := by
simpa only [mul_comm] using tendsto_const_mul_atTop_of_pos hr
#align filter.tendsto_mul_const_at_top_of_pos Filter.tendsto_mul_const_atTop_of_pos
/-- If `r` is a positive constant, `x ↦ f x / r` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
lemma tendsto_div_const_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atTop := by
simpa only [div_eq_mul_inv] using tendsto_mul_const_atTop_of_pos (inv_pos.2 hr)
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`fun x ↦ r * f x` tends to infinity if and only if `0 < r. `-/
theorem tendsto_const_mul_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atTop ↔ 0 < r := by
refine ⟨fun hrf => not_le.mp fun hr => ?_, fun hr => (tendsto_const_mul_atTop_of_pos hr).mpr h⟩
rcases ((h.eventually_ge_atTop 0).and (hrf.eventually_gt_atTop 0)).exists with ⟨x, hx, hrx⟩
exact (mul_nonpos_of_nonpos_of_nonneg hr hx).not_lt hrx
#align filter.tendsto_const_mul_at_top_iff_pos Filter.tendsto_const_mul_atTop_iff_pos
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`fun x ↦ f x * r` tends to infinity if and only if `0 < r. `-/
theorem tendsto_mul_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atTop ↔ 0 < r := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_pos h]
#align filter.tendsto_mul_const_at_top_iff_pos Filter.tendsto_mul_const_atTop_iff_pos
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`x ↦ f x * r` tends to infinity if and only if `0 < r. `-/
lemma tendsto_div_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r := by
simp only [div_eq_mul_inv, tendsto_mul_const_atTop_iff_pos h, inv_pos]
/-- If `f` tends to infinity along a filter, then `f` multiplied by a positive
constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`Filter.Tendsto.const_mul_atTop'` instead. -/
theorem Tendsto.const_mul_atTop (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atTop :=
(tendsto_const_mul_atTop_of_pos hr).2 hf
#align filter.tendsto.const_mul_at_top Filter.Tendsto.const_mul_atTop
/-- If a function `f` tends to infinity along a filter, then `f` multiplied by a positive
constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`Filter.Tendsto.atTop_mul_const'` instead. -/
theorem Tendsto.atTop_mul_const (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atTop :=
(tendsto_mul_const_atTop_of_pos hr).2 hf
#align filter.tendsto.at_top_mul_const Filter.Tendsto.atTop_mul_const
/-- If a function `f` tends to infinity along a filter, then `f` divided by a positive
constant also tends to infinity. -/
theorem Tendsto.atTop_div_const (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x / r) l atTop := by
simpa only [div_eq_mul_inv] using hf.atTop_mul_const (inv_pos.2 hr)
#align filter.tendsto.at_top_div_const Filter.Tendsto.atTop_div_const
theorem tendsto_const_mul_pow_atTop (hn : n ≠ 0) (hc : 0 < c) :
Tendsto (fun x => c * x ^ n) atTop atTop :=
Tendsto.const_mul_atTop hc (tendsto_pow_atTop hn)
#align filter.tendsto_const_mul_pow_at_top Filter.tendsto_const_mul_pow_atTop
theorem tendsto_const_mul_pow_atTop_iff :
Tendsto (fun x => c * x ^ n) atTop atTop ↔ n ≠ 0 ∧ 0 < c := by
refine ⟨fun h => ⟨?_, ?_⟩, fun h => tendsto_const_mul_pow_atTop h.1 h.2⟩
· rintro rfl
simp only [pow_zero, not_tendsto_const_atTop] at h
· rcases ((h.eventually_gt_atTop 0).and (eventually_ge_atTop 0)).exists with ⟨k, hck, hk⟩
exact pos_of_mul_pos_left hck (pow_nonneg hk _)
#align filter.tendsto_const_mul_pow_at_top_iff Filter.tendsto_const_mul_pow_atTop_iff
lemma tendsto_zpow_atTop_atTop {n : ℤ} (hn : 0 < n) : Tendsto (fun x : α ↦ x ^ n) atTop atTop := by
lift n to ℕ+ using hn; simp
#align tendsto_zpow_at_top_at_top Filter.tendsto_zpow_atTop_atTop
end LinearOrderedSemifield
section LinearOrderedField
variable [LinearOrderedField α] {l : Filter β} {f : β → α} {r : α}
/-- If `r` is a positive constant, `fun x ↦ r * f x` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
theorem tendsto_const_mul_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atBot := by
simpa only [← mul_neg, ← tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos hr
#align filter.tendsto_const_mul_at_bot_of_pos Filter.tendsto_const_mul_atBot_of_pos
/-- If `r` is a positive constant, `fun x ↦ f x * r` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
theorem tendsto_mul_const_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atBot := by
simpa only [mul_comm] using tendsto_const_mul_atBot_of_pos hr
#align filter.tendsto_mul_const_at_bot_of_pos Filter.tendsto_mul_const_atBot_of_pos
/-- If `r` is a positive constant, `fun x ↦ f x / r` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
lemma tendsto_div_const_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_pos, hr]
/-- If `r` is a negative constant, `fun x ↦ r * f x` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
theorem tendsto_const_mul_atTop_of_neg (hr : r < 0) :
Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atBot := by
simpa only [neg_mul, tendsto_neg_atBot_iff] using tendsto_const_mul_atBot_of_pos (neg_pos.2 hr)
#align filter.tendsto_const_mul_at_top_of_neg Filter.tendsto_const_mul_atTop_of_neg
/-- If `r` is a negative constant, `fun x ↦ f x * r` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
theorem tendsto_mul_const_atTop_of_neg (hr : r < 0) :
Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atBot := by
simpa only [mul_comm] using tendsto_const_mul_atTop_of_neg hr
/-- If `r` is a negative constant, `fun x ↦ f x / r` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
lemma tendsto_div_const_atTop_of_neg (hr : r < 0) :
Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_of_neg, hr]
/-- If `r` is a negative constant, `fun x ↦ r * f x` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
theorem tendsto_const_mul_atBot_of_neg (hr : r < 0) :
Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atTop := by
simpa only [neg_mul, tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos (neg_pos.2 hr)
#align filter.tendsto_const_mul_at_bot_of_neg Filter.tendsto_const_mul_atBot_of_neg
/-- If `r` is a negative constant, `fun x ↦ f x * r` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
theorem tendsto_mul_const_atBot_of_neg (hr : r < 0) :
Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atTop := by
simpa only [mul_comm] using tendsto_const_mul_atBot_of_neg hr
#align filter.tendsto_mul_const_at_bot_of_neg Filter.tendsto_mul_const_atBot_of_neg
/-- If `r` is a negative constant, `fun x ↦ f x / r` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
lemma tendsto_div_const_atBot_of_neg (hr : r < 0) :
Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atTop := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_neg, hr]
/-- The function `fun x ↦ r * f x` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
theorem tendsto_const_mul_atTop_iff [NeBot l] :
Tendsto (fun x => r * f x) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
rcases lt_trichotomy r 0 with (hr | rfl | hr)
· simp [hr, hr.not_lt, tendsto_const_mul_atTop_of_neg]
· simp [not_tendsto_const_atTop]
· simp [hr, hr.not_lt, tendsto_const_mul_atTop_of_pos]
#align filter.tendsto_const_mul_at_top_iff Filter.tendsto_const_mul_atTop_iff
/-- The function `fun x ↦ f x * r` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
theorem tendsto_mul_const_atTop_iff [NeBot l] :
Tendsto (fun x => f x * r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff]
#align filter.tendsto_mul_const_at_top_iff Filter.tendsto_mul_const_atTop_iff
/-- The function `fun x ↦ f x / r` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
lemma tendsto_div_const_atTop_iff [NeBot l] :
Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff]
/-- The function `fun x ↦ r * f x` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
theorem tendsto_const_mul_atBot_iff [NeBot l] :
Tendsto (fun x => r * f x) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp only [← tendsto_neg_atTop_iff, ← mul_neg, tendsto_const_mul_atTop_iff, neg_neg]
#align filter.tendsto_const_mul_at_bot_iff Filter.tendsto_const_mul_atBot_iff
/-- The function `fun x ↦ f x * r` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
theorem tendsto_mul_const_atBot_iff [NeBot l] :
Tendsto (fun x => f x * r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff]
#align filter.tendsto_mul_const_at_bot_iff Filter.tendsto_mul_const_atBot_iff
/-- The function `fun x ↦ f x / r` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
lemma tendsto_div_const_atBot_iff [NeBot l] :
Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff]
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ r * f x` tends to infinity if and only if `r < 0. `-/
theorem tendsto_const_mul_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atTop ↔ r < 0 := by
simp [tendsto_const_mul_atTop_iff, h, h.not_tendsto disjoint_atBot_atTop]
#align filter.tendsto_const_mul_at_top_iff_neg Filter.tendsto_const_mul_atTop_iff_neg
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ f x * r` tends to infinity if and only if `r < 0. `-/
theorem tendsto_mul_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atTop ↔ r < 0 := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_neg h]
#align filter.tendsto_mul_const_at_top_iff_neg Filter.tendsto_mul_const_atTop_iff_neg
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ f x / r` tends to infinity if and only if `r < 0. `-/
lemma tendsto_div_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x ↦ f x / r) l atTop ↔ r < 0 := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff_neg h]
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ r * f x` tends to negative infinity if and only if `0 < r. `-/
theorem tendsto_const_mul_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atBot ↔ 0 < r := by
simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atBot_atTop]
#align filter.tendsto_const_mul_at_bot_iff_pos Filter.tendsto_const_mul_atBot_iff_pos
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ f x * r` tends to negative infinity if and only if `0 < r. `-/
theorem tendsto_mul_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atBot ↔ 0 < r := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_pos h]
#align filter.tendsto_mul_const_at_bot_iff_pos Filter.tendsto_mul_const_atBot_iff_pos
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ f x / r` tends to negative infinity if and only if `0 < r. `-/
lemma tendsto_div_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_pos h]
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ r * f x` tends to negative infinity if and only if `r < 0. `-/
theorem tendsto_const_mul_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atBot ↔ r < 0 := by
simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atTop_atBot]
#align filter.tendsto_const_mul_at_bot_iff_neg Filter.tendsto_const_mul_atBot_iff_neg
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ f x * r` tends to negative infinity if and only if `r < 0. `-/
theorem tendsto_mul_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atBot ↔ r < 0 := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_neg h]
#align filter.tendsto_mul_const_at_bot_iff_neg Filter.tendsto_mul_const_atBot_iff_neg
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ f x / r` tends to negative infinity if and only if `r < 0. `-/
lemma tendsto_div_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atBot ↔ r < 0 := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_neg h]
/-- If a function `f` tends to infinity along a filter,
then `f` multiplied by a negative constant (on the left) tends to negative infinity. -/
theorem Tendsto.const_mul_atTop_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atBot :=
(tendsto_const_mul_atBot_of_neg hr).2 hf
#align filter.tendsto.neg_const_mul_at_top Filter.Tendsto.const_mul_atTop_of_neg
/-- If a function `f` tends to infinity along a filter,
then `f` multiplied by a negative constant (on the right) tends to negative infinity. -/
theorem Tendsto.atTop_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atBot :=
(tendsto_mul_const_atBot_of_neg hr).2 hf
#align filter.tendsto.at_top_mul_neg_const Filter.Tendsto.atTop_mul_const_of_neg
/-- If a function `f` tends to infinity along a filter,
then `f` divided by a negative constant tends to negative infinity. -/
lemma Tendsto.atTop_div_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atBot := (tendsto_div_const_atBot_of_neg hr).2 hf
/-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by
a positive constant (on the left) also tends to negative infinity. -/
theorem Tendsto.const_mul_atBot (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atBot :=
(tendsto_const_mul_atBot_of_pos hr).2 hf
#align filter.tendsto.const_mul_at_bot Filter.Tendsto.const_mul_atBot
/-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by
a positive constant (on the right) also tends to negative infinity. -/
theorem Tendsto.atBot_mul_const (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atBot :=
(tendsto_mul_const_atBot_of_pos hr).2 hf
#align filter.tendsto.at_bot_mul_const Filter.Tendsto.atBot_mul_const
/-- If a function `f` tends to negative infinity along a filter, then `f` divided by
a positive constant also tends to negative infinity. -/
theorem Tendsto.atBot_div_const (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x / r) l atBot := (tendsto_div_const_atBot_of_pos hr).2 hf
#align filter.tendsto.at_bot_div_const Filter.Tendsto.atBot_div_const
/-- If a function `f` tends to negative infinity along a filter,
then `f` multiplied by a negative constant (on the left) tends to positive infinity. -/
theorem Tendsto.const_mul_atBot_of_neg (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atTop :=
(tendsto_const_mul_atTop_of_neg hr).2 hf
#align filter.tendsto.neg_const_mul_at_bot Filter.Tendsto.const_mul_atBot_of_neg
/-- If a function tends to negative infinity along a filter,
then `f` multiplied by a negative constant (on the right) tends to positive infinity. -/
theorem Tendsto.atBot_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atTop :=
(tendsto_mul_const_atTop_of_neg hr).2 hf
#align filter.tendsto.at_bot_mul_neg_const Filter.Tendsto.atBot_mul_const_of_neg
theorem tendsto_neg_const_mul_pow_atTop {c : α} {n : ℕ} (hn : n ≠ 0) (hc : c < 0) :
Tendsto (fun x => c * x ^ n) atTop atBot :=
(tendsto_pow_atTop hn).const_mul_atTop_of_neg hc
#align filter.tendsto_neg_const_mul_pow_at_top Filter.tendsto_neg_const_mul_pow_atTop
theorem tendsto_const_mul_pow_atBot_iff {c : α} {n : ℕ} :
Tendsto (fun x => c * x ^ n) atTop atBot ↔ n ≠ 0 ∧ c < 0 := by
simp only [← tendsto_neg_atTop_iff, ← neg_mul, tendsto_const_mul_pow_atTop_iff, neg_pos]
#align filter.tendsto_const_mul_pow_at_bot_iff Filter.tendsto_const_mul_pow_atBot_iff
@[deprecated (since := "2024-05-06")]
alias Tendsto.neg_const_mul_atTop := Tendsto.const_mul_atTop_of_neg
@[deprecated (since := "2024-05-06")]
alias Tendsto.atTop_mul_neg_const := Tendsto.atTop_mul_const_of_neg
@[deprecated (since := "2024-05-06")]
alias Tendsto.neg_const_mul_atBot := Tendsto.const_mul_atBot_of_neg
@[deprecated (since := "2024-05-06")]
alias Tendsto.atBot_mul_neg_const := Tendsto.atBot_mul_const_of_neg
end LinearOrderedField
open Filter
theorem tendsto_atTop' [Nonempty α] [SemilatticeSup α] {f : α → β} {l : Filter β} :
Tendsto f atTop l ↔ ∀ s ∈ l, ∃ a, ∀ b ≥ a, f b ∈ s := by
simp only [tendsto_def, mem_atTop_sets, mem_preimage]
#align filter.tendsto_at_top' Filter.tendsto_atTop'
theorem tendsto_atBot' [Nonempty α] [SemilatticeInf α] {f : α → β} {l : Filter β} :
Tendsto f atBot l ↔ ∀ s ∈ l, ∃ a, ∀ b ≤ a, f b ∈ s :=
@tendsto_atTop' αᵒᵈ _ _ _ _ _
#align filter.tendsto_at_bot' Filter.tendsto_atBot'
theorem tendsto_atTop_principal [Nonempty β] [SemilatticeSup β] {f : β → α} {s : Set α} :
Tendsto f atTop (𝓟 s) ↔ ∃ N, ∀ n ≥ N, f n ∈ s := by
simp_rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_atTop_sets, mem_preimage]
#align filter.tendsto_at_top_principal Filter.tendsto_atTop_principal
theorem tendsto_atBot_principal [Nonempty β] [SemilatticeInf β] {f : β → α} {s : Set α} :
Tendsto f atBot (𝓟 s) ↔ ∃ N, ∀ n ≤ N, f n ∈ s :=
@tendsto_atTop_principal _ βᵒᵈ _ _ _ _
#align filter.tendsto_at_bot_principal Filter.tendsto_atBot_principal
/-- A function `f` grows to `+∞` independent of an order-preserving embedding `e`. -/
theorem tendsto_atTop_atTop [Nonempty α] [SemilatticeSup α] [Preorder β] {f : α → β} :
Tendsto f atTop atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a :=
Iff.trans tendsto_iInf <| forall_congr' fun _ => tendsto_atTop_principal
#align filter.tendsto_at_top_at_top Filter.tendsto_atTop_atTop
theorem tendsto_atTop_atBot [Nonempty α] [SemilatticeSup α] [Preorder β] {f : α → β} :
Tendsto f atTop atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → f a ≤ b :=
@tendsto_atTop_atTop α βᵒᵈ _ _ _ f
#align filter.tendsto_at_top_at_bot Filter.tendsto_atTop_atBot
theorem tendsto_atBot_atTop [Nonempty α] [SemilatticeInf α] [Preorder β] {f : α → β} :
Tendsto f atBot atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → b ≤ f a :=
@tendsto_atTop_atTop αᵒᵈ β _ _ _ f
#align filter.tendsto_at_bot_at_top Filter.tendsto_atBot_atTop
theorem tendsto_atBot_atBot [Nonempty α] [SemilatticeInf α] [Preorder β] {f : α → β} :
Tendsto f atBot atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → f a ≤ b :=
@tendsto_atTop_atTop αᵒᵈ βᵒᵈ _ _ _ f
#align filter.tendsto_at_bot_at_bot Filter.tendsto_atBot_atBot
theorem tendsto_atTop_atTop_of_monotone [Preorder α] [Preorder β] {f : α → β} (hf : Monotone f)
(h : ∀ b, ∃ a, b ≤ f a) : Tendsto f atTop atTop :=
tendsto_iInf.2 fun b =>
tendsto_principal.2 <|
let ⟨a, ha⟩ := h b
mem_of_superset (mem_atTop a) fun _a' ha' => le_trans ha (hf ha')
#align filter.tendsto_at_top_at_top_of_monotone Filter.tendsto_atTop_atTop_of_monotone
theorem tendsto_atTop_atBot_of_antitone [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f)
(h : ∀ b, ∃ a, f a ≤ b) : Tendsto f atTop atBot :=
@tendsto_atTop_atTop_of_monotone _ βᵒᵈ _ _ _ hf h
theorem tendsto_atBot_atBot_of_monotone [Preorder α] [Preorder β] {f : α → β} (hf : Monotone f)
(h : ∀ b, ∃ a, f a ≤ b) : Tendsto f atBot atBot :=
tendsto_iInf.2 fun b => tendsto_principal.2 <|
let ⟨a, ha⟩ := h b; mem_of_superset (mem_atBot a) fun _a' ha' => le_trans (hf ha') ha
#align filter.tendsto_at_bot_at_bot_of_monotone Filter.tendsto_atBot_atBot_of_monotone
theorem tendsto_atBot_atTop_of_antitone [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f)
(h : ∀ b, ∃ a, b ≤ f a) : Tendsto f atBot atTop :=
@tendsto_atBot_atBot_of_monotone _ βᵒᵈ _ _ _ hf h
theorem tendsto_atTop_atTop_iff_of_monotone [Nonempty α] [SemilatticeSup α] [Preorder β] {f : α → β}
(hf : Monotone f) : Tendsto f atTop atTop ↔ ∀ b : β, ∃ a : α, b ≤ f a :=
tendsto_atTop_atTop.trans <| forall_congr' fun _ => exists_congr fun a =>
⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans h <| hf ha'⟩
#align filter.tendsto_at_top_at_top_iff_of_monotone Filter.tendsto_atTop_atTop_iff_of_monotone
theorem tendsto_atTop_atBot_iff_of_antitone [Nonempty α] [SemilatticeSup α] [Preorder β] {f : α → β}
(hf : Antitone f) : Tendsto f atTop atBot ↔ ∀ b : β, ∃ a : α, f a ≤ b :=
@tendsto_atTop_atTop_iff_of_monotone _ βᵒᵈ _ _ _ _ hf
theorem tendsto_atBot_atBot_iff_of_monotone [Nonempty α] [SemilatticeInf α] [Preorder β] {f : α → β}
(hf : Monotone f) : Tendsto f atBot atBot ↔ ∀ b : β, ∃ a : α, f a ≤ b :=
tendsto_atBot_atBot.trans <| forall_congr' fun _ => exists_congr fun a =>
⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans (hf ha') h⟩
#align filter.tendsto_at_bot_at_bot_iff_of_monotone Filter.tendsto_atBot_atBot_iff_of_monotone
theorem tendsto_atBot_atTop_iff_of_antitone [Nonempty α] [SemilatticeInf α] [Preorder β] {f : α → β}
(hf : Antitone f) : Tendsto f atBot atTop ↔ ∀ b : β, ∃ a : α, b ≤ f a :=
@tendsto_atBot_atBot_iff_of_monotone _ βᵒᵈ _ _ _ _ hf
alias _root_.Monotone.tendsto_atTop_atTop := tendsto_atTop_atTop_of_monotone
#align monotone.tendsto_at_top_at_top Monotone.tendsto_atTop_atTop
alias _root_.Monotone.tendsto_atBot_atBot := tendsto_atBot_atBot_of_monotone
#align monotone.tendsto_at_bot_at_bot Monotone.tendsto_atBot_atBot
alias _root_.Monotone.tendsto_atTop_atTop_iff := tendsto_atTop_atTop_iff_of_monotone
#align monotone.tendsto_at_top_at_top_iff Monotone.tendsto_atTop_atTop_iff
alias _root_.Monotone.tendsto_atBot_atBot_iff := tendsto_atBot_atBot_iff_of_monotone
#align monotone.tendsto_at_bot_at_bot_iff Monotone.tendsto_atBot_atBot_iff
theorem comap_embedding_atTop [Preorder β] [Preorder γ] {e : β → γ}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, c ≤ e b) : comap e atTop = atTop :=
le_antisymm
(le_iInf fun b =>
le_principal_iff.2 <| mem_comap.2 ⟨Ici (e b), mem_atTop _, fun _ => (hm _ _).1⟩)
(tendsto_atTop_atTop_of_monotone (fun _ _ => (hm _ _).2) hu).le_comap
#align filter.comap_embedding_at_top Filter.comap_embedding_atTop
theorem comap_embedding_atBot [Preorder β] [Preorder γ] {e : β → γ}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, e b ≤ c) : comap e atBot = atBot :=
@comap_embedding_atTop βᵒᵈ γᵒᵈ _ _ e (Function.swap hm) hu
#align filter.comap_embedding_at_bot Filter.comap_embedding_atBot
theorem tendsto_atTop_embedding [Preorder β] [Preorder γ] {f : α → β} {e : β → γ} {l : Filter α}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, c ≤ e b) :
Tendsto (e ∘ f) l atTop ↔ Tendsto f l atTop := by
rw [← comap_embedding_atTop hm hu, tendsto_comap_iff]
#align filter.tendsto_at_top_embedding Filter.tendsto_atTop_embedding
/-- A function `f` goes to `-∞` independent of an order-preserving embedding `e`. -/
theorem tendsto_atBot_embedding [Preorder β] [Preorder γ] {f : α → β} {e : β → γ} {l : Filter α}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, e b ≤ c) :
Tendsto (e ∘ f) l atBot ↔ Tendsto f l atBot :=
@tendsto_atTop_embedding α βᵒᵈ γᵒᵈ _ _ f e l (Function.swap hm) hu
#align filter.tendsto_at_bot_embedding Filter.tendsto_atBot_embedding
theorem tendsto_finset_range : Tendsto Finset.range atTop atTop :=
Finset.range_mono.tendsto_atTop_atTop Finset.exists_nat_subset_range
#align filter.tendsto_finset_range Filter.tendsto_finset_range
theorem atTop_finset_eq_iInf : (atTop : Filter (Finset α)) = ⨅ x : α, 𝓟 (Ici {x}) := by
refine le_antisymm (le_iInf fun i => le_principal_iff.2 <| mem_atTop ({i} : Finset α)) ?_
refine
le_iInf fun s =>
le_principal_iff.2 <| mem_iInf_of_iInter s.finite_toSet (fun i => mem_principal_self _) ?_
simp only [subset_def, mem_iInter, SetCoe.forall, mem_Ici, Finset.le_iff_subset,
Finset.mem_singleton, Finset.subset_iff, forall_eq]
exact fun t => id
#align filter.at_top_finset_eq_infi Filter.atTop_finset_eq_iInf
/-- If `f` is a monotone sequence of `Finset`s and each `x` belongs to one of `f n`, then
`Tendsto f atTop atTop`. -/
theorem tendsto_atTop_finset_of_monotone [Preorder β] {f : β → Finset α} (h : Monotone f)
(h' : ∀ x : α, ∃ n, x ∈ f n) : Tendsto f atTop atTop := by
simp only [atTop_finset_eq_iInf, tendsto_iInf, tendsto_principal]
intro a
rcases h' a with ⟨b, hb⟩
exact (eventually_ge_atTop b).mono fun b' hb' => (Finset.singleton_subset_iff.2 hb).trans (h hb')
#align filter.tendsto_at_top_finset_of_monotone Filter.tendsto_atTop_finset_of_monotone
alias _root_.Monotone.tendsto_atTop_finset := tendsto_atTop_finset_of_monotone
#align monotone.tendsto_at_top_finset Monotone.tendsto_atTop_finset
-- Porting note: add assumption `DecidableEq β` so that the lemma applies to any instance
theorem tendsto_finset_image_atTop_atTop [DecidableEq β] {i : β → γ} {j : γ → β}
(h : Function.LeftInverse j i) : Tendsto (Finset.image j) atTop atTop :=
(Finset.image_mono j).tendsto_atTop_finset fun a =>
⟨{i a}, by simp only [Finset.image_singleton, h a, Finset.mem_singleton]⟩
#align filter.tendsto_finset_image_at_top_at_top Filter.tendsto_finset_image_atTop_atTop
theorem tendsto_finset_preimage_atTop_atTop {f : α → β} (hf : Function.Injective f) :
Tendsto (fun s : Finset β => s.preimage f (hf.injOn)) atTop atTop :=
(Finset.monotone_preimage hf).tendsto_atTop_finset fun x =>
⟨{f x}, Finset.mem_preimage.2 <| Finset.mem_singleton_self _⟩
#align filter.tendsto_finset_preimage_at_top_at_top Filter.tendsto_finset_preimage_atTop_atTop
-- Porting note: generalized from `SemilatticeSup` to `Preorder`
theorem prod_atTop_atTop_eq [Preorder α] [Preorder β] :
(atTop : Filter α) ×ˢ (atTop : Filter β) = (atTop : Filter (α × β)) := by
cases isEmpty_or_nonempty α
· exact Subsingleton.elim _ _
cases isEmpty_or_nonempty β
· exact Subsingleton.elim _ _
simpa [atTop, prod_iInf_left, prod_iInf_right, iInf_prod] using iInf_comm
#align filter.prod_at_top_at_top_eq Filter.prod_atTop_atTop_eq
-- Porting note: generalized from `SemilatticeSup` to `Preorder`
theorem prod_atBot_atBot_eq [Preorder β₁] [Preorder β₂] :
(atBot : Filter β₁) ×ˢ (atBot : Filter β₂) = (atBot : Filter (β₁ × β₂)) :=
@prod_atTop_atTop_eq β₁ᵒᵈ β₂ᵒᵈ _ _
#align filter.prod_at_bot_at_bot_eq Filter.prod_atBot_atBot_eq
-- Porting note: generalized from `SemilatticeSup` to `Preorder`
theorem prod_map_atTop_eq {α₁ α₂ β₁ β₂ : Type*} [Preorder β₁] [Preorder β₂]
(u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : map u₁ atTop ×ˢ map u₂ atTop = map (Prod.map u₁ u₂) atTop := by
rw [prod_map_map_eq, prod_atTop_atTop_eq, Prod.map_def]
#align filter.prod_map_at_top_eq Filter.prod_map_atTop_eq
-- Porting note: generalized from `SemilatticeSup` to `Preorder`
theorem prod_map_atBot_eq {α₁ α₂ β₁ β₂ : Type*} [Preorder β₁] [Preorder β₂]
(u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : map u₁ atBot ×ˢ map u₂ atBot = map (Prod.map u₁ u₂) atBot :=
@prod_map_atTop_eq _ _ β₁ᵒᵈ β₂ᵒᵈ _ _ _ _
#align filter.prod_map_at_bot_eq Filter.prod_map_atBot_eq
theorem Tendsto.subseq_mem {F : Filter α} {V : ℕ → Set α} (h : ∀ n, V n ∈ F) {u : ℕ → α}
(hu : Tendsto u atTop F) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, u (φ n) ∈ V n :=
extraction_forall_of_eventually'
(fun n => tendsto_atTop'.mp hu _ (h n) : ∀ n, ∃ N, ∀ k ≥ N, u k ∈ V n)
#align filter.tendsto.subseq_mem Filter.Tendsto.subseq_mem
theorem tendsto_atBot_diagonal [SemilatticeInf α] : Tendsto (fun a : α => (a, a)) atBot atBot := by
rw [← prod_atBot_atBot_eq]
exact tendsto_id.prod_mk tendsto_id
#align filter.tendsto_at_bot_diagonal Filter.tendsto_atBot_diagonal
theorem tendsto_atTop_diagonal [SemilatticeSup α] : Tendsto (fun a : α => (a, a)) atTop atTop := by
rw [← prod_atTop_atTop_eq]
exact tendsto_id.prod_mk tendsto_id
#align filter.tendsto_at_top_diagonal Filter.tendsto_atTop_diagonal
theorem Tendsto.prod_map_prod_atBot [SemilatticeInf γ] {F : Filter α} {G : Filter β} {f : α → γ}
{g : β → γ} (hf : Tendsto f F atBot) (hg : Tendsto g G atBot) :
Tendsto (Prod.map f g) (F ×ˢ G) atBot := by
rw [← prod_atBot_atBot_eq]
exact hf.prod_map hg
#align filter.tendsto.prod_map_prod_at_bot Filter.Tendsto.prod_map_prod_atBot
theorem Tendsto.prod_map_prod_atTop [SemilatticeSup γ] {F : Filter α} {G : Filter β} {f : α → γ}
{g : β → γ} (hf : Tendsto f F atTop) (hg : Tendsto g G atTop) :
Tendsto (Prod.map f g) (F ×ˢ G) atTop := by
rw [← prod_atTop_atTop_eq]
exact hf.prod_map hg
#align filter.tendsto.prod_map_prod_at_top Filter.Tendsto.prod_map_prod_atTop
theorem Tendsto.prod_atBot [SemilatticeInf α] [SemilatticeInf γ] {f g : α → γ}
(hf : Tendsto f atBot atBot) (hg : Tendsto g atBot atBot) :
Tendsto (Prod.map f g) atBot atBot := by
rw [← prod_atBot_atBot_eq]
exact hf.prod_map_prod_atBot hg
#align filter.tendsto.prod_at_bot Filter.Tendsto.prod_atBot
theorem Tendsto.prod_atTop [SemilatticeSup α] [SemilatticeSup γ] {f g : α → γ}
(hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) :
Tendsto (Prod.map f g) atTop atTop := by
rw [← prod_atTop_atTop_eq]
exact hf.prod_map_prod_atTop hg
#align filter.tendsto.prod_at_top Filter.Tendsto.prod_atTop
theorem eventually_atBot_prod_self [SemilatticeInf α] [Nonempty α] {p : α × α → Prop} :
(∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ k l, k ≤ a → l ≤ a → p (k, l) := by
simp [← prod_atBot_atBot_eq, (@atBot_basis α _ _).prod_self.eventually_iff]
#align filter.eventually_at_bot_prod_self Filter.eventually_atBot_prod_self
theorem eventually_atTop_prod_self [SemilatticeSup α] [Nonempty α] {p : α × α → Prop} :
(∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ k l, a ≤ k → a ≤ l → p (k, l) :=
eventually_atBot_prod_self (α := αᵒᵈ)
#align filter.eventually_at_top_prod_self Filter.eventually_atTop_prod_self
theorem eventually_atBot_prod_self' [SemilatticeInf α] [Nonempty α] {p : α × α → Prop} :
(∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ k ≤ a, ∀ l ≤ a, p (k, l) := by
simp only [eventually_atBot_prod_self, forall_cond_comm]
#align filter.eventually_at_bot_prod_self' Filter.eventually_atBot_prod_self'
theorem eventually_atTop_prod_self' [SemilatticeSup α] [Nonempty α] {p : α × α → Prop} :
(∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ k ≥ a, ∀ l ≥ a, p (k, l) := by
simp only [eventually_atTop_prod_self, forall_cond_comm]
#align filter.eventually_at_top_prod_self' Filter.eventually_atTop_prod_self'
theorem eventually_atTop_curry [SemilatticeSup α] [SemilatticeSup β] {p : α × β → Prop}
(hp : ∀ᶠ x : α × β in Filter.atTop, p x) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, p (k, l) := by
rw [← prod_atTop_atTop_eq] at hp
exact hp.curry
#align filter.eventually_at_top_curry Filter.eventually_atTop_curry
theorem eventually_atBot_curry [SemilatticeInf α] [SemilatticeInf β] {p : α × β → Prop}
(hp : ∀ᶠ x : α × β in Filter.atBot, p x) : ∀ᶠ k in atBot, ∀ᶠ l in atBot, p (k, l) :=
@eventually_atTop_curry αᵒᵈ βᵒᵈ _ _ _ hp
#align filter.eventually_at_bot_curry Filter.eventually_atBot_curry
/-- A function `f` maps upwards closed sets (atTop sets) to upwards closed sets when it is a
Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an
insertion and a connection above `b'`. -/
theorem map_atTop_eq_of_gc [SemilatticeSup α] [SemilatticeSup β] {f : α → β} (g : β → α) (b' : β)
(hf : Monotone f) (gc : ∀ a, ∀ b ≥ b', f a ≤ b ↔ a ≤ g b) (hgi : ∀ b ≥ b', b ≤ f (g b)) :
map f atTop = atTop := by
refine
le_antisymm
(hf.tendsto_atTop_atTop fun b => ⟨g (b ⊔ b'), le_sup_left.trans <| hgi _ le_sup_right⟩) ?_
rw [@map_atTop_eq _ _ ⟨g b'⟩]
refine le_iInf fun a => iInf_le_of_le (f a ⊔ b') <| principal_mono.2 fun b hb => ?_
rw [mem_Ici, sup_le_iff] at hb
exact ⟨g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 le_rfl) (hgi _ hb.2)⟩
#align filter.map_at_top_eq_of_gc Filter.map_atTop_eq_of_gc
theorem map_atBot_eq_of_gc [SemilatticeInf α] [SemilatticeInf β] {f : α → β} (g : β → α) (b' : β)
(hf : Monotone f) (gc : ∀ a, ∀ b ≤ b', b ≤ f a ↔ g b ≤ a) (hgi : ∀ b ≤ b', f (g b) ≤ b) :
map f atBot = atBot :=
@map_atTop_eq_of_gc αᵒᵈ βᵒᵈ _ _ _ _ _ hf.dual gc hgi
#align filter.map_at_bot_eq_of_gc Filter.map_atBot_eq_of_gc
theorem map_val_atTop_of_Ici_subset [SemilatticeSup α] {a : α} {s : Set α} (h : Ici a ⊆ s) :
map ((↑) : s → α) atTop = atTop := by
haveI : Nonempty s := ⟨⟨a, h le_rfl⟩⟩
have : Directed (· ≥ ·) fun x : s => 𝓟 (Ici x) := fun x y ↦ by
use ⟨x ⊔ y ⊔ a, h le_sup_right⟩
simp only [principal_mono, Ici_subset_Ici, ← Subtype.coe_le_coe, Subtype.coe_mk]
exact ⟨le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left⟩
simp only [le_antisymm_iff, atTop, le_iInf_iff, le_principal_iff, mem_map, mem_setOf_eq,
map_iInf_eq this, map_principal]
constructor
· intro x
refine mem_of_superset (mem_iInf_of_mem ⟨x ⊔ a, h le_sup_right⟩ (mem_principal_self _)) ?_
rintro _ ⟨y, hy, rfl⟩
exact le_trans le_sup_left (Subtype.coe_le_coe.2 hy)
· intro x
filter_upwards [mem_atTop (↑x ⊔ a)] with b hb
exact ⟨⟨b, h <| le_sup_right.trans hb⟩, Subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl⟩
#align filter.map_coe_at_top_of_Ici_subset Filter.map_val_atTop_of_Ici_subset
/-- The image of the filter `atTop` on `Ici a` under the coercion equals `atTop`. -/
@[simp]
theorem map_val_Ici_atTop [SemilatticeSup α] (a : α) : map ((↑) : Ici a → α) atTop = atTop :=
map_val_atTop_of_Ici_subset (Subset.refl _)
#align filter.map_coe_Ici_at_top Filter.map_val_Ici_atTop
/-- The image of the filter `atTop` on `Ioi a` under the coercion equals `atTop`. -/
@[simp]
theorem map_val_Ioi_atTop [SemilatticeSup α] [NoMaxOrder α] (a : α) :
map ((↑) : Ioi a → α) atTop = atTop :=
let ⟨_b, hb⟩ := exists_gt a
map_val_atTop_of_Ici_subset <| Ici_subset_Ioi.2 hb
#align filter.map_coe_Ioi_at_top Filter.map_val_Ioi_atTop
/-- The `atTop` filter for an open interval `Ioi a` comes from the `atTop` filter in the ambient
order. -/
theorem atTop_Ioi_eq [SemilatticeSup α] (a : α) : atTop = comap ((↑) : Ioi a → α) atTop := by
rcases isEmpty_or_nonempty (Ioi a) with h|⟨⟨b, hb⟩⟩
· exact Subsingleton.elim _ _
· rw [← map_val_atTop_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map Subtype.coe_injective]
#align filter.at_top_Ioi_eq Filter.atTop_Ioi_eq
/-- The `atTop` filter for an open interval `Ici a` comes from the `atTop` filter in the ambient
order. -/
theorem atTop_Ici_eq [SemilatticeSup α] (a : α) : atTop = comap ((↑) : Ici a → α) atTop := by
rw [← map_val_Ici_atTop a, comap_map Subtype.coe_injective]
#align filter.at_top_Ici_eq Filter.atTop_Ici_eq
/-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient
order. -/
@[simp]
theorem map_val_Iio_atBot [SemilatticeInf α] [NoMinOrder α] (a : α) :
map ((↑) : Iio a → α) atBot = atBot :=
@map_val_Ioi_atTop αᵒᵈ _ _ _
#align filter.map_coe_Iio_at_bot Filter.map_val_Iio_atBot
/-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient
order. -/
theorem atBot_Iio_eq [SemilatticeInf α] (a : α) : atBot = comap ((↑) : Iio a → α) atBot :=
@atTop_Ioi_eq αᵒᵈ _ _
#align filter.at_bot_Iio_eq Filter.atBot_Iio_eq
/-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient
order. -/
@[simp]
theorem map_val_Iic_atBot [SemilatticeInf α] (a : α) : map ((↑) : Iic a → α) atBot = atBot :=
@map_val_Ici_atTop αᵒᵈ _ _
#align filter.map_coe_Iic_at_bot Filter.map_val_Iic_atBot
/-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient
order. -/
theorem atBot_Iic_eq [SemilatticeInf α] (a : α) : atBot = comap ((↑) : Iic a → α) atBot :=
@atTop_Ici_eq αᵒᵈ _ _
#align filter.at_bot_Iic_eq Filter.atBot_Iic_eq
theorem tendsto_Ioi_atTop [SemilatticeSup α] {a : α} {f : β → Ioi a} {l : Filter β} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by
rw [atTop_Ioi_eq, tendsto_comap_iff, Function.comp_def]
#align filter.tendsto_Ioi_at_top Filter.tendsto_Ioi_atTop
theorem tendsto_Iio_atBot [SemilatticeInf α] {a : α} {f : β → Iio a} {l : Filter β} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot := by
rw [atBot_Iio_eq, tendsto_comap_iff, Function.comp_def]
#align filter.tendsto_Iio_at_bot Filter.tendsto_Iio_atBot
theorem tendsto_Ici_atTop [SemilatticeSup α] {a : α} {f : β → Ici a} {l : Filter β} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by
rw [atTop_Ici_eq, tendsto_comap_iff, Function.comp_def]
#align filter.tendsto_Ici_at_top Filter.tendsto_Ici_atTop
theorem tendsto_Iic_atBot [SemilatticeInf α] {a : α} {f : β → Iic a} {l : Filter β} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot := by
rw [atBot_Iic_eq, tendsto_comap_iff, Function.comp_def]
#align filter.tendsto_Iic_at_bot Filter.tendsto_Iic_atBot
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Ioi_atTop [SemilatticeSup α] [NoMaxOrder α] {a : α} {f : α → β}
{l : Filter β} : Tendsto (fun x : Ioi a => f x) atTop l ↔ Tendsto f atTop l := by
rw [← map_val_Ioi_atTop a, tendsto_map'_iff, Function.comp_def]
#align filter.tendsto_comp_coe_Ioi_at_top Filter.tendsto_comp_val_Ioi_atTop
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Ici_atTop [SemilatticeSup α] {a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Ici a => f x) atTop l ↔ Tendsto f atTop l := by
rw [← map_val_Ici_atTop a, tendsto_map'_iff, Function.comp_def]
#align filter.tendsto_comp_coe_Ici_at_top Filter.tendsto_comp_val_Ici_atTop
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Iio_atBot [SemilatticeInf α] [NoMinOrder α] {a : α} {f : α → β}
{l : Filter β} : Tendsto (fun x : Iio a => f x) atBot l ↔ Tendsto f atBot l := by
rw [← map_val_Iio_atBot a, tendsto_map'_iff, Function.comp_def]
#align filter.tendsto_comp_coe_Iio_at_bot Filter.tendsto_comp_val_Iio_atBot
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Iic_atBot [SemilatticeInf α] {a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Iic a => f x) atBot l ↔ Tendsto f atBot l := by
rw [← map_val_Iic_atBot a, tendsto_map'_iff, Function.comp_def]
#align filter.tendsto_comp_coe_Iic_at_bot Filter.tendsto_comp_val_Iic_atBot
theorem map_add_atTop_eq_nat (k : ℕ) : map (fun a => a + k) atTop = atTop :=
map_atTop_eq_of_gc (fun a => a - k) k (fun a b h => add_le_add_right h k)
(fun a b h => (le_tsub_iff_right h).symm) fun a h => by rw [tsub_add_cancel_of_le h]
#align filter.map_add_at_top_eq_nat Filter.map_add_atTop_eq_nat
theorem map_sub_atTop_eq_nat (k : ℕ) : map (fun a => a - k) atTop = atTop :=
map_atTop_eq_of_gc (fun a => a + k) 0 (fun a b h => tsub_le_tsub_right h _)
(fun a b _ => tsub_le_iff_right) fun b _ => by rw [add_tsub_cancel_right]
#align filter.map_sub_at_top_eq_nat Filter.map_sub_atTop_eq_nat
theorem tendsto_add_atTop_nat (k : ℕ) : Tendsto (fun a => a + k) atTop atTop :=
le_of_eq (map_add_atTop_eq_nat k)
#align filter.tendsto_add_at_top_nat Filter.tendsto_add_atTop_nat
theorem tendsto_sub_atTop_nat (k : ℕ) : Tendsto (fun a => a - k) atTop atTop :=
le_of_eq (map_sub_atTop_eq_nat k)
#align filter.tendsto_sub_at_top_nat Filter.tendsto_sub_atTop_nat
theorem tendsto_add_atTop_iff_nat {f : ℕ → α} {l : Filter α} (k : ℕ) :
Tendsto (fun n => f (n + k)) atTop l ↔ Tendsto f atTop l :=
show Tendsto (f ∘ fun n => n + k) atTop l ↔ Tendsto f atTop l by
rw [← tendsto_map'_iff, map_add_atTop_eq_nat]
#align filter.tendsto_add_at_top_iff_nat Filter.tendsto_add_atTop_iff_nat
theorem map_div_atTop_eq_nat (k : ℕ) (hk : 0 < k) : map (fun a => a / k) atTop = atTop :=
map_atTop_eq_of_gc (fun b => b * k + (k - 1)) 1 (fun a b h => Nat.div_le_div_right h)
-- Porting note: there was a parse error in `calc`, use `simp` instead
(fun a b _ => by simp only [← Nat.lt_succ_iff, Nat.div_lt_iff_lt_mul hk, Nat.succ_eq_add_one,
add_assoc, tsub_add_cancel_of_le (Nat.one_le_iff_ne_zero.2 hk.ne'), add_mul, one_mul])
fun b _ =>
calc
b = b * k / k := by rw [Nat.mul_div_cancel b hk]
_ ≤ (b * k + (k - 1)) / k := Nat.div_le_div_right <| Nat.le_add_right _ _
#align filter.map_div_at_top_eq_nat Filter.map_div_atTop_eq_nat
/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded
above, then `Tendsto u atTop atTop`. -/
theorem tendsto_atTop_atTop_of_monotone' [Preorder ι] [LinearOrder α] {u : ι → α} (h : Monotone u)
(H : ¬BddAbove (range u)) : Tendsto u atTop atTop := by
apply h.tendsto_atTop_atTop
intro b
rcases not_bddAbove_iff.1 H b with ⟨_, ⟨N, rfl⟩, hN⟩
exact ⟨N, le_of_lt hN⟩
#align filter.tendsto_at_top_at_top_of_monotone' Filter.tendsto_atTop_atTop_of_monotone'
/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded
below, then `Tendsto u atBot atBot`. -/
theorem tendsto_atBot_atBot_of_monotone' [Preorder ι] [LinearOrder α] {u : ι → α} (h : Monotone u)
(H : ¬BddBelow (range u)) : Tendsto u atBot atBot :=
@tendsto_atTop_atTop_of_monotone' ιᵒᵈ αᵒᵈ _ _ _ h.dual H
#align filter.tendsto_at_bot_at_bot_of_monotone' Filter.tendsto_atBot_atBot_of_monotone'
theorem unbounded_of_tendsto_atTop [Nonempty α] [SemilatticeSup α] [Preorder β] [NoMaxOrder β]
{f : α → β} (h : Tendsto f atTop atTop) : ¬BddAbove (range f) := by
rintro ⟨M, hM⟩
cases' mem_atTop_sets.mp (h <| Ioi_mem_atTop M) with a ha
apply lt_irrefl M
calc
M < f a := ha a le_rfl
_ ≤ M := hM (Set.mem_range_self a)
#align filter.unbounded_of_tendsto_at_top Filter.unbounded_of_tendsto_atTop
theorem unbounded_of_tendsto_atBot [Nonempty α] [SemilatticeSup α] [Preorder β] [NoMinOrder β]
{f : α → β} (h : Tendsto f atTop atBot) : ¬BddBelow (range f) :=
@unbounded_of_tendsto_atTop _ βᵒᵈ _ _ _ _ _ h
#align filter.unbounded_of_tendsto_at_bot Filter.unbounded_of_tendsto_atBot
theorem unbounded_of_tendsto_atTop' [Nonempty α] [SemilatticeInf α] [Preorder β] [NoMaxOrder β]
{f : α → β} (h : Tendsto f atBot atTop) : ¬BddAbove (range f) :=
@unbounded_of_tendsto_atTop αᵒᵈ _ _ _ _ _ _ h
#align filter.unbounded_of_tendsto_at_top' Filter.unbounded_of_tendsto_atTop'
theorem unbounded_of_tendsto_atBot' [Nonempty α] [SemilatticeInf α] [Preorder β] [NoMinOrder β]
{f : α → β} (h : Tendsto f atBot atBot) : ¬BddBelow (range f) :=
@unbounded_of_tendsto_atTop αᵒᵈ βᵒᵈ _ _ _ _ _ h
#align filter.unbounded_of_tendsto_at_bot' Filter.unbounded_of_tendsto_atBot'
/-- If a monotone function `u : ι → α` tends to `atTop` along *some* non-trivial filter `l`, then
it tends to `atTop` along `atTop`. -/
theorem tendsto_atTop_of_monotone_of_filter [Preorder ι] [Preorder α] {l : Filter ι} {u : ι → α}
(h : Monotone u) [NeBot l] (hu : Tendsto u l atTop) : Tendsto u atTop atTop :=
h.tendsto_atTop_atTop fun b => (hu.eventually (mem_atTop b)).exists
#align filter.tendsto_at_top_of_monotone_of_filter Filter.tendsto_atTop_of_monotone_of_filter
/-- If a monotone function `u : ι → α` tends to `atBot` along *some* non-trivial filter `l`, then
it tends to `atBot` along `atBot`. -/
theorem tendsto_atBot_of_monotone_of_filter [Preorder ι] [Preorder α] {l : Filter ι} {u : ι → α}
(h : Monotone u) [NeBot l] (hu : Tendsto u l atBot) : Tendsto u atBot atBot :=
@tendsto_atTop_of_monotone_of_filter ιᵒᵈ αᵒᵈ _ _ _ _ h.dual _ hu
#align filter.tendsto_at_bot_of_monotone_of_filter Filter.tendsto_atBot_of_monotone_of_filter
theorem tendsto_atTop_of_monotone_of_subseq [Preorder ι] [Preorder α] {u : ι → α} {φ : ι' → ι}
(h : Monotone u) {l : Filter ι'} [NeBot l] (H : Tendsto (u ∘ φ) l atTop) :
Tendsto u atTop atTop :=
tendsto_atTop_of_monotone_of_filter h (tendsto_map' H)
#align filter.tendsto_at_top_of_monotone_of_subseq Filter.tendsto_atTop_of_monotone_of_subseq
theorem tendsto_atBot_of_monotone_of_subseq [Preorder ι] [Preorder α] {u : ι → α} {φ : ι' → ι}
(h : Monotone u) {l : Filter ι'} [NeBot l] (H : Tendsto (u ∘ φ) l atBot) :
Tendsto u atBot atBot :=
tendsto_atBot_of_monotone_of_filter h (tendsto_map' H)
#align filter.tendsto_at_bot_of_monotone_of_subseq Filter.tendsto_atBot_of_monotone_of_subseq
/-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient
condition for comparison of the filter `atTop.map (fun s ↦ ∏ b ∈ s, f b)` with
`atTop.map (fun s ↦ ∏ b ∈ s, g b)`. This is useful to compare the set of limit points of
`Π b in s, f b` as `s → atTop` with the similar set for `g`. -/
@[to_additive "Let `f` and `g` be two maps to the same commutative additive monoid. This lemma gives
a sufficient condition for comparison of the filter `atTop.map (fun s ↦ ∑ b ∈ s, f b)` with
`atTop.map (fun s ↦ ∑ b ∈ s, g b)`. This is useful to compare the set of limit points of
`∑ b ∈ s, f b` as `s → atTop` with the similar set for `g`."]
| Mathlib/Order/Filter/AtTopBot.lean | 1,889 | 1,898 | theorem map_atTop_finset_prod_le_of_prod_eq [CommMonoid α] {f : β → α} {g : γ → α}
(h_eq : ∀ u : Finset γ,
∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) :
(atTop.map fun s : Finset β => ∏ b ∈ s, f b) ≤
atTop.map fun s : Finset γ => ∏ x ∈ s, g x := by |
classical
refine ((atTop_basis.map _).le_basis_iff (atTop_basis.map _)).2 fun b _ => ?_
let ⟨v, hv⟩ := h_eq b
refine ⟨v, trivial, ?_⟩
simpa [image_subset_iff] using hv
|
/-
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
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'⟩
#align measure_theory.not_is_finite_measure_iff MeasureTheory.not_isFiniteMeasure_iff
instance Restrict.isFiniteMeasure (μ : Measure α) [hs : Fact (μ s < ∞)] :
IsFiniteMeasure (μ.restrict s) :=
⟨by simpa using hs.elim⟩
#align measure_theory.restrict.is_finite_measure MeasureTheory.Restrict.isFiniteMeasure
theorem measure_lt_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s < ∞ :=
(measure_mono (subset_univ s)).trans_lt IsFiniteMeasure.measure_univ_lt_top
#align measure_theory.measure_lt_top MeasureTheory.measure_lt_top
instance isFiniteMeasureRestrict (μ : Measure α) (s : Set α) [h : IsFiniteMeasure μ] :
IsFiniteMeasure (μ.restrict s) :=
⟨by simpa using measure_lt_top μ s⟩
#align measure_theory.is_finite_measure_restrict MeasureTheory.isFiniteMeasureRestrict
theorem measure_ne_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s ≠ ∞ :=
ne_of_lt (measure_lt_top μ s)
#align measure_theory.measure_ne_top MeasureTheory.measure_ne_top
theorem measure_compl_le_add_of_le_add [IsFiniteMeasure μ] (hs : MeasurableSet s)
(ht : MeasurableSet t) {ε : ℝ≥0∞} (h : μ s ≤ μ t + ε) : μ tᶜ ≤ μ sᶜ + ε := by
rw [measure_compl ht (measure_ne_top μ _), measure_compl hs (measure_ne_top μ _),
tsub_le_iff_right]
calc
μ univ = μ univ - μ s + μ s := (tsub_add_cancel_of_le <| measure_mono s.subset_univ).symm
_ ≤ μ univ - μ s + (μ t + ε) := add_le_add_left h _
_ = _ := by rw [add_right_comm, add_assoc]
#align measure_theory.measure_compl_le_add_of_le_add MeasureTheory.measure_compl_le_add_of_le_add
theorem measure_compl_le_add_iff [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t)
{ε : ℝ≥0∞} : μ sᶜ ≤ μ tᶜ + ε ↔ μ t ≤ μ s + ε :=
⟨fun h => compl_compl s ▸ compl_compl t ▸ measure_compl_le_add_of_le_add hs.compl ht.compl h,
measure_compl_le_add_of_le_add ht hs⟩
#align measure_theory.measure_compl_le_add_iff MeasureTheory.measure_compl_le_add_iff
/-- The measure of the whole space with respect to a finite measure, considered as `ℝ≥0`. -/
def measureUnivNNReal (μ : Measure α) : ℝ≥0 :=
(μ univ).toNNReal
#align measure_theory.measure_univ_nnreal MeasureTheory.measureUnivNNReal
@[simp]
theorem coe_measureUnivNNReal (μ : Measure α) [IsFiniteMeasure μ] :
↑(measureUnivNNReal μ) = μ univ :=
ENNReal.coe_toNNReal (measure_ne_top μ univ)
#align measure_theory.coe_measure_univ_nnreal MeasureTheory.coe_measureUnivNNReal
instance isFiniteMeasureZero : IsFiniteMeasure (0 : Measure α) :=
⟨by simp⟩
#align measure_theory.is_finite_measure_zero MeasureTheory.isFiniteMeasureZero
instance (priority := 50) isFiniteMeasureOfIsEmpty [IsEmpty α] : IsFiniteMeasure μ := by
rw [eq_zero_of_isEmpty μ]
infer_instance
#align measure_theory.is_finite_measure_of_is_empty MeasureTheory.isFiniteMeasureOfIsEmpty
@[simp]
theorem measureUnivNNReal_zero : measureUnivNNReal (0 : Measure α) = 0 :=
rfl
#align measure_theory.measure_univ_nnreal_zero MeasureTheory.measureUnivNNReal_zero
instance isFiniteMeasureAdd [IsFiniteMeasure μ] [IsFiniteMeasure ν] : IsFiniteMeasure (μ + ν) where
measure_univ_lt_top := by
rw [Measure.coe_add, Pi.add_apply, ENNReal.add_lt_top]
exact ⟨measure_lt_top _ _, measure_lt_top _ _⟩
#align measure_theory.is_finite_measure_add MeasureTheory.isFiniteMeasureAdd
instance isFiniteMeasureSMulNNReal [IsFiniteMeasure μ] {r : ℝ≥0} : IsFiniteMeasure (r • μ) where
measure_univ_lt_top := ENNReal.mul_lt_top ENNReal.coe_ne_top (measure_ne_top _ _)
#align measure_theory.is_finite_measure_smul_nnreal MeasureTheory.isFiniteMeasureSMulNNReal
instance IsFiniteMeasure.average : IsFiniteMeasure ((μ univ)⁻¹ • μ) where
measure_univ_lt_top := by
rw [smul_apply, smul_eq_mul, ← ENNReal.div_eq_inv_mul]
exact ENNReal.div_self_le_one.trans_lt ENNReal.one_lt_top
instance isFiniteMeasureSMulOfNNRealTower {R} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] [IsFiniteMeasure μ] {r : R} : IsFiniteMeasure (r • μ) := by
rw [← smul_one_smul ℝ≥0 r μ]
infer_instance
#align measure_theory.is_finite_measure_smul_of_nnreal_tower MeasureTheory.isFiniteMeasureSMulOfNNRealTower
theorem isFiniteMeasure_of_le (μ : Measure α) [IsFiniteMeasure μ] (h : ν ≤ μ) : IsFiniteMeasure ν :=
{ measure_univ_lt_top := (h Set.univ).trans_lt (measure_lt_top _ _) }
#align measure_theory.is_finite_measure_of_le MeasureTheory.isFiniteMeasure_of_le
@[instance]
theorem Measure.isFiniteMeasure_map {m : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ]
(f : α → β) : IsFiniteMeasure (μ.map f) := by
by_cases hf : AEMeasurable f μ
· constructor
rw [map_apply_of_aemeasurable hf MeasurableSet.univ]
exact measure_lt_top μ _
· rw [map_of_not_aemeasurable hf]
exact MeasureTheory.isFiniteMeasureZero
#align measure_theory.measure.is_finite_measure_map MeasureTheory.Measure.isFiniteMeasure_map
@[simp]
theorem measureUnivNNReal_eq_zero [IsFiniteMeasure μ] : measureUnivNNReal μ = 0 ↔ μ = 0 := by
rw [← MeasureTheory.Measure.measure_univ_eq_zero, ← coe_measureUnivNNReal]
norm_cast
#align measure_theory.measure_univ_nnreal_eq_zero MeasureTheory.measureUnivNNReal_eq_zero
theorem measureUnivNNReal_pos [IsFiniteMeasure μ] (hμ : μ ≠ 0) : 0 < measureUnivNNReal μ := by
contrapose! hμ
simpa [measureUnivNNReal_eq_zero, Nat.le_zero] using hμ
#align measure_theory.measure_univ_nnreal_pos MeasureTheory.measureUnivNNReal_pos
/-- `le_of_add_le_add_left` is normally applicable to `OrderedCancelAddCommMonoid`,
but it holds for measures with the additional assumption that μ is finite. -/
theorem Measure.le_of_add_le_add_left [IsFiniteMeasure μ] (A2 : μ + ν₁ ≤ μ + ν₂) : ν₁ ≤ ν₂ :=
fun S => ENNReal.le_of_add_le_add_left (MeasureTheory.measure_ne_top μ S) (A2 S)
#align measure_theory.measure.le_of_add_le_add_left MeasureTheory.Measure.le_of_add_le_add_left
theorem summable_measure_toReal [hμ : IsFiniteMeasure μ] {f : ℕ → Set α}
(hf₁ : ∀ i : ℕ, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) :
Summable fun x => (μ (f x)).toReal := by
apply ENNReal.summable_toReal
rw [← MeasureTheory.measure_iUnion hf₂ hf₁]
exact ne_of_lt (measure_lt_top _ _)
#align measure_theory.summable_measure_to_real MeasureTheory.summable_measure_toReal
theorem ae_eq_univ_iff_measure_eq [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ) :
s =ᵐ[μ] univ ↔ μ s = μ univ := by
refine ⟨measure_congr, fun h => ?_⟩
obtain ⟨t, -, ht₁, ht₂⟩ := hs.exists_measurable_subset_ae_eq
exact
ht₂.symm.trans
(ae_eq_of_subset_of_measure_ge (subset_univ t) (Eq.le ((measure_congr ht₂).trans h).symm) ht₁
(measure_ne_top μ univ))
#align measure_theory.ae_eq_univ_iff_measure_eq MeasureTheory.ae_eq_univ_iff_measure_eq
theorem ae_iff_measure_eq [IsFiniteMeasure μ] {p : α → Prop}
(hp : NullMeasurableSet { a | p a } μ) : (∀ᵐ a ∂μ, p a) ↔ μ { a | p a } = μ univ := by
rw [← ae_eq_univ_iff_measure_eq hp, eventuallyEq_univ, eventually_iff]
#align measure_theory.ae_iff_measure_eq MeasureTheory.ae_iff_measure_eq
theorem ae_mem_iff_measure_eq [IsFiniteMeasure μ] {s : Set α} (hs : NullMeasurableSet s μ) :
(∀ᵐ a ∂μ, a ∈ s) ↔ μ s = μ univ :=
ae_iff_measure_eq hs
#align measure_theory.ae_mem_iff_measure_eq MeasureTheory.ae_mem_iff_measure_eq
lemma tendsto_measure_biUnion_Ici_zero_of_pairwise_disjoint
{X : Type*} [MeasurableSpace X] {μ : Measure X} [IsFiniteMeasure μ]
{Es : ℕ → Set X} (Es_mble : ∀ i, MeasurableSet (Es i))
(Es_disj : Pairwise fun n m ↦ Disjoint (Es n) (Es m)) :
Tendsto (μ ∘ fun n ↦ ⋃ i ≥ n, Es i) atTop (𝓝 0) := by
have decr : Antitone fun n ↦ ⋃ i ≥ n, Es i :=
fun n m hnm ↦ biUnion_mono (fun _ hi ↦ le_trans hnm hi) (fun _ _ ↦ subset_rfl)
have nothing : ⋂ n, ⋃ i ≥ n, Es i = ∅ := by
apply subset_antisymm _ (empty_subset _)
intro x hx
simp only [ge_iff_le, mem_iInter, mem_iUnion, exists_prop] at hx
obtain ⟨j, _, x_in_Es_j⟩ := hx 0
obtain ⟨k, k_gt_j, x_in_Es_k⟩ := hx (j+1)
have oops := (Es_disj (Nat.ne_of_lt k_gt_j)).ne_of_mem x_in_Es_j x_in_Es_k
contradiction
have key :=
tendsto_measure_iInter (μ := μ) (fun n ↦ by measurability) decr ⟨0, measure_ne_top _ _⟩
simp only [ge_iff_le, nothing, measure_empty] at key
convert key
open scoped symmDiff
theorem abs_toReal_measure_sub_le_measure_symmDiff'
(hs : MeasurableSet s) (ht : MeasurableSet t) (hs' : μ s ≠ ∞) (ht' : μ t ≠ ∞) :
|(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal := by
have hst : μ (s \ t) ≠ ∞ := (measure_lt_top_of_subset diff_subset hs').ne
have hts : μ (t \ s) ≠ ∞ := (measure_lt_top_of_subset diff_subset ht').ne
suffices (μ s).toReal - (μ t).toReal = (μ (s \ t)).toReal - (μ (t \ s)).toReal by
rw [this, measure_symmDiff_eq hs ht, ENNReal.toReal_add hst hts]
convert abs_sub (μ (s \ t)).toReal (μ (t \ s)).toReal <;> simp
rw [measure_diff' s ht ht', measure_diff' t hs hs',
ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top hs' ht'),
ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top ht' hs'),
union_comm t s]
abel
theorem abs_toReal_measure_sub_le_measure_symmDiff [IsFiniteMeasure μ]
(hs : MeasurableSet s) (ht : MeasurableSet t) :
|(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal :=
abs_toReal_measure_sub_le_measure_symmDiff' hs ht (measure_ne_top μ s) (measure_ne_top μ t)
end IsFiniteMeasure
section IsProbabilityMeasure
/-- A measure `μ` is called a probability measure if `μ univ = 1`. -/
class IsProbabilityMeasure (μ : Measure α) : Prop where
measure_univ : μ univ = 1
#align measure_theory.is_probability_measure MeasureTheory.IsProbabilityMeasure
#align measure_theory.is_probability_measure.measure_univ MeasureTheory.IsProbabilityMeasure.measure_univ
export MeasureTheory.IsProbabilityMeasure (measure_univ)
attribute [simp] IsProbabilityMeasure.measure_univ
lemma isProbabilityMeasure_iff : IsProbabilityMeasure μ ↔ μ univ = 1 :=
⟨fun _ ↦ measure_univ, IsProbabilityMeasure.mk⟩
instance (priority := 100) IsProbabilityMeasure.toIsFiniteMeasure (μ : Measure α)
[IsProbabilityMeasure μ] : IsFiniteMeasure μ :=
⟨by simp only [measure_univ, ENNReal.one_lt_top]⟩
#align measure_theory.is_probability_measure.to_is_finite_measure MeasureTheory.IsProbabilityMeasure.toIsFiniteMeasure
theorem IsProbabilityMeasure.ne_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ ≠ 0 :=
mt measure_univ_eq_zero.2 <| by simp [measure_univ]
#align measure_theory.is_probability_measure.ne_zero MeasureTheory.IsProbabilityMeasure.ne_zero
instance (priority := 100) IsProbabilityMeasure.neZero (μ : Measure α) [IsProbabilityMeasure μ] :
NeZero μ := ⟨IsProbabilityMeasure.ne_zero μ⟩
-- Porting note: no longer an `instance` because `inferInstance` can find it now
theorem IsProbabilityMeasure.ae_neBot [IsProbabilityMeasure μ] : NeBot (ae μ) := inferInstance
#align measure_theory.is_probability_measure.ae_ne_bot MeasureTheory.IsProbabilityMeasure.ae_neBot
theorem prob_add_prob_compl [IsProbabilityMeasure μ] (h : MeasurableSet s) : μ s + μ sᶜ = 1 :=
(measure_add_measure_compl h).trans measure_univ
#align measure_theory.prob_add_prob_compl MeasureTheory.prob_add_prob_compl
theorem prob_le_one [IsProbabilityMeasure μ] : μ s ≤ 1 :=
(measure_mono <| Set.subset_univ _).trans_eq measure_univ
#align measure_theory.prob_le_one MeasureTheory.prob_le_one
-- Porting note: made an `instance`, using `NeZero`
instance isProbabilityMeasureSMul [IsFiniteMeasure μ] [NeZero μ] :
IsProbabilityMeasure ((μ univ)⁻¹ • μ) :=
⟨ENNReal.inv_mul_cancel (NeZero.ne (μ univ)) (measure_ne_top _ _)⟩
#align measure_theory.is_probability_measure_smul MeasureTheory.isProbabilityMeasureSMulₓ
variable [IsProbabilityMeasure μ] {p : α → Prop} {f : β → α}
theorem isProbabilityMeasure_map {f : α → β} (hf : AEMeasurable f μ) :
IsProbabilityMeasure (map f μ) :=
⟨by simp [map_apply_of_aemeasurable, hf]⟩
#align measure_theory.is_probability_measure_map MeasureTheory.isProbabilityMeasure_map
@[simp]
theorem one_le_prob_iff : 1 ≤ μ s ↔ μ s = 1 :=
⟨fun h => le_antisymm prob_le_one h, fun h => h ▸ le_refl _⟩
#align measure_theory.one_le_prob_iff MeasureTheory.one_le_prob_iff
/-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`.
Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the
better-behaved subtraction of `ℝ`. -/
lemma prob_compl_eq_one_sub₀ (h : NullMeasurableSet s μ) : μ sᶜ = 1 - μ s := by
rw [measure_compl₀ h (measure_ne_top _ _), measure_univ]
/-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`.
Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the
better-behaved subtraction of `ℝ`. -/
theorem prob_compl_eq_one_sub (hs : MeasurableSet s) : μ sᶜ = 1 - μ s :=
prob_compl_eq_one_sub₀ hs.nullMeasurableSet
#align measure_theory.prob_compl_eq_one_sub MeasureTheory.prob_compl_eq_one_sub
lemma prob_compl_lt_one_sub_of_lt_prob {p : ℝ≥0∞} (hμs : p < μ s) (s_mble : MeasurableSet s) :
μ sᶜ < 1 - p := by
rw [prob_compl_eq_one_sub s_mble]
apply ENNReal.sub_lt_of_sub_lt prob_le_one (Or.inl one_ne_top)
convert hμs
exact ENNReal.sub_sub_cancel one_ne_top (lt_of_lt_of_le hμs prob_le_one).le
lemma prob_compl_le_one_sub_of_le_prob {p : ℝ≥0∞} (hμs : p ≤ μ s) (s_mble : MeasurableSet s) :
μ sᶜ ≤ 1 - p := by
simpa [prob_compl_eq_one_sub s_mble] using tsub_le_tsub_left hμs 1
@[simp] lemma prob_compl_eq_zero_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 0 ↔ μ s = 1 := by
rw [prob_compl_eq_one_sub₀ hs, tsub_eq_zero_iff_le, one_le_prob_iff]
@[simp] lemma prob_compl_eq_zero_iff (hs : MeasurableSet s) : μ sᶜ = 0 ↔ μ s = 1 :=
prob_compl_eq_zero_iff₀ hs.nullMeasurableSet
#align measure_theory.prob_compl_eq_zero_iff MeasureTheory.prob_compl_eq_zero_iff
@[simp] lemma prob_compl_eq_one_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 1 ↔ μ s = 0 := by
rw [← prob_compl_eq_zero_iff₀ hs.compl, compl_compl]
@[simp] lemma prob_compl_eq_one_iff (hs : MeasurableSet s) : μ sᶜ = 1 ↔ μ s = 0 :=
prob_compl_eq_one_iff₀ hs.nullMeasurableSet
#align measure_theory.prob_compl_eq_one_iff MeasureTheory.prob_compl_eq_one_iff
lemma mem_ae_iff_prob_eq_one₀ (hs : NullMeasurableSet s μ) : s ∈ ae μ ↔ μ s = 1 :=
mem_ae_iff.trans <| prob_compl_eq_zero_iff₀ hs
lemma mem_ae_iff_prob_eq_one (hs : MeasurableSet s) : s ∈ ae μ ↔ μ s = 1 :=
mem_ae_iff.trans <| prob_compl_eq_zero_iff hs
lemma ae_iff_prob_eq_one (hp : Measurable p) : (∀ᵐ a ∂μ, p a) ↔ μ {a | p a} = 1 :=
mem_ae_iff_prob_eq_one hp.setOf
lemma isProbabilityMeasure_comap (hf : Injective f) (hf' : ∀ᵐ a ∂μ, a ∈ range f)
(hf'' : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) :
IsProbabilityMeasure (μ.comap f) where
measure_univ := by
rw [comap_apply _ hf hf'' _ MeasurableSet.univ,
← mem_ae_iff_prob_eq_one (hf'' _ MeasurableSet.univ)]
simpa
protected lemma _root_.MeasurableEmbedding.isProbabilityMeasure_comap (hf : MeasurableEmbedding f)
(hf' : ∀ᵐ a ∂μ, a ∈ range f) : IsProbabilityMeasure (μ.comap f) :=
isProbabilityMeasure_comap hf.injective hf' hf.measurableSet_image'
instance isProbabilityMeasure_map_up :
IsProbabilityMeasure (μ.map ULift.up) := isProbabilityMeasure_map measurable_up.aemeasurable
instance isProbabilityMeasure_comap_down : IsProbabilityMeasure (μ.comap ULift.down) :=
MeasurableEquiv.ulift.measurableEmbedding.isProbabilityMeasure_comap <| ae_of_all _ <| by
simp [Function.Surjective.range_eq <| EquivLike.surjective _]
end IsProbabilityMeasure
section NoAtoms
/-- Measure `μ` *has no atoms* if the measure of each singleton is zero.
NB: Wikipedia assumes that for any measurable set `s` with positive `μ`-measure,
there exists a measurable `t ⊆ s` such that `0 < μ t < μ s`. While this implies `μ {x} = 0`,
the converse is not true. -/
class NoAtoms {m0 : MeasurableSpace α} (μ : Measure α) : Prop where
measure_singleton : ∀ x, μ {x} = 0
#align measure_theory.has_no_atoms MeasureTheory.NoAtoms
#align measure_theory.has_no_atoms.measure_singleton MeasureTheory.NoAtoms.measure_singleton
export MeasureTheory.NoAtoms (measure_singleton)
attribute [simp] measure_singleton
variable [NoAtoms μ]
theorem _root_.Set.Subsingleton.measure_zero (hs : s.Subsingleton) (μ : Measure α) [NoAtoms μ] :
μ s = 0 :=
hs.induction_on (p := fun s => μ s = 0) measure_empty measure_singleton
#align set.subsingleton.measure_zero Set.Subsingleton.measure_zero
theorem Measure.restrict_singleton' {a : α} : μ.restrict {a} = 0 := by
simp only [measure_singleton, Measure.restrict_eq_zero]
#align measure_theory.measure.restrict_singleton' MeasureTheory.Measure.restrict_singleton'
instance Measure.restrict.instNoAtoms (s : Set α) : NoAtoms (μ.restrict s) := by
refine ⟨fun x => ?_⟩
obtain ⟨t, hxt, ht1, ht2⟩ := exists_measurable_superset_of_null (measure_singleton x : μ {x} = 0)
apply measure_mono_null hxt
rw [Measure.restrict_apply ht1]
apply measure_mono_null inter_subset_left ht2
#align measure_theory.measure.restrict.has_no_atoms MeasureTheory.Measure.restrict.instNoAtoms
theorem _root_.Set.Countable.measure_zero (h : s.Countable) (μ : Measure α) [NoAtoms μ] :
μ s = 0 := by
rw [← biUnion_of_singleton s, measure_biUnion_null_iff h]
simp
#align set.countable.measure_zero Set.Countable.measure_zero
theorem _root_.Set.Countable.ae_not_mem (h : s.Countable) (μ : Measure α) [NoAtoms μ] :
∀ᵐ x ∂μ, x ∉ s := by
simpa only [ae_iff, Classical.not_not] using h.measure_zero μ
#align set.countable.ae_not_mem Set.Countable.ae_not_mem
lemma _root_.Set.Countable.measure_restrict_compl (h : s.Countable) (μ : Measure α) [NoAtoms μ] :
μ.restrict sᶜ = μ :=
restrict_eq_self_of_ae_mem <| h.ae_not_mem μ
@[simp]
lemma restrict_compl_singleton (a : α) : μ.restrict ({a}ᶜ) = μ :=
(countable_singleton _).measure_restrict_compl μ
theorem _root_.Set.Finite.measure_zero (h : s.Finite) (μ : Measure α) [NoAtoms μ] : μ s = 0 :=
h.countable.measure_zero μ
#align set.finite.measure_zero Set.Finite.measure_zero
theorem _root_.Finset.measure_zero (s : Finset α) (μ : Measure α) [NoAtoms μ] : μ s = 0 :=
s.finite_toSet.measure_zero μ
#align finset.measure_zero Finset.measure_zero
theorem insert_ae_eq_self (a : α) (s : Set α) : (insert a s : Set α) =ᵐ[μ] s :=
union_ae_eq_right.2 <| measure_mono_null diff_subset (measure_singleton _)
#align measure_theory.insert_ae_eq_self MeasureTheory.insert_ae_eq_self
section
variable [PartialOrder α] {a b : α}
theorem Iio_ae_eq_Iic : Iio a =ᵐ[μ] Iic a :=
Iio_ae_eq_Iic' (measure_singleton a)
#align measure_theory.Iio_ae_eq_Iic MeasureTheory.Iio_ae_eq_Iic
theorem Ioi_ae_eq_Ici : Ioi a =ᵐ[μ] Ici a :=
Ioi_ae_eq_Ici' (measure_singleton a)
#align measure_theory.Ioi_ae_eq_Ici MeasureTheory.Ioi_ae_eq_Ici
theorem Ioo_ae_eq_Ioc : Ioo a b =ᵐ[μ] Ioc a b :=
Ioo_ae_eq_Ioc' (measure_singleton b)
#align measure_theory.Ioo_ae_eq_Ioc MeasureTheory.Ioo_ae_eq_Ioc
theorem Ioc_ae_eq_Icc : Ioc a b =ᵐ[μ] Icc a b :=
Ioc_ae_eq_Icc' (measure_singleton a)
#align measure_theory.Ioc_ae_eq_Icc MeasureTheory.Ioc_ae_eq_Icc
theorem Ioo_ae_eq_Ico : Ioo a b =ᵐ[μ] Ico a b :=
Ioo_ae_eq_Ico' (measure_singleton a)
#align measure_theory.Ioo_ae_eq_Ico MeasureTheory.Ioo_ae_eq_Ico
theorem Ioo_ae_eq_Icc : Ioo a b =ᵐ[μ] Icc a b :=
Ioo_ae_eq_Icc' (measure_singleton a) (measure_singleton b)
#align measure_theory.Ioo_ae_eq_Icc MeasureTheory.Ioo_ae_eq_Icc
theorem Ico_ae_eq_Icc : Ico a b =ᵐ[μ] Icc a b :=
Ico_ae_eq_Icc' (measure_singleton b)
#align measure_theory.Ico_ae_eq_Icc MeasureTheory.Ico_ae_eq_Icc
theorem Ico_ae_eq_Ioc : Ico a b =ᵐ[μ] Ioc a b :=
Ico_ae_eq_Ioc' (measure_singleton a) (measure_singleton b)
#align measure_theory.Ico_ae_eq_Ioc MeasureTheory.Ico_ae_eq_Ioc
theorem restrict_Iio_eq_restrict_Iic : μ.restrict (Iio a) = μ.restrict (Iic a) :=
restrict_congr_set Iio_ae_eq_Iic
theorem restrict_Ioi_eq_restrict_Ici : μ.restrict (Ioi a) = μ.restrict (Ici a) :=
restrict_congr_set Ioi_ae_eq_Ici
theorem restrict_Ioo_eq_restrict_Ioc : μ.restrict (Ioo a b) = μ.restrict (Ioc a b) :=
restrict_congr_set Ioo_ae_eq_Ioc
theorem restrict_Ioc_eq_restrict_Icc : μ.restrict (Ioc a b) = μ.restrict (Icc a b) :=
restrict_congr_set Ioc_ae_eq_Icc
theorem restrict_Ioo_eq_restrict_Ico : μ.restrict (Ioo a b) = μ.restrict (Ico a b) :=
restrict_congr_set Ioo_ae_eq_Ico
theorem restrict_Ioo_eq_restrict_Icc : μ.restrict (Ioo a b) = μ.restrict (Icc a b) :=
restrict_congr_set Ioo_ae_eq_Icc
theorem restrict_Ico_eq_restrict_Icc : μ.restrict (Ico a b) = μ.restrict (Icc a b) :=
restrict_congr_set Ico_ae_eq_Icc
theorem restrict_Ico_eq_restrict_Ioc : μ.restrict (Ico a b) = μ.restrict (Ioc a b) :=
restrict_congr_set Ico_ae_eq_Ioc
end
open Interval
theorem uIoc_ae_eq_interval [LinearOrder α] {a b : α} : Ι a b =ᵐ[μ] [[a, b]] :=
Ioc_ae_eq_Icc
#align measure_theory.uIoc_ae_eq_interval MeasureTheory.uIoc_ae_eq_interval
end NoAtoms
theorem ite_ae_eq_of_measure_zero {γ} (f : α → γ) (g : α → γ) (s : Set α) [DecidablePred (· ∈ s)]
(hs_zero : μ s = 0) :
(fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] g := by
have h_ss : sᶜ ⊆ { a : α | ite (a ∈ s) (f a) (g a) = g a } := fun x hx => by
simp [(Set.mem_compl_iff _ _).mp hx]
refine measure_mono_null ?_ hs_zero
conv_rhs => rw [← compl_compl s]
rwa [Set.compl_subset_compl]
#align measure_theory.ite_ae_eq_of_measure_zero MeasureTheory.ite_ae_eq_of_measure_zero
theorem ite_ae_eq_of_measure_compl_zero {γ} (f : α → γ) (g : α → γ)
(s : Set α) [DecidablePred (· ∈ s)] (hs_zero : μ sᶜ = 0) :
(fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] f := by
rw [← mem_ae_iff] at hs_zero
filter_upwards [hs_zero]
intros
split_ifs
rfl
#align measure_theory.ite_ae_eq_of_measure_compl_zero MeasureTheory.ite_ae_eq_of_measure_compl_zero
namespace Measure
/-- A measure is called finite at filter `f` if it is finite at some set `s ∈ f`.
Equivalently, it is eventually finite at `s` in `f.small_sets`. -/
def FiniteAtFilter {_m0 : MeasurableSpace α} (μ : Measure α) (f : Filter α) : Prop :=
∃ s ∈ f, μ s < ∞
#align measure_theory.measure.finite_at_filter MeasureTheory.Measure.FiniteAtFilter
theorem finiteAtFilter_of_finite {_m0 : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ]
(f : Filter α) : μ.FiniteAtFilter f :=
⟨univ, univ_mem, measure_lt_top μ univ⟩
#align measure_theory.measure.finite_at_filter_of_finite MeasureTheory.Measure.finiteAtFilter_of_finite
theorem FiniteAtFilter.exists_mem_basis {f : Filter α} (hμ : FiniteAtFilter μ f) {p : ι → Prop}
{s : ι → Set α} (hf : f.HasBasis p s) : ∃ i, p i ∧ μ (s i) < ∞ :=
(hf.exists_iff fun {_s _t} hst ht => (measure_mono hst).trans_lt ht).1 hμ
#align measure_theory.measure.finite_at_filter.exists_mem_basis MeasureTheory.Measure.FiniteAtFilter.exists_mem_basis
theorem finiteAtBot {m0 : MeasurableSpace α} (μ : Measure α) : μ.FiniteAtFilter ⊥ :=
⟨∅, mem_bot, by simp only [measure_empty, zero_lt_top]⟩
#align measure_theory.measure.finite_at_bot MeasureTheory.Measure.finiteAtBot
/-- `μ` has finite spanning sets in `C` if there is a countable sequence of sets in `C` that have
finite measures. This structure is a type, which is useful if we want to record extra properties
about the sets, such as that they are monotone.
`SigmaFinite` is defined in terms of this: `μ` is σ-finite if there exists a sequence of
finite spanning sets in the collection of all measurable sets. -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
structure FiniteSpanningSetsIn {m0 : MeasurableSpace α} (μ : Measure α) (C : Set (Set α)) where
protected set : ℕ → Set α
protected set_mem : ∀ i, set i ∈ C
protected finite : ∀ i, μ (set i) < ∞
protected spanning : ⋃ i, set i = univ
#align measure_theory.measure.finite_spanning_sets_in MeasureTheory.Measure.FiniteSpanningSetsIn
#align measure_theory.measure.finite_spanning_sets_in.set MeasureTheory.Measure.FiniteSpanningSetsIn.set
#align measure_theory.measure.finite_spanning_sets_in.set_mem MeasureTheory.Measure.FiniteSpanningSetsIn.set_mem
#align measure_theory.measure.finite_spanning_sets_in.finite MeasureTheory.Measure.FiniteSpanningSetsIn.finite
#align measure_theory.measure.finite_spanning_sets_in.spanning MeasureTheory.Measure.FiniteSpanningSetsIn.spanning
end Measure
open Measure
section SFinite
/-- A measure is called s-finite if it is a countable sum of finite measures. -/
class SFinite (μ : Measure α) : Prop where
out' : ∃ m : ℕ → Measure α, (∀ n, IsFiniteMeasure (m n)) ∧ μ = Measure.sum m
/-- A sequence of finite measures such that `μ = sum (sFiniteSeq μ)` (see `sum_sFiniteSeq`). -/
noncomputable
def sFiniteSeq (μ : Measure α) [h : SFinite μ] : ℕ → Measure α := h.1.choose
instance isFiniteMeasure_sFiniteSeq [h : SFinite μ] (n : ℕ) : IsFiniteMeasure (sFiniteSeq μ n) :=
h.1.choose_spec.1 n
lemma sum_sFiniteSeq (μ : Measure α) [h : SFinite μ] : sum (sFiniteSeq μ) = μ :=
h.1.choose_spec.2.symm
instance : SFinite (0 : Measure α) := ⟨fun _ ↦ 0, inferInstance, by rw [Measure.sum_zero]⟩
@[simp]
lemma sFiniteSeq_zero (n : ℕ) : sFiniteSeq (0 : Measure α) n = 0 := by
ext s hs
have h : ∑' n, sFiniteSeq (0 : Measure α) n s = 0 := by
simp [← Measure.sum_apply _ hs, sum_sFiniteSeq]
simp only [ENNReal.tsum_eq_zero] at h
exact h n
/-- A countable sum of finite measures is s-finite.
This lemma is superseeded by the instance below. -/
lemma sfinite_sum_of_countable [Countable ι]
(m : ι → Measure α) [∀ n, IsFiniteMeasure (m n)] : SFinite (Measure.sum m) := by
classical
obtain ⟨f, hf⟩ : ∃ f : ι → ℕ, Function.Injective f := Countable.exists_injective_nat ι
refine ⟨_, fun n ↦ ?_, (sum_extend_zero hf m).symm⟩
rcases em (n ∈ range f) with ⟨i, rfl⟩ | hn
· rw [hf.extend_apply]
infer_instance
· rw [Function.extend_apply' _ _ _ hn, Pi.zero_apply]
infer_instance
instance [Countable ι] (m : ι → Measure α) [∀ n, SFinite (m n)] : SFinite (Measure.sum m) := by
change SFinite (Measure.sum (fun i ↦ m i))
simp_rw [← sum_sFiniteSeq (m _), Measure.sum_sum]
apply sfinite_sum_of_countable
instance [SFinite μ] [SFinite ν] : SFinite (μ + ν) := by
refine ⟨fun n ↦ sFiniteSeq μ n + sFiniteSeq ν n, inferInstance, ?_⟩
ext s hs
simp only [Measure.add_apply, sum_apply _ hs]
rw [tsum_add ENNReal.summable ENNReal.summable, ← sum_apply _ hs, ← sum_apply _ hs,
sum_sFiniteSeq, sum_sFiniteSeq]
instance [SFinite μ] (s : Set α) : SFinite (μ.restrict s) :=
⟨fun n ↦ (sFiniteSeq μ n).restrict s, fun n ↦ inferInstance,
by rw [← restrict_sum_of_countable, sum_sFiniteSeq]⟩
end SFinite
/-- A measure `μ` is called σ-finite if there is a countable collection of sets
`{ A i | i ∈ ℕ }` such that `μ (A i) < ∞` and `⋃ i, A i = s`. -/
class SigmaFinite {m0 : MeasurableSpace α} (μ : Measure α) : Prop where
out' : Nonempty (μ.FiniteSpanningSetsIn univ)
#align measure_theory.sigma_finite MeasureTheory.SigmaFinite
#align measure_theory.sigma_finite.out' MeasureTheory.SigmaFinite.out'
theorem sigmaFinite_iff : SigmaFinite μ ↔ Nonempty (μ.FiniteSpanningSetsIn univ) :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
#align measure_theory.sigma_finite_iff MeasureTheory.sigmaFinite_iff
theorem SigmaFinite.out (h : SigmaFinite μ) : Nonempty (μ.FiniteSpanningSetsIn univ) :=
h.1
#align measure_theory.sigma_finite.out MeasureTheory.SigmaFinite.out
/-- If `μ` is σ-finite it has finite spanning sets in the collection of all measurable sets. -/
def Measure.toFiniteSpanningSetsIn (μ : Measure α) [h : SigmaFinite μ] :
μ.FiniteSpanningSetsIn { s | MeasurableSet s } where
set n := toMeasurable μ (h.out.some.set n)
set_mem n := measurableSet_toMeasurable _ _
finite n := by
rw [measure_toMeasurable]
exact h.out.some.finite n
spanning := eq_univ_of_subset (iUnion_mono fun n => subset_toMeasurable _ _) h.out.some.spanning
#align measure_theory.measure.to_finite_spanning_sets_in MeasureTheory.Measure.toFiniteSpanningSetsIn
/-- A noncomputable way to get a monotone collection of sets that span `univ` and have finite
measure using `Classical.choose`. This definition satisfies monotonicity in addition to all other
properties in `SigmaFinite`. -/
def spanningSets (μ : Measure α) [SigmaFinite μ] (i : ℕ) : Set α :=
Accumulate μ.toFiniteSpanningSetsIn.set i
#align measure_theory.spanning_sets MeasureTheory.spanningSets
theorem monotone_spanningSets (μ : Measure α) [SigmaFinite μ] : Monotone (spanningSets μ) :=
monotone_accumulate
#align measure_theory.monotone_spanning_sets MeasureTheory.monotone_spanningSets
theorem measurable_spanningSets (μ : Measure α) [SigmaFinite μ] (i : ℕ) :
MeasurableSet (spanningSets μ i) :=
MeasurableSet.iUnion fun j => MeasurableSet.iUnion fun _ => μ.toFiniteSpanningSetsIn.set_mem j
#align measure_theory.measurable_spanning_sets MeasureTheory.measurable_spanningSets
theorem measure_spanningSets_lt_top (μ : Measure α) [SigmaFinite μ] (i : ℕ) :
μ (spanningSets μ i) < ∞ :=
measure_biUnion_lt_top (finite_le_nat i) fun j _ => (μ.toFiniteSpanningSetsIn.finite j).ne
#align measure_theory.measure_spanning_sets_lt_top MeasureTheory.measure_spanningSets_lt_top
theorem iUnion_spanningSets (μ : Measure α) [SigmaFinite μ] : ⋃ i : ℕ, spanningSets μ i = univ := by
simp_rw [spanningSets, iUnion_accumulate, μ.toFiniteSpanningSetsIn.spanning]
#align measure_theory.Union_spanning_sets MeasureTheory.iUnion_spanningSets
theorem isCountablySpanning_spanningSets (μ : Measure α) [SigmaFinite μ] :
IsCountablySpanning (range (spanningSets μ)) :=
⟨spanningSets μ, mem_range_self, iUnion_spanningSets μ⟩
#align measure_theory.is_countably_spanning_spanning_sets MeasureTheory.isCountablySpanning_spanningSets
open scoped Classical in
/-- `spanningSetsIndex μ x` is the least `n : ℕ` such that `x ∈ spanningSets μ n`. -/
noncomputable def spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) : ℕ :=
Nat.find <| iUnion_eq_univ_iff.1 (iUnion_spanningSets μ) x
#align measure_theory.spanning_sets_index MeasureTheory.spanningSetsIndex
open scoped Classical in
theorem measurable_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] :
Measurable (spanningSetsIndex μ) :=
measurable_find _ <| measurable_spanningSets μ
#align measure_theory.measurable_spanning_sets_index MeasureTheory.measurable_spanningSetsIndex
open scoped Classical in
theorem preimage_spanningSetsIndex_singleton (μ : Measure α) [SigmaFinite μ] (n : ℕ) :
spanningSetsIndex μ ⁻¹' {n} = disjointed (spanningSets μ) n :=
preimage_find_eq_disjointed _ _ _
#align measure_theory.preimage_spanning_sets_index_singleton MeasureTheory.preimage_spanningSetsIndex_singleton
theorem spanningSetsIndex_eq_iff (μ : Measure α) [SigmaFinite μ] {x : α} {n : ℕ} :
spanningSetsIndex μ x = n ↔ x ∈ disjointed (spanningSets μ) n := by
convert Set.ext_iff.1 (preimage_spanningSetsIndex_singleton μ n) x
#align measure_theory.spanning_sets_index_eq_iff MeasureTheory.spanningSetsIndex_eq_iff
theorem mem_disjointed_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) :
x ∈ disjointed (spanningSets μ) (spanningSetsIndex μ x) :=
(spanningSetsIndex_eq_iff μ).1 rfl
#align measure_theory.mem_disjointed_spanning_sets_index MeasureTheory.mem_disjointed_spanningSetsIndex
theorem mem_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) :
x ∈ spanningSets μ (spanningSetsIndex μ x) :=
disjointed_subset _ _ (mem_disjointed_spanningSetsIndex μ x)
#align measure_theory.mem_spanning_sets_index MeasureTheory.mem_spanningSetsIndex
theorem mem_spanningSets_of_index_le (μ : Measure α) [SigmaFinite μ] (x : α) {n : ℕ}
(hn : spanningSetsIndex μ x ≤ n) : x ∈ spanningSets μ n :=
monotone_spanningSets μ hn (mem_spanningSetsIndex μ x)
#align measure_theory.mem_spanning_sets_of_index_le MeasureTheory.mem_spanningSets_of_index_le
theorem eventually_mem_spanningSets (μ : Measure α) [SigmaFinite μ] (x : α) :
∀ᶠ n in atTop, x ∈ spanningSets μ n :=
eventually_atTop.2 ⟨spanningSetsIndex μ x, fun _ => mem_spanningSets_of_index_le μ x⟩
#align measure_theory.eventually_mem_spanning_sets MeasureTheory.eventually_mem_spanningSets
theorem sum_restrict_disjointed_spanningSets (μ : Measure α) [SigmaFinite μ] :
sum (fun n ↦ μ.restrict (disjointed (spanningSets μ) n)) = μ := by
rw [← restrict_iUnion (disjoint_disjointed _)
(MeasurableSet.disjointed (measurable_spanningSets _)),
iUnion_disjointed, iUnion_spanningSets, restrict_univ]
instance (priority := 100) [SigmaFinite μ] : SFinite μ := by
have : ∀ n, Fact (μ (disjointed (spanningSets μ) n) < ∞) :=
fun n ↦ ⟨(measure_mono (disjointed_subset _ _)).trans_lt (measure_spanningSets_lt_top μ n)⟩
exact ⟨⟨fun n ↦ μ.restrict (disjointed (spanningSets μ) n), fun n ↦ by infer_instance,
(sum_restrict_disjointed_spanningSets μ).symm⟩⟩
namespace Measure
/-- A set in a σ-finite space has zero measure if and only if its intersection with
all members of the countable family of finite measure spanning sets has zero measure. -/
theorem forall_measure_inter_spanningSets_eq_zero [MeasurableSpace α] {μ : Measure α}
[SigmaFinite μ] (s : Set α) : (∀ n, μ (s ∩ spanningSets μ n) = 0) ↔ μ s = 0 := by
nth_rw 2 [show s = ⋃ n, s ∩ spanningSets μ n by
rw [← inter_iUnion, iUnion_spanningSets, inter_univ] ]
rw [measure_iUnion_null_iff]
#align measure_theory.measure.forall_measure_inter_spanning_sets_eq_zero MeasureTheory.Measure.forall_measure_inter_spanningSets_eq_zero
/-- A set in a σ-finite space has positive measure if and only if its intersection with
some member of the countable family of finite measure spanning sets has positive measure. -/
theorem exists_measure_inter_spanningSets_pos [MeasurableSpace α] {μ : Measure α} [SigmaFinite μ]
(s : Set α) : (∃ n, 0 < μ (s ∩ spanningSets μ n)) ↔ 0 < μ s := by
rw [← not_iff_not]
simp only [not_exists, not_lt, nonpos_iff_eq_zero]
exact forall_measure_inter_spanningSets_eq_zero s
#align measure_theory.measure.exists_measure_inter_spanning_sets_pos MeasureTheory.Measure.exists_measure_inter_spanningSets_pos
/-- If the union of a.e.-disjoint null-measurable sets has finite measure, then there are only
finitely many members of the union whose measure exceeds any given positive number. -/
theorem finite_const_le_meas_of_disjoint_iUnion₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α)
{ε : ℝ≥0∞} (ε_pos : 0 < ε) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Finite { i : ι | ε ≤ μ (As i) } :=
ENNReal.finite_const_le_of_tsum_ne_top
(ne_top_of_le_ne_top Union_As_finite (tsum_meas_le_meas_iUnion_of_disjoint₀ μ As_mble As_disj))
ε_pos.ne'
/-- If the union of disjoint measurable sets has finite measure, then there are only
finitely many members of the union whose measure exceeds any given positive number. -/
theorem finite_const_le_meas_of_disjoint_iUnion {ι : Type*} [MeasurableSpace α] (μ : Measure α)
{ε : ℝ≥0∞} (ε_pos : 0 < ε) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Finite { i : ι | ε ≤ μ (As i) } :=
finite_const_le_meas_of_disjoint_iUnion₀ μ ε_pos (fun i ↦ (As_mble i).nullMeasurableSet)
(fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) Union_As_finite
#align measure_theory.measure.finite_const_le_meas_of_disjoint_Union MeasureTheory.Measure.finite_const_le_meas_of_disjoint_iUnion
/-- If all elements of an infinite set have measure uniformly separated from zero,
then the set has infinite measure. -/
theorem _root_.Set.Infinite.meas_eq_top [MeasurableSingletonClass α]
{s : Set α} (hs : s.Infinite) (h' : ∃ ε, ε ≠ 0 ∧ ∀ x ∈ s, ε ≤ μ {x}) : μ s = ∞ := top_unique <|
let ⟨ε, hne, hε⟩ := h'; have := hs.to_subtype
calc
∞ = ∑' _ : s, ε := (ENNReal.tsum_const_eq_top_of_ne_zero hne).symm
_ ≤ ∑' x : s, μ {x.1} := ENNReal.tsum_le_tsum fun x ↦ hε x x.2
_ ≤ μ (⋃ x : s, {x.1}) := tsum_meas_le_meas_iUnion_of_disjoint _
(fun _ ↦ MeasurableSet.singleton _) fun x y hne ↦ by simpa [Subtype.val_inj]
_ = μ s := by simp
/-- If the union of a.e.-disjoint null-measurable sets has finite measure, then there are only
countably many members of the union whose measure is positive. -/
theorem countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀ {ι : Type*} {_ : MeasurableSpace α}
(μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Countable { i : ι | 0 < μ (As i) } := by
set posmeas := { i : ι | 0 < μ (As i) } with posmeas_def
rcases exists_seq_strictAnti_tendsto' (zero_lt_one : (0 : ℝ≥0∞) < 1) with
⟨as, _, as_mem, as_lim⟩
set fairmeas := fun n : ℕ => { i : ι | as n ≤ μ (As i) }
have countable_union : posmeas = ⋃ n, fairmeas n := by
have fairmeas_eq : ∀ n, fairmeas n = (fun i => μ (As i)) ⁻¹' Ici (as n) := fun n => by
simp only [fairmeas]
rfl
simpa only [fairmeas_eq, posmeas_def, ← preimage_iUnion,
iUnion_Ici_eq_Ioi_of_lt_of_tendsto (0 : ℝ≥0∞) (fun n => (as_mem n).1) as_lim]
rw [countable_union]
refine countable_iUnion fun n => Finite.countable ?_
exact finite_const_le_meas_of_disjoint_iUnion₀ μ (as_mem n).1 As_mble As_disj Union_As_finite
/-- If the union of disjoint measurable sets has finite measure, then there are only
countably many members of the union whose measure is positive. -/
theorem countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top {ι : Type*} {_ : MeasurableSpace α}
(μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Countable { i : ι | 0 < μ (As i) } :=
countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀ μ (fun i ↦ (As_mble i).nullMeasurableSet)
((fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))) Union_As_finite
#align measure_theory.measure.countable_meas_pos_of_disjoint_of_meas_Union_ne_top MeasureTheory.Measure.countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top
/-- In an s-finite space, among disjoint null-measurable sets, only countably many can have positive
measure. -/
theorem countable_meas_pos_of_disjoint_iUnion₀ {ι : Type*} { _ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) :
Set.Countable { i : ι | 0 < μ (As i) } := by
rw [← sum_sFiniteSeq μ] at As_disj As_mble ⊢
have obs : { i : ι | 0 < sum (sFiniteSeq μ) (As i) }
⊆ ⋃ n, { i : ι | 0 < sFiniteSeq μ n (As i) } := by
intro i hi
by_contra con
simp only [mem_iUnion, mem_setOf_eq, not_exists, not_lt, nonpos_iff_eq_zero] at *
rw [sum_apply₀] at hi
· simp_rw [con] at hi
simp at hi
· exact As_mble i
apply Countable.mono obs
refine countable_iUnion fun n ↦ ?_
apply countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀
· exact fun i ↦ (As_mble i).mono (le_sum _ _)
· exact fun i j hij ↦ AEDisjoint.of_le (As_disj hij) (le_sum _ _)
· exact measure_ne_top _ (⋃ i, As i)
/-- In an s-finite space, among disjoint measurable sets, only countably many can have positive
measure. -/
theorem countable_meas_pos_of_disjoint_iUnion {ι : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) : Set.Countable { i : ι | 0 < μ (As i) } :=
countable_meas_pos_of_disjoint_iUnion₀ (fun i ↦ (As_mble i).nullMeasurableSet)
((fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)))
#align measure_theory.measure.countable_meas_pos_of_disjoint_Union MeasureTheory.Measure.countable_meas_pos_of_disjoint_iUnion
theorem countable_meas_level_set_pos₀ {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] [MeasurableSpace β] [MeasurableSingletonClass β] {g : α → β}
(g_mble : NullMeasurable g μ) : Set.Countable { t : β | 0 < μ { a : α | g a = t } } := by
have level_sets_disjoint : Pairwise (Disjoint on fun t : β => { a : α | g a = t }) :=
fun s t hst => Disjoint.preimage g (disjoint_singleton.mpr hst)
exact Measure.countable_meas_pos_of_disjoint_iUnion₀
(fun b => g_mble (‹MeasurableSingletonClass β›.measurableSet_singleton b))
((fun _ _ h ↦ Disjoint.aedisjoint (level_sets_disjoint h)))
theorem countable_meas_level_set_pos {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] [MeasurableSpace β] [MeasurableSingletonClass β] {g : α → β}
(g_mble : Measurable g) : Set.Countable { t : β | 0 < μ { a : α | g a = t } } :=
countable_meas_level_set_pos₀ g_mble.nullMeasurable
#align measure_theory.measure.countable_meas_level_set_pos MeasureTheory.Measure.countable_meas_level_set_pos
/-- If a measure `μ` is the sum of a countable family `mₙ`, and a set `t` has finite measure for
each `mₙ`, then its measurable superset `toMeasurable μ t` (which has the same measure as `t`)
satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`. -/
theorem measure_toMeasurable_inter_of_sum {s : Set α} (hs : MeasurableSet s) {t : Set α}
{m : ℕ → Measure α} (hv : ∀ n, m n t ≠ ∞) (hμ : μ = sum m) :
μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := by
-- we show that there is a measurable superset of `t` satisfying the conclusion for any
-- measurable set `s`. It is built for each measure `mₙ` using `toMeasurable`
-- (which is well behaved for finite measure sets thanks to `measure_toMeasurable_inter`), and
-- then taking the intersection over `n`.
have A : ∃ t', t' ⊇ t ∧ MeasurableSet t' ∧ ∀ u, MeasurableSet u → μ (t' ∩ u) = μ (t ∩ u) := by
let w n := toMeasurable (m n) t
have T : t ⊆ ⋂ n, w n := subset_iInter (fun i ↦ subset_toMeasurable (m i) t)
have M : MeasurableSet (⋂ n, w n) :=
MeasurableSet.iInter (fun i ↦ measurableSet_toMeasurable (m i) t)
refine ⟨⋂ n, w n, T, M, fun u hu ↦ ?_⟩
refine le_antisymm ?_ (by gcongr)
rw [hμ, sum_apply _ (M.inter hu)]
apply le_trans _ (le_sum_apply _ _)
apply ENNReal.tsum_le_tsum (fun i ↦ ?_)
calc
m i ((⋂ n, w n) ∩ u) ≤ m i (w i ∩ u) := by gcongr; apply iInter_subset
_ = m i (t ∩ u) := measure_toMeasurable_inter hu (hv i)
-- thanks to the definition of `toMeasurable`, the previous property will also be shared
-- by `toMeasurable μ t`, which is enough to conclude the proof.
rw [toMeasurable]
split_ifs with ht
· apply measure_congr
exact ae_eq_set_inter ht.choose_spec.2.2 (ae_eq_refl _)
· exact A.choose_spec.2.2 s hs
/-- If a set `t` is covered by a countable family of finite measure sets, then its measurable
superset `toMeasurable μ t` (which has the same measure as `t`) satisfies,
for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`. -/
theorem measure_toMeasurable_inter_of_cover {s : Set α} (hs : MeasurableSet s) {t : Set α}
{v : ℕ → Set α} (hv : t ⊆ ⋃ n, v n) (h'v : ∀ n, μ (t ∩ v n) ≠ ∞) :
μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := by
-- we show that there is a measurable superset of `t` satisfying the conclusion for any
-- measurable set `s`. It is built on each member of a spanning family using `toMeasurable`
-- (which is well behaved for finite measure sets thanks to `measure_toMeasurable_inter`), and
-- the desired property passes to the union.
have A : ∃ t', t' ⊇ t ∧ MeasurableSet t' ∧ ∀ u, MeasurableSet u → μ (t' ∩ u) = μ (t ∩ u) := by
let w n := toMeasurable μ (t ∩ v n)
have hw : ∀ n, μ (w n) < ∞ := by
intro n
simp_rw [w, measure_toMeasurable]
exact (h'v n).lt_top
set t' := ⋃ n, toMeasurable μ (t ∩ disjointed w n) with ht'
have tt' : t ⊆ t' :=
calc
t ⊆ ⋃ n, t ∩ disjointed w n := by
rw [← inter_iUnion, iUnion_disjointed, inter_iUnion]
intro x hx
rcases mem_iUnion.1 (hv hx) with ⟨n, hn⟩
refine mem_iUnion.2 ⟨n, ?_⟩
have : x ∈ t ∩ v n := ⟨hx, hn⟩
exact ⟨hx, subset_toMeasurable μ _ this⟩
_ ⊆ ⋃ n, toMeasurable μ (t ∩ disjointed w n) :=
iUnion_mono fun n => subset_toMeasurable _ _
refine ⟨t', tt', MeasurableSet.iUnion fun n => measurableSet_toMeasurable μ _, fun u hu => ?_⟩
apply le_antisymm _ (by gcongr)
calc
μ (t' ∩ u) ≤ ∑' n, μ (toMeasurable μ (t ∩ disjointed w n) ∩ u) := by
rw [ht', iUnion_inter]
exact measure_iUnion_le _
_ = ∑' n, μ (t ∩ disjointed w n ∩ u) := by
congr 1
ext1 n
apply measure_toMeasurable_inter hu
apply ne_of_lt
calc
μ (t ∩ disjointed w n) ≤ μ (t ∩ w n) := by
gcongr
exact disjointed_le w n
_ ≤ μ (w n) := measure_mono inter_subset_right
_ < ∞ := hw n
_ = ∑' n, μ.restrict (t ∩ u) (disjointed w n) := by
congr 1
ext1 n
rw [restrict_apply, inter_comm t _, inter_assoc]
refine MeasurableSet.disjointed (fun n => ?_) n
exact measurableSet_toMeasurable _ _
_ = μ.restrict (t ∩ u) (⋃ n, disjointed w n) := by
rw [measure_iUnion]
· exact disjoint_disjointed _
· intro i
refine MeasurableSet.disjointed (fun n => ?_) i
exact measurableSet_toMeasurable _ _
_ ≤ μ.restrict (t ∩ u) univ := measure_mono (subset_univ _)
_ = μ (t ∩ u) := by rw [restrict_apply MeasurableSet.univ, univ_inter]
-- thanks to the definition of `toMeasurable`, the previous property will also be shared
-- by `toMeasurable μ t`, which is enough to conclude the proof.
rw [toMeasurable]
split_ifs with ht
· apply measure_congr
exact ae_eq_set_inter ht.choose_spec.2.2 (ae_eq_refl _)
· exact A.choose_spec.2.2 s hs
#align measure_theory.measure.measure_to_measurable_inter_of_cover MeasureTheory.Measure.measure_toMeasurable_inter_of_cover
theorem restrict_toMeasurable_of_cover {s : Set α} {v : ℕ → Set α} (hv : s ⊆ ⋃ n, v n)
(h'v : ∀ n, μ (s ∩ v n) ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
simp only [restrict_apply ht, inter_comm t, measure_toMeasurable_inter_of_cover ht hv h'v]
#align measure_theory.measure.restrict_to_measurable_of_cover MeasureTheory.Measure.restrict_toMeasurable_of_cover
/-- 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) = μ (t ∩ s)`.
This only holds when `μ` is s-finite -- for example for σ-finite measures. For a version without
this assumption (but requiring that `t` has finite measure), see `measure_toMeasurable_inter`. -/
theorem measure_toMeasurable_inter_of_sFinite [SFinite μ] {s : Set α} (hs : MeasurableSet s)
(t : Set α) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) :=
measure_toMeasurable_inter_of_sum hs (fun _ ↦ measure_ne_top _ t) (sum_sFiniteSeq μ).symm
#align measure_theory.measure.measure_to_measurable_inter_of_sigma_finite MeasureTheory.Measure.measure_toMeasurable_inter_of_sFinite
@[simp]
theorem restrict_toMeasurable_of_sFinite [SFinite μ] (s : Set α) :
μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, inter_comm t, measure_toMeasurable_inter_of_sFinite ht,
restrict_apply ht, inter_comm t]
#align measure_theory.measure.restrict_to_measurable_of_sigma_finite MeasureTheory.Measure.restrict_toMeasurable_of_sFinite
/-- Auxiliary lemma for `iSup_restrict_spanningSets`. -/
theorem iSup_restrict_spanningSets_of_measurableSet [SigmaFinite μ] (hs : MeasurableSet s) :
⨆ i, μ.restrict (spanningSets μ i) s = μ s :=
calc
⨆ i, μ.restrict (spanningSets μ i) s = μ.restrict (⋃ i, spanningSets μ i) s :=
(restrict_iUnion_apply_eq_iSup (monotone_spanningSets μ).directed_le hs).symm
_ = μ s := by rw [iUnion_spanningSets, restrict_univ]
#align measure_theory.measure.supr_restrict_spanning_sets MeasureTheory.Measure.iSup_restrict_spanningSets_of_measurableSet
theorem iSup_restrict_spanningSets [SigmaFinite μ] (s : Set α) :
⨆ i, μ.restrict (spanningSets μ i) s = μ s := by
rw [← measure_toMeasurable s,
← iSup_restrict_spanningSets_of_measurableSet (measurableSet_toMeasurable _ _)]
simp_rw [restrict_apply' (measurable_spanningSets μ _), Set.inter_comm s,
← restrict_apply (measurable_spanningSets μ _), ← restrict_toMeasurable_of_sFinite s,
restrict_apply (measurable_spanningSets μ _), Set.inter_comm _ (toMeasurable μ s)]
/-- In a σ-finite space, any measurable set of measure `> r` contains a measurable subset of
finite measure `> r`. -/
theorem exists_subset_measure_lt_top [SigmaFinite μ] {r : ℝ≥0∞} (hs : MeasurableSet s)
(h's : r < μ s) : ∃ t, MeasurableSet t ∧ t ⊆ s ∧ r < μ t ∧ μ t < ∞ := by
rw [← iSup_restrict_spanningSets,
@lt_iSup_iff _ _ _ r fun i : ℕ => μ.restrict (spanningSets μ i) s] at h's
rcases h's with ⟨n, hn⟩
simp only [restrict_apply hs] at hn
refine
⟨s ∩ spanningSets μ n, hs.inter (measurable_spanningSets _ _), inter_subset_left, hn, ?_⟩
exact (measure_mono inter_subset_right).trans_lt (measure_spanningSets_lt_top _ _)
#align measure_theory.measure.exists_subset_measure_lt_top MeasureTheory.Measure.exists_subset_measure_lt_top
namespace FiniteSpanningSetsIn
variable {C D : Set (Set α)}
/-- If `μ` has finite spanning sets in `C` and `C ∩ {s | μ s < ∞} ⊆ D` then `μ` has finite spanning
sets in `D`. -/
protected def mono' (h : μ.FiniteSpanningSetsIn C) (hC : C ∩ { s | μ s < ∞ } ⊆ D) :
μ.FiniteSpanningSetsIn D :=
⟨h.set, fun i => hC ⟨h.set_mem i, h.finite i⟩, h.finite, h.spanning⟩
#align measure_theory.measure.finite_spanning_sets_in.mono' MeasureTheory.Measure.FiniteSpanningSetsIn.mono'
/-- If `μ` has finite spanning sets in `C` and `C ⊆ D` then `μ` has finite spanning sets in `D`. -/
protected def mono (h : μ.FiniteSpanningSetsIn C) (hC : C ⊆ D) : μ.FiniteSpanningSetsIn D :=
h.mono' fun _s hs => hC hs.1
#align measure_theory.measure.finite_spanning_sets_in.mono MeasureTheory.Measure.FiniteSpanningSetsIn.mono
/-- If `μ` has finite spanning sets in the collection of measurable sets `C`, then `μ` is σ-finite.
-/
protected theorem sigmaFinite (h : μ.FiniteSpanningSetsIn C) : SigmaFinite μ :=
⟨⟨h.mono <| subset_univ C⟩⟩
#align measure_theory.measure.finite_spanning_sets_in.sigma_finite MeasureTheory.Measure.FiniteSpanningSetsIn.sigmaFinite
/-- An extensionality for measures. It is `ext_of_generateFrom_of_iUnion` formulated in terms of
`FiniteSpanningSetsIn`. -/
protected theorem ext {ν : Measure α} {C : Set (Set α)} (hA : ‹_› = generateFrom C)
(hC : IsPiSystem C) (h : μ.FiniteSpanningSetsIn C) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=
ext_of_generateFrom_of_iUnion C _ hA hC h.spanning h.set_mem (fun i => (h.finite i).ne) h_eq
#align measure_theory.measure.finite_spanning_sets_in.ext MeasureTheory.Measure.FiniteSpanningSetsIn.ext
protected theorem isCountablySpanning (h : μ.FiniteSpanningSetsIn C) : IsCountablySpanning C :=
⟨h.set, h.set_mem, h.spanning⟩
#align measure_theory.measure.finite_spanning_sets_in.is_countably_spanning MeasureTheory.Measure.FiniteSpanningSetsIn.isCountablySpanning
end FiniteSpanningSetsIn
theorem sigmaFinite_of_countable {S : Set (Set α)} (hc : S.Countable) (hμ : ∀ s ∈ S, μ s < ∞)
(hU : ⋃₀ S = univ) : SigmaFinite μ := by
obtain ⟨s, hμ, hs⟩ : ∃ s : ℕ → Set α, (∀ n, μ (s n) < ∞) ∧ ⋃ n, s n = univ :=
(@exists_seq_cover_iff_countable _ (fun x => μ x < ∞) ⟨∅, by simp⟩).2 ⟨S, hc, hμ, hU⟩
exact ⟨⟨⟨fun n => s n, fun _ => trivial, hμ, hs⟩⟩⟩
#align measure_theory.measure.sigma_finite_of_countable MeasureTheory.Measure.sigmaFinite_of_countable
/-- Given measures `μ`, `ν` where `ν ≤ μ`, `FiniteSpanningSetsIn.ofLe` provides the induced
`FiniteSpanningSet` with respect to `ν` from a `FiniteSpanningSet` with respect to `μ`. -/
def FiniteSpanningSetsIn.ofLE (h : ν ≤ μ) {C : Set (Set α)} (S : μ.FiniteSpanningSetsIn C) :
ν.FiniteSpanningSetsIn C where
set := S.set
set_mem := S.set_mem
finite n := lt_of_le_of_lt (le_iff'.1 h _) (S.finite n)
spanning := S.spanning
#align measure_theory.measure.finite_spanning_sets_in.of_le MeasureTheory.Measure.FiniteSpanningSetsIn.ofLE
theorem sigmaFinite_of_le (μ : Measure α) [hs : SigmaFinite μ] (h : ν ≤ μ) : SigmaFinite ν :=
⟨hs.out.map <| FiniteSpanningSetsIn.ofLE h⟩
#align measure_theory.measure.sigma_finite_of_le MeasureTheory.Measure.sigmaFinite_of_le
@[simp] lemma add_right_inj (μ ν₁ ν₂ : Measure α) [SigmaFinite μ] :
μ + ν₁ = μ + ν₂ ↔ ν₁ = ν₂ := by
refine ⟨fun h ↦ ?_, fun h ↦ by rw [h]⟩
rw [ext_iff_of_iUnion_eq_univ (iUnion_spanningSets μ)]
intro i
ext s hs
rw [← ENNReal.add_right_inj (measure_mono s.inter_subset_right |>.trans_lt <|
measure_spanningSets_lt_top μ i).ne]
simp only [ext_iff', coe_add, Pi.add_apply] at h
simp [hs, h]
@[simp] lemma add_left_inj (μ ν₁ ν₂ : Measure α) [SigmaFinite μ] :
ν₁ + μ = ν₂ + μ ↔ ν₁ = ν₂ := by rw [add_comm _ μ, add_comm _ μ, μ.add_right_inj]
end Measure
/-- Every finite measure is σ-finite. -/
instance (priority := 100) IsFiniteMeasure.toSigmaFinite {_m0 : MeasurableSpace α} (μ : Measure α)
[IsFiniteMeasure μ] : SigmaFinite μ :=
⟨⟨⟨fun _ => univ, fun _ => trivial, fun _ => measure_lt_top μ _, iUnion_const _⟩⟩⟩
#align measure_theory.is_finite_measure.to_sigma_finite MeasureTheory.IsFiniteMeasure.toSigmaFinite
theorem sigmaFinite_bot_iff (μ : @Measure α ⊥) : SigmaFinite μ ↔ IsFiniteMeasure μ := by
refine
⟨fun h => ⟨?_⟩, fun h => by
haveI := h
infer_instance⟩
haveI : SigmaFinite μ := h
let s := spanningSets μ
have hs_univ : ⋃ i, s i = Set.univ := iUnion_spanningSets μ
have hs_meas : ∀ i, MeasurableSet[⊥] (s i) := measurable_spanningSets μ
simp_rw [MeasurableSpace.measurableSet_bot_iff] at hs_meas
by_cases h_univ_empty : (Set.univ : Set α) = ∅
· rw [h_univ_empty, measure_empty]
exact ENNReal.zero_ne_top.lt_top
obtain ⟨i, hsi⟩ : ∃ i, s i = Set.univ := by
by_contra! h_not_univ
have h_empty : ∀ i, s i = ∅ := by simpa [h_not_univ] using hs_meas
simp only [h_empty, iUnion_empty] at hs_univ
exact h_univ_empty hs_univ.symm
rw [← hsi]
exact measure_spanningSets_lt_top μ i
#align measure_theory.sigma_finite_bot_iff MeasureTheory.sigmaFinite_bot_iff
instance Restrict.sigmaFinite (μ : Measure α) [SigmaFinite μ] (s : Set α) :
SigmaFinite (μ.restrict s) := by
refine ⟨⟨⟨spanningSets μ, fun _ => trivial, fun i => ?_, iUnion_spanningSets μ⟩⟩⟩
rw [Measure.restrict_apply (measurable_spanningSets μ i)]
exact (measure_mono inter_subset_left).trans_lt (measure_spanningSets_lt_top μ i)
#align measure_theory.restrict.sigma_finite MeasureTheory.Restrict.sigmaFinite
instance sum.sigmaFinite {ι} [Finite ι] (μ : ι → Measure α) [∀ i, SigmaFinite (μ i)] :
SigmaFinite (sum μ) := by
cases nonempty_fintype ι
have : ∀ n, MeasurableSet (⋂ i : ι, spanningSets (μ i) n) := fun n =>
MeasurableSet.iInter fun i => measurable_spanningSets (μ i) n
refine ⟨⟨⟨fun n => ⋂ i, spanningSets (μ i) n, fun _ => trivial, fun n => ?_, ?_⟩⟩⟩
· rw [sum_apply _ (this n), tsum_fintype, ENNReal.sum_lt_top_iff]
rintro i -
exact (measure_mono <| iInter_subset _ i).trans_lt (measure_spanningSets_lt_top (μ i) n)
· rw [iUnion_iInter_of_monotone]
· simp_rw [iUnion_spanningSets, iInter_univ]
exact fun i => monotone_spanningSets (μ i)
#align measure_theory.sum.sigma_finite MeasureTheory.sum.sigmaFinite
instance Add.sigmaFinite (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] :
SigmaFinite (μ + ν) := by
rw [← sum_cond]
refine @sum.sigmaFinite _ _ _ _ _ (Bool.rec ?_ ?_) <;> simpa
#align measure_theory.add.sigma_finite MeasureTheory.Add.sigmaFinite
instance SMul.sigmaFinite {μ : Measure α} [SigmaFinite μ] (c : ℝ≥0) :
MeasureTheory.SigmaFinite (c • μ) where
out' :=
⟨{ set := spanningSets μ
set_mem := fun _ ↦ trivial
finite := by
intro i
simp only [Measure.coe_smul, Pi.smul_apply, nnreal_smul_coe_apply]
exact ENNReal.mul_lt_top ENNReal.coe_ne_top (measure_spanningSets_lt_top μ i).ne
spanning := iUnion_spanningSets μ }⟩
theorem SigmaFinite.of_map (μ : Measure α) {f : α → β} (hf : AEMeasurable f μ)
(h : SigmaFinite (μ.map f)) : SigmaFinite μ :=
⟨⟨⟨fun n => f ⁻¹' spanningSets (μ.map f) n, fun _ => trivial, fun n => by
simp only [← map_apply_of_aemeasurable hf, measurable_spanningSets,
measure_spanningSets_lt_top],
by rw [← preimage_iUnion, iUnion_spanningSets, preimage_univ]⟩⟩⟩
#align measure_theory.sigma_finite.of_map MeasureTheory.SigmaFinite.of_map
theorem _root_.MeasurableEquiv.sigmaFinite_map {μ : Measure α} (f : α ≃ᵐ β) (h : SigmaFinite μ) :
SigmaFinite (μ.map f) := by
refine SigmaFinite.of_map _ f.symm.measurable.aemeasurable ?_
rwa [map_map f.symm.measurable f.measurable, f.symm_comp_self, Measure.map_id]
#align measurable_equiv.sigma_finite_map MeasurableEquiv.sigmaFinite_map
/-- Similar to `ae_of_forall_measure_lt_top_ae_restrict`, but where you additionally get the
hypothesis that another σ-finite measure has finite values on `s`. -/
theorem ae_of_forall_measure_lt_top_ae_restrict' {μ : Measure α} (ν : Measure α) [SigmaFinite μ]
[SigmaFinite ν] (P : α → Prop)
(h : ∀ s, MeasurableSet s → μ s < ∞ → ν s < ∞ → ∀ᵐ x ∂μ.restrict s, P x) : ∀ᵐ x ∂μ, P x := by
have : ∀ n, ∀ᵐ x ∂μ, x ∈ spanningSets (μ + ν) n → P x := by
intro n
have := h
(spanningSets (μ + ν) n) (measurable_spanningSets _ _)
((self_le_add_right _ _).trans_lt (measure_spanningSets_lt_top (μ + ν) _))
((self_le_add_left _ _).trans_lt (measure_spanningSets_lt_top (μ + ν) _))
exact (ae_restrict_iff' (measurable_spanningSets _ _)).mp this
filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _)
#align measure_theory.ae_of_forall_measure_lt_top_ae_restrict' MeasureTheory.ae_of_forall_measure_lt_top_ae_restrict'
/-- To prove something for almost all `x` w.r.t. a σ-finite measure, it is sufficient to show that
this holds almost everywhere in sets where the measure has finite value. -/
theorem ae_of_forall_measure_lt_top_ae_restrict {μ : Measure α} [SigmaFinite μ] (P : α → Prop)
(h : ∀ s, MeasurableSet s → μ s < ∞ → ∀ᵐ x ∂μ.restrict s, P x) : ∀ᵐ x ∂μ, P x :=
ae_of_forall_measure_lt_top_ae_restrict' μ P fun s hs h2s _ => h s hs h2s
#align measure_theory.ae_of_forall_measure_lt_top_ae_restrict MeasureTheory.ae_of_forall_measure_lt_top_ae_restrict
/-- A measure is called locally finite if it is finite in some neighborhood of each point. -/
class IsLocallyFiniteMeasure [TopologicalSpace α] (μ : Measure α) : Prop where
finiteAtNhds : ∀ x, μ.FiniteAtFilter (𝓝 x)
#align measure_theory.is_locally_finite_measure MeasureTheory.IsLocallyFiniteMeasure
#align measure_theory.is_locally_finite_measure.finite_at_nhds MeasureTheory.IsLocallyFiniteMeasure.finiteAtNhds
-- see Note [lower instance priority]
instance (priority := 100) IsFiniteMeasure.toIsLocallyFiniteMeasure [TopologicalSpace α]
(μ : Measure α) [IsFiniteMeasure μ] : IsLocallyFiniteMeasure μ :=
⟨fun _ => finiteAtFilter_of_finite _ _⟩
#align measure_theory.is_finite_measure.to_is_locally_finite_measure MeasureTheory.IsFiniteMeasure.toIsLocallyFiniteMeasure
theorem Measure.finiteAt_nhds [TopologicalSpace α] (μ : Measure α) [IsLocallyFiniteMeasure μ]
(x : α) : μ.FiniteAtFilter (𝓝 x) :=
IsLocallyFiniteMeasure.finiteAtNhds x
#align measure_theory.measure.finite_at_nhds MeasureTheory.Measure.finiteAt_nhds
theorem Measure.smul_finite (μ : Measure α) [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) :
IsFiniteMeasure (c • μ) := by
lift c to ℝ≥0 using hc
exact MeasureTheory.isFiniteMeasureSMulNNReal
#align measure_theory.measure.smul_finite MeasureTheory.Measure.smul_finite
theorem Measure.exists_isOpen_measure_lt_top [TopologicalSpace α] (μ : Measure α)
[IsLocallyFiniteMeasure μ] (x : α) : ∃ s : Set α, x ∈ s ∧ IsOpen s ∧ μ s < ∞ := by
simpa only [and_assoc] using (μ.finiteAt_nhds x).exists_mem_basis (nhds_basis_opens x)
#align measure_theory.measure.exists_is_open_measure_lt_top MeasureTheory.Measure.exists_isOpen_measure_lt_top
instance isLocallyFiniteMeasureSMulNNReal [TopologicalSpace α] (μ : Measure α)
[IsLocallyFiniteMeasure μ] (c : ℝ≥0) : IsLocallyFiniteMeasure (c • μ) := by
refine ⟨fun x => ?_⟩
rcases μ.exists_isOpen_measure_lt_top x with ⟨o, xo, o_open, μo⟩
refine ⟨o, o_open.mem_nhds xo, ?_⟩
apply ENNReal.mul_lt_top _ μo.ne
simp
#align measure_theory.is_locally_finite_measure_smul_nnreal MeasureTheory.isLocallyFiniteMeasureSMulNNReal
protected theorem Measure.isTopologicalBasis_isOpen_lt_top [TopologicalSpace α]
(μ : Measure α) [IsLocallyFiniteMeasure μ] :
TopologicalSpace.IsTopologicalBasis { s | IsOpen s ∧ μ s < ∞ } := by
refine TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds (fun s hs => hs.1) ?_
intro x s xs hs
rcases μ.exists_isOpen_measure_lt_top x with ⟨v, xv, hv, μv⟩
refine ⟨v ∩ s, ⟨hv.inter hs, lt_of_le_of_lt ?_ μv⟩, ⟨xv, xs⟩, inter_subset_right⟩
exact measure_mono inter_subset_left
#align measure_theory.measure.is_topological_basis_is_open_lt_top MeasureTheory.Measure.isTopologicalBasis_isOpen_lt_top
/-- A measure `μ` is finite on compacts if any compact set `K` satisfies `μ K < ∞`. -/
class IsFiniteMeasureOnCompacts [TopologicalSpace α] (μ : Measure α) : Prop where
protected lt_top_of_isCompact : ∀ ⦃K : Set α⦄, IsCompact K → μ K < ∞
#align measure_theory.is_finite_measure_on_compacts MeasureTheory.IsFiniteMeasureOnCompacts
#align measure_theory.is_finite_measure_on_compacts.lt_top_of_is_compact MeasureTheory.IsFiniteMeasureOnCompacts.lt_top_of_isCompact
/-- A compact subset has finite measure for a measure which is finite on compacts. -/
theorem _root_.IsCompact.measure_lt_top [TopologicalSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] ⦃K : Set α⦄ (hK : IsCompact K) : μ K < ∞ :=
IsFiniteMeasureOnCompacts.lt_top_of_isCompact hK
#align is_compact.measure_lt_top IsCompact.measure_lt_top
/-- A compact subset has finite measure for a measure which is finite on compacts. -/
theorem _root_.IsCompact.measure_ne_top [TopologicalSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] ⦃K : Set α⦄ (hK : IsCompact K) : μ K ≠ ∞ :=
hK.measure_lt_top.ne
/-- A bounded subset has finite measure for a measure which is finite on compact sets, in a
proper space. -/
theorem _root_.Bornology.IsBounded.measure_lt_top [PseudoMetricSpace α] [ProperSpace α]
{μ : Measure α} [IsFiniteMeasureOnCompacts μ] ⦃s : Set α⦄ (hs : Bornology.IsBounded s) :
μ s < ∞ :=
calc
μ s ≤ μ (closure s) := measure_mono subset_closure
_ < ∞ := (Metric.isCompact_of_isClosed_isBounded isClosed_closure hs.closure).measure_lt_top
#align metric.bounded.measure_lt_top Bornology.IsBounded.measure_lt_top
theorem measure_closedBall_lt_top [PseudoMetricSpace α] [ProperSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] {x : α} {r : ℝ} : μ (Metric.closedBall x r) < ∞ :=
Metric.isBounded_closedBall.measure_lt_top
#align measure_theory.measure_closed_ball_lt_top MeasureTheory.measure_closedBall_lt_top
theorem measure_ball_lt_top [PseudoMetricSpace α] [ProperSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] {x : α} {r : ℝ} : μ (Metric.ball x r) < ∞ :=
Metric.isBounded_ball.measure_lt_top
#align measure_theory.measure_ball_lt_top MeasureTheory.measure_ball_lt_top
protected theorem IsFiniteMeasureOnCompacts.smul [TopologicalSpace α] (μ : Measure α)
[IsFiniteMeasureOnCompacts μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : IsFiniteMeasureOnCompacts (c • μ) :=
⟨fun _K hK => ENNReal.mul_lt_top hc hK.measure_lt_top.ne⟩
#align measure_theory.is_finite_measure_on_compacts.smul MeasureTheory.IsFiniteMeasureOnCompacts.smul
instance IsFiniteMeasureOnCompacts.smul_nnreal [TopologicalSpace α] (μ : Measure α)
[IsFiniteMeasureOnCompacts μ] (c : ℝ≥0) : IsFiniteMeasureOnCompacts (c • μ) :=
IsFiniteMeasureOnCompacts.smul μ coe_ne_top
instance instIsFiniteMeasureOnCompactsRestrict [TopologicalSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] {s : Set α} : IsFiniteMeasureOnCompacts (μ.restrict s) :=
⟨fun _k hk ↦ (restrict_apply_le _ _).trans_lt hk.measure_lt_top⟩
instance (priority := 100) CompactSpace.isFiniteMeasure [TopologicalSpace α] [CompactSpace α]
[IsFiniteMeasureOnCompacts μ] : IsFiniteMeasure μ :=
⟨IsFiniteMeasureOnCompacts.lt_top_of_isCompact isCompact_univ⟩
#align measure_theory.compact_space.is_finite_measure MeasureTheory.CompactSpace.isFiniteMeasure
instance (priority := 100) SigmaFinite.of_isFiniteMeasureOnCompacts [TopologicalSpace α]
[SigmaCompactSpace α] (μ : Measure α) [IsFiniteMeasureOnCompacts μ] : SigmaFinite μ :=
⟨⟨{ set := compactCovering α
set_mem := fun _ => trivial
finite := fun n => (isCompact_compactCovering α n).measure_lt_top
spanning := iUnion_compactCovering α }⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) sigmaFinite_of_locallyFinite [TopologicalSpace α]
[SecondCountableTopology α] [IsLocallyFiniteMeasure μ] : SigmaFinite μ := by
choose s hsx hsμ using μ.finiteAt_nhds
rcases TopologicalSpace.countable_cover_nhds hsx with ⟨t, htc, htU⟩
refine Measure.sigmaFinite_of_countable (htc.image s) (forall_mem_image.2 fun x _ => hsμ x) ?_
rwa [sUnion_image]
#align measure_theory.sigma_finite_of_locally_finite MeasureTheory.sigmaFinite_of_locallyFinite
/-- A measure which is finite on compact sets in a locally compact space is locally finite. -/
instance (priority := 100) isLocallyFiniteMeasure_of_isFiniteMeasureOnCompacts [TopologicalSpace α]
[WeaklyLocallyCompactSpace α] [IsFiniteMeasureOnCompacts μ] : IsLocallyFiniteMeasure μ :=
⟨fun x ↦
let ⟨K, K_compact, K_mem⟩ := exists_compact_mem_nhds x
⟨K, K_mem, K_compact.measure_lt_top⟩⟩
#align measure_theory.is_locally_finite_measure_of_is_finite_measure_on_compacts MeasureTheory.isLocallyFiniteMeasure_of_isFiniteMeasureOnCompacts
theorem exists_pos_measure_of_cover [Countable ι] {U : ι → Set α} (hU : ⋃ i, U i = univ)
(hμ : μ ≠ 0) : ∃ i, 0 < μ (U i) := by
contrapose! hμ with H
rw [← measure_univ_eq_zero, ← hU]
exact measure_iUnion_null fun i => nonpos_iff_eq_zero.1 (H i)
#align measure_theory.exists_pos_measure_of_cover MeasureTheory.exists_pos_measure_of_cover
theorem exists_pos_preimage_ball [PseudoMetricSpace δ] (f : α → δ) (x : δ) (hμ : μ ≠ 0) :
∃ n : ℕ, 0 < μ (f ⁻¹' Metric.ball x n) :=
exists_pos_measure_of_cover (by rw [← preimage_iUnion, Metric.iUnion_ball_nat, preimage_univ]) hμ
#align measure_theory.exists_pos_preimage_ball MeasureTheory.exists_pos_preimage_ball
theorem exists_pos_ball [PseudoMetricSpace α] (x : α) (hμ : μ ≠ 0) :
∃ n : ℕ, 0 < μ (Metric.ball x n) :=
exists_pos_preimage_ball id x hμ
#align measure_theory.exists_pos_ball MeasureTheory.exists_pos_ball
/-- If a set has zero measure in a neighborhood of each of its points, then it has zero measure
in a second-countable space. -/
@[deprecated (since := "2024-05-14")]
alias null_of_locally_null := measure_null_of_locally_null
theorem exists_ne_forall_mem_nhds_pos_measure_preimage {β} [TopologicalSpace β] [T1Space β]
[SecondCountableTopology β] [Nonempty β] {f : α → β} (h : ∀ b, ∃ᵐ x ∂μ, f x ≠ b) :
∃ a b : β, a ≠ b ∧ (∀ s ∈ 𝓝 a, 0 < μ (f ⁻¹' s)) ∧ ∀ t ∈ 𝓝 b, 0 < μ (f ⁻¹' t) := by
-- We use an `OuterMeasure` so that the proof works without `Measurable f`
set m : OuterMeasure β := OuterMeasure.map f μ.toOuterMeasure
replace h : ∀ b : β, m {b}ᶜ ≠ 0 := fun b => not_eventually.mpr (h b)
inhabit β
have : m univ ≠ 0 := ne_bot_of_le_ne_bot (h default) (measure_mono <| subset_univ _)
rcases exists_mem_forall_mem_nhdsWithin_pos_measure this with ⟨b, -, hb⟩
simp only [nhdsWithin_univ] at hb
rcases exists_mem_forall_mem_nhdsWithin_pos_measure (h b) with ⟨a, hab : a ≠ b, ha⟩
simp only [isOpen_compl_singleton.nhdsWithin_eq hab] at ha
exact ⟨a, b, hab, ha, hb⟩
#align measure_theory.exists_ne_forall_mem_nhds_pos_measure_preimage MeasureTheory.exists_ne_forall_mem_nhds_pos_measure_preimage
/-- If two finite measures give the same mass to the whole space and coincide on a π-system made
of measurable sets, then they coincide on all sets in the σ-algebra generated by the π-system. -/
theorem ext_on_measurableSpace_of_generate_finite {α} (m₀ : MeasurableSpace α) {μ ν : Measure α}
[IsFiniteMeasure μ] (C : Set (Set α)) (hμν : ∀ s ∈ C, μ s = ν s) {m : MeasurableSpace α}
(h : m ≤ m₀) (hA : m = MeasurableSpace.generateFrom C) (hC : IsPiSystem C)
(h_univ : μ Set.univ = ν Set.univ) {s : Set α} (hs : MeasurableSet[m] s) : μ s = ν s := by
haveI : IsFiniteMeasure ν := by
constructor
rw [← h_univ]
apply IsFiniteMeasure.measure_univ_lt_top
refine induction_on_inter hA hC (by simp) hμν ?_ ?_ hs
· intro t h1t h2t
have h1t_ : @MeasurableSet α m₀ t := h _ h1t
rw [@measure_compl α m₀ μ t h1t_ (@measure_ne_top α m₀ μ _ t),
@measure_compl α m₀ ν t h1t_ (@measure_ne_top α m₀ ν _ t), h_univ, h2t]
· intro f h1f h2f h3f
have h2f_ : ∀ i : ℕ, @MeasurableSet α m₀ (f i) := fun i => h _ (h2f i)
simp [measure_iUnion, h1f, h3f, h2f_]
#align measure_theory.ext_on_measurable_space_of_generate_finite MeasureTheory.ext_on_measurableSpace_of_generate_finite
/-- Two finite measures are equal if they are equal on the π-system generating the σ-algebra
(and `univ`). -/
theorem ext_of_generate_finite (C : Set (Set α)) (hA : m0 = generateFrom C) (hC : IsPiSystem C)
[IsFiniteMeasure μ] (hμν : ∀ s ∈ C, μ s = ν s) (h_univ : μ univ = ν univ) : μ = ν :=
Measure.ext fun _s hs =>
ext_on_measurableSpace_of_generate_finite m0 C hμν le_rfl hA hC h_univ hs
#align measure_theory.ext_of_generate_finite MeasureTheory.ext_of_generate_finite
namespace Measure
section disjointed
/-- Given `S : μ.FiniteSpanningSetsIn {s | MeasurableSet s}`,
`FiniteSpanningSetsIn.disjointed` provides a `FiniteSpanningSetsIn {s | MeasurableSet s}`
such that its underlying sets are pairwise disjoint. -/
protected def FiniteSpanningSetsIn.disjointed {μ : Measure α}
(S : μ.FiniteSpanningSetsIn { s | MeasurableSet s }) :
μ.FiniteSpanningSetsIn { s | MeasurableSet s } :=
⟨disjointed S.set, MeasurableSet.disjointed S.set_mem, fun n =>
lt_of_le_of_lt (measure_mono (disjointed_subset S.set n)) (S.finite _),
S.spanning ▸ iUnion_disjointed⟩
#align measure_theory.measure.finite_spanning_sets_in.disjointed MeasureTheory.Measure.FiniteSpanningSetsIn.disjointed
theorem FiniteSpanningSetsIn.disjointed_set_eq {μ : Measure α}
(S : μ.FiniteSpanningSetsIn { s | MeasurableSet s }) : S.disjointed.set = disjointed S.set :=
rfl
#align measure_theory.measure.finite_spanning_sets_in.disjointed_set_eq MeasureTheory.Measure.FiniteSpanningSetsIn.disjointed_set_eq
theorem exists_eq_disjoint_finiteSpanningSetsIn (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] :
∃ (S : μ.FiniteSpanningSetsIn { s | MeasurableSet s })
(T : ν.FiniteSpanningSetsIn { s | MeasurableSet s }),
S.set = T.set ∧ Pairwise (Disjoint on S.set) :=
let S := (μ + ν).toFiniteSpanningSetsIn.disjointed
⟨S.ofLE (Measure.le_add_right le_rfl), S.ofLE (Measure.le_add_left le_rfl), rfl,
disjoint_disjointed _⟩
#align measure_theory.measure.exists_eq_disjoint_finite_spanning_sets_in MeasureTheory.Measure.exists_eq_disjoint_finiteSpanningSetsIn
end disjointed
namespace FiniteAtFilter
variable {f g : Filter α}
theorem filter_mono (h : f ≤ g) : μ.FiniteAtFilter g → μ.FiniteAtFilter f := fun ⟨s, hs, hμ⟩ =>
⟨s, h hs, hμ⟩
#align measure_theory.measure.finite_at_filter.filter_mono MeasureTheory.Measure.FiniteAtFilter.filter_mono
theorem inf_of_left (h : μ.FiniteAtFilter f) : μ.FiniteAtFilter (f ⊓ g) :=
h.filter_mono inf_le_left
#align measure_theory.measure.finite_at_filter.inf_of_left MeasureTheory.Measure.FiniteAtFilter.inf_of_left
theorem inf_of_right (h : μ.FiniteAtFilter g) : μ.FiniteAtFilter (f ⊓ g) :=
h.filter_mono inf_le_right
#align measure_theory.measure.finite_at_filter.inf_of_right MeasureTheory.Measure.FiniteAtFilter.inf_of_right
@[simp]
| Mathlib/MeasureTheory/Measure/Typeclasses.lean | 1,417 | 1,421 | theorem inf_ae_iff : μ.FiniteAtFilter (f ⊓ ae μ) ↔ μ.FiniteAtFilter f := by |
refine ⟨?_, fun h => h.filter_mono inf_le_left⟩
rintro ⟨s, ⟨t, ht, u, hu, rfl⟩, hμ⟩
suffices μ t ≤ μ (t ∩ u) from ⟨t, ht, this.trans_lt hμ⟩
exact measure_mono_ae (mem_of_superset hu fun x hu ht => ⟨ht, hu⟩)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Init.ZeroOne
import Mathlib.Data.Set.Defs
import Mathlib.Order.Basic
import Mathlib.Order.SymmDiff
import Mathlib.Tactic.Tauto
import Mathlib.Tactic.ByContra
import Mathlib.Util.Delaborators
#align_import data.set.basic from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Basic properties of sets
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not
be decidable. The definition is in the core library.
This file provides some basic definitions related to sets and functions not present in the core
library, as well as extra lemmas for functions in the core library (empty set, univ, union,
intersection, insert, singleton, set-theoretic difference, complement, and powerset).
Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending
`s` to the corresponding subtype `↥s`.
See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean.
## Main definitions
Notation used here:
- `f : α → β` is a function,
- `s : Set α` and `s₁ s₂ : Set α` are subsets of `α`
- `t : Set β` is a subset of `β`.
Definitions in the file:
* `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the
fact that `s` has an element (see the Implementation Notes).
* `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`.
## Notation
* `sᶜ` for the complement of `s`
## Implementation notes
* `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that
the `s.Nonempty` dot notation can be used.
* For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`.
## Tags
set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset
-/
/-! ### Set coercion to a type -/
open Function
universe u v w x
namespace Set
variable {α : Type u} {s t : Set α}
instance instBooleanAlgebraSet : BooleanAlgebra (Set α) :=
{ (inferInstance : BooleanAlgebra (α → Prop)) with
sup := (· ∪ ·),
le := (· ≤ ·),
lt := fun s t => s ⊆ t ∧ ¬t ⊆ s,
inf := (· ∩ ·),
bot := ∅,
compl := (·ᶜ),
top := univ,
sdiff := (· \ ·) }
instance : HasSSubset (Set α) :=
⟨(· < ·)⟩
@[simp]
theorem top_eq_univ : (⊤ : Set α) = univ :=
rfl
#align set.top_eq_univ Set.top_eq_univ
@[simp]
theorem bot_eq_empty : (⊥ : Set α) = ∅ :=
rfl
#align set.bot_eq_empty Set.bot_eq_empty
@[simp]
theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) :=
rfl
#align set.sup_eq_union Set.sup_eq_union
@[simp]
theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) :=
rfl
#align set.inf_eq_inter Set.inf_eq_inter
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) :=
rfl
#align set.le_eq_subset Set.le_eq_subset
@[simp]
theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) :=
rfl
#align set.lt_eq_ssubset Set.lt_eq_ssubset
theorem le_iff_subset : s ≤ t ↔ s ⊆ t :=
Iff.rfl
#align set.le_iff_subset Set.le_iff_subset
theorem lt_iff_ssubset : s < t ↔ s ⊂ t :=
Iff.rfl
#align set.lt_iff_ssubset Set.lt_iff_ssubset
alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset
#align has_subset.subset.le HasSubset.Subset.le
alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset
#align has_ssubset.ssubset.lt HasSSubset.SSubset.lt
instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) :
CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True :=
PiSubtype.canLift ι α s
#align set.pi_set_coe.can_lift Set.PiSetCoe.canLift
instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiSetCoe.canLift ι (fun _ => α) s
#align set.pi_set_coe.can_lift' Set.PiSetCoe.canLift'
end Set
section SetCoe
variable {α : Type u}
instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩
theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } :=
rfl
#align set.coe_eq_subtype Set.coe_eq_subtype
@[simp]
theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } :=
rfl
#align set.coe_set_of Set.coe_setOf
-- Porting note (#10618): removed `simp` because `simp` can prove it
theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
#align set_coe.forall SetCoe.forall
-- Porting note (#10618): removed `simp` because `simp` can prove it
theorem SetCoe.exists {s : Set α} {p : s → Prop} :
(∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.exists
#align set_coe.exists SetCoe.exists
theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 :=
(@SetCoe.exists _ _ fun x => p x.1 x.2).symm
#align set_coe.exists' SetCoe.exists'
theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 :=
(@SetCoe.forall _ _ fun x => p x.1 x.2).symm
#align set_coe.forall' SetCoe.forall'
@[simp]
theorem set_coe_cast :
∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩
| _, _, rfl, _, _ => rfl
#align set_coe_cast set_coe_cast
theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b :=
Subtype.eq
#align set_coe.ext SetCoe.ext
theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
Iff.intro SetCoe.ext fun h => h ▸ rfl
#align set_coe.ext_iff SetCoe.ext_iff
end SetCoe
/-- See also `Subtype.prop` -/
theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s :=
p.prop
#align subtype.mem Subtype.mem
/-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/
theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t :=
fun h₁ _ h₂ => by rw [← h₁]; exact h₂
#align eq.subset Eq.subset
namespace Set
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α}
instance : Inhabited (Set α) :=
⟨∅⟩
theorem ext_iff {s t : Set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t :=
⟨fun h x => by rw [h], ext⟩
#align set.ext_iff Set.ext_iff
@[trans]
theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t :=
h hx
#align set.mem_of_mem_of_subset Set.mem_of_mem_of_subset
theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by
tauto
#align set.forall_in_swap Set.forall_in_swap
/-! ### Lemmas about `mem` and `setOf` -/
theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a :=
Iff.rfl
#align set.mem_set_of Set.mem_setOf
/-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can
nevertheless be useful for various reasons, e.g. to apply further projection notation or in an
argument to `simp`. -/
theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a :=
h
#align has_mem.mem.out Membership.mem.out
theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a :=
Iff.rfl
#align set.nmem_set_of_iff Set.nmem_setOf_iff
@[simp]
theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s :=
rfl
#align set.set_of_mem_eq Set.setOf_mem_eq
theorem setOf_set {s : Set α} : setOf s = s :=
rfl
#align set.set_of_set Set.setOf_set
theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x :=
Iff.rfl
#align set.set_of_app_iff Set.setOf_app_iff
theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a :=
Iff.rfl
#align set.mem_def Set.mem_def
theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) :=
bijective_id
#align set.set_of_bijective Set.setOf_bijective
theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x :=
Iff.rfl
theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s :=
Iff.rfl
@[simp]
theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a :=
Iff.rfl
#align set.set_of_subset_set_of Set.setOf_subset_setOf
theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } :=
rfl
#align set.set_of_and Set.setOf_and
theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } :=
rfl
#align set.set_of_or Set.setOf_or
/-! ### Subset and strict subset relations -/
instance : IsRefl (Set α) (· ⊆ ·) :=
show IsRefl (Set α) (· ≤ ·) by infer_instance
instance : IsTrans (Set α) (· ⊆ ·) :=
show IsTrans (Set α) (· ≤ ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) :=
show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance
instance : IsAntisymm (Set α) (· ⊆ ·) :=
show IsAntisymm (Set α) (· ≤ ·) by infer_instance
instance : IsIrrefl (Set α) (· ⊂ ·) :=
show IsIrrefl (Set α) (· < ·) by infer_instance
instance : IsTrans (Set α) (· ⊂ ·) :=
show IsTrans (Set α) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· < ·) (· < ·) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) :=
show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance
instance : IsAsymm (Set α) (· ⊂ ·) :=
show IsAsymm (Set α) (· < ·) by infer_instance
instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) :=
⟨fun _ _ => Iff.rfl⟩
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t :=
rfl
#align set.subset_def Set.subset_def
theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) :=
rfl
#align set.ssubset_def Set.ssubset_def
@[refl]
theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id
#align set.subset.refl Set.Subset.refl
theorem Subset.rfl {s : Set α} : s ⊆ s :=
Subset.refl s
#align set.subset.rfl Set.Subset.rfl
@[trans]
theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h
#align set.subset.trans Set.Subset.trans
@[trans]
theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
hx.symm ▸ h
#align set.mem_of_eq_of_mem Set.mem_of_eq_of_mem
theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩
#align set.subset.antisymm Set.Subset.antisymm
theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩
#align set.subset.antisymm_iff Set.Subset.antisymm_iff
-- an alternative name
theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b :=
Subset.antisymm
#align set.eq_of_subset_of_subset Set.eq_of_subset_of_subset
theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ :=
@h _
#align set.mem_of_subset_of_mem Set.mem_of_subset_of_mem
theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s :=
mt <| mem_of_subset_of_mem h
#align set.not_mem_subset Set.not_mem_subset
theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by
simp only [subset_def, not_forall, exists_prop]
#align set.not_subset Set.not_subset
lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h
/-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/
protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t :=
eq_or_lt_of_le h
#align set.eq_or_ssubset_of_subset Set.eq_or_ssubset_of_subset
theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s :=
not_subset.1 h.2
#align set.exists_of_ssubset Set.exists_of_ssubset
protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne (Set α) _ s t
#align set.ssubset_iff_subset_ne Set.ssubset_iff_subset_ne
theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s :=
⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩
#align set.ssubset_iff_of_subset Set.ssubset_iff_of_subset
protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂)
(hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩
#align set.ssubset_of_ssubset_of_subset Set.ssubset_of_ssubset_of_subset
protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂)
(hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩
#align set.ssubset_of_subset_of_ssubset Set.ssubset_of_subset_of_ssubset
theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) :=
id
#align set.not_mem_empty Set.not_mem_empty
-- Porting note (#10618): removed `simp` because `simp` can prove it
theorem not_not_mem : ¬a ∉ s ↔ a ∈ s :=
not_not
#align set.not_not_mem Set.not_not_mem
/-! ### Non-empty sets -/
-- Porting note: we seem to need parentheses at `(↥s)`,
-- even if we increase the right precedence of `↥` in `Mathlib.Tactic.Coe`.
-- Porting note: removed `simp` as it is competing with `nonempty_subtype`.
-- @[simp]
theorem nonempty_coe_sort {s : Set α} : Nonempty (↥s) ↔ s.Nonempty :=
nonempty_subtype
#align set.nonempty_coe_sort Set.nonempty_coe_sort
alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort
#align set.nonempty.coe_sort Set.Nonempty.coe_sort
theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s :=
Iff.rfl
#align set.nonempty_def Set.nonempty_def
theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty :=
⟨x, h⟩
#align set.nonempty_of_mem Set.nonempty_of_mem
theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅
| ⟨_, hx⟩, hs => hs hx
#align set.nonempty.not_subset_empty Set.Nonempty.not_subset_empty
/-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/
protected noncomputable def Nonempty.some (h : s.Nonempty) : α :=
Classical.choose h
#align set.nonempty.some Set.Nonempty.some
protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s :=
Classical.choose_spec h
#align set.nonempty.some_mem Set.Nonempty.some_mem
theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
hs.imp ht
#align set.nonempty.mono Set.Nonempty.mono
theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty :=
let ⟨x, xs, xt⟩ := not_subset.1 h
⟨x, xs, xt⟩
#align set.nonempty_of_not_subset Set.nonempty_of_not_subset
theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty :=
nonempty_of_not_subset ht.2
#align set.nonempty_of_ssubset Set.nonempty_of_ssubset
theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
#align set.nonempty.of_diff Set.Nonempty.of_diff
theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty :=
(nonempty_of_ssubset ht).of_diff
#align set.nonempty_of_ssubset' Set.nonempty_of_ssubset'
theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty :=
hs.imp fun _ => Or.inl
#align set.nonempty.inl Set.Nonempty.inl
theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty :=
ht.imp fun _ => Or.inr
#align set.nonempty.inr Set.Nonempty.inr
@[simp]
theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty :=
exists_or
#align set.union_nonempty Set.union_nonempty
theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
#align set.nonempty.left Set.Nonempty.left
theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty :=
h.imp fun _ => And.right
#align set.nonempty.right Set.Nonempty.right
theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t :=
Iff.rfl
#align set.inter_nonempty Set.inter_nonempty
theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by
simp_rw [inter_nonempty]
#align set.inter_nonempty_iff_exists_left Set.inter_nonempty_iff_exists_left
theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by
simp_rw [inter_nonempty, and_comm]
#align set.inter_nonempty_iff_exists_right Set.inter_nonempty_iff_exists_right
theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty :=
⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩
#align set.nonempty_iff_univ_nonempty Set.nonempty_iff_univ_nonempty
@[simp]
theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty
| ⟨x⟩ => ⟨x, trivial⟩
#align set.univ_nonempty Set.univ_nonempty
theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) :=
nonempty_subtype.2
#align set.nonempty.to_subtype Set.Nonempty.to_subtype
theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩
#align set.nonempty.to_type Set.Nonempty.to_type
instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) :=
Set.univ_nonempty.to_subtype
#align set.univ.nonempty Set.univ.nonempty
theorem nonempty_of_nonempty_subtype [Nonempty (↥s)] : s.Nonempty :=
nonempty_subtype.mp ‹_›
#align set.nonempty_of_nonempty_subtype Set.nonempty_of_nonempty_subtype
/-! ### Lemmas about the empty set -/
theorem empty_def : (∅ : Set α) = { _x : α | False } :=
rfl
#align set.empty_def Set.empty_def
@[simp]
theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False :=
Iff.rfl
#align set.mem_empty_iff_false Set.mem_empty_iff_false
@[simp]
theorem setOf_false : { _a : α | False } = ∅ :=
rfl
#align set.set_of_false Set.setOf_false
@[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl
@[simp]
theorem empty_subset (s : Set α) : ∅ ⊆ s :=
nofun
#align set.empty_subset Set.empty_subset
theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ :=
(Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm
#align set.subset_empty_iff Set.subset_empty_iff
theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s :=
subset_empty_iff.symm
#align set.eq_empty_iff_forall_not_mem Set.eq_empty_iff_forall_not_mem
theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ :=
subset_empty_iff.1 h
#align set.eq_empty_of_forall_not_mem Set.eq_empty_of_forall_not_mem
theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ :=
subset_empty_iff.1
#align set.eq_empty_of_subset_empty Set.eq_empty_of_subset_empty
theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ :=
eq_empty_of_subset_empty fun x _ => isEmptyElim x
#align set.eq_empty_of_is_empty Set.eq_empty_of_isEmpty
/-- There is exactly one set of a type that is empty. -/
instance uniqueEmpty [IsEmpty α] : Unique (Set α) where
default := ∅
uniq := eq_empty_of_isEmpty
#align set.unique_empty Set.uniqueEmpty
/-- See also `Set.nonempty_iff_ne_empty`. -/
theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by
simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem]
#align set.not_nonempty_iff_eq_empty Set.not_nonempty_iff_eq_empty
/-- See also `Set.not_nonempty_iff_eq_empty`. -/
theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty.not_right
#align set.nonempty_iff_ne_empty Set.nonempty_iff_ne_empty
/-- See also `nonempty_iff_ne_empty'`. -/
theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by
rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem]
/-- See also `not_nonempty_iff_eq_empty'`. -/
theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty'.not_right
alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty
#align set.nonempty.ne_empty Set.Nonempty.ne_empty
@[simp]
theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx
#align set.not_nonempty_empty Set.not_nonempty_empty
-- Porting note: removing `@[simp]` as it is competing with `isEmpty_subtype`.
-- @[simp]
theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ :=
not_iff_not.1 <| by simpa using nonempty_iff_ne_empty
#align set.is_empty_coe_sort Set.isEmpty_coe_sort
theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty :=
or_iff_not_imp_left.2 nonempty_iff_ne_empty.2
#align set.eq_empty_or_nonempty Set.eq_empty_or_nonempty
theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ :=
subset_empty_iff.1 <| e ▸ h
#align set.subset_eq_empty Set.subset_eq_empty
theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True :=
iff_true_intro fun _ => False.elim
#align set.ball_empty_iff Set.forall_mem_empty
@[deprecated (since := "2024-03-23")] alias ball_empty_iff := forall_mem_empty
instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) :=
⟨fun x => x.2⟩
@[simp]
theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty :=
(@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm
#align set.empty_ssubset Set.empty_ssubset
alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset
#align set.nonempty.empty_ssubset Set.Nonempty.empty_ssubset
/-!
### Universal set.
In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`.
Mathematically it is the same as `α` but it has a different type.
-/
@[simp]
theorem setOf_true : { _x : α | True } = univ :=
rfl
#align set.set_of_true Set.setOf_true
@[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl
@[simp]
theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α :=
eq_empty_iff_forall_not_mem.trans
⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩
#align set.univ_eq_empty_iff Set.univ_eq_empty_iff
theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e =>
not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm
#align set.empty_ne_univ Set.empty_ne_univ
@[simp]
theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial
#align set.subset_univ Set.subset_univ
@[simp]
theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ :=
@top_le_iff _ _ _ s
#align set.univ_subset_iff Set.univ_subset_iff
alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff
#align set.eq_univ_of_univ_subset Set.eq_univ_of_univ_subset
theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s :=
univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial
#align set.eq_univ_iff_forall Set.eq_univ_iff_forall
theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ :=
eq_univ_iff_forall.2
#align set.eq_univ_of_forall Set.eq_univ_of_forall
theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by
rintro ⟨x, hx⟩
exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x]
#align set.nonempty.eq_univ Set.Nonempty.eq_univ
theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ :=
eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t)
#align set.eq_univ_of_subset Set.eq_univ_of_subset
theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α)
| ⟨x⟩ => ⟨x, trivial⟩
#align set.exists_mem_of_nonempty Set.exists_mem_of_nonempty
theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by
rw [← not_forall, ← eq_univ_iff_forall]
#align set.ne_univ_iff_exists_not_mem Set.ne_univ_iff_exists_not_mem
theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} :
¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def]
#align set.not_subset_iff_exists_mem_not_mem Set.not_subset_iff_exists_mem_not_mem
theorem univ_unique [Unique α] : @Set.univ α = {default} :=
Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default
#align set.univ_unique Set.univ_unique
theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ :=
lt_top_iff_ne_top
#align set.ssubset_univ_iff Set.ssubset_univ_iff
instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) :=
⟨⟨∅, univ, empty_ne_univ⟩⟩
#align set.nontrivial_of_nonempty Set.nontrivial_of_nonempty
/-! ### Lemmas about union -/
theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } :=
rfl
#align set.union_def Set.union_def
theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b :=
Or.inl
#align set.mem_union_left Set.mem_union_left
theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b :=
Or.inr
#align set.mem_union_right Set.mem_union_right
theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b :=
H
#align set.mem_or_mem_of_mem_union Set.mem_or_mem_of_mem_union
theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P)
(H₃ : x ∈ b → P) : P :=
Or.elim H₁ H₂ H₃
#align set.mem_union.elim Set.MemUnion.elim
@[simp]
theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b :=
Iff.rfl
#align set.mem_union Set.mem_union
@[simp]
theorem union_self (a : Set α) : a ∪ a = a :=
ext fun _ => or_self_iff
#align set.union_self Set.union_self
@[simp]
theorem union_empty (a : Set α) : a ∪ ∅ = a :=
ext fun _ => or_false_iff _
#align set.union_empty Set.union_empty
@[simp]
theorem empty_union (a : Set α) : ∅ ∪ a = a :=
ext fun _ => false_or_iff _
#align set.empty_union Set.empty_union
theorem union_comm (a b : Set α) : a ∪ b = b ∪ a :=
ext fun _ => or_comm
#align set.union_comm Set.union_comm
theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) :=
ext fun _ => or_assoc
#align set.union_assoc Set.union_assoc
instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) :=
⟨union_assoc⟩
#align set.union_is_assoc Set.union_isAssoc
instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) :=
⟨union_comm⟩
#align set.union_is_comm Set.union_isComm
theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
ext fun _ => or_left_comm
#align set.union_left_comm Set.union_left_comm
theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ :=
ext fun _ => or_right_comm
#align set.union_right_comm Set.union_right_comm
@[simp]
theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s :=
sup_eq_left
#align set.union_eq_left_iff_subset Set.union_eq_left
@[simp]
theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t :=
sup_eq_right
#align set.union_eq_right_iff_subset Set.union_eq_right
theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t :=
union_eq_right.mpr h
#align set.union_eq_self_of_subset_left Set.union_eq_self_of_subset_left
theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s :=
union_eq_left.mpr h
#align set.union_eq_self_of_subset_right Set.union_eq_self_of_subset_right
@[simp]
theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl
#align set.subset_union_left Set.subset_union_left
@[simp]
theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr
#align set.subset_union_right Set.subset_union_right
theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ =>
Or.rec (@sr _) (@tr _)
#align set.union_subset Set.union_subset
@[simp]
theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u :=
(forall_congr' fun _ => or_imp).trans forall_and
#align set.union_subset_iff Set.union_subset_iff
@[gcongr]
theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) :
s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _)
#align set.union_subset_union Set.union_subset_union
@[gcongr]
theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h Subset.rfl
#align set.union_subset_union_left Set.union_subset_union_left
@[gcongr]
theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union Subset.rfl h
#align set.union_subset_union_right Set.union_subset_union_right
theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_left
#align set.subset_union_of_subset_left Set.subset_union_of_subset_left
theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_right
#align set.subset_union_of_subset_right Set.subset_union_of_subset_right
-- Porting note: replaced `⊔` in RHS
theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u :=
sup_congr_left ht hu
#align set.union_congr_left Set.union_congr_left
theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u :=
sup_congr_right hs ht
#align set.union_congr_right Set.union_congr_right
theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t :=
sup_eq_sup_iff_left
#align set.union_eq_union_iff_left Set.union_eq_union_iff_left
theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u :=
sup_eq_sup_iff_right
#align set.union_eq_union_iff_right Set.union_eq_union_iff_right
@[simp]
theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by
simp only [← subset_empty_iff]
exact union_subset_iff
#align set.union_empty_iff Set.union_empty_iff
@[simp]
theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _
#align set.union_univ Set.union_univ
@[simp]
theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _
#align set.univ_union Set.univ_union
/-! ### Lemmas about intersection -/
theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } :=
rfl
#align set.inter_def Set.inter_def
@[simp, mfld_simps]
theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b :=
Iff.rfl
#align set.mem_inter_iff Set.mem_inter_iff
theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b :=
⟨ha, hb⟩
#align set.mem_inter Set.mem_inter
theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a :=
h.left
#align set.mem_of_mem_inter_left Set.mem_of_mem_inter_left
theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b :=
h.right
#align set.mem_of_mem_inter_right Set.mem_of_mem_inter_right
@[simp]
theorem inter_self (a : Set α) : a ∩ a = a :=
ext fun _ => and_self_iff
#align set.inter_self Set.inter_self
@[simp]
theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ :=
ext fun _ => and_false_iff _
#align set.inter_empty Set.inter_empty
@[simp]
theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ :=
ext fun _ => false_and_iff _
#align set.empty_inter Set.empty_inter
theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a :=
ext fun _ => and_comm
#align set.inter_comm Set.inter_comm
theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) :=
ext fun _ => and_assoc
#align set.inter_assoc Set.inter_assoc
instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) :=
⟨inter_assoc⟩
#align set.inter_is_assoc Set.inter_isAssoc
instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) :=
⟨inter_comm⟩
#align set.inter_is_comm Set.inter_isComm
theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext fun _ => and_left_comm
#align set.inter_left_comm Set.inter_left_comm
theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ :=
ext fun _ => and_right_comm
#align set.inter_right_comm Set.inter_right_comm
@[simp, mfld_simps]
theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left
#align set.inter_subset_left Set.inter_subset_left
@[simp]
theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right
#align set.inter_subset_right Set.inter_subset_right
theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h =>
⟨rs h, rt h⟩
#align set.subset_inter Set.subset_inter
@[simp]
theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t :=
(forall_congr' fun _ => imp_and).trans forall_and
#align set.subset_inter_iff Set.subset_inter_iff
@[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left
#align set.inter_eq_left_iff_subset Set.inter_eq_left
@[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right
#align set.inter_eq_right_iff_subset Set.inter_eq_right
@[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf
@[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf
theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s :=
inter_eq_left.mpr
#align set.inter_eq_self_of_subset_left Set.inter_eq_self_of_subset_left
theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t :=
inter_eq_right.mpr
#align set.inter_eq_self_of_subset_right Set.inter_eq_self_of_subset_right
theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u :=
inf_congr_left ht hu
#align set.inter_congr_left Set.inter_congr_left
theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u :=
inf_congr_right hs ht
#align set.inter_congr_right Set.inter_congr_right
theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u :=
inf_eq_inf_iff_left
#align set.inter_eq_inter_iff_left Set.inter_eq_inter_iff_left
theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t :=
inf_eq_inf_iff_right
#align set.inter_eq_inter_iff_right Set.inter_eq_inter_iff_right
@[simp, mfld_simps]
theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _
#align set.inter_univ Set.inter_univ
@[simp, mfld_simps]
theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _
#align set.univ_inter Set.univ_inter
@[gcongr]
theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) :
s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _)
#align set.inter_subset_inter Set.inter_subset_inter
@[gcongr]
theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u :=
inter_subset_inter H Subset.rfl
#align set.inter_subset_inter_left Set.inter_subset_inter_left
@[gcongr]
theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t :=
inter_subset_inter Subset.rfl H
#align set.inter_subset_inter_right Set.inter_subset_inter_right
theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s :=
inter_eq_self_of_subset_right subset_union_left
#align set.union_inter_cancel_left Set.union_inter_cancel_left
theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t :=
inter_eq_self_of_subset_right subset_union_right
#align set.union_inter_cancel_right Set.union_inter_cancel_right
theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} :=
rfl
#align set.inter_set_of_eq_sep Set.inter_setOf_eq_sep
theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} :=
inter_comm _ _
#align set.set_of_inter_eq_sep Set.setOf_inter_eq_sep
/-! ### Distributivity laws -/
theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u :=
inf_sup_left _ _ _
#align set.inter_distrib_left Set.inter_union_distrib_left
theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u :=
inf_sup_right _ _ _
#align set.inter_distrib_right Set.union_inter_distrib_right
theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) :=
sup_inf_left _ _ _
#align set.union_distrib_left Set.union_inter_distrib_left
theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) :=
sup_inf_right _ _ _
#align set.union_distrib_right Set.inter_union_distrib_right
-- 2024-03-22
@[deprecated] alias inter_distrib_left := inter_union_distrib_left
@[deprecated] alias inter_distrib_right := union_inter_distrib_right
@[deprecated] alias union_distrib_left := union_inter_distrib_left
@[deprecated] alias union_distrib_right := inter_union_distrib_right
theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) :=
sup_sup_distrib_left _ _ _
#align set.union_union_distrib_left Set.union_union_distrib_left
theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) :=
sup_sup_distrib_right _ _ _
#align set.union_union_distrib_right Set.union_union_distrib_right
theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) :=
inf_inf_distrib_left _ _ _
#align set.inter_inter_distrib_left Set.inter_inter_distrib_left
theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) :=
inf_inf_distrib_right _ _ _
#align set.inter_inter_distrib_right Set.inter_inter_distrib_right
theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) :=
sup_sup_sup_comm _ _ _ _
#align set.union_union_union_comm Set.union_union_union_comm
theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) :=
inf_inf_inf_comm _ _ _ _
#align set.inter_inter_inter_comm Set.inter_inter_inter_comm
/-!
### Lemmas about `insert`
`insert α s` is the set `{α} ∪ s`.
-/
theorem insert_def (x : α) (s : Set α) : insert x s = { y | y = x ∨ y ∈ s } :=
rfl
#align set.insert_def Set.insert_def
@[simp]
theorem subset_insert (x : α) (s : Set α) : s ⊆ insert x s := fun _ => Or.inr
#align set.subset_insert Set.subset_insert
theorem mem_insert (x : α) (s : Set α) : x ∈ insert x s :=
Or.inl rfl
#align set.mem_insert Set.mem_insert
theorem mem_insert_of_mem {x : α} {s : Set α} (y : α) : x ∈ s → x ∈ insert y s :=
Or.inr
#align set.mem_insert_of_mem Set.mem_insert_of_mem
theorem eq_or_mem_of_mem_insert {x a : α} {s : Set α} : x ∈ insert a s → x = a ∨ x ∈ s :=
id
#align set.eq_or_mem_of_mem_insert Set.eq_or_mem_of_mem_insert
theorem mem_of_mem_insert_of_ne : b ∈ insert a s → b ≠ a → b ∈ s :=
Or.resolve_left
#align set.mem_of_mem_insert_of_ne Set.mem_of_mem_insert_of_ne
theorem eq_of_not_mem_of_mem_insert : b ∈ insert a s → b ∉ s → b = a :=
Or.resolve_right
#align set.eq_of_not_mem_of_mem_insert Set.eq_of_not_mem_of_mem_insert
@[simp]
theorem mem_insert_iff {x a : α} {s : Set α} : x ∈ insert a s ↔ x = a ∨ x ∈ s :=
Iff.rfl
#align set.mem_insert_iff Set.mem_insert_iff
@[simp]
theorem insert_eq_of_mem {a : α} {s : Set α} (h : a ∈ s) : insert a s = s :=
ext fun _ => or_iff_right_of_imp fun e => e.symm ▸ h
#align set.insert_eq_of_mem Set.insert_eq_of_mem
theorem ne_insert_of_not_mem {s : Set α} (t : Set α) {a : α} : a ∉ s → s ≠ insert a t :=
mt fun e => e.symm ▸ mem_insert _ _
#align set.ne_insert_of_not_mem Set.ne_insert_of_not_mem
@[simp]
theorem insert_eq_self : insert a s = s ↔ a ∈ s :=
⟨fun h => h ▸ mem_insert _ _, insert_eq_of_mem⟩
#align set.insert_eq_self Set.insert_eq_self
theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s :=
insert_eq_self.not
#align set.insert_ne_self Set.insert_ne_self
theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by
simp only [subset_def, mem_insert_iff, or_imp, forall_and, forall_eq]
#align set.insert_subset Set.insert_subset_iff
theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t :=
insert_subset_iff.mpr ⟨ha, hs⟩
theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := fun _ => Or.imp_right (@h _)
#align set.insert_subset_insert Set.insert_subset_insert
@[simp] theorem insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by
refine ⟨fun h x hx => ?_, insert_subset_insert⟩
rcases h (subset_insert _ _ hx) with (rfl | hxt)
exacts [(ha hx).elim, hxt]
#align set.insert_subset_insert_iff Set.insert_subset_insert_iff
theorem subset_insert_iff_of_not_mem (ha : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t :=
forall₂_congr fun _ hb => or_iff_right <| ne_of_mem_of_not_mem hb ha
#align set.subset_insert_iff_of_not_mem Set.subset_insert_iff_of_not_mem
theorem ssubset_iff_insert {s t : Set α} : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := by
simp only [insert_subset_iff, exists_and_right, ssubset_def, not_subset]
aesop
#align set.ssubset_iff_insert Set.ssubset_iff_insert
theorem ssubset_insert {s : Set α} {a : α} (h : a ∉ s) : s ⊂ insert a s :=
ssubset_iff_insert.2 ⟨a, h, Subset.rfl⟩
#align set.ssubset_insert Set.ssubset_insert
theorem insert_comm (a b : α) (s : Set α) : insert a (insert b s) = insert b (insert a s) :=
ext fun _ => or_left_comm
#align set.insert_comm Set.insert_comm
-- Porting note (#10618): removing `simp` attribute because `simp` can prove it
theorem insert_idem (a : α) (s : Set α) : insert a (insert a s) = insert a s :=
insert_eq_of_mem <| mem_insert _ _
#align set.insert_idem Set.insert_idem
theorem insert_union : insert a s ∪ t = insert a (s ∪ t) :=
ext fun _ => or_assoc
#align set.insert_union Set.insert_union
@[simp]
theorem union_insert : s ∪ insert a t = insert a (s ∪ t) :=
ext fun _ => or_left_comm
#align set.union_insert Set.union_insert
@[simp]
theorem insert_nonempty (a : α) (s : Set α) : (insert a s).Nonempty :=
⟨a, mem_insert a s⟩
#align set.insert_nonempty Set.insert_nonempty
instance (a : α) (s : Set α) : Nonempty (insert a s : Set α) :=
(insert_nonempty a s).to_subtype
theorem insert_inter_distrib (a : α) (s t : Set α) : insert a (s ∩ t) = insert a s ∩ insert a t :=
ext fun _ => or_and_left
#align set.insert_inter_distrib Set.insert_inter_distrib
theorem insert_union_distrib (a : α) (s t : Set α) : insert a (s ∪ t) = insert a s ∪ insert a t :=
ext fun _ => or_or_distrib_left
#align set.insert_union_distrib Set.insert_union_distrib
theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b :=
⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert a s) ha,
congr_arg (fun x => insert x s)⟩
#align set.insert_inj Set.insert_inj
-- useful in proofs by induction
theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ insert a s → P x)
(x) (h : x ∈ s) : P x :=
H _ (Or.inr h)
#align set.forall_of_forall_insert Set.forall_of_forall_insert
theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ s → P x) (ha : P a)
(x) (h : x ∈ insert a s) : P x :=
h.elim (fun e => e.symm ▸ ha) (H _)
#align set.forall_insert_of_forall Set.forall_insert_of_forall
/- Porting note: ∃ x ∈ insert a s, P x is parsed as ∃ x, x ∈ insert a s ∧ P x,
where in Lean3 it was parsed as `∃ x, ∃ (h : x ∈ insert a s), P x` -/
theorem exists_mem_insert {P : α → Prop} {a : α} {s : Set α} :
(∃ x ∈ insert a s, P x) ↔ (P a ∨ ∃ x ∈ s, P x) := by
simp [mem_insert_iff, or_and_right, exists_and_left, exists_or]
#align set.bex_insert_iff Set.exists_mem_insert
@[deprecated (since := "2024-03-23")] alias bex_insert_iff := exists_mem_insert
theorem forall_mem_insert {P : α → Prop} {a : α} {s : Set α} :
(∀ x ∈ insert a s, P x) ↔ P a ∧ ∀ x ∈ s, P x :=
forall₂_or_left.trans <| and_congr_left' forall_eq
#align set.ball_insert_iff Set.forall_mem_insert
@[deprecated (since := "2024-03-23")] alias ball_insert_iff := forall_mem_insert
/-! ### Lemmas about singletons -/
/- porting note: instance was in core in Lean3 -/
instance : LawfulSingleton α (Set α) :=
⟨fun x => Set.ext fun a => by
simp only [mem_empty_iff_false, mem_insert_iff, or_false]
exact Iff.rfl⟩
theorem singleton_def (a : α) : ({a} : Set α) = insert a ∅ :=
(insert_emptyc_eq a).symm
#align set.singleton_def Set.singleton_def
@[simp]
theorem mem_singleton_iff {a b : α} : a ∈ ({b} : Set α) ↔ a = b :=
Iff.rfl
#align set.mem_singleton_iff Set.mem_singleton_iff
@[simp]
theorem setOf_eq_eq_singleton {a : α} : { n | n = a } = {a} :=
rfl
#align set.set_of_eq_eq_singleton Set.setOf_eq_eq_singleton
@[simp]
theorem setOf_eq_eq_singleton' {a : α} : { x | a = x } = {a} :=
ext fun _ => eq_comm
#align set.set_of_eq_eq_singleton' Set.setOf_eq_eq_singleton'
-- TODO: again, annotation needed
--Porting note (#11119): removed `simp` attribute
theorem mem_singleton (a : α) : a ∈ ({a} : Set α) :=
@rfl _ _
#align set.mem_singleton Set.mem_singleton
theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Set α)) : x = y :=
h
#align set.eq_of_mem_singleton Set.eq_of_mem_singleton
@[simp]
theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : Set α) ↔ x = y :=
ext_iff.trans eq_iff_eq_cancel_left
#align set.singleton_eq_singleton_iff Set.singleton_eq_singleton_iff
theorem singleton_injective : Injective (singleton : α → Set α) := fun _ _ =>
singleton_eq_singleton_iff.mp
#align set.singleton_injective Set.singleton_injective
theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : Set α) :=
H
#align set.mem_singleton_of_eq Set.mem_singleton_of_eq
theorem insert_eq (x : α) (s : Set α) : insert x s = ({x} : Set α) ∪ s :=
rfl
#align set.insert_eq Set.insert_eq
@[simp]
theorem singleton_nonempty (a : α) : ({a} : Set α).Nonempty :=
⟨a, rfl⟩
#align set.singleton_nonempty Set.singleton_nonempty
@[simp]
theorem singleton_ne_empty (a : α) : ({a} : Set α) ≠ ∅ :=
(singleton_nonempty _).ne_empty
#align set.singleton_ne_empty Set.singleton_ne_empty
--Porting note (#10618): removed `simp` attribute because `simp` can prove it
theorem empty_ssubset_singleton : (∅ : Set α) ⊂ {a} :=
(singleton_nonempty _).empty_ssubset
#align set.empty_ssubset_singleton Set.empty_ssubset_singleton
@[simp]
theorem singleton_subset_iff {a : α} {s : Set α} : {a} ⊆ s ↔ a ∈ s :=
forall_eq
#align set.singleton_subset_iff Set.singleton_subset_iff
theorem singleton_subset_singleton : ({a} : Set α) ⊆ {b} ↔ a = b := by simp
#align set.singleton_subset_singleton Set.singleton_subset_singleton
theorem set_compr_eq_eq_singleton {a : α} : { b | b = a } = {a} :=
rfl
#align set.set_compr_eq_eq_singleton Set.set_compr_eq_eq_singleton
@[simp]
theorem singleton_union : {a} ∪ s = insert a s :=
rfl
#align set.singleton_union Set.singleton_union
@[simp]
theorem union_singleton : s ∪ {a} = insert a s :=
union_comm _ _
#align set.union_singleton Set.union_singleton
@[simp]
theorem singleton_inter_nonempty : ({a} ∩ s).Nonempty ↔ a ∈ s := by
simp only [Set.Nonempty, mem_inter_iff, mem_singleton_iff, exists_eq_left]
#align set.singleton_inter_nonempty Set.singleton_inter_nonempty
@[simp]
theorem inter_singleton_nonempty : (s ∩ {a}).Nonempty ↔ a ∈ s := by
rw [inter_comm, singleton_inter_nonempty]
#align set.inter_singleton_nonempty Set.inter_singleton_nonempty
@[simp]
theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s :=
not_nonempty_iff_eq_empty.symm.trans singleton_inter_nonempty.not
#align set.singleton_inter_eq_empty Set.singleton_inter_eq_empty
@[simp]
theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s := by
rw [inter_comm, singleton_inter_eq_empty]
#align set.inter_singleton_eq_empty Set.inter_singleton_eq_empty
theorem nmem_singleton_empty {s : Set α} : s ∉ ({∅} : Set (Set α)) ↔ s.Nonempty :=
nonempty_iff_ne_empty.symm
#align set.nmem_singleton_empty Set.nmem_singleton_empty
instance uniqueSingleton (a : α) : Unique (↥({a} : Set α)) :=
⟨⟨⟨a, mem_singleton a⟩⟩, fun ⟨_, h⟩ => Subtype.eq h⟩
#align set.unique_singleton Set.uniqueSingleton
theorem eq_singleton_iff_unique_mem : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a :=
Subset.antisymm_iff.trans <| and_comm.trans <| and_congr_left' singleton_subset_iff
#align set.eq_singleton_iff_unique_mem Set.eq_singleton_iff_unique_mem
theorem eq_singleton_iff_nonempty_unique_mem : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a :=
eq_singleton_iff_unique_mem.trans <|
and_congr_left fun H => ⟨fun h' => ⟨_, h'⟩, fun ⟨x, h⟩ => H x h ▸ h⟩
#align set.eq_singleton_iff_nonempty_unique_mem Set.eq_singleton_iff_nonempty_unique_mem
set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532
-- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS.
@[simp]
theorem default_coe_singleton (x : α) : (default : ({x} : Set α)) = ⟨x, rfl⟩ :=
rfl
#align set.default_coe_singleton Set.default_coe_singleton
/-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/
section Sep
variable {p q : α → Prop} {x : α}
theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } :=
⟨xs, px⟩
#align set.mem_sep Set.mem_sep
@[simp]
theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t :=
rfl
#align set.sep_mem_eq Set.sep_mem_eq
@[simp]
theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x :=
Iff.rfl
#align set.mem_sep_iff Set.mem_sep_iff
theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by
simp_rw [ext_iff, mem_sep_iff, and_congr_right_iff]
#align set.sep_ext_iff Set.sep_ext_iff
theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s :=
inter_eq_self_of_subset_right h
#align set.sep_eq_of_subset Set.sep_eq_of_subset
@[simp]
theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left
#align set.sep_subset Set.sep_subset
@[simp]
theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by
simp_rw [ext_iff, mem_sep_iff, and_iff_left_iff_imp]
#align set.sep_eq_self_iff_mem_true Set.sep_eq_self_iff_mem_true
@[simp]
theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by
simp_rw [ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false_iff, not_and]
#align set.sep_eq_empty_iff_mem_false Set.sep_eq_empty_iff_mem_false
--Porting note (#10618): removed `simp` attribute because `simp` can prove it
theorem sep_true : { x ∈ s | True } = s :=
inter_univ s
#align set.sep_true Set.sep_true
--Porting note (#10618): removed `simp` attribute because `simp` can prove it
theorem sep_false : { x ∈ s | False } = ∅ :=
inter_empty s
#align set.sep_false Set.sep_false
--Porting note (#10618): removed `simp` attribute because `simp` can prove it
theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ :=
empty_inter {x | p x}
#align set.sep_empty Set.sep_empty
--Porting note (#10618): removed `simp` attribute because `simp` can prove it
theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } :=
univ_inter {x | p x}
#align set.sep_univ Set.sep_univ
@[simp]
theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } :=
union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p
#align set.sep_union Set.sep_union
@[simp]
theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } :=
inter_inter_distrib_right s t {x | p x}
#align set.sep_inter Set.sep_inter
@[simp]
theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } :=
inter_inter_distrib_left s {x | p x} {x | q x}
#align set.sep_and Set.sep_and
@[simp]
theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } :=
inter_union_distrib_left s p q
#align set.sep_or Set.sep_or
@[simp]
theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } :=
rfl
#align set.sep_set_of Set.sep_setOf
end Sep
@[simp]
theorem subset_singleton_iff {α : Type*} {s : Set α} {x : α} : s ⊆ {x} ↔ ∀ y ∈ s, y = x :=
Iff.rfl
#align set.subset_singleton_iff Set.subset_singleton_iff
theorem subset_singleton_iff_eq {s : Set α} {x : α} : s ⊆ {x} ↔ s = ∅ ∨ s = {x} := by
obtain rfl | hs := s.eq_empty_or_nonempty
· exact ⟨fun _ => Or.inl rfl, fun _ => empty_subset _⟩
· simp [eq_singleton_iff_nonempty_unique_mem, hs, hs.ne_empty]
#align set.subset_singleton_iff_eq Set.subset_singleton_iff_eq
theorem Nonempty.subset_singleton_iff (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} :=
subset_singleton_iff_eq.trans <| or_iff_right h.ne_empty
#align set.nonempty.subset_singleton_iff Set.Nonempty.subset_singleton_iff
theorem ssubset_singleton_iff {s : Set α} {x : α} : s ⊂ {x} ↔ s = ∅ := by
rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_right, and_not_self_iff, or_false_iff,
and_iff_left_iff_imp]
exact fun h => h ▸ (singleton_ne_empty _).symm
#align set.ssubset_singleton_iff Set.ssubset_singleton_iff
theorem eq_empty_of_ssubset_singleton {s : Set α} {x : α} (hs : s ⊂ {x}) : s = ∅ :=
ssubset_singleton_iff.1 hs
#align set.eq_empty_of_ssubset_singleton Set.eq_empty_of_ssubset_singleton
theorem eq_of_nonempty_of_subsingleton {α} [Subsingleton α] (s t : Set α) [Nonempty s]
[Nonempty t] : s = t :=
nonempty_of_nonempty_subtype.eq_univ.trans nonempty_of_nonempty_subtype.eq_univ.symm
theorem eq_of_nonempty_of_subsingleton' {α} [Subsingleton α] {s : Set α} (t : Set α)
(hs : s.Nonempty) [Nonempty t] : s = t :=
have := hs.to_subtype; eq_of_nonempty_of_subsingleton s t
set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532
theorem Nonempty.eq_zero [Subsingleton α] [Zero α] {s : Set α} (h : s.Nonempty) :
s = {0} := eq_of_nonempty_of_subsingleton' {0} h
set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532
theorem Nonempty.eq_one [Subsingleton α] [One α] {s : Set α} (h : s.Nonempty) :
s = {1} := eq_of_nonempty_of_subsingleton' {1} h
/-! ### Disjointness -/
protected theorem disjoint_iff : Disjoint s t ↔ s ∩ t ⊆ ∅ :=
disjoint_iff_inf_le
#align set.disjoint_iff Set.disjoint_iff
theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ :=
disjoint_iff
#align set.disjoint_iff_inter_eq_empty Set.disjoint_iff_inter_eq_empty
theorem _root_.Disjoint.inter_eq : Disjoint s t → s ∩ t = ∅ :=
Disjoint.eq_bot
#align disjoint.inter_eq Disjoint.inter_eq
theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t :=
disjoint_iff_inf_le.trans <| forall_congr' fun _ => not_and
#align set.disjoint_left Set.disjoint_left
theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [disjoint_comm, disjoint_left]
#align set.disjoint_right Set.disjoint_right
lemma not_disjoint_iff : ¬Disjoint s t ↔ ∃ x, x ∈ s ∧ x ∈ t :=
Set.disjoint_iff.not.trans <| not_forall.trans <| exists_congr fun _ ↦ not_not
#align set.not_disjoint_iff Set.not_disjoint_iff
lemma not_disjoint_iff_nonempty_inter : ¬ Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff
#align set.not_disjoint_iff_nonempty_inter Set.not_disjoint_iff_nonempty_inter
alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter
#align set.nonempty.not_disjoint Set.Nonempty.not_disjoint
lemma disjoint_or_nonempty_inter (s t : Set α) : Disjoint s t ∨ (s ∩ t).Nonempty :=
(em _).imp_right not_disjoint_iff_nonempty_inter.1
#align set.disjoint_or_nonempty_inter Set.disjoint_or_nonempty_inter
lemma disjoint_iff_forall_ne : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ t → a ≠ b := by
simp only [Ne, disjoint_left, @imp_not_comm _ (_ = _), forall_eq']
#align set.disjoint_iff_forall_ne Set.disjoint_iff_forall_ne
alias ⟨_root_.Disjoint.ne_of_mem, _⟩ := disjoint_iff_forall_ne
#align disjoint.ne_of_mem Disjoint.ne_of_mem
lemma disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := d.mono_left h
#align set.disjoint_of_subset_left Set.disjoint_of_subset_left
lemma disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := d.mono_right h
#align set.disjoint_of_subset_right Set.disjoint_of_subset_right
lemma disjoint_of_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (h : Disjoint s₂ t₂) : Disjoint s₁ t₁ :=
h.mono hs ht
#align set.disjoint_of_subset Set.disjoint_of_subset
@[simp]
lemma disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := disjoint_sup_left
#align set.disjoint_union_left Set.disjoint_union_left
@[simp]
lemma disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := disjoint_sup_right
#align set.disjoint_union_right Set.disjoint_union_right
@[simp] lemma disjoint_empty (s : Set α) : Disjoint s ∅ := disjoint_bot_right
#align set.disjoint_empty Set.disjoint_empty
@[simp] lemma empty_disjoint (s : Set α) : Disjoint ∅ s := disjoint_bot_left
#align set.empty_disjoint Set.empty_disjoint
@[simp] lemma univ_disjoint : Disjoint univ s ↔ s = ∅ := top_disjoint
#align set.univ_disjoint Set.univ_disjoint
@[simp] lemma disjoint_univ : Disjoint s univ ↔ s = ∅ := disjoint_top
#align set.disjoint_univ Set.disjoint_univ
lemma disjoint_sdiff_left : Disjoint (t \ s) s := disjoint_sdiff_self_left
#align set.disjoint_sdiff_left Set.disjoint_sdiff_left
lemma disjoint_sdiff_right : Disjoint s (t \ s) := disjoint_sdiff_self_right
#align set.disjoint_sdiff_right Set.disjoint_sdiff_right
-- TODO: prove this in terms of a lattice lemma
theorem disjoint_sdiff_inter : Disjoint (s \ t) (s ∩ t) :=
disjoint_of_subset_right inter_subset_right disjoint_sdiff_left
#align set.disjoint_sdiff_inter Set.disjoint_sdiff_inter
theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u :=
sdiff_sup_sdiff_cancel hts hut
#align set.diff_union_diff_cancel Set.diff_union_diff_cancel
theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h
#align set.diff_diff_eq_sdiff_union Set.diff_diff_eq_sdiff_union
@[simp default+1]
lemma disjoint_singleton_left : Disjoint {a} s ↔ a ∉ s := by simp [Set.disjoint_iff, subset_def]
#align set.disjoint_singleton_left Set.disjoint_singleton_left
@[simp]
lemma disjoint_singleton_right : Disjoint s {a} ↔ a ∉ s :=
disjoint_comm.trans disjoint_singleton_left
#align set.disjoint_singleton_right Set.disjoint_singleton_right
lemma disjoint_singleton : Disjoint ({a} : Set α) {b} ↔ a ≠ b := by
simp
#align set.disjoint_singleton Set.disjoint_singleton
lemma subset_diff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff
#align set.subset_diff Set.subset_diff
lemma ssubset_iff_sdiff_singleton : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t \ {a} := by
simp [ssubset_iff_insert, subset_diff, insert_subset_iff]; aesop
theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) :=
inf_sdiff_distrib_left _ _ _
#align set.inter_diff_distrib_left Set.inter_diff_distrib_left
theorem inter_diff_distrib_right (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ (t ∩ u) :=
inf_sdiff_distrib_right _ _ _
#align set.inter_diff_distrib_right Set.inter_diff_distrib_right
/-! ### Lemmas about complement -/
theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } :=
rfl
#align set.compl_def Set.compl_def
theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ :=
h
#align set.mem_compl Set.mem_compl
theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } :=
rfl
#align set.compl_set_of Set.compl_setOf
theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s :=
h
#align set.not_mem_of_mem_compl Set.not_mem_of_mem_compl
theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s :=
not_not
#align set.not_mem_compl_iff Set.not_mem_compl_iff
@[simp]
theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ :=
inf_compl_eq_bot
#align set.inter_compl_self Set.inter_compl_self
@[simp]
theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ :=
compl_inf_eq_bot
#align set.compl_inter_self Set.compl_inter_self
@[simp]
theorem compl_empty : (∅ : Set α)ᶜ = univ :=
compl_bot
#align set.compl_empty Set.compl_empty
@[simp]
theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ :=
compl_sup
#align set.compl_union Set.compl_union
theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ :=
compl_inf
#align set.compl_inter Set.compl_inter
@[simp]
theorem compl_univ : (univ : Set α)ᶜ = ∅ :=
compl_top
#align set.compl_univ Set.compl_univ
@[simp]
theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ :=
compl_eq_bot
#align set.compl_empty_iff Set.compl_empty_iff
@[simp]
theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ :=
compl_eq_top
#align set.compl_univ_iff Set.compl_univ_iff
theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty :=
compl_univ_iff.not.trans nonempty_iff_ne_empty.symm
#align set.compl_ne_univ Set.compl_ne_univ
theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ :=
(ne_univ_iff_exists_not_mem s).symm
#align set.nonempty_compl Set.nonempty_compl
@[simp] lemma nonempty_compl_of_nontrivial [Nontrivial α] (x : α) : Set.Nonempty {x}ᶜ := by
obtain ⟨y, hy⟩ := exists_ne x
exact ⟨y, by simp [hy]⟩
theorem mem_compl_singleton_iff {a x : α} : x ∈ ({a} : Set α)ᶜ ↔ x ≠ a :=
Iff.rfl
#align set.mem_compl_singleton_iff Set.mem_compl_singleton_iff
theorem compl_singleton_eq (a : α) : ({a} : Set α)ᶜ = { x | x ≠ a } :=
rfl
#align set.compl_singleton_eq Set.compl_singleton_eq
@[simp]
theorem compl_ne_eq_singleton (a : α) : ({ x | x ≠ a } : Set α)ᶜ = {a} :=
compl_compl _
#align set.compl_ne_eq_singleton Set.compl_ne_eq_singleton
theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ :=
ext fun _ => or_iff_not_and_not
#align set.union_eq_compl_compl_inter_compl Set.union_eq_compl_compl_inter_compl
theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ :=
ext fun _ => and_iff_not_or_not
#align set.inter_eq_compl_compl_union_compl Set.inter_eq_compl_compl_union_compl
@[simp]
theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ :=
eq_univ_iff_forall.2 fun _ => em _
#align set.union_compl_self Set.union_compl_self
@[simp]
theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self]
#align set.compl_union_self Set.compl_union_self
theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s :=
@compl_le_iff_compl_le _ s _ _
#align set.compl_subset_comm Set.compl_subset_comm
theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ :=
@le_compl_iff_le_compl _ _ _ t
#align set.subset_compl_comm Set.subset_compl_comm
@[simp]
theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s :=
@compl_le_compl_iff_le (Set α) _ _ _
#align set.compl_subset_compl Set.compl_subset_compl
@[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h
theorem subset_compl_iff_disjoint_left : s ⊆ tᶜ ↔ Disjoint t s :=
@le_compl_iff_disjoint_left (Set α) _ _ _
#align set.subset_compl_iff_disjoint_left Set.subset_compl_iff_disjoint_left
theorem subset_compl_iff_disjoint_right : s ⊆ tᶜ ↔ Disjoint s t :=
@le_compl_iff_disjoint_right (Set α) _ _ _
#align set.subset_compl_iff_disjoint_right Set.subset_compl_iff_disjoint_right
theorem disjoint_compl_left_iff_subset : Disjoint sᶜ t ↔ t ⊆ s :=
disjoint_compl_left_iff
#align set.disjoint_compl_left_iff_subset Set.disjoint_compl_left_iff_subset
theorem disjoint_compl_right_iff_subset : Disjoint s tᶜ ↔ s ⊆ t :=
disjoint_compl_right_iff
#align set.disjoint_compl_right_iff_subset Set.disjoint_compl_right_iff_subset
alias ⟨_, _root_.Disjoint.subset_compl_right⟩ := subset_compl_iff_disjoint_right
#align disjoint.subset_compl_right Disjoint.subset_compl_right
alias ⟨_, _root_.Disjoint.subset_compl_left⟩ := subset_compl_iff_disjoint_left
#align disjoint.subset_compl_left Disjoint.subset_compl_left
alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_left⟩ := disjoint_compl_left_iff_subset
#align has_subset.subset.disjoint_compl_left HasSubset.Subset.disjoint_compl_left
alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_right⟩ := disjoint_compl_right_iff_subset
#align has_subset.subset.disjoint_compl_right HasSubset.Subset.disjoint_compl_right
theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t :=
(@isCompl_compl _ u _).le_sup_right_iff_inf_left_le
#align set.subset_union_compl_iff_inter_subset Set.subset_union_compl_iff_inter_subset
theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ :=
Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left
#align set.compl_subset_iff_union Set.compl_subset_iff_union
@[simp]
theorem subset_compl_singleton_iff {a : α} {s : Set α} : s ⊆ {a}ᶜ ↔ a ∉ s :=
subset_compl_comm.trans singleton_subset_iff
#align set.subset_compl_singleton_iff Set.subset_compl_singleton_iff
theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c :=
forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or
#align set.inter_subset Set.inter_subset
theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t :=
(not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm
#align set.inter_compl_nonempty_iff Set.inter_compl_nonempty_iff
/-! ### Lemmas about set difference -/
theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx
#align set.not_mem_diff_of_mem Set.not_mem_diff_of_mem
theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s :=
h.left
#align set.mem_of_mem_diff Set.mem_of_mem_diff
theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t :=
h.right
#align set.not_mem_of_mem_diff Set.not_mem_of_mem_diff
theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm]
#align set.diff_eq_compl_inter Set.diff_eq_compl_inter
theorem nonempty_diff {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t :=
inter_compl_nonempty_iff
#align set.nonempty_diff Set.nonempty_diff
theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le
#align set.diff_subset Set.diff_subset
theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ :=
diff_eq_compl_inter ▸ inter_subset_left
theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u :=
sup_sdiff_cancel' h₁ h₂
#align set.union_diff_cancel' Set.union_diff_cancel'
theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t :=
sup_sdiff_cancel_right h
#align set.union_diff_cancel Set.union_diff_cancel
theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t :=
Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h
#align set.union_diff_cancel_left Set.union_diff_cancel_left
theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s :=
Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h
#align set.union_diff_cancel_right Set.union_diff_cancel_right
@[simp]
theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s :=
sup_sdiff_left_self
#align set.union_diff_left Set.union_diff_left
@[simp]
theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
#align set.union_diff_right Set.union_diff_right
theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u :=
sup_sdiff
#align set.union_diff_distrib Set.union_diff_distrib
theorem inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) :=
inf_sdiff_assoc
#align set.inter_diff_assoc Set.inter_diff_assoc
@[simp]
theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ :=
inf_sdiff_self_right
#align set.inter_diff_self Set.inter_diff_self
@[simp]
theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s :=
sup_inf_sdiff s t
#align set.inter_union_diff Set.inter_union_diff
@[simp]
theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by
rw [union_comm]
exact sup_inf_sdiff _ _
#align set.diff_union_inter Set.diff_union_inter
@[simp]
theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s :=
inter_union_diff _ _
#align set.inter_union_compl Set.inter_union_compl
@[gcongr]
theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ :=
show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff
#align set.diff_subset_diff Set.diff_subset_diff
@[gcongr]
theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t :=
sdiff_le_sdiff_right ‹s₁ ≤ s₂›
#align set.diff_subset_diff_left Set.diff_subset_diff_left
@[gcongr]
theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t :=
sdiff_le_sdiff_left ‹t ≤ u›
#align set.diff_subset_diff_right Set.diff_subset_diff_right
theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s :=
top_sdiff.symm
#align set.compl_eq_univ_diff Set.compl_eq_univ_diff
@[simp]
theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ :=
bot_sdiff
#align set.empty_diff Set.empty_diff
theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t :=
sdiff_eq_bot_iff
#align set.diff_eq_empty Set.diff_eq_empty
@[simp]
theorem diff_empty {s : Set α} : s \ ∅ = s :=
sdiff_bot
#align set.diff_empty Set.diff_empty
@[simp]
theorem diff_univ (s : Set α) : s \ univ = ∅ :=
diff_eq_empty.2 (subset_univ s)
#align set.diff_univ Set.diff_univ
theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) :=
sdiff_sdiff_left
#align set.diff_diff Set.diff_diff
-- the following statement contains parentheses to help the reader
theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t :=
sdiff_sdiff_comm
#align set.diff_diff_comm Set.diff_diff_comm
theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u :=
show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff
#align set.diff_subset_iff Set.diff_subset_iff
theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t :=
show s ≤ s \ t ∪ t from le_sdiff_sup
#align set.subset_diff_union Set.subset_diff_union
theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s :=
Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _)
#align set.diff_union_of_subset Set.diff_union_of_subset
@[simp]
theorem diff_singleton_subset_iff {x : α} {s t : Set α} : s \ {x} ⊆ t ↔ s ⊆ insert x t := by
rw [← union_singleton, union_comm]
apply diff_subset_iff
#align set.diff_singleton_subset_iff Set.diff_singleton_subset_iff
theorem subset_diff_singleton {x : α} {s t : Set α} (h : s ⊆ t) (hx : x ∉ s) : s ⊆ t \ {x} :=
subset_inter h <| subset_compl_comm.1 <| singleton_subset_iff.2 hx
#align set.subset_diff_singleton Set.subset_diff_singleton
theorem subset_insert_diff_singleton (x : α) (s : Set α) : s ⊆ insert x (s \ {x}) := by
rw [← diff_singleton_subset_iff]
#align set.subset_insert_diff_singleton Set.subset_insert_diff_singleton
theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t :=
show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm
#align set.diff_subset_comm Set.diff_subset_comm
theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u :=
sdiff_inf
#align set.diff_inter Set.diff_inter
theorem diff_inter_diff {s t u : Set α} : s \ t ∩ (s \ u) = s \ (t ∪ u) :=
sdiff_sup.symm
#align set.diff_inter_diff Set.diff_inter_diff
theorem diff_compl : s \ tᶜ = s ∩ t :=
sdiff_compl
#align set.diff_compl Set.diff_compl
theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u :=
sdiff_sdiff_right'
#align set.diff_diff_right Set.diff_diff_right
@[simp]
theorem insert_diff_of_mem (s) (h : a ∈ t) : insert a s \ t = s \ t := by
ext
constructor <;> simp (config := { contextual := true }) [or_imp, h]
#align set.insert_diff_of_mem Set.insert_diff_of_mem
theorem insert_diff_of_not_mem (s) (h : a ∉ t) : insert a s \ t = insert a (s \ t) := by
classical
ext x
by_cases h' : x ∈ t
· have : x ≠ a := by
intro H
rw [H] at h'
exact h h'
simp [h, h', this]
· simp [h, h']
#align set.insert_diff_of_not_mem Set.insert_diff_of_not_mem
theorem insert_diff_self_of_not_mem {a : α} {s : Set α} (h : a ∉ s) : insert a s \ {a} = s := by
ext x
simp [and_iff_left_of_imp fun hx : x ∈ s => show x ≠ a from fun hxa => h <| hxa ▸ hx]
#align set.insert_diff_self_of_not_mem Set.insert_diff_self_of_not_mem
@[simp]
theorem insert_diff_eq_singleton {a : α} {s : Set α} (h : a ∉ s) : insert a s \ s = {a} := by
ext
rw [Set.mem_diff, Set.mem_insert_iff, Set.mem_singleton_iff, or_and_right, and_not_self_iff,
or_false_iff, and_iff_left_iff_imp]
rintro rfl
exact h
#align set.insert_diff_eq_singleton Set.insert_diff_eq_singleton
theorem inter_insert_of_mem (h : a ∈ s) : s ∩ insert a t = insert a (s ∩ t) := by
rw [insert_inter_distrib, insert_eq_of_mem h]
#align set.inter_insert_of_mem Set.inter_insert_of_mem
theorem insert_inter_of_mem (h : a ∈ t) : insert a s ∩ t = insert a (s ∩ t) := by
rw [insert_inter_distrib, insert_eq_of_mem h]
#align set.insert_inter_of_mem Set.insert_inter_of_mem
theorem inter_insert_of_not_mem (h : a ∉ s) : s ∩ insert a t = s ∩ t :=
ext fun _ => and_congr_right fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h
#align set.inter_insert_of_not_mem Set.inter_insert_of_not_mem
theorem insert_inter_of_not_mem (h : a ∉ t) : insert a s ∩ t = s ∩ t :=
ext fun _ => and_congr_left fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h
#align set.insert_inter_of_not_mem Set.insert_inter_of_not_mem
@[simp]
theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t :=
sup_sdiff_self _ _
#align set.union_diff_self Set.union_diff_self
@[simp]
theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t :=
sdiff_sup_self _ _
#align set.diff_union_self Set.diff_union_self
@[simp]
theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ :=
inf_sdiff_self_left
#align set.diff_inter_self Set.diff_inter_self
@[simp]
theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t :=
sdiff_inf_self_right _ _
#align set.diff_inter_self_eq_diff Set.diff_inter_self_eq_diff
@[simp]
theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t :=
sdiff_inf_self_left _ _
#align set.diff_self_inter Set.diff_self_inter
@[simp]
theorem diff_singleton_eq_self {a : α} {s : Set α} (h : a ∉ s) : s \ {a} = s :=
sdiff_eq_self_iff_disjoint.2 <| by simp [h]
#align set.diff_singleton_eq_self Set.diff_singleton_eq_self
@[simp]
theorem diff_singleton_sSubset {s : Set α} {a : α} : s \ {a} ⊂ s ↔ a ∈ s :=
sdiff_le.lt_iff_ne.trans <| sdiff_eq_left.not.trans <| by simp
#align set.diff_singleton_ssubset Set.diff_singleton_sSubset
@[simp]
theorem insert_diff_singleton {a : α} {s : Set α} : insert a (s \ {a}) = insert a s := by
simp [insert_eq, union_diff_self, -union_singleton, -singleton_union]
#align set.insert_diff_singleton Set.insert_diff_singleton
theorem insert_diff_singleton_comm (hab : a ≠ b) (s : Set α) :
insert a (s \ {b}) = insert a s \ {b} := by
simp_rw [← union_singleton, union_diff_distrib,
diff_singleton_eq_self (mem_singleton_iff.not.2 hab.symm)]
#align set.insert_diff_singleton_comm Set.insert_diff_singleton_comm
--Porting note (#10618): removed `simp` attribute because `simp` can prove it
theorem diff_self {s : Set α} : s \ s = ∅ :=
sdiff_self
#align set.diff_self Set.diff_self
theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t :=
sdiff_sdiff_right_self
#align set.diff_diff_right_self Set.diff_diff_right_self
theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s :=
sdiff_sdiff_eq_self h
#align set.diff_diff_cancel_left Set.diff_diff_cancel_left
theorem mem_diff_singleton {x y : α} {s : Set α} : x ∈ s \ {y} ↔ x ∈ s ∧ x ≠ y :=
Iff.rfl
#align set.mem_diff_singleton Set.mem_diff_singleton
theorem mem_diff_singleton_empty {t : Set (Set α)} : s ∈ t \ {∅} ↔ s ∈ t ∧ s.Nonempty :=
mem_diff_singleton.trans <| and_congr_right' nonempty_iff_ne_empty.symm
#align set.mem_diff_singleton_empty Set.mem_diff_singleton_empty
theorem subset_insert_iff {s t : Set α} {x : α} :
s ⊆ insert x t ↔ s ⊆ t ∨ (x ∈ s ∧ s \ {x} ⊆ t) := by
rw [← diff_singleton_subset_iff]
by_cases hx : x ∈ s
· rw [and_iff_right hx, or_iff_right_of_imp diff_subset.trans]
rw [diff_singleton_eq_self hx, or_iff_left_of_imp And.right]
theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t :=
sup_eq_sdiff_sup_sdiff_sup_inf
#align set.union_eq_diff_union_diff_union_inter Set.union_eq_diff_union_diff_union_inter
/-! ### Lemmas about pairs -/
--Porting note (#10618): removed `simp` attribute because `simp` can prove it
theorem pair_eq_singleton (a : α) : ({a, a} : Set α) = {a} :=
union_self _
#align set.pair_eq_singleton Set.pair_eq_singleton
theorem pair_comm (a b : α) : ({a, b} : Set α) = {b, a} :=
union_comm _ _
#align set.pair_comm Set.pair_comm
theorem pair_eq_pair_iff {x y z w : α} :
({x, y} : Set α) = {z, w} ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by
simp [subset_antisymm_iff, insert_subset_iff]; aesop
#align set.pair_eq_pair_iff Set.pair_eq_pair_iff
theorem pair_diff_left (hne : a ≠ b) : ({a, b} : Set α) \ {a} = {b} := by
rw [insert_diff_of_mem _ (mem_singleton a), diff_singleton_eq_self (by simpa)]
theorem pair_diff_right (hne : a ≠ b) : ({a, b} : Set α) \ {b} = {a} := by
rw [pair_comm, pair_diff_left hne.symm]
theorem pair_subset_iff : {a, b} ⊆ s ↔ a ∈ s ∧ b ∈ s := by
rw [insert_subset_iff, singleton_subset_iff]
theorem pair_subset (ha : a ∈ s) (hb : b ∈ s) : {a, b} ⊆ s :=
pair_subset_iff.2 ⟨ha,hb⟩
theorem subset_pair_iff : s ⊆ {a, b} ↔ ∀ x ∈ s, x = a ∨ x = b := by
simp [subset_def]
theorem subset_pair_iff_eq {x y : α} : s ⊆ {x, y} ↔ s = ∅ ∨ s = {x} ∨ s = {y} ∨ s = {x, y} := by
refine ⟨?_, by rintro (rfl | rfl | rfl | rfl) <;> simp [pair_subset_iff]⟩
rw [subset_insert_iff, subset_singleton_iff_eq, subset_singleton_iff_eq,
← subset_empty_iff (s := s \ {x}), diff_subset_iff, union_empty, subset_singleton_iff_eq]
have h : x ∈ s → {y} = s \ {x} → s = {x,y} := fun h₁ h₂ ↦ by simp [h₁, h₂]
tauto
theorem Nonempty.subset_pair_iff_eq (hs : s.Nonempty) :
s ⊆ {a, b} ↔ s = {a} ∨ s = {b} ∨ s = {a, b} := by
rw [Set.subset_pair_iff_eq, or_iff_right]; exact hs.ne_empty
/-! ### Symmetric difference -/
section
open scoped symmDiff
theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s :=
Iff.rfl
#align set.mem_symm_diff Set.mem_symmDiff
protected theorem symmDiff_def (s t : Set α) : s ∆ t = s \ t ∪ t \ s :=
rfl
#align set.symm_diff_def Set.symmDiff_def
theorem symmDiff_subset_union : s ∆ t ⊆ s ∪ t :=
@symmDiff_le_sup (Set α) _ _ _
#align set.symm_diff_subset_union Set.symmDiff_subset_union
@[simp]
theorem symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t :=
symmDiff_eq_bot
#align set.symm_diff_eq_empty Set.symmDiff_eq_empty
@[simp]
theorem symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t :=
nonempty_iff_ne_empty.trans symmDiff_eq_empty.not
#align set.symm_diff_nonempty Set.symmDiff_nonempty
theorem inter_symmDiff_distrib_left (s t u : Set α) : s ∩ t ∆ u = (s ∩ t) ∆ (s ∩ u) :=
inf_symmDiff_distrib_left _ _ _
#align set.inter_symm_diff_distrib_left Set.inter_symmDiff_distrib_left
theorem inter_symmDiff_distrib_right (s t u : Set α) : s ∆ t ∩ u = (s ∩ u) ∆ (t ∩ u) :=
inf_symmDiff_distrib_right _ _ _
#align set.inter_symm_diff_distrib_right Set.inter_symmDiff_distrib_right
theorem subset_symmDiff_union_symmDiff_left (h : Disjoint s t) : u ⊆ s ∆ u ∪ t ∆ u :=
h.le_symmDiff_sup_symmDiff_left
#align set.subset_symm_diff_union_symm_diff_left Set.subset_symmDiff_union_symmDiff_left
theorem subset_symmDiff_union_symmDiff_right (h : Disjoint t u) : s ⊆ s ∆ t ∪ s ∆ u :=
h.le_symmDiff_sup_symmDiff_right
#align set.subset_symm_diff_union_symm_diff_right Set.subset_symmDiff_union_symmDiff_right
end
/-! ### Powerset -/
#align set.powerset Set.powerset
theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h
#align set.mem_powerset Set.mem_powerset
theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h
#align set.subset_of_mem_powerset Set.subset_of_mem_powerset
@[simp]
theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s :=
Iff.rfl
#align set.mem_powerset_iff Set.mem_powerset_iff
theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t :=
ext fun _ => subset_inter_iff
#align set.powerset_inter Set.powerset_inter
@[simp]
theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t :=
⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩
#align set.powerset_mono Set.powerset_mono
theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2
#align set.monotone_powerset Set.monotone_powerset
@[simp]
theorem powerset_nonempty : (𝒫 s).Nonempty :=
⟨∅, fun _ h => empty_subset s h⟩
#align set.powerset_nonempty Set.powerset_nonempty
@[simp]
theorem powerset_empty : 𝒫(∅ : Set α) = {∅} :=
ext fun _ => subset_empty_iff
#align set.powerset_empty Set.powerset_empty
@[simp]
theorem powerset_univ : 𝒫(univ : Set α) = univ :=
eq_univ_of_forall subset_univ
#align set.powerset_univ Set.powerset_univ
/-- The powerset of a singleton contains only `∅` and the singleton itself. -/
theorem powerset_singleton (x : α) : 𝒫({x} : Set α) = {∅, {x}} := by
ext y
rw [mem_powerset_iff, subset_singleton_iff_eq, mem_insert_iff, mem_singleton_iff]
#align set.powerset_singleton Set.powerset_singleton
/-! ### Sets defined as an if-then-else -/
theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) :
(x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h := by
split_ifs with hp
· exact ⟨fun hx => ⟨fun _ => hx, fun hnp => (hnp hp).elim⟩, fun hx => hx.1 hp⟩
· exact ⟨fun hx => ⟨fun h => (hp h).elim, fun _ => hx⟩, fun hx => hx.2 hp⟩
theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by
split_ifs <;> simp_all
#align set.mem_dite_univ_right Set.mem_dite_univ_right
@[simp]
theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t Set.univ ↔ p → x ∈ t :=
mem_dite_univ_right p (fun _ => t) x
#align set.mem_ite_univ_right Set.mem_ite_univ_right
theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by
split_ifs <;> simp_all
#align set.mem_dite_univ_left Set.mem_dite_univ_left
@[simp]
theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p Set.univ t ↔ ¬p → x ∈ t :=
mem_dite_univ_left p (fun _ => t) x
#align set.mem_ite_univ_left Set.mem_ite_univ_left
theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false, not_not]
exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩
#align set.mem_dite_empty_right Set.mem_dite_empty_right
@[simp]
theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t ∅ ↔ p ∧ x ∈ t :=
(mem_dite_empty_right p (fun _ => t) x).trans (by simp)
#align set.mem_ite_empty_right Set.mem_ite_empty_right
theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false]
exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩
#align set.mem_dite_empty_left Set.mem_dite_empty_left
@[simp]
theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t :=
(mem_dite_empty_left p (fun _ => t) x).trans (by simp)
#align set.mem_ite_empty_left Set.mem_ite_empty_left
/-! ### If-then-else for sets -/
/-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`.
Defined as `s ∩ t ∪ s' \ t`. -/
protected def ite (t s s' : Set α) : Set α :=
s ∩ t ∪ s' \ t
#align set.ite Set.ite
@[simp]
theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by
rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty]
#align set.ite_inter_self Set.ite_inter_self
@[simp]
theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by
rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq]
#align set.ite_compl Set.ite_compl
@[simp]
theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by
rw [← ite_compl, ite_inter_self]
#align set.ite_inter_compl_self Set.ite_inter_compl_self
@[simp]
theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t :=
ite_inter_compl_self t s s'
#align set.ite_diff_self Set.ite_diff_self
@[simp]
theorem ite_same (t s : Set α) : t.ite s s = s :=
inter_union_diff _ _
#align set.ite_same Set.ite_same
@[simp]
theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite]
#align set.ite_left Set.ite_left
@[simp]
theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite]
#align set.ite_right Set.ite_right
@[simp]
theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite]
#align set.ite_empty Set.ite_empty
@[simp]
theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite]
#align set.ite_univ Set.ite_univ
@[simp]
theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite]
#align set.ite_empty_left Set.ite_empty_left
@[simp]
theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite]
#align set.ite_empty_right Set.ite_empty_right
theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') :
t.ite s₁ s₁' ⊆ t.ite s₂ s₂' :=
union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')
#align set.ite_mono Set.ite_mono
theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' :=
union_subset_union inter_subset_left diff_subset
#align set.ite_subset_union Set.ite_subset_union
theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' :=
ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right
#align set.inter_subset_ite Set.inter_subset_ite
theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) :
t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by
ext x
simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union]
tauto
#align set.ite_inter_inter Set.ite_inter_inter
theorem ite_inter (t s₁ s₂ s : Set α) : t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s := by
rw [ite_inter_inter, ite_same]
#align set.ite_inter Set.ite_inter
theorem ite_inter_of_inter_eq (t : Set α) {s₁ s₂ s : Set α} (h : s₁ ∩ s = s₂ ∩ s) :
t.ite s₁ s₂ ∩ s = s₁ ∩ s := by rw [← ite_inter, ← h, ite_same]
#align set.ite_inter_of_inter_eq Set.ite_inter_of_inter_eq
theorem subset_ite {t s s' u : Set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' := by
simp only [subset_def, ← forall_and]
refine forall_congr' fun x => ?_
by_cases hx : x ∈ t <;> simp [*, Set.ite]
#align set.subset_ite Set.subset_ite
theorem ite_eq_of_subset_left (t : Set α) {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) :
t.ite s₁ s₂ = s₁ ∪ (s₂ \ t) := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_right_of_imp (@h x)]
theorem ite_eq_of_subset_right (t : Set α) {s₁ s₂ : Set α} (h : s₂ ⊆ s₁) :
t.ite s₁ s₂ = (s₁ ∩ t) ∪ s₂ := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_left_of_imp (@h x)]
section Preorder
variable [Preorder α] [Preorder β] {f : α → β}
-- Porting note:
-- If we decide we want `Elem` to semireducible rather than reducible, we will need:
-- instance : Preorder (↑s) := Subtype.instPreorderSubtype _
-- here, along with appropriate lemmas.
theorem monotoneOn_iff_monotone : MonotoneOn f s ↔
Monotone fun a : s => f a := by
simp [Monotone, MonotoneOn]
#align set.monotone_on_iff_monotone Set.monotoneOn_iff_monotone
| Mathlib/Data/Set/Basic.lean | 2,372 | 2,374 | theorem antitoneOn_iff_antitone : AntitoneOn f s ↔
Antitone fun a : s => f a := by |
simp [Antitone, AntitoneOn]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.MvPolynomial.Rename
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
#align_import data.mv_polynomial.variables from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4"
/-!
# Degrees of polynomials
This file establishes many results about the degree of a multivariate polynomial.
The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the
variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a
monomial of $P$.
## Main declarations
* `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets
corresponding to each non-zero monomial in `p`.
For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}`
* `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`.
For example if `p = x⁴y+yz` then `degreeOf y p = 1`.
* `MvPolynomial.totalDegree p : ℕ` :
the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`.
For example if `p = x⁴y+yz` then `totalDegree p = 5`.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v w
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
section Degrees
/-! ### `degrees` -/
/-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
(For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.)
-/
def degrees (p : MvPolynomial σ R) : Multiset σ :=
letI := Classical.decEq σ
p.support.sup fun s : σ →₀ ℕ => toMultiset s
#align mv_polynomial.degrees MvPolynomial.degrees
theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) :
p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl
#align mv_polynomial.degrees_def MvPolynomial.degrees_def
theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by
classical
refine (supDegree_single s a).trans_le ?_
split_ifs
exacts [bot_le, le_rfl]
#align mv_polynomial.degrees_monomial MvPolynomial.degrees_monomial
theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) :
degrees (monomial s a) = toMultiset s := by
classical
exact (supDegree_single s a).trans (if_neg ha)
#align mv_polynomial.degrees_monomial_eq MvPolynomial.degrees_monomial_eq
theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 :=
Multiset.le_zero.1 <| degrees_monomial _ _
set_option linter.uppercaseLean3 false in
#align mv_polynomial.degrees_C MvPolynomial.degrees_C
theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} :=
le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _
set_option linter.uppercaseLean3 false in
#align mv_polynomial.degrees_X' MvPolynomial.degrees_X'
@[simp]
theorem degrees_X [Nontrivial R] (n : σ) : degrees (X n : MvPolynomial σ R) = {n} :=
(degrees_monomial_eq _ (1 : R) one_ne_zero).trans (toMultiset_single _ _)
set_option linter.uppercaseLean3 false in
#align mv_polynomial.degrees_X MvPolynomial.degrees_X
@[simp]
theorem degrees_zero : degrees (0 : MvPolynomial σ R) = 0 := by
rw [← C_0]
exact degrees_C 0
#align mv_polynomial.degrees_zero MvPolynomial.degrees_zero
@[simp]
theorem degrees_one : degrees (1 : MvPolynomial σ R) = 0 :=
degrees_C 1
#align mv_polynomial.degrees_one MvPolynomial.degrees_one
theorem degrees_add [DecidableEq σ] (p q : MvPolynomial σ R) :
(p + q).degrees ≤ p.degrees ⊔ q.degrees := by
simp_rw [degrees_def]; exact supDegree_add_le
#align mv_polynomial.degrees_add MvPolynomial.degrees_add
theorem degrees_sum {ι : Type*} [DecidableEq σ] (s : Finset ι) (f : ι → MvPolynomial σ R) :
(∑ i ∈ s, f i).degrees ≤ s.sup fun i => (f i).degrees := by
simp_rw [degrees_def]; exact supDegree_sum_le
#align mv_polynomial.degrees_sum MvPolynomial.degrees_sum
theorem degrees_mul (p q : MvPolynomial σ R) : (p * q).degrees ≤ p.degrees + q.degrees := by
classical
simp_rw [degrees_def]
exact supDegree_mul_le (map_add _)
#align mv_polynomial.degrees_mul MvPolynomial.degrees_mul
theorem degrees_prod {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) :
(∏ i ∈ s, f i).degrees ≤ ∑ i ∈ s, (f i).degrees := by
classical exact supDegree_prod_le (map_zero _) (map_add _)
#align mv_polynomial.degrees_prod MvPolynomial.degrees_prod
theorem degrees_pow (p : MvPolynomial σ R) (n : ℕ) : (p ^ n).degrees ≤ n • p.degrees := by
simpa using degrees_prod (Finset.range n) fun _ ↦ p
#align mv_polynomial.degrees_pow MvPolynomial.degrees_pow
theorem mem_degrees {p : MvPolynomial σ R} {i : σ} :
i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support := by
classical
simp only [degrees_def, Multiset.mem_sup, ← mem_support_iff, Finsupp.mem_toMultiset, exists_prop]
#align mv_polynomial.mem_degrees MvPolynomial.mem_degrees
theorem le_degrees_add {p q : MvPolynomial σ R} (h : p.degrees.Disjoint q.degrees) :
p.degrees ≤ (p + q).degrees := by
classical
apply Finset.sup_le
intro d hd
rw [Multiset.disjoint_iff_ne] at h
obtain rfl | h0 := eq_or_ne d 0
· rw [toMultiset_zero]; apply Multiset.zero_le
· refine Finset.le_sup_of_le (b := d) ?_ le_rfl
rw [mem_support_iff, coeff_add]
suffices q.coeff d = 0 by rwa [this, add_zero, coeff, ← Finsupp.mem_support_iff]
rw [Ne, ← Finsupp.support_eq_empty, ← Ne, ← Finset.nonempty_iff_ne_empty] at h0
obtain ⟨j, hj⟩ := h0
contrapose! h
rw [mem_support_iff] at hd
refine ⟨j, ?_, j, ?_, rfl⟩
all_goals rw [mem_degrees]; refine ⟨d, ?_, hj⟩; assumption
#align mv_polynomial.le_degrees_add MvPolynomial.le_degrees_add
theorem degrees_add_of_disjoint [DecidableEq σ] {p q : MvPolynomial σ R}
(h : Multiset.Disjoint p.degrees q.degrees) : (p + q).degrees = p.degrees ∪ q.degrees := by
apply le_antisymm
· apply degrees_add
· apply Multiset.union_le
· apply le_degrees_add h
· rw [add_comm]
apply le_degrees_add h.symm
#align mv_polynomial.degrees_add_of_disjoint MvPolynomial.degrees_add_of_disjoint
theorem degrees_map [CommSemiring S] (p : MvPolynomial σ R) (f : R →+* S) :
(map f p).degrees ⊆ p.degrees := by
classical
dsimp only [degrees]
apply Multiset.subset_of_le
apply Finset.sup_mono
apply MvPolynomial.support_map_subset
#align mv_polynomial.degrees_map MvPolynomial.degrees_map
theorem degrees_rename (f : σ → τ) (φ : MvPolynomial σ R) :
(rename f φ).degrees ⊆ φ.degrees.map f := by
classical
intro i
rw [mem_degrees, Multiset.mem_map]
rintro ⟨d, hd, hi⟩
obtain ⟨x, rfl, hx⟩ := coeff_rename_ne_zero _ _ _ hd
simp only [Finsupp.mapDomain, Finsupp.mem_support_iff] at hi
rw [sum_apply, Finsupp.sum] at hi
contrapose! hi
rw [Finset.sum_eq_zero]
intro j hj
simp only [exists_prop, mem_degrees] at hi
specialize hi j ⟨x, hx, hj⟩
rw [Finsupp.single_apply, if_neg hi]
#align mv_polynomial.degrees_rename MvPolynomial.degrees_rename
theorem degrees_map_of_injective [CommSemiring S] (p : MvPolynomial σ R) {f : R →+* S}
(hf : Injective f) : (map f p).degrees = p.degrees := by
simp only [degrees, MvPolynomial.support_map_of_injective _ hf]
#align mv_polynomial.degrees_map_of_injective MvPolynomial.degrees_map_of_injective
theorem degrees_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} (h : Function.Injective f) :
degrees (rename f p) = (degrees p).map f := by
classical
simp only [degrees, Multiset.map_finset_sup p.support Finsupp.toMultiset f h,
support_rename_of_injective h, Finset.sup_image]
refine Finset.sup_congr rfl fun x _ => ?_
exact (Finsupp.toMultiset_map _ _).symm
#align mv_polynomial.degrees_rename_of_injective MvPolynomial.degrees_rename_of_injective
end Degrees
section DegreeOf
/-! ### `degreeOf` -/
/-- `degreeOf n p` gives the highest power of X_n that appears in `p` -/
def degreeOf (n : σ) (p : MvPolynomial σ R) : ℕ :=
letI := Classical.decEq σ
p.degrees.count n
#align mv_polynomial.degree_of MvPolynomial.degreeOf
theorem degreeOf_def [DecidableEq σ] (n : σ) (p : MvPolynomial σ R) :
p.degreeOf n = p.degrees.count n := by rw [degreeOf]; convert rfl
#align mv_polynomial.degree_of_def MvPolynomial.degreeOf_def
theorem degreeOf_eq_sup (n : σ) (f : MvPolynomial σ R) :
degreeOf n f = f.support.sup fun m => m n := by
classical
rw [degreeOf_def, degrees, Multiset.count_finset_sup]
congr
ext
simp
#align mv_polynomial.degree_of_eq_sup MvPolynomial.degreeOf_eq_sup
theorem degreeOf_lt_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} (h : 0 < d) :
degreeOf n f < d ↔ ∀ m : σ →₀ ℕ, m ∈ f.support → m n < d := by
rwa [degreeOf_eq_sup, Finset.sup_lt_iff]
#align mv_polynomial.degree_of_lt_iff MvPolynomial.degreeOf_lt_iff
lemma degreeOf_le_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} :
degreeOf n f ≤ d ↔ ∀ m ∈ support f, m n ≤ d := by
rw [degreeOf_eq_sup, Finset.sup_le_iff]
@[simp]
theorem degreeOf_zero (n : σ) : degreeOf n (0 : MvPolynomial σ R) = 0 := by
classical simp only [degreeOf_def, degrees_zero, Multiset.count_zero]
#align mv_polynomial.degree_of_zero MvPolynomial.degreeOf_zero
@[simp]
theorem degreeOf_C (a : R) (x : σ) : degreeOf x (C a : MvPolynomial σ R) = 0 := by
classical simp [degreeOf_def, degrees_C]
set_option linter.uppercaseLean3 false in
#align mv_polynomial.degree_of_C MvPolynomial.degreeOf_C
theorem degreeOf_X [DecidableEq σ] (i j : σ) [Nontrivial R] :
degreeOf i (X j : MvPolynomial σ R) = if i = j then 1 else 0 := by
classical
by_cases c : i = j
· simp only [c, if_true, eq_self_iff_true, degreeOf_def, degrees_X, Multiset.count_singleton]
simp [c, if_false, degreeOf_def, degrees_X]
set_option linter.uppercaseLean3 false in
#align mv_polynomial.degree_of_X MvPolynomial.degreeOf_X
theorem degreeOf_add_le (n : σ) (f g : MvPolynomial σ R) :
degreeOf n (f + g) ≤ max (degreeOf n f) (degreeOf n g) := by
simp_rw [degreeOf_eq_sup]; exact supDegree_add_le
#align mv_polynomial.degree_of_add_le MvPolynomial.degreeOf_add_le
theorem monomial_le_degreeOf (i : σ) {f : MvPolynomial σ R} {m : σ →₀ ℕ} (h_m : m ∈ f.support) :
m i ≤ degreeOf i f := by
rw [degreeOf_eq_sup i]
apply Finset.le_sup h_m
#align mv_polynomial.monomial_le_degree_of MvPolynomial.monomial_le_degreeOf
-- TODO we can prove equality here if R is a domain
theorem degreeOf_mul_le (i : σ) (f g : MvPolynomial σ R) :
degreeOf i (f * g) ≤ degreeOf i f + degreeOf i g := by
classical
repeat' rw [degreeOf]
convert Multiset.count_le_of_le i (degrees_mul f g)
rw [Multiset.count_add]
#align mv_polynomial.degree_of_mul_le MvPolynomial.degreeOf_mul_le
theorem degreeOf_mul_X_ne {i j : σ} (f : MvPolynomial σ R) (h : i ≠ j) :
degreeOf i (f * X j) = degreeOf i f := by
classical
repeat' rw [degreeOf_eq_sup (R := R) i]
rw [support_mul_X]
simp only [Finset.sup_map]
congr
ext
simp only [Finsupp.single, Nat.one_ne_zero, add_right_eq_self, addRightEmbedding_apply, coe_mk,
Pi.add_apply, comp_apply, ite_eq_right_iff, Finsupp.coe_add, Pi.single_eq_of_ne h]
set_option linter.uppercaseLean3 false in
#align mv_polynomial.degree_of_mul_X_ne MvPolynomial.degreeOf_mul_X_ne
-- TODO in the following we have equality iff f ≠ 0
theorem degreeOf_mul_X_eq (j : σ) (f : MvPolynomial σ R) :
degreeOf j (f * X j) ≤ degreeOf j f + 1 := by
classical
repeat' rw [degreeOf]
apply (Multiset.count_le_of_le j (degrees_mul f (X j))).trans
simp only [Multiset.count_add, add_le_add_iff_left]
convert Multiset.count_le_of_le j (degrees_X' (R := R) j)
rw [Multiset.count_singleton_self]
set_option linter.uppercaseLean3 false in
#align mv_polynomial.degree_of_mul_X_eq MvPolynomial.degreeOf_mul_X_eq
| Mathlib/Algebra/MvPolynomial/Degrees.lean | 328 | 332 | theorem degreeOf_C_mul_le (p : MvPolynomial σ R) (i : σ) (c : R) :
(C c * p).degreeOf i ≤ p.degreeOf i := by |
unfold degreeOf
convert Multiset.count_le_of_le i <| degrees_mul (C c) p
simp [degrees_C]
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Set.Subsingleton
#align_import combinatorics.composition from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# Compositions
A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum
of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into
non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks.
This notion is closely related to that of a partition of `n`, but in a composition of `n` the
order of the `iⱼ`s matters.
We implement two different structures covering these two viewpoints on compositions. The first
one, made of a list of positive integers summing to `n`, is the main one and is called
`Composition n`. The second one is useful for combinatorial arguments (for instance to show that
the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`
containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost
points of each block. The main API is built on `Composition n`, and we provide an equivalence
between the two types.
## Main functions
* `c : Composition n` is a structure, made of a list of integers which are all positive and
add up to `n`.
* `composition_card` states that the cardinality of `Composition n` is exactly
`2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which
is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is
nat subtraction).
Let `c : Composition n` be a composition of `n`. Then
* `c.blocks` is the list of blocks in `c`.
* `c.length` is the number of blocks in the composition.
* `c.blocks_fun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on
`Fin c.length`. This is the main object when using compositions to understand the composition of
analytic functions.
* `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.;
* `c.embedding i : Fin (c.blocks_fun i) → Fin n` is the increasing embedding of the `i`-th block in
`Fin n`;
* `c.index j`, for `j : Fin n`, is the index of the block containing `j`.
* `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.
* `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.
Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition
of `n`.
* `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the
blocks of `c`.
* `join_splitWrtComposition` states that splitting a list and then joining it gives back the
original list.
* `joinSplitWrtComposition_join` states that joining a list of lists, and then splitting it back
according to the right composition, gives back the original list of lists.
We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`.
`c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries`
and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not
make sense in the edge case `n = 0`, while the previous description works in all cases).
The elements of this set (other than `n`) correspond to leftmost points of blocks.
Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We
only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able
to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv
between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`
from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that
`CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)`
(see `compositionAsSet_card` and `composition_card`).
## Implementation details
The main motivation for this structure and its API is in the construction of the composition of
formal multilinear series, and the proof that the composition of analytic functions is analytic.
The representation of a composition as a list is very handy as lists are very flexible and already
have a well-developed API.
## Tags
Composition, partition
## References
<https://en.wikipedia.org/wiki/Composition_(combinatorics)>
-/
open List
variable {n : ℕ}
/-- A composition of `n` is a list of positive integers summing to `n`. -/
@[ext]
structure Composition (n : ℕ) where
/-- List of positive integers summing to `n`-/
blocks : List ℕ
/-- Proof of positivity for `blocks`-/
blocks_pos : ∀ {i}, i ∈ blocks → 0 < i
/-- Proof that `blocks` sums to `n`-/
blocks_sum : blocks.sum = n
#align composition Composition
/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of
consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding
a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and
get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure
`CompositionAsSet n`. -/
@[ext]
structure CompositionAsSet (n : ℕ) where
/-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}`-/
boundaries : Finset (Fin n.succ)
/-- Proof that `0` is a member of `boundaries`-/
zero_mem : (0 : Fin n.succ) ∈ boundaries
/-- Last element of the composition-/
getLast_mem : Fin.last n ∈ boundaries
#align composition_as_set CompositionAsSet
instance {n : ℕ} : Inhabited (CompositionAsSet n) :=
⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩
/-!
### Compositions
A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of
positive integers.
-/
namespace Composition
variable (c : Composition n)
instance (n : ℕ) : ToString (Composition n) :=
⟨fun c => toString c.blocks⟩
/-- The length of a composition, i.e., the number of blocks in the composition. -/
abbrev length : ℕ :=
c.blocks.length
#align composition.length Composition.length
theorem blocks_length : c.blocks.length = c.length :=
rfl
#align composition.blocks_length Composition.blocks_length
/-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic
functions using compositions, this is the main player. -/
def blocksFun : Fin c.length → ℕ := c.blocks.get
#align composition.blocks_fun Composition.blocksFun
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
#align composition.of_fn_blocks_fun Composition.ofFn_blocksFun
theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]
#align composition.sum_blocks_fun Composition.sum_blocksFun
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _ _
#align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks
@[simp]
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h
#align composition.one_le_blocks Composition.one_le_blocks
@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks.get ⟨i, h⟩ :=
c.one_le_blocks (get_mem (blocks c) i h)
#align composition.one_le_blocks' Composition.one_le_blocks'
@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks.get ⟨i, h⟩ :=
c.one_le_blocks' h
#align composition.blocks_pos' Composition.blocks_pos'
theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
#align composition.one_le_blocks_fun Composition.one_le_blocksFun
theorem length_le : c.length ≤ n := by
conv_rhs => rw [← c.blocks_sum]
exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi
#align composition.length_le Composition.length_le
theorem length_pos_of_pos (h : 0 < n) : 0 < c.length := by
apply length_pos_of_sum_pos
convert h
exact c.blocks_sum
#align composition.length_pos_of_pos Composition.length_pos_of_pos
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : ℕ) : ℕ :=
(c.blocks.take i).sum
#align composition.size_up_to Composition.sizeUpTo
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
#align composition.size_up_to_zero Composition.sizeUpTo_zero
theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_all_of_le h
#align composition.size_up_to_of_length_le Composition.sizeUpTo_ofLength_le
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
#align composition.size_up_to_length Composition.sizeUpTo_length
theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by
conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i]
exact Nat.le_add_right _ _
#align composition.size_up_to_le Composition.sizeUpTo_le
theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks.get ⟨i, h⟩ := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
#align composition.size_up_to_succ Composition.sizeUpTo_succ
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
#align composition.size_up_to_succ' Composition.sizeUpTo_succ'
theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
#align composition.size_up_to_strict_mono Composition.sizeUpTo_strict_mono
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
#align composition.monotone_size_up_to Composition.monotone_sizeUpTo
/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundary : Fin (c.length + 1) ↪o Fin (n + 1) :=
(OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <|
Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi
#align composition.boundary Composition.boundary
@[simp]
theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]
#align composition.boundary_zero Composition.boundary_zero
@[simp]
theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by
simp [boundary, Fin.ext_iff]
#align composition.boundary_last Composition.boundary_last
/-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundaries : Finset (Fin (n + 1)) :=
Finset.univ.map c.boundary.toEmbedding
#align composition.boundaries Composition.boundaries
theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]
#align composition.card_boundaries_eq_succ_length Composition.card_boundaries_eq_succ_length
/-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost
point of each block, and adding a virtual point at the right of the last block. -/
def toCompositionAsSet : CompositionAsSet n where
boundaries := c.boundaries
zero_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨0, And.intro True.intro rfl⟩
getLast_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩
#align composition.to_composition_as_set Composition.toCompositionAsSet
/-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is
exactly `c.boundary`. -/
theorem orderEmbOfFin_boundaries :
c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by
refine (Finset.orderEmbOfFin_unique' _ ?_).symm
exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _)
#align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries
/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocks_fun i)`) into
`Fin n` at the relevant position. -/
def embedding (i : Fin c.length) : Fin (c.blocksFun i) ↪o Fin n :=
(Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <|
calc
c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ _).symm
_ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2
_ = n := c.sizeUpTo_length
#align composition.embedding Composition.embedding
@[simp]
theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.embedding i j : ℕ) = c.sizeUpTo i + j :=
rfl
#align composition.coe_embedding Composition.coe_embedding
/-- `index_exists` asserts there is some `i` with `j < c.size_up_to (i+1)`.
In the next definition `index` we use `Nat.find` to produce the minimal such index.
-/
theorem index_exists {j : ℕ} (h : j < n) : ∃ i : ℕ, j < c.sizeUpTo (i + 1) ∧ i < c.length := by
have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h
have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos
have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this
refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩
have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos
simp [this, h]
#align composition.index_exists Composition.index_exists
/-- `c.index j` is the index of the block in the composition `c` containing `j`. -/
def index (j : Fin n) : Fin c.length :=
⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩
#align composition.index Composition.index
theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ :=
(Nat.find_spec (c.index_exists j.2)).1
#align composition.lt_size_up_to_index_succ Composition.lt_sizeUpTo_index_succ
theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≤ j := by
by_contra H
set i := c.index j
push_neg at H
have i_pos : (0 : ℕ) < i := by
by_contra! i_pos
revert H
simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero]
let i₁ := (i : ℕ).pred
have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos)
have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos
have := Nat.find_min (c.index_exists j.2) i₁_lt_i
simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this
exact Nat.lt_le_asymm H this
#align composition.size_up_to_index_le Composition.sizeUpTo_index_le
/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with
`Fin (c.blocks_fun (c.index j))` through the canonical increasing bijection. -/
def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) :=
⟨j - c.sizeUpTo (c.index j), by
rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ']
· exact lt_sizeUpTo_index_succ _ _
· exact sizeUpTo_index_le _ _⟩
#align composition.inv_embedding Composition.invEmbedding
@[simp]
theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) :=
rfl
#align composition.coe_inv_embedding Composition.coe_invEmbedding
theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by
rw [Fin.ext_iff]
apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j)
#align composition.embedding_comp_inv Composition.embedding_comp_inv
theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≤ j ∧ (j : ℕ) < c.sizeUpTo (i : ℕ).succ := by
constructor
· intro h
rcases Set.mem_range.2 h with ⟨k, hk⟩
rw [Fin.ext_iff] at hk
dsimp at hk
rw [← hk]
simp [sizeUpTo_succ', k.is_lt]
· intro h
apply Set.mem_range.2
refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩
· rw [tsub_lt_iff_left, ← sizeUpTo_succ']
· exact h.2
· exact h.1
· rw [Fin.ext_iff]
exact add_tsub_cancel_of_le h.1
#align composition.mem_range_embedding_iff Composition.mem_range_embedding_iff
/-- The embeddings of different blocks of a composition are disjoint. -/
theorem disjoint_range {i₁ i₂ : Fin c.length} (h : i₁ ≠ i₂) :
Disjoint (Set.range (c.embedding i₁)) (Set.range (c.embedding i₂)) := by
classical
wlog h' : i₁ < i₂
· exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm
by_contra d
obtain ⟨x, hx₁, hx₂⟩ :
∃ x : Fin n, x ∈ Set.range (c.embedding i₁) ∧ x ∈ Set.range (c.embedding i₂) :=
Set.not_disjoint_iff.1 d
have A : (i₁ : ℕ).succ ≤ i₂ := Nat.succ_le_of_lt h'
apply lt_irrefl (x : ℕ)
calc
(x : ℕ) < c.sizeUpTo (i₁ : ℕ).succ := (c.mem_range_embedding_iff.1 hx₁).2
_ ≤ c.sizeUpTo (i₂ : ℕ) := monotone_sum_take _ A
_ ≤ x := (c.mem_range_embedding_iff.1 hx₂).1
#align composition.disjoint_range Composition.disjoint_range
theorem mem_range_embedding (j : Fin n) : j ∈ Set.range (c.embedding (c.index j)) := by
have : c.embedding (c.index j) (c.invEmbedding j) ∈ Set.range (c.embedding (c.index j)) :=
Set.mem_range_self _
rwa [c.embedding_comp_inv j] at this
#align composition.mem_range_embedding Composition.mem_range_embedding
theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ i = c.index j := by
constructor
· rw [← not_imp_not]
intro h
exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j)
· intro h
rw [h]
exact c.mem_range_embedding j
#align composition.mem_range_embedding_iff' Composition.mem_range_embedding_iff'
theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
c.index (c.embedding i j) = i := by
symm
rw [← mem_range_embedding_iff']
apply Set.mem_range_self
#align composition.index_embedding Composition.index_embedding
theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.invEmbedding (c.embedding i j) : ℕ) = j := by
simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left]
#align composition.inv_embedding_comp Composition.invEmbedding_comp
/-- Equivalence between the disjoint union of the blocks (each of them seen as
`Fin (c.blocks_fun i)`) with `Fin n`. -/
def blocksFinEquiv : (Σi : Fin c.length, Fin (c.blocksFun i)) ≃ Fin n where
toFun x := c.embedding x.1 x.2
invFun j := ⟨c.index j, c.invEmbedding j⟩
left_inv x := by
rcases x with ⟨i, y⟩
dsimp
congr; · exact c.index_embedding _ _
rw [Fin.heq_ext_iff]
· exact c.invEmbedding_comp _ _
· rw [c.index_embedding]
right_inv j := c.embedding_comp_inv j
#align composition.blocks_fin_equiv Composition.blocksFinEquiv
theorem blocksFun_congr {n₁ n₂ : ℕ} (c₁ : Composition n₁) (c₂ : Composition n₂) (i₁ : Fin c₁.length)
(i₂ : Fin c₂.length) (hn : n₁ = n₂) (hc : c₁.blocks = c₂.blocks) (hi : (i₁ : ℕ) = i₂) :
c₁.blocksFun i₁ = c₂.blocksFun i₂ := by
cases hn
rw [← Composition.ext_iff] at hc
cases hc
congr
rwa [Fin.ext_iff]
#align composition.blocks_fun_congr Composition.blocksFun_congr
/-- Two compositions (possibly of different integers) coincide if and only if they have the
same sequence of blocks. -/
theorem sigma_eq_iff_blocks_eq {c : Σn, Composition n} {c' : Σn, Composition n} :
c = c' ↔ c.2.blocks = c'.2.blocks := by
refine ⟨fun H => by rw [H], fun H => ?_⟩
rcases c with ⟨n, c⟩
rcases c' with ⟨n', c'⟩
have : n = n' := by rw [← c.blocks_sum, ← c'.blocks_sum, H]
induction this
congr
ext1
exact H
#align composition.sigma_eq_iff_blocks_eq Composition.sigma_eq_iff_blocks_eq
/-! ### The composition `Composition.ones` -/
/-- The composition made of blocks all of size `1`. -/
def ones (n : ℕ) : Composition n :=
⟨replicate n (1 : ℕ), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp⟩
#align composition.ones Composition.ones
instance {n : ℕ} : Inhabited (Composition n) :=
⟨Composition.ones n⟩
@[simp]
theorem ones_length (n : ℕ) : (ones n).length = n :=
List.length_replicate n 1
#align composition.ones_length Composition.ones_length
@[simp]
theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) :=
rfl
#align composition.ones_blocks Composition.ones_blocks
@[simp]
theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by
simp only [blocksFun, ones, blocks, i.2, List.get_replicate]
#align composition.ones_blocks_fun Composition.ones_blocksFun
@[simp]
| Mathlib/Combinatorics/Enumerative/Composition.lean | 494 | 495 | theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by |
simp [sizeUpTo, ones_blocks, take_replicate]
|
/-
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.Basic
import Mathlib.RingTheory.Ideal.QuotientOperations
#align_import ring_theory.derivation.to_square_zero from "leanprover-community/mathlib"@"b608348ffaeb7f557f2fd46876037abafd326ff3"
/-!
# Results
- `derivationToSquareZeroOfLift`: The `R`-derivations from `A` into a square-zero ideal `I`
of `B` corresponds to the lifts `A →ₐ[R] B` of the map `A →ₐ[R] B ⧸ I`.
-/
section ToSquareZero
universe u v w
variable {R : Type u} {A : Type v} {B : Type w} [CommSemiring R] [CommSemiring A] [CommRing B]
variable [Algebra R A] [Algebra R B] (I : Ideal B) (hI : I ^ 2 = ⊥)
/-- If `f₁ f₂ : A →ₐ[R] B` are two lifts of the same `A →ₐ[R] B ⧸ I`,
we may define a map `f₁ - f₂ : A →ₗ[R] I`. -/
def diffToIdealOfQuotientCompEq (f₁ f₂ : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) : A →ₗ[R] I :=
LinearMap.codRestrict (I.restrictScalars _) (f₁.toLinearMap - f₂.toLinearMap) (by
intro x
change f₁ x - f₂ x ∈ I
rw [← Ideal.Quotient.eq, ← Ideal.Quotient.mkₐ_eq_mk R, ← AlgHom.comp_apply, e]
rfl)
#align diff_to_ideal_of_quotient_comp_eq diffToIdealOfQuotientCompEq
@[simp]
theorem diffToIdealOfQuotientCompEq_apply (f₁ f₂ : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) (x : A) :
((diffToIdealOfQuotientCompEq I f₁ f₂ e) x : B) = f₁ x - f₂ x :=
rfl
#align diff_to_ideal_of_quotient_comp_eq_apply diffToIdealOfQuotientCompEq_apply
variable [Algebra A B] [IsScalarTower R A B]
/-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each lift `A →ₐ[R] B`
of the canonical map `A →ₐ[R] B ⧸ I` corresponds to an `R`-derivation from `A` to `I`. -/
def derivationToSquareZeroOfLift (f : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) :
Derivation R A I := by
refine
{ diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) ?_ with
map_one_eq_zero' := ?_
leibniz' := ?_ }
· rw [e]; ext; rfl
· ext; change f 1 - algebraMap A B 1 = 0; rw [map_one, map_one, sub_self]
· intro x y
let F := diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) (by rw [e]; ext; rfl)
have : (f x - algebraMap A B x) * (f y - algebraMap A B y) = 0 := by
rw [← Ideal.mem_bot, ← hI, pow_two]
convert Ideal.mul_mem_mul (F x).2 (F y).2 using 1
ext
dsimp only [Submodule.coe_add, Submodule.coe_mk, LinearMap.coe_mk,
diffToIdealOfQuotientCompEq_apply, Submodule.coe_smul_of_tower, IsScalarTower.coe_toAlgHom',
LinearMap.toFun_eq_coe]
simp only [map_mul, sub_mul, mul_sub, Algebra.smul_def] at this ⊢
rw [sub_eq_iff_eq_add, sub_eq_iff_eq_add] at this
simp only [LinearMap.coe_toAddHom, diffToIdealOfQuotientCompEq_apply, map_mul, this,
IsScalarTower.coe_toAlgHom']
ring
#align derivation_to_square_zero_of_lift derivationToSquareZeroOfLift
theorem derivationToSquareZeroOfLift_apply (f : A →ₐ[R] B)
(e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) (x : A) :
(derivationToSquareZeroOfLift I hI f e x : B) = f x - algebraMap A B x :=
rfl
#align derivation_to_square_zero_of_lift_apply derivationToSquareZeroOfLift_apply
/-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each `R`-derivation
from `A` to `I` corresponds to a lift `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I`. -/
@[simps (config := .lemmasOnly)]
def liftOfDerivationToSquareZero (f : Derivation R A I) : A →ₐ[R] B :=
{ ((I.restrictScalars R).subtype.comp f.toLinearMap + (IsScalarTower.toAlgHom R A B).toLinearMap :
A →ₗ[R] B) with
toFun := fun x => f x + algebraMap A B x
map_one' := by
dsimp
-- Note: added the `(algebraMap _ _)` hint because otherwise it would match `f 1`
rw [map_one (algebraMap _ _), f.map_one_eq_zero, Submodule.coe_zero, zero_add]
map_mul' := fun x y => by
have : (f x : B) * f y = 0 := by
rw [← Ideal.mem_bot, ← hI, pow_two]
convert Ideal.mul_mem_mul (f x).2 (f y).2 using 1
simp only [map_mul, f.leibniz, add_mul, mul_add, Submodule.coe_add,
Submodule.coe_smul_of_tower, Algebra.smul_def, this]
ring
commutes' := fun r => by
simp only [Derivation.map_algebraMap, eq_self_iff_true, zero_add, Submodule.coe_zero, ←
IsScalarTower.algebraMap_apply R A B r]
map_zero' := ((I.restrictScalars R).subtype.comp f.toLinearMap +
(IsScalarTower.toAlgHom R A B).toLinearMap).map_zero }
#align lift_of_derivation_to_square_zero liftOfDerivationToSquareZero
-- @[simp] -- Porting note: simp normal form is `liftOfDerivationToSquareZero_mk_apply'`
theorem liftOfDerivationToSquareZero_mk_apply (d : Derivation R A I) (x : A) :
Ideal.Quotient.mk I (liftOfDerivationToSquareZero I hI d x) = algebraMap A (B ⧸ I) x := by
rw [liftOfDerivationToSquareZero_apply, map_add, Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop,
zero_add]
rfl
#align lift_of_derivation_to_square_zero_mk_apply liftOfDerivationToSquareZero_mk_apply
@[simp]
| Mathlib/RingTheory/Derivation/ToSquareZero.lean | 114 | 116 | theorem liftOfDerivationToSquareZero_mk_apply' (d : Derivation R A I) (x : A) :
(Ideal.Quotient.mk I) (d x) + (algebraMap A (B ⧸ I)) x = algebraMap A (B ⧸ I) x := by |
simp only [Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop, zero_add]
|
/-
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, Johannes Hölzl
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.RelIso.Basic
#align_import order.ord_continuous from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432"
/-!
# Order continuity
We say that a function is *left order continuous* if it sends all least upper bounds
to least upper bounds. The order dual notion is called *right order continuity*.
For monotone functions `ℝ → ℝ` these notions correspond to the usual left and right continuity.
We prove some basic lemmas (`map_sup`, `map_sSup` etc) and prove that a `RelIso` is both left
and right order continuous.
-/
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
open Function OrderDual Set
/-!
### Definitions
-/
/-- A function `f` between preorders is left order continuous if it preserves all suprema. We
define it using `IsLUB` instead of `sSup` so that the proof works both for complete lattices and
conditionally complete lattices. -/
def LeftOrdContinuous [Preorder α] [Preorder β] (f : α → β) :=
∀ ⦃s : Set α⦄ ⦃x⦄, IsLUB s x → IsLUB (f '' s) (f x)
#align left_ord_continuous LeftOrdContinuous
/-- A function `f` between preorders is right order continuous if it preserves all infima. We
define it using `IsGLB` instead of `sInf` so that the proof works both for complete lattices and
conditionally complete lattices. -/
def RightOrdContinuous [Preorder α] [Preorder β] (f : α → β) :=
∀ ⦃s : Set α⦄ ⦃x⦄, IsGLB s x → IsGLB (f '' s) (f x)
#align right_ord_continuous RightOrdContinuous
namespace LeftOrdContinuous
section Preorder
variable (α) [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β}
protected theorem id : LeftOrdContinuous (id : α → α) := fun s x h => by
simpa only [image_id] using h
#align left_ord_continuous.id LeftOrdContinuous.id
variable {α}
-- Porting note: not sure what is the correct name for this
protected theorem order_dual : LeftOrdContinuous f → RightOrdContinuous (toDual ∘ f ∘ ofDual) :=
id
#align left_ord_continuous.order_dual LeftOrdContinuous.order_dual
theorem map_isGreatest (hf : LeftOrdContinuous f) {s : Set α} {x : α} (h : IsGreatest s x) :
IsGreatest (f '' s) (f x) :=
⟨mem_image_of_mem f h.1, (hf h.isLUB).1⟩
#align left_ord_continuous.map_is_greatest LeftOrdContinuous.map_isGreatest
theorem mono (hf : LeftOrdContinuous f) : Monotone f := fun a₁ a₂ h =>
have : IsGreatest {a₁, a₂} a₂ := ⟨Or.inr rfl, by simp [*]⟩
(hf.map_isGreatest this).2 <| mem_image_of_mem _ (Or.inl rfl)
#align left_ord_continuous.mono LeftOrdContinuous.mono
theorem comp (hg : LeftOrdContinuous g) (hf : LeftOrdContinuous f) : LeftOrdContinuous (g ∘ f) :=
fun s x h => by simpa only [image_image] using hg (hf h)
#align left_ord_continuous.comp LeftOrdContinuous.comp
-- Porting note: how to do this in non-tactic mode?
protected theorem iterate {f : α → α} (hf : LeftOrdContinuous f) (n : ℕ) :
LeftOrdContinuous f^[n] := by
induction n with
| zero => exact LeftOrdContinuous.id α
| succ n ihn => exact ihn.comp hf
#align left_ord_continuous.iterate LeftOrdContinuous.iterate
end Preorder
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β] {f : α → β}
theorem map_sup (hf : LeftOrdContinuous f) (x y : α) : f (x ⊔ y) = f x ⊔ f y :=
(hf isLUB_pair).unique <| by simp only [image_pair, isLUB_pair]
#align left_ord_continuous.map_sup LeftOrdContinuous.map_sup
theorem le_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x ≤ f y ↔ x ≤ y := by
simp only [← sup_eq_right, ← hf.map_sup, h.eq_iff]
#align left_ord_continuous.le_iff LeftOrdContinuous.le_iff
theorem lt_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x < f y ↔ x < y := by
simp only [lt_iff_le_not_le, hf.le_iff h]
#align left_ord_continuous.lt_iff LeftOrdContinuous.lt_iff
variable (f)
/-- Convert an injective left order continuous function to an order embedding. -/
def toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) : α ↪o β :=
⟨⟨f, h⟩, hf.le_iff h⟩
#align left_ord_continuous.to_order_embedding LeftOrdContinuous.toOrderEmbedding
variable {f}
@[simp]
theorem coe_toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) :
⇑(hf.toOrderEmbedding f h) = f :=
rfl
#align left_ord_continuous.coe_to_order_embedding LeftOrdContinuous.coe_toOrderEmbedding
end SemilatticeSup
section CompleteLattice
variable [CompleteLattice α] [CompleteLattice β] {f : α → β}
theorem map_sSup' (hf : LeftOrdContinuous f) (s : Set α) : f (sSup s) = sSup (f '' s) :=
(hf <| isLUB_sSup s).sSup_eq.symm
#align left_ord_continuous.map_Sup' LeftOrdContinuous.map_sSup'
theorem map_sSup (hf : LeftOrdContinuous f) (s : Set α) : f (sSup s) = ⨆ x ∈ s, f x := by
rw [hf.map_sSup', sSup_image]
#align left_ord_continuous.map_Sup LeftOrdContinuous.map_sSup
theorem map_iSup (hf : LeftOrdContinuous f) (g : ι → α) : f (⨆ i, g i) = ⨆ i, f (g i) := by
simp only [iSup, hf.map_sSup', ← range_comp]
rfl
#align left_ord_continuous.map_supr LeftOrdContinuous.map_iSup
end CompleteLattice
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [Nonempty ι] {f : α → β}
theorem map_csSup (hf : LeftOrdContinuous f) {s : Set α} (sne : s.Nonempty) (sbdd : BddAbove s) :
f (sSup s) = sSup (f '' s) :=
((hf <| isLUB_csSup sne sbdd).csSup_eq <| sne.image f).symm
#align left_ord_continuous.map_cSup LeftOrdContinuous.map_csSup
| Mathlib/Order/OrdContinuous.lean | 151 | 154 | theorem map_ciSup (hf : LeftOrdContinuous f) {g : ι → α} (hg : BddAbove (range g)) :
f (⨆ i, g i) = ⨆ i, f (g i) := by |
simp only [iSup, hf.map_csSup (range_nonempty _) hg, ← range_comp]
rfl
|
/-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Batteries.Data.Rat.Basic
import Batteries.Tactic.SeqFocus
/-! # Additional lemmas about the Rational Numbers -/
namespace Rat
theorem ext : {p q : Rat} → p.num = q.num → p.den = q.den → p = q
| ⟨_,_,_,_⟩, ⟨_,_,_,_⟩, rfl, rfl => rfl
@[simp] theorem mk_den_one {r : Int} :
⟨r, 1, Nat.one_ne_zero, (Nat.coprime_one_right _)⟩ = (r : Rat) := rfl
@[simp] theorem zero_num : (0 : Rat).num = 0 := rfl
@[simp] theorem zero_den : (0 : Rat).den = 1 := rfl
@[simp] theorem one_num : (1 : Rat).num = 1 := rfl
@[simp] theorem one_den : (1 : Rat).den = 1 := rfl
@[simp] theorem maybeNormalize_eq {num den g} (den_nz reduced) :
maybeNormalize num den g den_nz reduced =
{ num := num.div g, den := den / g, den_nz, reduced } := by
unfold maybeNormalize; split
· subst g; simp
· rfl
theorem normalize.reduced' {num : Int} {den g : Nat} (den_nz : den ≠ 0)
(e : g = num.natAbs.gcd den) : (num / g).natAbs.Coprime (den / g) := by
rw [← Int.div_eq_ediv_of_dvd (e ▸ Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))]
exact normalize.reduced den_nz e
theorem normalize_eq {num den} (den_nz) : normalize num den den_nz =
{ num := num / num.natAbs.gcd den
den := den / num.natAbs.gcd den
den_nz := normalize.den_nz den_nz rfl
reduced := normalize.reduced' den_nz rfl } := by
simp only [normalize, maybeNormalize_eq,
Int.div_eq_ediv_of_dvd (Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))]
@[simp] theorem normalize_zero (nz) : normalize 0 d nz = 0 := by
simp [normalize, Int.zero_div, Int.natAbs_zero, Nat.div_self (Nat.pos_of_ne_zero nz)]; rfl
theorem mk_eq_normalize (num den nz c) : ⟨num, den, nz, c⟩ = normalize num den nz := by
simp [normalize_eq, c.gcd_eq_one]
theorem normalize_self (r : Rat) : normalize r.num r.den r.den_nz = r := (mk_eq_normalize ..).symm
theorem normalize_mul_left {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) :
normalize (↑a * n) (a * d) (Nat.mul_ne_zero a0 d0) = normalize n d d0 := by
simp [normalize_eq, mk'.injEq, Int.natAbs_mul, Nat.gcd_mul_left,
Nat.mul_div_mul_left _ _ (Nat.pos_of_ne_zero a0), Int.ofNat_mul,
Int.mul_ediv_mul_of_pos _ _ (Int.ofNat_pos.2 <| Nat.pos_of_ne_zero a0)]
theorem normalize_mul_right {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) :
normalize (n * a) (d * a) (Nat.mul_ne_zero d0 a0) = normalize n d d0 := by
rw [← normalize_mul_left (d0 := d0) a0]; congr 1 <;> [apply Int.mul_comm; apply Nat.mul_comm]
theorem normalize_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
normalize n₁ d₁ z₁ = normalize n₂ d₂ z₂ ↔ n₁ * d₂ = n₂ * d₁ := by
constructor <;> intro h
· simp only [normalize_eq, mk'.injEq] at h
have' hn₁ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₁.natAbs d₁
have' hn₂ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₂.natAbs d₂
have' hd₁ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₁.natAbs d₁
have' hd₂ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₂.natAbs d₂
rw [← Int.ediv_mul_cancel (Int.dvd_trans hd₂ (Int.dvd_mul_left ..)),
Int.mul_ediv_assoc _ hd₂, ← Int.ofNat_ediv, ← h.2, Int.ofNat_ediv,
← Int.mul_ediv_assoc _ hd₁, Int.mul_ediv_assoc' _ hn₁,
Int.mul_right_comm, h.1, Int.ediv_mul_cancel hn₂]
· rw [← normalize_mul_right _ z₂, ← normalize_mul_left z₂ z₁, Int.mul_comm d₁, h]
theorem maybeNormalize_eq_normalize {num : Int} {den g : Nat} (den_nz reduced)
(hn : ↑g ∣ num) (hd : g ∣ den) :
maybeNormalize num den g den_nz reduced = normalize num den (mt (by simp [·]) den_nz) := by
simp only [maybeNormalize_eq, mk_eq_normalize, Int.div_eq_ediv_of_dvd hn]
have : g ≠ 0 := mt (by simp [·]) den_nz
rw [← normalize_mul_right _ this, Int.ediv_mul_cancel hn]
congr 1; exact Nat.div_mul_cancel hd
@[simp] theorem normalize_eq_zero (d0 : d ≠ 0) : normalize n d d0 = 0 ↔ n = 0 := by
have' := normalize_eq_iff d0 Nat.one_ne_zero
rw [normalize_zero (d := 1)] at this; rw [this]; simp
theorem normalize_num_den' (num den nz) : ∃ d : Nat, d ≠ 0 ∧
num = (normalize num den nz).num * d ∧ den = (normalize num den nz).den * d := by
refine ⟨num.natAbs.gcd den, Nat.gcd_ne_zero_right nz, ?_⟩
simp [normalize_eq, Int.ediv_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..),
Nat.div_mul_cancel (Nat.gcd_dvd_right ..)]
theorem normalize_num_den (h : normalize n d z = ⟨n', d', z', c⟩) :
∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := by
have := normalize_num_den' n d z; rwa [h] at this
theorem normalize_eq_mkRat {num den} (den_nz) : normalize num den den_nz = mkRat num den := by
simp [mkRat, den_nz]
theorem mkRat_num_den (z : d ≠ 0) (h : mkRat n d = ⟨n', d', z', c⟩) :
∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m :=
normalize_num_den ((normalize_eq_mkRat z).symm ▸ h)
theorem mkRat_def (n d) : mkRat n d = if d0 : d = 0 then 0 else normalize n d d0 := rfl
theorem mkRat_self (a : Rat) : mkRat a.num a.den = a := by
rw [← normalize_eq_mkRat a.den_nz, normalize_self]
theorem mk_eq_mkRat (num den nz c) : ⟨num, den, nz, c⟩ = mkRat num den := by
simp [mk_eq_normalize, normalize_eq_mkRat]
@[simp] theorem zero_mkRat (n) : mkRat 0 n = 0 := by simp [mkRat_def]
@[simp] theorem mkRat_zero (n) : mkRat n 0 = 0 := by simp [mkRat_def]
theorem mkRat_eq_zero (d0 : d ≠ 0) : mkRat n d = 0 ↔ n = 0 := by simp [mkRat_def, d0]
theorem mkRat_ne_zero (d0 : d ≠ 0) : mkRat n d ≠ 0 ↔ n ≠ 0 := not_congr (mkRat_eq_zero d0)
theorem mkRat_mul_left {a : Nat} (a0 : a ≠ 0) : mkRat (↑a * n) (a * d) = mkRat n d := by
if d0 : d = 0 then simp [d0] else
rw [← normalize_eq_mkRat d0, ← normalize_mul_left d0 a0, normalize_eq_mkRat]
theorem mkRat_mul_right {a : Nat} (a0 : a ≠ 0) : mkRat (n * a) (d * a) = mkRat n d := by
rw [← mkRat_mul_left (d := d) a0]; congr 1 <;> [apply Int.mul_comm; apply Nat.mul_comm]
theorem mkRat_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
mkRat n₁ d₁ = mkRat n₂ d₂ ↔ n₁ * d₂ = n₂ * d₁ := by
rw [← normalize_eq_mkRat z₁, ← normalize_eq_mkRat z₂, normalize_eq_iff]
@[simp] theorem divInt_ofNat (num den) : num /. (den : Nat) = mkRat num den := by
simp [divInt, normalize_eq_mkRat]
theorem mk_eq_divInt (num den nz c) : ⟨num, den, nz, c⟩ = num /. (den : Nat) := by
simp [mk_eq_mkRat]
theorem divInt_self (a : Rat) : a.num /. a.den = a := by rw [divInt_ofNat, mkRat_self]
@[simp] theorem zero_divInt (n) : 0 /. n = 0 := by cases n <;> simp [divInt]
@[simp] theorem divInt_zero (n) : n /. 0 = 0 := mkRat_zero n
theorem neg_divInt_neg (num den) : -num /. -den = num /. den := by
match den with
| Nat.succ n =>
simp only [divInt, Int.neg_ofNat_succ]
simp [normalize_eq_mkRat, Int.neg_neg]
| 0 => rfl
| Int.negSucc n =>
simp only [divInt, Int.neg_negSucc]
simp [normalize_eq_mkRat, Int.neg_neg]
theorem divInt_neg' (num den) : num /. -den = -num /. den := by rw [← neg_divInt_neg, Int.neg_neg]
theorem divInt_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
n₁ /. d₁ = n₂ /. d₂ ↔ n₁ * d₂ = n₂ * d₁ := by
rcases Int.eq_nat_or_neg d₁ with ⟨_, rfl | rfl⟩ <;>
rcases Int.eq_nat_or_neg d₂ with ⟨_, rfl | rfl⟩ <;>
simp_all [divInt_neg', Int.ofNat_eq_zero, Int.neg_eq_zero,
mkRat_eq_iff, Int.neg_mul, Int.mul_neg, Int.eq_neg_comm, eq_comm]
theorem divInt_mul_left {a : Int} (a0 : a ≠ 0) : (a * n) /. (a * d) = n /. d := by
if d0 : d = 0 then simp [d0] else
simp [divInt_eq_iff (Int.mul_ne_zero a0 d0) d0, Int.mul_assoc, Int.mul_left_comm]
theorem divInt_mul_right {a : Int} (a0 : a ≠ 0) : (n * a) /. (d * a) = n /. d := by
simp [← divInt_mul_left (d := d) a0, Int.mul_comm]
| .lake/packages/batteries/Batteries/Data/Rat/Lemmas.lean | 170 | 178 | theorem divInt_num_den (z : d ≠ 0) (h : n /. d = ⟨n', d', z', c⟩) :
∃ m, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := by |
rcases Int.eq_nat_or_neg d with ⟨_, rfl | rfl⟩ <;>
simp_all [divInt_neg', Int.ofNat_eq_zero, Int.neg_eq_zero]
· have ⟨m, h₁, h₂⟩ := mkRat_num_den z h; exists m
simp [Int.ofNat_eq_zero, Int.ofNat_mul, h₁, h₂]
· have ⟨m, h₁, h₂⟩ := mkRat_num_den z h; exists -m
rw [← Int.neg_inj, Int.neg_neg] at h₂
simp [Int.ofNat_eq_zero, Int.ofNat_mul, h₁, h₂, Int.mul_neg, Int.neg_eq_zero]
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Fin.Basic
import Mathlib.Order.Chain
import Mathlib.Order.Cover
import Mathlib.Order.Fin
/-!
# Range of `f : Fin (n + 1) → α` as a `Flag`
Let `f : Fin (n + 1) → α` be an `(n + 1)`-tuple `(f₀, …, fₙ)` such that
- `f₀ = ⊥` and `fₙ = ⊤`;
- `fₖ₊₁` weakly covers `fₖ` for all `0 ≤ k < n`;
this means that `fₖ ≤ fₖ₊₁` and there is no `c` such that `fₖ<c<fₖ₊₁`.
Then the range of `f` is a maximal chain.
We formulate this result in terms of `IsMaxChain` and `Flag`.
-/
open Set
variable {α : Type*} [PartialOrder α] [BoundedOrder α] {n : ℕ} {f : Fin (n + 1) → α}
/-- Let `f : Fin (n + 1) → α` be an `(n + 1)`-tuple `(f₀, …, fₙ)` such that
- `f₀ = ⊥` and `fₙ = ⊤`;
- `fₖ₊₁` weakly covers `fₖ` for all `0 ≤ k < n`;
this means that `fₖ ≤ fₖ₊₁` and there is no `c` such that `fₖ<c<fₖ₊₁`.
Then the range of `f` is a maximal chain. -/
| Mathlib/Data/Fin/FlagRange.lean | 32 | 44 | theorem IsMaxChain.range_fin_of_covBy (h0 : f 0 = ⊥) (hlast : f (.last n) = ⊤)
(hcovBy : ∀ k : Fin n, f k.castSucc ⩿ f k.succ) :
IsMaxChain (· ≤ ·) (range f) := by |
have hmono : Monotone f := Fin.monotone_iff_le_succ.2 fun k ↦ (hcovBy k).1
refine ⟨hmono.isChain_range, fun t htc hbt ↦ hbt.antisymm fun x hx ↦ ?_⟩
rw [mem_range]; by_contra! h
suffices ∀ k, f k < x by simpa [hlast] using this (.last _)
intro k
induction k using Fin.induction with
| zero => simpa [h0, bot_lt_iff_ne_bot] using (h 0).symm
| succ k ihk =>
rw [range_subset_iff] at hbt
exact (htc.lt_of_le (hbt k.succ) hx (h _)).resolve_right ((hcovBy k).2 ihk)
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import Mathlib.Analysis.InnerProductSpace.Basic
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
#align_import geometry.euclidean.angle.unoriented.basic from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5"
/-!
# Angles between vectors
This file defines unoriented angles in real inner product spaces.
## Main definitions
* `InnerProductGeometry.angle` is the undirected angle between two vectors.
## TODO
Prove the triangle inequality for the angle.
-/
assert_not_exists HasFDerivAt
assert_not_exists ConformalAt
noncomputable section
open Real Set
open Real
open RealInnerProductSpace
namespace InnerProductGeometry
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] {x y : V}
/-- The undirected angle between two vectors. If either vector is 0,
this is π/2. See `Orientation.oangle` for the corresponding oriented angle
definition. -/
def angle (x y : V) : ℝ :=
Real.arccos (⟪x, y⟫ / (‖x‖ * ‖y‖))
#align inner_product_geometry.angle InnerProductGeometry.angle
theorem continuousAt_angle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :
ContinuousAt (fun y : V × V => angle y.1 y.2) x :=
Real.continuous_arccos.continuousAt.comp <|
continuous_inner.continuousAt.div
((continuous_norm.comp continuous_fst).mul (continuous_norm.comp continuous_snd)).continuousAt
(by simp [hx1, hx2])
#align inner_product_geometry.continuous_at_angle InnerProductGeometry.continuousAt_angle
theorem angle_smul_smul {c : ℝ} (hc : c ≠ 0) (x y : V) : angle (c • x) (c • y) = angle x y := by
have : c * c ≠ 0 := mul_ne_zero hc hc
rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs,
mul_mul_mul_comm _ ‖x‖, abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this]
#align inner_product_geometry.angle_smul_smul InnerProductGeometry.angle_smul_smul
@[simp]
theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F]
[InnerProductSpace ℝ E] [InnerProductSpace ℝ F] (f : E →ₗᵢ[ℝ] F) (u v : E) :
angle (f u) (f v) = angle u v := by
rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map]
#align linear_isometry.angle_map LinearIsometry.angle_map
@[simp, norm_cast]
theorem _root_.Submodule.angle_coe {s : Submodule ℝ V} (x y : s) :
angle (x : V) (y : V) = angle x y :=
s.subtypeₗᵢ.angle_map x y
#align submodule.angle_coe Submodule.angle_coe
/-- The cosine of the angle between two vectors. -/
theorem cos_angle (x y : V) : Real.cos (angle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) :=
Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1
(abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2
#align inner_product_geometry.cos_angle InnerProductGeometry.cos_angle
/-- The angle between two vectors does not depend on their order. -/
theorem angle_comm (x y : V) : angle x y = angle y x := by
unfold angle
rw [real_inner_comm, mul_comm]
#align inner_product_geometry.angle_comm InnerProductGeometry.angle_comm
/-- The angle between the negation of two vectors. -/
@[simp]
theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by
unfold angle
rw [inner_neg_neg, norm_neg, norm_neg]
#align inner_product_geometry.angle_neg_neg InnerProductGeometry.angle_neg_neg
/-- The angle between two vectors is nonnegative. -/
theorem angle_nonneg (x y : V) : 0 ≤ angle x y :=
Real.arccos_nonneg _
#align inner_product_geometry.angle_nonneg InnerProductGeometry.angle_nonneg
/-- The angle between two vectors is at most π. -/
theorem angle_le_pi (x y : V) : angle x y ≤ π :=
Real.arccos_le_pi _
#align inner_product_geometry.angle_le_pi InnerProductGeometry.angle_le_pi
/-- The angle between a vector and the negation of another vector. -/
theorem angle_neg_right (x y : V) : angle x (-y) = π - angle x y := by
unfold angle
rw [← Real.arccos_neg, norm_neg, inner_neg_right, neg_div]
#align inner_product_geometry.angle_neg_right InnerProductGeometry.angle_neg_right
/-- The angle between the negation of a vector and another vector. -/
theorem angle_neg_left (x y : V) : angle (-x) y = π - angle x y := by
rw [← angle_neg_neg, neg_neg, angle_neg_right]
#align inner_product_geometry.angle_neg_left InnerProductGeometry.angle_neg_left
proof_wanted angle_triangle (x y z : V) : angle x z ≤ angle x y + angle y z
/-- The angle between the zero vector and a vector. -/
@[simp]
theorem angle_zero_left (x : V) : angle 0 x = π / 2 := by
unfold angle
rw [inner_zero_left, zero_div, Real.arccos_zero]
#align inner_product_geometry.angle_zero_left InnerProductGeometry.angle_zero_left
/-- The angle between a vector and the zero vector. -/
@[simp]
theorem angle_zero_right (x : V) : angle x 0 = π / 2 := by
unfold angle
rw [inner_zero_right, zero_div, Real.arccos_zero]
#align inner_product_geometry.angle_zero_right InnerProductGeometry.angle_zero_right
/-- The angle between a nonzero vector and itself. -/
@[simp]
theorem angle_self {x : V} (hx : x ≠ 0) : angle x x = 0 := by
unfold angle
rw [← real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : ⟪x, x⟫ ≠ 0),
Real.arccos_one]
#align inner_product_geometry.angle_self InnerProductGeometry.angle_self
/-- The angle between a nonzero vector and its negation. -/
@[simp]
theorem angle_self_neg_of_nonzero {x : V} (hx : x ≠ 0) : angle x (-x) = π := by
rw [angle_neg_right, angle_self hx, sub_zero]
#align inner_product_geometry.angle_self_neg_of_nonzero InnerProductGeometry.angle_self_neg_of_nonzero
/-- The angle between the negation of a nonzero vector and that
vector. -/
@[simp]
theorem angle_neg_self_of_nonzero {x : V} (hx : x ≠ 0) : angle (-x) x = π := by
rw [angle_comm, angle_self_neg_of_nonzero hx]
#align inner_product_geometry.angle_neg_self_of_nonzero InnerProductGeometry.angle_neg_self_of_nonzero
/-- The angle between a vector and a positive multiple of a vector. -/
@[simp]
theorem angle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle x (r • y) = angle x y := by
unfold angle
rw [inner_smul_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), ← mul_assoc,
mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)]
#align inner_product_geometry.angle_smul_right_of_pos InnerProductGeometry.angle_smul_right_of_pos
/-- The angle between a positive multiple of a vector and a vector. -/
@[simp]
theorem angle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle (r • x) y = angle x y := by
rw [angle_comm, angle_smul_right_of_pos y x hr, angle_comm]
#align inner_product_geometry.angle_smul_left_of_pos InnerProductGeometry.angle_smul_left_of_pos
/-- The angle between a vector and a negative multiple of a vector. -/
@[simp]
theorem angle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) :
angle x (r • y) = angle x (-y) := by
rw [← neg_neg r, neg_smul, angle_neg_right, angle_smul_right_of_pos x y (neg_pos_of_neg hr),
angle_neg_right]
#align inner_product_geometry.angle_smul_right_of_neg InnerProductGeometry.angle_smul_right_of_neg
/-- The angle between a negative multiple of a vector and a vector. -/
@[simp]
theorem angle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : angle (r • x) y = angle (-x) y := by
rw [angle_comm, angle_smul_right_of_neg y x hr, angle_comm]
#align inner_product_geometry.angle_smul_left_of_neg InnerProductGeometry.angle_smul_left_of_neg
/-- The cosine of the angle between two vectors, multiplied by the
product of their norms. -/
theorem cos_angle_mul_norm_mul_norm (x y : V) : Real.cos (angle x y) * (‖x‖ * ‖y‖) = ⟪x, y⟫ := by
rw [cos_angle, div_mul_cancel_of_imp]
simp (config := { contextual := true }) [or_imp]
#align inner_product_geometry.cos_angle_mul_norm_mul_norm InnerProductGeometry.cos_angle_mul_norm_mul_norm
/-- The sine of the angle between two vectors, multiplied by the
product of their norms. -/
theorem sin_angle_mul_norm_mul_norm (x y : V) :
Real.sin (angle x y) * (‖x‖ * ‖y‖) = √(⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫) := by
unfold angle
rw [Real.sin_arccos, ← Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)),
← Real.sqrt_mul' _ (mul_self_nonneg _), sq,
Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)),
real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm]
by_cases h : ‖x‖ * ‖y‖ = 0
· rw [show ‖x‖ * ‖x‖ * (‖y‖ * ‖y‖) = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) by ring, h, mul_zero,
mul_zero, zero_sub]
cases' eq_zero_or_eq_zero_of_mul_eq_zero h with hx hy
· rw [norm_eq_zero] at hx
rw [hx, inner_zero_left, zero_mul, neg_zero]
· rw [norm_eq_zero] at hy
rw [hy, inner_zero_right, zero_mul, neg_zero]
· field_simp [h]
ring_nf
#align inner_product_geometry.sin_angle_mul_norm_mul_norm InnerProductGeometry.sin_angle_mul_norm_mul_norm
/-- The angle between two vectors is zero if and only if they are
nonzero and one is a positive multiple of the other. -/
theorem angle_eq_zero_iff {x y : V} : angle x y = 0 ↔ x ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • x := by
rw [angle, ← real_inner_div_norm_mul_norm_eq_one_iff, Real.arccos_eq_zero, LE.le.le_iff_eq,
eq_comm]
exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2
#align inner_product_geometry.angle_eq_zero_iff InnerProductGeometry.angle_eq_zero_iff
/-- The angle between two vectors is π if and only if they are nonzero
and one is a negative multiple of the other. -/
theorem angle_eq_pi_iff {x y : V} : angle x y = π ↔ x ≠ 0 ∧ ∃ r : ℝ, r < 0 ∧ y = r • x := by
rw [angle, ← real_inner_div_norm_mul_norm_eq_neg_one_iff, Real.arccos_eq_pi, LE.le.le_iff_eq]
exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1
#align inner_product_geometry.angle_eq_pi_iff InnerProductGeometry.angle_eq_pi_iff
/-- If the angle between two vectors is π, the angles between those
vectors and a third vector add to π. -/
theorem angle_add_angle_eq_pi_of_angle_eq_pi {x y : V} (z : V) (h : angle x y = π) :
angle x z + angle y z = π := by
rcases angle_eq_pi_iff.1 h with ⟨_, ⟨r, ⟨hr, rfl⟩⟩⟩
rw [angle_smul_left_of_neg x z hr, angle_neg_left, add_sub_cancel]
#align inner_product_geometry.angle_add_angle_eq_pi_of_angle_eq_pi InnerProductGeometry.angle_add_angle_eq_pi_of_angle_eq_pi
/-- Two vectors have inner product 0 if and only if the angle between
them is π/2. -/
theorem inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : ⟪x, y⟫ = 0 ↔ angle x y = π / 2 :=
Iff.symm <| by simp (config := { contextual := true }) [angle, or_imp]
#align inner_product_geometry.inner_eq_zero_iff_angle_eq_pi_div_two InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two
/-- If the angle between two vectors is π, the inner product equals the negative product
of the norms. -/
theorem inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) :
⟪x, y⟫ = -(‖x‖ * ‖y‖) := by
simp [← cos_angle_mul_norm_mul_norm, h]
#align inner_product_geometry.inner_eq_neg_mul_norm_of_angle_eq_pi InnerProductGeometry.inner_eq_neg_mul_norm_of_angle_eq_pi
/-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/
theorem inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ⟪x, y⟫ = ‖x‖ * ‖y‖ := by
simp [← cos_angle_mul_norm_mul_norm, h]
#align inner_product_geometry.inner_eq_mul_norm_of_angle_eq_zero InnerProductGeometry.inner_eq_mul_norm_of_angle_eq_zero
/-- The inner product of two non-zero vectors equals the negative product of their norms
if and only if the angle between the two vectors is π. -/
theorem inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
⟪x, y⟫ = -(‖x‖ * ‖y‖) ↔ angle x y = π := by
refine ⟨fun h => ?_, inner_eq_neg_mul_norm_of_angle_eq_pi⟩
have h₁ : ‖x‖ * ‖y‖ ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne'
rw [angle, h, neg_div, div_self h₁, Real.arccos_neg_one]
#align inner_product_geometry.inner_eq_neg_mul_norm_iff_angle_eq_pi InnerProductGeometry.inner_eq_neg_mul_norm_iff_angle_eq_pi
/-- The inner product of two non-zero vectors equals the product of their norms
if and only if the angle between the two vectors is 0. -/
theorem inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
⟪x, y⟫ = ‖x‖ * ‖y‖ ↔ angle x y = 0 := by
refine ⟨fun h => ?_, inner_eq_mul_norm_of_angle_eq_zero⟩
have h₁ : ‖x‖ * ‖y‖ ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne'
rw [angle, h, div_self h₁, Real.arccos_one]
#align inner_product_geometry.inner_eq_mul_norm_iff_angle_eq_zero InnerProductGeometry.inner_eq_mul_norm_iff_angle_eq_zero
/-- If the angle between two vectors is π, the norm of their difference equals
the sum of their norms. -/
theorem norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) :
‖x - y‖ = ‖x‖ + ‖y‖ := by
rw [← sq_eq_sq (norm_nonneg (x - y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)),
norm_sub_pow_two_real, inner_eq_neg_mul_norm_of_angle_eq_pi h]
ring
#align inner_product_geometry.norm_sub_eq_add_norm_of_angle_eq_pi InnerProductGeometry.norm_sub_eq_add_norm_of_angle_eq_pi
/-- If the angle between two vectors is 0, the norm of their sum equals
the sum of their norms. -/
| Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean | 279 | 283 | theorem norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) :
‖x + y‖ = ‖x‖ + ‖y‖ := by |
rw [← sq_eq_sq (norm_nonneg (x + y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)),
norm_add_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h]
ring
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Logic.Function.Basic
import Mathlib.Logic.Relator
import Mathlib.Init.Data.Quot
import Mathlib.Tactic.Cases
import Mathlib.Tactic.Use
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.SimpRw
#align_import logic.relation from "leanprover-community/mathlib"@"3365b20c2ffa7c35e47e5209b89ba9abdddf3ffe"
/-!
# Relation closures
This file defines the reflexive, transitive, and reflexive transitive closures of relations.
It also proves some basic results on definitions such as `EqvGen`.
Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For
the bundled version, see `Rel`.
## Definitions
* `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all
`a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`.
* `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related
transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`.
* `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything
`r` related transitively, plus for all `a` it relates `a` with itself. So
`ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as
the reflexive closure of the transitive closure, or the transitive closure of the reflexive
closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of
rewrites.
* `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and
`s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to
both.
* `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`,
`g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b`
related by `r`.
* `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In
terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term.
-/
open Function
variable {α β γ δ ε ζ : Type*}
section NeImp
variable {r : α → α → Prop}
theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x
#align is_refl.reflexive IsRefl.reflexive
/-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`,
it suffices to show it holds when `x ≠ y`. -/
theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by
by_cases hxy : x = y
· exact hxy ▸ h x
· exact hr hxy
#align reflexive.rel_of_ne_imp Reflexive.rel_of_ne_imp
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. -/
theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y :=
⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩
#align reflexive.ne_imp_iff Reflexive.ne_imp_iff
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/
theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y :=
IsRefl.reflexive.ne_imp_iff
#align reflexive_ne_imp_iff reflexive_ne_imp_iff
protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x :=
⟨fun h ↦ H h, fun h ↦ H h⟩
#align symmetric.iff Symmetric.iff
theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r :=
funext₂ fun _ _ ↦ propext <| h.iff _ _
#align symmetric.flip_eq Symmetric.flip_eq
theorem Symmetric.swap_eq : Symmetric r → swap r = r :=
Symmetric.flip_eq
#align symmetric.swap_eq Symmetric.swap_eq
theorem flip_eq_iff : flip r = r ↔ Symmetric r :=
⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩
#align flip_eq_iff flip_eq_iff
theorem swap_eq_iff : swap r = r ↔ Symmetric r :=
flip_eq_iff
#align swap_eq_iff swap_eq_iff
end NeImp
section Comap
variable {r : β → β → Prop}
theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a)
#align reflexive.comap Reflexive.comap
theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab
#align symmetric.comap Symmetric.comap
theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) :=
fun _ _ _ hab hbc ↦ h hab hbc
#align transitive.comap Transitive.comap
theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) :=
⟨h.reflexive.comap f, @(h.symmetric.comap f), @(h.transitive.comap f)⟩
#align equivalence.comap Equivalence.comap
end Comap
namespace Relation
section Comp
variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop}
/-- The composition of two relations, yielding a new relation. The result
relates a term of `α` and a term of `γ` if there is an intermediate
term of `β` related to both.
-/
def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop :=
∃ b, r a b ∧ p b c
#align relation.comp Relation.Comp
@[inherit_doc]
local infixr:80 " ∘r " => Relation.Comp
theorem comp_eq : r ∘r (· = ·) = r :=
funext fun _ ↦ funext fun b ↦ propext <|
Iff.intro (fun ⟨_, h, Eq⟩ ↦ Eq ▸ h) fun h ↦ ⟨b, h, rfl⟩
#align relation.comp_eq Relation.comp_eq
theorem eq_comp : (· = ·) ∘r r = r :=
funext fun a ↦ funext fun _ ↦ propext <|
Iff.intro (fun ⟨_, Eq, h⟩ ↦ Eq.symm ▸ h) fun h ↦ ⟨a, rfl, h⟩
#align relation.eq_comp Relation.eq_comp
theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, eq_comp]
#align relation.iff_comp Relation.iff_comp
theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, comp_eq]
#align relation.comp_iff Relation.comp_iff
theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by
funext a d
apply propext
constructor
· exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩
· exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩
#align relation.comp_assoc Relation.comp_assoc
theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by
funext c a
apply propext
constructor
· exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩
· exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩
#align relation.flip_comp Relation.flip_comp
end Comp
section Fibration
variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β)
/-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all
`a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image
of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/
def Fibration :=
∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b
#align relation.fibration Relation.Fibration
variable {rα rβ}
/-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is
accessible under `rα`, then `f a` is accessible under `rβ`. -/
theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by
induction' ha with a _ ih
refine Acc.intro (f a) fun b hr ↦ ?_
obtain ⟨a', hr', rfl⟩ := fib hr
exact ih a' hr'
#align acc.of_fibration Acc.of_fibration
theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α)
(ha : Acc (InvImage rβ f) a) : Acc rβ (f a) :=
ha.of_fibration f fun a _ h ↦
let ⟨a', he⟩ := dc h
-- Porting note: Lean 3 did not need the motive
⟨a', he.substr (p := fun x ↦ rβ x (f a)) h, he⟩
#align acc.of_downward_closed Acc.of_downward_closed
end Fibration
section Map
variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ}
/-- The map of a relation `r` through a pair of functions pushes the
relation to the codomains of the functions. The resulting relation is
defined by having pairs of terms related if they have preimages
related by `r`.
-/
protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦
∃ a b, r a b ∧ f a = c ∧ g b = d
#align relation.map Relation.Map
lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl
#align relation.map_apply Relation.map_apply
@[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) :
Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by
ext a b
simp_rw [Relation.Map, Function.comp_apply, ← exists_and_right, @exists_comm γ, @exists_comm δ]
refine exists₂_congr fun a b ↦ ⟨?_, fun h ↦ ⟨_, _, ⟨⟨h.1, rfl, rfl⟩, h.2⟩⟩⟩
rintro ⟨_, _, ⟨hab, rfl, rfl⟩, h⟩
exact ⟨hab, h⟩
#align relation.map_map Relation.map_map
@[simp]
lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) :
Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff]
@[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map]
#align relation.map_id_id Relation.map_id_id
instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) :=
‹Decidable _›
end Map
variable {r : α → α → Prop} {a b c d : α}
/-- `ReflTransGen r`: reflexive transitive closure of `r` -/
@[mk_iff ReflTransGen.cases_tail_iff]
inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflTransGen r a a
| tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c
#align relation.refl_trans_gen Relation.ReflTransGen
#align relation.refl_trans_gen.cases_tail_iff Relation.ReflTransGen.cases_tail_iff
attribute [refl] ReflTransGen.refl
/-- `ReflGen r`: reflexive closure of `r` -/
@[mk_iff]
inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflGen r a a
| single {b} : r a b → ReflGen r a b
#align relation.refl_gen Relation.ReflGen
#align relation.refl_gen_iff Relation.reflGen_iff
/-- `TransGen r`: transitive closure of `r` -/
@[mk_iff]
inductive TransGen (r : α → α → Prop) (a : α) : α → Prop
| single {b} : r a b → TransGen r a b
| tail {b c} : TransGen r a b → r b c → TransGen r a c
#align relation.trans_gen Relation.TransGen
#align relation.trans_gen_iff Relation.transGen_iff
attribute [refl] ReflGen.refl
namespace ReflGen
theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b
| a, _, refl => by rfl
| a, b, single h => ReflTransGen.tail ReflTransGen.refl h
#align relation.refl_gen.to_refl_trans_gen Relation.ReflGen.to_reflTransGen
theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b
| a, _, ReflGen.refl => by rfl
| a, b, single h => single (hp a b h)
#align relation.refl_gen.mono Relation.ReflGen.mono
instance : IsRefl α (ReflGen r) :=
⟨@refl α r⟩
end ReflGen
namespace ReflTransGen
@[trans]
theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
#align relation.refl_trans_gen.trans Relation.ReflTransGen.trans
theorem single (hab : r a b) : ReflTransGen r a b :=
refl.tail hab
#align relation.refl_trans_gen.single Relation.ReflTransGen.single
theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => exact refl.tail hab
| tail _ hcd hac => exact hac.tail hcd
#align relation.refl_trans_gen.head Relation.ReflTransGen.head
theorem symmetric (h : Symmetric r) : Symmetric (ReflTransGen r) := by
intro x y h
induction' h with z w _ b c
· rfl
· apply Relation.ReflTransGen.head (h b) c
#align relation.refl_trans_gen.symmetric Relation.ReflTransGen.symmetric
theorem cases_tail : ReflTransGen r a b → b = a ∨ ∃ c, ReflTransGen r a c ∧ r c b :=
(cases_tail_iff r a b).1
#align relation.refl_trans_gen.cases_tail Relation.ReflTransGen.cases_tail
@[elab_as_elim]
theorem head_induction_on {P : ∀ a : α, ReflTransGen r a b → Prop} {a : α} (h : ReflTransGen r a b)
(refl : P b refl)
(head : ∀ {a c} (h' : r a c) (h : ReflTransGen r c b), P c h → P a (h.head h')) : P a h := by
induction h with
| refl => exact refl
| @tail b c _ hbc ih =>
apply ih
· exact head hbc _ refl
· exact fun h1 h2 ↦ head h1 (h2.tail hbc)
#align relation.refl_trans_gen.head_induction_on Relation.ReflTransGen.head_induction_on
@[elab_as_elim]
theorem trans_induction_on {P : ∀ {a b : α}, ReflTransGen r a b → Prop} {a b : α}
(h : ReflTransGen r a b) (ih₁ : ∀ a, @P a a refl) (ih₂ : ∀ {a b} (h : r a b), P (single h))
(ih₃ : ∀ {a b c} (h₁ : ReflTransGen r a b) (h₂ : ReflTransGen r b c), P h₁ → P h₂ →
P (h₁.trans h₂)) : P h := by
induction h with
| refl => exact ih₁ a
| tail hab hbc ih => exact ih₃ hab (single hbc) ih (ih₂ hbc)
#align relation.refl_trans_gen.trans_induction_on Relation.ReflTransGen.trans_induction_on
theorem cases_head (h : ReflTransGen r a b) : a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
induction h using Relation.ReflTransGen.head_induction_on
· left
rfl
· right
exact ⟨_, by assumption, by assumption⟩;
#align relation.refl_trans_gen.cases_head Relation.ReflTransGen.cases_head
theorem cases_head_iff : ReflTransGen r a b ↔ a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
use cases_head
rintro (rfl | ⟨c, hac, hcb⟩)
· rfl
· exact head hac hcb
#align relation.refl_trans_gen.cases_head_iff Relation.ReflTransGen.cases_head_iff
theorem total_of_right_unique (U : Relator.RightUnique r) (ab : ReflTransGen r a b)
(ac : ReflTransGen r a c) : ReflTransGen r b c ∨ ReflTransGen r c b := by
induction' ab with b d _ bd IH
· exact Or.inl ac
· rcases IH with (IH | IH)
· rcases cases_head IH with (rfl | ⟨e, be, ec⟩)
· exact Or.inr (single bd)
· cases U bd be
exact Or.inl ec
· exact Or.inr (IH.tail bd)
#align relation.refl_trans_gen.total_of_right_unique Relation.ReflTransGen.total_of_right_unique
end ReflTransGen
namespace TransGen
theorem to_reflTransGen {a b} (h : TransGen r a b) : ReflTransGen r a b := by
induction' h with b h b c _ bc ab
· exact ReflTransGen.single h
· exact ReflTransGen.tail ab bc
-- Porting note: in Lean 3 this function was called `to_refl` which seems wrong.
#align relation.trans_gen.to_refl Relation.TransGen.to_reflTransGen
theorem trans_left (hab : TransGen r a b) (hbc : ReflTransGen r b c) : TransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
#align relation.trans_gen.trans_left Relation.TransGen.trans_left
instance : Trans (TransGen r) (ReflTransGen r) (TransGen r) :=
⟨trans_left⟩
@[trans]
theorem trans (hab : TransGen r a b) (hbc : TransGen r b c) : TransGen r a c :=
trans_left hab hbc.to_reflTransGen
#align relation.trans_gen.trans Relation.TransGen.trans
instance : Trans (TransGen r) (TransGen r) (TransGen r) :=
⟨trans⟩
theorem head' (hab : r a b) (hbc : ReflTransGen r b c) : TransGen r a c :=
trans_left (single hab) hbc
#align relation.trans_gen.head' Relation.TransGen.head'
theorem tail' (hab : ReflTransGen r a b) (hbc : r b c) : TransGen r a c := by
induction hab generalizing c with
| refl => exact single hbc
| tail _ hdb IH => exact tail (IH hdb) hbc
#align relation.trans_gen.tail' Relation.TransGen.tail'
theorem head (hab : r a b) (hbc : TransGen r b c) : TransGen r a c :=
head' hab hbc.to_reflTransGen
#align relation.trans_gen.head Relation.TransGen.head
@[elab_as_elim]
theorem head_induction_on {P : ∀ a : α, TransGen r a b → Prop} {a : α} (h : TransGen r a b)
(base : ∀ {a} (h : r a b), P a (single h))
(ih : ∀ {a c} (h' : r a c) (h : TransGen r c b), P c h → P a (h.head h')) : P a h := by
induction h with
| single h => exact base h
| @tail b c _ hbc h_ih =>
apply h_ih
· exact fun h ↦ ih h (single hbc) (base hbc)
· exact fun hab hbc ↦ ih hab _
#align relation.trans_gen.head_induction_on Relation.TransGen.head_induction_on
@[elab_as_elim]
theorem trans_induction_on {P : ∀ {a b : α}, TransGen r a b → Prop} {a b : α} (h : TransGen r a b)
(base : ∀ {a b} (h : r a b), P (single h))
(ih : ∀ {a b c} (h₁ : TransGen r a b) (h₂ : TransGen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) :
P h := by
induction h with
| single h => exact base h
| tail hab hbc h_ih => exact ih hab (single hbc) h_ih (base hbc)
#align relation.trans_gen.trans_induction_on Relation.TransGen.trans_induction_on
theorem trans_right (hab : ReflTransGen r a b) (hbc : TransGen r b c) : TransGen r a c := by
induction hbc with
| single hbc => exact tail' hab hbc
| tail _ hcd hac => exact hac.tail hcd
#align relation.trans_gen.trans_right Relation.TransGen.trans_right
instance : Trans (ReflTransGen r) (TransGen r) (TransGen r) :=
⟨trans_right⟩
theorem tail'_iff : TransGen r a c ↔ ∃ b, ReflTransGen r a b ∧ r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ tail' hab hbc⟩
cases' h with _ hac b _ hab hbc
· exact ⟨_, by rfl, hac⟩
· exact ⟨_, hab.to_reflTransGen, hbc⟩
#align relation.trans_gen.tail'_iff Relation.TransGen.tail'_iff
theorem head'_iff : TransGen r a c ↔ ∃ b, r a b ∧ ReflTransGen r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ head' hab hbc⟩
induction h with
| single hac => exact ⟨_, hac, by rfl⟩
| tail _ hbc IH =>
rcases IH with ⟨d, had, hdb⟩
exact ⟨_, had, hdb.tail hbc⟩
#align relation.trans_gen.head'_iff Relation.TransGen.head'_iff
end TransGen
theorem _root_.Acc.TransGen (h : Acc r a) : Acc (TransGen r) a := by
induction' h with x _ H
refine Acc.intro x fun y hy ↦ ?_
cases' hy with _ hyx z _ hyz hzx
exacts [H y hyx, (H z hzx).inv hyz]
#align acc.trans_gen Acc.TransGen
theorem _root_.acc_transGen_iff : Acc (TransGen r) a ↔ Acc r a :=
⟨Subrelation.accessible TransGen.single, Acc.TransGen⟩
#align acc_trans_gen_iff acc_transGen_iff
theorem _root_.WellFounded.transGen (h : WellFounded r) : WellFounded (TransGen r) :=
⟨fun a ↦ (h.apply a).TransGen⟩
#align well_founded.trans_gen WellFounded.transGen
section reflGen
lemma reflGen_eq_self (hr : Reflexive r) : ReflGen r = r := by
ext x y
simpa only [reflGen_iff, or_iff_right_iff_imp] using fun h ↦ h ▸ hr y
lemma reflexive_reflGen : Reflexive (ReflGen r) := fun _ ↦ .refl
lemma reflGen_minimal {r' : α → α → Prop} (hr' : Reflexive r') (h : ∀ x y, r x y → r' x y) {x y : α}
(hxy : ReflGen r x y) : r' x y := by
simpa [reflGen_eq_self hr'] using ReflGen.mono h hxy
end reflGen
section TransGen
theorem transGen_eq_self (trans : Transitive r) : TransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction h with
| single hc => exact hc
| tail _ hcd hac => exact trans hac hcd, TransGen.single⟩
#align relation.trans_gen_eq_self Relation.transGen_eq_self
theorem transitive_transGen : Transitive (TransGen r) := fun _ _ _ ↦ TransGen.trans
#align relation.transitive_trans_gen Relation.transitive_transGen
instance : IsTrans α (TransGen r) :=
⟨@TransGen.trans α r⟩
theorem transGen_idem : TransGen (TransGen r) = TransGen r :=
transGen_eq_self transitive_transGen
#align relation.trans_gen_idem Relation.transGen_idem
theorem TransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b))
(hab : TransGen r a b) : TransGen p (f a) (f b) := by
induction hab with
| single hac => exact TransGen.single (h a _ hac)
| tail _ hcd hac => exact TransGen.tail hac (h _ _ hcd)
#align relation.trans_gen.lift Relation.TransGen.lift
theorem TransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → TransGen p (f a) (f b)) (hab : TransGen r a b) :
TransGen p (f a) (f b) := by
simpa [transGen_idem] using hab.lift f h
#align relation.trans_gen.lift' Relation.TransGen.lift'
theorem TransGen.closed {p : α → α → Prop} :
(∀ a b, r a b → TransGen p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift' id
#align relation.trans_gen.closed Relation.TransGen.closed
theorem TransGen.mono {p : α → α → Prop} :
(∀ a b, r a b → p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift id
#align relation.trans_gen.mono Relation.TransGen.mono
lemma transGen_minimal {r' : α → α → Prop} (hr' : Transitive r') (h : ∀ x y, r x y → r' x y)
{x y : α} (hxy : TransGen r x y) : r' x y := by
simpa [transGen_eq_self hr'] using TransGen.mono h hxy
theorem TransGen.swap (h : TransGen r b a) : TransGen (swap r) a b := by
induction' h with b h b c _ hbc ih
· exact TransGen.single h
· exact ih.head hbc
#align relation.trans_gen.swap Relation.TransGen.swap
theorem transGen_swap : TransGen (swap r) a b ↔ TransGen r b a :=
⟨TransGen.swap, TransGen.swap⟩
#align relation.trans_gen_swap Relation.transGen_swap
end TransGen
section ReflTransGen
open ReflTransGen
theorem reflTransGen_iff_eq (h : ∀ b, ¬r a b) : ReflTransGen r a b ↔ b = a := by
rw [cases_head_iff]; simp [h, eq_comm]
#align relation.refl_trans_gen_iff_eq Relation.reflTransGen_iff_eq
theorem reflTransGen_iff_eq_or_transGen : ReflTransGen r a b ↔ b = a ∨ TransGen r a b := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· cases' h with c _ hac hcb
· exact Or.inl rfl
· exact Or.inr (TransGen.tail' hac hcb)
· rcases h with (rfl | h)
· rfl
· exact h.to_reflTransGen
#align relation.refl_trans_gen_iff_eq_or_trans_gen Relation.reflTransGen_iff_eq_or_transGen
theorem ReflTransGen.lift {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) :=
ReflTransGen.trans_induction_on hab (fun _ ↦ refl) (ReflTransGen.single ∘ h _ _) fun _ _ ↦ trans
#align relation.refl_trans_gen.lift Relation.ReflTransGen.lift
theorem ReflTransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) →
ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift id
#align relation.refl_trans_gen.mono Relation.ReflTransGen.mono
theorem reflTransGen_eq_self (refl : Reflexive r) (trans : Transitive r) : ReflTransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction' h with b c _ h₂ IH
· apply refl
· exact trans IH h₂, single⟩
#align relation.refl_trans_gen_eq_self Relation.reflTransGen_eq_self
lemma reflTransGen_minimal {r' : α → α → Prop} (hr₁ : Reflexive r') (hr₂ : Transitive r')
(h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflTransGen r x y) : r' x y := by
simpa [reflTransGen_eq_self hr₁ hr₂] using ReflTransGen.mono h hxy
theorem reflexive_reflTransGen : Reflexive (ReflTransGen r) := fun _ ↦ refl
#align relation.reflexive_refl_trans_gen Relation.reflexive_reflTransGen
theorem transitive_reflTransGen : Transitive (ReflTransGen r) := fun _ _ _ ↦ trans
#align relation.transitive_refl_trans_gen Relation.transitive_reflTransGen
instance : IsRefl α (ReflTransGen r) :=
⟨@ReflTransGen.refl α r⟩
instance : IsTrans α (ReflTransGen r) :=
⟨@ReflTransGen.trans α r⟩
theorem reflTransGen_idem : ReflTransGen (ReflTransGen r) = ReflTransGen r :=
reflTransGen_eq_self reflexive_reflTransGen transitive_reflTransGen
#align relation.refl_trans_gen_idem Relation.reflTransGen_idem
theorem ReflTransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → ReflTransGen p (f a) (f b))
(hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := by
simpa [reflTransGen_idem] using hab.lift f h
#align relation.refl_trans_gen.lift' Relation.ReflTransGen.lift'
theorem reflTransGen_closed {p : α → α → Prop} :
(∀ a b, r a b → ReflTransGen p a b) → ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift' id
#align relation.refl_trans_gen_closed Relation.reflTransGen_closed
theorem ReflTransGen.swap (h : ReflTransGen r b a) : ReflTransGen (swap r) a b := by
induction' h with b c _ hbc ih
· rfl
· exact ih.head hbc
#align relation.refl_trans_gen.swap Relation.ReflTransGen.swap
theorem reflTransGen_swap : ReflTransGen (swap r) a b ↔ ReflTransGen r b a :=
⟨ReflTransGen.swap, ReflTransGen.swap⟩
#align relation.refl_trans_gen_swap Relation.reflTransGen_swap
@[simp] lemma reflGen_transGen : ReflGen (TransGen r) = ReflTransGen r := by
ext x y
simp_rw [reflTransGen_iff_eq_or_transGen, reflGen_iff]
@[simp] lemma transGen_reflGen : TransGen (ReflGen r) = ReflTransGen r := by
ext x y
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simpa [reflTransGen_idem]
using TransGen.to_reflTransGen <| TransGen.mono (fun _ _ ↦ ReflGen.to_reflTransGen) h
· obtain (rfl | h) := reflTransGen_iff_eq_or_transGen.mp h
· exact .single .refl
· exact TransGen.mono (fun _ _ ↦ .single) h
@[simp] lemma reflTransGen_reflGen : ReflTransGen (ReflGen r) = ReflTransGen r := by
simp only [← transGen_reflGen, reflGen_eq_self reflexive_reflGen]
@[simp] lemma reflTransGen_transGen : ReflTransGen (TransGen r) = ReflTransGen r := by
simp only [← reflGen_transGen, transGen_idem]
lemma reflTransGen_eq_transGen (hr : Reflexive r) :
ReflTransGen r = TransGen r := by
rw [← transGen_reflGen, reflGen_eq_self hr]
lemma reflTransGen_eq_reflGen (hr : Transitive r) :
ReflTransGen r = ReflGen r := by
rw [← reflGen_transGen, transGen_eq_self hr]
end ReflTransGen
/-- The join of a relation on a single type is a new relation for which
pairs of terms are related if there is a third term they are both
related to. For example, if `r` is a relation representing rewrites
in a term rewriting system, then *confluence* is the property that if
`a` rewrites to both `b` and `c`, then `join r` relates `b` and `c`
(see `Relation.church_rosser`).
-/
def Join (r : α → α → Prop) : α → α → Prop := fun a b ↦ ∃ c, r a c ∧ r b c
#align relation.join Relation.Join
section Join
open ReflTransGen ReflGen
/-- A sufficient condition for the Church-Rosser property. -/
theorem church_rosser (h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d)
(hab : ReflTransGen r a b) (hac : ReflTransGen r a c) : Join (ReflTransGen r) b c := by
induction hab with
| refl => exact ⟨c, hac, refl⟩
| @tail d e _ hde ih =>
rcases ih with ⟨b, hdb, hcb⟩
have : ∃ a, ReflTransGen r e a ∧ ReflGen r b a := by
clear hcb
induction hdb with
| refl => exact ⟨e, refl, ReflGen.single hde⟩
| @tail f b _ hfb ih =>
rcases ih with ⟨a, hea, hfa⟩
cases' hfa with _ hfa
· exact ⟨b, hea.tail hfb, ReflGen.refl⟩
· rcases h _ _ _ hfb hfa with ⟨c, hbc, hac⟩
exact ⟨c, hea.trans hac, hbc⟩
rcases this with ⟨a, hea, hba⟩
cases' hba with _ hba
· exact ⟨b, hea, hcb⟩
· exact ⟨a, hea, hcb.tail hba⟩
#align relation.church_rosser Relation.church_rosser
theorem join_of_single (h : Reflexive r) (hab : r a b) : Join r a b :=
⟨b, hab, h b⟩
#align relation.join_of_single Relation.join_of_single
theorem symmetric_join : Symmetric (Join r) := fun _ _ ⟨c, hac, hcb⟩ ↦ ⟨c, hcb, hac⟩
#align relation.symmetric_join Relation.symmetric_join
theorem reflexive_join (h : Reflexive r) : Reflexive (Join r) := fun a ↦ ⟨a, h a, h a⟩
#align relation.reflexive_join Relation.reflexive_join
theorem transitive_join (ht : Transitive r) (h : ∀ a b c, r a b → r a c → Join r b c) :
Transitive (Join r) :=
fun _ b _ ⟨x, hax, hbx⟩ ⟨y, hby, hcy⟩ ↦
let ⟨z, hxz, hyz⟩ := h b x y hbx hby
⟨z, ht hax hxz, ht hcy hyz⟩
#align relation.transitive_join Relation.transitive_join
theorem equivalence_join (hr : Reflexive r) (ht : Transitive r)
(h : ∀ a b c, r a b → r a c → Join r b c) : Equivalence (Join r) :=
⟨reflexive_join hr, @symmetric_join _ _, @transitive_join _ _ ht h⟩
#align relation.equivalence_join Relation.equivalence_join
theorem equivalence_join_reflTransGen
(h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d) :
Equivalence (Join (ReflTransGen r)) :=
equivalence_join reflexive_reflTransGen transitive_reflTransGen fun _ _ _ ↦ church_rosser h
#align relation.equivalence_join_refl_trans_gen Relation.equivalence_join_reflTransGen
theorem join_of_equivalence {r' : α → α → Prop} (hr : Equivalence r) (h : ∀ a b, r' a b → r a b) :
Join r' a b → r a b
| ⟨_, hac, hbc⟩ => hr.trans (h _ _ hac) (hr.symm <| h _ _ hbc)
#align relation.join_of_equivalence Relation.join_of_equivalence
| Mathlib/Logic/Relation.lean | 728 | 732 | theorem reflTransGen_of_transitive_reflexive {r' : α → α → Prop} (hr : Reflexive r)
(ht : Transitive r) (h : ∀ a b, r' a b → r a b) (h' : ReflTransGen r' a b) : r a b := by |
induction' h' with b c _ hbc ih
· exact hr _
· exact ht ih (h _ _ hbc)
|
/-
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.Algebra.CharZero.Lemmas
import Mathlib.Order.Interval.Finset.Basic
#align_import data.int.interval from "leanprover-community/mathlib"@"1d29de43a5ba4662dd33b5cfeecfc2a27a5a8a29"
/-!
# Finite intervals of integers
This file proves that `ℤ` is a `LocallyFiniteOrder` and calculates the cardinality of its
intervals as finsets and fintypes.
-/
open Finset Int
namespace Int
instance instLocallyFiniteOrder : LocallyFiniteOrder ℤ where
finsetIcc a b :=
(Finset.range (b + 1 - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding a
finsetIco a b := (Finset.range (b - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding a
finsetIoc a b :=
(Finset.range (b - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)
finsetIoo a b :=
(Finset.range (b - a - 1).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)
finset_mem_Icc a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
rw [lt_sub_iff_add_lt, Int.lt_add_one_iff, add_comm] at h
exact ⟨Int.le.intro a rfl, h⟩
· rintro ⟨ha, hb⟩
use (x - a).toNat
rw [← lt_add_one_iff] at hb
rw [toNat_sub_of_le ha]
exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩
finset_mem_Ico a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
exact ⟨Int.le.intro a rfl, lt_sub_iff_add_lt'.mp h⟩
· rintro ⟨ha, hb⟩
use (x - a).toNat
rw [toNat_sub_of_le ha]
exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩
finset_mem_Ioc a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
rw [← add_one_le_iff, le_sub_iff_add_le', add_comm _ (1 : ℤ), ← add_assoc] at h
exact ⟨Int.le.intro a rfl, h⟩
· rintro ⟨ha, hb⟩
use (x - (a + 1)).toNat
rw [toNat_sub_of_le ha, ← add_one_le_iff, sub_add, add_sub_cancel_right]
exact ⟨sub_le_sub_right hb _, add_sub_cancel _ _⟩
finset_mem_Ioo a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
rw [sub_sub, lt_sub_iff_add_lt'] at h
exact ⟨Int.le.intro a rfl, h⟩
· rintro ⟨ha, hb⟩
use (x - (a + 1)).toNat
rw [toNat_sub_of_le ha, sub_sub]
exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩
variable (a b : ℤ)
theorem Icc_eq_finset_map :
Icc a b =
(Finset.range (b + 1 - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding a) :=
rfl
#align int.Icc_eq_finset_map Int.Icc_eq_finset_map
theorem Ico_eq_finset_map :
Ico a b = (Finset.range (b - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding a) :=
rfl
#align int.Ico_eq_finset_map Int.Ico_eq_finset_map
theorem Ioc_eq_finset_map :
Ioc a b =
(Finset.range (b - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)) :=
rfl
#align int.Ioc_eq_finset_map Int.Ioc_eq_finset_map
theorem Ioo_eq_finset_map :
Ioo a b =
(Finset.range (b - a - 1).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)) :=
rfl
#align int.Ioo_eq_finset_map Int.Ioo_eq_finset_map
theorem uIcc_eq_finset_map :
uIcc a b = (range (max a b + 1 - min a b).toNat).map
(Nat.castEmbedding.trans <| addLeftEmbedding <| min a b) := rfl
#align int.uIcc_eq_finset_map Int.uIcc_eq_finset_map
@[simp]
theorem card_Icc : (Icc a b).card = (b + 1 - a).toNat := (card_map _).trans <| card_range _
#align int.card_Icc Int.card_Icc
@[simp]
theorem card_Ico : (Ico a b).card = (b - a).toNat := (card_map _).trans <| card_range _
#align int.card_Ico Int.card_Ico
@[simp]
theorem card_Ioc : (Ioc a b).card = (b - a).toNat := (card_map _).trans <| card_range _
#align int.card_Ioc Int.card_Ioc
@[simp]
theorem card_Ioo : (Ioo a b).card = (b - a - 1).toNat := (card_map _).trans <| card_range _
#align int.card_Ioo Int.card_Ioo
@[simp]
theorem card_uIcc : (uIcc a b).card = (b - a).natAbs + 1 :=
(card_map _).trans <|
Int.ofNat.inj <| by
-- Porting note (#11215): TODO: Restore `int.coe_nat_inj` and remove the `change`
change ((↑) : ℕ → ℤ) _ = ((↑) : ℕ → ℤ) _
rw [card_range, sup_eq_max, inf_eq_min,
Int.toNat_of_nonneg (sub_nonneg_of_le <| le_add_one min_le_max), Int.ofNat_add,
Int.natCast_natAbs, add_comm, add_sub_assoc, max_sub_min_eq_abs, add_comm, Int.ofNat_one]
#align int.card_uIcc Int.card_uIcc
| Mathlib/Data/Int/Interval.lean | 133 | 134 | theorem card_Icc_of_le (h : a ≤ b + 1) : ((Icc a b).card : ℤ) = b + 1 - a := by |
rw [card_Icc, toNat_sub_of_le h]
|
/-
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
| .lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean | 42 | 43 | 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]
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker, Anne Baanen
-/
import Mathlib.Algebra.Associated
import Mathlib.Algebra.BigOperators.Finsupp
#align_import algebra.big_operators.associated from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c"
/-!
# Products of associated, prime, and irreducible elements.
This file contains some theorems relating definitions in `Algebra.Associated`
and products of multisets, finsets, and finsupps.
-/
variable {α β γ δ : Type*}
-- the same local notation used in `Algebra.Associated`
local infixl:50 " ~ᵤ " => Associated
namespace Prime
variable [CommMonoidWithZero α] {p : α} (hp : Prime p)
theorem exists_mem_multiset_dvd {s : Multiset α} : p ∣ s.prod → ∃ a ∈ s, p ∣ a :=
Multiset.induction_on s (fun h => (hp.not_dvd_one h).elim) fun a s ih h =>
have : p ∣ a * s.prod := by simpa using h
match hp.dvd_or_dvd this with
| Or.inl h => ⟨a, Multiset.mem_cons_self a s, h⟩
| Or.inr h =>
let ⟨a, has, h⟩ := ih h
⟨a, Multiset.mem_cons_of_mem has, h⟩
#align prime.exists_mem_multiset_dvd Prime.exists_mem_multiset_dvd
theorem exists_mem_multiset_map_dvd {s : Multiset β} {f : β → α} :
p ∣ (s.map f).prod → ∃ a ∈ s, p ∣ f a := fun h => by
simpa only [exists_prop, Multiset.mem_map, exists_exists_and_eq_and] using
hp.exists_mem_multiset_dvd h
#align prime.exists_mem_multiset_map_dvd Prime.exists_mem_multiset_map_dvd
theorem exists_mem_finset_dvd {s : Finset β} {f : β → α} : p ∣ s.prod f → ∃ i ∈ s, p ∣ f i :=
hp.exists_mem_multiset_map_dvd
#align prime.exists_mem_finset_dvd Prime.exists_mem_finset_dvd
end Prime
theorem Prod.associated_iff {M N : Type*} [Monoid M] [Monoid N] {x z : M × N} :
x ~ᵤ z ↔ x.1 ~ᵤ z.1 ∧ x.2 ~ᵤ z.2 :=
⟨fun ⟨u, hu⟩ => ⟨⟨(MulEquiv.prodUnits.toFun u).1, (Prod.eq_iff_fst_eq_snd_eq.1 hu).1⟩,
⟨(MulEquiv.prodUnits.toFun u).2, (Prod.eq_iff_fst_eq_snd_eq.1 hu).2⟩⟩,
fun ⟨⟨u₁, h₁⟩, ⟨u₂, h₂⟩⟩ =>
⟨MulEquiv.prodUnits.invFun (u₁, u₂), Prod.eq_iff_fst_eq_snd_eq.2 ⟨h₁, h₂⟩⟩⟩
theorem Associated.prod {M : Type*} [CommMonoid M] {ι : Type*} (s : Finset ι) (f : ι → M)
(g : ι → M) (h : ∀ i, i ∈ s → (f i) ~ᵤ (g i)) : (∏ i ∈ s, f i) ~ᵤ (∏ i ∈ s, g i) := by
induction s using Finset.induction with
| empty =>
simp only [Finset.prod_empty]
rfl
| @insert j s hjs IH =>
classical
convert_to (∏ i ∈ insert j s, f i) ~ᵤ (∏ i ∈ insert j s, g i)
rw [Finset.prod_insert hjs, Finset.prod_insert hjs]
exact Associated.mul_mul (h j (Finset.mem_insert_self j s))
(IH (fun i hi ↦ h i (Finset.mem_insert_of_mem hi)))
theorem exists_associated_mem_of_dvd_prod [CancelCommMonoidWithZero α] {p : α} (hp : Prime p)
{s : Multiset α} : (∀ r ∈ s, Prime r) → p ∣ s.prod → ∃ q ∈ s, p ~ᵤ q :=
Multiset.induction_on s (by simp [mt isUnit_iff_dvd_one.2 hp.not_unit]) fun a s ih hs hps => by
rw [Multiset.prod_cons] at hps
cases' hp.dvd_or_dvd hps with h h
· have hap := hs a (Multiset.mem_cons.2 (Or.inl rfl))
exact ⟨a, Multiset.mem_cons_self a _, hp.associated_of_dvd hap h⟩
· rcases ih (fun r hr => hs _ (Multiset.mem_cons.2 (Or.inr hr))) h with ⟨q, hq₁, hq₂⟩
exact ⟨q, Multiset.mem_cons.2 (Or.inr hq₁), hq₂⟩
#align exists_associated_mem_of_dvd_prod exists_associated_mem_of_dvd_prod
| Mathlib/Algebra/BigOperators/Associated.lean | 82 | 100 | theorem Multiset.prod_primes_dvd [CancelCommMonoidWithZero α]
[∀ a : α, DecidablePred (Associated a)] {s : Multiset α} (n : α) (h : ∀ a ∈ s, Prime a)
(div : ∀ a ∈ s, a ∣ n) (uniq : ∀ a, s.countP (Associated a) ≤ 1) : s.prod ∣ n := by |
induction' s using Multiset.induction_on with a s induct n primes divs generalizing n
· simp only [Multiset.prod_zero, one_dvd]
· rw [Multiset.prod_cons]
obtain ⟨k, rfl⟩ : a ∣ n := div a (Multiset.mem_cons_self a s)
apply mul_dvd_mul_left a
refine induct _ (fun a ha => h a (Multiset.mem_cons_of_mem ha)) (fun b b_in_s => ?_)
fun a => (Multiset.countP_le_of_le _ (Multiset.le_cons_self _ _)).trans (uniq a)
have b_div_n := div b (Multiset.mem_cons_of_mem b_in_s)
have a_prime := h a (Multiset.mem_cons_self a s)
have b_prime := h b (Multiset.mem_cons_of_mem b_in_s)
refine (b_prime.dvd_or_dvd b_div_n).resolve_left fun b_div_a => ?_
have assoc := b_prime.associated_of_dvd a_prime b_div_a
have := uniq a
rw [Multiset.countP_cons_of_pos _ (Associated.refl _), Nat.succ_le_succ_iff, ← not_lt,
Multiset.countP_pos] at this
exact this ⟨b, b_in_s, assoc.symm⟩
|
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.ContDiff.Bounds
import Mathlib.Analysis.Calculus.IteratedDeriv.Defs
import Mathlib.Analysis.Calculus.LineDeriv.Basic
import Mathlib.Analysis.LocallyConvex.WithSeminorms
import Mathlib.Analysis.Normed.Group.ZeroAtInfty
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Analysis.SpecialFunctions.JapaneseBracket
import Mathlib.Topology.Algebra.UniformFilterBasis
import Mathlib.Tactic.MoveAdd
#align_import analysis.schwartz_space from "leanprover-community/mathlib"@"e137999b2c6f2be388f4cd3bbf8523de1910cd2b"
/-!
# Schwartz space
This file defines the Schwartz space. Usually, the Schwartz space is defined as the set of smooth
functions $f : ℝ^n → ℂ$ such that there exists $C_{αβ} > 0$ with $$|x^α ∂^β f(x)| < C_{αβ}$$ for
all $x ∈ ℝ^n$ and for all multiindices $α, β$.
In mathlib, we use a slightly different approach and define the Schwartz space as all
smooth functions `f : E → F`, where `E` and `F` are real normed vector spaces such that for all
natural numbers `k` and `n` we have uniform bounds `‖x‖^k * ‖iteratedFDeriv ℝ n f x‖ < C`.
This approach completely avoids using partial derivatives as well as polynomials.
We construct the topology on the Schwartz space by a family of seminorms, which are the best
constants in the above estimates. The abstract theory of topological vector spaces developed in
`SeminormFamily.moduleFilterBasis` and `WithSeminorms.toLocallyConvexSpace` turns the
Schwartz space into a locally convex topological vector space.
## Main definitions
* `SchwartzMap`: The Schwartz space is the space of smooth functions such that all derivatives
decay faster than any power of `‖x‖`.
* `SchwartzMap.seminorm`: The family of seminorms as described above
* `SchwartzMap.fderivCLM`: The differential as a continuous linear map
`𝓢(E, F) →L[𝕜] 𝓢(E, E →L[ℝ] F)`
* `SchwartzMap.derivCLM`: The one-dimensional derivative as a continuous linear map
`𝓢(ℝ, F) →L[𝕜] 𝓢(ℝ, F)`
* `SchwartzMap.integralCLM`: Integration as a continuous linear map `𝓢(ℝ, F) →L[ℝ] F`
## Main statements
* `SchwartzMap.instUniformAddGroup` and `SchwartzMap.instLocallyConvexSpace`: The Schwartz space
is a locally convex topological vector space.
* `SchwartzMap.one_add_le_sup_seminorm_apply`: For a Schwartz function `f` there is a uniform bound
on `(1 + ‖x‖) ^ k * ‖iteratedFDeriv ℝ n f x‖`.
## Implementation details
The implementation of the seminorms is taken almost literally from `ContinuousLinearMap.opNorm`.
## Notation
* `𝓢(E, F)`: The Schwartz space `SchwartzMap E F` localized in `SchwartzSpace`
## Tags
Schwartz space, tempered distributions
-/
noncomputable section
open scoped Nat NNReal
variable {𝕜 𝕜' D E F G V : Type*}
variable [NormedAddCommGroup E] [NormedSpace ℝ E]
variable [NormedAddCommGroup F] [NormedSpace ℝ F]
variable (E F)
/-- A function is a Schwartz function if it is smooth and all derivatives decay faster than
any power of `‖x‖`. -/
structure SchwartzMap where
toFun : E → F
smooth' : ContDiff ℝ ⊤ toFun
decay' : ∀ k n : ℕ, ∃ C : ℝ, ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n toFun x‖ ≤ C
#align schwartz_map SchwartzMap
/-- A function is a Schwartz function if it is smooth and all derivatives decay faster than
any power of `‖x‖`. -/
scoped[SchwartzMap] notation "𝓢(" E ", " F ")" => SchwartzMap E F
variable {E F}
namespace SchwartzMap
-- Porting note: removed
-- instance : Coe 𝓢(E, F) (E → F) := ⟨toFun⟩
instance instFunLike : FunLike 𝓢(E, F) E F where
coe f := f.toFun
coe_injective' f g h := by cases f; cases g; congr
#align schwartz_map.fun_like SchwartzMap.instFunLike
/-- Helper instance for when there's too many metavariables to apply `DFunLike.hasCoeToFun`. -/
instance instCoeFun : CoeFun 𝓢(E, F) fun _ => E → F :=
DFunLike.hasCoeToFun
#align schwartz_map.has_coe_to_fun SchwartzMap.instCoeFun
/-- All derivatives of a Schwartz function are rapidly decaying. -/
theorem decay (f : 𝓢(E, F)) (k n : ℕ) :
∃ C : ℝ, 0 < C ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ C := by
rcases f.decay' k n with ⟨C, hC⟩
exact ⟨max C 1, by positivity, fun x => (hC x).trans (le_max_left _ _)⟩
#align schwartz_map.decay SchwartzMap.decay
/-- Every Schwartz function is smooth. -/
theorem smooth (f : 𝓢(E, F)) (n : ℕ∞) : ContDiff ℝ n f :=
f.smooth'.of_le le_top
#align schwartz_map.smooth SchwartzMap.smooth
/-- Every Schwartz function is continuous. -/
@[continuity]
protected theorem continuous (f : 𝓢(E, F)) : Continuous f :=
(f.smooth 0).continuous
#align schwartz_map.continuous SchwartzMap.continuous
instance instContinuousMapClass : ContinuousMapClass 𝓢(E, F) E F where
map_continuous := SchwartzMap.continuous
/-- Every Schwartz function is differentiable. -/
protected theorem differentiable (f : 𝓢(E, F)) : Differentiable ℝ f :=
(f.smooth 1).differentiable rfl.le
#align schwartz_map.differentiable SchwartzMap.differentiable
/-- Every Schwartz function is differentiable at any point. -/
protected theorem differentiableAt (f : 𝓢(E, F)) {x : E} : DifferentiableAt ℝ f x :=
f.differentiable.differentiableAt
#align schwartz_map.differentiable_at SchwartzMap.differentiableAt
@[ext]
theorem ext {f g : 𝓢(E, F)} (h : ∀ x, (f : E → F) x = g x) : f = g :=
DFunLike.ext f g h
#align schwartz_map.ext SchwartzMap.ext
section IsBigO
open Asymptotics Filter
variable (f : 𝓢(E, F))
/-- Auxiliary lemma, used in proving the more general result `isBigO_cocompact_rpow`. -/
theorem isBigO_cocompact_zpow_neg_nat (k : ℕ) :
f =O[cocompact E] fun x => ‖x‖ ^ (-k : ℤ) := by
obtain ⟨d, _, hd'⟩ := f.decay k 0
simp only [norm_iteratedFDeriv_zero] at hd'
simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith]
refine ⟨d, Filter.Eventually.filter_mono Filter.cocompact_le_cofinite ?_⟩
refine (Filter.eventually_cofinite_ne 0).mono fun x hx => ?_
rw [Real.norm_of_nonneg (zpow_nonneg (norm_nonneg _) _), zpow_neg, ← div_eq_mul_inv, le_div_iff']
exacts [hd' x, zpow_pos_of_pos (norm_pos_iff.mpr hx) _]
set_option linter.uppercaseLean3 false in
#align schwartz_map.is_O_cocompact_zpow_neg_nat SchwartzMap.isBigO_cocompact_zpow_neg_nat
| Mathlib/Analysis/Distribution/SchwartzSpace.lean | 157 | 169 | theorem isBigO_cocompact_rpow [ProperSpace E] (s : ℝ) :
f =O[cocompact E] fun x => ‖x‖ ^ s := by |
let k := ⌈-s⌉₊
have hk : -(k : ℝ) ≤ s := neg_le.mp (Nat.le_ceil (-s))
refine (isBigO_cocompact_zpow_neg_nat f k).trans ?_
suffices (fun x : ℝ => x ^ (-k : ℤ)) =O[atTop] fun x : ℝ => x ^ s
from this.comp_tendsto tendsto_norm_cocompact_atTop
simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith]
refine ⟨1, (Filter.eventually_ge_atTop 1).mono fun x hx => ?_⟩
rw [one_mul, Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans hx) _),
Real.norm_of_nonneg (zpow_nonneg (zero_le_one.trans hx) _), ← Real.rpow_intCast, Int.cast_neg,
Int.cast_natCast]
exact Real.rpow_le_rpow_of_exponent_le hx hk
|
/-
Copyright (c) 2018 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.Module.Pi
#align_import data.holor from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226"
/-!
# Basic properties of holors
Holors are indexed collections of tensor coefficients. Confusingly,
they are often called tensors in physics and in the neural network
community.
A holor is simply a multidimensional array of values. The size of a
holor is specified by a `List ℕ`, whose length is called the dimension
of the holor.
The tensor product of `x₁ : Holor α ds₁` and `x₂ : Holor α ds₂` is the
holor given by `(x₁ ⊗ x₂) (i₁ ++ i₂) = x₁ i₁ * x₂ i₂`. A holor is "of
rank at most 1" if it is a tensor product of one-dimensional holors.
The CP rank of a holor `x` is the smallest N such that `x` is the sum
of N holors of rank at most 1.
Based on the tensor library found in <https://www.isa-afp.org/entries/Deep_Learning.html>
## References
* <https://en.wikipedia.org/wiki/Tensor_rank_decomposition>
-/
universe u
open List
/-- `HolorIndex ds` is the type of valid index tuples used to identify an entry of a holor
of dimensions `ds`. -/
def HolorIndex (ds : List ℕ) : Type :=
{ is : List ℕ // Forall₂ (· < ·) is ds }
#align holor_index HolorIndex
namespace HolorIndex
variable {ds₁ ds₂ ds₃ : List ℕ}
def take : ∀ {ds₁ : List ℕ}, HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₁
| ds, is => ⟨List.take (length ds) is.1, forall₂_take_append is.1 ds ds₂ is.2⟩
#align holor_index.take HolorIndex.take
def drop : ∀ {ds₁ : List ℕ}, HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₂
| ds, is => ⟨List.drop (length ds) is.1, forall₂_drop_append is.1 ds ds₂ is.2⟩
#align holor_index.drop HolorIndex.drop
theorem cast_type (is : List ℕ) (eq : ds₁ = ds₂) (h : Forall₂ (· < ·) is ds₁) :
(cast (congr_arg HolorIndex eq) ⟨is, h⟩).val = is := by subst eq; rfl
#align holor_index.cast_type HolorIndex.cast_type
def assocRight : HolorIndex (ds₁ ++ ds₂ ++ ds₃) → HolorIndex (ds₁ ++ (ds₂ ++ ds₃)) :=
cast (congr_arg HolorIndex (append_assoc ds₁ ds₂ ds₃))
#align holor_index.assoc_right HolorIndex.assocRight
def assocLeft : HolorIndex (ds₁ ++ (ds₂ ++ ds₃)) → HolorIndex (ds₁ ++ ds₂ ++ ds₃) :=
cast (congr_arg HolorIndex (append_assoc ds₁ ds₂ ds₃).symm)
#align holor_index.assoc_left HolorIndex.assocLeft
theorem take_take : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.take = t.take.take
| ⟨is, h⟩ =>
Subtype.eq <| by
simp [assocRight, take, cast_type, List.take_take, Nat.le_add_right, min_eq_left]
#align holor_index.take_take HolorIndex.take_take
theorem drop_take : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.drop.take = t.take.drop
| ⟨is, h⟩ => Subtype.eq (by simp [assocRight, take, drop, cast_type, List.drop_take])
#align holor_index.drop_take HolorIndex.drop_take
theorem drop_drop : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.drop.drop = t.drop
| ⟨is, h⟩ => Subtype.eq (by simp [add_comm, assocRight, drop, cast_type, List.drop_drop])
#align holor_index.drop_drop HolorIndex.drop_drop
end HolorIndex
/-- Holor (indexed collections of tensor coefficients) -/
def Holor (α : Type u) (ds : List ℕ) :=
HolorIndex ds → α
#align holor Holor
namespace Holor
variable {α : Type} {d : ℕ} {ds : List ℕ} {ds₁ : List ℕ} {ds₂ : List ℕ} {ds₃ : List ℕ}
instance [Inhabited α] : Inhabited (Holor α ds) :=
⟨fun _ => default⟩
instance [Zero α] : Zero (Holor α ds) :=
⟨fun _ => 0⟩
instance [Add α] : Add (Holor α ds) :=
⟨fun x y t => x t + y t⟩
instance [Neg α] : Neg (Holor α ds) :=
⟨fun a t => -a t⟩
instance [AddSemigroup α] : AddSemigroup (Holor α ds) := Pi.addSemigroup
instance [AddCommSemigroup α] : AddCommSemigroup (Holor α ds) := Pi.addCommSemigroup
instance [AddMonoid α] : AddMonoid (Holor α ds) := Pi.addMonoid
instance [AddCommMonoid α] : AddCommMonoid (Holor α ds) := Pi.addCommMonoid
instance [AddGroup α] : AddGroup (Holor α ds) := Pi.addGroup
instance [AddCommGroup α] : AddCommGroup (Holor α ds) := Pi.addCommGroup
-- scalar product
instance [Mul α] : SMul α (Holor α ds) :=
⟨fun a x => fun t => a * x t⟩
instance [Semiring α] : Module α (Holor α ds) := Pi.module _ _ _
/-- The tensor product of two holors. -/
def mul [Mul α] (x : Holor α ds₁) (y : Holor α ds₂) : Holor α (ds₁ ++ ds₂) := fun t =>
x t.take * y t.drop
#align holor.mul Holor.mul
local infixl:70 " ⊗ " => mul
theorem cast_type (eq : ds₁ = ds₂) (a : Holor α ds₁) :
cast (congr_arg (Holor α) eq) a = fun t => a (cast (congr_arg HolorIndex eq.symm) t) := by
subst eq; rfl
#align holor.cast_type Holor.cast_type
def assocRight : Holor α (ds₁ ++ ds₂ ++ ds₃) → Holor α (ds₁ ++ (ds₂ ++ ds₃)) :=
cast (congr_arg (Holor α) (append_assoc ds₁ ds₂ ds₃))
#align holor.assoc_right Holor.assocRight
def assocLeft : Holor α (ds₁ ++ (ds₂ ++ ds₃)) → Holor α (ds₁ ++ ds₂ ++ ds₃) :=
cast (congr_arg (Holor α) (append_assoc ds₁ ds₂ ds₃).symm)
#align holor.assoc_left Holor.assocLeft
theorem mul_assoc0 [Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃) :
x ⊗ y ⊗ z = (x ⊗ (y ⊗ z)).assocLeft :=
funext fun t : HolorIndex (ds₁ ++ ds₂ ++ ds₃) => by
rw [assocLeft]
unfold mul
rw [mul_assoc, ← HolorIndex.take_take, ← HolorIndex.drop_take, ← HolorIndex.drop_drop,
cast_type]
· rfl
rw [append_assoc]
#align holor.mul_assoc0 Holor.mul_assoc0
theorem mul_assoc [Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃) :
HEq (mul (mul x y) z) (mul x (mul y z)) := by simp [cast_heq, mul_assoc0, assocLeft]
#align holor.mul_assoc Holor.mul_assoc
theorem mul_left_distrib [Distrib α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₂) :
x ⊗ (y + z) = x ⊗ y + x ⊗ z := funext fun t => left_distrib (x t.take) (y t.drop) (z t.drop)
#align holor.mul_left_distrib Holor.mul_left_distrib
theorem mul_right_distrib [Distrib α] (x : Holor α ds₁) (y : Holor α ds₁) (z : Holor α ds₂) :
(x + y) ⊗ z = x ⊗ z + y ⊗ z := funext fun t => add_mul (x t.take) (y t.take) (z t.drop)
#align holor.mul_right_distrib Holor.mul_right_distrib
@[simp]
nonrec theorem zero_mul {α : Type} [Ring α] (x : Holor α ds₂) : (0 : Holor α ds₁) ⊗ x = 0 :=
funext fun t => zero_mul (x (HolorIndex.drop t))
#align holor.zero_mul Holor.zero_mul
@[simp]
nonrec theorem mul_zero {α : Type} [Ring α] (x : Holor α ds₁) : x ⊗ (0 : Holor α ds₂) = 0 :=
funext fun t => mul_zero (x (HolorIndex.take t))
#align holor.mul_zero Holor.mul_zero
theorem mul_scalar_mul [Monoid α] (x : Holor α []) (y : Holor α ds) :
x ⊗ y = x ⟨[], Forall₂.nil⟩ • y := by
simp (config := { unfoldPartialApp := true }) [mul, SMul.smul, HolorIndex.take, HolorIndex.drop,
HSMul.hSMul]
#align holor.mul_scalar_mul Holor.mul_scalar_mul
-- holor slices
/-- A slice is a subholor consisting of all entries with initial index i. -/
def slice (x : Holor α (d :: ds)) (i : ℕ) (h : i < d) : Holor α ds := fun is : HolorIndex ds =>
x ⟨i :: is.1, Forall₂.cons h is.2⟩
#align holor.slice Holor.slice
/-- The 1-dimensional "unit" holor with 1 in the `j`th position. -/
def unitVec [Monoid α] [AddMonoid α] (d : ℕ) (j : ℕ) : Holor α [d] := fun ti =>
if ti.1 = [j] then 1 else 0
#align holor.unit_vec Holor.unitVec
theorem holor_index_cons_decomp (p : HolorIndex (d :: ds) → Prop) :
∀ t : HolorIndex (d :: ds),
(∀ i is, ∀ h : t.1 = i :: is, p ⟨i :: is, by rw [← h]; exact t.2⟩) → p t
| ⟨[], hforall₂⟩, _ => absurd (forall₂_nil_left_iff.1 hforall₂) (cons_ne_nil d ds)
| ⟨i :: is, _⟩, hp => hp i is rfl
#align holor.holor_index_cons_decomp Holor.holor_index_cons_decomp
/-- Two holors are equal if all their slices are equal. -/
theorem slice_eq (x : Holor α (d :: ds)) (y : Holor α (d :: ds)) (h : slice x = slice y) : x = y :=
funext fun t : HolorIndex (d :: ds) =>
holor_index_cons_decomp (fun t => x t = y t) t fun i is hiis =>
have hiisdds : Forall₂ (· < ·) (i :: is) (d :: ds) := by rw [← hiis]; exact t.2
have hid : i < d := (forall₂_cons.1 hiisdds).1
have hisds : Forall₂ (· < ·) is ds := (forall₂_cons.1 hiisdds).2
calc
x ⟨i :: is, _⟩ = slice x i hid ⟨is, hisds⟩ := congr_arg (fun t => x t) (Subtype.eq rfl)
_ = slice y i hid ⟨is, hisds⟩ := by rw [h]
_ = y ⟨i :: is, _⟩ := congr_arg (fun t => y t) (Subtype.eq rfl)
#align holor.slice_eq Holor.slice_eq
theorem slice_unitVec_mul [Ring α] {i : ℕ} {j : ℕ} (hid : i < d) (x : Holor α ds) :
slice (unitVec d j ⊗ x) i hid = if i = j then x else 0 :=
funext fun t : HolorIndex ds =>
if h : i = j then by simp [slice, mul, HolorIndex.take, unitVec, HolorIndex.drop, h]
else by simp [slice, mul, HolorIndex.take, unitVec, HolorIndex.drop, h]; rfl
#align holor.slice_unit_vec_mul Holor.slice_unitVec_mul
theorem slice_add [Add α] (i : ℕ) (hid : i < d) (x : Holor α (d :: ds)) (y : Holor α (d :: ds)) :
slice x i hid + slice y i hid = slice (x + y) i hid :=
funext fun t => by simp [slice, (· + ·), Add.add]
#align holor.slice_add Holor.slice_add
theorem slice_zero [Zero α] (i : ℕ) (hid : i < d) : slice (0 : Holor α (d :: ds)) i hid = 0 :=
rfl
#align holor.slice_zero Holor.slice_zero
theorem slice_sum [AddCommMonoid α] {β : Type} (i : ℕ) (hid : i < d) (s : Finset β)
(f : β → Holor α (d :: ds)) : (∑ x ∈ s, slice (f x) i hid) = slice (∑ x ∈ s, f x) i hid := by
letI := Classical.decEq β
refine Finset.induction_on s ?_ ?_
· simp [slice_zero]
· intro _ _ h_not_in ih
rw [Finset.sum_insert h_not_in, ih, slice_add, Finset.sum_insert h_not_in]
#align holor.slice_sum Holor.slice_sum
/-- The original holor can be recovered from its slices by multiplying with unit vectors and
summing up. -/
@[simp]
theorem sum_unitVec_mul_slice [Ring α] (x : Holor α (d :: ds)) :
(∑ i ∈ (Finset.range d).attach,
unitVec d i ⊗ slice x i (Nat.succ_le_of_lt (Finset.mem_range.1 i.prop))) =
x := by
apply slice_eq _ _ _
ext i hid
rw [← slice_sum]
simp only [slice_unitVec_mul hid]
rw [Finset.sum_eq_single (Subtype.mk i <| Finset.mem_range.2 hid)]
· simp
· intro (b : { x // x ∈ Finset.range d }) (_ : b ∈ (Finset.range d).attach) (hbi : b ≠ ⟨i, _⟩)
have hbi' : i ≠ b := by simpa only [Ne, Subtype.ext_iff, Subtype.coe_mk] using hbi.symm
simp [hbi']
· intro (hid' : Subtype.mk i _ ∉ Finset.attach (Finset.range d))
exfalso
exact absurd (Finset.mem_attach _ _) hid'
#align holor.sum_unit_vec_mul_slice Holor.sum_unitVec_mul_slice
-- CP rank
/-- `CPRankMax1 x` means `x` has CP rank at most 1, that is,
it is the tensor product of 1-dimensional holors. -/
inductive CPRankMax1 [Mul α] : ∀ {ds}, Holor α ds → Prop
| nil (x : Holor α []) : CPRankMax1 x
| cons {d} {ds} (x : Holor α [d]) (y : Holor α ds) : CPRankMax1 y → CPRankMax1 (x ⊗ y)
#align holor.cprank_max1 Holor.CPRankMax1
/-- `CPRankMax N x` means `x` has CP rank at most `N`, that is,
it can be written as the sum of N holors of rank at most 1. -/
inductive CPRankMax [Mul α] [AddMonoid α] : ℕ → ∀ {ds}, Holor α ds → Prop
| zero {ds} : CPRankMax 0 (0 : Holor α ds)
| succ (n) {ds} (x : Holor α ds) (y : Holor α ds) :
CPRankMax1 x → CPRankMax n y → CPRankMax (n + 1) (x + y)
#align holor.cprank_max Holor.CPRankMax
theorem cprankMax_nil [Monoid α] [AddMonoid α] (x : Holor α nil) : CPRankMax 1 x := by
have h := CPRankMax.succ 0 x 0 (CPRankMax1.nil x) CPRankMax.zero
rwa [add_zero x, zero_add] at h
#align holor.cprank_max_nil Holor.cprankMax_nil
| Mathlib/Data/Holor.lean | 282 | 285 | theorem cprankMax_1 [Monoid α] [AddMonoid α] {x : Holor α ds} (h : CPRankMax1 x) :
CPRankMax 1 x := by |
have h' := CPRankMax.succ 0 x 0 h CPRankMax.zero
rwa [zero_add, add_zero] at h'
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad
-/
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Data.Set.Finite
#align_import order.filter.basic from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494"
/-!
# Theory of filters on sets
## Main definitions
* `Filter` : filters on a set;
* `Filter.principal` : filter of all sets containing a given set;
* `Filter.map`, `Filter.comap` : operations on filters;
* `Filter.Tendsto` : limit with respect to filters;
* `Filter.Eventually` : `f.eventually p` means `{x | p x} ∈ f`;
* `Filter.Frequently` : `f.frequently p` means `{x | ¬p x} ∉ f`;
* `filter_upwards [h₁, ..., hₙ]` :
a tactic that takes a list of proofs `hᵢ : sᵢ ∈ f`,
and replaces a goal `s ∈ f` with `∀ x, x ∈ s₁ → ... → x ∈ sₙ → x ∈ s`;
* `Filter.NeBot f` : a utility class stating that `f` is a non-trivial filter.
Filters on a type `X` are sets of sets of `X` satisfying three conditions. They are mostly used to
abstract two related kinds of ideas:
* *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions
at a point or at infinity, etc...
* *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough
a point `x`, or for close enough pairs of points, or things happening almost everywhere in the
sense of measure theory. Dually, filters can also express the idea of *things happening often*:
for arbitrarily large `n`, or at a point in any neighborhood of given a point etc...
In this file, we define the type `Filter X` of filters on `X`, and endow it with a complete lattice
structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois
insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to
the smallest filter containing it in the other direction.
We also prove `Filter` is a monadic functor, with a push-forward operation
`Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the
order on filters.
The examples of filters appearing in the description of the two motivating ideas are:
* `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N`
* `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic)
* `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces
defined in `Mathlib/Topology/UniformSpace/Basic.lean`)
* `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ`
(defined in `Mathlib/MeasureTheory/OuterMeasure/AE`)
The general notion of limit of a map with respect to filters on the source and target types
is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation.
The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is
`Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come
rather late in this file in order to immediately relate them to the lattice structure).
For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to
some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of
`M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`,
which is a special case of `mem_closure_of_tendsto` from Topology.Basic.
## Notations
* `∀ᶠ x in f, p x` : `f.Eventually p`;
* `∃ᶠ x in f, p x` : `f.Frequently p`;
* `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`;
* `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`;
* `𝓟 s` : `Filter.Principal s`, localized in `Filter`.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which
we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element
`⊥` for its lattice structure, at the cost of including the assumption
`[NeBot f]` in a number of lemmas and definitions.
-/
set_option autoImplicit true
open Function Set Order
open scoped Classical
universe u v w x y
/-- A filter `F` on a type `α` is a collection of sets of `α` which contains the whole `α`,
is upwards-closed, and is stable under intersection. We do not forbid this collection to be
all sets of `α`. -/
structure Filter (α : Type*) where
/-- The set of sets that belong to the filter. -/
sets : Set (Set α)
/-- The set `Set.univ` belongs to any filter. -/
univ_sets : Set.univ ∈ sets
/-- If a set belongs to a filter, then its superset belongs to the filter as well. -/
sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets
/-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/
inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets
#align filter Filter
/-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/
instance {α : Type*} : Membership (Set α) (Filter α) :=
⟨fun U F => U ∈ F.sets⟩
namespace Filter
variable {α : Type u} {f g : Filter α} {s t : Set α}
@[simp]
protected theorem mem_mk {t : Set (Set α)} {h₁ h₂ h₃} : s ∈ mk t h₁ h₂ h₃ ↔ s ∈ t :=
Iff.rfl
#align filter.mem_mk Filter.mem_mk
@[simp]
protected theorem mem_sets : s ∈ f.sets ↔ s ∈ f :=
Iff.rfl
#align filter.mem_sets Filter.mem_sets
instance inhabitedMem : Inhabited { s : Set α // s ∈ f } :=
⟨⟨univ, f.univ_sets⟩⟩
#align filter.inhabited_mem Filter.inhabitedMem
theorem filter_eq : ∀ {f g : Filter α}, f.sets = g.sets → f = g
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
#align filter.filter_eq Filter.filter_eq
theorem filter_eq_iff : f = g ↔ f.sets = g.sets :=
⟨congr_arg _, filter_eq⟩
#align filter.filter_eq_iff Filter.filter_eq_iff
protected theorem ext_iff : f = g ↔ ∀ s, s ∈ f ↔ s ∈ g := by
simp only [filter_eq_iff, ext_iff, Filter.mem_sets]
#align filter.ext_iff Filter.ext_iff
@[ext]
protected theorem ext : (∀ s, s ∈ f ↔ s ∈ g) → f = g :=
Filter.ext_iff.2
#align filter.ext Filter.ext
/-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g.,
`Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/
protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g :=
Filter.ext <| compl_surjective.forall.2 h
#align filter.coext Filter.coext
@[simp]
theorem univ_mem : univ ∈ f :=
f.univ_sets
#align filter.univ_mem Filter.univ_mem
theorem mem_of_superset {x y : Set α} (hx : x ∈ f) (hxy : x ⊆ y) : y ∈ f :=
f.sets_of_superset hx hxy
#align filter.mem_of_superset Filter.mem_of_superset
instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where
trans h₁ h₂ := mem_of_superset h₂ h₁
theorem inter_mem {s t : Set α} (hs : s ∈ f) (ht : t ∈ f) : s ∩ t ∈ f :=
f.inter_sets hs ht
#align filter.inter_mem Filter.inter_mem
@[simp]
theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f :=
⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩,
and_imp.2 inter_mem⟩
#align filter.inter_mem_iff Filter.inter_mem_iff
theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f :=
inter_mem hs ht
#align filter.diff_mem Filter.diff_mem
theorem univ_mem' (h : ∀ a, a ∈ s) : s ∈ f :=
mem_of_superset univ_mem fun x _ => h x
#align filter.univ_mem' Filter.univ_mem'
theorem mp_mem (hs : s ∈ f) (h : { x | x ∈ s → x ∈ t } ∈ f) : t ∈ f :=
mem_of_superset (inter_mem hs h) fun _ ⟨h₁, h₂⟩ => h₂ h₁
#align filter.mp_mem Filter.mp_mem
theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f :=
⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs =>
mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩
#align filter.congr_sets Filter.congr_sets
/-- Override `sets` field of a filter to provide better definitional equality. -/
protected def copy (f : Filter α) (S : Set (Set α)) (hmem : ∀ s, s ∈ S ↔ s ∈ f) : Filter α where
sets := S
univ_sets := (hmem _).2 univ_mem
sets_of_superset h hsub := (hmem _).2 <| mem_of_superset ((hmem _).1 h) hsub
inter_sets h₁ h₂ := (hmem _).2 <| inter_mem ((hmem _).1 h₁) ((hmem _).1 h₂)
lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem
@[simp] lemma mem_copy {S hmem} : s ∈ f.copy S hmem ↔ s ∈ S := Iff.rfl
@[simp]
theorem biInter_mem {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Finite) :
(⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f :=
Finite.induction_on hf (by simp) fun _ _ hs => by simp [hs]
#align filter.bInter_mem Filter.biInter_mem
@[simp]
theorem biInter_finset_mem {β : Type v} {s : β → Set α} (is : Finset β) :
(⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f :=
biInter_mem is.finite_toSet
#align filter.bInter_finset_mem Filter.biInter_finset_mem
alias _root_.Finset.iInter_mem_sets := biInter_finset_mem
#align finset.Inter_mem_sets Finset.iInter_mem_sets
-- attribute [protected] Finset.iInter_mem_sets porting note: doesn't work
@[simp]
theorem sInter_mem {s : Set (Set α)} (hfin : s.Finite) : ⋂₀ s ∈ f ↔ ∀ U ∈ s, U ∈ f := by
rw [sInter_eq_biInter, biInter_mem hfin]
#align filter.sInter_mem Filter.sInter_mem
@[simp]
theorem iInter_mem {β : Sort v} {s : β → Set α} [Finite β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f :=
(sInter_mem (finite_range _)).trans forall_mem_range
#align filter.Inter_mem Filter.iInter_mem
theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f :=
⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩
#align filter.exists_mem_subset_iff Filter.exists_mem_subset_iff
theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h =>
mem_of_superset h hst
#align filter.monotone_mem Filter.monotone_mem
theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P)
(hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by
constructor
· rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩
exact
⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩
· rintro ⟨u, huf, hPu, hQu⟩
exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩
#align filter.exists_mem_and_iff Filter.exists_mem_and_iff
theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} :
(∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b :=
Set.forall_in_swap
#align filter.forall_in_swap Filter.forall_in_swap
end Filter
namespace Mathlib.Tactic
open Lean Meta Elab Tactic
/--
`filter_upwards [h₁, ⋯, hₙ]` replaces a goal of the form `s ∈ f` and terms
`h₁ : t₁ ∈ f, ⋯, hₙ : tₙ ∈ f` with `∀ x, x ∈ t₁ → ⋯ → x ∈ tₙ → x ∈ s`.
The list is an optional parameter, `[]` being its default value.
`filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ` is a short form for
`{ filter_upwards [h₁, ⋯, hₙ], intros a₁ a₂ ⋯ aₖ }`.
`filter_upwards [h₁, ⋯, hₙ] using e` is a short form for
`{ filter_upwards [h1, ⋯, hn], exact e }`.
Combining both shortcuts is done by writing `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ using e`.
Note that in this case, the `aᵢ` terms can be used in `e`.
-/
syntax (name := filterUpwards) "filter_upwards" (" [" term,* "]")?
(" with" (ppSpace colGt term:max)*)? (" using " term)? : tactic
elab_rules : tactic
| `(tactic| filter_upwards $[[$[$args],*]]? $[with $wth*]? $[using $usingArg]?) => do
let config : ApplyConfig := {newGoals := ApplyNewGoals.nonDependentOnly}
for e in args.getD #[] |>.reverse do
let goal ← getMainGoal
replaceMainGoal <| ← goal.withContext <| runTermElab do
let m ← mkFreshExprMVar none
let lem ← Term.elabTermEnsuringType
(← ``(Filter.mp_mem $e $(← Term.exprToSyntax m))) (← goal.getType)
goal.assign lem
return [m.mvarId!]
liftMetaTactic fun goal => do
goal.apply (← mkConstWithFreshMVarLevels ``Filter.univ_mem') config
evalTactic <|← `(tactic| dsimp (config := {zeta := false}) only [Set.mem_setOf_eq])
if let some l := wth then
evalTactic <|← `(tactic| intro $[$l]*)
if let some e := usingArg then
evalTactic <|← `(tactic| exact $e)
end Mathlib.Tactic
namespace Filter
variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x}
section Principal
/-- The principal filter of `s` is the collection of all supersets of `s`. -/
def principal (s : Set α) : Filter α where
sets := { t | s ⊆ t }
univ_sets := subset_univ s
sets_of_superset hx := Subset.trans hx
inter_sets := subset_inter
#align filter.principal Filter.principal
@[inherit_doc]
scoped notation "𝓟" => Filter.principal
@[simp] theorem mem_principal {s t : Set α} : s ∈ 𝓟 t ↔ t ⊆ s := Iff.rfl
#align filter.mem_principal Filter.mem_principal
theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl
#align filter.mem_principal_self Filter.mem_principal_self
end Principal
open Filter
section Join
/-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/
def join (f : Filter (Filter α)) : Filter α where
sets := { s | { t : Filter α | s ∈ t } ∈ f }
univ_sets := by simp only [mem_setOf_eq, univ_sets, ← Filter.mem_sets, setOf_true]
sets_of_superset hx xy := mem_of_superset hx fun f h => mem_of_superset h xy
inter_sets hx hy := mem_of_superset (inter_mem hx hy) fun f ⟨h₁, h₂⟩ => inter_mem h₁ h₂
#align filter.join Filter.join
@[simp]
theorem mem_join {s : Set α} {f : Filter (Filter α)} : s ∈ join f ↔ { t | s ∈ t } ∈ f :=
Iff.rfl
#align filter.mem_join Filter.mem_join
end Join
section Lattice
variable {f g : Filter α} {s t : Set α}
instance : PartialOrder (Filter α) where
le f g := ∀ ⦃U : Set α⦄, U ∈ g → U ∈ f
le_antisymm a b h₁ h₂ := filter_eq <| Subset.antisymm h₂ h₁
le_refl a := Subset.rfl
le_trans a b c h₁ h₂ := Subset.trans h₂ h₁
theorem le_def : f ≤ g ↔ ∀ x ∈ g, x ∈ f :=
Iff.rfl
#align filter.le_def Filter.le_def
protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop]
#align filter.not_le Filter.not_le
/-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/
inductive GenerateSets (g : Set (Set α)) : Set α → Prop
| basic {s : Set α} : s ∈ g → GenerateSets g s
| univ : GenerateSets g univ
| superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t
| inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t)
#align filter.generate_sets Filter.GenerateSets
/-- `generate g` is the largest filter containing the sets `g`. -/
def generate (g : Set (Set α)) : Filter α where
sets := {s | GenerateSets g s}
univ_sets := GenerateSets.univ
sets_of_superset := GenerateSets.superset
inter_sets := GenerateSets.inter
#align filter.generate Filter.generate
lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) :
U ∈ generate s := GenerateSets.basic h
theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets :=
Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu =>
hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy =>
inter_mem hx hy
#align filter.sets_iff_generate Filter.le_generate_iff
theorem mem_generate_iff {s : Set <| Set α} {U : Set α} :
U ∈ generate s ↔ ∃ t ⊆ s, Set.Finite t ∧ ⋂₀ t ⊆ U := by
constructor <;> intro h
· induction h with
| @basic V V_in =>
exact ⟨{V}, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subset⟩
| univ => exact ⟨∅, empty_subset _, finite_empty, subset_univ _⟩
| superset _ hVW hV =>
rcases hV with ⟨t, hts, ht, htV⟩
exact ⟨t, hts, ht, htV.trans hVW⟩
| inter _ _ hV hW =>
rcases hV, hW with ⟨⟨t, hts, ht, htV⟩, u, hus, hu, huW⟩
exact
⟨t ∪ u, union_subset hts hus, ht.union hu,
(sInter_union _ _).subset.trans <| inter_subset_inter htV huW⟩
· rcases h with ⟨t, hts, tfin, h⟩
exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h
#align filter.mem_generate_iff Filter.mem_generate_iff
@[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s :=
le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <|
le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl
/-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly
`s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/
protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where
sets := s
univ_sets := hs ▸ univ_mem
sets_of_superset := hs ▸ mem_of_superset
inter_sets := hs ▸ inter_mem
#align filter.mk_of_closure Filter.mkOfClosure
theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} :
Filter.mkOfClosure s hs = generate s :=
Filter.ext fun u =>
show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl
#align filter.mk_of_closure_sets Filter.mkOfClosure_sets
/-- Galois insertion from sets of sets into filters. -/
def giGenerate (α : Type*) :
@GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where
gc _ _ := le_generate_iff
le_l_u _ _ h := GenerateSets.basic h
choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl)
choice_eq _ _ := mkOfClosure_sets
#align filter.gi_generate Filter.giGenerate
/-- The infimum of filters is the filter generated by intersections
of elements of the two filters. -/
instance : Inf (Filter α) :=
⟨fun f g : Filter α =>
{ sets := { s | ∃ a ∈ f, ∃ b ∈ g, s = a ∩ b }
univ_sets := ⟨_, univ_mem, _, univ_mem, by simp⟩
sets_of_superset := by
rintro x y ⟨a, ha, b, hb, rfl⟩ xy
refine
⟨a ∪ y, mem_of_superset ha subset_union_left, b ∪ y,
mem_of_superset hb subset_union_left, ?_⟩
rw [← inter_union_distrib_right, union_eq_self_of_subset_left xy]
inter_sets := by
rintro x y ⟨a, ha, b, hb, rfl⟩ ⟨c, hc, d, hd, rfl⟩
refine ⟨a ∩ c, inter_mem ha hc, b ∩ d, inter_mem hb hd, ?_⟩
ac_rfl }⟩
theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ :=
Iff.rfl
#align filter.mem_inf_iff Filter.mem_inf_iff
theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g :=
⟨s, h, univ, univ_mem, (inter_univ s).symm⟩
#align filter.mem_inf_of_left Filter.mem_inf_of_left
theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g :=
⟨univ, univ_mem, s, h, (univ_inter s).symm⟩
#align filter.mem_inf_of_right Filter.mem_inf_of_right
theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) :
s ∩ t ∈ f ⊓ g :=
⟨s, hs, t, ht, rfl⟩
#align filter.inter_mem_inf Filter.inter_mem_inf
theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g)
(h : s ∩ t ⊆ u) : u ∈ f ⊓ g :=
mem_of_superset (inter_mem_inf hs ht) h
#align filter.mem_inf_of_inter Filter.mem_inf_of_inter
theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} :
s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s :=
⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ =>
mem_inf_of_inter h₁ h₂ sub⟩
#align filter.mem_inf_iff_superset Filter.mem_inf_iff_superset
instance : Top (Filter α) :=
⟨{ sets := { s | ∀ x, x ∈ s }
univ_sets := fun x => mem_univ x
sets_of_superset := fun hx hxy a => hxy (hx a)
inter_sets := fun hx hy _ => mem_inter (hx _) (hy _) }⟩
theorem mem_top_iff_forall {s : Set α} : s ∈ (⊤ : Filter α) ↔ ∀ x, x ∈ s :=
Iff.rfl
#align filter.mem_top_iff_forall Filter.mem_top_iff_forall
@[simp]
theorem mem_top {s : Set α} : s ∈ (⊤ : Filter α) ↔ s = univ := by
rw [mem_top_iff_forall, eq_univ_iff_forall]
#align filter.mem_top Filter.mem_top
section CompleteLattice
/- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately,
we want to have different definitional equalities for some lattice operations. So we define them
upfront and change the lattice operations for the complete lattice instance. -/
instance instCompleteLatticeFilter : CompleteLattice (Filter α) :=
{ @OrderDual.instCompleteLattice _ (giGenerate α).liftCompleteLattice with
le := (· ≤ ·)
top := ⊤
le_top := fun _ _s hs => (mem_top.1 hs).symm ▸ univ_mem
inf := (· ⊓ ·)
inf_le_left := fun _ _ _ => mem_inf_of_left
inf_le_right := fun _ _ _ => mem_inf_of_right
le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb)
sSup := join ∘ 𝓟
le_sSup := fun _ _f hf _s hs => hs hf
sSup_le := fun _ _f hf _s hs _g hg => hf _ hg hs }
instance : Inhabited (Filter α) := ⟨⊥⟩
end CompleteLattice
/-- A filter is `NeBot` if it is not equal to `⊥`, or equivalently the empty set does not belong to
the filter. Bourbaki include this assumption in the definition of a filter but we prefer to have a
`CompleteLattice` structure on `Filter _`, so we use a typeclass argument in lemmas instead. -/
class NeBot (f : Filter α) : Prop where
/-- The filter is nontrivial: `f ≠ ⊥` or equivalently, `∅ ∉ f`. -/
ne' : f ≠ ⊥
#align filter.ne_bot Filter.NeBot
theorem neBot_iff {f : Filter α} : NeBot f ↔ f ≠ ⊥ :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
#align filter.ne_bot_iff Filter.neBot_iff
theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne'
#align filter.ne_bot.ne Filter.NeBot.ne
@[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left
#align filter.not_ne_bot Filter.not_neBot
theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g :=
⟨ne_bot_of_le_ne_bot hf.1 hg⟩
#align filter.ne_bot.mono Filter.NeBot.mono
theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g :=
hf.mono hg
#align filter.ne_bot_of_le Filter.neBot_of_le
@[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by
simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff]
#align filter.sup_ne_bot Filter.sup_neBot
theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff]
#align filter.not_disjoint_self_iff Filter.not_disjoint_self_iff
theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl
#align filter.bot_sets_eq Filter.bot_sets_eq
/-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot`
as the second alternative, to be used as an instance. -/
theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk
theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets :=
(giGenerate α).gc.u_inf
#align filter.sup_sets_eq Filter.sup_sets_eq
theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets :=
(giGenerate α).gc.u_sInf
#align filter.Sup_sets_eq Filter.sSup_sets_eq
theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets :=
(giGenerate α).gc.u_iInf
#align filter.supr_sets_eq Filter.iSup_sets_eq
theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) :=
(giGenerate α).gc.l_bot
#align filter.generate_empty Filter.generate_empty
theorem generate_univ : Filter.generate univ = (⊥ : Filter α) :=
bot_unique fun _ _ => GenerateSets.basic (mem_univ _)
#align filter.generate_univ Filter.generate_univ
theorem generate_union {s t : Set (Set α)} :
Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t :=
(giGenerate α).gc.l_sup
#align filter.generate_union Filter.generate_union
theorem generate_iUnion {s : ι → Set (Set α)} :
Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) :=
(giGenerate α).gc.l_iSup
#align filter.generate_Union Filter.generate_iUnion
@[simp]
theorem mem_bot {s : Set α} : s ∈ (⊥ : Filter α) :=
trivial
#align filter.mem_bot Filter.mem_bot
@[simp]
theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g :=
Iff.rfl
#align filter.mem_sup Filter.mem_sup
theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g :=
⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩
#align filter.union_mem_sup Filter.union_mem_sup
@[simp]
theorem mem_sSup {x : Set α} {s : Set (Filter α)} : x ∈ sSup s ↔ ∀ f ∈ s, x ∈ (f : Filter α) :=
Iff.rfl
#align filter.mem_Sup Filter.mem_sSup
@[simp]
theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by
simp only [← Filter.mem_sets, iSup_sets_eq, iff_self_iff, mem_iInter]
#align filter.mem_supr Filter.mem_iSup
@[simp]
theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by
simp [neBot_iff]
#align filter.supr_ne_bot Filter.iSup_neBot
theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) :=
show generate _ = generate _ from congr_arg _ <| congr_arg sSup <| (range_comp _ _).symm
#align filter.infi_eq_generate Filter.iInf_eq_generate
theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i :=
iInf_le f i hs
#align filter.mem_infi_of_mem Filter.mem_iInf_of_mem
theorem mem_iInf_of_iInter {ι} {s : ι → Filter α} {U : Set α} {I : Set ι} (I_fin : I.Finite)
{V : I → Set α} (hV : ∀ i, V i ∈ s i) (hU : ⋂ i, V i ⊆ U) : U ∈ ⨅ i, s i := by
haveI := I_fin.fintype
refine mem_of_superset (iInter_mem.2 fun i => ?_) hU
exact mem_iInf_of_mem (i : ι) (hV _)
#align filter.mem_infi_of_Inter Filter.mem_iInf_of_iInter
theorem mem_iInf {ι} {s : ι → Filter α} {U : Set α} :
(U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : I → Set α, (∀ i, V i ∈ s i) ∧ U = ⋂ i, V i := by
constructor
· rw [iInf_eq_generate, mem_generate_iff]
rintro ⟨t, tsub, tfin, tinter⟩
rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with ⟨I, Ifin, σ, σfin, σsub, rfl⟩
rw [sInter_iUnion] at tinter
set V := fun i => U ∪ ⋂₀ σ i with hV
have V_in : ∀ i, V i ∈ s i := by
rintro i
have : ⋂₀ σ i ∈ s i := by
rw [sInter_mem (σfin _)]
apply σsub
exact mem_of_superset this subset_union_right
refine ⟨I, Ifin, V, V_in, ?_⟩
rwa [hV, ← union_iInter, union_eq_self_of_subset_right]
· rintro ⟨I, Ifin, V, V_in, rfl⟩
exact mem_iInf_of_iInter Ifin V_in Subset.rfl
#align filter.mem_infi Filter.mem_iInf
theorem mem_iInf' {ι} {s : ι → Filter α} {U : Set α} :
(U ∈ ⨅ i, s i) ↔
∃ I : Set ι, I.Finite ∧ ∃ V : ι → Set α, (∀ i, V i ∈ s i) ∧
(∀ i ∉ I, V i = univ) ∧ (U = ⋂ i ∈ I, V i) ∧ U = ⋂ i, V i := by
simp only [mem_iInf, SetCoe.forall', biInter_eq_iInter]
refine ⟨?_, fun ⟨I, If, V, hVs, _, hVU, _⟩ => ⟨I, If, fun i => V i, fun i => hVs i, hVU⟩⟩
rintro ⟨I, If, V, hV, rfl⟩
refine ⟨I, If, fun i => if hi : i ∈ I then V ⟨i, hi⟩ else univ, fun i => ?_, fun i hi => ?_, ?_⟩
· dsimp only
split_ifs
exacts [hV _, univ_mem]
· exact dif_neg hi
· simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta,
iInter_univ, inter_univ, eq_self_iff_true, true_and_iff]
#align filter.mem_infi' Filter.mem_iInf'
theorem exists_iInter_of_mem_iInf {ι : Type*} {α : Type*} {f : ι → Filter α} {s}
(hs : s ∈ ⨅ i, f i) : ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i :=
let ⟨_, _, V, hVs, _, _, hVU'⟩ := mem_iInf'.1 hs; ⟨V, hVs, hVU'⟩
#align filter.exists_Inter_of_mem_infi Filter.exists_iInter_of_mem_iInf
theorem mem_iInf_of_finite {ι : Type*} [Finite ι] {α : Type*} {f : ι → Filter α} (s) :
(s ∈ ⨅ i, f i) ↔ ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by
refine ⟨exists_iInter_of_mem_iInf, ?_⟩
rintro ⟨t, ht, rfl⟩
exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i)
#align filter.mem_infi_of_finite Filter.mem_iInf_of_finite
@[simp]
theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f :=
⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩
#align filter.le_principal_iff Filter.le_principal_iff
theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } :=
Set.ext fun _ => le_principal_iff
#align filter.Iic_principal Filter.Iic_principal
theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by
simp only [le_principal_iff, iff_self_iff, mem_principal]
#align filter.principal_mono Filter.principal_mono
@[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono
@[mono]
theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2
#align filter.monotone_principal Filter.monotone_principal
@[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by
simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl
#align filter.principal_eq_iff_eq Filter.principal_eq_iff_eq
@[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl
#align filter.join_principal_eq_Sup Filter.join_principal_eq_sSup
@[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ :=
top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true]
#align filter.principal_univ Filter.principal_univ
@[simp]
theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ :=
bot_unique fun _ _ => empty_subset _
#align filter.principal_empty Filter.principal_empty
theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s :=
eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def]
#align filter.generate_eq_binfi Filter.generate_eq_biInf
/-! ### Lattice equations -/
theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ :=
⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩
#align filter.empty_mem_iff_bot Filter.empty_mem_iff_bot
theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id
#align filter.nonempty_of_mem Filter.nonempty_of_mem
theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty :=
@Filter.nonempty_of_mem α f hf s hs
#align filter.ne_bot.nonempty_of_mem Filter.NeBot.nonempty_of_mem
@[simp]
theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl
#align filter.empty_not_mem Filter.empty_not_mem
theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α :=
nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f)
#align filter.nonempty_of_ne_bot Filter.nonempty_of_neBot
theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc =>
(nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s
#align filter.compl_not_mem Filter.compl_not_mem
theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ :=
empty_mem_iff_bot.mp <| univ_mem' isEmptyElim
#align filter.filter_eq_bot_of_is_empty Filter.filter_eq_bot_of_isEmpty
protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by
simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty,
@eq_comm _ ∅]
#align filter.disjoint_iff Filter.disjoint_iff
theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f)
(ht : t ∈ g) : Disjoint f g :=
Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩
#align filter.disjoint_of_disjoint_of_mem Filter.disjoint_of_disjoint_of_mem
theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h =>
not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩
#align filter.ne_bot.not_disjoint Filter.NeBot.not_disjoint
theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by
simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty]
#align filter.inf_eq_bot_iff Filter.inf_eq_bot_iff
theorem _root_.Pairwise.exists_mem_filter_of_disjoint {ι : Type*} [Finite ι] {l : ι → Filter α}
(hd : Pairwise (Disjoint on l)) :
∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ Pairwise (Disjoint on s) := by
have : Pairwise fun i j => ∃ (s : {s // s ∈ l i}) (t : {t // t ∈ l j}), Disjoint s.1 t.1 := by
simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd
choose! s t hst using this
refine ⟨fun i => ⋂ j, @s i j ∩ @t j i, fun i => ?_, fun i j hij => ?_⟩
exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2,
(hst hij).mono ((iInter_subset _ j).trans inter_subset_left)
((iInter_subset _ i).trans inter_subset_right)]
#align pairwise.exists_mem_filter_of_disjoint Pairwise.exists_mem_filter_of_disjoint
theorem _root_.Set.PairwiseDisjoint.exists_mem_filter {ι : Type*} {l : ι → Filter α} {t : Set ι}
(hd : t.PairwiseDisjoint l) (ht : t.Finite) :
∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ t.PairwiseDisjoint s := by
haveI := ht.to_subtype
rcases (hd.subtype _ _).exists_mem_filter_of_disjoint with ⟨s, hsl, hsd⟩
lift s to (i : t) → {s // s ∈ l i} using hsl
rcases @Subtype.exists_pi_extension ι (fun i => { s // s ∈ l i }) _ _ s with ⟨s, rfl⟩
exact ⟨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _⟩
#align set.pairwise_disjoint.exists_mem_filter Set.PairwiseDisjoint.exists_mem_filter
/-- There is exactly one filter on an empty type. -/
instance unique [IsEmpty α] : Unique (Filter α) where
default := ⊥
uniq := filter_eq_bot_of_isEmpty
#align filter.unique Filter.unique
theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α :=
not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _)
/-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are
equal. -/
theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by
refine top_unique fun s hs => ?_
obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs)
exact univ_mem
#align filter.eq_top_of_ne_bot Filter.eq_top_of_neBot
theorem forall_mem_nonempty_iff_neBot {f : Filter α} :
(∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f :=
⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩
#align filter.forall_mem_nonempty_iff_ne_bot Filter.forall_mem_nonempty_iff_neBot
instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) :=
⟨⟨⊤, ⊥, NeBot.ne <| forall_mem_nonempty_iff_neBot.1
fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]⟩⟩
theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α :=
⟨fun _ =>
by_contra fun h' =>
haveI := not_nonempty_iff.1 h'
not_subsingleton (Filter α) inferInstance,
@Filter.instNontrivialFilter α⟩
#align filter.nontrivial_iff_nonempty Filter.nontrivial_iff_nonempty
theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S :=
le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩)
fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs
#align filter.eq_Inf_of_mem_iff_exists_mem Filter.eq_sInf_of_mem_iff_exists_mem
theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f :=
eq_sInf_of_mem_iff_exists_mem <| h.trans exists_range_iff.symm
#align filter.eq_infi_of_mem_iff_exists_mem Filter.eq_iInf_of_mem_iff_exists_mem
theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by
rw [iInf_subtype']
exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop]
#align filter.eq_binfi_of_mem_iff_exists_mem Filter.eq_biInf_of_mem_iff_exists_memₓ
theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] :
(iInf f).sets = ⋃ i, (f i).sets :=
let ⟨i⟩ := ne
let u :=
{ sets := ⋃ i, (f i).sets
univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩
sets_of_superset := by
simp only [mem_iUnion, exists_imp]
exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩
inter_sets := by
simp only [mem_iUnion, exists_imp]
intro x y a hx b hy
rcases h a b with ⟨c, ha, hb⟩
exact ⟨c, inter_mem (ha hx) (hb hy)⟩ }
have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion
-- Porting note: it was just `congr_arg filter.sets this.symm`
(congr_arg Filter.sets this.symm).trans <| by simp only
#align filter.infi_sets_eq Filter.iInf_sets_eq
theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) :
s ∈ iInf f ↔ ∃ i, s ∈ f i := by
simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion]
#align filter.mem_infi_of_directed Filter.mem_iInf_of_directed
theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by
haveI := ne.to_subtype
simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop]
#align filter.mem_binfi_of_directed Filter.mem_biInf_of_directed
theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets :=
ext fun t => by simp [mem_biInf_of_directed h ne]
#align filter.binfi_sets_eq Filter.biInf_sets_eq
theorem iInf_sets_eq_finite {ι : Type*} (f : ι → Filter α) :
(⨅ i, f i).sets = ⋃ t : Finset ι, (⨅ i ∈ t, f i).sets := by
rw [iInf_eq_iInf_finset, iInf_sets_eq]
exact directed_of_isDirected_le fun _ _ => biInf_mono
#align filter.infi_sets_eq_finite Filter.iInf_sets_eq_finite
theorem iInf_sets_eq_finite' (f : ι → Filter α) :
(⨅ i, f i).sets = ⋃ t : Finset (PLift ι), (⨅ i ∈ t, f (PLift.down i)).sets := by
rw [← iInf_sets_eq_finite, ← Equiv.plift.surjective.iInf_comp, Equiv.plift_apply]
#align filter.infi_sets_eq_finite' Filter.iInf_sets_eq_finite'
theorem mem_iInf_finite {ι : Type*} {f : ι → Filter α} (s) :
s ∈ iInf f ↔ ∃ t : Finset ι, s ∈ ⨅ i ∈ t, f i :=
(Set.ext_iff.1 (iInf_sets_eq_finite f) s).trans mem_iUnion
#align filter.mem_infi_finite Filter.mem_iInf_finite
theorem mem_iInf_finite' {f : ι → Filter α} (s) :
s ∈ iInf f ↔ ∃ t : Finset (PLift ι), s ∈ ⨅ i ∈ t, f (PLift.down i) :=
(Set.ext_iff.1 (iInf_sets_eq_finite' f) s).trans mem_iUnion
#align filter.mem_infi_finite' Filter.mem_iInf_finite'
@[simp]
theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) :=
Filter.ext fun x => by simp only [mem_sup, mem_join]
#align filter.sup_join Filter.sup_join
@[simp]
theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) :=
Filter.ext fun x => by simp only [mem_iSup, mem_join]
#align filter.supr_join Filter.iSup_join
instance : DistribLattice (Filter α) :=
{ Filter.instCompleteLatticeFilter with
le_sup_inf := by
intro x y z s
simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp]
rintro hs t₁ ht₁ t₂ ht₂ rfl
exact
⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂,
x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ }
-- The dual version does not hold! `Filter α` is not a `CompleteDistribLattice`. -/
instance : Coframe (Filter α) :=
{ Filter.instCompleteLatticeFilter with
iInf_sup_le_sup_sInf := fun f s t ⟨h₁, h₂⟩ => by
rw [iInf_subtype']
rw [sInf_eq_iInf', iInf_sets_eq_finite, mem_iUnion] at h₂
obtain ⟨u, hu⟩ := h₂
rw [← Finset.inf_eq_iInf] at hu
suffices ⨅ i : s, f ⊔ ↑i ≤ f ⊔ u.inf fun i => ↑i from this ⟨h₁, hu⟩
refine Finset.induction_on u (le_sup_of_le_right le_top) ?_
rintro ⟨i⟩ u _ ih
rw [Finset.inf_insert, sup_inf_left]
exact le_inf (iInf_le _ _) ih }
theorem mem_iInf_finset {s : Finset α} {f : α → Filter β} {t : Set β} :
(t ∈ ⨅ a ∈ s, f a) ↔ ∃ p : α → Set β, (∀ a ∈ s, p a ∈ f a) ∧ t = ⋂ a ∈ s, p a := by
simp only [← Finset.set_biInter_coe, biInter_eq_iInter, iInf_subtype']
refine ⟨fun h => ?_, ?_⟩
· rcases (mem_iInf_of_finite _).1 h with ⟨p, hp, rfl⟩
refine ⟨fun a => if h : a ∈ s then p ⟨a, h⟩ else univ,
fun a ha => by simpa [ha] using hp ⟨a, ha⟩, ?_⟩
refine iInter_congr_of_surjective id surjective_id ?_
rintro ⟨a, ha⟩
simp [ha]
· rintro ⟨p, hpf, rfl⟩
exact iInter_mem.2 fun a => mem_iInf_of_mem a (hpf a a.2)
#align filter.mem_infi_finset Filter.mem_iInf_finset
/-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/
theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
(∀ i, NeBot (f i)) → NeBot (iInf f) :=
not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot,
mem_iInf_of_directed hd] using id
#align filter.infi_ne_bot_of_directed' Filter.iInf_neBot_of_directed'
/-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/
theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f)
(hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by
cases isEmpty_or_nonempty ι
· constructor
simp [iInf_of_empty f, top_ne_bot]
· exact iInf_neBot_of_directed' hd hb
#align filter.infi_ne_bot_of_directed Filter.iInf_neBot_of_directed
theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
@iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ =>
⟨ne_of_mem_of_not_mem hf hbot⟩
#align filter.Inf_ne_bot_of_directed' Filter.sInf_neBot_of_directed'
theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩
#align filter.Inf_ne_bot_of_directed Filter.sInf_neBot_of_directed
theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩
#align filter.infi_ne_bot_iff_of_directed' Filter.iInf_neBot_iff_of_directed'
theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩
#align filter.infi_ne_bot_iff_of_directed Filter.iInf_neBot_iff_of_directed
@[elab_as_elim]
theorem iInf_sets_induct {f : ι → Filter α} {s : Set α} (hs : s ∈ iInf f) {p : Set α → Prop}
(uni : p univ) (ins : ∀ {i s₁ s₂}, s₁ ∈ f i → p s₂ → p (s₁ ∩ s₂)) : p s := by
rw [mem_iInf_finite'] at hs
simp only [← Finset.inf_eq_iInf] at hs
rcases hs with ⟨is, his⟩
induction is using Finset.induction_on generalizing s with
| empty => rwa [mem_top.1 his]
| insert _ ih =>
rw [Finset.inf_insert, mem_inf_iff] at his
rcases his with ⟨s₁, hs₁, s₂, hs₂, rfl⟩
exact ins hs₁ (ih hs₂)
#align filter.infi_sets_induct Filter.iInf_sets_induct
/-! #### `principal` equations -/
@[simp]
theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) :=
le_antisymm
(by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩)
(by simp [le_inf_iff, inter_subset_left, inter_subset_right])
#align filter.inf_principal Filter.inf_principal
@[simp]
theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) :=
Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal]
#align filter.sup_principal Filter.sup_principal
@[simp]
theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) :=
Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff]
#align filter.supr_principal Filter.iSup_principal
@[simp]
theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ :=
empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff
#align filter.principal_eq_bot_iff Filter.principal_eq_bot_iff
@[simp]
theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty :=
neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm
#align filter.principal_ne_bot_iff Filter.principal_neBot_iff
alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff
#align set.nonempty.principal_ne_bot Set.Nonempty.principal_neBot
theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) :=
IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by
rw [sup_principal, union_compl_self, principal_univ]
#align filter.is_compl_principal Filter.isCompl_principal
theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by
simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal,
← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl]
#align filter.mem_inf_principal' Filter.mem_inf_principal'
lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by
simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq]
#align filter.mem_inf_principal Filter.mem_inf_principal
lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by
ext
simp only [mem_iSup, mem_inf_principal]
#align filter.supr_inf_principal Filter.iSup_inf_principal
theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by
rw [← empty_mem_iff_bot, mem_inf_principal]
simp only [mem_empty_iff_false, imp_false, compl_def]
#align filter.inf_principal_eq_bot Filter.inf_principal_eq_bot
theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by
rwa [inf_principal_eq_bot, compl_compl] at h
#align filter.mem_of_eq_bot Filter.mem_of_eq_bot
theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) :
s \ t ∈ f ⊓ 𝓟 tᶜ :=
inter_mem_inf hs <| mem_principal_self tᶜ
#align filter.diff_mem_inf_principal_compl Filter.diff_mem_inf_principal_compl
theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by
simp_rw [le_def, mem_principal]
#align filter.principal_le_iff Filter.principal_le_iff
@[simp]
theorem iInf_principal_finset {ι : Type w} (s : Finset ι) (f : ι → Set α) :
⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by
induction' s using Finset.induction_on with i s _ hs
· simp
· rw [Finset.iInf_insert, Finset.set_biInter_insert, hs, inf_principal]
#align filter.infi_principal_finset Filter.iInf_principal_finset
theorem iInf_principal {ι : Sort w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := by
cases nonempty_fintype (PLift ι)
rw [← iInf_plift_down, ← iInter_plift_down]
simpa using iInf_principal_finset Finset.univ (f <| PLift.down ·)
/-- A special case of `iInf_principal` that is safe to mark `simp`. -/
@[simp]
theorem iInf_principal' {ι : Type w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) :=
iInf_principal _
#align filter.infi_principal Filter.iInf_principal
theorem iInf_principal_finite {ι : Type w} {s : Set ι} (hs : s.Finite) (f : ι → Set α) :
⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by
lift s to Finset ι using hs
exact mod_cast iInf_principal_finset s f
#align filter.infi_principal_finite Filter.iInf_principal_finite
end Lattice
@[mono, gcongr]
theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs
#align filter.join_mono Filter.join_mono
/-! ### Eventually -/
/-- `f.Eventually p` or `∀ᶠ x in f, p x` mean that `{x | p x} ∈ f`. E.g., `∀ᶠ x in atTop, p x`
means that `p` holds true for sufficiently large `x`. -/
protected def Eventually (p : α → Prop) (f : Filter α) : Prop :=
{ x | p x } ∈ f
#align filter.eventually Filter.Eventually
@[inherit_doc Filter.Eventually]
notation3 "∀ᶠ "(...)" in "f", "r:(scoped p => Filter.Eventually p f) => r
theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f :=
Iff.rfl
#align filter.eventually_iff Filter.eventually_iff
@[simp]
theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l :=
Iff.rfl
#align filter.eventually_mem_set Filter.eventually_mem_set
protected theorem ext' {f₁ f₂ : Filter α}
(h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ :=
Filter.ext h
#align filter.ext' Filter.ext'
theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop}
(hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x :=
h hp
#align filter.eventually.filter_mono Filter.Eventually.filter_mono
theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f)
(h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x :=
mem_of_superset hU h
#align filter.eventually_of_mem Filter.eventually_of_mem
protected theorem Eventually.and {p q : α → Prop} {f : Filter α} :
f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x :=
inter_mem
#align filter.eventually.and Filter.Eventually.and
@[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem
#align filter.eventually_true Filter.eventually_true
theorem eventually_of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x :=
univ_mem' hp
#align filter.eventually_of_forall Filter.eventually_of_forall
@[simp]
theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ :=
empty_mem_iff_bot
#align filter.eventually_false_iff_eq_bot Filter.eventually_false_iff_eq_bot
@[simp]
theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by
by_cases h : p <;> simp [h, t.ne]
#align filter.eventually_const Filter.eventually_const
theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y :=
exists_mem_subset_iff.symm
#align filter.eventually_iff_exists_mem Filter.eventually_iff_exists_mem
theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) :
∃ v ∈ f, ∀ y ∈ v, p y :=
eventually_iff_exists_mem.1 hp
#align filter.eventually.exists_mem Filter.Eventually.exists_mem
theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x :=
mp_mem hp hq
#align filter.eventually.mp Filter.Eventually.mp
theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x :=
hp.mp (eventually_of_forall hq)
#align filter.eventually.mono Filter.Eventually.mono
theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop}
(h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y :=
fun y => h.mono fun _ h => h y
#align filter.forall_eventually_of_eventually_forall Filter.forall_eventually_of_eventually_forall
@[simp]
theorem eventually_and {p q : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x :=
inter_mem_iff
#align filter.eventually_and Filter.eventually_and
theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x)
(h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x :=
h'.mp (h.mono fun _ hx => hx.mp)
#align filter.eventually.congr Filter.Eventually.congr
theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) :
(∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x :=
⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩
#align filter.eventually_congr Filter.eventually_congr
@[simp]
theorem eventually_all {ι : Sort*} [Finite ι] {l} {p : ι → α → Prop} :
(∀ᶠ x in l, ∀ i, p i x) ↔ ∀ i, ∀ᶠ x in l, p i x := by
simpa only [Filter.Eventually, setOf_forall] using iInter_mem
#align filter.eventually_all Filter.eventually_all
@[simp]
theorem eventually_all_finite {ι} {I : Set ι} (hI : I.Finite) {l} {p : ι → α → Prop} :
(∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := by
simpa only [Filter.Eventually, setOf_forall] using biInter_mem hI
#align filter.eventually_all_finite Filter.eventually_all_finite
alias _root_.Set.Finite.eventually_all := eventually_all_finite
#align set.finite.eventually_all Set.Finite.eventually_all
-- attribute [protected] Set.Finite.eventually_all
@[simp] theorem eventually_all_finset {ι} (I : Finset ι) {l} {p : ι → α → Prop} :
(∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x :=
I.finite_toSet.eventually_all
#align filter.eventually_all_finset Filter.eventually_all_finset
alias _root_.Finset.eventually_all := eventually_all_finset
#align finset.eventually_all Finset.eventually_all
-- attribute [protected] Finset.eventually_all
@[simp]
theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x :=
by_cases (fun h : p => by simp [h]) fun h => by simp [h]
#align filter.eventually_or_distrib_left Filter.eventually_or_distrib_left
@[simp]
theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by
simp only [@or_comm _ q, eventually_or_distrib_left]
#align filter.eventually_or_distrib_right Filter.eventually_or_distrib_right
theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x :=
eventually_all
#align filter.eventually_imp_distrib_left Filter.eventually_imp_distrib_left
@[simp]
theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x :=
⟨⟩
#align filter.eventually_bot Filter.eventually_bot
@[simp]
theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x :=
Iff.rfl
#align filter.eventually_top Filter.eventually_top
@[simp]
theorem eventually_sup {p : α → Prop} {f g : Filter α} :
(∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x :=
Iff.rfl
#align filter.eventually_sup Filter.eventually_sup
@[simp]
theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x :=
Iff.rfl
#align filter.eventually_Sup Filter.eventually_sSup
@[simp]
theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} :
(∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x :=
mem_iSup
#align filter.eventually_supr Filter.eventually_iSup
@[simp]
theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x :=
Iff.rfl
#align filter.eventually_principal Filter.eventually_principal
theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop}
(hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x :=
Filter.eventually_principal.mp (hP.filter_mono hf)
theorem eventually_inf {f g : Filter α} {p : α → Prop} :
(∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x :=
mem_inf_iff_superset
#align filter.eventually_inf Filter.eventually_inf
theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} :
(∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x :=
mem_inf_principal
#align filter.eventually_inf_principal Filter.eventually_inf_principal
/-! ### Frequently -/
/-- `f.Frequently p` or `∃ᶠ x in f, p x` mean that `{x | ¬p x} ∉ f`. E.g., `∃ᶠ x in atTop, p x`
means that there exist arbitrarily large `x` for which `p` holds true. -/
protected def Frequently (p : α → Prop) (f : Filter α) : Prop :=
¬∀ᶠ x in f, ¬p x
#align filter.frequently Filter.Frequently
@[inherit_doc Filter.Frequently]
notation3 "∃ᶠ "(...)" in "f", "r:(scoped p => Filter.Frequently p f) => r
theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) :
∃ᶠ x in f, p x :=
compl_not_mem h
#align filter.eventually.frequently Filter.Eventually.frequently
theorem frequently_of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) :
∃ᶠ x in f, p x :=
Eventually.frequently (eventually_of_forall h)
#align filter.frequently_of_forall Filter.frequently_of_forall
theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x :=
mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h
#align filter.frequently.mp Filter.Frequently.mp
theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) :
∃ᶠ x in g, p x :=
mt (fun h' => h'.filter_mono hle) h
#align filter.frequently.filter_mono Filter.Frequently.filter_mono
theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x :=
h.mp (eventually_of_forall hpq)
#align filter.frequently.mono Filter.Frequently.mono
theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x)
(hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
refine mt (fun h => hq.mp <| h.mono ?_) hp
exact fun x hpq hq hp => hpq ⟨hp, hq⟩
#align filter.frequently.and_eventually Filter.Frequently.and_eventually
theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
simpa only [and_comm] using hq.and_eventually hp
#align filter.eventually.and_frequently Filter.Eventually.and_frequently
theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by
by_contra H
replace H : ∀ᶠ x in f, ¬p x := eventually_of_forall (not_exists.1 H)
exact hp H
#align filter.frequently.exists Filter.Frequently.exists
theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) :
∃ x, p x :=
hp.frequently.exists
#align filter.eventually.exists Filter.Eventually.exists
lemma frequently_iff_neBot {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by
rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl
lemma frequently_mem_iff_neBot {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) :=
frequently_iff_neBot
theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} :
(∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x :=
⟨fun hp q hq => (hp.and_eventually hq).exists, fun H hp => by
simpa only [and_not_self_iff, exists_false] using H hp⟩
#align filter.frequently_iff_forall_eventually_exists_and Filter.frequently_iff_forall_eventually_exists_and
theorem frequently_iff {f : Filter α} {P : α → Prop} :
(∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by
simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)]
rfl
#align filter.frequently_iff Filter.frequently_iff
@[simp]
theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by
simp [Filter.Frequently]
#align filter.not_eventually Filter.not_eventually
@[simp]
theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by
simp only [Filter.Frequently, not_not]
#align filter.not_frequently Filter.not_frequently
@[simp]
theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by
simp [frequently_iff_neBot]
#align filter.frequently_true_iff_ne_bot Filter.frequently_true_iff_neBot
@[simp]
theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp
#align filter.frequently_false Filter.frequently_false
@[simp]
theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by
by_cases p <;> simp [*]
#align filter.frequently_const Filter.frequently_const
@[simp]
theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and]
#align filter.frequently_or_distrib Filter.frequently_or_distrib
theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp
#align filter.frequently_or_distrib_left Filter.frequently_or_distrib_left
theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp
#align filter.frequently_or_distrib_right Filter.frequently_or_distrib_right
theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by
simp [imp_iff_not_or]
#align filter.frequently_imp_distrib Filter.frequently_imp_distrib
theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib]
#align filter.frequently_imp_distrib_left Filter.frequently_imp_distrib_left
theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by
set_option tactic.skipAssignedInstances false in simp [frequently_imp_distrib]
#align filter.frequently_imp_distrib_right Filter.frequently_imp_distrib_right
theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by
simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently]
#align filter.eventually_imp_distrib_right Filter.eventually_imp_distrib_right
@[simp]
theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp]
#align filter.frequently_and_distrib_left Filter.frequently_and_distrib_left
@[simp]
theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by
simp only [@and_comm _ q, frequently_and_distrib_left]
#align filter.frequently_and_distrib_right Filter.frequently_and_distrib_right
@[simp]
theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp
#align filter.frequently_bot Filter.frequently_bot
@[simp]
theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently]
#align filter.frequently_top Filter.frequently_top
@[simp]
theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by
simp [Filter.Frequently, not_forall]
#align filter.frequently_principal Filter.frequently_principal
theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by
simp only [Filter.Frequently, eventually_inf_principal, not_and]
alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal
theorem frequently_sup {p : α → Prop} {f g : Filter α} :
(∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by
simp only [Filter.Frequently, eventually_sup, not_and_or]
#align filter.frequently_sup Filter.frequently_sup
@[simp]
theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by
simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop]
#align filter.frequently_Sup Filter.frequently_sSup
@[simp]
theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} :
(∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by
simp only [Filter.Frequently, eventually_iSup, not_forall]
#align filter.frequently_supr Filter.frequently_iSup
theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) :
∃ f : α → β, ∀ᶠ x in l, r x (f x) := by
haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty
choose! f hf using fun x (hx : ∃ y, r x y) => hx
exact ⟨f, h.mono hf⟩
#align filter.eventually.choice Filter.Eventually.choice
/-!
### Relation “eventually equal”
-/
/-- Two functions `f` and `g` are *eventually equal* along a filter `l` if the set of `x` such that
`f x = g x` belongs to `l`. -/
def EventuallyEq (l : Filter α) (f g : α → β) : Prop :=
∀ᶠ x in l, f x = g x
#align filter.eventually_eq Filter.EventuallyEq
@[inherit_doc]
notation:50 f " =ᶠ[" l:50 "] " g:50 => EventuallyEq l f g
theorem EventuallyEq.eventually {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) :
∀ᶠ x in l, f x = g x :=
h
#align filter.eventually_eq.eventually Filter.EventuallyEq.eventually
theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop)
(hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) :=
hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl
#align filter.eventually_eq.rw Filter.EventuallyEq.rw
theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t :=
eventually_congr <| eventually_of_forall fun _ ↦ eq_iff_iff
#align filter.eventually_eq_set Filter.eventuallyEq_set
alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set
#align filter.eventually_eq.mem_iff Filter.EventuallyEq.mem_iff
#align filter.eventually.set_eq Filter.Eventually.set_eq
@[simp]
theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by
simp [eventuallyEq_set]
#align filter.eventually_eq_univ Filter.eventuallyEq_univ
theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) :
∃ s ∈ l, EqOn f g s :=
Eventually.exists_mem h
#align filter.eventually_eq.exists_mem Filter.EventuallyEq.exists_mem
theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) :
f =ᶠ[l] g :=
eventually_of_mem hs h
#align filter.eventually_eq_of_mem Filter.eventuallyEq_of_mem
theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} :
f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s :=
eventually_iff_exists_mem
#align filter.eventually_eq_iff_exists_mem Filter.eventuallyEq_iff_exists_mem
theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) :
f =ᶠ[l'] g :=
h₂ h₁
#align filter.eventually_eq.filter_mono Filter.EventuallyEq.filter_mono
@[refl, simp]
theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f :=
eventually_of_forall fun _ => rfl
#align filter.eventually_eq.refl Filter.EventuallyEq.refl
protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f :=
EventuallyEq.refl l f
#align filter.eventually_eq.rfl Filter.EventuallyEq.rfl
@[symm]
theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f :=
H.mono fun _ => Eq.symm
#align filter.eventually_eq.symm Filter.EventuallyEq.symm
@[trans]
theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) :
f =ᶠ[l] h :=
H₂.rw (fun x y => f x = y) H₁
#align filter.eventually_eq.trans Filter.EventuallyEq.trans
instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where
trans := EventuallyEq.trans
theorem EventuallyEq.prod_mk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') :
(fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) :=
hf.mp <|
hg.mono <| by
intros
simp only [*]
#align filter.eventually_eq.prod_mk Filter.EventuallyEq.prod_mk
-- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t.
-- composition on the right.
theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) :
h ∘ f =ᶠ[l] h ∘ g :=
H.mono fun _ hx => congr_arg h hx
#align filter.eventually_eq.fun_comp Filter.EventuallyEq.fun_comp
theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ)
(Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) :=
(Hf.prod_mk Hg).fun_comp (uncurry h)
#align filter.eventually_eq.comp₂ Filter.EventuallyEq.comp₂
@[to_additive]
theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x :=
h.comp₂ (· * ·) h'
#align filter.eventually_eq.mul Filter.EventuallyEq.mul
#align filter.eventually_eq.add Filter.EventuallyEq.add
@[to_additive const_smul]
theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ):
(fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c :=
h.fun_comp (· ^ c)
#align filter.eventually_eq.const_smul Filter.EventuallyEq.const_smul
@[to_additive]
theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
(fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ :=
h.fun_comp Inv.inv
#align filter.eventually_eq.inv Filter.EventuallyEq.inv
#align filter.eventually_eq.neg Filter.EventuallyEq.neg
@[to_additive]
theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x :=
h.comp₂ (· / ·) h'
#align filter.eventually_eq.div Filter.EventuallyEq.div
#align filter.eventually_eq.sub Filter.EventuallyEq.sub
attribute [to_additive] EventuallyEq.const_smul
#align filter.eventually_eq.const_vadd Filter.EventuallyEq.const_vadd
@[to_additive]
theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β}
(hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x :=
hf.comp₂ (· • ·) hg
#align filter.eventually_eq.smul Filter.EventuallyEq.smul
#align filter.eventually_eq.vadd Filter.EventuallyEq.vadd
theorem EventuallyEq.sup [Sup β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x :=
hf.comp₂ (· ⊔ ·) hg
#align filter.eventually_eq.sup Filter.EventuallyEq.sup
theorem EventuallyEq.inf [Inf β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x :=
hf.comp₂ (· ⊓ ·) hg
#align filter.eventually_eq.inf Filter.EventuallyEq.inf
theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) :
f ⁻¹' s =ᶠ[l] g ⁻¹' s :=
h.fun_comp s
#align filter.eventually_eq.preimage Filter.EventuallyEq.preimage
theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) :=
h.comp₂ (· ∧ ·) h'
#align filter.eventually_eq.inter Filter.EventuallyEq.inter
theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) :=
h.comp₂ (· ∨ ·) h'
#align filter.eventually_eq.union Filter.EventuallyEq.union
theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) :
(sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) :=
h.fun_comp Not
#align filter.eventually_eq.compl Filter.EventuallyEq.compl
theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) :=
h.inter h'.compl
#align filter.eventually_eq.diff Filter.EventuallyEq.diff
theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s :=
eventuallyEq_set.trans <| by simp
#align filter.eventually_eq_empty Filter.eventuallyEq_empty
theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by
simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp]
#align filter.inter_eventually_eq_left Filter.inter_eventuallyEq_left
theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by
rw [inter_comm, inter_eventuallyEq_left]
#align filter.inter_eventually_eq_right Filter.inter_eventuallyEq_right
@[simp]
theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s :=
Iff.rfl
#align filter.eventually_eq_principal Filter.eventuallyEq_principal
theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} :
f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x :=
eventually_inf_principal
#align filter.eventually_eq_inf_principal_iff Filter.eventuallyEq_inf_principal_iff
theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm
#align filter.eventually_eq.sub_eq Filter.EventuallyEq.sub_eq
theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} :
f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 :=
⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩
#align filter.eventually_eq_iff_sub Filter.eventuallyEq_iff_sub
section LE
variable [LE β] {l : Filter α}
/-- A function `f` is eventually less than or equal to a function `g` at a filter `l`. -/
def EventuallyLE (l : Filter α) (f g : α → β) : Prop :=
∀ᶠ x in l, f x ≤ g x
#align filter.eventually_le Filter.EventuallyLE
@[inherit_doc]
notation:50 f " ≤ᶠ[" l:50 "] " g:50 => EventuallyLE l f g
theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f' ≤ᶠ[l] g' :=
H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H
#align filter.eventually_le.congr Filter.EventuallyLE.congr
theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' :=
⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩
#align filter.eventually_le_congr Filter.eventuallyLE_congr
end LE
section Preorder
variable [Preorder β] {l : Filter α} {f g h : α → β}
theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g :=
h.mono fun _ => le_of_eq
#align filter.eventually_eq.le Filter.EventuallyEq.le
@[refl]
theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f :=
EventuallyEq.rfl.le
#align filter.eventually_le.refl Filter.EventuallyLE.refl
theorem EventuallyLE.rfl : f ≤ᶠ[l] f :=
EventuallyLE.refl l f
#align filter.eventually_le.rfl Filter.EventuallyLE.rfl
@[trans]
theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h :=
H₂.mp <| H₁.mono fun _ => le_trans
#align filter.eventually_le.trans Filter.EventuallyLE.trans
instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyLE.trans
@[trans]
theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h :=
H₁.le.trans H₂
#align filter.eventually_eq.trans_le Filter.EventuallyEq.trans_le
instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyEq.trans_le
@[trans]
theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h :=
H₁.trans H₂.le
#align filter.eventually_le.trans_eq Filter.EventuallyLE.trans_eq
instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyLE.trans_eq
end Preorder
theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g)
(h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g :=
h₂.mp <| h₁.mono fun _ => le_antisymm
#align filter.eventually_le.antisymm Filter.EventuallyLE.antisymm
theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} :
f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by
simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and]
#align filter.eventually_le_antisymm_iff Filter.eventuallyLE_antisymm_iff
theorem EventuallyLE.le_iff_eq [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) :
g ≤ᶠ[l] f ↔ g =ᶠ[l] f :=
⟨fun h' => h'.antisymm h, EventuallyEq.le⟩
#align filter.eventually_le.le_iff_eq Filter.EventuallyLE.le_iff_eq
theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) :
∀ᶠ x in l, f x ≠ g x :=
h.mono fun _ hx => hx.ne
#align filter.eventually.ne_of_lt Filter.Eventually.ne_of_lt
theorem Eventually.ne_top_of_lt [PartialOrder β] [OrderTop β] {l : Filter α} {f g : α → β}
(h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ :=
h.mono fun _ hx => hx.ne_top
#align filter.eventually.ne_top_of_lt Filter.Eventually.ne_top_of_lt
theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β}
(h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ :=
h.mono fun _ hx => hx.lt_top
#align filter.eventually.lt_top_of_ne Filter.Eventually.lt_top_of_ne
theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} :
(∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ :=
⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩
#align filter.eventually.lt_top_iff_ne_top Filter.Eventually.lt_top_iff_ne_top
@[mono]
theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') :
(s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) :=
h'.mp <| h.mono fun _ => And.imp
#align filter.eventually_le.inter Filter.EventuallyLE.inter
@[mono]
theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') :
(s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) :=
h'.mp <| h.mono fun _ => Or.imp
#align filter.eventually_le.union Filter.EventuallyLE.union
protected lemma EventuallyLE.iUnion [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i ≤ᶠ[l] t i) : (⋃ i, s i) ≤ᶠ[l] ⋃ i, t i :=
(eventually_all.2 h).mono fun _x hx hx' ↦
let ⟨i, hi⟩ := mem_iUnion.1 hx'; mem_iUnion.2 ⟨i, hx i hi⟩
protected lemma EventuallyEq.iUnion [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i =ᶠ[l] t i) : (⋃ i, s i) =ᶠ[l] ⋃ i, t i :=
(EventuallyLE.iUnion fun i ↦ (h i).le).antisymm <| .iUnion fun i ↦ (h i).symm.le
protected lemma EventuallyLE.iInter [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i ≤ᶠ[l] t i) : (⋂ i, s i) ≤ᶠ[l] ⋂ i, t i :=
(eventually_all.2 h).mono fun _x hx hx' ↦ mem_iInter.2 fun i ↦ hx i (mem_iInter.1 hx' i)
protected lemma EventuallyEq.iInter [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i =ᶠ[l] t i) : (⋂ i, s i) =ᶠ[l] ⋂ i, t i :=
(EventuallyLE.iInter fun i ↦ (h i).le).antisymm <| .iInter fun i ↦ (h i).symm.le
lemma _root_.Set.Finite.eventuallyLE_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) := by
have := hs.to_subtype
rw [biUnion_eq_iUnion, biUnion_eq_iUnion]
exact .iUnion fun i ↦ hle i.1 i.2
alias EventuallyLE.biUnion := Set.Finite.eventuallyLE_iUnion
lemma _root_.Set.Finite.eventuallyEq_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) :=
(EventuallyLE.biUnion hs fun i hi ↦ (heq i hi).le).antisymm <|
.biUnion hs fun i hi ↦ (heq i hi).symm.le
alias EventuallyEq.biUnion := Set.Finite.eventuallyEq_iUnion
lemma _root_.Set.Finite.eventuallyLE_iInter {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) := by
have := hs.to_subtype
rw [biInter_eq_iInter, biInter_eq_iInter]
exact .iInter fun i ↦ hle i.1 i.2
alias EventuallyLE.biInter := Set.Finite.eventuallyLE_iInter
lemma _root_.Set.Finite.eventuallyEq_iInter {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) :=
(EventuallyLE.biInter hs fun i hi ↦ (heq i hi).le).antisymm <|
.biInter hs fun i hi ↦ (heq i hi).symm.le
alias EventuallyEq.biInter := Set.Finite.eventuallyEq_iInter
lemma _root_.Finset.eventuallyLE_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) :=
.biUnion s.finite_toSet hle
lemma _root_.Finset.eventuallyEq_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) :=
.biUnion s.finite_toSet heq
lemma _root_.Finset.eventuallyLE_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) :=
.biInter s.finite_toSet hle
lemma _root_.Finset.eventuallyEq_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) :=
.biInter s.finite_toSet heq
@[mono]
theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) :
(tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) :=
h.mono fun _ => mt
#align filter.eventually_le.compl Filter.EventuallyLE.compl
@[mono]
theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') :
(s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) :=
h.inter h'.compl
#align filter.eventually_le.diff Filter.EventuallyLE.diff
theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} :
s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s :=
eventually_inf_principal.symm
#align filter.set_eventually_le_iff_mem_inf_principal Filter.set_eventuallyLE_iff_mem_inf_principal
theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} :
s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t :=
set_eventuallyLE_iff_mem_inf_principal.trans <| by
simp only [le_inf_iff, inf_le_left, true_and_iff, le_principal_iff]
#align filter.set_eventually_le_iff_inf_principal_le Filter.set_eventuallyLE_iff_inf_principal_le
theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} :
s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by
simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le]
#align filter.set_eventually_eq_iff_inf_principal Filter.set_eventuallyEq_iff_inf_principal
theorem EventuallyLE.mul_le_mul [MulZeroClass β] [PartialOrder β] [PosMulMono β] [MulPosMono β]
{l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) (hg₀ : 0 ≤ᶠ[l] g₁)
(hf₀ : 0 ≤ᶠ[l] f₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by
filter_upwards [hf, hg, hg₀, hf₀] with x using _root_.mul_le_mul
#align filter.eventually_le.mul_le_mul Filter.EventuallyLE.mul_le_mul
@[to_additive EventuallyLE.add_le_add]
theorem EventuallyLE.mul_le_mul' [Mul β] [Preorder β] [CovariantClass β β (· * ·) (· ≤ ·)]
[CovariantClass β β (swap (· * ·)) (· ≤ ·)] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β}
(hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by
filter_upwards [hf, hg] with x hfx hgx using _root_.mul_le_mul' hfx hgx
#align filter.eventually_le.mul_le_mul' Filter.EventuallyLE.mul_le_mul'
#align filter.eventually_le.add_le_add Filter.EventuallyLE.add_le_add
theorem EventuallyLE.mul_nonneg [OrderedSemiring β] {l : Filter α} {f g : α → β} (hf : 0 ≤ᶠ[l] f)
(hg : 0 ≤ᶠ[l] g) : 0 ≤ᶠ[l] f * g := by filter_upwards [hf, hg] with x using _root_.mul_nonneg
#align filter.eventually_le.mul_nonneg Filter.EventuallyLE.mul_nonneg
theorem eventually_sub_nonneg [OrderedRing β] {l : Filter α} {f g : α → β} :
0 ≤ᶠ[l] g - f ↔ f ≤ᶠ[l] g :=
eventually_congr <| eventually_of_forall fun _ => sub_nonneg
#align filter.eventually_sub_nonneg Filter.eventually_sub_nonneg
theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂)
(hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by
filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx
#align filter.eventually_le.sup Filter.EventuallyLE.sup
theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h)
(hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by
filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx
#align filter.eventually_le.sup_le Filter.EventuallyLE.sup_le
theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β}
(hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g :=
hf.mono fun _ => _root_.le_sup_of_le_left
#align filter.eventually_le.le_sup_of_le_left Filter.EventuallyLE.le_sup_of_le_left
theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β}
(hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g :=
hg.mono fun _ => _root_.le_sup_of_le_right
#align filter.eventually_le.le_sup_of_le_right Filter.EventuallyLE.le_sup_of_le_right
theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l :=
fun _ hs => h.mono fun _ hm => hm hs
#align filter.join_le Filter.join_le
/-! ### Push-forwards, pull-backs, and the monad structure -/
section Map
/-- The forward map of a filter -/
def map (m : α → β) (f : Filter α) : Filter β where
sets := preimage m ⁻¹' f.sets
univ_sets := univ_mem
sets_of_superset hs st := mem_of_superset hs <| preimage_mono st
inter_sets hs ht := inter_mem hs ht
#align filter.map Filter.map
@[simp]
theorem map_principal {s : Set α} {f : α → β} : map f (𝓟 s) = 𝓟 (Set.image f s) :=
Filter.ext fun _ => image_subset_iff.symm
#align filter.map_principal Filter.map_principal
variable {f : Filter α} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β}
@[simp]
theorem eventually_map {P : β → Prop} : (∀ᶠ b in map m f, P b) ↔ ∀ᶠ a in f, P (m a) :=
Iff.rfl
#align filter.eventually_map Filter.eventually_map
@[simp]
theorem frequently_map {P : β → Prop} : (∃ᶠ b in map m f, P b) ↔ ∃ᶠ a in f, P (m a) :=
Iff.rfl
#align filter.frequently_map Filter.frequently_map
@[simp]
theorem mem_map : t ∈ map m f ↔ m ⁻¹' t ∈ f :=
Iff.rfl
#align filter.mem_map Filter.mem_map
theorem mem_map' : t ∈ map m f ↔ { x | m x ∈ t } ∈ f :=
Iff.rfl
#align filter.mem_map' Filter.mem_map'
theorem image_mem_map (hs : s ∈ f) : m '' s ∈ map m f :=
f.sets_of_superset hs <| subset_preimage_image m s
#align filter.image_mem_map Filter.image_mem_map
-- The simpNF linter says that the LHS can be simplified via `Filter.mem_map`.
-- However this is a higher priority lemma.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem image_mem_map_iff (hf : Injective m) : m '' s ∈ map m f ↔ s ∈ f :=
⟨fun h => by rwa [← preimage_image_eq s hf], image_mem_map⟩
#align filter.image_mem_map_iff Filter.image_mem_map_iff
theorem range_mem_map : range m ∈ map m f := by
rw [← image_univ]
exact image_mem_map univ_mem
#align filter.range_mem_map Filter.range_mem_map
theorem mem_map_iff_exists_image : t ∈ map m f ↔ ∃ s ∈ f, m '' s ⊆ t :=
⟨fun ht => ⟨m ⁻¹' t, ht, image_preimage_subset _ _⟩, fun ⟨_, hs, ht⟩ =>
mem_of_superset (image_mem_map hs) ht⟩
#align filter.mem_map_iff_exists_image Filter.mem_map_iff_exists_image
@[simp]
theorem map_id : Filter.map id f = f :=
filter_eq <| rfl
#align filter.map_id Filter.map_id
@[simp]
theorem map_id' : Filter.map (fun x => x) f = f :=
map_id
#align filter.map_id' Filter.map_id'
@[simp]
theorem map_compose : Filter.map m' ∘ Filter.map m = Filter.map (m' ∘ m) :=
funext fun _ => filter_eq <| rfl
#align filter.map_compose Filter.map_compose
@[simp]
theorem map_map : Filter.map m' (Filter.map m f) = Filter.map (m' ∘ m) f :=
congr_fun Filter.map_compose f
#align filter.map_map Filter.map_map
/-- If functions `m₁` and `m₂` are eventually equal at a filter `f`, then
they map this filter to the same filter. -/
theorem map_congr {m₁ m₂ : α → β} {f : Filter α} (h : m₁ =ᶠ[f] m₂) : map m₁ f = map m₂ f :=
Filter.ext' fun _ => eventually_congr (h.mono fun _ hx => hx ▸ Iff.rfl)
#align filter.map_congr Filter.map_congr
end Map
section Comap
/-- The inverse map of a filter. A set `s` belongs to `Filter.comap m f` if either of the following
equivalent conditions hold.
1. There exists a set `t ∈ f` such that `m ⁻¹' t ⊆ s`. This is used as a definition.
2. The set `kernImage m s = {y | ∀ x, m x = y → x ∈ s}` belongs to `f`, see `Filter.mem_comap'`.
3. The set `(m '' sᶜ)ᶜ` belongs to `f`, see `Filter.mem_comap_iff_compl` and
`Filter.compl_mem_comap`. -/
def comap (m : α → β) (f : Filter β) : Filter α where
sets := { s | ∃ t ∈ f, m ⁻¹' t ⊆ s }
univ_sets := ⟨univ, univ_mem, by simp only [subset_univ, preimage_univ]⟩
sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩
inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ =>
⟨a' ∩ b', inter_mem ha₁ hb₁, inter_subset_inter ha₂ hb₂⟩
#align filter.comap Filter.comap
variable {f : α → β} {l : Filter β} {p : α → Prop} {s : Set α}
theorem mem_comap' : s ∈ comap f l ↔ { y | ∀ ⦃x⦄, f x = y → x ∈ s } ∈ l :=
⟨fun ⟨t, ht, hts⟩ => mem_of_superset ht fun y hy x hx => hts <| mem_preimage.2 <| by rwa [hx],
fun h => ⟨_, h, fun x hx => hx rfl⟩⟩
#align filter.mem_comap' Filter.mem_comap'
-- TODO: it would be nice to use `kernImage` much more to take advantage of common name and API,
-- and then this would become `mem_comap'`
theorem mem_comap'' : s ∈ comap f l ↔ kernImage f s ∈ l :=
mem_comap'
/-- RHS form is used, e.g., in the definition of `UniformSpace`. -/
lemma mem_comap_prod_mk {x : α} {s : Set β} {F : Filter (α × β)} :
s ∈ comap (Prod.mk x) F ↔ {p : α × β | p.fst = x → p.snd ∈ s} ∈ F := by
simp_rw [mem_comap', Prod.ext_iff, and_imp, @forall_swap β (_ = _), forall_eq, eq_comm]
#align filter.mem_comap_prod_mk Filter.mem_comap_prod_mk
@[simp]
theorem eventually_comap : (∀ᶠ a in comap f l, p a) ↔ ∀ᶠ b in l, ∀ a, f a = b → p a :=
mem_comap'
#align filter.eventually_comap Filter.eventually_comap
@[simp]
theorem frequently_comap : (∃ᶠ a in comap f l, p a) ↔ ∃ᶠ b in l, ∃ a, f a = b ∧ p a := by
simp only [Filter.Frequently, eventually_comap, not_exists, _root_.not_and]
#align filter.frequently_comap Filter.frequently_comap
theorem mem_comap_iff_compl : s ∈ comap f l ↔ (f '' sᶜ)ᶜ ∈ l := by
simp only [mem_comap'', kernImage_eq_compl]
#align filter.mem_comap_iff_compl Filter.mem_comap_iff_compl
theorem compl_mem_comap : sᶜ ∈ comap f l ↔ (f '' s)ᶜ ∈ l := by rw [mem_comap_iff_compl, compl_compl]
#align filter.compl_mem_comap Filter.compl_mem_comap
end Comap
section KernMap
/-- The analog of `kernImage` for filters. A set `s` belongs to `Filter.kernMap m f` if either of
the following equivalent conditions hold.
1. There exists a set `t ∈ f` such that `s = kernImage m t`. This is used as a definition.
2. There exists a set `t` such that `tᶜ ∈ f` and `sᶜ = m '' t`, see `Filter.mem_kernMap_iff_compl`
and `Filter.compl_mem_kernMap`.
This definition because it gives a right adjoint to `Filter.comap`, and because it has a nice
interpretation when working with `co-` filters (`Filter.cocompact`, `Filter.cofinite`, ...).
For example, `kernMap m (cocompact α)` is the filter generated by the complements of the sets
`m '' K` where `K` is a compact subset of `α`. -/
def kernMap (m : α → β) (f : Filter α) : Filter β where
sets := (kernImage m) '' f.sets
univ_sets := ⟨univ, f.univ_sets, by simp [kernImage_eq_compl]⟩
sets_of_superset := by
rintro _ t ⟨s, hs, rfl⟩ hst
refine ⟨s ∪ m ⁻¹' t, mem_of_superset hs subset_union_left, ?_⟩
rw [kernImage_union_preimage, union_eq_right.mpr hst]
inter_sets := by
rintro _ _ ⟨s₁, h₁, rfl⟩ ⟨s₂, h₂, rfl⟩
exact ⟨s₁ ∩ s₂, f.inter_sets h₁ h₂, Set.preimage_kernImage.u_inf⟩
variable {m : α → β} {f : Filter α}
theorem mem_kernMap {s : Set β} : s ∈ kernMap m f ↔ ∃ t ∈ f, kernImage m t = s :=
Iff.rfl
theorem mem_kernMap_iff_compl {s : Set β} : s ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = sᶜ := by
rw [mem_kernMap, compl_surjective.exists]
refine exists_congr (fun x ↦ and_congr_right fun _ ↦ ?_)
rw [kernImage_compl, compl_eq_comm, eq_comm]
theorem compl_mem_kernMap {s : Set β} : sᶜ ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = s := by
simp_rw [mem_kernMap_iff_compl, compl_compl]
end KernMap
/-- The monadic bind operation on filter is defined the usual way in terms of `map` and `join`.
Unfortunately, this `bind` does not result in the expected applicative. See `Filter.seq` for the
applicative instance. -/
def bind (f : Filter α) (m : α → Filter β) : Filter β :=
join (map m f)
#align filter.bind Filter.bind
/-- The applicative sequentiation operation. This is not induced by the bind operation. -/
def seq (f : Filter (α → β)) (g : Filter α) : Filter β where
sets := { s | ∃ u ∈ f, ∃ t ∈ g, ∀ m ∈ u, ∀ x ∈ t, (m : α → β) x ∈ s }
univ_sets := ⟨univ, univ_mem, univ, univ_mem, fun _ _ _ _ => trivial⟩
sets_of_superset := fun ⟨t₀, t₁, h₀, h₁, h⟩ hst =>
⟨t₀, t₁, h₀, h₁, fun _ hx _ hy => hst <| h _ hx _ hy⟩
inter_sets := fun ⟨t₀, ht₀, t₁, ht₁, ht⟩ ⟨u₀, hu₀, u₁, hu₁, hu⟩ =>
⟨t₀ ∩ u₀, inter_mem ht₀ hu₀, t₁ ∩ u₁, inter_mem ht₁ hu₁, fun _ ⟨hx₀, hx₁⟩ _ ⟨hy₀, hy₁⟩ =>
⟨ht _ hx₀ _ hy₀, hu _ hx₁ _ hy₁⟩⟩
#align filter.seq Filter.seq
/-- `pure x` is the set of sets that contain `x`. It is equal to `𝓟 {x}` but
with this definition we have `s ∈ pure a` defeq `a ∈ s`. -/
instance : Pure Filter :=
⟨fun x =>
{ sets := { s | x ∈ s }
inter_sets := And.intro
sets_of_superset := fun hs hst => hst hs
univ_sets := trivial }⟩
instance : Bind Filter :=
⟨@Filter.bind⟩
instance : Functor Filter where map := @Filter.map
instance : LawfulFunctor (Filter : Type u → Type u) where
id_map _ := map_id
comp_map _ _ _ := map_map.symm
map_const := rfl
theorem pure_sets (a : α) : (pure a : Filter α).sets = { s | a ∈ s } :=
rfl
#align filter.pure_sets Filter.pure_sets
@[simp]
theorem mem_pure {a : α} {s : Set α} : s ∈ (pure a : Filter α) ↔ a ∈ s :=
Iff.rfl
#align filter.mem_pure Filter.mem_pure
@[simp]
theorem eventually_pure {a : α} {p : α → Prop} : (∀ᶠ x in pure a, p x) ↔ p a :=
Iff.rfl
#align filter.eventually_pure Filter.eventually_pure
@[simp]
theorem principal_singleton (a : α) : 𝓟 {a} = pure a :=
Filter.ext fun s => by simp only [mem_pure, mem_principal, singleton_subset_iff]
#align filter.principal_singleton Filter.principal_singleton
@[simp]
theorem map_pure (f : α → β) (a : α) : map f (pure a) = pure (f a) :=
rfl
#align filter.map_pure Filter.map_pure
theorem pure_le_principal (a : α) : pure a ≤ 𝓟 s ↔ a ∈ s := by
simp
@[simp] theorem join_pure (f : Filter α) : join (pure f) = f := rfl
#align filter.join_pure Filter.join_pure
@[simp]
theorem pure_bind (a : α) (m : α → Filter β) : bind (pure a) m = m a := by
simp only [Bind.bind, bind, map_pure, join_pure]
#align filter.pure_bind Filter.pure_bind
theorem map_bind {α β} (m : β → γ) (f : Filter α) (g : α → Filter β) :
map m (bind f g) = bind f (map m ∘ g) :=
rfl
theorem bind_map {α β} (m : α → β) (f : Filter α) (g : β → Filter γ) :
(bind (map m f) g) = bind f (g ∘ m) :=
rfl
/-!
### `Filter` as a `Monad`
In this section we define `Filter.monad`, a `Monad` structure on `Filter`s. This definition is not
an instance because its `Seq` projection is not equal to the `Filter.seq` function we use in the
`Applicative` instance on `Filter`.
-/
section
/-- The monad structure on filters. -/
protected def monad : Monad Filter where map := @Filter.map
#align filter.monad Filter.monad
attribute [local instance] Filter.monad
protected theorem lawfulMonad : LawfulMonad Filter where
map_const := rfl
id_map _ := rfl
seqLeft_eq _ _ := rfl
seqRight_eq _ _ := rfl
pure_seq _ _ := rfl
bind_pure_comp _ _ := rfl
bind_map _ _ := rfl
pure_bind _ _ := rfl
bind_assoc _ _ _ := rfl
#align filter.is_lawful_monad Filter.lawfulMonad
end
instance : Alternative Filter where
seq := fun x y => x.seq (y ())
failure := ⊥
orElse x y := x ⊔ y ()
@[simp]
theorem map_def {α β} (m : α → β) (f : Filter α) : m <$> f = map m f :=
rfl
#align filter.map_def Filter.map_def
@[simp]
theorem bind_def {α β} (f : Filter α) (m : α → Filter β) : f >>= m = bind f m :=
rfl
#align filter.bind_def Filter.bind_def
/-! #### `map` and `comap` equations -/
section Map
variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Filter β} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β}
@[simp] theorem mem_comap : s ∈ comap m g ↔ ∃ t ∈ g, m ⁻¹' t ⊆ s := Iff.rfl
#align filter.mem_comap Filter.mem_comap
theorem preimage_mem_comap (ht : t ∈ g) : m ⁻¹' t ∈ comap m g :=
⟨t, ht, Subset.rfl⟩
#align filter.preimage_mem_comap Filter.preimage_mem_comap
theorem Eventually.comap {p : β → Prop} (hf : ∀ᶠ b in g, p b) (f : α → β) :
∀ᶠ a in comap f g, p (f a) :=
preimage_mem_comap hf
#align filter.eventually.comap Filter.Eventually.comap
theorem comap_id : comap id f = f :=
le_antisymm (fun _ => preimage_mem_comap) fun _ ⟨_, ht, hst⟩ => mem_of_superset ht hst
#align filter.comap_id Filter.comap_id
theorem comap_id' : comap (fun x => x) f = f := comap_id
#align filter.comap_id' Filter.comap_id'
theorem comap_const_of_not_mem {x : β} (ht : t ∈ g) (hx : x ∉ t) : comap (fun _ : α => x) g = ⊥ :=
empty_mem_iff_bot.1 <| mem_comap'.2 <| mem_of_superset ht fun _ hx' _ h => hx <| h.symm ▸ hx'
#align filter.comap_const_of_not_mem Filter.comap_const_of_not_mem
theorem comap_const_of_mem {x : β} (h : ∀ t ∈ g, x ∈ t) : comap (fun _ : α => x) g = ⊤ :=
top_unique fun _ hs => univ_mem' fun _ => h _ (mem_comap'.1 hs) rfl
#align filter.comap_const_of_mem Filter.comap_const_of_mem
theorem map_const [NeBot f] {c : β} : (f.map fun _ => c) = pure c := by
ext s
by_cases h : c ∈ s <;> simp [h]
#align filter.map_const Filter.map_const
theorem comap_comap {m : γ → β} {n : β → α} : comap m (comap n f) = comap (n ∘ m) f :=
Filter.coext fun s => by simp only [compl_mem_comap, image_image, (· ∘ ·)]
#align filter.comap_comap Filter.comap_comap
section comm
/-!
The variables in the following lemmas are used as in this diagram:
```
φ
α → β
θ ↓ ↓ ψ
γ → δ
ρ
```
-/
variable {φ : α → β} {θ : α → γ} {ψ : β → δ} {ρ : γ → δ} (H : ψ ∘ φ = ρ ∘ θ)
theorem map_comm (F : Filter α) : map ψ (map φ F) = map ρ (map θ F) := by
rw [Filter.map_map, H, ← Filter.map_map]
#align filter.map_comm Filter.map_comm
theorem comap_comm (G : Filter δ) : comap φ (comap ψ G) = comap θ (comap ρ G) := by
rw [Filter.comap_comap, H, ← Filter.comap_comap]
#align filter.comap_comm Filter.comap_comm
end comm
theorem _root_.Function.Semiconj.filter_map {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) :=
map_comm h.comp_eq
#align function.semiconj.filter_map Function.Semiconj.filter_map
theorem _root_.Function.Commute.filter_map {f g : α → α} (h : Function.Commute f g) :
Function.Commute (map f) (map g) :=
h.semiconj.filter_map
#align function.commute.filter_map Function.Commute.filter_map
theorem _root_.Function.Semiconj.filter_comap {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (comap f) (comap gb) (comap ga) :=
comap_comm h.comp_eq.symm
#align function.semiconj.filter_comap Function.Semiconj.filter_comap
theorem _root_.Function.Commute.filter_comap {f g : α → α} (h : Function.Commute f g) :
Function.Commute (comap f) (comap g) :=
h.semiconj.filter_comap
#align function.commute.filter_comap Function.Commute.filter_comap
section
open Filter
theorem _root_.Function.LeftInverse.filter_map {f : α → β} {g : β → α} (hfg : LeftInverse g f) :
LeftInverse (map g) (map f) := fun F ↦ by
rw [map_map, hfg.comp_eq_id, map_id]
theorem _root_.Function.LeftInverse.filter_comap {f : α → β} {g : β → α} (hfg : LeftInverse g f) :
RightInverse (comap g) (comap f) := fun F ↦ by
rw [comap_comap, hfg.comp_eq_id, comap_id]
nonrec theorem _root_.Function.RightInverse.filter_map {f : α → β} {g : β → α}
(hfg : RightInverse g f) : RightInverse (map g) (map f) :=
hfg.filter_map
nonrec theorem _root_.Function.RightInverse.filter_comap {f : α → β} {g : β → α}
(hfg : RightInverse g f) : LeftInverse (comap g) (comap f) :=
hfg.filter_comap
theorem _root_.Set.LeftInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : LeftInvOn g f s) :
LeftInvOn (map g) (map f) (Iic <| 𝓟 s) := fun F (hF : F ≤ 𝓟 s) ↦ by
have : (g ∘ f) =ᶠ[𝓟 s] id := by simpa only [eventuallyEq_principal] using hfg
rw [map_map, map_congr (this.filter_mono hF), map_id]
nonrec theorem _root_.Set.RightInvOn.filter_map_Iic {f : α → β} {g : β → α}
(hfg : RightInvOn g f t) : RightInvOn (map g) (map f) (Iic <| 𝓟 t) :=
hfg.filter_map_Iic
end
@[simp]
theorem comap_principal {t : Set β} : comap m (𝓟 t) = 𝓟 (m ⁻¹' t) :=
Filter.ext fun _ => ⟨fun ⟨_u, hu, b⟩ => (preimage_mono hu).trans b,
fun h => ⟨t, Subset.rfl, h⟩⟩
#align filter.comap_principal Filter.comap_principal
theorem principal_subtype {α : Type*} (s : Set α) (t : Set s) :
𝓟 t = comap (↑) (𝓟 (((↑) : s → α) '' t)) := by
rw [comap_principal, preimage_image_eq _ Subtype.coe_injective]
#align principal_subtype Filter.principal_subtype
@[simp]
theorem comap_pure {b : β} : comap m (pure b) = 𝓟 (m ⁻¹' {b}) := by
rw [← principal_singleton, comap_principal]
#align filter.comap_pure Filter.comap_pure
theorem map_le_iff_le_comap : map m f ≤ g ↔ f ≤ comap m g :=
⟨fun h _ ⟨_, ht, hts⟩ => mem_of_superset (h ht) hts, fun h _ ht => h ⟨_, ht, Subset.rfl⟩⟩
#align filter.map_le_iff_le_comap Filter.map_le_iff_le_comap
theorem gc_map_comap (m : α → β) : GaloisConnection (map m) (comap m) :=
fun _ _ => map_le_iff_le_comap
#align filter.gc_map_comap Filter.gc_map_comap
theorem comap_le_iff_le_kernMap : comap m g ≤ f ↔ g ≤ kernMap m f := by
simp [Filter.le_def, mem_comap'', mem_kernMap, -mem_comap]
theorem gc_comap_kernMap (m : α → β) : GaloisConnection (comap m) (kernMap m) :=
fun _ _ ↦ comap_le_iff_le_kernMap
theorem kernMap_principal {s : Set α} : kernMap m (𝓟 s) = 𝓟 (kernImage m s) := by
refine eq_of_forall_le_iff (fun g ↦ ?_)
rw [← comap_le_iff_le_kernMap, le_principal_iff, le_principal_iff, mem_comap'']
@[mono]
theorem map_mono : Monotone (map m) :=
(gc_map_comap m).monotone_l
#align filter.map_mono Filter.map_mono
@[mono]
theorem comap_mono : Monotone (comap m) :=
(gc_map_comap m).monotone_u
#align filter.comap_mono Filter.comap_mono
/-- Temporary lemma that we can tag with `gcongr` -/
@[gcongr, deprecated] theorem map_le_map (h : F ≤ G) : map m F ≤ map m G := map_mono h
/-- Temporary lemma that we can tag with `gcongr` -/
@[gcongr, deprecated] theorem comap_le_comap (h : F ≤ G) : comap m F ≤ comap m G := comap_mono h
@[simp] theorem map_bot : map m ⊥ = ⊥ := (gc_map_comap m).l_bot
#align filter.map_bot Filter.map_bot
@[simp] theorem map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_comap m).l_sup
#align filter.map_sup Filter.map_sup
@[simp]
theorem map_iSup {f : ι → Filter α} : map m (⨆ i, f i) = ⨆ i, map m (f i) :=
(gc_map_comap m).l_iSup
#align filter.map_supr Filter.map_iSup
@[simp]
theorem map_top (f : α → β) : map f ⊤ = 𝓟 (range f) := by
rw [← principal_univ, map_principal, image_univ]
#align filter.map_top Filter.map_top
@[simp] theorem comap_top : comap m ⊤ = ⊤ := (gc_map_comap m).u_top
#align filter.comap_top Filter.comap_top
@[simp] theorem comap_inf : comap m (g₁ ⊓ g₂) = comap m g₁ ⊓ comap m g₂ := (gc_map_comap m).u_inf
#align filter.comap_inf Filter.comap_inf
@[simp]
theorem comap_iInf {f : ι → Filter β} : comap m (⨅ i, f i) = ⨅ i, comap m (f i) :=
(gc_map_comap m).u_iInf
#align filter.comap_infi Filter.comap_iInf
theorem le_comap_top (f : α → β) (l : Filter α) : l ≤ comap f ⊤ := by
rw [comap_top]
exact le_top
#align filter.le_comap_top Filter.le_comap_top
theorem map_comap_le : map m (comap m g) ≤ g :=
(gc_map_comap m).l_u_le _
#align filter.map_comap_le Filter.map_comap_le
theorem le_comap_map : f ≤ comap m (map m f) :=
(gc_map_comap m).le_u_l _
#align filter.le_comap_map Filter.le_comap_map
@[simp]
theorem comap_bot : comap m ⊥ = ⊥ :=
bot_unique fun s _ => ⟨∅, mem_bot, by simp only [empty_subset, preimage_empty]⟩
#align filter.comap_bot Filter.comap_bot
theorem neBot_of_comap (h : (comap m g).NeBot) : g.NeBot := by
rw [neBot_iff] at *
contrapose! h
rw [h]
exact comap_bot
#align filter.ne_bot_of_comap Filter.neBot_of_comap
theorem comap_inf_principal_range : comap m (g ⊓ 𝓟 (range m)) = comap m g := by
simp
#align filter.comap_inf_principal_range Filter.comap_inf_principal_range
theorem disjoint_comap (h : Disjoint g₁ g₂) : Disjoint (comap m g₁) (comap m g₂) := by
simp only [disjoint_iff, ← comap_inf, h.eq_bot, comap_bot]
#align filter.disjoint_comap Filter.disjoint_comap
theorem comap_iSup {ι} {f : ι → Filter β} {m : α → β} : comap m (iSup f) = ⨆ i, comap m (f i) :=
(gc_comap_kernMap m).l_iSup
#align filter.comap_supr Filter.comap_iSup
theorem comap_sSup {s : Set (Filter β)} {m : α → β} : comap m (sSup s) = ⨆ f ∈ s, comap m f := by
simp only [sSup_eq_iSup, comap_iSup, eq_self_iff_true]
#align filter.comap_Sup Filter.comap_sSup
theorem comap_sup : comap m (g₁ ⊔ g₂) = comap m g₁ ⊔ comap m g₂ := by
rw [sup_eq_iSup, comap_iSup, iSup_bool_eq, Bool.cond_true, Bool.cond_false]
#align filter.comap_sup Filter.comap_sup
theorem map_comap (f : Filter β) (m : α → β) : (f.comap m).map m = f ⊓ 𝓟 (range m) := by
refine le_antisymm (le_inf map_comap_le <| le_principal_iff.2 range_mem_map) ?_
rintro t' ⟨t, ht, sub⟩
refine mem_inf_principal.2 (mem_of_superset ht ?_)
rintro _ hxt ⟨x, rfl⟩
exact sub hxt
#align filter.map_comap Filter.map_comap
theorem map_comap_setCoe_val (f : Filter β) (s : Set β) :
(f.comap ((↑) : s → β)).map (↑) = f ⊓ 𝓟 s := by
rw [map_comap, Subtype.range_val]
theorem map_comap_of_mem {f : Filter β} {m : α → β} (hf : range m ∈ f) : (f.comap m).map m = f := by
rw [map_comap, inf_eq_left.2 (le_principal_iff.2 hf)]
#align filter.map_comap_of_mem Filter.map_comap_of_mem
instance canLift (c) (p) [CanLift α β c p] :
CanLift (Filter α) (Filter β) (map c) fun f => ∀ᶠ x : α in f, p x where
prf f hf := ⟨comap c f, map_comap_of_mem <| hf.mono CanLift.prf⟩
#align filter.can_lift Filter.canLift
theorem comap_le_comap_iff {f g : Filter β} {m : α → β} (hf : range m ∈ f) :
comap m f ≤ comap m g ↔ f ≤ g :=
⟨fun h => map_comap_of_mem hf ▸ (map_mono h).trans map_comap_le, fun h => comap_mono h⟩
#align filter.comap_le_comap_iff Filter.comap_le_comap_iff
theorem map_comap_of_surjective {f : α → β} (hf : Surjective f) (l : Filter β) :
map f (comap f l) = l :=
map_comap_of_mem <| by simp only [hf.range_eq, univ_mem]
#align filter.map_comap_of_surjective Filter.map_comap_of_surjective
theorem comap_injective {f : α → β} (hf : Surjective f) : Injective (comap f) :=
LeftInverse.injective <| map_comap_of_surjective hf
theorem _root_.Function.Surjective.filter_map_top {f : α → β} (hf : Surjective f) : map f ⊤ = ⊤ :=
(congr_arg _ comap_top).symm.trans <| map_comap_of_surjective hf ⊤
#align function.surjective.filter_map_top Function.Surjective.filter_map_top
theorem subtype_coe_map_comap (s : Set α) (f : Filter α) :
map ((↑) : s → α) (comap ((↑) : s → α) f) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_coe]
#align filter.subtype_coe_map_comap Filter.subtype_coe_map_comap
theorem image_mem_of_mem_comap {f : Filter α} {c : β → α} (h : range c ∈ f) {W : Set β}
(W_in : W ∈ comap c f) : c '' W ∈ f := by
rw [← map_comap_of_mem h]
exact image_mem_map W_in
#align filter.image_mem_of_mem_comap Filter.image_mem_of_mem_comap
theorem image_coe_mem_of_mem_comap {f : Filter α} {U : Set α} (h : U ∈ f) {W : Set U}
(W_in : W ∈ comap ((↑) : U → α) f) : (↑) '' W ∈ f :=
image_mem_of_mem_comap (by simp [h]) W_in
#align filter.image_coe_mem_of_mem_comap Filter.image_coe_mem_of_mem_comap
theorem comap_map {f : Filter α} {m : α → β} (h : Injective m) : comap m (map m f) = f :=
le_antisymm
(fun s hs =>
mem_of_superset (preimage_mem_comap <| image_mem_map hs) <| by
simp only [preimage_image_eq s h, Subset.rfl])
le_comap_map
#align filter.comap_map Filter.comap_map
theorem mem_comap_iff {f : Filter β} {m : α → β} (inj : Injective m) (large : Set.range m ∈ f)
{S : Set α} : S ∈ comap m f ↔ m '' S ∈ f := by
rw [← image_mem_map_iff inj, map_comap_of_mem large]
#align filter.mem_comap_iff Filter.mem_comap_iff
theorem map_le_map_iff_of_injOn {l₁ l₂ : Filter α} {f : α → β} {s : Set α} (h₁ : s ∈ l₁)
(h₂ : s ∈ l₂) (hinj : InjOn f s) : map f l₁ ≤ map f l₂ ↔ l₁ ≤ l₂ :=
⟨fun h _t ht =>
mp_mem h₁ <|
mem_of_superset (h <| image_mem_map (inter_mem h₂ ht)) fun _y ⟨_x, ⟨hxs, hxt⟩, hxy⟩ hys =>
hinj hxs hys hxy ▸ hxt,
fun h => map_mono h⟩
#align filter.map_le_map_iff_of_inj_on Filter.map_le_map_iff_of_injOn
theorem map_le_map_iff {f g : Filter α} {m : α → β} (hm : Injective m) :
map m f ≤ map m g ↔ f ≤ g := by rw [map_le_iff_le_comap, comap_map hm]
#align filter.map_le_map_iff Filter.map_le_map_iff
theorem map_eq_map_iff_of_injOn {f g : Filter α} {m : α → β} {s : Set α} (hsf : s ∈ f) (hsg : s ∈ g)
(hm : InjOn m s) : map m f = map m g ↔ f = g := by
simp only [le_antisymm_iff, map_le_map_iff_of_injOn hsf hsg hm,
map_le_map_iff_of_injOn hsg hsf hm]
#align filter.map_eq_map_iff_of_inj_on Filter.map_eq_map_iff_of_injOn
theorem map_inj {f g : Filter α} {m : α → β} (hm : Injective m) : map m f = map m g ↔ f = g :=
map_eq_map_iff_of_injOn univ_mem univ_mem hm.injOn
#align filter.map_inj Filter.map_inj
theorem map_injective {m : α → β} (hm : Injective m) : Injective (map m) := fun _ _ =>
(map_inj hm).1
#align filter.map_injective Filter.map_injective
theorem comap_neBot_iff {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∀ t ∈ f, ∃ a, m a ∈ t := by
simp only [← forall_mem_nonempty_iff_neBot, mem_comap, forall_exists_index, and_imp]
exact ⟨fun h t t_in => h (m ⁻¹' t) t t_in Subset.rfl, fun h s t ht hst => (h t ht).imp hst⟩
#align filter.comap_ne_bot_iff Filter.comap_neBot_iff
theorem comap_neBot {f : Filter β} {m : α → β} (hm : ∀ t ∈ f, ∃ a, m a ∈ t) : NeBot (comap m f) :=
comap_neBot_iff.mpr hm
#align filter.comap_ne_bot Filter.comap_neBot
theorem comap_neBot_iff_frequently {f : Filter β} {m : α → β} :
NeBot (comap m f) ↔ ∃ᶠ y in f, y ∈ range m := by
simp only [comap_neBot_iff, frequently_iff, mem_range, @and_comm (_ ∈ _), exists_exists_eq_and]
#align filter.comap_ne_bot_iff_frequently Filter.comap_neBot_iff_frequently
theorem comap_neBot_iff_compl_range {f : Filter β} {m : α → β} :
NeBot (comap m f) ↔ (range m)ᶜ ∉ f :=
comap_neBot_iff_frequently
#align filter.comap_ne_bot_iff_compl_range Filter.comap_neBot_iff_compl_range
theorem comap_eq_bot_iff_compl_range {f : Filter β} {m : α → β} : comap m f = ⊥ ↔ (range m)ᶜ ∈ f :=
not_iff_not.mp <| neBot_iff.symm.trans comap_neBot_iff_compl_range
#align filter.comap_eq_bot_iff_compl_range Filter.comap_eq_bot_iff_compl_range
theorem comap_surjective_eq_bot {f : Filter β} {m : α → β} (hm : Surjective m) :
comap m f = ⊥ ↔ f = ⊥ := by
rw [comap_eq_bot_iff_compl_range, hm.range_eq, compl_univ, empty_mem_iff_bot]
#align filter.comap_surjective_eq_bot Filter.comap_surjective_eq_bot
theorem disjoint_comap_iff (h : Surjective m) :
Disjoint (comap m g₁) (comap m g₂) ↔ Disjoint g₁ g₂ := by
rw [disjoint_iff, disjoint_iff, ← comap_inf, comap_surjective_eq_bot h]
#align filter.disjoint_comap_iff Filter.disjoint_comap_iff
theorem NeBot.comap_of_range_mem {f : Filter β} {m : α → β} (_ : NeBot f) (hm : range m ∈ f) :
NeBot (comap m f) :=
comap_neBot_iff_frequently.2 <| Eventually.frequently hm
#align filter.ne_bot.comap_of_range_mem Filter.NeBot.comap_of_range_mem
@[simp]
theorem comap_fst_neBot_iff {f : Filter α} :
(f.comap (Prod.fst : α × β → α)).NeBot ↔ f.NeBot ∧ Nonempty β := by
cases isEmpty_or_nonempty β
· rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp [*]
· simp [comap_neBot_iff_frequently, *]
#align filter.comap_fst_ne_bot_iff Filter.comap_fst_neBot_iff
@[instance]
theorem comap_fst_neBot [Nonempty β] {f : Filter α} [NeBot f] :
(f.comap (Prod.fst : α × β → α)).NeBot :=
comap_fst_neBot_iff.2 ⟨‹_›, ‹_›⟩
#align filter.comap_fst_ne_bot Filter.comap_fst_neBot
@[simp]
theorem comap_snd_neBot_iff {f : Filter β} :
(f.comap (Prod.snd : α × β → β)).NeBot ↔ Nonempty α ∧ f.NeBot := by
cases' isEmpty_or_nonempty α with hα hα
· rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp
· simp [comap_neBot_iff_frequently, hα]
#align filter.comap_snd_ne_bot_iff Filter.comap_snd_neBot_iff
@[instance]
theorem comap_snd_neBot [Nonempty α] {f : Filter β} [NeBot f] :
(f.comap (Prod.snd : α × β → β)).NeBot :=
comap_snd_neBot_iff.2 ⟨‹_›, ‹_›⟩
#align filter.comap_snd_ne_bot Filter.comap_snd_neBot
theorem comap_eval_neBot_iff' {ι : Type*} {α : ι → Type*} {i : ι} {f : Filter (α i)} :
(comap (eval i) f).NeBot ↔ (∀ j, Nonempty (α j)) ∧ NeBot f := by
cases' isEmpty_or_nonempty (∀ j, α j) with H H
· rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]
simp [← Classical.nonempty_pi]
· have : ∀ j, Nonempty (α j) := Classical.nonempty_pi.1 H
simp [comap_neBot_iff_frequently, *]
#align filter.comap_eval_ne_bot_iff' Filter.comap_eval_neBot_iff'
@[simp]
theorem comap_eval_neBot_iff {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] {i : ι}
{f : Filter (α i)} : (comap (eval i) f).NeBot ↔ NeBot f := by simp [comap_eval_neBot_iff', *]
#align filter.comap_eval_ne_bot_iff Filter.comap_eval_neBot_iff
@[instance]
theorem comap_eval_neBot {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] (i : ι)
(f : Filter (α i)) [NeBot f] : (comap (eval i) f).NeBot :=
comap_eval_neBot_iff.2 ‹_›
#align filter.comap_eval_ne_bot Filter.comap_eval_neBot
theorem comap_inf_principal_neBot_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α}
(hs : m '' s ∈ f) : NeBot (comap m f ⊓ 𝓟 s) := by
refine ⟨compl_compl s ▸ mt mem_of_eq_bot ?_⟩
rintro ⟨t, ht, hts⟩
rcases hf.nonempty_of_mem (inter_mem hs ht) with ⟨_, ⟨x, hxs, rfl⟩, hxt⟩
exact absurd hxs (hts hxt)
#align filter.comap_inf_principal_ne_bot_of_image_mem Filter.comap_inf_principal_neBot_of_image_mem
theorem comap_coe_neBot_of_le_principal {s : Set γ} {l : Filter γ} [h : NeBot l] (h' : l ≤ 𝓟 s) :
NeBot (comap ((↑) : s → γ) l) :=
h.comap_of_range_mem <| (@Subtype.range_coe γ s).symm ▸ h' (mem_principal_self s)
#align filter.comap_coe_ne_bot_of_le_principal Filter.comap_coe_neBot_of_le_principal
theorem NeBot.comap_of_surj {f : Filter β} {m : α → β} (hf : NeBot f) (hm : Surjective m) :
NeBot (comap m f) :=
hf.comap_of_range_mem <| univ_mem' hm
#align filter.ne_bot.comap_of_surj Filter.NeBot.comap_of_surj
theorem NeBot.comap_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α}
(hs : m '' s ∈ f) : NeBot (comap m f) :=
hf.comap_of_range_mem <| mem_of_superset hs (image_subset_range _ _)
#align filter.ne_bot.comap_of_image_mem Filter.NeBot.comap_of_image_mem
@[simp]
theorem map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ :=
⟨by
rw [← empty_mem_iff_bot, ← empty_mem_iff_bot]
exact id, fun h => by simp only [h, map_bot]⟩
#align filter.map_eq_bot_iff Filter.map_eq_bot_iff
theorem map_neBot_iff (f : α → β) {F : Filter α} : NeBot (map f F) ↔ NeBot F := by
simp only [neBot_iff, Ne, map_eq_bot_iff]
#align filter.map_ne_bot_iff Filter.map_neBot_iff
theorem NeBot.map (hf : NeBot f) (m : α → β) : NeBot (map m f) :=
(map_neBot_iff m).2 hf
#align filter.ne_bot.map Filter.NeBot.map
theorem NeBot.of_map : NeBot (f.map m) → NeBot f :=
(map_neBot_iff m).1
#align filter.ne_bot.of_map Filter.NeBot.of_map
instance map_neBot [hf : NeBot f] : NeBot (f.map m) :=
hf.map m
#align filter.map_ne_bot Filter.map_neBot
theorem sInter_comap_sets (f : α → β) (F : Filter β) : ⋂₀ (comap f F).sets = ⋂ U ∈ F, f ⁻¹' U := by
ext x
suffices (∀ (A : Set α) (B : Set β), B ∈ F → f ⁻¹' B ⊆ A → x ∈ A) ↔
∀ B : Set β, B ∈ F → f x ∈ B by
simp only [mem_sInter, mem_iInter, Filter.mem_sets, mem_comap, this, and_imp, exists_prop,
mem_preimage, exists_imp]
constructor
· intro h U U_in
simpa only [Subset.rfl, forall_prop_of_true, mem_preimage] using h (f ⁻¹' U) U U_in
· intro h V U U_in f_U_V
exact f_U_V (h U U_in)
#align filter.sInter_comap_sets Filter.sInter_comap_sets
end Map
-- this is a generic rule for monotone functions:
theorem map_iInf_le {f : ι → Filter α} {m : α → β} : map m (iInf f) ≤ ⨅ i, map m (f i) :=
le_iInf fun _ => map_mono <| iInf_le _ _
#align filter.map_infi_le Filter.map_iInf_le
theorem map_iInf_eq {f : ι → Filter α} {m : α → β} (hf : Directed (· ≥ ·) f) [Nonempty ι] :
map m (iInf f) = ⨅ i, map m (f i) :=
map_iInf_le.antisymm fun s (hs : m ⁻¹' s ∈ iInf f) =>
let ⟨i, hi⟩ := (mem_iInf_of_directed hf _).1 hs
have : ⨅ i, map m (f i) ≤ 𝓟 s :=
iInf_le_of_le i <| by simpa only [le_principal_iff, mem_map]
Filter.le_principal_iff.1 this
#align filter.map_infi_eq Filter.map_iInf_eq
theorem map_biInf_eq {ι : Type w} {f : ι → Filter α} {m : α → β} {p : ι → Prop}
(h : DirectedOn (f ⁻¹'o (· ≥ ·)) { x | p x }) (ne : ∃ i, p i) :
map m (⨅ (i) (_ : p i), f i) = ⨅ (i) (_ : p i), map m (f i) := by
haveI := nonempty_subtype.2 ne
simp only [iInf_subtype']
exact map_iInf_eq h.directed_val
#align filter.map_binfi_eq Filter.map_biInf_eq
theorem map_inf_le {f g : Filter α} {m : α → β} : map m (f ⊓ g) ≤ map m f ⊓ map m g :=
(@map_mono _ _ m).map_inf_le f g
#align filter.map_inf_le Filter.map_inf_le
theorem map_inf {f g : Filter α} {m : α → β} (h : Injective m) :
map m (f ⊓ g) = map m f ⊓ map m g := by
refine map_inf_le.antisymm ?_
rintro t ⟨s₁, hs₁, s₂, hs₂, ht : m ⁻¹' t = s₁ ∩ s₂⟩
refine mem_inf_of_inter (image_mem_map hs₁) (image_mem_map hs₂) ?_
rw [← image_inter h, image_subset_iff, ht]
#align filter.map_inf Filter.map_inf
theorem map_inf' {f g : Filter α} {m : α → β} {t : Set α} (htf : t ∈ f) (htg : t ∈ g)
(h : InjOn m t) : map m (f ⊓ g) = map m f ⊓ map m g := by
lift f to Filter t using htf; lift g to Filter t using htg
replace h : Injective (m ∘ ((↑) : t → α)) := h.injective
simp only [map_map, ← map_inf Subtype.coe_injective, map_inf h]
#align filter.map_inf' Filter.map_inf'
lemma disjoint_of_map {α β : Type*} {F G : Filter α} {f : α → β}
(h : Disjoint (map f F) (map f G)) : Disjoint F G :=
disjoint_iff.mpr <| map_eq_bot_iff.mp <| le_bot_iff.mp <| trans map_inf_le (disjoint_iff.mp h)
theorem disjoint_map {m : α → β} (hm : Injective m) {f₁ f₂ : Filter α} :
Disjoint (map m f₁) (map m f₂) ↔ Disjoint f₁ f₂ := by
simp only [disjoint_iff, ← map_inf hm, map_eq_bot_iff]
#align filter.disjoint_map Filter.disjoint_map
theorem map_equiv_symm (e : α ≃ β) (f : Filter β) : map e.symm f = comap e f :=
map_injective e.injective <| by
rw [map_map, e.self_comp_symm, map_id, map_comap_of_surjective e.surjective]
#align filter.map_equiv_symm Filter.map_equiv_symm
theorem map_eq_comap_of_inverse {f : Filter α} {m : α → β} {n : β → α} (h₁ : m ∘ n = id)
(h₂ : n ∘ m = id) : map m f = comap n f :=
map_equiv_symm ⟨n, m, congr_fun h₁, congr_fun h₂⟩ f
#align filter.map_eq_comap_of_inverse Filter.map_eq_comap_of_inverse
theorem comap_equiv_symm (e : α ≃ β) (f : Filter α) : comap e.symm f = map e f :=
(map_eq_comap_of_inverse e.self_comp_symm e.symm_comp_self).symm
#align filter.comap_equiv_symm Filter.comap_equiv_symm
theorem map_swap_eq_comap_swap {f : Filter (α × β)} : Prod.swap <$> f = comap Prod.swap f :=
map_eq_comap_of_inverse Prod.swap_swap_eq Prod.swap_swap_eq
#align filter.map_swap_eq_comap_swap Filter.map_swap_eq_comap_swap
/-- A useful lemma when dealing with uniformities. -/
theorem map_swap4_eq_comap {f : Filter ((α × β) × γ × δ)} :
map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f =
comap (fun p : (α × γ) × β × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f :=
map_eq_comap_of_inverse (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl)
#align filter.map_swap4_eq_comap Filter.map_swap4_eq_comap
theorem le_map {f : Filter α} {m : α → β} {g : Filter β} (h : ∀ s ∈ f, m '' s ∈ g) : g ≤ f.map m :=
fun _ hs => mem_of_superset (h _ hs) <| image_preimage_subset _ _
#align filter.le_map Filter.le_map
theorem le_map_iff {f : Filter α} {m : α → β} {g : Filter β} : g ≤ f.map m ↔ ∀ s ∈ f, m '' s ∈ g :=
⟨fun h _ hs => h (image_mem_map hs), le_map⟩
#align filter.le_map_iff Filter.le_map_iff
protected theorem push_pull (f : α → β) (F : Filter α) (G : Filter β) :
map f (F ⊓ comap f G) = map f F ⊓ G := by
apply le_antisymm
· calc
map f (F ⊓ comap f G) ≤ map f F ⊓ (map f <| comap f G) := map_inf_le
_ ≤ map f F ⊓ G := inf_le_inf_left (map f F) map_comap_le
· rintro U ⟨V, V_in, W, ⟨Z, Z_in, hZ⟩, h⟩
apply mem_inf_of_inter (image_mem_map V_in) Z_in
calc
f '' V ∩ Z = f '' (V ∩ f ⁻¹' Z) := by rw [image_inter_preimage]
_ ⊆ f '' (V ∩ W) := image_subset _ (inter_subset_inter_right _ ‹_›)
_ = f '' (f ⁻¹' U) := by rw [h]
_ ⊆ U := image_preimage_subset f U
#align filter.push_pull Filter.push_pull
protected theorem push_pull' (f : α → β) (F : Filter α) (G : Filter β) :
map f (comap f G ⊓ F) = G ⊓ map f F := by simp only [Filter.push_pull, inf_comm]
#align filter.push_pull' Filter.push_pull'
theorem principal_eq_map_coe_top (s : Set α) : 𝓟 s = map ((↑) : s → α) ⊤ := by simp
#align filter.principal_eq_map_coe_top Filter.principal_eq_map_coe_top
theorem inf_principal_eq_bot_iff_comap {F : Filter α} {s : Set α} :
F ⊓ 𝓟 s = ⊥ ↔ comap ((↑) : s → α) F = ⊥ := by
rw [principal_eq_map_coe_top s, ← Filter.push_pull', inf_top_eq, map_eq_bot_iff]
#align filter.inf_principal_eq_bot_iff_comap Filter.inf_principal_eq_bot_iff_comap
section Applicative
theorem singleton_mem_pure {a : α} : {a} ∈ (pure a : Filter α) :=
mem_singleton a
#align filter.singleton_mem_pure Filter.singleton_mem_pure
theorem pure_injective : Injective (pure : α → Filter α) := fun a _ hab =>
(Filter.ext_iff.1 hab { x | a = x }).1 rfl
#align filter.pure_injective Filter.pure_injective
instance pure_neBot {α : Type u} {a : α} : NeBot (pure a) :=
⟨mt empty_mem_iff_bot.2 <| not_mem_empty a⟩
#align filter.pure_ne_bot Filter.pure_neBot
@[simp]
theorem le_pure_iff {f : Filter α} {a : α} : f ≤ pure a ↔ {a} ∈ f := by
rw [← principal_singleton, le_principal_iff]
#align filter.le_pure_iff Filter.le_pure_iff
theorem mem_seq_def {f : Filter (α → β)} {g : Filter α} {s : Set β} :
s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, ∀ x ∈ u, ∀ y ∈ t, (x : α → β) y ∈ s :=
Iff.rfl
#align filter.mem_seq_def Filter.mem_seq_def
theorem mem_seq_iff {f : Filter (α → β)} {g : Filter α} {s : Set β} :
s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, Set.seq u t ⊆ s := by
simp only [mem_seq_def, seq_subset, exists_prop, iff_self_iff]
#align filter.mem_seq_iff Filter.mem_seq_iff
theorem mem_map_seq_iff {f : Filter α} {g : Filter β} {m : α → β → γ} {s : Set γ} :
s ∈ (f.map m).seq g ↔ ∃ t u, t ∈ g ∧ u ∈ f ∧ ∀ x ∈ u, ∀ y ∈ t, m x y ∈ s :=
Iff.intro (fun ⟨t, ht, s, hs, hts⟩ => ⟨s, m ⁻¹' t, hs, ht, fun _ => hts _⟩)
fun ⟨t, s, ht, hs, hts⟩ =>
⟨m '' s, image_mem_map hs, t, ht, fun _ ⟨_, has, Eq⟩ => Eq ▸ hts _ has⟩
#align filter.mem_map_seq_iff Filter.mem_map_seq_iff
theorem seq_mem_seq {f : Filter (α → β)} {g : Filter α} {s : Set (α → β)} {t : Set α} (hs : s ∈ f)
(ht : t ∈ g) : s.seq t ∈ f.seq g :=
⟨s, hs, t, ht, fun f hf a ha => ⟨f, hf, a, ha, rfl⟩⟩
#align filter.seq_mem_seq Filter.seq_mem_seq
theorem le_seq {f : Filter (α → β)} {g : Filter α} {h : Filter β}
(hh : ∀ t ∈ f, ∀ u ∈ g, Set.seq t u ∈ h) : h ≤ seq f g := fun _ ⟨_, ht, _, hu, hs⟩ =>
mem_of_superset (hh _ ht _ hu) fun _ ⟨_, hm, _, ha, eq⟩ => eq ▸ hs _ hm _ ha
#align filter.le_seq Filter.le_seq
@[mono]
theorem seq_mono {f₁ f₂ : Filter (α → β)} {g₁ g₂ : Filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
f₁.seq g₁ ≤ f₂.seq g₂ :=
le_seq fun _ hs _ ht => seq_mem_seq (hf hs) (hg ht)
#align filter.seq_mono Filter.seq_mono
@[simp]
theorem pure_seq_eq_map (g : α → β) (f : Filter α) : seq (pure g) f = f.map g := by
refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_)
· rw [← singleton_seq]
apply seq_mem_seq _ hs
exact singleton_mem_pure
· refine sets_of_superset (map g f) (image_mem_map ht) ?_
rintro b ⟨a, ha, rfl⟩
exact ⟨g, hs, a, ha, rfl⟩
#align filter.pure_seq_eq_map Filter.pure_seq_eq_map
@[simp]
theorem seq_pure (f : Filter (α → β)) (a : α) : seq f (pure a) = map (fun g : α → β => g a) f := by
refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_)
· rw [← seq_singleton]
exact seq_mem_seq hs singleton_mem_pure
· refine sets_of_superset (map (fun g : α → β => g a) f) (image_mem_map hs) ?_
rintro b ⟨g, hg, rfl⟩
exact ⟨g, hg, a, ht, rfl⟩
#align filter.seq_pure Filter.seq_pure
@[simp]
theorem seq_assoc (x : Filter α) (g : Filter (α → β)) (h : Filter (β → γ)) :
seq h (seq g x) = seq (seq (map (· ∘ ·) h) g) x := by
refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_)
· rcases mem_seq_iff.1 hs with ⟨u, hu, v, hv, hs⟩
rcases mem_map_iff_exists_image.1 hu with ⟨w, hw, hu⟩
refine mem_of_superset ?_ (Set.seq_mono ((Set.seq_mono hu Subset.rfl).trans hs) Subset.rfl)
rw [← Set.seq_seq]
exact seq_mem_seq hw (seq_mem_seq hv ht)
· rcases mem_seq_iff.1 ht with ⟨u, hu, v, hv, ht⟩
refine mem_of_superset ?_ (Set.seq_mono Subset.rfl ht)
rw [Set.seq_seq]
exact seq_mem_seq (seq_mem_seq (image_mem_map hs) hu) hv
#align filter.seq_assoc Filter.seq_assoc
theorem prod_map_seq_comm (f : Filter α) (g : Filter β) :
(map Prod.mk f).seq g = seq (map (fun b a => (a, b)) g) f := by
refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_)
· rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩
refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl)
rw [← Set.prod_image_seq_comm]
exact seq_mem_seq (image_mem_map ht) hu
· rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩
refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl)
rw [Set.prod_image_seq_comm]
exact seq_mem_seq (image_mem_map ht) hu
#align filter.prod_map_seq_comm Filter.prod_map_seq_comm
theorem seq_eq_filter_seq {α β : Type u} (f : Filter (α → β)) (g : Filter α) :
f <*> g = seq f g :=
rfl
#align filter.seq_eq_filter_seq Filter.seq_eq_filter_seq
instance : LawfulApplicative (Filter : Type u → Type u) where
map_pure := map_pure
seqLeft_eq _ _ := rfl
seqRight_eq _ _ := rfl
seq_pure := seq_pure
pure_seq := pure_seq_eq_map
seq_assoc := seq_assoc
instance : CommApplicative (Filter : Type u → Type u) :=
⟨fun f g => prod_map_seq_comm f g⟩
end Applicative
/-! #### `bind` equations -/
section Bind
@[simp]
theorem eventually_bind {f : Filter α} {m : α → Filter β} {p : β → Prop} :
(∀ᶠ y in bind f m, p y) ↔ ∀ᶠ x in f, ∀ᶠ y in m x, p y :=
Iff.rfl
#align filter.eventually_bind Filter.eventually_bind
@[simp]
theorem eventuallyEq_bind {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} :
g₁ =ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ =ᶠ[m x] g₂ :=
Iff.rfl
#align filter.eventually_eq_bind Filter.eventuallyEq_bind
@[simp]
theorem eventuallyLE_bind [LE γ] {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} :
g₁ ≤ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ ≤ᶠ[m x] g₂ :=
Iff.rfl
#align filter.eventually_le_bind Filter.eventuallyLE_bind
theorem mem_bind' {s : Set β} {f : Filter α} {m : α → Filter β} :
s ∈ bind f m ↔ { a | s ∈ m a } ∈ f :=
Iff.rfl
#align filter.mem_bind' Filter.mem_bind'
@[simp]
theorem mem_bind {s : Set β} {f : Filter α} {m : α → Filter β} :
s ∈ bind f m ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x :=
calc
s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl
_ ↔ ∃ t ∈ f, t ⊆ { a | s ∈ m a } := exists_mem_subset_iff.symm
_ ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := Iff.rfl
#align filter.mem_bind Filter.mem_bind
theorem bind_le {f : Filter α} {g : α → Filter β} {l : Filter β} (h : ∀ᶠ x in f, g x ≤ l) :
f.bind g ≤ l :=
join_le <| eventually_map.2 h
#align filter.bind_le Filter.bind_le
@[mono]
theorem bind_mono {f₁ f₂ : Filter α} {g₁ g₂ : α → Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ᶠ[f₁] g₂) :
bind f₁ g₁ ≤ bind f₂ g₂ := by
refine le_trans (fun s hs => ?_) (join_mono <| map_mono hf)
simp only [mem_join, mem_bind', mem_map] at hs ⊢
filter_upwards [hg, hs] with _ hx hs using hx hs
#align filter.bind_mono Filter.bind_mono
theorem bind_inf_principal {f : Filter α} {g : α → Filter β} {s : Set β} :
(f.bind fun x => g x ⊓ 𝓟 s) = f.bind g ⊓ 𝓟 s :=
Filter.ext fun s => by simp only [mem_bind, mem_inf_principal]
#align filter.bind_inf_principal Filter.bind_inf_principal
theorem sup_bind {f g : Filter α} {h : α → Filter β} : bind (f ⊔ g) h = bind f h ⊔ bind g h := rfl
#align filter.sup_bind Filter.sup_bind
theorem principal_bind {s : Set α} {f : α → Filter β} : bind (𝓟 s) f = ⨆ x ∈ s, f x :=
show join (map f (𝓟 s)) = ⨆ x ∈ s, f x by
simp only [sSup_image, join_principal_eq_sSup, map_principal, eq_self_iff_true]
#align filter.principal_bind Filter.principal_bind
end Bind
/-! ### Limits -/
/-- `Filter.Tendsto` is the generic "limit of a function" predicate.
`Tendsto f l₁ l₂` asserts that for every `l₂` neighborhood `a`,
the `f`-preimage of `a` is an `l₁` neighborhood. -/
def Tendsto (f : α → β) (l₁ : Filter α) (l₂ : Filter β) :=
l₁.map f ≤ l₂
#align filter.tendsto Filter.Tendsto
theorem tendsto_def {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f ⁻¹' s ∈ l₁ :=
Iff.rfl
#align filter.tendsto_def Filter.tendsto_def
theorem tendsto_iff_eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ ⦃p : β → Prop⦄, (∀ᶠ y in l₂, p y) → ∀ᶠ x in l₁, p (f x) :=
Iff.rfl
#align filter.tendsto_iff_eventually Filter.tendsto_iff_eventually
theorem tendsto_iff_forall_eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, ∀ᶠ x in l₁, f x ∈ s :=
Iff.rfl
#align filter.tendsto_iff_forall_eventually_mem Filter.tendsto_iff_forall_eventually_mem
lemma Tendsto.eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {s : Set β}
(hf : Tendsto f l₁ l₂) (h : s ∈ l₂) : ∀ᶠ x in l₁, f x ∈ s :=
hf h
theorem Tendsto.eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop}
(hf : Tendsto f l₁ l₂) (h : ∀ᶠ y in l₂, p y) : ∀ᶠ x in l₁, p (f x) :=
hf h
#align filter.tendsto.eventually Filter.Tendsto.eventually
theorem not_tendsto_iff_exists_frequently_nmem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
¬Tendsto f l₁ l₂ ↔ ∃ s ∈ l₂, ∃ᶠ x in l₁, f x ∉ s := by
simp only [tendsto_iff_forall_eventually_mem, not_forall, exists_prop, not_eventually]
#align filter.not_tendsto_iff_exists_frequently_nmem Filter.not_tendsto_iff_exists_frequently_nmem
theorem Tendsto.frequently {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop}
(hf : Tendsto f l₁ l₂) (h : ∃ᶠ x in l₁, p (f x)) : ∃ᶠ y in l₂, p y :=
mt hf.eventually h
#align filter.tendsto.frequently Filter.Tendsto.frequently
theorem Tendsto.frequently_map {l₁ : Filter α} {l₂ : Filter β} {p : α → Prop} {q : β → Prop}
(f : α → β) (c : Filter.Tendsto f l₁ l₂) (w : ∀ x, p x → q (f x)) (h : ∃ᶠ x in l₁, p x) :
∃ᶠ y in l₂, q y :=
c.frequently (h.mono w)
#align filter.tendsto.frequently_map Filter.Tendsto.frequently_map
@[simp]
theorem tendsto_bot {f : α → β} {l : Filter β} : Tendsto f ⊥ l := by simp [Tendsto]
#align filter.tendsto_bot Filter.tendsto_bot
@[simp] theorem tendsto_top {f : α → β} {l : Filter α} : Tendsto f l ⊤ := le_top
#align filter.tendsto_top Filter.tendsto_top
theorem le_map_of_right_inverse {mab : α → β} {mba : β → α} {f : Filter α} {g : Filter β}
(h₁ : mab ∘ mba =ᶠ[g] id) (h₂ : Tendsto mba g f) : g ≤ map mab f := by
rw [← @map_id _ g, ← map_congr h₁, ← map_map]
exact map_mono h₂
#align filter.le_map_of_right_inverse Filter.le_map_of_right_inverse
theorem tendsto_of_isEmpty [IsEmpty α] {f : α → β} {la : Filter α} {lb : Filter β} :
Tendsto f la lb := by simp only [filter_eq_bot_of_isEmpty la, tendsto_bot]
#align filter.tendsto_of_is_empty Filter.tendsto_of_isEmpty
theorem eventuallyEq_of_left_inv_of_right_inv {f : α → β} {g₁ g₂ : β → α} {fa : Filter α}
{fb : Filter β} (hleft : ∀ᶠ x in fa, g₁ (f x) = x) (hright : ∀ᶠ y in fb, f (g₂ y) = y)
(htendsto : Tendsto g₂ fb fa) : g₁ =ᶠ[fb] g₂ :=
(htendsto.eventually hleft).mp <| hright.mono fun _ hr hl => (congr_arg g₁ hr.symm).trans hl
#align filter.eventually_eq_of_left_inv_of_right_inv Filter.eventuallyEq_of_left_inv_of_right_inv
theorem tendsto_iff_comap {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ l₁ ≤ l₂.comap f :=
map_le_iff_le_comap
#align filter.tendsto_iff_comap Filter.tendsto_iff_comap
alias ⟨Tendsto.le_comap, _⟩ := tendsto_iff_comap
#align filter.tendsto.le_comap Filter.Tendsto.le_comap
protected theorem Tendsto.disjoint {f : α → β} {la₁ la₂ : Filter α} {lb₁ lb₂ : Filter β}
(h₁ : Tendsto f la₁ lb₁) (hd : Disjoint lb₁ lb₂) (h₂ : Tendsto f la₂ lb₂) : Disjoint la₁ la₂ :=
(disjoint_comap hd).mono h₁.le_comap h₂.le_comap
#align filter.tendsto.disjoint Filter.Tendsto.disjoint
theorem tendsto_congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂) :
Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ := by rw [Tendsto, Tendsto, map_congr hl]
#align filter.tendsto_congr' Filter.tendsto_congr'
theorem Tendsto.congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂)
(h : Tendsto f₁ l₁ l₂) : Tendsto f₂ l₁ l₂ :=
(tendsto_congr' hl).1 h
#align filter.tendsto.congr' Filter.Tendsto.congr'
theorem tendsto_congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) :
Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ :=
tendsto_congr' (univ_mem' h)
#align filter.tendsto_congr Filter.tendsto_congr
theorem Tendsto.congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) :
Tendsto f₁ l₁ l₂ → Tendsto f₂ l₁ l₂ :=
(tendsto_congr h).1
#align filter.tendsto.congr Filter.Tendsto.congr
theorem tendsto_id' {x y : Filter α} : Tendsto id x y ↔ x ≤ y :=
Iff.rfl
#align filter.tendsto_id' Filter.tendsto_id'
theorem tendsto_id {x : Filter α} : Tendsto id x x :=
le_refl x
#align filter.tendsto_id Filter.tendsto_id
theorem Tendsto.comp {f : α → β} {g : β → γ} {x : Filter α} {y : Filter β} {z : Filter γ}
(hg : Tendsto g y z) (hf : Tendsto f x y) : Tendsto (g ∘ f) x z := fun _ hs => hf (hg hs)
#align filter.tendsto.comp Filter.Tendsto.comp
protected theorem Tendsto.iterate {f : α → α} {l : Filter α} (h : Tendsto f l l) :
∀ n, Tendsto (f^[n]) l l
| 0 => tendsto_id
| (n + 1) => (h.iterate n).comp h
theorem Tendsto.mono_left {f : α → β} {x y : Filter α} {z : Filter β} (hx : Tendsto f x z)
(h : y ≤ x) : Tendsto f y z :=
(map_mono h).trans hx
#align filter.tendsto.mono_left Filter.Tendsto.mono_left
theorem Tendsto.mono_right {f : α → β} {x : Filter α} {y z : Filter β} (hy : Tendsto f x y)
(hz : y ≤ z) : Tendsto f x z :=
le_trans hy hz
#align filter.tendsto.mono_right Filter.Tendsto.mono_right
theorem Tendsto.neBot {f : α → β} {x : Filter α} {y : Filter β} (h : Tendsto f x y) [hx : NeBot x] :
NeBot y :=
(hx.map _).mono h
#align filter.tendsto.ne_bot Filter.Tendsto.neBot
theorem tendsto_map {f : α → β} {x : Filter α} : Tendsto f x (map f x) :=
le_refl (map f x)
#align filter.tendsto_map Filter.tendsto_map
@[simp]
theorem tendsto_map'_iff {f : β → γ} {g : α → β} {x : Filter α} {y : Filter γ} :
Tendsto f (map g x) y ↔ Tendsto (f ∘ g) x y := by
rw [Tendsto, Tendsto, map_map]
#align filter.tendsto_map'_iff Filter.tendsto_map'_iff
alias ⟨_, tendsto_map'⟩ := tendsto_map'_iff
#align filter.tendsto_map' Filter.tendsto_map'
theorem tendsto_comap {f : α → β} {x : Filter β} : Tendsto f (comap f x) x :=
map_comap_le
#align filter.tendsto_comap Filter.tendsto_comap
@[simp]
theorem tendsto_comap_iff {f : α → β} {g : β → γ} {a : Filter α} {c : Filter γ} :
Tendsto f a (c.comap g) ↔ Tendsto (g ∘ f) a c :=
⟨fun h => tendsto_comap.comp h, fun h => map_le_iff_le_comap.mp <| by rwa [map_map]⟩
#align filter.tendsto_comap_iff Filter.tendsto_comap_iff
| Mathlib/Order/Filter/Basic.lean | 3,163 | 3,166 | theorem tendsto_comap'_iff {m : α → β} {f : Filter α} {g : Filter β} {i : γ → α} (h : range i ∈ f) :
Tendsto (m ∘ i) (comap i f) g ↔ Tendsto m f g := by |
rw [Tendsto, ← map_compose]
simp only [(· ∘ ·), map_comap_of_mem h, Tendsto]
|
/-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu, Anne Baanen
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.Algebra.Module.LocalizedModule
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Localization.Integer
#align_import ring_theory.localization.module from "leanprover-community/mathlib"@"2e59a6de168f95d16b16d217b808a36290398c0a"
/-!
# Modules / vector spaces over localizations / fraction fields
This file contains some results about vector spaces over the field of fractions of a ring.
## Main results
* `LinearIndependent.localization`: `b` is linear independent over a localization of `R`
if it is linear independent over `R` itself
* `Basis.ofIsLocalizedModule` / `Basis.localizationLocalization`: promote an `R`-basis `b` of `A`
to an `Rₛ`-basis of `Aₛ`, where `Rₛ` and `Aₛ` are localizations of `R` and `A` at `s`
respectively
* `LinearIndependent.iff_fractionRing`: `b` is linear independent over `R` iff it is
linear independent over `Frac(R)`
-/
open nonZeroDivisors
section Localization
variable {R : Type*} (Rₛ : Type*) [CommSemiring R] (S : Submonoid R)
section IsLocalizedModule
section AddCommMonoid
open Submodule
variable [CommSemiring Rₛ] [Algebra R Rₛ] [hT : IsLocalization S Rₛ]
variable {M M' : Type*} [AddCommMonoid M] [Module R M] [Module Rₛ M] [IsScalarTower R Rₛ M]
[AddCommMonoid M'] [Module R M'] [Module Rₛ M'] [IsScalarTower R Rₛ M'] (f : M →ₗ[R] M')
[IsLocalizedModule S f]
theorem span_eq_top_of_isLocalizedModule {v : Set M} (hv : span R v = ⊤) :
span Rₛ (f '' v) = ⊤ := top_unique fun x _ ↦ by
obtain ⟨⟨m, s⟩, h⟩ := IsLocalizedModule.surj S f x
rw [Submonoid.smul_def, ← algebraMap_smul Rₛ, ← Units.smul_isUnit (IsLocalization.map_units Rₛ s),
eq_comm, ← inv_smul_eq_iff] at h
refine h ▸ smul_mem _ _ (span_subset_span R Rₛ _ ?_)
rw [← LinearMap.coe_restrictScalars R, ← LinearMap.map_span, hv]
exact mem_map_of_mem mem_top
theorem LinearIndependent.of_isLocalizedModule {ι : Type*} {v : ι → M}
(hv : LinearIndependent R v) : LinearIndependent Rₛ (f ∘ v) := by
rw [linearIndependent_iff'] at hv ⊢
intro t g hg i hi
choose! a g' hg' using IsLocalization.exist_integer_multiples S t g
have h0 : f (∑ i ∈ t, g' i • v i) = 0 := by
apply_fun ((a : R) • ·) at hg
rw [smul_zero, Finset.smul_sum] at hg
rw [map_sum, ← hg]
refine Finset.sum_congr rfl fun i hi => ?_
rw [← smul_assoc, ← hg' i hi, map_smul, Function.comp_apply, algebraMap_smul]
obtain ⟨s, hs⟩ := (IsLocalizedModule.eq_zero_iff S f).mp h0
simp_rw [Finset.smul_sum, Submonoid.smul_def, smul_smul] at hs
specialize hv t _ hs i hi
rw [← (IsLocalization.map_units Rₛ a).mul_right_eq_zero, ← Algebra.smul_def, ← hg' i hi]
exact (IsLocalization.map_eq_zero_iff S _ _).2 ⟨s, hv⟩
theorem LinearIndependent.localization {ι : Type*} {b : ι → M} (hli : LinearIndependent R b) :
LinearIndependent Rₛ b := by
have := isLocalizedModule_id S M Rₛ
exact hli.of_isLocalizedModule Rₛ S .id
#align linear_independent.localization LinearIndependent.localization
end AddCommMonoid
section Basis
variable [CommRing Rₛ] [Algebra R Rₛ] [hT : IsLocalization S Rₛ]
open Submodule
variable {M Mₛ : Type*} [AddCommGroup M] [AddCommGroup Mₛ] [Module R M] [Module R Mₛ] [Module R Mₛ]
[Module Rₛ Mₛ] (f : M →ₗ[R] Mₛ) [IsLocalizedModule S f] [IsScalarTower R Rₛ Mₛ]
{ι : Type*} (b : Basis ι R M)
/-- If `M` has an `R`-basis, then localizing `M` at `S` has a basis over `R` localized at `S`. -/
noncomputable def Basis.ofIsLocalizedModule : Basis ι Rₛ Mₛ :=
.mk (b.linearIndependent.of_isLocalizedModule Rₛ S f) <| by
rw [Set.range_comp, span_eq_top_of_isLocalizedModule Rₛ S _ b.span_eq]
@[simp]
theorem Basis.ofIsLocalizedModule_apply (i : ι) : b.ofIsLocalizedModule Rₛ S f i = f (b i) := by
rw [ofIsLocalizedModule, coe_mk, Function.comp_apply]
@[simp]
theorem Basis.ofIsLocalizedModule_repr_apply (m : M) (i : ι) :
((b.ofIsLocalizedModule Rₛ S f).repr (f m)) i = algebraMap R Rₛ (b.repr m i) := by
suffices ((b.ofIsLocalizedModule Rₛ S f).repr.toLinearMap.restrictScalars R) ∘ₗ f =
Finsupp.mapRange.linearMap (Algebra.linearMap R Rₛ) ∘ₗ b.repr.toLinearMap by
exact DFunLike.congr_fun (LinearMap.congr_fun this m) i
refine Basis.ext b fun i ↦ ?_
rw [LinearMap.coe_comp, Function.comp_apply, LinearMap.coe_restrictScalars,
LinearEquiv.coe_coe, ← b.ofIsLocalizedModule_apply Rₛ S f, repr_self, LinearMap.coe_comp,
Function.comp_apply, LinearEquiv.coe_coe, repr_self, Finsupp.mapRange.linearMap_apply,
Finsupp.mapRange_single, Algebra.linearMap_apply, map_one]
| Mathlib/RingTheory/Localization/Module.lean | 112 | 117 | theorem Basis.ofIsLocalizedModule_span :
span R (Set.range (b.ofIsLocalizedModule Rₛ S f)) = LinearMap.range f := by |
calc span R (Set.range (b.ofIsLocalizedModule Rₛ S f))
_ = span R (f '' (Set.range b)) := by congr; ext; simp
_ = map f (span R (Set.range b)) := by rw [Submodule.map_span]
_ = LinearMap.range f := by rw [b.span_eq, Submodule.map_top]
|
/-
Copyright (c) 2023 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Geißer, Michael Stoll
-/
import Mathlib.Tactic.Qify
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.DiophantineApproximation
import Mathlib.NumberTheory.Zsqrtd.Basic
#align_import number_theory.pell from "leanprover-community/mathlib"@"7ad820c4997738e2f542f8a20f32911f52020e26"
/-!
# Pell's Equation
*Pell's Equation* is the equation $x^2 - d y^2 = 1$, where $d$ is a positive integer
that is not a square, and one is interested in solutions in integers $x$ and $y$.
In this file, we aim at providing all of the essential theory of Pell's Equation for general $d$
(as opposed to the contents of `NumberTheory.PellMatiyasevic`, which is specific to the case
$d = a^2 - 1$ for some $a > 1$).
We begin by defining a type `Pell.Solution₁ d` for solutions of the equation,
show that it has a natural structure as an abelian group, and prove some basic
properties.
We then prove the following
**Theorem.** Let $d$ be a positive integer that is not a square. Then the equation
$x^2 - d y^2 = 1$ has a nontrivial (i.e., with $y \ne 0$) solution in integers.
See `Pell.exists_of_not_isSquare` and `Pell.Solution₁.exists_nontrivial_of_not_isSquare`.
We then define the *fundamental solution* to be the solution
with smallest $x$ among all solutions satisfying $x > 1$ and $y > 0$.
We show that every solution is a power (in the sense of the group structure mentioned above)
of the fundamental solution up to a (common) sign,
see `Pell.IsFundamental.eq_zpow_or_neg_zpow`, and that a (positive) solution has this property
if and only if it is fundamental, see `Pell.pos_generator_iff_fundamental`.
## References
* [K. Ireland, M. Rosen, *A classical introduction to modern number theory*
(Section 17.5)][IrelandRosen1990]
## Tags
Pell's equation
## TODO
* Extend to `x ^ 2 - d * y ^ 2 = -1` and further generalizations.
* Connect solutions to the continued fraction expansion of `√d`.
-/
namespace Pell
/-!
### Group structure of the solution set
We define a structure of a commutative multiplicative group with distributive negation
on the set of all solutions to the Pell equation `x^2 - d*y^2 = 1`.
The type of such solutions is `Pell.Solution₁ d`. It corresponds to a pair of integers `x` and `y`
and a proof that `(x, y)` is indeed a solution.
The multiplication is given by `(x, y) * (x', y') = (x*y' + d*y*y', x*y' + y*x')`.
This is obtained by mapping `(x, y)` to `x + y*√d` and multiplying the results.
In fact, we define `Pell.Solution₁ d` to be `↥(unitary (ℤ√d))` and transport
the "commutative group with distributive negation" structure from `↥(unitary (ℤ√d))`.
We then set up an API for `Pell.Solution₁ d`.
-/
open Zsqrtd
/-- An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if
it is contained in the submonoid of unitary elements.
TODO: merge this result with `Pell.isPell_iff_mem_unitary`. -/
theorem is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} :
a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary (ℤ√d) := by
rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc]
#align pell.is_pell_solution_iff_mem_unitary Pell.is_pell_solution_iff_mem_unitary
-- We use `solution₁ d` to allow for a more general structure `solution d m` that
-- encodes solutions to `x^2 - d*y^2 = m` to be added later.
/-- `Pell.Solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`.
We define this in terms of elements of `ℤ√d` of norm one.
-/
def Solution₁ (d : ℤ) : Type :=
↥(unitary (ℤ√d))
#align pell.solution₁ Pell.Solution₁
namespace Solution₁
variable {d : ℤ}
-- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020): manual deriving
instance instCommGroup : CommGroup (Solution₁ d) :=
inferInstanceAs (CommGroup (unitary (ℤ√d)))
#align pell.solution₁.comm_group Pell.Solution₁.instCommGroup
instance instHasDistribNeg : HasDistribNeg (Solution₁ d) :=
inferInstanceAs (HasDistribNeg (unitary (ℤ√d)))
#align pell.solution₁.has_distrib_neg Pell.Solution₁.instHasDistribNeg
instance instInhabited : Inhabited (Solution₁ d) :=
inferInstanceAs (Inhabited (unitary (ℤ√d)))
#align pell.solution₁.inhabited Pell.Solution₁.instInhabited
instance : Coe (Solution₁ d) (ℤ√d) where coe := Subtype.val
/-- The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def x (a : Solution₁ d) : ℤ :=
(a : ℤ√d).re
#align pell.solution₁.x Pell.Solution₁.x
/-- The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def y (a : Solution₁ d) : ℤ :=
(a : ℤ√d).im
#align pell.solution₁.y Pell.Solution₁.y
/-- The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1` -/
theorem prop (a : Solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 :=
is_pell_solution_iff_mem_unitary.mpr a.property
#align pell.solution₁.prop Pell.Solution₁.prop
/-- An alternative form of the equation, suitable for rewriting `x^2`. -/
theorem prop_x (a : Solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by rw [← a.prop]; ring
#align pell.solution₁.prop_x Pell.Solution₁.prop_x
/-- An alternative form of the equation, suitable for rewriting `d * y^2`. -/
theorem prop_y (a : Solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by rw [← a.prop]; ring
#align pell.solution₁.prop_y Pell.Solution₁.prop_y
/-- Two solutions are equal if their `x` and `y` components are equal. -/
@[ext]
theorem ext {a b : Solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b :=
Subtype.ext <| Zsqrtd.ext _ _ hx hy
#align pell.solution₁.ext Pell.Solution₁.ext
/-- Construct a solution from `x`, `y` and a proof that the equation is satisfied. -/
def mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : Solution₁ d where
val := ⟨x, y⟩
property := is_pell_solution_iff_mem_unitary.mp prop
#align pell.solution₁.mk Pell.Solution₁.mk
@[simp]
theorem x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x :=
rfl
#align pell.solution₁.x_mk Pell.Solution₁.x_mk
@[simp]
theorem y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y :=
rfl
#align pell.solution₁.y_mk Pell.Solution₁.y_mk
@[simp]
theorem coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x, y⟩ :=
Zsqrtd.ext _ _ (x_mk x y prop) (y_mk x y prop)
#align pell.solution₁.coe_mk Pell.Solution₁.coe_mk
@[simp]
theorem x_one : (1 : Solution₁ d).x = 1 :=
rfl
#align pell.solution₁.x_one Pell.Solution₁.x_one
@[simp]
theorem y_one : (1 : Solution₁ d).y = 0 :=
rfl
#align pell.solution₁.y_one Pell.Solution₁.y_one
@[simp]
theorem x_mul (a b : Solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by
rw [← mul_assoc]
rfl
#align pell.solution₁.x_mul Pell.Solution₁.x_mul
@[simp]
theorem y_mul (a b : Solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x :=
rfl
#align pell.solution₁.y_mul Pell.Solution₁.y_mul
@[simp]
theorem x_inv (a : Solution₁ d) : a⁻¹.x = a.x :=
rfl
#align pell.solution₁.x_inv Pell.Solution₁.x_inv
@[simp]
theorem y_inv (a : Solution₁ d) : a⁻¹.y = -a.y :=
rfl
#align pell.solution₁.y_inv Pell.Solution₁.y_inv
@[simp]
theorem x_neg (a : Solution₁ d) : (-a).x = -a.x :=
rfl
#align pell.solution₁.x_neg Pell.Solution₁.x_neg
@[simp]
theorem y_neg (a : Solution₁ d) : (-a).y = -a.y :=
rfl
#align pell.solution₁.y_neg Pell.Solution₁.y_neg
/-- When `d` is negative, then `x` or `y` must be zero in a solution. -/
theorem eq_zero_of_d_neg (h₀ : d < 0) (a : Solution₁ d) : a.x = 0 ∨ a.y = 0 := by
have h := a.prop
contrapose! h
have h1 := sq_pos_of_ne_zero h.1
have h2 := sq_pos_of_ne_zero h.2
nlinarith
#align pell.solution₁.eq_zero_of_d_neg Pell.Solution₁.eq_zero_of_d_neg
/-- A solution has `x ≠ 0`. -/
theorem x_ne_zero (h₀ : 0 ≤ d) (a : Solution₁ d) : a.x ≠ 0 := by
intro hx
have h : 0 ≤ d * a.y ^ 2 := mul_nonneg h₀ (sq_nonneg _)
rw [a.prop_y, hx, sq, zero_mul, zero_sub] at h
exact not_le.mpr (neg_one_lt_zero : (-1 : ℤ) < 0) h
#align pell.solution₁.x_ne_zero Pell.Solution₁.x_ne_zero
/-- A solution with `x > 1` must have `y ≠ 0`. -/
theorem y_ne_zero_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : a.y ≠ 0 := by
intro hy
have prop := a.prop
rw [hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero] at prop
exact lt_irrefl _ (((one_lt_sq_iff <| zero_le_one.trans ha.le).mpr ha).trans_eq prop)
#align pell.solution₁.y_ne_zero_of_one_lt_x Pell.Solution₁.y_ne_zero_of_one_lt_x
/-- If a solution has `x > 1`, then `d` is positive. -/
theorem d_pos_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : 0 < d := by
refine pos_of_mul_pos_left ?_ (sq_nonneg a.y)
rw [a.prop_y, sub_pos]
exact one_lt_pow ha two_ne_zero
#align pell.solution₁.d_pos_of_one_lt_x Pell.Solution₁.d_pos_of_one_lt_x
/-- If a solution has `x > 1`, then `d` is not a square. -/
theorem d_nonsquare_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : ¬IsSquare d := by
have hp := a.prop
rintro ⟨b, rfl⟩
simp_rw [← sq, ← mul_pow, sq_sub_sq, Int.mul_eq_one_iff_eq_one_or_neg_one] at hp
rcases hp with (⟨hp₁, hp₂⟩ | ⟨hp₁, hp₂⟩) <;> omega
#align pell.solution₁.d_nonsquare_of_one_lt_x Pell.Solution₁.d_nonsquare_of_one_lt_x
/-- A solution with `x = 1` is trivial. -/
theorem eq_one_of_x_eq_one (h₀ : d ≠ 0) {a : Solution₁ d} (ha : a.x = 1) : a = 1 := by
have prop := a.prop_y
rw [ha, one_pow, sub_self, mul_eq_zero, or_iff_right h₀, sq_eq_zero_iff] at prop
exact ext ha prop
#align pell.solution₁.eq_one_of_x_eq_one Pell.Solution₁.eq_one_of_x_eq_one
/-- A solution is `1` or `-1` if and only if `y = 0`. -/
| Mathlib/NumberTheory/Pell.lean | 256 | 260 | theorem eq_one_or_neg_one_iff_y_eq_zero {a : Solution₁ d} : a = 1 ∨ a = -1 ↔ a.y = 0 := by |
refine ⟨fun H => H.elim (fun h => by simp [h]) fun h => by simp [h], fun H => ?_⟩
have prop := a.prop
rw [H, sq (0 : ℤ), mul_zero, mul_zero, sub_zero, sq_eq_one_iff] at prop
exact prop.imp (fun h => ext h H) fun h => ext h H
|
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Decomposition.RadonNikodym
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
import Mathlib.Probability.Independence.Basic
#align_import probability.density from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520"
/-!
# Probability density function
This file defines the probability density function of random variables, by which we mean
measurable functions taking values in a Borel space. The probability density function is defined
as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f`
is said to the probability density function of a random variable `X` if for all measurable
sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing
the distribution of a random variable, and are useful for calculating probabilities and
finding moments (although the latter is better achieved with moment generating functions).
This file also defines the continuous uniform distribution and proves some properties about
random variables with this distribution.
## Main definitions
* `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with
respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X`
is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`.
* `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X`
is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`.
* `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform
distribution if it has a constant probability density function with a compact, non-null support.
## Main results
* `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician,
i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for
all measurable `g : E → F`.
* `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with
pdf `f` has expectation `∫ x, x * f x dx`.
* `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with
its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ`
is the Lebesgue measure.
## TODOs
Ultimately, we would also like to define characteristic functions to describe distributions as
it exists for all random variables. However, to define this, we will need Fourier transforms
which we currently do not have.
-/
open scoped Classical MeasureTheory NNReal ENNReal
open TopologicalSpace MeasureTheory.Measure
noncomputable section
namespace MeasureTheory
variable {Ω E : Type*} [MeasurableSpace E]
/-- A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and
`μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to
`μ` and they `HaveLebesgueDecomposition`. -/
class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : Prop where
pdf' : AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ
#align measure_theory.has_pdf MeasureTheory.HasPDF
section HasPDF
variable {_ : MeasurableSpace Ω}
theorem hasPDF_iff {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} :
HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ :=
⟨@HasPDF.pdf' _ _ _ _ _ _ _, HasPDF.mk⟩
#align measure_theory.pdf.has_pdf_iff MeasureTheory.hasPDF_iff
theorem hasPDF_iff_of_aemeasurable {X : Ω → E} {ℙ : Measure Ω}
{μ : Measure E} (hX : AEMeasurable X ℙ) :
HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by
rw [hasPDF_iff]
simp only [hX, true_and]
#align measure_theory.pdf.has_pdf_iff_of_measurable MeasureTheory.hasPDF_iff_of_aemeasurable
@[measurability]
theorem HasPDF.aemeasurable (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E) [hX : HasPDF X ℙ μ] : AEMeasurable X ℙ :=
hX.pdf'.1
#align measure_theory.has_pdf.measurable MeasureTheory.HasPDF.aemeasurable
instance HasPDF.haveLebesgueDecomposition {X : Ω → E} {ℙ : Measure Ω}
{μ : Measure E} [hX : HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ :=
hX.pdf'.2.1
#align measure_theory.pdf.have_lebesgue_decomposition_of_has_pdf MeasureTheory.HasPDF.haveLebesgueDecomposition
theorem HasPDF.absolutelyContinuous {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E}
[hX : HasPDF X ℙ μ] : map X ℙ ≪ μ :=
hX.pdf'.2.2
#align measure_theory.pdf.map_absolutely_continuous MeasureTheory.HasPDF.absolutelyContinuous
/-- A random variable that `HasPDF` is quasi-measure preserving. -/
theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E)
[HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ :=
{ measurable := h
absolutelyContinuous := HasPDF.absolutelyContinuous }
#align measure_theory.pdf.to_quasi_measure_preserving MeasureTheory.HasPDF.quasiMeasurePreserving_of_measurable
theorem HasPDF.congr {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y)
[hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ :=
⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition,
ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩
theorem HasPDF.congr' {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y) :
HasPDF X ℙ μ ↔ HasPDF Y ℙ μ :=
⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩
/-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/
theorem hasPDF_of_map_eq_withDensity {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E}
(hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ) (h : map X ℙ = μ.withDensity f) :
HasPDF X ℙ μ := by
refine ⟨hX, ?_, ?_⟩ <;> rw [h]
· rw [withDensity_congr_ae hf.ae_eq_mk]
exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk
· exact withDensity_absolutelyContinuous μ f
end HasPDF
/-- If `X` is a random variable, then `pdf X` is the Radon–Nikodym derivative of the push-forward
measure of `ℙ` along `X` with respect to `μ`. -/
def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :
E → ℝ≥0∞ :=
(map X ℙ).rnDeriv μ
#align measure_theory.pdf MeasureTheory.pdf
theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} :
pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl
theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
{X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by
rw [pdf_def, map_of_not_aemeasurable hX]
exact rnDeriv_zero μ
#align measure_theory.pdf_eq_zero_of_not_measurable MeasureTheory.pdf_of_not_aemeasurable
theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
{μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 :=
rnDeriv_of_not_haveLebesgueDecomposition h
theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
(X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by
contrapose! h
exact pdf_of_not_aemeasurable h
#align measure_theory.measurable_of_pdf_ne_zero MeasureTheory.aemeasurable_of_pdf_ne_zero
theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E}
(hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by
refine ⟨?_, ?_, hac⟩
· exact aemeasurable_of_pdf_ne_zero X hpdf
· contrapose! hpdf
have := pdf_of_not_haveLebesgueDecomposition hpdf
filter_upwards using congrFun this
#align measure_theory.has_pdf_of_pdf_ne_zero MeasureTheory.hasPDF_of_pdf_ne_zero
@[measurability]
theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by
exact measurable_rnDeriv _ _
#align measure_theory.measurable_pdf MeasureTheory.measurable_pdf
theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ :=
withDensity_rnDeriv_le _ _
theorem set_lintegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) (s : Set E) :
∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by
apply (withDensity_apply_le _ s).trans
exact withDensity_pdf_le_map _ _ _ s
theorem map_eq_withDensity_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] :
map X ℙ = μ.withDensity (pdf X ℙ μ) := by
rw [pdf_def, withDensity_rnDeriv_eq _ _ hX.absolutelyContinuous]
#align measure_theory.map_eq_with_density_pdf MeasureTheory.map_eq_withDensity_pdf
theorem map_eq_set_lintegral_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] {s : Set E}
(hs : MeasurableSet s) : map X ℙ s = ∫⁻ x in s, pdf X ℙ μ x ∂μ := by
rw [← withDensity_apply _ hs, map_eq_withDensity_pdf X ℙ μ]
#align measure_theory.map_eq_set_lintegral_pdf MeasureTheory.map_eq_set_lintegral_pdf
namespace pdf
variable {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
protected theorem congr {X Y : Ω → E} (hXY : X =ᵐ[ℙ] Y) : pdf X ℙ μ = pdf Y ℙ μ := by
rw [pdf_def, pdf_def, map_congr hXY]
theorem lintegral_eq_measure_univ {X : Ω → E} [HasPDF X ℙ μ] :
∫⁻ x, pdf X ℙ μ x ∂μ = ℙ Set.univ := by
rw [← set_lintegral_univ, ← map_eq_set_lintegral_pdf X ℙ μ MeasurableSet.univ,
map_apply_of_aemeasurable (HasPDF.aemeasurable X ℙ μ) MeasurableSet.univ, Set.preimage_univ]
#align measure_theory.pdf.lintegral_eq_measure_univ MeasureTheory.pdf.lintegral_eq_measure_univ
theorem eq_of_map_eq_withDensity [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := by
rw [map_eq_withDensity_pdf X ℙ μ]
apply withDensity_eq_iff (measurable_pdf X ℙ μ).aemeasurable hmf
rw [lintegral_eq_measure_univ]
exact measure_ne_top _ _
theorem eq_of_map_eq_withDensity' [SigmaFinite μ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f :=
map_eq_withDensity_pdf X ℙ μ ▸
withDensity_eq_iff_of_sigmaFinite (measurable_pdf X ℙ μ).aemeasurable hmf
nonrec theorem ae_lt_top [IsFiniteMeasure ℙ] {μ : Measure E} {X : Ω → E} :
∀ᵐ x ∂μ, pdf X ℙ μ x < ∞ :=
rnDeriv_lt_top (map X ℙ) μ
#align measure_theory.pdf.ae_lt_top MeasureTheory.pdf.ae_lt_top
nonrec theorem ofReal_toReal_ae_eq [IsFiniteMeasure ℙ] {X : Ω → E} :
(fun x => ENNReal.ofReal (pdf X ℙ μ x).toReal) =ᵐ[μ] pdf X ℙ μ :=
ofReal_toReal_ae_eq ae_lt_top
#align measure_theory.pdf.of_real_to_real_ae_eq MeasureTheory.pdf.ofReal_toReal_ae_eq
section IntegralPDFMul
/-- **The Law of the Unconscious Statistician** for nonnegative random variables. -/
theorem lintegral_pdf_mul {X : Ω → E} [HasPDF X ℙ μ] {f : E → ℝ≥0∞}
(hf : AEMeasurable f μ) : ∫⁻ x, pdf X ℙ μ x * f x ∂μ = ∫⁻ x, f (X x) ∂ℙ := by
rw [pdf_def,
← lintegral_map' (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ),
lintegral_rnDeriv_mul HasPDF.absolutelyContinuous hf]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F]
theorem integrable_pdf_smul_iff [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) :
Integrable (fun x => (pdf X ℙ μ x).toReal • f x) μ ↔ Integrable (fun x => f (X x)) ℙ := by
-- Porting note: using `erw` because `rw` doesn't recognize `(f <| X ·)` as `f ∘ X`
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [← integrable_map_measure (hf.mono_ac HasPDF.absolutelyContinuous)
(HasPDF.aemeasurable X ℙ μ),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integrable_rnDeriv_smul_iff HasPDF.absolutelyContinuous]
eta_reduce
rw [withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
#align measure_theory.pdf.integrable_iff_integrable_mul_pdf MeasureTheory.pdf.integrable_pdf_smul_iff
/-- **The Law of the Unconscious Statistician**: Given a random variable `X` and a measurable
function `f`, `f ∘ X` is a random variable with expectation `∫ x, pdf X x • f x ∂μ`
where `μ` is a measure on the codomain of `X`. -/
theorem integral_pdf_smul [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) : ∫ x, (pdf X ℙ μ x).toReal • f x ∂μ = ∫ x, f (X x) ∂ℙ := by
rw [← integral_map (HasPDF.aemeasurable X ℙ μ) (hf.mono_ac HasPDF.absolutelyContinuous),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integral_rnDeriv_smul HasPDF.absolutelyContinuous,
withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
#align measure_theory.pdf.integral_fun_mul_eq_integral MeasureTheory.pdf.integral_pdf_smul
end IntegralPDFMul
section
variable {F : Type*} [MeasurableSpace F] {ν : Measure F}
/-- A random variable that `HasPDF` transformed under a `QuasiMeasurePreserving`
map also `HasPDF` if `(map g (map X ℙ)).HaveLebesgueDecomposition μ`.
`quasiMeasurePreserving_hasPDF` is more useful in the case we are working with a
probability measure and a real-valued random variable. -/
| Mathlib/Probability/Density.lean | 274 | 289 | theorem quasiMeasurePreserving_hasPDF {X : Ω → E} [HasPDF X ℙ μ] (hX : AEMeasurable X ℙ) {g : E → F}
(hg : QuasiMeasurePreserving g μ ν) (hmap : (map g (map X ℙ)).HaveLebesgueDecomposition ν) :
HasPDF (g ∘ X) ℙ ν := by |
wlog hmX : Measurable X
· have hae : g ∘ X =ᵐ[ℙ] g ∘ hX.mk := hX.ae_eq_mk.mono fun x h ↦ by dsimp; rw [h]
have hXmk : HasPDF hX.mk ℙ μ := HasPDF.congr hX.ae_eq_mk
apply (HasPDF.congr' hae).mpr
exact this hX.measurable_mk.aemeasurable hg (map_congr hX.ae_eq_mk ▸ hmap) hX.measurable_mk
rw [hasPDF_iff, ← map_map hg.measurable hmX]
refine ⟨(hg.measurable.comp hmX).aemeasurable, hmap, ?_⟩
rw [map_eq_withDensity_pdf X ℙ μ]
refine AbsolutelyContinuous.mk fun s hsm hs => ?_
rw [map_apply hg.measurable hsm, withDensity_apply _ (hg.measurable hsm)]
have := hg.absolutelyContinuous hs
rw [map_apply hg.measurable hsm] at this
exact set_lintegral_measure_zero _ _ this
|
/-
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, Johan Commelin
-/
import Mathlib.RingTheory.WittVector.Domain
import Mathlib.RingTheory.WittVector.MulCoeff
import Mathlib.RingTheory.DiscreteValuationRing.Basic
import Mathlib.Tactic.LinearCombination
#align_import ring_theory.witt_vector.discrete_valuation_ring from "leanprover-community/mathlib"@"c163ec99dfc664628ca15d215fce0a5b9c265b68"
/-!
# Witt vectors over a perfect ring
This file establishes that Witt vectors over a perfect field are a discrete valuation ring.
When `k` is a perfect ring, a nonzero `a : 𝕎 k` can be written as `p^m * b` for some `m : ℕ` and
`b : 𝕎 k` with nonzero 0th coefficient.
When `k` is also a field, this `b` can be chosen to be a unit of `𝕎 k`.
## Main declarations
* `WittVector.exists_eq_pow_p_mul`: the existence of this element `b` over a perfect ring
* `WittVector.exists_eq_pow_p_mul'`: the existence of this unit `b` over a perfect field
* `WittVector.discreteValuationRing`: `𝕎 k` is a discrete valuation ring if `k` is a perfect field
-/
noncomputable section
namespace WittVector
variable {p : ℕ} [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
section CommRing
variable {k : Type*} [CommRing k] [CharP k p]
/-- This is the `n+1`st coefficient of our inverse. -/
def succNthValUnits (n : ℕ) (a : Units k) (A : 𝕎 k) (bs : Fin (n + 1) → k) : k :=
-↑(a⁻¹ ^ p ^ (n + 1)) *
(A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) + nthRemainder p n (truncateFun (n + 1) A) bs)
#align witt_vector.succ_nth_val_units WittVector.succNthValUnits
/--
Recursively defines the sequence of coefficients for the inverse to a Witt vector whose first entry
is a unit.
-/
noncomputable def inverseCoeff (a : Units k) (A : 𝕎 k) : ℕ → k
| 0 => ↑a⁻¹
| n + 1 => succNthValUnits n a A fun i => inverseCoeff a A i.val
#align witt_vector.inverse_coeff WittVector.inverseCoeff
/--
Upgrade a Witt vector `A` whose first entry `A.coeff 0` is a unit to be, itself, a unit in `𝕎 k`.
-/
def mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : Units (𝕎 k) :=
Units.mkOfMulEqOne A (@WittVector.mk' p _ (inverseCoeff a A)) (by
ext n
induction' n with n _
· simp [WittVector.mul_coeff_zero, inverseCoeff, hA]
let H_coeff := A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) +
nthRemainder p n (truncateFun (n + 1) A) fun i : Fin (n + 1) => inverseCoeff a A i
have H := Units.mul_inv (a ^ p ^ (n + 1))
linear_combination (norm := skip) -H_coeff * H
have ha : (a : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1)) := by norm_cast
have ha_inv : (↑a⁻¹ : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1))⁻¹ := by norm_cast
simp only [nthRemainder_spec, inverseCoeff, succNthValUnits, hA,
one_coeff_eq_of_pos, Nat.succ_pos', ha_inv, ha, inv_pow]
ring!)
#align witt_vector.mk_unit WittVector.mkUnit
@[simp]
theorem coe_mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : (mkUnit hA : 𝕎 k) = A :=
rfl
#align witt_vector.coe_mk_unit WittVector.coe_mkUnit
end CommRing
section Field
variable {k : Type*} [Field k] [CharP k p]
theorem isUnit_of_coeff_zero_ne_zero (x : 𝕎 k) (hx : x.coeff 0 ≠ 0) : IsUnit x := by
let y : kˣ := Units.mk0 (x.coeff 0) hx
have hy : x.coeff 0 = y := rfl
exact (mkUnit hy).isUnit
#align witt_vector.is_unit_of_coeff_zero_ne_zero WittVector.isUnit_of_coeff_zero_ne_zero
variable (p)
| Mathlib/RingTheory/WittVector/DiscreteValuationRing.lean | 96 | 112 | theorem irreducible : Irreducible (p : 𝕎 k) := by |
have hp : ¬IsUnit (p : 𝕎 k) := by
intro hp
simpa only [constantCoeff_apply, coeff_p_zero, not_isUnit_zero] using
(constantCoeff : WittVector p k →+* _).isUnit_map hp
refine ⟨hp, fun a b hab => ?_⟩
obtain ⟨ha0, hb0⟩ : a ≠ 0 ∧ b ≠ 0 := by
rw [← mul_ne_zero_iff]; intro h; rw [h] at hab; exact p_nonzero p k hab
obtain ⟨m, a, ha, rfl⟩ := verschiebung_nonzero ha0
obtain ⟨n, b, hb, rfl⟩ := verschiebung_nonzero hb0
cases m; · exact Or.inl (isUnit_of_coeff_zero_ne_zero a ha)
cases' n with n; · exact Or.inr (isUnit_of_coeff_zero_ne_zero b hb)
rw [iterate_verschiebung_mul] at hab
apply_fun fun x => coeff x 1 at hab
simp only [coeff_p_one, Nat.add_succ, add_comm _ n, Function.iterate_succ', Function.comp_apply,
verschiebung_coeff_add_one, verschiebung_coeff_zero] at hab
exact (one_ne_zero hab).elim
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Topology.ContinuousOn
import Mathlib.Order.Minimal
/-!
# Irreducibility in topological spaces
## Main definitions
* `IrreducibleSpace`: a typeclass applying to topological spaces, stating that the space is not the
union of a nontrivial pair of disjoint opens.
* `IsIrreducible`: for a nonempty set in a topological space, the property that the set is an
irreducible space in the subspace topology.
## On the definition of irreducible and connected sets/spaces
In informal mathematics, irreducible spaces are assumed to be nonempty.
We formalise the predicate without that assumption as `IsPreirreducible`.
In other words, the only difference is whether the empty space counts as irreducible.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open Set Classical
variable {X : Type*} {Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X}
section Preirreducible
/-- A preirreducible set `s` is one where there is no non-trivial pair of disjoint opens on `s`. -/
def IsPreirreducible (s : Set X) : Prop :=
∀ u v : Set X, IsOpen u → IsOpen v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty
#align is_preirreducible IsPreirreducible
/-- An irreducible set `s` is one that is nonempty and
where there is no non-trivial pair of disjoint opens on `s`. -/
def IsIrreducible (s : Set X) : Prop :=
s.Nonempty ∧ IsPreirreducible s
#align is_irreducible IsIrreducible
theorem IsIrreducible.nonempty (h : IsIrreducible s) : s.Nonempty :=
h.1
#align is_irreducible.nonempty IsIrreducible.nonempty
theorem IsIrreducible.isPreirreducible (h : IsIrreducible s) : IsPreirreducible s :=
h.2
#align is_irreducible.is_preirreducible IsIrreducible.isPreirreducible
theorem isPreirreducible_empty : IsPreirreducible (∅ : Set X) := fun _ _ _ _ _ ⟨_, h1, _⟩ =>
h1.elim
#align is_preirreducible_empty isPreirreducible_empty
theorem Set.Subsingleton.isPreirreducible (hs : s.Subsingleton) : IsPreirreducible s :=
fun _u _v _ _ ⟨_x, hxs, hxu⟩ ⟨y, hys, hyv⟩ => ⟨y, hys, hs hxs hys ▸ hxu, hyv⟩
#align set.subsingleton.is_preirreducible Set.Subsingleton.isPreirreducible
-- Porting note (#10756): new lemma
theorem isPreirreducible_singleton {x} : IsPreirreducible ({x} : Set X) :=
subsingleton_singleton.isPreirreducible
theorem isIrreducible_singleton {x} : IsIrreducible ({x} : Set X) :=
⟨singleton_nonempty x, isPreirreducible_singleton⟩
#align is_irreducible_singleton isIrreducible_singleton
theorem isPreirreducible_iff_closure : IsPreirreducible (closure s) ↔ IsPreirreducible s :=
forall₄_congr fun u v hu hv => by
iterate 3 rw [closure_inter_open_nonempty_iff]
exacts [hu.inter hv, hv, hu]
#align is_preirreducible_iff_closure isPreirreducible_iff_closure
theorem isIrreducible_iff_closure : IsIrreducible (closure s) ↔ IsIrreducible s :=
and_congr closure_nonempty_iff isPreirreducible_iff_closure
#align is_irreducible_iff_closure isIrreducible_iff_closure
protected alias ⟨_, IsPreirreducible.closure⟩ := isPreirreducible_iff_closure
#align is_preirreducible.closure IsPreirreducible.closure
protected alias ⟨_, IsIrreducible.closure⟩ := isIrreducible_iff_closure
#align is_irreducible.closure IsIrreducible.closure
theorem exists_preirreducible (s : Set X) (H : IsPreirreducible s) :
∃ t : Set X, IsPreirreducible t ∧ s ⊆ t ∧ ∀ u, IsPreirreducible u → t ⊆ u → u = t :=
let ⟨m, hm, hsm, hmm⟩ :=
zorn_subset_nonempty { t : Set X | IsPreirreducible t }
(fun c hc hcc _ =>
⟨⋃₀ c, fun u v hu hv ⟨y, hy, hyu⟩ ⟨x, hx, hxv⟩ =>
let ⟨p, hpc, hyp⟩ := mem_sUnion.1 hy
let ⟨q, hqc, hxq⟩ := mem_sUnion.1 hx
Or.casesOn (hcc.total hpc hqc)
(fun hpq : p ⊆ q =>
let ⟨x, hxp, hxuv⟩ := hc hqc u v hu hv ⟨y, hpq hyp, hyu⟩ ⟨x, hxq, hxv⟩
⟨x, mem_sUnion_of_mem hxp hqc, hxuv⟩)
fun hqp : q ⊆ p =>
let ⟨x, hxp, hxuv⟩ := hc hpc u v hu hv ⟨y, hyp, hyu⟩ ⟨x, hqp hxq, hxv⟩
⟨x, mem_sUnion_of_mem hxp hpc, hxuv⟩,
fun _ hxc => subset_sUnion_of_mem hxc⟩)
s H
⟨m, hm, hsm, fun _u hu hmu => hmm _ hu hmu⟩
#align exists_preirreducible exists_preirreducible
/-- The set of irreducible components of a topological space. -/
def irreducibleComponents (X : Type*) [TopologicalSpace X] : Set (Set X) :=
maximals (· ≤ ·) { s : Set X | IsIrreducible s }
#align irreducible_components irreducibleComponents
theorem isClosed_of_mem_irreducibleComponents (s) (H : s ∈ irreducibleComponents X) :
IsClosed s := by
rw [← closure_eq_iff_isClosed, eq_comm]
exact subset_closure.antisymm (H.2 H.1.closure subset_closure)
#align is_closed_of_mem_irreducible_components isClosed_of_mem_irreducibleComponents
theorem irreducibleComponents_eq_maximals_closed (X : Type*) [TopologicalSpace X] :
irreducibleComponents X = maximals (· ≤ ·) { s : Set X | IsClosed s ∧ IsIrreducible s } := by
ext s
constructor
· intro H
exact ⟨⟨isClosed_of_mem_irreducibleComponents _ H, H.1⟩, fun x h e => H.2 h.2 e⟩
· intro H
refine ⟨H.1.2, fun x h e => ?_⟩
have : closure x ≤ s := H.2 ⟨isClosed_closure, h.closure⟩ (e.trans subset_closure)
exact le_trans subset_closure this
#align irreducible_components_eq_maximals_closed irreducibleComponents_eq_maximals_closed
/-- A maximal irreducible set that contains a given point. -/
def irreducibleComponent (x : X) : Set X :=
Classical.choose (exists_preirreducible {x} isPreirreducible_singleton)
#align irreducible_component irreducibleComponent
theorem irreducibleComponent_property (x : X) :
IsPreirreducible (irreducibleComponent x) ∧
{x} ⊆ irreducibleComponent x ∧
∀ u, IsPreirreducible u → irreducibleComponent x ⊆ u → u = irreducibleComponent x :=
Classical.choose_spec (exists_preirreducible {x} isPreirreducible_singleton)
#align irreducible_component_property irreducibleComponent_property
theorem mem_irreducibleComponent {x : X} : x ∈ irreducibleComponent x :=
singleton_subset_iff.1 (irreducibleComponent_property x).2.1
#align mem_irreducible_component mem_irreducibleComponent
theorem isIrreducible_irreducibleComponent {x : X} : IsIrreducible (irreducibleComponent x) :=
⟨⟨x, mem_irreducibleComponent⟩, (irreducibleComponent_property x).1⟩
#align is_irreducible_irreducible_component isIrreducible_irreducibleComponent
theorem eq_irreducibleComponent {x : X} :
IsPreirreducible s → irreducibleComponent x ⊆ s → s = irreducibleComponent x :=
(irreducibleComponent_property x).2.2 _
#align eq_irreducible_component eq_irreducibleComponent
theorem irreducibleComponent_mem_irreducibleComponents (x : X) :
irreducibleComponent x ∈ irreducibleComponents X :=
⟨isIrreducible_irreducibleComponent, fun _ h₁ h₂ => (eq_irreducibleComponent h₁.2 h₂).le⟩
#align irreducible_component_mem_irreducible_components irreducibleComponent_mem_irreducibleComponents
theorem isClosed_irreducibleComponent {x : X} : IsClosed (irreducibleComponent x) :=
isClosed_of_mem_irreducibleComponents _ (irreducibleComponent_mem_irreducibleComponents x)
#align is_closed_irreducible_component isClosed_irreducibleComponent
/-- A preirreducible space is one where there is no non-trivial pair of disjoint opens. -/
class PreirreducibleSpace (X : Type*) [TopologicalSpace X] : Prop where
/-- In a preirreducible space, `Set.univ` is a preirreducible set. -/
isPreirreducible_univ : IsPreirreducible (univ : Set X)
#align preirreducible_space PreirreducibleSpace
/-- An irreducible space is one that is nonempty
and where there is no non-trivial pair of disjoint opens. -/
class IrreducibleSpace (X : Type*) [TopologicalSpace X] extends PreirreducibleSpace X : Prop where
toNonempty : Nonempty X
#align irreducible_space IrreducibleSpace
-- see Note [lower instance priority]
attribute [instance 50] IrreducibleSpace.toNonempty
theorem IrreducibleSpace.isIrreducible_univ (X : Type*) [TopologicalSpace X] [IrreducibleSpace X] :
IsIrreducible (univ : Set X) :=
⟨univ_nonempty, PreirreducibleSpace.isPreirreducible_univ⟩
#align irreducible_space.is_irreducible_univ IrreducibleSpace.isIrreducible_univ
theorem irreducibleSpace_def (X : Type*) [TopologicalSpace X] :
IrreducibleSpace X ↔ IsIrreducible (⊤ : Set X) :=
⟨@IrreducibleSpace.isIrreducible_univ X _, fun h =>
haveI : PreirreducibleSpace X := ⟨h.2⟩
⟨⟨h.1.some⟩⟩⟩
#align irreducible_space_def irreducibleSpace_def
theorem nonempty_preirreducible_inter [PreirreducibleSpace X] :
IsOpen s → IsOpen t → s.Nonempty → t.Nonempty → (s ∩ t).Nonempty := by
simpa only [univ_inter, univ_subset_iff] using
@PreirreducibleSpace.isPreirreducible_univ X _ _ s t
#align nonempty_preirreducible_inter nonempty_preirreducible_inter
/-- In a (pre)irreducible space, a nonempty open set is dense. -/
protected theorem IsOpen.dense [PreirreducibleSpace X] (ho : IsOpen s) (hne : s.Nonempty) :
Dense s :=
dense_iff_inter_open.2 fun _t hto htne => nonempty_preirreducible_inter hto ho htne hne
#align is_open.dense IsOpen.dense
theorem IsPreirreducible.image (H : IsPreirreducible s) (f : X → Y) (hf : ContinuousOn f s) :
IsPreirreducible (f '' s) := by
rintro u v hu hv ⟨_, ⟨⟨x, hx, rfl⟩, hxu⟩⟩ ⟨_, ⟨⟨y, hy, rfl⟩, hyv⟩⟩
rw [← mem_preimage] at hxu hyv
rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩
rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩
have := H u' v' hu' hv'
rw [inter_comm s u', ← u'_eq] at this
rw [inter_comm s v', ← v'_eq] at this
rcases this ⟨x, hxu, hx⟩ ⟨y, hyv, hy⟩ with ⟨x, hxs, hxu', hxv'⟩
refine ⟨f x, mem_image_of_mem f hxs, ?_, ?_⟩
all_goals
rw [← mem_preimage]
apply mem_of_mem_inter_left
show x ∈ _ ∩ s
simp [*]
#align is_preirreducible.image IsPreirreducible.image
theorem IsIrreducible.image (H : IsIrreducible s) (f : X → Y) (hf : ContinuousOn f s) :
IsIrreducible (f '' s) :=
⟨H.nonempty.image _, H.isPreirreducible.image f hf⟩
#align is_irreducible.image IsIrreducible.image
theorem Subtype.preirreducibleSpace (h : IsPreirreducible s) : PreirreducibleSpace s where
isPreirreducible_univ := by
rintro _ _ ⟨u, hu, rfl⟩ ⟨v, hv, rfl⟩ ⟨⟨x, hxs⟩, -, hxu⟩ ⟨⟨y, hys⟩, -, hyv⟩
rcases h u v hu hv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨x, hxs, ⟨hxu, hxv⟩⟩
exact ⟨⟨x, hxs⟩, ⟨Set.mem_univ _, ⟨hxu, hxv⟩⟩⟩
#align subtype.preirreducible_space Subtype.preirreducibleSpace
theorem Subtype.irreducibleSpace (h : IsIrreducible s) : IrreducibleSpace s where
isPreirreducible_univ :=
(Subtype.preirreducibleSpace h.isPreirreducible).isPreirreducible_univ
toNonempty := h.nonempty.to_subtype
#align subtype.irreducible_space Subtype.irreducibleSpace
/-- An infinite type with cofinite topology is an irreducible topological space. -/
instance (priority := 100) {X} [Infinite X] : IrreducibleSpace (CofiniteTopology X) where
isPreirreducible_univ u v := by
haveI : Infinite (CofiniteTopology X) := ‹_›
simp only [CofiniteTopology.isOpen_iff, univ_inter]
intro hu hv hu' hv'
simpa only [compl_union, compl_compl] using ((hu hu').union (hv hv')).infinite_compl.nonempty
toNonempty := (inferInstance : Nonempty X)
/-- A set `s` is irreducible if and only if
for every finite collection of open sets all of whose members intersect `s`,
`s` also intersects the intersection of the entire collection
(i.e., there is an element of `s` contained in every member of the collection). -/
| Mathlib/Topology/Irreducible.lean | 252 | 265 | theorem isIrreducible_iff_sInter :
IsIrreducible s ↔
∀ (U : Finset (Set X)), (∀ u ∈ U, IsOpen u) → (∀ u ∈ U, (s ∩ u).Nonempty) →
(s ∩ ⋂₀ ↑U).Nonempty := by |
refine ⟨fun h U hu hU => ?_, fun h => ⟨?_, ?_⟩⟩
· induction U using Finset.induction_on with
| empty => simpa using h.nonempty
| @insert u U _ IH =>
rw [Finset.coe_insert, sInter_insert]
rw [Finset.forall_mem_insert] at hu hU
exact h.2 _ _ hu.1 (U.finite_toSet.isOpen_sInter hu.2) hU.1 (IH hu.2 hU.2)
· simpa using h ∅
· intro u v hu hv hu' hv'
simpa [*] using h {u, v}
|
/-
Copyright (c) 2022 Rémy Degenne, Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Kexing Ying
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.MeasureTheory.Function.Egorov
import Mathlib.MeasureTheory.Function.LpSpace
#align_import measure_theory.function.convergence_in_measure from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8"
/-!
# Convergence in measure
We define convergence in measure which is one of the many notions of convergence in probability.
A sequence of functions `f` is said to converge in measure to some function `g`
if for all `ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i`
converges along some given filter `l`.
Convergence in measure is most notably used in the formulation of the weak law of large numbers
and is also useful in theorems such as the Vitali convergence theorem. This file provides some
basic lemmas for working with convergence in measure and establishes some relations between
convergence in measure and other notions of convergence.
## Main definitions
* `MeasureTheory.TendstoInMeasure (μ : Measure α) (f : ι → α → E) (g : α → E)`: `f` converges
in `μ`-measure to `g`.
## Main results
* `MeasureTheory.tendstoInMeasure_of_tendsto_ae`: convergence almost everywhere in a finite
measure space implies convergence in measure.
* `MeasureTheory.TendstoInMeasure.exists_seq_tendsto_ae`: if `f` is a sequence of functions
which converges in measure to `g`, then `f` has a subsequence which convergence almost
everywhere to `g`.
* `MeasureTheory.tendstoInMeasure_of_tendsto_snorm`: convergence in Lp implies convergence
in measure.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory Topology
namespace MeasureTheory
variable {α ι E : Type*} {m : MeasurableSpace α} {μ : Measure α}
/-- A sequence of functions `f` is said to converge in measure to some function `g` if for all
`ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i` converges along
some given filter `l`. -/
def TendstoInMeasure [Dist E] {_ : MeasurableSpace α} (μ : Measure α) (f : ι → α → E) (l : Filter ι)
(g : α → E) : Prop :=
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ dist (f i x) (g x) }) l (𝓝 0)
#align measure_theory.tendsto_in_measure MeasureTheory.TendstoInMeasure
theorem tendstoInMeasure_iff_norm [SeminormedAddCommGroup E] {l : Filter ι} {f : ι → α → E}
{g : α → E} :
TendstoInMeasure μ f l g ↔
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ ‖f i x - g x‖ }) l (𝓝 0) := by
simp_rw [TendstoInMeasure, dist_eq_norm]
#align measure_theory.tendsto_in_measure_iff_norm MeasureTheory.tendstoInMeasure_iff_norm
namespace TendstoInMeasure
variable [Dist E] {l : Filter ι} {f f' : ι → α → E} {g g' : α → E}
protected theorem congr' (h_left : ∀ᶠ i in l, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' := by
intro ε hε
suffices
(fun i => μ { x | ε ≤ dist (f' i x) (g' x) }) =ᶠ[l] fun i => μ { x | ε ≤ dist (f i x) (g x) } by
rw [tendsto_congr' this]
exact h_tendsto ε hε
filter_upwards [h_left] with i h_ae_eq
refine measure_congr ?_
filter_upwards [h_ae_eq, h_right] with x hxf hxg
rw [eq_iff_iff]
change ε ≤ dist (f' i x) (g' x) ↔ ε ≤ dist (f i x) (g x)
rw [hxg, hxf]
#align measure_theory.tendsto_in_measure.congr' MeasureTheory.TendstoInMeasure.congr'
protected theorem congr (h_left : ∀ i, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' :=
TendstoInMeasure.congr' (eventually_of_forall h_left) h_right h_tendsto
#align measure_theory.tendsto_in_measure.congr MeasureTheory.TendstoInMeasure.congr
theorem congr_left (h : ∀ i, f i =ᵐ[μ] f' i) (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f' l g :=
h_tendsto.congr h EventuallyEq.rfl
#align measure_theory.tendsto_in_measure.congr_left MeasureTheory.TendstoInMeasure.congr_left
theorem congr_right (h : g =ᵐ[μ] g') (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f l g' :=
h_tendsto.congr (fun _ => EventuallyEq.rfl) h
#align measure_theory.tendsto_in_measure.congr_right MeasureTheory.TendstoInMeasure.congr_right
end TendstoInMeasure
section ExistsSeqTendstoAe
variable [MetricSpace E]
variable {f : ℕ → α → E} {g : α → E}
/-- Auxiliary lemma for `tendstoInMeasure_of_tendsto_ae`. -/
theorem tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable [IsFiniteMeasure μ]
(hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by
refine fun ε hε => ENNReal.tendsto_atTop_zero.mpr fun δ hδ => ?_
by_cases hδi : δ = ∞
· simp only [hδi, imp_true_iff, le_top, exists_const]
lift δ to ℝ≥0 using hδi
rw [gt_iff_lt, ENNReal.coe_pos, ← NNReal.coe_pos] at hδ
obtain ⟨t, _, ht, hunif⟩ := tendstoUniformlyOn_of_ae_tendsto' hf hg hfg hδ
rw [ENNReal.ofReal_coe_nnreal] at ht
rw [Metric.tendstoUniformlyOn_iff] at hunif
obtain ⟨N, hN⟩ := eventually_atTop.1 (hunif ε hε)
refine ⟨N, fun n hn => ?_⟩
suffices { x : α | ε ≤ dist (f n x) (g x) } ⊆ t from (measure_mono this).trans ht
rw [← Set.compl_subset_compl]
intro x hx
rw [Set.mem_compl_iff, Set.nmem_setOf_iff, dist_comm, not_le]
exact hN n hn x hx
#align measure_theory.tendsto_in_measure_of_tendsto_ae_of_strongly_measurable MeasureTheory.tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable
/-- Convergence a.e. implies convergence in measure in a finite measure space. -/
theorem tendstoInMeasure_of_tendsto_ae [IsFiniteMeasure μ] (hf : ∀ n, AEStronglyMeasurable (f n) μ)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by
have hg : AEStronglyMeasurable g μ := aestronglyMeasurable_of_tendsto_ae _ hf hfg
refine TendstoInMeasure.congr (fun i => (hf i).ae_eq_mk.symm) hg.ae_eq_mk.symm ?_
refine tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable
(fun i => (hf i).stronglyMeasurable_mk) hg.stronglyMeasurable_mk ?_
have hf_eq_ae : ∀ᵐ x ∂μ, ∀ n, (hf n).mk (f n) x = f n x :=
ae_all_iff.mpr fun n => (hf n).ae_eq_mk.symm
filter_upwards [hf_eq_ae, hg.ae_eq_mk, hfg] with x hxf hxg hxfg
rw [← hxg, funext fun n => hxf n]
exact hxfg
#align measure_theory.tendsto_in_measure_of_tendsto_ae MeasureTheory.tendstoInMeasure_of_tendsto_ae
namespace ExistsSeqTendstoAe
| Mathlib/MeasureTheory/Function/ConvergenceInMeasure.lean | 143 | 147 | theorem exists_nat_measure_lt_two_inv (hfg : TendstoInMeasure μ f atTop g) (n : ℕ) :
∃ N, ∀ m ≥ N, μ { x | (2 : ℝ)⁻¹ ^ n ≤ dist (f m x) (g x) } ≤ (2⁻¹ : ℝ≥0∞) ^ n := by |
specialize hfg ((2⁻¹ : ℝ) ^ n) (by simp only [Real.rpow_natCast, inv_pos, zero_lt_two, pow_pos])
rw [ENNReal.tendsto_atTop_zero] at hfg
exact hfg ((2 : ℝ≥0∞)⁻¹ ^ n) (pos_iff_ne_zero.mpr fun h_zero => by simpa using pow_eq_zero h_zero)
|
/-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.Data.Nat.Choose.Dvd
import Mathlib.RingTheory.IntegrallyClosed
import Mathlib.RingTheory.Norm
import Mathlib.RingTheory.Polynomial.Cyclotomic.Expand
#align_import ring_theory.polynomial.eisenstein.is_integral from "leanprover-community/mathlib"@"5bfbcca0a7ffdd21cf1682e59106d6c942434a32"
/-!
# Eisenstein polynomials
In this file we gather more miscellaneous results about Eisenstein polynomials
## Main results
* `mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt`: let `K` be the field of fraction
of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an
integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given
`z : L` integral over `R`, if `p ^ n • z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`.
Together with `Algebra.discr_mul_isIntegral_mem_adjoin` this result often allows to compute the
ring of integers of `L`.
-/
universe u v w z
variable {R : Type u}
open Ideal Algebra Finset
open scoped Polynomial
section Cyclotomic
variable (p : ℕ)
local notation "𝓟" => Submodule.span ℤ {(p : ℤ)}
open Polynomial
| Mathlib/RingTheory/Polynomial/Eisenstein/IsIntegral.lean | 44 | 73 | theorem cyclotomic_comp_X_add_one_isEisensteinAt [hp : Fact p.Prime] :
((cyclotomic p ℤ).comp (X + 1)).IsEisensteinAt 𝓟 := by |
refine Monic.isEisensteinAt_of_mem_of_not_mem ?_
(Ideal.IsPrime.ne_top <| (Ideal.span_singleton_prime (mod_cast hp.out.ne_zero)).2 <|
Nat.prime_iff_prime_int.1 hp.out) (fun {i hi} => ?_) ?_
· rw [show (X + 1 : ℤ[X]) = X + C 1 by simp]
refine (cyclotomic.monic p ℤ).comp (monic_X_add_C 1) fun h => ?_
rw [natDegree_X_add_C] at h
exact zero_ne_one h.symm
· rw [cyclotomic_prime, geom_sum_X_comp_X_add_one_eq_sum, ← lcoeff_apply, map_sum]
conv =>
congr
congr
next => skip
ext
rw [lcoeff_apply, ← C_eq_natCast, C_mul_X_pow_eq_monomial, coeff_monomial]
rw [natDegree_comp, show (X + 1 : ℤ[X]) = X + C 1 by simp, natDegree_X_add_C, mul_one,
natDegree_cyclotomic, Nat.totient_prime hp.out] at hi
simp only [hi.trans_le (Nat.sub_le _ _), sum_ite_eq', mem_range, if_true,
Ideal.submodule_span_eq, Ideal.mem_span_singleton, Int.natCast_dvd_natCast]
exact hp.out.dvd_choose_self i.succ_ne_zero (lt_tsub_iff_right.1 hi)
· rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime, eval_add, eval_X, eval_one, zero_add,
eval_geom_sum, one_geom_sum, Ideal.submodule_span_eq, Ideal.span_singleton_pow,
Ideal.mem_span_singleton]
intro h
obtain ⟨k, hk⟩ := Int.natCast_dvd_natCast.1 h
rw [mul_assoc, mul_comm 1, mul_one] at hk
nth_rw 1 [← Nat.mul_one p] at hk
rw [mul_right_inj' hp.out.ne_zero] at hk
exact Nat.Prime.not_dvd_one hp.out (Dvd.intro k hk.symm)
|
/-
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.Complex.Log
#align_import analysis.special_functions.pow.complex from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8"
/-! # Power function on `ℂ`
We construct the power functions `x ^ y`, where `x` and `y` are complex numbers.
-/
open scoped Classical
open Real Topology Filter ComplexConjugate Finset Set
namespace Complex
/-- The complex power function `x ^ y`, given by `x ^ y = exp(y log x)` (where `log` is the
principal determination of the logarithm), unless `x = 0` where one sets `0 ^ 0 = 1` and
`0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def cpow (x y : ℂ) : ℂ :=
if x = 0 then if y = 0 then 1 else 0 else exp (log x * y)
#align complex.cpow Complex.cpow
noncomputable instance : Pow ℂ ℂ :=
⟨cpow⟩
@[simp]
theorem cpow_eq_pow (x y : ℂ) : cpow x y = x ^ y :=
rfl
#align complex.cpow_eq_pow Complex.cpow_eq_pow
theorem cpow_def (x y : ℂ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) :=
rfl
#align complex.cpow_def Complex.cpow_def
theorem cpow_def_of_ne_zero {x : ℂ} (hx : x ≠ 0) (y : ℂ) : x ^ y = exp (log x * y) :=
if_neg hx
#align complex.cpow_def_of_ne_zero Complex.cpow_def_of_ne_zero
@[simp]
theorem cpow_zero (x : ℂ) : x ^ (0 : ℂ) = 1 := by simp [cpow_def]
#align complex.cpow_zero Complex.cpow_zero
@[simp]
theorem cpow_eq_zero_iff (x y : ℂ) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
simp only [cpow_def]
split_ifs <;> simp [*, exp_ne_zero]
#align complex.cpow_eq_zero_iff Complex.cpow_eq_zero_iff
@[simp]
theorem zero_cpow {x : ℂ} (h : x ≠ 0) : (0 : ℂ) ^ x = 0 := by simp [cpow_def, *]
#align complex.zero_cpow Complex.zero_cpow
theorem zero_cpow_eq_iff {x : ℂ} {a : ℂ} : (0 : ℂ) ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
constructor
· intro hyp
simp only [cpow_def, eq_self_iff_true, if_true] at hyp
by_cases h : x = 0
· subst h
simp only [if_true, eq_self_iff_true] at hyp
right
exact ⟨rfl, hyp.symm⟩
· rw [if_neg h] at hyp
left
exact ⟨h, hyp.symm⟩
· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩)
· exact zero_cpow h
· exact cpow_zero _
#align complex.zero_cpow_eq_iff Complex.zero_cpow_eq_iff
theorem eq_zero_cpow_iff {x : ℂ} {a : ℂ} : a = (0 : ℂ) ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
rw [← zero_cpow_eq_iff, eq_comm]
#align complex.eq_zero_cpow_iff Complex.eq_zero_cpow_iff
@[simp]
theorem cpow_one (x : ℂ) : x ^ (1 : ℂ) = x :=
if hx : x = 0 then by simp [hx, cpow_def]
else by rw [cpow_def, if_neg (one_ne_zero : (1 : ℂ) ≠ 0), if_neg hx, mul_one, exp_log hx]
#align complex.cpow_one Complex.cpow_one
@[simp]
theorem one_cpow (x : ℂ) : (1 : ℂ) ^ x = 1 := by
rw [cpow_def]
split_ifs <;> simp_all [one_ne_zero]
#align complex.one_cpow Complex.one_cpow
theorem cpow_add {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by
simp only [cpow_def, ite_mul, boole_mul, mul_ite, mul_boole]
simp_all [exp_add, mul_add]
#align complex.cpow_add Complex.cpow_add
| Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean | 96 | 99 | theorem cpow_mul {x y : ℂ} (z : ℂ) (h₁ : -π < (log x * y).im) (h₂ : (log x * y).im ≤ π) :
x ^ (y * z) = (x ^ y) ^ z := by |
simp only [cpow_def]
split_ifs <;> simp_all [exp_ne_zero, log_exp h₁ h₂, mul_assoc]
|
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.MeasureTheory.Integral.Pi
import Mathlib.Analysis.Fourier.FourierTransform
/-!
# Fourier transform of the Gaussian
We prove that the Fourier transform of the Gaussian function is another Gaussian:
* `integral_cexp_quadratic`: general formula for `∫ (x : ℝ), exp (b * x ^ 2 + c * x + d)`
* `fourierIntegral_gaussian`: for all complex `b` and `t` with `0 < re b`, we have
`∫ x:ℝ, exp (I * t * x) * exp (-b * x^2) = (π / b) ^ (1 / 2) * exp (-t ^ 2 / (4 * b))`.
* `fourierIntegral_gaussian_pi`: a variant with `b` and `t` scaled to give a more symmetric
statement, and formulated in terms of the Fourier transform operator `𝓕`.
We also give versions of these formulas in finite-dimensional inner product spaces, see
`integral_cexp_neg_mul_sq_norm_add` and `fourierIntegral_gaussian_innerProductSpace`.
-/
/-!
## Fourier integral of Gaussian functions
-/
open Real Set MeasureTheory Filter Asymptotics intervalIntegral
open scoped Real Topology FourierTransform RealInnerProductSpace
open Complex hiding exp continuous_exp abs_of_nonneg sq_abs
noncomputable section
namespace GaussianFourier
variable {b : ℂ}
/-- The integral of the Gaussian function over the vertical edges of a rectangle
with vertices at `(±T, 0)` and `(±T, c)`. -/
def verticalIntegral (b : ℂ) (c T : ℝ) : ℂ :=
∫ y : ℝ in (0 : ℝ)..c, I * (cexp (-b * (T + y * I) ^ 2) - cexp (-b * (T - y * I) ^ 2))
#align gaussian_fourier.vertical_integral GaussianFourier.verticalIntegral
/-- Explicit formula for the norm of the Gaussian function along the vertical
edges. -/
theorem norm_cexp_neg_mul_sq_add_mul_I (b : ℂ) (c T : ℝ) :
‖cexp (-b * (T + c * I) ^ 2)‖ = exp (-(b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2)) := by
rw [Complex.norm_eq_abs, Complex.abs_exp, neg_mul, neg_re, ← re_add_im b]
simp only [sq, re_add_im, mul_re, mul_im, add_re, add_im, ofReal_re, ofReal_im, I_re, I_im]
ring_nf
set_option linter.uppercaseLean3 false in
#align gaussian_fourier.norm_cexp_neg_mul_sq_add_mul_I GaussianFourier.norm_cexp_neg_mul_sq_add_mul_I
| Mathlib/Analysis/SpecialFunctions/Gaussian/FourierTransform.lean | 59 | 66 | theorem norm_cexp_neg_mul_sq_add_mul_I' (hb : b.re ≠ 0) (c T : ℝ) :
‖cexp (-b * (T + c * I) ^ 2)‖ =
exp (-(b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re))) := by |
have :
b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2 =
b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re) := by
field_simp; ring
rw [norm_cexp_neg_mul_sq_add_mul_I, this]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Michael Stoll
-/
import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.Basic
#align_import number_theory.legendre_symbol.basic from "leanprover-community/mathlib"@"5b2fe80501ff327b9109fb09b7cc8c325cd0d7d9"
/-!
# Legendre symbol
This file contains results about Legendre symbols.
We define the Legendre symbol $\Bigl(\frac{a}{p}\Bigr)$ as `legendreSym p a`.
Note the order of arguments! The advantage of this form is that then `legendreSym p`
is a multiplicative map.
The Legendre symbol is used to define the Jacobi symbol, `jacobiSym a b`, for integers `a`
and (odd) natural numbers `b`, which extends the Legendre symbol.
## Main results
We also prove the supplementary laws that give conditions for when `-1`
is a square modulo a prime `p`:
`legendreSym.at_neg_one` and `ZMod.exists_sq_eq_neg_one_iff` for `-1`.
See `NumberTheory.LegendreSymbol.QuadraticReciprocity` for the conditions when `2` and `-2`
are squares:
`legendreSym.at_two` and `ZMod.exists_sq_eq_two_iff` for `2`,
`legendreSym.at_neg_two` and `ZMod.exists_sq_eq_neg_two_iff` for `-2`.
## Tags
quadratic residue, quadratic nonresidue, Legendre symbol
-/
open Nat
section Euler
namespace ZMod
variable (p : ℕ) [Fact p.Prime]
/-- Euler's Criterion: A unit `x` of `ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/
theorem euler_criterion_units (x : (ZMod p)ˣ) : (∃ y : (ZMod p)ˣ, y ^ 2 = x) ↔ x ^ (p / 2) = 1 := by
by_cases hc : p = 2
· subst hc
simp only [eq_iff_true_of_subsingleton, exists_const]
· have h₀ := FiniteField.unit_isSquare_iff (by rwa [ringChar_zmod_n]) x
have hs : (∃ y : (ZMod p)ˣ, y ^ 2 = x) ↔ IsSquare x := by
rw [isSquare_iff_exists_sq x]
simp_rw [eq_comm]
rw [hs]
rwa [card p] at h₀
#align zmod.euler_criterion_units ZMod.euler_criterion_units
/-- Euler's Criterion: a nonzero `a : ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/
theorem euler_criterion {a : ZMod p} (ha : a ≠ 0) : IsSquare (a : ZMod p) ↔ a ^ (p / 2) = 1 := by
apply (iff_congr _ (by simp [Units.ext_iff])).mp (euler_criterion_units p (Units.mk0 a ha))
simp only [Units.ext_iff, sq, Units.val_mk0, Units.val_mul]
constructor
· rintro ⟨y, hy⟩; exact ⟨y, hy.symm⟩
· rintro ⟨y, rfl⟩
have hy : y ≠ 0 := by
rintro rfl
simp [zero_pow, mul_zero, ne_eq, not_true] at ha
refine ⟨Units.mk0 y hy, ?_⟩; simp
#align zmod.euler_criterion ZMod.euler_criterion
/-- If `a : ZMod p` is nonzero, then `a^(p/2)` is either `1` or `-1`. -/
theorem pow_div_two_eq_neg_one_or_one {a : ZMod p} (ha : a ≠ 0) :
a ^ (p / 2) = 1 ∨ a ^ (p / 2) = -1 := by
cases' Prime.eq_two_or_odd (@Fact.out p.Prime _) with hp2 hp_odd
· subst p; revert a ha; intro a; fin_cases a
· tauto
· simp
rw [← mul_self_eq_one_iff, ← pow_add, ← two_mul, two_mul_odd_div_two hp_odd]
exact pow_card_sub_one_eq_one ha
#align zmod.pow_div_two_eq_neg_one_or_one ZMod.pow_div_two_eq_neg_one_or_one
end ZMod
end Euler
section Legendre
/-!
### Definition of the Legendre symbol and basic properties
-/
open ZMod
variable (p : ℕ) [Fact p.Prime]
/-- The Legendre symbol of `a : ℤ` and a prime `p`, `legendreSym p a`,
is an integer defined as
* `0` if `a` is `0` modulo `p`;
* `1` if `a` is a nonzero square modulo `p`
* `-1` otherwise.
Note the order of the arguments! The advantage of the order chosen here is
that `legendreSym p` is a multiplicative function `ℤ → ℤ`.
-/
def legendreSym (a : ℤ) : ℤ :=
quadraticChar (ZMod p) a
#align legendre_sym legendreSym
namespace legendreSym
/-- We have the congruence `legendreSym p a ≡ a ^ (p / 2) mod p`. -/
theorem eq_pow (a : ℤ) : (legendreSym p a : ZMod p) = (a : ZMod p) ^ (p / 2) := by
rcases eq_or_ne (ringChar (ZMod p)) 2 with hc | hc
· by_cases ha : (a : ZMod p) = 0
· rw [legendreSym, ha, quadraticChar_zero,
zero_pow (Nat.div_pos (@Fact.out p.Prime).two_le (succ_pos 1)).ne']
norm_cast
· have := (ringChar_zmod_n p).symm.trans hc
-- p = 2
subst p
rw [legendreSym, quadraticChar_eq_one_of_char_two hc ha]
revert ha
push_cast
generalize (a : ZMod 2) = b; fin_cases b
· tauto
· simp
· convert quadraticChar_eq_pow_of_char_ne_two' hc (a : ZMod p)
exact (card p).symm
#align legendre_sym.eq_pow legendreSym.eq_pow
/-- If `p ∤ a`, then `legendreSym p a` is `1` or `-1`. -/
theorem eq_one_or_neg_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) :
legendreSym p a = 1 ∨ legendreSym p a = -1 :=
quadraticChar_dichotomy ha
#align legendre_sym.eq_one_or_neg_one legendreSym.eq_one_or_neg_one
theorem eq_neg_one_iff_not_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) :
legendreSym p a = -1 ↔ ¬legendreSym p a = 1 :=
quadraticChar_eq_neg_one_iff_not_one ha
#align legendre_sym.eq_neg_one_iff_not_one legendreSym.eq_neg_one_iff_not_one
/-- The Legendre symbol of `p` and `a` is zero iff `p ∣ a`. -/
theorem eq_zero_iff (a : ℤ) : legendreSym p a = 0 ↔ (a : ZMod p) = 0 :=
quadraticChar_eq_zero_iff
#align legendre_sym.eq_zero_iff legendreSym.eq_zero_iff
@[simp]
theorem at_zero : legendreSym p 0 = 0 := by rw [legendreSym, Int.cast_zero, MulChar.map_zero]
#align legendre_sym.at_zero legendreSym.at_zero
@[simp]
theorem at_one : legendreSym p 1 = 1 := by rw [legendreSym, Int.cast_one, MulChar.map_one]
#align legendre_sym.at_one legendreSym.at_one
/-- The Legendre symbol is multiplicative in `a` for `p` fixed. -/
protected theorem mul (a b : ℤ) : legendreSym p (a * b) = legendreSym p a * legendreSym p b := by
simp [legendreSym, Int.cast_mul, map_mul, quadraticCharFun_mul]
#align legendre_sym.mul legendreSym.mul
/-- The Legendre symbol is a homomorphism of monoids with zero. -/
@[simps]
def hom : ℤ →*₀ ℤ where
toFun := legendreSym p
map_zero' := at_zero p
map_one' := at_one p
map_mul' := legendreSym.mul p
#align legendre_sym.hom legendreSym.hom
/-- The square of the symbol is 1 if `p ∤ a`. -/
theorem sq_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p a ^ 2 = 1 :=
quadraticChar_sq_one ha
#align legendre_sym.sq_one legendreSym.sq_one
/-- The Legendre symbol of `a^2` at `p` is 1 if `p ∤ a`. -/
theorem sq_one' {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p (a ^ 2) = 1 := by
dsimp only [legendreSym]
rw [Int.cast_pow]
exact quadraticChar_sq_one' ha
#align legendre_sym.sq_one' legendreSym.sq_one'
/-- The Legendre symbol depends only on `a` mod `p`. -/
protected theorem mod (a : ℤ) : legendreSym p a = legendreSym p (a % p) := by
simp only [legendreSym, intCast_mod]
#align legendre_sym.mod legendreSym.mod
/-- When `p ∤ a`, then `legendreSym p a = 1` iff `a` is a square mod `p`. -/
theorem eq_one_iff {a : ℤ} (ha0 : (a : ZMod p) ≠ 0) : legendreSym p a = 1 ↔ IsSquare (a : ZMod p) :=
quadraticChar_one_iff_isSquare ha0
#align legendre_sym.eq_one_iff legendreSym.eq_one_iff
theorem eq_one_iff' {a : ℕ} (ha0 : (a : ZMod p) ≠ 0) :
legendreSym p a = 1 ↔ IsSquare (a : ZMod p) := by
rw [eq_one_iff]
· norm_cast
· exact mod_cast ha0
#align legendre_sym.eq_one_iff' legendreSym.eq_one_iff'
/-- `legendreSym p a = -1` iff `a` is a nonsquare mod `p`. -/
theorem eq_neg_one_iff {a : ℤ} : legendreSym p a = -1 ↔ ¬IsSquare (a : ZMod p) :=
quadraticChar_neg_one_iff_not_isSquare
#align legendre_sym.eq_neg_one_iff legendreSym.eq_neg_one_iff
theorem eq_neg_one_iff' {a : ℕ} : legendreSym p a = -1 ↔ ¬IsSquare (a : ZMod p) := by
rw [eq_neg_one_iff]; norm_cast
#align legendre_sym.eq_neg_one_iff' legendreSym.eq_neg_one_iff'
/-- The number of square roots of `a` modulo `p` is determined by the Legendre symbol. -/
theorem card_sqrts (hp : p ≠ 2) (a : ℤ) :
↑{x : ZMod p | x ^ 2 = a}.toFinset.card = legendreSym p a + 1 :=
quadraticChar_card_sqrts ((ringChar_zmod_n p).substr hp) a
#align legendre_sym.card_sqrts legendreSym.card_sqrts
end legendreSym
end Legendre
section QuadraticForm
/-!
### Applications to binary quadratic forms
-/
namespace legendreSym
/-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `ℤ/pℤ`
of the equation `x^2 - a*y^2 = 0` with `y ≠ 0`. -/
theorem eq_one_of_sq_sub_mul_sq_eq_zero {p : ℕ} [Fact p.Prime] {a : ℤ} (ha : (a : ZMod p) ≠ 0)
{x y : ZMod p} (hy : y ≠ 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by
apply_fun (· * y⁻¹ ^ 2) at hxy
simp only [zero_mul] at hxy
rw [(by ring : (x ^ 2 - ↑a * y ^ 2) * y⁻¹ ^ 2 = (x * y⁻¹) ^ 2 - a * (y * y⁻¹) ^ 2),
mul_inv_cancel hy, one_pow, mul_one, sub_eq_zero, pow_two] at hxy
exact (eq_one_iff p ha).mpr ⟨x * y⁻¹, hxy.symm⟩
#align legendre_sym.eq_one_of_sq_sub_mul_sq_eq_zero legendreSym.eq_one_of_sq_sub_mul_sq_eq_zero
/-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `ℤ/pℤ`
of the equation `x^2 - a*y^2 = 0` with `x ≠ 0`. -/
theorem eq_one_of_sq_sub_mul_sq_eq_zero' {p : ℕ} [Fact p.Prime] {a : ℤ} (ha : (a : ZMod p) ≠ 0)
{x y : ZMod p} (hx : x ≠ 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by
haveI hy : y ≠ 0 := by
rintro rfl
rw [zero_pow two_ne_zero, mul_zero, sub_zero, sq_eq_zero_iff] at hxy
exact hx hxy
exact eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy
#align legendre_sym.eq_one_of_sq_sub_mul_sq_eq_zero' legendreSym.eq_one_of_sq_sub_mul_sq_eq_zero'
/-- If `legendreSym p a = -1`, then the only solution of `x^2 - a*y^2 = 0` in `ℤ/pℤ`
is the trivial one. -/
theorem eq_zero_mod_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : legendreSym p a = -1)
{x y : ZMod p} (hxy : x ^ 2 - a * y ^ 2 = 0) : x = 0 ∧ y = 0 := by
have ha : (a : ZMod p) ≠ 0 := by
intro hf
rw [(eq_zero_iff p a).mpr hf] at h
simp at h
by_contra hf
cases' imp_iff_or_not.mp (not_and'.mp hf) with hx hy
· rw [eq_one_of_sq_sub_mul_sq_eq_zero' ha hx hxy, eq_neg_self_iff] at h
exact one_ne_zero h
· rw [eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy, eq_neg_self_iff] at h
exact one_ne_zero h
#align legendre_sym.eq_zero_mod_of_eq_neg_one legendreSym.eq_zero_mod_of_eq_neg_one
/-- If `legendreSym p a = -1` and `p` divides `x^2 - a*y^2`, then `p` must divide `x` and `y`. -/
theorem prime_dvd_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : legendreSym p a = -1) {x y : ℤ}
(hxy : (p : ℤ) ∣ x ^ 2 - a * y ^ 2) : ↑p ∣ x ∧ ↑p ∣ y := by
simp_rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] at hxy ⊢
push_cast at hxy
exact eq_zero_mod_of_eq_neg_one h hxy
#align legendre_sym.prime_dvd_of_eq_neg_one legendreSym.prime_dvd_of_eq_neg_one
end legendreSym
end QuadraticForm
section Values
/-!
### The value of the Legendre symbol at `-1`
See `jacobiSym.at_neg_one` for the corresponding statement for the Jacobi symbol.
-/
variable {p : ℕ} [Fact p.Prime]
open ZMod
/-- `legendreSym p (-1)` is given by `χ₄ p`. -/
theorem legendreSym.at_neg_one (hp : p ≠ 2) : legendreSym p (-1) = χ₄ p := by
simp only [legendreSym, card p, quadraticChar_neg_one ((ringChar_zmod_n p).substr hp),
Int.cast_neg, Int.cast_one]
#align legendre_sym.at_neg_one legendreSym.at_neg_one
namespace ZMod
/-- `-1` is a square in `ZMod p` iff `p` is not congruent to `3` mod `4`. -/
| Mathlib/NumberTheory/LegendreSymbol/Basic.lean | 302 | 303 | theorem exists_sq_eq_neg_one_iff : IsSquare (-1 : ZMod p) ↔ p % 4 ≠ 3 := by |
rw [FiniteField.isSquare_neg_one_iff, card p]
|
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.NonUnitalHom
import Mathlib.Data.Set.UnionLift
import Mathlib.LinearAlgebra.Basic
import Mathlib.LinearAlgebra.Span
import Mathlib.RingTheory.NonUnitalSubring.Basic
/-!
# Non-unital Subalgebras over Commutative Semirings
In this file we define `NonUnitalSubalgebra`s and the usual operations on them (`map`, `comap`).
## TODO
* once we have scalar actions by semigroups (as opposed to monoids), implement the action of a
non-unital subalgebra on the larger algebra.
-/
universe u u' v v' w w'
section NonUnitalSubalgebraClass
variable {S R A : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A]
variable [SetLike S A] [NonUnitalSubsemiringClass S A] [hSR : SMulMemClass S R A] (s : S)
namespace NonUnitalSubalgebraClass
/-- Embedding of a non-unital subalgebra into the non-unital algebra. -/
def subtype (s : S) : s →ₙₐ[R] A :=
{ NonUnitalSubsemiringClass.subtype s, SMulMemClass.subtype s with toFun := (↑) }
@[simp]
theorem coeSubtype : (subtype s : s → A) = ((↑) : s → A) :=
rfl
end NonUnitalSubalgebraClass
end NonUnitalSubalgebraClass
/-- A non-unital subalgebra is a sub(semi)ring that is also a submodule. -/
structure NonUnitalSubalgebra (R : Type u) (A : Type v) [CommSemiring R]
[NonUnitalNonAssocSemiring A] [Module R A]
extends NonUnitalSubsemiring A, Submodule R A : Type v
/-- Reinterpret a `NonUnitalSubalgebra` as a `NonUnitalSubsemiring`. -/
add_decl_doc NonUnitalSubalgebra.toNonUnitalSubsemiring
/-- Reinterpret a `NonUnitalSubalgebra` as a `Submodule`. -/
add_decl_doc NonUnitalSubalgebra.toSubmodule
namespace NonUnitalSubalgebra
variable {F : Type v'} {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}
section NonUnitalNonAssocSemiring
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [NonUnitalNonAssocSemiring C]
variable [Module R A] [Module R B] [Module R C]
instance : SetLike (NonUnitalSubalgebra R A) A where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h
instance instNonUnitalSubsemiringClass :
NonUnitalSubsemiringClass (NonUnitalSubalgebra R A) A where
add_mem {s} := s.add_mem'
mul_mem {s} := s.mul_mem'
zero_mem {s} := s.zero_mem'
instance instSMulMemClass : SMulMemClass (NonUnitalSubalgebra R A) R A where
smul_mem := @fun s => s.smul_mem'
theorem mem_carrier {s : NonUnitalSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
@[ext]
theorem ext {S T : NonUnitalSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
@[simp]
theorem mem_toNonUnitalSubsemiring {S : NonUnitalSubalgebra R A} {x} :
x ∈ S.toNonUnitalSubsemiring ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubsemiring (S : NonUnitalSubalgebra R A) :
(↑S.toNonUnitalSubsemiring : Set A) = S :=
rfl
theorem toNonUnitalSubsemiring_injective :
Function.Injective
(toNonUnitalSubsemiring : NonUnitalSubalgebra R A → NonUnitalSubsemiring A) :=
fun S T h =>
ext fun x => by rw [← mem_toNonUnitalSubsemiring, ← mem_toNonUnitalSubsemiring, h]
theorem toNonUnitalSubsemiring_inj {S U : NonUnitalSubalgebra R A} :
S.toNonUnitalSubsemiring = U.toNonUnitalSubsemiring ↔ S = U :=
toNonUnitalSubsemiring_injective.eq_iff
theorem mem_toSubmodule (S : NonUnitalSubalgebra R A) {x} : x ∈ S.toSubmodule ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_toSubmodule (S : NonUnitalSubalgebra R A) : (↑S.toSubmodule : Set A) = S :=
rfl
theorem toSubmodule_injective :
Function.Injective (toSubmodule : NonUnitalSubalgebra R A → Submodule R A) := fun S T h =>
ext fun x => by rw [← mem_toSubmodule, ← mem_toSubmodule, h]
theorem toSubmodule_inj {S U : NonUnitalSubalgebra R A} : S.toSubmodule = U.toSubmodule ↔ S = U :=
toSubmodule_injective.eq_iff
/-- Copy of a non-unital subalgebra with a new `carrier` equal to the old one.
Useful to fix definitional equalities. -/
protected def copy (S : NonUnitalSubalgebra R A) (s : Set A) (hs : s = ↑S) :
NonUnitalSubalgebra R A :=
{ S.toNonUnitalSubsemiring.copy s hs with
smul_mem' := fun r a (ha : a ∈ s) => by
show r • a ∈ s
rw [hs] at ha ⊢
exact S.smul_mem' r ha }
@[simp]
theorem coe_copy (S : NonUnitalSubalgebra R A) (s : Set A) (hs : s = ↑S) :
(S.copy s hs : Set A) = s :=
rfl
theorem copy_eq (S : NonUnitalSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
instance (S : NonUnitalSubalgebra R A) : Inhabited S :=
⟨(0 : S.toNonUnitalSubsemiring)⟩
end NonUnitalNonAssocSemiring
section NonUnitalNonAssocRing
variable [CommRing R]
variable [NonUnitalNonAssocRing A] [NonUnitalNonAssocRing B] [NonUnitalNonAssocRing C]
variable [Module R A] [Module R B] [Module R C]
instance instNonUnitalSubringClass : NonUnitalSubringClass (NonUnitalSubalgebra R A) A :=
{ NonUnitalSubalgebra.instNonUnitalSubsemiringClass with
neg_mem := @fun _ x hx => neg_one_smul R x ▸ SMulMemClass.smul_mem _ hx }
/-- A non-unital subalgebra over a ring is also a `Subring`. -/
def toNonUnitalSubring (S : NonUnitalSubalgebra R A) : NonUnitalSubring A where
toNonUnitalSubsemiring := S.toNonUnitalSubsemiring
neg_mem' := neg_mem (s := S)
@[simp]
theorem mem_toNonUnitalSubring {S : NonUnitalSubalgebra R A} {x} :
x ∈ S.toNonUnitalSubring ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubring (S : NonUnitalSubalgebra R A) :
(↑S.toNonUnitalSubring : Set A) = S :=
rfl
theorem toNonUnitalSubring_injective :
Function.Injective (toNonUnitalSubring : NonUnitalSubalgebra R A → NonUnitalSubring A) :=
fun S T h => ext fun x => by rw [← mem_toNonUnitalSubring, ← mem_toNonUnitalSubring, h]
theorem toNonUnitalSubring_inj {S U : NonUnitalSubalgebra R A} :
S.toNonUnitalSubring = U.toNonUnitalSubring ↔ S = U :=
toNonUnitalSubring_injective.eq_iff
end NonUnitalNonAssocRing
section
/-! `NonUnitalSubalgebra`s inherit structure from their `NonUnitalSubsemiring` / `Semiring`
coercions. -/
instance toNonUnitalNonAssocSemiring [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A]
(S : NonUnitalSubalgebra R A) : NonUnitalNonAssocSemiring S :=
inferInstance
instance toNonUnitalSemiring [CommSemiring R] [NonUnitalSemiring A] [Module R A]
(S : NonUnitalSubalgebra R A) : NonUnitalSemiring S :=
inferInstance
instance toNonUnitalCommSemiring [CommSemiring R] [NonUnitalCommSemiring A] [Module R A]
(S : NonUnitalSubalgebra R A) : NonUnitalCommSemiring S :=
inferInstance
instance toNonUnitalNonAssocRing [CommRing R] [NonUnitalNonAssocRing A] [Module R A]
(S : NonUnitalSubalgebra R A) : NonUnitalNonAssocRing S :=
inferInstance
instance toNonUnitalRing [CommRing R] [NonUnitalRing A] [Module R A]
(S : NonUnitalSubalgebra R A) : NonUnitalRing S :=
inferInstance
instance toNonUnitalCommRing [CommRing R] [NonUnitalCommRing A] [Module R A]
(S : NonUnitalSubalgebra R A) : NonUnitalCommRing S :=
inferInstance
end
/-- The forgetful map from `NonUnitalSubalgebra` to `Submodule` as an `OrderEmbedding` -/
def toSubmodule' [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] :
NonUnitalSubalgebra R A ↪o Submodule R A where
toEmbedding :=
{ toFun := fun S => S.toSubmodule
inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h }
map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe
/-- The forgetful map from `NonUnitalSubalgebra` to `NonUnitalSubsemiring` as an
`OrderEmbedding` -/
def toNonUnitalSubsemiring' [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] :
NonUnitalSubalgebra R A ↪o NonUnitalSubsemiring A where
toEmbedding :=
{ toFun := fun S => S.toNonUnitalSubsemiring
inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h }
map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe
/-- The forgetful map from `NonUnitalSubalgebra` to `NonUnitalSubsemiring` as an
`OrderEmbedding` -/
def toNonUnitalSubring' [CommRing R] [NonUnitalNonAssocRing A] [Module R A] :
NonUnitalSubalgebra R A ↪o NonUnitalSubring A where
toEmbedding :=
{ toFun := fun S => S.toNonUnitalSubring
inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h }
map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [NonUnitalNonAssocSemiring C]
variable [Module R A] [Module R B] [Module R C]
variable {S : NonUnitalSubalgebra R A}
section
/-! ### `NonUnitalSubalgebra`s inherit structure from their `Submodule` coercions. -/
instance instModule' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=
SMulMemClass.toModule' _ R' R A S
instance instModule : Module R S :=
S.instModule'
instance instIsScalarTower' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] :
IsScalarTower R' R S :=
S.toSubmodule.isScalarTower
instance [IsScalarTower R A A] : IsScalarTower R S S where
smul_assoc r x y := Subtype.ext <| smul_assoc r (x : A) (y : A)
instance instSMulCommClass' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A]
[SMulCommClass R' R A] : SMulCommClass R' R S where
smul_comm r' r s := Subtype.ext <| smul_comm r' r (s : A)
instance instSMulCommClass [SMulCommClass R A A] : SMulCommClass R S S where
smul_comm r x y := Subtype.ext <| smul_comm r (x : A) (y : A)
instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=
⟨fun {c x} h =>
have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg ((↑) : S → A) h)
this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩
end
protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y :=
rfl
protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y :=
rfl
protected theorem coe_zero : ((0 : S) : A) = 0 :=
rfl
protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]
{S : NonUnitalSubalgebra R A} (x : S) : (↑(-x) : A) = -↑x :=
rfl
protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A]
{S : NonUnitalSubalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y :=
rfl
@[simp, norm_cast]
theorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :
↑(r • x) = r • (x : A) :=
rfl
protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=
ZeroMemClass.coe_eq_zero
@[simp]
theorem toNonUnitalSubsemiring_subtype :
NonUnitalSubsemiringClass.subtype S = NonUnitalSubalgebraClass.subtype (R := R) S :=
rfl
@[simp]
theorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A]
(S : NonUnitalSubalgebra R A) :
NonUnitalSubringClass.subtype S = NonUnitalSubalgebraClass.subtype (R := R) S :=
rfl
/-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal,
we define it as a `LinearEquiv` to avoid type equalities. -/
def toSubmoduleEquiv (S : NonUnitalSubalgebra R A) : S.toSubmodule ≃ₗ[R] S :=
LinearEquiv.ofEq _ _ rfl
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B]
/-- Transport a non-unital subalgebra via an algebra homomorphism. -/
def map (f : F) (S : NonUnitalSubalgebra R A) : NonUnitalSubalgebra R B :=
{ S.toNonUnitalSubsemiring.map (f : A →ₙ+* B) with
smul_mem' := fun r b hb => by
rcases hb with ⟨a, ha, rfl⟩
exact map_smulₛₗ f r a ▸ Set.mem_image_of_mem f (S.smul_mem' r ha) }
theorem map_mono {S₁ S₂ : NonUnitalSubalgebra R A} {f : F} :
S₁ ≤ S₂ → (map f S₁ : NonUnitalSubalgebra R B) ≤ map f S₂ :=
Set.image_subset f
theorem map_injective {f : F} (hf : Function.Injective f) :
Function.Injective (map f : NonUnitalSubalgebra R A → NonUnitalSubalgebra R B) :=
fun _S₁ _S₂ ih =>
ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih
@[simp]
theorem map_id (S : NonUnitalSubalgebra R A) : map (NonUnitalAlgHom.id R A) S = S :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (S : NonUnitalSubalgebra R A) (g : B →ₙₐ[R] C) (f : A →ₙₐ[R] B) :
(S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
@[simp]
theorem mem_map {S : NonUnitalSubalgebra R A} {f : F} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y :=
NonUnitalSubsemiring.mem_map
theorem map_toSubmodule {S : NonUnitalSubalgebra R A} {f : F} :
-- TODO: introduce a better coercion from `NonUnitalAlgHomClass` to `LinearMap`
(map f S).toSubmodule = Submodule.map (LinearMapClass.linearMap f) S.toSubmodule :=
SetLike.coe_injective rfl
theorem map_toNonUnitalSubsemiring {S : NonUnitalSubalgebra R A} {f : F} :
(map f S).toNonUnitalSubsemiring = S.toNonUnitalSubsemiring.map (f : A →ₙ+* B) :=
SetLike.coe_injective rfl
@[simp]
theorem coe_map (S : NonUnitalSubalgebra R A) (f : F) : (map f S : Set B) = f '' S :=
rfl
/-- Preimage of a non-unital subalgebra under an algebra homomorphism. -/
def comap (f : F) (S : NonUnitalSubalgebra R B) : NonUnitalSubalgebra R A :=
{ S.toNonUnitalSubsemiring.comap (f : A →ₙ+* B) with
smul_mem' := fun r a (ha : f a ∈ S) =>
show f (r • a) ∈ S from (map_smulₛₗ f r a).symm ▸ SMulMemClass.smul_mem r ha }
theorem map_le {S : NonUnitalSubalgebra R A} {f : F} {U : NonUnitalSubalgebra R B} :
map f S ≤ U ↔ S ≤ comap f U :=
Set.image_subset_iff
theorem gc_map_comap (f : F) :
GaloisConnection (map f : NonUnitalSubalgebra R A → NonUnitalSubalgebra R B) (comap f) :=
fun _ _ => map_le
@[simp]
theorem mem_comap (S : NonUnitalSubalgebra R B) (f : F) (x : A) : x ∈ comap f S ↔ f x ∈ S :=
Iff.rfl
@[simp, norm_cast]
theorem coe_comap (S : NonUnitalSubalgebra R B) (f : F) : (comap f S : Set A) = f ⁻¹' (S : Set B) :=
rfl
instance noZeroDivisors {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [NoZeroDivisors A]
[Module R A] (S : NonUnitalSubalgebra R A) : NoZeroDivisors S :=
NonUnitalSubsemiringClass.noZeroDivisors S
end NonUnitalSubalgebra
namespace Submodule
variable {R A : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A]
/-- A submodule closed under multiplication is a non-unital subalgebra. -/
def toNonUnitalSubalgebra (p : Submodule R A) (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) :
NonUnitalSubalgebra R A :=
{ p with
mul_mem' := h_mul _ _ }
@[simp]
theorem mem_toNonUnitalSubalgebra {p : Submodule R A} {h_mul} {x} :
x ∈ p.toNonUnitalSubalgebra h_mul ↔ x ∈ p :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubalgebra (p : Submodule R A) (h_mul) :
(p.toNonUnitalSubalgebra h_mul : Set A) = p :=
rfl
theorem toNonUnitalSubalgebra_mk (p : Submodule R A) hmul :
p.toNonUnitalSubalgebra hmul =
NonUnitalSubalgebra.mk ⟨⟨⟨p, p.add_mem⟩, p.zero_mem⟩, hmul _ _⟩ p.smul_mem' :=
rfl
@[simp]
theorem toNonUnitalSubalgebra_toSubmodule (p : Submodule R A) (h_mul) :
(p.toNonUnitalSubalgebra h_mul).toSubmodule = p :=
SetLike.coe_injective rfl
@[simp]
theorem _root_.NonUnitalSubalgebra.toSubmodule_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A) :
(S.toSubmodule.toNonUnitalSubalgebra fun _ _ => mul_mem (s := S)) = S :=
SetLike.coe_injective rfl
end Submodule
namespace NonUnitalAlgHom
variable {F : Type v'} {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [NonUnitalNonAssocSemiring B] [Module R B]
variable [NonUnitalNonAssocSemiring C] [Module R C] [FunLike F A B] [NonUnitalAlgHomClass F R A B]
/-- Range of an `NonUnitalAlgHom` as a non-unital subalgebra. -/
protected def range (φ : F) : NonUnitalSubalgebra R B where
toNonUnitalSubsemiring := NonUnitalRingHom.srange (φ : A →ₙ+* B)
smul_mem' := fun r a => by rintro ⟨a, rfl⟩; exact ⟨r • a, map_smul φ r a⟩
@[simp]
theorem mem_range (φ : F) {y : B} :
y ∈ (NonUnitalAlgHom.range φ : NonUnitalSubalgebra R B) ↔ ∃ x : A, φ x = y :=
NonUnitalRingHom.mem_srange
theorem mem_range_self (φ : F) (x : A) :
φ x ∈ (NonUnitalAlgHom.range φ : NonUnitalSubalgebra R B) :=
(NonUnitalAlgHom.mem_range φ).2 ⟨x, rfl⟩
@[simp]
theorem coe_range (φ : F) :
((NonUnitalAlgHom.range φ : NonUnitalSubalgebra R B) : Set B) = Set.range (φ : A → B) := by
ext
rw [SetLike.mem_coe, mem_range]
rfl
theorem range_comp (f : A →ₙₐ[R] B) (g : B →ₙₐ[R] C) :
NonUnitalAlgHom.range (g.comp f) = (NonUnitalAlgHom.range f).map g :=
SetLike.coe_injective (Set.range_comp g f)
theorem range_comp_le_range (f : A →ₙₐ[R] B) (g : B →ₙₐ[R] C) :
NonUnitalAlgHom.range (g.comp f) ≤ NonUnitalAlgHom.range g :=
SetLike.coe_mono (Set.range_comp_subset_range f g)
/-- Restrict the codomain of a non-unital algebra homomorphism. -/
def codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₙₐ[R] S :=
{ NonUnitalRingHom.codRestrict (f : A →ₙ+* B) S.toNonUnitalSubsemiring hf with
map_smul' := fun r a => Subtype.ext <| map_smul f r a }
@[simp]
theorem subtype_comp_codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x : A, f x ∈ S) :
(NonUnitalSubalgebraClass.subtype S).comp (NonUnitalAlgHom.codRestrict f S hf) = f :=
NonUnitalAlgHom.ext fun _ => rfl
@[simp]
theorem coe_codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :
↑(NonUnitalAlgHom.codRestrict f S hf x) = f x :=
rfl
theorem injective_codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x : A, f x ∈ S) :
Function.Injective (NonUnitalAlgHom.codRestrict f S hf) ↔ Function.Injective f :=
⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩
/-- Restrict the codomain of an `NonUnitalAlgHom` `f` to `f.range`.
This is the bundled version of `Set.rangeFactorization`. -/
abbrev rangeRestrict (f : F) : A →ₙₐ[R] (NonUnitalAlgHom.range f : NonUnitalSubalgebra R B) :=
NonUnitalAlgHom.codRestrict f (NonUnitalAlgHom.range f) (NonUnitalAlgHom.mem_range_self f)
/-- The equalizer of two non-unital `R`-algebra homomorphisms -/
def equalizer (ϕ ψ : F) : NonUnitalSubalgebra R A where
carrier := {a | (ϕ a : B) = ψ a}
zero_mem' := by rw [Set.mem_setOf_eq, map_zero, map_zero]
add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by
rw [Set.mem_setOf_eq, map_add, map_add, hx, hy]
mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by
rw [Set.mem_setOf_eq, map_mul, map_mul, hx, hy]
smul_mem' r x (hx : ϕ x = ψ x) := by rw [Set.mem_setOf_eq, map_smul, map_smul, hx]
@[simp]
theorem mem_equalizer (φ ψ : F) (x : A) :
x ∈ NonUnitalAlgHom.equalizer φ ψ ↔ φ x = ψ x :=
Iff.rfl
/-- The range of a morphism of algebras is a fintype, if the domain is a fintype.
Note that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/
instance fintypeRange [Fintype A] [DecidableEq B] (φ : F) :
Fintype (NonUnitalAlgHom.range φ) :=
Set.fintypeRange φ
end NonUnitalAlgHom
namespace NonUnitalAlgebra
variable {F : Type*} (R : Type u) {A : Type v} {B : Type w}
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [IsScalarTower R B B] [SMulCommClass R B B]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B]
/-- The minimal non-unital subalgebra that includes `s`. -/
def adjoin (s : Set A) : NonUnitalSubalgebra R A :=
{ Submodule.span R (NonUnitalSubsemiring.closure s : Set A) with
mul_mem' :=
@fun a b (ha : a ∈ Submodule.span R (NonUnitalSubsemiring.closure s : Set A))
(hb : b ∈ Submodule.span R (NonUnitalSubsemiring.closure s : Set A)) =>
show a * b ∈ Submodule.span R (NonUnitalSubsemiring.closure s : Set A) by
refine Submodule.span_induction ha ?_ ?_ ?_ ?_
· refine Submodule.span_induction hb ?_ ?_ ?_ ?_
· exact fun x (hx : x ∈ NonUnitalSubsemiring.closure s) y
(hy : y ∈ NonUnitalSubsemiring.closure s) => Submodule.subset_span (mul_mem hy hx)
· exact fun x _hx => (mul_zero x).symm ▸ Submodule.zero_mem _
· exact fun x y hx hy z hz => (mul_add z x y).symm ▸ add_mem (hx z hz) (hy z hz)
· exact fun r x hx y hy => (mul_smul_comm r y x).symm ▸ SMulMemClass.smul_mem r (hx y hy)
· exact (zero_mul b).symm ▸ Submodule.zero_mem _
· exact fun x y => (add_mul x y b).symm ▸ add_mem
· exact fun r x hx => (smul_mul_assoc r x b).symm ▸ SMulMemClass.smul_mem r hx }
theorem adjoin_toSubmodule (s : Set A) :
(adjoin R s).toSubmodule = Submodule.span R (NonUnitalSubsemiring.closure s : Set A) :=
rfl
@[aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_adjoin {s : Set A} : s ⊆ adjoin R s :=
NonUnitalSubsemiring.subset_closure.trans Submodule.subset_span
theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) :=
NonUnitalAlgebra.subset_adjoin R (Set.mem_singleton x)
variable {R}
/-- If some predicate holds for all `x ∈ (s : Set A)` and this predicate is closed under the
`algebraMap`, addition, multiplication and star operations, then it holds for `a ∈ adjoin R s`. -/
@[elab_as_elim]
theorem adjoin_induction {s : Set A} {p : A → Prop} {a : A} (h : a ∈ adjoin R s)
(mem : ∀ x ∈ s, p x) (add : ∀ x y, p x → p y → p (x + y)) (zero : p 0)
(mul : ∀ x y, p x → p y → p (x * y)) (smul : ∀ (r : R) x, p x → p (r • x)) : p a :=
Submodule.span_induction h
(fun _a ha => NonUnitalSubsemiring.closure_induction ha mem zero add mul) zero add smul
@[elab_as_elim]
theorem adjoin_induction₂ {s : Set A} {p : A → A → Prop} {a b : A} (ha : a ∈ adjoin R s)
(hb : b ∈ adjoin R s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ y, p 0 y)
(H0_right : ∀ x, p x 0) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y)
(Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂))
(Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y)
(Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂))
(Hsmul_left : ∀ (r : R) x y, p x y → p (r • x) y)
(Hsmul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b :=
Submodule.span_induction₂ ha hb
(fun _x hx _y hy =>
NonUnitalSubsemiring.closure_induction₂ hx hy Hs H0_left H0_right Hadd_left Hadd_right
Hmul_left Hmul_right)
H0_left H0_right Hadd_left Hadd_right Hsmul_left Hsmul_right
/-- The difference with `NonUnitalAlgebra.adjoin_induction` is that this acts on the subtype. -/
@[elab_as_elim]
lemma adjoin_induction_subtype {s : Set A} {p : adjoin R s → Prop} (a : adjoin R s)
(mem : ∀ x (h : x ∈ s), p ⟨x, subset_adjoin R h⟩)
(add : ∀ x y, p x → p y → p (x + y)) (zero : p 0)
(mul : ∀ x y, p x → p y → p (x * y)) (smul : ∀ (r : R) x, p x → p (r • x)) : p a :=
Subtype.recOn a fun b hb => by
refine Exists.elim ?_ (fun (hb : b ∈ adjoin R s) (hc : p ⟨b, hb⟩) => hc)
refine adjoin_induction hb ?_ ?_ ?_ ?_ ?_
· exact fun x hx => ⟨subset_adjoin R hx, mem x hx⟩
· exact fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy =>
⟨add_mem hx' hy', add _ _ hx hy⟩
· exact ⟨_, zero⟩
· exact fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy =>
⟨mul_mem hx' hy', mul _ _ hx hy⟩
· exact fun r x hx => Exists.elim hx fun hx' hx =>
⟨SMulMemClass.smul_mem r hx', smul r _ hx⟩
/-- A dependent version of `NonUnitalAlgebra.adjoin_induction`. -/
theorem adjoin_induction' {s : Set A} {p : ∀ x, x ∈ adjoin R s → Prop}
(mem : ∀ (x) (h : x ∈ s), p x (subset_adjoin R h))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem ‹_› ‹_›))
(zero : p 0 (zero_mem _))
(mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem ‹_› ‹_›))
(smul : ∀ (r : R) (x hx), p x hx → p (r • x) (SMulMemClass.smul_mem _ ‹_›))
{a} (ha : a ∈ adjoin R s) : p a ha :=
adjoin_induction_subtype ⟨a, ha⟩ (p := fun x ↦ p x.1 x.2) mem (fun x y ↦ add x.1 x.2 y.1 y.2)
zero (fun x y ↦ mul x.1 x.2 y.1 y.2) (fun r x ↦ smul r x.1 x.2)
protected theorem gc : GaloisConnection (adjoin R : Set A → NonUnitalSubalgebra R A) (↑) :=
fun s S =>
⟨fun H => (NonUnitalSubsemiring.subset_closure.trans Submodule.subset_span).trans H,
fun H => show Submodule.span R _ ≤ S.toSubmodule from Submodule.span_le.mpr <|
show NonUnitalSubsemiring.closure s ≤ S.toNonUnitalSubsemiring from
NonUnitalSubsemiring.closure_le.2 H⟩
/-- Galois insertion between `adjoin` and `Subtype.val`. -/
protected def gi : GaloisInsertion (adjoin R : Set A → NonUnitalSubalgebra R A) (↑) where
choice s hs := (adjoin R s).copy s <| le_antisymm (NonUnitalAlgebra.gc.le_u_l s) hs
gc := NonUnitalAlgebra.gc
le_l_u S := (NonUnitalAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl
choice_eq _ _ := NonUnitalSubalgebra.copy_eq _ _ _
instance : CompleteLattice (NonUnitalSubalgebra R A) :=
GaloisInsertion.liftCompleteLattice NonUnitalAlgebra.gi
theorem adjoin_le {S : NonUnitalSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S :=
NonUnitalAlgebra.gc.l_le hs
theorem adjoin_le_iff {S : NonUnitalSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S :=
NonUnitalAlgebra.gc _ _
theorem adjoin_union (s t : Set A) : adjoin R (s ∪ t) = adjoin R s ⊔ adjoin R t :=
(NonUnitalAlgebra.gc : GaloisConnection _ ((↑) : NonUnitalSubalgebra R A → Set A)).l_sup
lemma adjoin_eq (s : NonUnitalSubalgebra R A) : adjoin R (s : Set A) = s :=
le_antisymm (adjoin_le le_rfl) (subset_adjoin R)
open Submodule in
lemma adjoin_eq_span (s : Set A) : (adjoin R s).toSubmodule = span R (Subsemigroup.closure s) := by
apply le_antisymm
· intro x hx
induction hx using adjoin_induction' with
| mem x hx => exact subset_span <| Subsemigroup.subset_closure hx
| add x _ y _ hpx hpy => exact add_mem hpx hpy
| zero => exact zero_mem _
| mul x _ y _ hpx hpy =>
apply span_induction₂ hpx hpy ?Hs (by simp) (by simp) ?Hadd_l ?Hadd_r ?Hsmul_l ?Hsmul_r
case Hs => exact fun x hx y hy ↦ subset_span <| mul_mem hx hy
case Hadd_l => exact fun x y z hxz hyz ↦ by simpa [add_mul] using add_mem hxz hyz
case Hadd_r => exact fun x y z hxz hyz ↦ by simpa [mul_add] using add_mem hxz hyz
case Hsmul_l => exact fun r x y hxy ↦ by simpa [smul_mul_assoc] using smul_mem _ _ hxy
case Hsmul_r => exact fun r x y hxy ↦ by simpa [mul_smul_comm] using smul_mem _ _ hxy
| smul r x _ hpx => exact smul_mem _ _ hpx
· apply span_le.2 _
show Subsemigroup.closure s ≤ (adjoin R s).toSubsemigroup
exact Subsemigroup.closure_le.2 (subset_adjoin R)
@[simp]
lemma span_eq_toSubmodule (s : NonUnitalSubalgebra R A) :
Submodule.span R (s : Set A) = s.toSubmodule := by
simp [SetLike.ext'_iff, Submodule.coe_span_eq_self]
variable (R A)
@[simp]
theorem adjoin_empty : adjoin R (∅ : Set A) = ⊥ :=
show adjoin R ⊥ = ⊥ by apply GaloisConnection.l_bot; exact NonUnitalAlgebra.gc
@[simp]
theorem adjoin_univ : adjoin R (Set.univ : Set A) = ⊤ :=
eq_top_iff.2 fun _x hx => subset_adjoin R hx
open NonUnitalSubalgebra in
lemma _root_.NonUnitalAlgHom.map_adjoin (f : F) (s : Set A) :
map f (adjoin R s) = adjoin R (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) NonUnitalAlgebra.gi.gc
NonUnitalAlgebra.gi.gc fun _t => rfl
open NonUnitalSubalgebra in
@[simp]
lemma _root_.NonUnitalAlgHom.map_adjoin_singleton (f : F) (x : A) :
map f (adjoin R {x}) = adjoin R {f x} := by
simp [NonUnitalAlgHom.map_adjoin]
variable {R A}
@[simp]
theorem coe_top : (↑(⊤ : NonUnitalSubalgebra R A) : Set A) = Set.univ :=
rfl
@[simp]
theorem mem_top {x : A} : x ∈ (⊤ : NonUnitalSubalgebra R A) :=
Set.mem_univ x
@[simp]
theorem top_toSubmodule : (⊤ : NonUnitalSubalgebra R A).toSubmodule = ⊤ :=
rfl
@[simp]
theorem top_toNonUnitalSubsemiring : (⊤ : NonUnitalSubalgebra R A).toNonUnitalSubsemiring = ⊤ :=
rfl
@[simp]
theorem top_toSubring {R A : Type*} [CommRing R] [NonUnitalNonAssocRing A] [Module R A]
[IsScalarTower R A A] [SMulCommClass R A A] :
(⊤ : NonUnitalSubalgebra R A).toNonUnitalSubring = ⊤ :=
rfl
@[simp]
theorem toSubmodule_eq_top {S : NonUnitalSubalgebra R A} : S.toSubmodule = ⊤ ↔ S = ⊤ :=
NonUnitalSubalgebra.toSubmodule'.injective.eq_iff' top_toSubmodule
@[simp]
theorem toNonUnitalSubsemiring_eq_top {S : NonUnitalSubalgebra R A} :
S.toNonUnitalSubsemiring = ⊤ ↔ S = ⊤ :=
NonUnitalSubalgebra.toNonUnitalSubsemiring_injective.eq_iff' top_toNonUnitalSubsemiring
@[simp]
theorem to_subring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A]
{S : NonUnitalSubalgebra R A} : S.toNonUnitalSubring = ⊤ ↔ S = ⊤ :=
NonUnitalSubalgebra.toNonUnitalSubring_injective.eq_iff' top_toSubring
theorem mem_sup_left {S T : NonUnitalSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_left
theorem mem_sup_right {S T : NonUnitalSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_right
theorem mul_mem_sup {S T : NonUnitalSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) :
x * y ∈ S ⊔ T :=
mul_mem (mem_sup_left hx) (mem_sup_right hy)
theorem map_sup (f : F) (S T : NonUnitalSubalgebra R A) :
((S ⊔ T).map f : NonUnitalSubalgebra R B) = S.map f ⊔ T.map f :=
(NonUnitalSubalgebra.gc_map_comap f).l_sup
@[simp, norm_cast]
theorem coe_inf (S T : NonUnitalSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T :=
rfl
@[simp]
theorem mem_inf {S T : NonUnitalSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T :=
Iff.rfl
@[simp]
theorem inf_toSubmodule (S T : NonUnitalSubalgebra R A) :
(S ⊓ T).toSubmodule = S.toSubmodule ⊓ T.toSubmodule :=
rfl
@[simp]
theorem inf_toNonUnitalSubsemiring (S T : NonUnitalSubalgebra R A) :
(S ⊓ T).toNonUnitalSubsemiring = S.toNonUnitalSubsemiring ⊓ T.toNonUnitalSubsemiring :=
rfl
@[simp, norm_cast]
theorem coe_sInf (S : Set (NonUnitalSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=
sInf_image
theorem mem_sInf {S : Set (NonUnitalSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by
simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]
@[simp]
theorem sInf_toSubmodule (S : Set (NonUnitalSubalgebra R A)) :
(sInf S).toSubmodule = sInf (NonUnitalSubalgebra.toSubmodule '' S) :=
SetLike.coe_injective <| by simp
@[simp]
theorem sInf_toNonUnitalSubsemiring (S : Set (NonUnitalSubalgebra R A)) :
(sInf S).toNonUnitalSubsemiring = sInf (NonUnitalSubalgebra.toNonUnitalSubsemiring '' S) :=
SetLike.coe_injective <| by simp
@[simp, norm_cast]
| Mathlib/Algebra/Algebra/NonUnitalSubalgebra.lean | 761 | 762 | theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalSubalgebra R A} :
(↑(⨅ i, S i) : Set A) = ⋂ i, S i := by | simp [iInf]
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
-/
import Mathlib.Init.Function
import Mathlib.Init.Order.Defs
#align_import data.bool.basic from "leanprover-community/mathlib"@"c4658a649d216f57e99621708b09dcb3dcccbd23"
/-!
# Booleans
This file proves various trivial lemmas about booleans and their
relation to decidable propositions.
## Tags
bool, boolean, Bool, De Morgan
-/
namespace Bool
@[deprecated (since := "2024-06-07")] alias decide_True := decide_true_eq_true
#align bool.to_bool_true decide_true_eq_true
@[deprecated (since := "2024-06-07")] alias decide_False := decide_false_eq_false
#align bool.to_bool_false decide_false_eq_false
#align bool.to_bool_coe Bool.decide_coe
@[deprecated (since := "2024-06-07")] alias coe_decide := decide_eq_true_iff
#align bool.coe_to_bool decide_eq_true_iff
@[deprecated decide_eq_true_iff (since := "2024-06-07")]
alias of_decide_iff := decide_eq_true_iff
#align bool.of_to_bool_iff decide_eq_true_iff
#align bool.tt_eq_to_bool_iff true_eq_decide_iff
#align bool.ff_eq_to_bool_iff false_eq_decide_iff
@[deprecated (since := "2024-06-07")] alias decide_not := decide_not
#align bool.to_bool_not decide_not
#align bool.to_bool_and Bool.decide_and
#align bool.to_bool_or Bool.decide_or
#align bool.to_bool_eq decide_eq_decide
@[deprecated (since := "2024-06-07")] alias not_false' := false_ne_true
#align bool.not_ff Bool.false_ne_true
@[deprecated (since := "2024-06-07")] alias eq_iff_eq_true_iff := eq_iff_iff
#align bool.default_bool Bool.default_bool
theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp
#align bool.dichotomy Bool.dichotomy
theorem forall_bool' {p : Bool → Prop} (b : Bool) : (∀ x, p x) ↔ p b ∧ p !b :=
⟨fun h ↦ ⟨h _, h _⟩, fun ⟨h₁, h₂⟩ x ↦ by cases b <;> cases x <;> assumption⟩
@[simp]
theorem forall_bool {p : Bool → Prop} : (∀ b, p b) ↔ p false ∧ p true :=
forall_bool' false
#align bool.forall_bool Bool.forall_bool
theorem exists_bool' {p : Bool → Prop} (b : Bool) : (∃ x, p x) ↔ p b ∨ p !b :=
⟨fun ⟨x, hx⟩ ↦ by cases x <;> cases b <;> first | exact .inl ‹_› | exact .inr ‹_›,
fun h ↦ by cases h <;> exact ⟨_, ‹_›⟩⟩
@[simp]
theorem exists_bool {p : Bool → Prop} : (∃ b, p b) ↔ p false ∨ p true :=
exists_bool' false
#align bool.exists_bool Bool.exists_bool
#align bool.decidable_forall_bool Bool.instDecidableForallOfDecidablePred
#align bool.decidable_exists_bool Bool.instDecidableExistsOfDecidablePred
#align bool.cond_eq_ite Bool.cond_eq_ite
#align bool.cond_to_bool Bool.cond_decide
#align bool.cond_bnot Bool.cond_not
theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true
#align bool.bnot_ne_id Bool.not_ne_id
#align bool.coe_bool_iff Bool.coe_iff_coe
@[deprecated (since := "2024-06-07")] alias eq_true_of_ne_false := eq_true_of_ne_false
#align bool.eq_tt_of_ne_ff eq_true_of_ne_false
@[deprecated (since := "2024-06-07")] alias eq_false_of_ne_true := eq_false_of_ne_true
#align bool.eq_ff_of_ne_tt eq_true_of_ne_false
#align bool.bor_comm Bool.or_comm
#align bool.bor_assoc Bool.or_assoc
#align bool.bor_left_comm Bool.or_left_comm
theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H]
#align bool.bor_inl Bool.or_inl
theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H]
#align bool.bor_inr Bool.or_inr
#align bool.band_comm Bool.and_comm
#align bool.band_assoc Bool.and_assoc
#align bool.band_left_comm Bool.and_left_comm
theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide
#align bool.band_elim_left Bool.and_elim_left
theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide
#align bool.band_intro Bool.and_intro
theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide
#align bool.band_elim_right Bool.and_elim_right
#align bool.band_bor_distrib_left Bool.and_or_distrib_left
#align bool.band_bor_distrib_right Bool.and_or_distrib_right
#align bool.bor_band_distrib_left Bool.or_and_distrib_left
#align bool.bor_band_distrib_right Bool.or_and_distrib_right
#align bool.bnot_ff Bool.not_false
#align bool.bnot_tt Bool.not_true
lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide
#align bool.eq_bnot_iff Bool.eq_not_iff
lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide
#align bool.bnot_eq_iff Bool.not_eq_iff
#align bool.not_eq_bnot Bool.not_eq_not
#align bool.bnot_not_eq Bool.not_not_eq
theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b :=
not_eq_not
#align bool.ne_bnot Bool.ne_not
@[deprecated (since := "2024-06-07")] alias not_ne := not_not_eq
#align bool.bnot_ne Bool.not_not_eq
lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide
#align bool.bnot_ne_self Bool.not_ne_self
lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide
#align bool.self_ne_bnot Bool.self_ne_not
lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide
#align bool.eq_or_eq_bnot Bool.eq_or_eq_not
-- Porting note: naming issue again: these two `not` are different.
theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp
#align bool.bnot_iff_not Bool.not_iff_not
theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by
cases a <;> decide
#align bool.eq_tt_of_bnot_eq_ff Bool.eq_true_of_not_eq_false'
theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by
cases a <;> decide
#align bool.eq_ff_of_bnot_eq_tt Bool.eq_false_of_not_eq_true'
#align bool.band_bnot_self Bool.and_not_self
#align bool.bnot_band_self Bool.not_and_self
#align bool.bor_bnot_self Bool.or_not_self
#align bool.bnot_bor_self Bool.not_or_self
| Mathlib/Data/Bool/Basic.lean | 167 | 167 | theorem bne_eq_xor : bne = xor := by | funext a b; revert a b; decide
|
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Group.GeometryOfNumbers
import Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
#align_import number_theory.number_field.canonical_embedding from "leanprover-community/mathlib"@"60da01b41bbe4206f05d34fd70c8dd7498717a30"
/-!
# Convex Bodies
The file contains the definitions of several convex bodies lying in the space `ℝ^r₁ × ℂ^r₂`
associated to a number field of signature `K` and proves several existence theorems by applying
*Minkowski Convex Body Theorem* to those.
## Main definitions and results
* `NumberField.mixedEmbedding.convexBodyLT`: The set of points `x` such that `‖x w‖ < f w` for all
infinite places `w` with `f : InfinitePlace K → ℝ≥0`.
* `NumberField.mixedEmbedding.convexBodySum`: The set of points `x` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_lt`: Let `I` be a fractional ideal of `K`.
Assume that `f` is such that `minkowskiBound K I < volume (convexBodyLT K f)`, then there exists a
nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`.
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_of_norm_le`: Let `I` be a fractional ideal
of `K`. Assume that `B` is such that `minkowskiBound K I < volume (convexBodySum K B)` (see
`convexBodySum_volume` for the computation of this volume), then there exists a nonzero algebraic
number `a` in `I` such that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.mixedEmbedding
open NumberField NumberField.InfinitePlace FiniteDimensional
/-- The space `ℝ^r₁ × ℂ^r₂` with `(r₁, r₂)` the signature of `K`. -/
local notation "E" K =>
({w : InfinitePlace K // IsReal w} → ℝ) × ({w : InfinitePlace K // IsComplex w} → ℂ)
section convexBodyLT
open Metric NNReal
variable (f : InfinitePlace K → ℝ≥0)
/-- The convex body defined by `f`: the set of points `x : E` such that `‖x w‖ < f w` for all
infinite places `w`. -/
abbrev convexBodyLT : Set (E K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } => ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } => ball 0 (f w)))
theorem convexBodyLT_mem {x : K} :
mixedEmbedding K x ∈ (convexBodyLT K f) ↔ ∀ w : InfinitePlace K, w x < f w := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, mem_ball_zero_iff, Pi.ringHom_apply, ← Complex.norm_real,
embedding_of_isReal_apply, Subtype.forall, ← forall₂_or_left, ← not_isReal_iff_isComplex, em,
forall_true_left, norm_embedding_eq]
theorem convexBodyLT_neg_mem (x : E K) (hx : x ∈ (convexBodyLT K f)) :
-x ∈ (convexBodyLT K f) := by
simp only [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
Prod.snd_neg, Complex.norm_eq_abs] at hx ⊢
exact hx
theorem convexBodyLT_convex : Convex ℝ (convexBodyLT K f) :=
Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => convex_ball _ _))
open Fintype MeasureTheory MeasureTheory.Measure ENNReal
open scoped Classical
variable [NumberField K]
instance : IsAddHaarMeasure (volume : Measure (E K)) := prod.instIsAddHaarMeasure volume volume
instance : NoAtoms (volume : Measure (E K)) := by
obtain ⟨w⟩ := (inferInstance : Nonempty (InfinitePlace K))
by_cases hw : IsReal w
· exact @prod.instNoAtoms_fst _ _ _ _ volume volume _ (pi_noAtoms ⟨w, hw⟩)
· exact @prod.instNoAtoms_snd _ _ _ _ volume volume _
(pi_noAtoms ⟨w, not_isReal_iff_isComplex.mp hw⟩)
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT`. -/
noncomputable abbrev convexBodyLTFactor : ℝ≥0 :=
(2 : ℝ≥0) ^ NrRealPlaces K * NNReal.pi ^ NrComplexPlaces K
theorem convexBodyLTFactor_ne_zero : convexBodyLTFactor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLTFactor : 1 ≤ convexBodyLTFactor K :=
one_le_mul₀ (one_le_pow_of_one_le one_le_two _)
(one_le_pow_of_one_le (le_trans one_le_two Real.two_le_pi) _)
/-- The volume of `(ConvexBodyLt K f)` where `convexBodyLT K f` is the set of points `x`
such that `‖x w‖ < f w` for all infinite places `w`. -/
theorem convexBodyLT_volume :
volume (convexBodyLT K f) = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
∏ x : {w // InfinitePlace.IsComplex w}, ENNReal.ofReal (f x.val) ^ 2 * NNReal.pi := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball, Complex.volume_ball]
_ = ((2:ℝ≥0) ^ NrRealPlaces K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val)))
* ((∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) *
NNReal.pi ^ NrComplexPlaces K) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_univ, ofReal_ofNat, ofReal_coe_nnreal, coe_ofNat]
_ = (convexBodyLTFactor K) * ((∏ x : {w // InfinitePlace.IsReal w}, .ofReal (f x.val)) *
(∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2)) := by
simp_rw [convexBodyLTFactor, coe_mul, ENNReal.coe_pow]
ring
_ = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
simp_rw [mult, pow_ite, pow_one, Finset.prod_ite, ofReal_coe_nnreal, not_isReal_iff_isComplex,
coe_mul, coe_finset_prod, ENNReal.coe_pow]
congr 2
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞))).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞) ^ 2)).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
variable {f}
/-- This is a technical result: quite often, we want to impose conditions at all infinite places
but one and choose the value at the remaining place so that we can apply
`exists_ne_zero_mem_ringOfIntegers_lt`. -/
theorem adjust_f {w₁ : InfinitePlace K} (B : ℝ≥0) (hf : ∀ w, w ≠ w₁ → f w ≠ 0) :
∃ g : InfinitePlace K → ℝ≥0, (∀ w, w ≠ w₁ → g w = f w) ∧ ∏ w, (g w) ^ mult w = B := by
let S := ∏ w ∈ Finset.univ.erase w₁, (f w) ^ mult w
refine ⟨Function.update f w₁ ((B * S⁻¹) ^ (mult w₁ : ℝ)⁻¹), ?_, ?_⟩
· exact fun w hw => Function.update_noteq hw _ f
· rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ w₁), Function.update_same,
Finset.prod_congr rfl fun w hw => by rw [Function.update_noteq (Finset.ne_of_mem_erase hw)],
← NNReal.rpow_natCast, ← NNReal.rpow_mul, inv_mul_cancel, NNReal.rpow_one, mul_assoc,
inv_mul_cancel, mul_one]
· rw [Finset.prod_ne_zero_iff]
exact fun w hw => pow_ne_zero _ (hf w (Finset.ne_of_mem_erase hw))
· rw [mult]; split_ifs <;> norm_num
end convexBodyLT
section convexBodyLT'
open Metric ENNReal NNReal
open scoped Classical
variable (f : InfinitePlace K → ℝ≥0) (w₀ : {w : InfinitePlace K // IsComplex w})
/-- A version of `convexBodyLT` with an additional condition at a fixed complex place. This is
needed to ensure the element constructed is not real, see for example
`exists_primitive_element_lt_of_isComplex`.
-/
abbrev convexBodyLT' : Set (E K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } ↦ ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } ↦
if w = w₀ then {x | |x.re| < 1 ∧ |x.im| < (f w : ℝ) ^ 2} else ball 0 (f w)))
theorem convexBodyLT'_mem {x : K} :
mixedEmbedding K x ∈ convexBodyLT' K f w₀ ↔
(∀ w : InfinitePlace K, w ≠ w₀ → w x < f w) ∧
|(w₀.val.embedding x).re| < 1 ∧ |(w₀.val.embedding x).im| < (f w₀: ℝ) ^ 2 := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, Pi.ringHom_apply, apply_ite, mem_ball_zero_iff, ← Complex.norm_real,
embedding_of_isReal_apply, norm_embedding_eq, Subtype.forall, Set.mem_setOf_eq]
refine ⟨fun ⟨h₁, h₂⟩ ↦ ⟨fun w h_ne ↦ ?_, ?_⟩, fun ⟨h₁, h₂⟩ ↦ ⟨fun w hw ↦ ?_, fun w hw ↦ ?_⟩⟩
· by_cases hw : IsReal w
· exact norm_embedding_eq w _ ▸ h₁ w hw
· specialize h₂ w (not_isReal_iff_isComplex.mp hw)
rwa [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)] at h₂
· simpa [if_true] using h₂ w₀.val w₀.prop
· exact h₁ w (ne_of_isReal_isComplex hw w₀.prop)
· by_cases h_ne : w = w₀
· simpa [h_ne]
· rw [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)]
exact h₁ w h_ne
theorem convexBodyLT'_neg_mem (x : E K) (hx : x ∈ convexBodyLT' K f w₀) :
-x ∈ convexBodyLT' K f w₀ := by
simp [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
Prod.snd_neg, Complex.norm_eq_abs] at hx ⊢
convert hx using 3
split_ifs <;> simp
theorem convexBodyLT'_convex : Convex ℝ (convexBodyLT' K f w₀) := by
refine Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => ?_))
split_ifs
· simp_rw [abs_lt]
refine Convex.inter ((convex_halfspace_re_gt _).inter (convex_halfspace_re_lt _))
((convex_halfspace_im_gt _).inter (convex_halfspace_im_lt _))
· exact convex_ball _ _
open MeasureTheory MeasureTheory.Measure
open scoped Classical
variable [NumberField K]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT'`. -/
noncomputable abbrev convexBodyLT'Factor : ℝ≥0 :=
(2 : ℝ≥0) ^ (NrRealPlaces K + 2) * NNReal.pi ^ (NrComplexPlaces K - 1)
theorem convexBodyLT'Factor_ne_zero : convexBodyLT'Factor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLT'Factor : 1 ≤ convexBodyLT'Factor K :=
one_le_mul₀ (one_le_pow_of_one_le one_le_two _)
(one_le_pow_of_one_le (le_trans one_le_two Real.two_le_pi) _)
theorem convexBodyLT'_volume :
volume (convexBodyLT' K f w₀) = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
have vol_box : ∀ B : ℝ≥0, volume {x : ℂ | |x.re| < 1 ∧ |x.im| < B^2} = 4*B^2 := by
intro B
rw [← (Complex.volume_preserving_equiv_real_prod.symm).measure_preimage]
· simp_rw [Set.preimage_setOf_eq, Complex.measurableEquivRealProd_symm_apply]
rw [show {a : ℝ × ℝ | |a.1| < 1 ∧ |a.2| < B ^ 2} =
Set.Ioo (-1:ℝ) (1:ℝ) ×ˢ Set.Ioo (- (B:ℝ) ^ 2) ((B:ℝ) ^ 2) by
ext; simp_rw [Set.mem_setOf_eq, Set.mem_prod, Set.mem_Ioo, abs_lt]]
simp_rw [volume_eq_prod, prod_prod, Real.volume_Ioo, sub_neg_eq_add, one_add_one_eq_two,
← two_mul, ofReal_mul zero_le_two, ofReal_pow (coe_nonneg B), ofReal_ofNat,
ofReal_coe_nnreal, ← mul_assoc, show (2:ℝ≥0∞) * 2 = 4 by norm_num]
· refine MeasurableSet.inter ?_ ?_
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_re) measurable_const
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_im) measurable_const
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2 * pi) *
(4 * (f w₀) ^ 2)) := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball]
rw [← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)]
congr 2
· refine Finset.prod_congr rfl (fun w' hw' ↦ ?_)
rw [if_neg (Finset.ne_of_mem_erase hw'), Complex.volume_ball]
· simpa only [ite_true] using vol_box (f w₀)
_ = ((2 : ℝ≥0) ^ NrRealPlaces K *
(∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2) *
↑pi ^ (NrComplexPlaces K - 1) * (4 * (f w₀) ^ 2)) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, ofReal_ofNat,
ofReal_coe_nnreal, coe_ofNat]
_ = convexBodyLT'Factor K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))
* (∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) := by
rw [show (4 : ℝ≥0∞) = (2 : ℝ≥0) ^ 2 by norm_num, convexBodyLT'Factor, pow_add,
← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀), ofReal_coe_nnreal]
simp_rw [coe_mul, ENNReal.coe_pow]
ring
_ = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
simp_rw [mult, pow_ite, pow_one, Finset.prod_ite, ofReal_coe_nnreal, not_isReal_iff_isComplex,
coe_mul, coe_finset_prod, ENNReal.coe_pow, mul_assoc]
congr 3
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞))).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞) ^ 2)).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
end convexBodyLT'
section convexBodySum
open ENNReal MeasureTheory Fintype
open scoped Real Classical NNReal
variable [NumberField K] (B : ℝ)
variable {K}
/-- The function that sends `x : ({w // IsReal w} → ℝ) × ({w // IsComplex w} → ℂ)` to
`∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖`. It defines a norm and it used to define `convexBodySum`. -/
noncomputable abbrev convexBodySumFun (x : E K) : ℝ := ∑ w, mult w * normAtPlace w x
theorem convexBodySumFun_apply (x : E K) :
convexBodySumFun x = ∑ w, mult w * normAtPlace w x := rfl
theorem convexBodySumFun_apply' (x : E K) :
convexBodySumFun x = ∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖ := by
simp_rw [convexBodySumFun_apply, ← Finset.sum_add_sum_compl {w | IsReal w}.toFinset,
Set.toFinset_setOf, Finset.compl_filter, not_isReal_iff_isComplex, ← Finset.subtype_univ,
← Finset.univ.sum_subtype_eq_sum_filter, Finset.mul_sum]
congr
· ext w
rw [mult, if_pos w.prop, normAtPlace_apply_isReal, Nat.cast_one, one_mul]
· ext w
rw [mult, if_neg (not_isReal_iff_isComplex.mpr w.prop), normAtPlace_apply_isComplex,
Nat.cast_ofNat]
theorem convexBodySumFun_nonneg (x : E K) :
0 ≤ convexBodySumFun x :=
Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _))
theorem convexBodySumFun_neg (x : E K) :
convexBodySumFun (- x) = convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_neg]
theorem convexBodySumFun_add_le (x y : E K) :
convexBodySumFun (x + y) ≤ convexBodySumFun x + convexBodySumFun y := by
simp_rw [convexBodySumFun, ← Finset.sum_add_distrib, ← mul_add]
exact Finset.sum_le_sum
fun _ _ ↦ mul_le_mul_of_nonneg_left (normAtPlace_add_le _ x y) (Nat.cast_pos.mpr mult_pos).le
theorem convexBodySumFun_smul (c : ℝ) (x : E K) :
convexBodySumFun (c • x) = |c| * convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_smul, ← mul_assoc, mul_comm, Finset.mul_sum, mul_assoc]
theorem convexBodySumFun_eq_zero_iff (x : E K) :
convexBodySumFun x = 0 ↔ x = 0 := by
rw [← normAtPlace_eq_zero, convexBodySumFun, Finset.sum_eq_zero_iff_of_nonneg fun _ _ =>
mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)]
conv =>
enter [1, w, hw]
rw [mul_left_mem_nonZeroDivisors_eq_zero_iff
(mem_nonZeroDivisors_iff_ne_zero.mpr <| Nat.cast_ne_zero.mpr mult_ne_zero)]
simp_rw [Finset.mem_univ, true_implies]
theorem norm_le_convexBodySumFun (x : E K) : ‖x‖ ≤ convexBodySumFun x := by
rw [norm_eq_sup'_normAtPlace]
refine (Finset.sup'_le_iff _ _).mpr fun w _ ↦ ?_
rw [convexBodySumFun_apply, ← Finset.univ.add_sum_erase _ (Finset.mem_univ w)]
refine le_add_of_le_of_nonneg ?_ ?_
· exact le_mul_of_one_le_left (normAtPlace_nonneg w x) one_le_mult
· exact Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le
(normAtPlace_nonneg _ _))
variable (K)
theorem convexBodySumFun_continuous :
Continuous (convexBodySumFun : (E K) → ℝ) := by
refine continuous_finset_sum Finset.univ fun w ↦ ?_
obtain hw | hw := isReal_or_isComplex w
all_goals
· simp only [normAtPlace_apply_isReal, normAtPlace_apply_isComplex, hw]
fun_prop
/-- The convex body equal to the set of points `x : E` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`. -/
abbrev convexBodySum : Set (E K) := { x | convexBodySumFun x ≤ B }
theorem convexBodySum_volume_eq_zero_of_le_zero {B} (hB : B ≤ 0) :
volume (convexBodySum K B) = 0 := by
obtain hB | hB := lt_or_eq_of_le hB
· suffices convexBodySum K B = ∅ by rw [this, measure_empty]
ext x
refine ⟨fun hx => ?_, fun h => h.elim⟩
rw [Set.mem_setOf] at hx
linarith [convexBodySumFun_nonneg x]
· suffices convexBodySum K B = { 0 } by rw [this, measure_singleton]
ext
rw [convexBodySum, Set.mem_setOf_eq, Set.mem_singleton_iff, hB, ← convexBodySumFun_eq_zero_iff]
exact (convexBodySumFun_nonneg _).le_iff_eq
theorem convexBodySum_mem {x : K} :
mixedEmbedding K x ∈ (convexBodySum K B) ↔
∑ w : InfinitePlace K, (mult w) * w.val x ≤ B := by
simp_rw [Set.mem_setOf_eq, convexBodySumFun, normAtPlace_apply]
rfl
theorem convexBodySum_neg_mem {x : E K} (hx : x ∈ (convexBodySum K B)) :
-x ∈ (convexBodySum K B) := by
rw [Set.mem_setOf, convexBodySumFun_neg]
exact hx
theorem convexBodySum_convex : Convex ℝ (convexBodySum K B) := by
refine Convex_subadditive_le (fun _ _ => convexBodySumFun_add_le _ _) (fun c x h => ?_) B
convert le_of_eq (convexBodySumFun_smul c x)
exact (abs_eq_self.mpr h).symm
theorem convexBodySum_isBounded : Bornology.IsBounded (convexBodySum K B) := by
refine Metric.isBounded_iff.mpr ⟨B + B, fun x hx y hy => ?_⟩
refine le_trans (norm_sub_le x y) (add_le_add ?_ ?_)
· exact le_trans (norm_le_convexBodySumFun x) hx
· exact le_trans (norm_le_convexBodySumFun y) hy
theorem convexBodySum_compact : IsCompact (convexBodySum K B) := by
rw [Metric.isCompact_iff_isClosed_bounded]
refine ⟨?_, convexBodySum_isBounded K B⟩
convert IsClosed.preimage (convexBodySumFun_continuous K) (isClosed_Icc : IsClosed (Set.Icc 0 B))
ext
simp [convexBodySumFun_nonneg]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLt`. -/
noncomputable abbrev convexBodySumFactor : ℝ≥0 :=
(2 : ℝ≥0) ^ NrRealPlaces K * (NNReal.pi / 2) ^ NrComplexPlaces K / (finrank ℚ K).factorial
theorem convexBodySumFactor_ne_zero : convexBodySumFactor K ≠ 0 := by
refine div_ne_zero ?_ <| Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)
exact mul_ne_zero (pow_ne_zero _ two_ne_zero)
(pow_ne_zero _ (div_ne_zero NNReal.pi_ne_zero two_ne_zero))
open MeasureTheory MeasureTheory.Measure Real in
theorem convexBodySum_volume :
volume (convexBodySum K B) = (convexBodySumFactor K) * (.ofReal B) ^ (finrank ℚ K) := by
obtain hB | hB := le_or_lt B 0
· rw [convexBodySum_volume_eq_zero_of_le_zero K hB, ofReal_eq_zero.mpr hB, zero_pow, mul_zero]
exact finrank_pos.ne'
· suffices volume (convexBodySum K 1) = (convexBodySumFactor K) by
rw [mul_comm]
convert addHaar_smul volume B (convexBodySum K 1)
· simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hB), Set.preimage_setOf_eq, convexBodySumFun,
normAtPlace_smul, abs_inv, abs_eq_self.mpr (le_of_lt hB), ← mul_assoc, mul_comm, mul_assoc,
← Finset.mul_sum, inv_mul_le_iff hB, mul_one]
· rw [abs_pow, ofReal_pow (abs_nonneg _), abs_eq_self.mpr (le_of_lt hB),
mixedEmbedding.finrank]
· exact this.symm
rw [MeasureTheory.measure_le_eq_lt _ ((convexBodySumFun_eq_zero_iff 0).mpr rfl)
convexBodySumFun_neg convexBodySumFun_add_le
(fun hx => (convexBodySumFun_eq_zero_iff _).mp hx)
(fun r x => le_of_eq (convexBodySumFun_smul r x))]
rw [measure_lt_one_eq_integral_div_gamma (g := fun x : (E K) => convexBodySumFun x)
volume ((convexBodySumFun_eq_zero_iff 0).mpr rfl) convexBodySumFun_neg convexBodySumFun_add_le
(fun hx => (convexBodySumFun_eq_zero_iff _).mp hx)
(fun r x => le_of_eq (convexBodySumFun_smul r x)) zero_lt_one]
simp_rw [mixedEmbedding.finrank, div_one, Gamma_nat_eq_factorial, ofReal_div_of_pos
(Nat.cast_pos.mpr (Nat.factorial_pos _)), Real.rpow_one, ofReal_natCast]
suffices ∫ x : E K, exp (-convexBodySumFun x) =
(2:ℝ) ^ NrRealPlaces K * (π / 2) ^ NrComplexPlaces K by
rw [this, convexBodySumFactor, ofReal_mul (by positivity), ofReal_pow zero_le_two,
ofReal_pow (by positivity), ofReal_div_of_pos zero_lt_two, ofReal_ofNat,
← NNReal.coe_real_pi, ofReal_coe_nnreal, coe_div (Nat.cast_ne_zero.mpr
(Nat.factorial_ne_zero _)), coe_mul, coe_pow, coe_pow, coe_ofNat, coe_div two_ne_zero,
coe_ofNat, coe_natCast]
calc
_ = (∫ x : {w : InfinitePlace K // IsReal w} → ℝ, ∏ w, exp (- ‖x w‖)) *
(∫ x : {w : InfinitePlace K // IsComplex w} → ℂ, ∏ w, exp (- 2 * ‖x w‖)) := by
simp_rw [convexBodySumFun_apply', neg_add, ← neg_mul, Finset.mul_sum,
← Finset.sum_neg_distrib, exp_add, exp_sum, ← integral_prod_mul, volume_eq_prod]
_ = (∫ x : ℝ, exp (-|x|)) ^ NrRealPlaces K *
(∫ x : ℂ, Real.exp (-2 * ‖x‖)) ^ NrComplexPlaces K := by
rw [integral_fintype_prod_eq_pow _ (fun x => exp (- ‖x‖)), integral_fintype_prod_eq_pow _
(fun x => exp (- 2 * ‖x‖))]
simp_rw [norm_eq_abs]
_ = (2 * Gamma (1 / 1 + 1)) ^ NrRealPlaces K *
(π * (2:ℝ) ^ (-(2:ℝ) / 1) * Gamma (2 / 1 + 1)) ^ NrComplexPlaces K := by
rw [integral_comp_abs (f := fun x => exp (- x)), ← integral_exp_neg_rpow zero_lt_one,
← Complex.integral_exp_neg_mul_rpow le_rfl zero_lt_two]
simp_rw [Real.rpow_one]
_ = (2:ℝ) ^ NrRealPlaces K * (π / 2) ^ NrComplexPlaces K := by
simp_rw [div_one, one_add_one_eq_two, Gamma_add_one two_ne_zero, Gamma_two, mul_one,
mul_assoc, ← Real.rpow_add_one two_ne_zero, show (-2:ℝ) + 1 = -1 by norm_num,
Real.rpow_neg_one]
rfl
end convexBodySum
section minkowski
open scoped Classical
open MeasureTheory MeasureTheory.Measure FiniteDimensional Zspan Real Submodule
open scoped ENNReal NNReal nonZeroDivisors IntermediateField
variable [NumberField K] (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ)
/-- The bound that appears in **Minkowski Convex Body theorem**, see
`MeasureTheory.exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure`. See
`NumberField.mixedEmbedding.volume_fundamentalDomain_idealLatticeBasis_eq` and
`NumberField.mixedEmbedding.volume_fundamentalDomain_latticeBasis` for the computation of
`volume (fundamentalDomain (idealLatticeBasis K))`. -/
noncomputable def minkowskiBound : ℝ≥0∞ :=
volume (fundamentalDomain (fractionalIdealLatticeBasis K I)) * (2 : ℝ≥0∞) ^ (finrank ℝ (E K))
theorem volume_fundamentalDomain_fractionalIdealLatticeBasis :
volume (fundamentalDomain (fractionalIdealLatticeBasis K I)) =
.ofReal (FractionalIdeal.absNorm I.1) * volume (fundamentalDomain (latticeBasis K)) := by
let e : (Module.Free.ChooseBasisIndex ℤ I) ≃ (Module.Free.ChooseBasisIndex ℤ (𝓞 K)) := by
refine Fintype.equivOfCardEq ?_
rw [← finrank_eq_card_chooseBasisIndex, ← finrank_eq_card_chooseBasisIndex,
fractionalIdeal_rank]
rw [← fundamentalDomain_reindex (fractionalIdealLatticeBasis K I) e,
measure_fundamentalDomain ((fractionalIdealLatticeBasis K I).reindex e)]
· rw [show (fractionalIdealLatticeBasis K I).reindex e = (mixedEmbedding K) ∘
(basisOfFractionalIdeal K I) ∘ e.symm by
ext1; simp only [Basis.coe_reindex, Function.comp_apply, fractionalIdealLatticeBasis_apply]]
rw [mixedEmbedding.det_basisOfFractionalIdeal_eq_norm]
theorem minkowskiBound_lt_top : minkowskiBound K I < ⊤ := by
refine ENNReal.mul_lt_top ?_ ?_
· exact ne_of_lt (fundamentalDomain_isBounded _).measure_lt_top
· exact ne_of_lt (ENNReal.pow_lt_top (lt_top_iff_ne_top.mpr ENNReal.two_ne_top) _)
theorem minkowskiBound_pos : 0 < minkowskiBound K I := by
refine zero_lt_iff.mpr (mul_ne_zero ?_ ?_)
· exact Zspan.measure_fundamentalDomain_ne_zero _
· exact ENNReal.pow_ne_zero two_ne_zero _
variable {f : InfinitePlace K → ℝ≥0} (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ)
/-- Let `I` be a fractional ideal of `K`. Assume that `f : InfinitePlace K → ℝ≥0` is such that
`minkowskiBound K I < volume (convexBodyLT K f)` where `convexBodyLT K f` is the set of
points `x` such that `‖x w‖ < f w` for all infinite places `w` (see `convexBodyLT_volume` for
the computation of this volume), then there exists a nonzero algebraic number `a` in `I` such
that `w a < f w` for all infinite places `w`. -/
| Mathlib/NumberTheory/NumberField/CanonicalEmbedding/ConvexBody.lean | 503 | 513 | theorem exists_ne_zero_mem_ideal_lt (h : minkowskiBound K I < volume (convexBodyLT K f)) :
∃ a ∈ (I : FractionalIdeal (𝓞 K)⁰ K), a ≠ 0 ∧ ∀ w : InfinitePlace K, w a < f w := by |
have h_fund := Zspan.isAddFundamentalDomain (fractionalIdealLatticeBasis K I) volume
have : Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))).toAddSubgroup := by
change Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I)) : Set (E K))
infer_instance
obtain ⟨⟨x, hx⟩, h_nz, h_mem⟩ := exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure
h_fund (convexBodyLT_neg_mem K f) (convexBodyLT_convex K f) h
rw [mem_toAddSubgroup, mem_span_fractionalIdealLatticeBasis] at hx
obtain ⟨a, ha, rfl⟩ := hx
exact ⟨a, ha, by simpa using h_nz, (convexBodyLT_mem K f).mp h_mem⟩
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Data.Stream.Defs
import Mathlib.Logic.Function.Basic
import Mathlib.Init.Data.List.Basic
import Mathlib.Data.List.Basic
#align_import data.stream.init from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432"
/-!
# Streams a.k.a. infinite lists a.k.a. infinite sequences
Porting note:
This file used to be in the core library. It was moved to `mathlib` and renamed to `init` to avoid
name clashes. -/
set_option autoImplicit true
open Nat Function Option
namespace Stream'
variable {α : Type u} {β : Type v} {δ : Type w}
instance [Inhabited α] : Inhabited (Stream' α) :=
⟨Stream'.const default⟩
protected theorem eta (s : Stream' α) : (head s::tail s) = s :=
funext fun i => by cases i <;> rfl
#align stream.eta Stream'.eta
@[ext]
protected theorem ext {s₁ s₂ : Stream' α} : (∀ n, get s₁ n = get s₂ n) → s₁ = s₂ :=
fun h => funext h
#align stream.ext Stream'.ext
@[simp]
theorem get_zero_cons (a : α) (s : Stream' α) : get (a::s) 0 = a :=
rfl
#align stream.nth_zero_cons Stream'.get_zero_cons
@[simp]
theorem head_cons (a : α) (s : Stream' α) : head (a::s) = a :=
rfl
#align stream.head_cons Stream'.head_cons
@[simp]
theorem tail_cons (a : α) (s : Stream' α) : tail (a::s) = s :=
rfl
#align stream.tail_cons Stream'.tail_cons
@[simp]
theorem get_drop (n m : Nat) (s : Stream' α) : get (drop m s) n = get s (n + m) :=
rfl
#align stream.nth_drop Stream'.get_drop
theorem tail_eq_drop (s : Stream' α) : tail s = drop 1 s :=
rfl
#align stream.tail_eq_drop Stream'.tail_eq_drop
@[simp]
theorem drop_drop (n m : Nat) (s : Stream' α) : drop n (drop m s) = drop (n + m) s := by
ext; simp [Nat.add_assoc]
#align stream.drop_drop Stream'.drop_drop
@[simp] theorem get_tail {s : Stream' α} : s.tail.get n = s.get (n + 1) := rfl
@[simp] theorem tail_drop' {s : Stream' α} : tail (drop i s) = s.drop (i+1) := by
ext; simp [Nat.add_comm, Nat.add_assoc, Nat.add_left_comm]
@[simp] theorem drop_tail' {s : Stream' α} : drop i (tail s) = s.drop (i+1) := rfl
theorem tail_drop (n : Nat) (s : Stream' α) : tail (drop n s) = drop n (tail s) := by simp
#align stream.tail_drop Stream'.tail_drop
theorem get_succ (n : Nat) (s : Stream' α) : get s (succ n) = get (tail s) n :=
rfl
#align stream.nth_succ Stream'.get_succ
@[simp]
theorem get_succ_cons (n : Nat) (s : Stream' α) (x : α) : get (x::s) n.succ = get s n :=
rfl
#align stream.nth_succ_cons Stream'.get_succ_cons
@[simp] theorem drop_zero {s : Stream' α} : s.drop 0 = s := rfl
theorem drop_succ (n : Nat) (s : Stream' α) : drop (succ n) s = drop n (tail s) :=
rfl
#align stream.drop_succ Stream'.drop_succ
theorem head_drop (a : Stream' α) (n : ℕ) : (a.drop n).head = a.get n := by simp
#align stream.head_drop Stream'.head_drop
theorem cons_injective2 : Function.Injective2 (cons : α → Stream' α → Stream' α) := fun x y s t h =>
⟨by rw [← get_zero_cons x s, h, get_zero_cons],
Stream'.ext fun n => by rw [← get_succ_cons n _ x, h, get_succ_cons]⟩
#align stream.cons_injective2 Stream'.cons_injective2
theorem cons_injective_left (s : Stream' α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
#align stream.cons_injective_left Stream'.cons_injective_left
theorem cons_injective_right (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
#align stream.cons_injective_right Stream'.cons_injective_right
theorem all_def (p : α → Prop) (s : Stream' α) : All p s = ∀ n, p (get s n) :=
rfl
#align stream.all_def Stream'.all_def
theorem any_def (p : α → Prop) (s : Stream' α) : Any p s = ∃ n, p (get s n) :=
rfl
#align stream.any_def Stream'.any_def
@[simp]
theorem mem_cons (a : α) (s : Stream' α) : a ∈ a::s :=
Exists.intro 0 rfl
#align stream.mem_cons Stream'.mem_cons
theorem mem_cons_of_mem {a : α} {s : Stream' α} (b : α) : a ∈ s → a ∈ b::s := fun ⟨n, h⟩ =>
Exists.intro (succ n) (by rw [get_succ, tail_cons, h])
#align stream.mem_cons_of_mem Stream'.mem_cons_of_mem
theorem eq_or_mem_of_mem_cons {a b : α} {s : Stream' α} : (a ∈ b::s) → a = b ∨ a ∈ s :=
fun ⟨n, h⟩ => by
cases' n with n'
· left
exact h
· right
rw [get_succ, tail_cons] at h
exact ⟨n', h⟩
#align stream.eq_or_mem_of_mem_cons Stream'.eq_or_mem_of_mem_cons
theorem mem_of_get_eq {n : Nat} {s : Stream' α} {a : α} : a = get s n → a ∈ s := fun h =>
Exists.intro n h
#align stream.mem_of_nth_eq Stream'.mem_of_get_eq
section Map
variable (f : α → β)
theorem drop_map (n : Nat) (s : Stream' α) : drop n (map f s) = map f (drop n s) :=
Stream'.ext fun _ => rfl
#align stream.drop_map Stream'.drop_map
@[simp]
theorem get_map (n : Nat) (s : Stream' α) : get (map f s) n = f (get s n) :=
rfl
#align stream.nth_map Stream'.get_map
theorem tail_map (s : Stream' α) : tail (map f s) = map f (tail s) := rfl
#align stream.tail_map Stream'.tail_map
@[simp]
theorem head_map (s : Stream' α) : head (map f s) = f (head s) :=
rfl
#align stream.head_map Stream'.head_map
theorem map_eq (s : Stream' α) : map f s = f (head s)::map f (tail s) := by
rw [← Stream'.eta (map f s), tail_map, head_map]
#align stream.map_eq Stream'.map_eq
theorem map_cons (a : α) (s : Stream' α) : map f (a::s) = f a::map f s := by
rw [← Stream'.eta (map f (a::s)), map_eq]; rfl
#align stream.map_cons Stream'.map_cons
@[simp]
theorem map_id (s : Stream' α) : map id s = s :=
rfl
#align stream.map_id Stream'.map_id
@[simp]
theorem map_map (g : β → δ) (f : α → β) (s : Stream' α) : map g (map f s) = map (g ∘ f) s :=
rfl
#align stream.map_map Stream'.map_map
@[simp]
theorem map_tail (s : Stream' α) : map f (tail s) = tail (map f s) :=
rfl
#align stream.map_tail Stream'.map_tail
theorem mem_map {a : α} {s : Stream' α} : a ∈ s → f a ∈ map f s := fun ⟨n, h⟩ =>
Exists.intro n (by rw [get_map, h])
#align stream.mem_map Stream'.mem_map
theorem exists_of_mem_map {f} {b : β} {s : Stream' α} : b ∈ map f s → ∃ a, a ∈ s ∧ f a = b :=
fun ⟨n, h⟩ => ⟨get s n, ⟨n, rfl⟩, h.symm⟩
#align stream.exists_of_mem_map Stream'.exists_of_mem_map
end Map
section Zip
variable (f : α → β → δ)
theorem drop_zip (n : Nat) (s₁ : Stream' α) (s₂ : Stream' β) :
drop n (zip f s₁ s₂) = zip f (drop n s₁) (drop n s₂) :=
Stream'.ext fun _ => rfl
#align stream.drop_zip Stream'.drop_zip
@[simp]
theorem get_zip (n : Nat) (s₁ : Stream' α) (s₂ : Stream' β) :
get (zip f s₁ s₂) n = f (get s₁ n) (get s₂ n) :=
rfl
#align stream.nth_zip Stream'.get_zip
theorem head_zip (s₁ : Stream' α) (s₂ : Stream' β) : head (zip f s₁ s₂) = f (head s₁) (head s₂) :=
rfl
#align stream.head_zip Stream'.head_zip
theorem tail_zip (s₁ : Stream' α) (s₂ : Stream' β) :
tail (zip f s₁ s₂) = zip f (tail s₁) (tail s₂) :=
rfl
#align stream.tail_zip Stream'.tail_zip
theorem zip_eq (s₁ : Stream' α) (s₂ : Stream' β) :
zip f s₁ s₂ = f (head s₁) (head s₂)::zip f (tail s₁) (tail s₂) := by
rw [← Stream'.eta (zip f s₁ s₂)]; rfl
#align stream.zip_eq Stream'.zip_eq
@[simp]
theorem get_enum (s : Stream' α) (n : ℕ) : get (enum s) n = (n, s.get n) :=
rfl
#align stream.nth_enum Stream'.get_enum
theorem enum_eq_zip (s : Stream' α) : enum s = zip Prod.mk nats s :=
rfl
#align stream.enum_eq_zip Stream'.enum_eq_zip
end Zip
@[simp]
theorem mem_const (a : α) : a ∈ const a :=
Exists.intro 0 rfl
#align stream.mem_const Stream'.mem_const
theorem const_eq (a : α) : const a = a::const a := by
apply Stream'.ext; intro n
cases n <;> rfl
#align stream.const_eq Stream'.const_eq
@[simp]
theorem tail_const (a : α) : tail (const a) = const a :=
suffices tail (a::const a) = const a by rwa [← const_eq] at this
rfl
#align stream.tail_const Stream'.tail_const
@[simp]
theorem map_const (f : α → β) (a : α) : map f (const a) = const (f a) :=
rfl
#align stream.map_const Stream'.map_const
@[simp]
theorem get_const (n : Nat) (a : α) : get (const a) n = a :=
rfl
#align stream.nth_const Stream'.get_const
@[simp]
theorem drop_const (n : Nat) (a : α) : drop n (const a) = const a :=
Stream'.ext fun _ => rfl
#align stream.drop_const Stream'.drop_const
@[simp]
theorem head_iterate (f : α → α) (a : α) : head (iterate f a) = a :=
rfl
#align stream.head_iterate Stream'.head_iterate
theorem get_succ_iterate' (n : Nat) (f : α → α) (a : α) :
get (iterate f a) (succ n) = f (get (iterate f a) n) := rfl
theorem tail_iterate (f : α → α) (a : α) : tail (iterate f a) = iterate f (f a) := by
ext n
rw [get_tail]
induction' n with n' ih
· rfl
· rw [get_succ_iterate', ih, get_succ_iterate']
#align stream.tail_iterate Stream'.tail_iterate
theorem iterate_eq (f : α → α) (a : α) : iterate f a = a::iterate f (f a) := by
rw [← Stream'.eta (iterate f a)]
rw [tail_iterate]; rfl
#align stream.iterate_eq Stream'.iterate_eq
@[simp]
theorem get_zero_iterate (f : α → α) (a : α) : get (iterate f a) 0 = a :=
rfl
#align stream.nth_zero_iterate Stream'.get_zero_iterate
theorem get_succ_iterate (n : Nat) (f : α → α) (a : α) :
get (iterate f a) (succ n) = get (iterate f (f a)) n := by rw [get_succ, tail_iterate]
#align stream.nth_succ_iterate Stream'.get_succ_iterate
section Bisim
variable (R : Stream' α → Stream' α → Prop)
/-- equivalence relation -/
local infixl:50 " ~ " => R
/-- Streams `s₁` and `s₂` are defined to be bisimulations if
their heads are equal and tails are bisimulations. -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ →
head s₁ = head s₂ ∧ tail s₁ ~ tail s₂
#align stream.is_bisimulation Stream'.IsBisimulation
theorem get_of_bisim (bisim : IsBisimulation R) :
∀ {s₁ s₂} (n), s₁ ~ s₂ → get s₁ n = get s₂ n ∧ drop (n + 1) s₁ ~ drop (n + 1) s₂
| _, _, 0, h => bisim h
| _, _, n + 1, h =>
match bisim h with
| ⟨_, trel⟩ => get_of_bisim bisim n trel
#align stream.nth_of_bisim Stream'.get_of_bisim
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) : ∀ {s₁ s₂}, s₁ ~ s₂ → s₁ = s₂ := fun r =>
Stream'.ext fun n => And.left (get_of_bisim R bisim n r)
#align stream.eq_of_bisim Stream'.eq_of_bisim
end Bisim
theorem bisim_simple (s₁ s₂ : Stream' α) :
head s₁ = head s₂ → s₁ = tail s₁ → s₂ = tail s₂ → s₁ = s₂ := fun hh ht₁ ht₂ =>
eq_of_bisim (fun s₁ s₂ => head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂)
(fun s₁ s₂ ⟨h₁, h₂, h₃⟩ => by
constructor
· exact h₁
rw [← h₂, ← h₃]
(repeat' constructor) <;> assumption)
(And.intro hh (And.intro ht₁ ht₂))
#align stream.bisim_simple Stream'.bisim_simple
theorem coinduction {s₁ s₂ : Stream' α} :
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Stream' α → β),
fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂ :=
fun hh ht =>
eq_of_bisim
(fun s₁ s₂ =>
head s₁ = head s₂ ∧
∀ (β : Type u) (fr : Stream' α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂))
(fun s₁ s₂ h =>
have h₁ : head s₁ = head s₂ := And.left h
have h₂ : head (tail s₁) = head (tail s₂) := And.right h α (@head α) h₁
have h₃ :
∀ (β : Type u) (fr : Stream' α → β),
fr (tail s₁) = fr (tail s₂) → fr (tail (tail s₁)) = fr (tail (tail s₂)) :=
fun β fr => And.right h β fun s => fr (tail s)
And.intro h₁ (And.intro h₂ h₃))
(And.intro hh ht)
#align stream.coinduction Stream'.coinduction
@[simp]
theorem iterate_id (a : α) : iterate id a = const a :=
coinduction rfl fun β fr ch => by rw [tail_iterate, tail_const]; exact ch
#align stream.iterate_id Stream'.iterate_id
theorem map_iterate (f : α → α) (a : α) : iterate f (f a) = map f (iterate f a) := by
funext n
induction' n with n' ih
· rfl
· unfold map iterate get
rw [map, get] at ih
rw [iterate]
exact congrArg f ih
#align stream.map_iterate Stream'.map_iterate
section Corec
theorem corec_def (f : α → β) (g : α → α) (a : α) : corec f g a = map f (iterate g a) :=
rfl
#align stream.corec_def Stream'.corec_def
theorem corec_eq (f : α → β) (g : α → α) (a : α) : corec f g a = f a::corec f g (g a) := by
rw [corec_def, map_eq, head_iterate, tail_iterate]; rfl
#align stream.corec_eq Stream'.corec_eq
| Mathlib/Data/Stream/Init.lean | 381 | 382 | theorem corec_id_id_eq_const (a : α) : corec id id a = const a := by |
rw [corec_def, map_id, iterate_id]
|
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.FieldTheory.RatFunc.Defs
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Polynomial.Content
#align_import field_theory.ratfunc from "leanprover-community/mathlib"@"bf9bbbcf0c1c1ead18280b0d010e417b10abb1b6"
/-!
# The field structure of rational functions
## Main definitions
Working with rational functions as polynomials:
- `RatFunc.instField` provides a field structure
You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials:
* `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions
* `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`,
in particular:
* `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of
fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change
the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`.
Working with rational functions as fractions:
- `RatFunc.num` and `RatFunc.denom` give the numerator and denominator.
These values are chosen to be coprime and such that `RatFunc.denom` is monic.
Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long
as the homomorphism retains the non-zero-divisor property:
- `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to
a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]`
- `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`,
where `[CommRing K] [Field L]`
- `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`,
where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]`
This is satisfied by injective homs.
We also have lifting homomorphisms of polynomials to other polynomials,
with the same condition on retaining the non-zero-divisor property across the map:
- `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when
`[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]`
-/
universe u v
noncomputable section
open scoped Classical
open scoped nonZeroDivisors Polynomial
variable {K : Type u}
namespace RatFunc
section Field
variable [CommRing K]
/-- The zero rational function. -/
protected irreducible_def zero : RatFunc K :=
⟨0⟩
#align ratfunc.zero RatFunc.zero
instance : Zero (RatFunc K) :=
⟨RatFunc.zero⟩
-- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [zero_def]`
-- that does not close the goal
theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := by
simp only [Zero.zero, OfNat.ofNat, RatFunc.zero]
#align ratfunc.of_fraction_ring_zero RatFunc.ofFractionRing_zero
/-- Addition of rational functions. -/
protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p + q⟩
#align ratfunc.add RatFunc.add
instance : Add (RatFunc K) :=
⟨RatFunc.add⟩
-- Porting note: added `HAdd.hAdd`. using `simp?` produces `simp only [add_def]`
-- that does not close the goal
theorem ofFractionRing_add (p q : FractionRing K[X]) :
ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := by
simp only [HAdd.hAdd, Add.add, RatFunc.add]
#align ratfunc.of_fraction_ring_add RatFunc.ofFractionRing_add
/-- Subtraction of rational functions. -/
protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p - q⟩
#align ratfunc.sub RatFunc.sub
instance : Sub (RatFunc K) :=
⟨RatFunc.sub⟩
-- Porting note: added `HSub.hSub`. using `simp?` produces `simp only [sub_def]`
-- that does not close the goal
theorem ofFractionRing_sub (p q : FractionRing K[X]) :
ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := by
simp only [Sub.sub, HSub.hSub, RatFunc.sub]
#align ratfunc.of_fraction_ring_sub RatFunc.ofFractionRing_sub
/-- Additive inverse of a rational function. -/
protected irreducible_def neg : RatFunc K → RatFunc K
| ⟨p⟩ => ⟨-p⟩
#align ratfunc.neg RatFunc.neg
instance : Neg (RatFunc K) :=
⟨RatFunc.neg⟩
theorem ofFractionRing_neg (p : FractionRing K[X]) :
ofFractionRing (-p) = -ofFractionRing p := by simp only [Neg.neg, RatFunc.neg]
#align ratfunc.of_fraction_ring_neg RatFunc.ofFractionRing_neg
/-- The multiplicative unit of rational functions. -/
protected irreducible_def one : RatFunc K :=
⟨1⟩
#align ratfunc.one RatFunc.one
instance : One (RatFunc K) :=
⟨RatFunc.one⟩
-- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [one_def]`
-- that does not close the goal
theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := by
simp only [One.one, OfNat.ofNat, RatFunc.one]
#align ratfunc.of_fraction_ring_one RatFunc.ofFractionRing_one
/-- Multiplication of rational functions. -/
protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p * q⟩
#align ratfunc.mul RatFunc.mul
instance : Mul (RatFunc K) :=
⟨RatFunc.mul⟩
-- Porting note: added `HMul.hMul`. using `simp?` produces `simp only [mul_def]`
-- that does not close the goal
theorem ofFractionRing_mul (p q : FractionRing K[X]) :
ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := by
simp only [Mul.mul, HMul.hMul, RatFunc.mul]
#align ratfunc.of_fraction_ring_mul RatFunc.ofFractionRing_mul
section IsDomain
variable [IsDomain K]
/-- Division of rational functions. -/
protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p / q⟩
#align ratfunc.div RatFunc.div
instance : Div (RatFunc K) :=
⟨RatFunc.div⟩
-- Porting note: added `HDiv.hDiv`. using `simp?` produces `simp only [div_def]`
-- that does not close the goal
theorem ofFractionRing_div (p q : FractionRing K[X]) :
ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := by
simp only [Div.div, HDiv.hDiv, RatFunc.div]
#align ratfunc.of_fraction_ring_div RatFunc.ofFractionRing_div
/-- Multiplicative inverse of a rational function. -/
protected irreducible_def inv : RatFunc K → RatFunc K
| ⟨p⟩ => ⟨p⁻¹⟩
#align ratfunc.inv RatFunc.inv
instance : Inv (RatFunc K) :=
⟨RatFunc.inv⟩
theorem ofFractionRing_inv (p : FractionRing K[X]) :
ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := by
simp only [Inv.inv, RatFunc.inv]
#align ratfunc.of_fraction_ring_inv RatFunc.ofFractionRing_inv
-- Auxiliary lemma for the `Field` instance
theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1
| ⟨p⟩, h => by
have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero]
simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one,
ofFractionRing.injEq] using -- Porting note: `ofFractionRing.injEq` was not present
_root_.mul_inv_cancel this
#align ratfunc.mul_inv_cancel RatFunc.mul_inv_cancel
end IsDomain
section SMul
variable {R : Type*}
/-- Scalar multiplication of rational functions. -/
protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K
| r, ⟨p⟩ => ⟨r • p⟩
#align ratfunc.smul RatFunc.smul
-- cannot reproduce
--@[nolint fails_quickly] -- Porting note: `linter 'fails_quickly' not found`
instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) :=
⟨RatFunc.smul⟩
-- Porting note: added `SMul.hSMul`. using `simp?` produces `simp only [smul_def]`
-- that does not close the goal
theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) :
ofFractionRing (c • p) = c • ofFractionRing p := by
simp only [SMul.smul, HSMul.hSMul, RatFunc.smul]
#align ratfunc.of_fraction_ring_smul RatFunc.ofFractionRing_smul
theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) :
toFractionRing (c • p) = c • toFractionRing p := by
cases p
rw [← ofFractionRing_smul]
#align ratfunc.to_fraction_ring_smul RatFunc.toFractionRing_smul
theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by
cases' x with x
-- Porting note: had to specify the induction principle manually
induction x using Localization.induction_on
rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk,
Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul]
set_option linter.uppercaseLean3 false in
#align ratfunc.smul_eq_C_smul RatFunc.smul_eq_C_smul
section IsDomain
variable [IsDomain K]
variable [Monoid R] [DistribMulAction R K[X]]
variable [IsScalarTower R K[X] K[X]]
theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by
by_cases hq : q = 0
· rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero]
· rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ←
ofFractionRing_smul]
#align ratfunc.mk_smul RatFunc.mk_smul
instance : IsScalarTower R K[X] (RatFunc K) :=
⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩
end IsDomain
end SMul
variable (K)
instance [Subsingleton K] : Subsingleton (RatFunc K) :=
toFractionRing_injective.subsingleton
instance : Inhabited (RatFunc K) :=
⟨0⟩
instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) :=
ofFractionRing_injective.nontrivial
#align ratfunc.nontrivial RatFunc.instNontrivial
/-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings.
This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`.
-/
@[simps apply]
def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where
toFun := toFractionRing
invFun := ofFractionRing
left_inv := fun ⟨_⟩ => rfl
right_inv _ := rfl
map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add]
map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul]
#align ratfunc.to_fraction_ring_ring_equiv RatFunc.toFractionRingRingEquiv
end Field
section TacticInterlude
-- Porting note: reimplemented the `frac_tac` and `smul_tac` as close to the originals as I could
/-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/
macro "frac_tac" : tactic => `(tactic| repeat (rintro (⟨⟩ : RatFunc _)) <;>
try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub,
← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div,
← ofFractionRing_inv,
add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero,
add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv,
add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_right_neg])
/-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/
macro "smul_tac" : tactic => `(tactic|
repeat
(first
| rintro (⟨⟩ : RatFunc _)
| intro) <;>
simp_rw [← ofFractionRing_smul] <;>
simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero,
neg_add, mul_neg,
Int.ofNat_eq_coe, Int.cast_zero, Int.cast_add, Int.cast_one,
Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ,
Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk,
ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg])
end TacticInterlude
section CommRing
variable (K) [CommRing K]
-- Porting note: split the CommRing instance up into multiple defs because it was hard to see
-- if the big instance declaration made any progress.
/-- `RatFunc K` is a commutative monoid.
This is an intermediate step on the way to the full instance `RatFunc.instCommRing`.
-/
def instCommMonoid : CommMonoid (RatFunc K) where
mul := (· * ·)
mul_assoc := by frac_tac
mul_comm := by frac_tac
one := 1
one_mul := by frac_tac
mul_one := by frac_tac
npow := npowRec
/-- `RatFunc K` is an additive commutative group.
This is an intermediate step on the way to the full instance `RatFunc.instCommRing`.
-/
def instAddCommGroup : AddCommGroup (RatFunc K) where
add := (· + ·)
add_assoc := by frac_tac
-- Porting note: `by frac_tac` didn't work:
add_comm := by repeat rintro (⟨⟩ : RatFunc _) <;> simp only [← ofFractionRing_add, add_comm]
zero := 0
zero_add := by frac_tac
add_zero := by frac_tac
neg := Neg.neg
add_left_neg := by frac_tac
sub := Sub.sub
sub_eq_add_neg := by frac_tac
nsmul := (· • ·)
nsmul_zero := by smul_tac
nsmul_succ _ := by smul_tac
zsmul := (· • ·)
zsmul_zero' := by smul_tac
zsmul_succ' _ := by smul_tac
zsmul_neg' _ := by smul_tac
instance instCommRing : CommRing (RatFunc K) :=
{ instCommMonoid K, instAddCommGroup K with
zero := 0
sub := Sub.sub
zero_mul := by frac_tac
mul_zero := by frac_tac
left_distrib := by frac_tac
right_distrib := by frac_tac
one := 1
nsmul := (· • ·)
zsmul := (· • ·)
npow := npowRec }
#align ratfunc.comm_ring RatFunc.instCommRing
variable {K}
section LiftHom
open RatFunc
variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S]
variable [FunLike F R[X] S[X]]
/-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]`
to a `RatFunc R →* RatFunc S`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
RatFunc R →* RatFunc S where
toFun f :=
RatFunc.liftOn f
(fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0)
fun {p q p' q'} hq hq' h => by
beta_reduce -- Porting note(#12129): force the function to be applied
rw [dif_pos, dif_pos]
on_goal 1 =>
congr 1 -- Porting note: this was a `rw [ofFractionRing.inj_eq]` which was overkill anyway
rw [Localization.mk_eq_mk_iff]
rotate_left
· exact hφ hq
· exact hφ hq'
refine Localization.r_of_eq ?_
simpa only [map_mul] using congr_arg φ h
map_one' := by
beta_reduce -- Porting note(#12129): force the function to be applied
rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, dif_pos]
· simpa using ofFractionRing_one
· simpa using Submonoid.one_mem _
map_mul' x y := by
beta_reduce -- Porting note(#12129): force the function to be applied
cases' x with x; cases' y with y
-- Porting note: added `using Localization.rec` (`Localization.induction_on` didn't work)
induction' x using Localization.rec with p q
· induction' y using Localization.rec with p' q'
· have hq : φ q ∈ S[X]⁰ := hφ q.prop
have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop
have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq'
simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq,
dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul,
Localization.mk_mul, Submonoid.mk_mul_mk]
· rfl
· rfl
#align ratfunc.map RatFunc.map
theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F)
(hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) :
map φ hφ (ofFractionRing (Localization.mk n d)) =
ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by
-- Porting note: replaced `convert` with `refine Eq.trans`
refine (liftOn_ofFractionRing_mk n _ _ _).trans ?_
rw [dif_pos]
#align ratfunc.map_apply_of_fraction_ring_mk RatFunc.map_apply_ofFractionRing_mk
theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ)
(hf : Function.Injective φ) : Function.Injective (map φ hφ) := by
rintro ⟨x⟩ ⟨y⟩ h
-- Porting note: had to hint `induction` which induction principle to use
induction x using Localization.induction_on
induction y using Localization.induction_on
simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff,
Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors,
exists_const, ← map_mul, hf.eq_iff] using h
#align ratfunc.map_injective RatFunc.map_injective
/-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]`
to a `RatFunc R →+* RatFunc S`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
RatFunc R →+* RatFunc S :=
{ map φ hφ with
map_zero' := by
simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰),
← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero,
Localization.mk_eq_mk', IsLocalization.mk'_zero]
map_add' := by
rintro ⟨x⟩ ⟨y⟩
-- Porting note: had to hint `induction` which induction principle to use
induction x using Localization.rec
induction y using Localization.rec
· simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul,
MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul]
-- Porting note: `Submonoid.mk_mul_mk` couldn't be applied: motive incorrect,
-- even though it is a rfl lemma.
rfl
· rfl
· rfl }
#align ratfunc.map_ring_hom RatFunc.mapRingHom
theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
(mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ :=
rfl
#align ratfunc.coe_map_ring_hom_eq_coe_map RatFunc.coe_mapRingHom_eq_coe_map
-- TODO: Generalize to `FunLike` classes,
/-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀`
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where
toFun f :=
RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q]
rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;>
exact nonZeroDivisors.ne_zero (hφ ‹_›)
map_one' := by
dsimp only -- Porting note: force the function to be applied (not just beta reduction!)
rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk]
simp only [map_one, OneMemClass.coe_one, div_one]
map_mul' x y := by
cases' x with x
cases' y with y
induction' x using Localization.rec with p q
· induction' y using Localization.rec with p' q'
· rw [← ofFractionRing_mul, Localization.mk_mul]
simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul]
· rfl
· rfl
map_zero' := by
beta_reduce -- Porting note(#12129): force the function to be applied
rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk]
simp only [map_zero, zero_div]
#align ratfunc.lift_monoid_with_zero_hom RatFunc.liftMonoidWithZeroHom
theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ)
(n : R[X]) (d : R[X]⁰) :
liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftOn_ofFractionRing_mk _ _ _ _
#align ratfunc.lift_monoid_with_zero_hom_apply_of_fraction_ring_mk RatFunc.liftMonoidWithZeroHom_apply_ofFractionRing_mk
theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ)
(hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftMonoidWithZeroHom φ hφ') := by
rintro ⟨x⟩ ⟨y⟩
induction' x using Localization.induction_on with a
induction' y using Localization.induction_on with a'
simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk]
intro h
congr 1
refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_)
have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h
· rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this
all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _)
#align ratfunc.lift_monoid_with_zero_hom_injective RatFunc.liftMonoidWithZeroHom_injective
/-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L`
by mapping both the numerator and denominator and quotienting them. -/
def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L :=
{ liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with
map_add' := fun x y => by
-- Porting note: used to invoke `MonoidWithZeroHom.toFun_eq_coe`
simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe]
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add]
cases' x with x
cases' y with y
-- Porting note: had to add the recursor explicitly below
induction' x using Localization.rec with p q
· induction' y using Localization.rec with p' q'
· rw [← ofFractionRing_add, Localization.add_mk]
simp only [RingHom.toMonoidWithZeroHom_eq_coe,
liftMonoidWithZeroHom_apply_ofFractionRing_mk]
rw [div_add_div, div_eq_div_iff]
· rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm]
simp only [map_add, map_mul, Submonoid.coe_mul]
all_goals
try simp only [← map_mul, ← Submonoid.coe_mul]
exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _))
· rfl
· rfl }
#align ratfunc.lift_ring_hom RatFunc.liftRingHom
theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X])
(d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _
#align ratfunc.lift_ring_hom_apply_of_fraction_ring_mk RatFunc.liftRingHom_apply_ofFractionRing_mk
theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ)
(hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftRingHom φ hφ') :=
liftMonoidWithZeroHom_injective _ hφ
#align ratfunc.lift_ring_hom_injective RatFunc.liftRingHom_injective
end LiftHom
variable (K)
instance instField [IsDomain K] : Field (RatFunc K) where
-- Porting note: used to be `by frac_tac`
inv_zero := by rw [← ofFractionRing_zero, ← ofFractionRing_inv, inv_zero]
div := (· / ·)
div_eq_mul_inv := by frac_tac
mul_inv_cancel _ := mul_inv_cancel
zpow := zpowRec
nnqsmul := _
qsmul := _
section IsFractionRing
/-! ### `RatFunc` as field of fractions of `Polynomial` -/
section IsDomain
variable [IsDomain K]
instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where
toFun x := RatFunc.mk (algebraMap _ _ x) 1
map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add]
map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul]
map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one]
map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero]
smul := (· • ·)
smul_def' c x := by
induction' x using RatFunc.induction_on' with p q hq
-- Porting note: the first `rw [...]` was not needed
rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
rw [mk_one', ← mk_smul, mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ←
ofFractionRing_mul, IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def]
commutes' c x := mul_comm _ _
variable {K}
/-- The coercion from polynomials to rational functions, implemented as the algebra map from a
domain to its field of fractions -/
@[coe]
def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P
instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩
theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x :=
rfl
#align ratfunc.mk_one RatFunc.mk_one
theorem ofFractionRing_algebraMap (x : K[X]) :
ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by
rw [← mk_one, mk_one']
#align ratfunc.of_fraction_ring_algebra_map RatFunc.ofFractionRing_algebraMap
@[simp]
theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by
simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap]
#align ratfunc.mk_eq_div RatFunc.mk_eq_div
@[simp]
theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R)
(p q : K[X]) :
algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q =
c • (algebraMap _ _ p / algebraMap _ _ q) := by
rw [← mk_eq_div, mk_smul, mk_eq_div]
#align ratfunc.div_smul RatFunc.div_smul
theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) :
algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by
rw [← mk_eq_div]
rfl
#align ratfunc.algebra_map_apply RatFunc.algebraMap_apply
theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]]
(φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) :
map φ hφ (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by
have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq))
simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk,
mk_eq_localization_mk _ hq']
#align ratfunc.map_apply_div_ne_zero RatFunc.map_apply_div_ne_zero
@[simp]
theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]]
(φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) :
map φ hφ (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by
rcases eq_or_ne q 0 with (rfl | hq)
· have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp
rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one,
map_one, div_one, map_zero, map_zero]
exact one_ne_zero
exact map_apply_div_ne_zero _ _ _ _ hq
#align ratfunc.map_apply_div RatFunc.map_apply_div
theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L]
(φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) :
liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by
rcases eq_or_ne q 0 with (rfl | hq)
· simp only [div_zero, map_zero]
simp only [← mk_eq_div, mk_eq_localization_mk _ hq,
liftMonoidWithZeroHom_apply_ofFractionRing_mk]
#align ratfunc.lift_monoid_with_zero_hom_apply_div RatFunc.liftMonoidWithZeroHom_apply_div
@[simp]
theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L]
(φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) :
liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) =
φ p / φ q := by
rw [← map_div₀, liftMonoidWithZeroHom_apply_div]
theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div _ hφ _ _ -- Porting note: gave explicitly the `hφ`
#align ratfunc.lift_ring_hom_apply_div RatFunc.liftRingHom_apply_div
@[simp]
theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) =
φ p / φ q :=
liftMonoidWithZeroHom_apply_div' _ hφ _ _ -- Porting note: gave explicitly the `hφ`
variable (K)
theorem ofFractionRing_comp_algebraMap :
ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ :=
funext ofFractionRing_algebraMap
#align ratfunc.of_fraction_ring_comp_algebra_map RatFunc.ofFractionRing_comp_algebraMap
theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by
rw [← ofFractionRing_comp_algebraMap]
exact ofFractionRing_injective.comp (IsFractionRing.injective _ _)
#align ratfunc.algebra_map_injective RatFunc.algebraMap_injective
@[simp]
theorem algebraMap_eq_zero_iff {x : K[X]} : algebraMap K[X] (RatFunc K) x = 0 ↔ x = 0 :=
⟨(injective_iff_map_eq_zero _).mp (algebraMap_injective K) _, fun hx => by
rw [hx, RingHom.map_zero]⟩
#align ratfunc.algebra_map_eq_zero_iff RatFunc.algebraMap_eq_zero_iff
variable {K}
theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 :=
mt (algebraMap_eq_zero_iff K).mp hx
#align ratfunc.algebra_map_ne_zero RatFunc.algebraMap_ne_zero
section LiftAlgHom
variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]]
[Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
/-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]`
to a `RatFunc K →ₐ[S] RatFunc R`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R :=
{ mapRingHom φ hφ with
commutes' := fun r => by
simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div,
map_one, AlgHom.commutes] }
#align ratfunc.map_alg_hom RatFunc.mapAlgHom
theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) :
(mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ :=
rfl
#align ratfunc.coe_map_alg_hom_eq_coe_map RatFunc.coe_mapAlgHom_eq_coe_map
/-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`
by mapping both the numerator and denominator and quotienting them. -/
def liftAlgHom : RatFunc K →ₐ[S] L :=
{ liftRingHom φ.toRingHom hφ with
commutes' := fun r => by
simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r,
liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] }
#align ratfunc.lift_alg_hom RatFunc.liftAlgHom
theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) :
liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ -- Porting note: gave explicitly the `hφ`
#align ratfunc.lift_alg_hom_apply_of_fraction_ring_mk RatFunc.liftAlgHom_apply_ofFractionRing_mk
theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ)
(hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftAlgHom φ hφ') :=
liftMonoidWithZeroHom_injective _ hφ
#align ratfunc.lift_alg_hom_injective RatFunc.liftAlgHom_injective
@[simp]
theorem liftAlgHom_apply_div' (p q : K[X]) :
liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div' _ hφ _ _ -- Porting note: gave explicitly the `hφ`
theorem liftAlgHom_apply_div (p q : K[X]) :
liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div _ hφ _ _ -- Porting note: gave explicitly the `hφ`
#align ratfunc.lift_alg_hom_apply_div RatFunc.liftAlgHom_apply_div
end LiftAlgHom
variable (K)
/-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/
instance : IsFractionRing K[X] (RatFunc K) where
map_units' y := by
rw [← ofFractionRing_algebraMap]
exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y)
exists_of_eq {x y} := by
rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap]
exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h)
surj' := by
rintro ⟨z⟩
convert IsLocalization.surj K[X]⁰ z
-- Porting note: `ext ⟨x, y⟩` no longer necessary
simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul]
rw [ofFractionRing.injEq] -- Porting note: added
variable {K}
@[simp]
theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q')
(H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' :=
fun {p q p' q'} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) :
(RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by
rw [← mk_eq_div, liftOn_mk _ _ f f0 @H']
#align ratfunc.lift_on_div RatFunc.liftOn_div
@[simp]
theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H) :
(RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by
rw [RatFunc.liftOn', liftOn_div _ _ _ f0]
apply liftOn_condition_of_liftOn'_condition H -- Porting note: `exact` did not work. Also,
-- was `@H` that still works, but is not needed.
#align ratfunc.lift_on'_div RatFunc.liftOn'_div
/-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`,
then `P` holds on all elements of `RatFunc K`.
See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`.
-/
protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K)
(f : ∀ (p q : K[X]) (hq : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x :=
x.induction_on' fun p q hq => by simpa using f p q hq
#align ratfunc.induction_on RatFunc.induction_on
theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) :
-- Porting note: I gave explicitly the argument `(FractionRing K[X])`
ofFractionRing (IsLocalization.mk' (FractionRing K[X]) x y) =
IsLocalization.mk' (RatFunc K) x y := by
rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div]
#align ratfunc.of_fraction_ring_mk' RatFunc.ofFractionRing_mk'
@[simp]
theorem ofFractionRing_eq :
(ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ :=
funext fun x =>
Localization.induction_on x fun x => by
simp only [IsLocalization.algEquiv_apply, IsLocalization.ringEquivOfRingEquiv_apply,
Localization.mk_eq_mk'_apply, IsLocalization.map_mk', ofFractionRing_mk',
RingEquiv.coe_toRingHom, RingEquiv.refl_apply, SetLike.eta]
-- Porting note: added following `simp`. The previous one can be squeezed.
simp only [IsFractionRing.mk'_eq_div, RingHom.id_apply, Subtype.coe_eta]
#align ratfunc.of_fraction_ring_eq RatFunc.ofFractionRing_eq
@[simp]
theorem toFractionRing_eq :
(toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ :=
funext fun ⟨x⟩ =>
Localization.induction_on x fun x => by
simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply,
IsLocalization.ringEquivOfRingEquiv_apply, IsLocalization.map_mk',
RingEquiv.coe_toRingHom, RingEquiv.refl_apply, SetLike.eta]
-- Porting note: added following `simp`. The previous one can be squeezed.
simp only [IsFractionRing.mk'_eq_div, RingHom.id_apply, Subtype.coe_eta]
#align ratfunc.to_fraction_ring_eq RatFunc.toFractionRing_eq
@[simp]
theorem toFractionRingRingEquiv_symm_eq :
(toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by
ext x
simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv']
#align ratfunc.to_fraction_ring_ring_equiv_symm_eq RatFunc.toFractionRingRingEquiv_symm_eq
end IsDomain
end IsFractionRing
end CommRing
section NumDenom
/-! ### Numerator and denominator -/
open GCDMonoid Polynomial
variable [Field K]
set_option tactic.skipAssignedInstances false in
/-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field,
normalized such that the denominator is monic. -/
def numDenom (x : RatFunc K) : K[X] × K[X] :=
x.liftOn'
(fun p q =>
if q = 0 then ⟨0, 1⟩
else
let r := gcd p q
⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r),
Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩)
(by
intros p q a hq ha
dsimp
rw [if_neg hq, if_neg (mul_ne_zero ha hq)]
have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha
have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha'
simp only [Prod.ext_iff, gcd_mul_left, normalize_apply, Polynomial.coe_normUnit, mul_assoc,
CommGroupWithZero.coe_normUnit _ ha']
have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq
have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by
rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add]
exact hdeg
have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p :=
(C_mul_dvd hainv).mpr (gcd_dvd_left p q)
have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q :=
(C_mul_dvd hainv).mpr (gcd_dvd_right p q)
-- Porting note: added `simp only [...]` and `rw [mul_assoc]`
-- Porting note: note the unfolding of `normalize` and `normUnit`!
simp only [normalize, normUnit, coe_normUnit, leadingCoeff_eq_zero, MonoidWithZeroHom.coe_mk,
ZeroHom.coe_mk, ha, dite_false, Units.val_inv_eq_inv_val, Units.val_mk0]
rw [mul_assoc]
rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq,
leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul,
Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ←
mul_assoc, ← Polynomial.C_mul]
constructor <;> congr <;>
rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, _root_.mul_inv_cancel ha',
one_mul, inv_div])
#align ratfunc.num_denom RatFunc.numDenom
@[simp]
theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
numDenom (algebraMap _ _ p / algebraMap _ _ q) =
(Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q),
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by
rw [numDenom, liftOn'_div, if_neg hq]
intro p
rw [if_pos rfl, if_neg (one_ne_zero' K[X])]
simp
#align ratfunc.num_denom_div RatFunc.numDenom_div
/-- `RatFunc.num` is the numerator of a rational function,
normalized such that the denominator is monic. -/
def num (x : RatFunc K) : K[X] :=
x.numDenom.1
#align ratfunc.num RatFunc.num
private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
num (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by
rw [num, numDenom_div _ hq]
@[simp]
theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp
#align ratfunc.num_zero RatFunc.num_zero
@[simp]
theorem num_div (p q : K[X]) :
num (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by
by_cases hq : q = 0
· simp [hq]
· exact num_div' p hq
#align ratfunc.num_div RatFunc.num_div
@[simp]
theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp
#align ratfunc.num_one RatFunc.num_one
@[simp]
theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp
#align ratfunc.num_algebra_map RatFunc.num_algebraMap
theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by
rw [num_div _ q, C_mul_dvd]
· exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q)
· simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq
#align ratfunc.num_div_dvd RatFunc.num_div_dvd
/-- A version of `num_div_dvd` with the LHS in simp normal form -/
@[simp]
theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq
#align ratfunc.num_div_dvd' RatFunc.num_div_dvd'
/-- `RatFunc.denom` is the denominator of a rational function,
normalized such that it is monic. -/
def denom (x : RatFunc K) : K[X] :=
x.numDenom.2
#align ratfunc.denom RatFunc.denom
@[simp]
| Mathlib/FieldTheory/RatFunc/Basic.lean | 956 | 959 | theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
denom (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by |
rw [denom, numDenom_div _ hq]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Data.ENat.Lattice
import Mathlib.Data.Part
import Mathlib.Tactic.NormNum
#align_import data.nat.part_enat from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8"
/-!
# Natural numbers with infinity
The natural numbers and an extra `top` element `⊤`. This implementation uses `Part ℕ` as an
implementation. Use `ℕ∞` instead unless you care about computability.
## Main definitions
The following instances are defined:
* `OrderedAddCommMonoid PartENat`
* `CanonicallyOrderedAddCommMonoid PartENat`
* `CompleteLinearOrder PartENat`
There is no additive analogue of `MonoidWithZero`; if there were then `PartENat` could
be an `AddMonoidWithTop`.
* `toWithTop` : the map from `PartENat` to `ℕ∞`, with theorems that it plays well
with `+` and `≤`.
* `withTopAddEquiv : PartENat ≃+ ℕ∞`
* `withTopOrderIso : PartENat ≃o ℕ∞`
## Implementation details
`PartENat` is defined to be `Part ℕ`.
`+` and `≤` are defined on `PartENat`, but there is an issue with `*` because it's not
clear what `0 * ⊤` should be. `mul` is hence left undefined. Similarly `⊤ - ⊤` is ambiguous
so there is no `-` defined on `PartENat`.
Before the `open scoped Classical` line, various proofs are made with decidability assumptions.
This can cause issues -- see for example the non-simp lemma `toWithTopZero` proved by `rfl`,
followed by `@[simp] lemma toWithTopZero'` whose proof uses `convert`.
## Tags
PartENat, ℕ∞
-/
open Part hiding some
/-- Type of natural numbers with infinity (`⊤`) -/
def PartENat : Type :=
Part ℕ
#align part_enat PartENat
namespace PartENat
/-- The computable embedding `ℕ → PartENat`.
This coincides with the coercion `coe : ℕ → PartENat`, see `PartENat.some_eq_natCast`. -/
@[coe]
def some : ℕ → PartENat :=
Part.some
#align part_enat.some PartENat.some
instance : Zero PartENat :=
⟨some 0⟩
instance : Inhabited PartENat :=
⟨0⟩
instance : One PartENat :=
⟨some 1⟩
instance : Add PartENat :=
⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => get x h.1 + get y h.2⟩⟩
instance (n : ℕ) : Decidable (some n).Dom :=
isTrue trivial
@[simp]
theorem dom_some (x : ℕ) : (some x).Dom :=
trivial
#align part_enat.dom_some PartENat.dom_some
instance addCommMonoid : AddCommMonoid PartENat where
add := (· + ·)
zero := 0
add_comm x y := Part.ext' and_comm fun _ _ => add_comm _ _
zero_add x := Part.ext' (true_and_iff _) fun _ _ => zero_add _
add_zero x := Part.ext' (and_true_iff _) fun _ _ => add_zero _
add_assoc x y z := Part.ext' and_assoc fun _ _ => add_assoc _ _ _
nsmul := nsmulRec
instance : AddCommMonoidWithOne PartENat :=
{ PartENat.addCommMonoid with
one := 1
natCast := some
natCast_zero := rfl
natCast_succ := fun _ => Part.ext' (true_and_iff _).symm fun _ _ => rfl }
theorem some_eq_natCast (n : ℕ) : some n = n :=
rfl
#align part_enat.some_eq_coe PartENat.some_eq_natCast
instance : CharZero PartENat where
cast_injective := Part.some_injective
/-- Alias of `Nat.cast_inj` specialized to `PartENat` --/
theorem natCast_inj {x y : ℕ} : (x : PartENat) = y ↔ x = y :=
Nat.cast_inj
#align part_enat.coe_inj PartENat.natCast_inj
@[simp]
theorem dom_natCast (x : ℕ) : (x : PartENat).Dom :=
trivial
#align part_enat.dom_coe PartENat.dom_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem dom_ofNat (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)).Dom :=
trivial
@[simp]
theorem dom_zero : (0 : PartENat).Dom :=
trivial
@[simp]
theorem dom_one : (1 : PartENat).Dom :=
trivial
instance : CanLift PartENat ℕ (↑) Dom :=
⟨fun n hn => ⟨n.get hn, Part.some_get _⟩⟩
instance : LE PartENat :=
⟨fun x y => ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy⟩
instance : Top PartENat :=
⟨none⟩
instance : Bot PartENat :=
⟨0⟩
instance : Sup PartENat :=
⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => x.get h.1 ⊔ y.get h.2⟩⟩
theorem le_def (x y : PartENat) :
x ≤ y ↔ ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy :=
Iff.rfl
#align part_enat.le_def PartENat.le_def
@[elab_as_elim]
protected theorem casesOn' {P : PartENat → Prop} :
∀ a : PartENat, P ⊤ → (∀ n : ℕ, P (some n)) → P a :=
Part.induction_on
#align part_enat.cases_on' PartENat.casesOn'
@[elab_as_elim]
protected theorem casesOn {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P n) → P a := by
exact PartENat.casesOn'
#align part_enat.cases_on PartENat.casesOn
-- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later
theorem top_add (x : PartENat) : ⊤ + x = ⊤ :=
Part.ext' (false_and_iff _) fun h => h.left.elim
#align part_enat.top_add PartENat.top_add
-- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later
theorem add_top (x : PartENat) : x + ⊤ = ⊤ := by rw [add_comm, top_add]
#align part_enat.add_top PartENat.add_top
@[simp]
theorem natCast_get {x : PartENat} (h : x.Dom) : (x.get h : PartENat) = x := by
exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl
#align part_enat.coe_get PartENat.natCast_get
@[simp, norm_cast]
theorem get_natCast' (x : ℕ) (h : (x : PartENat).Dom) : get (x : PartENat) h = x := by
rw [← natCast_inj, natCast_get]
#align part_enat.get_coe' PartENat.get_natCast'
theorem get_natCast {x : ℕ} : get (x : PartENat) (dom_natCast x) = x :=
get_natCast' _ _
#align part_enat.get_coe PartENat.get_natCast
theorem coe_add_get {x : ℕ} {y : PartENat} (h : ((x : PartENat) + y).Dom) :
get ((x : PartENat) + y) h = x + get y h.2 := by
rfl
#align part_enat.coe_add_get PartENat.coe_add_get
@[simp]
theorem get_add {x y : PartENat} (h : (x + y).Dom) : get (x + y) h = x.get h.1 + y.get h.2 :=
rfl
#align part_enat.get_add PartENat.get_add
@[simp]
theorem get_zero (h : (0 : PartENat).Dom) : (0 : PartENat).get h = 0 :=
rfl
#align part_enat.get_zero PartENat.get_zero
@[simp]
theorem get_one (h : (1 : PartENat).Dom) : (1 : PartENat).get h = 1 :=
rfl
#align part_enat.get_one PartENat.get_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem get_ofNat' (x : ℕ) [x.AtLeastTwo] (h : (no_index (OfNat.ofNat x : PartENat)).Dom) :
Part.get (no_index (OfNat.ofNat x : PartENat)) h = (no_index (OfNat.ofNat x)) :=
get_natCast' x h
nonrec theorem get_eq_iff_eq_some {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = some b :=
get_eq_iff_eq_some
#align part_enat.get_eq_iff_eq_some PartENat.get_eq_iff_eq_some
theorem get_eq_iff_eq_coe {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = b := by
rw [get_eq_iff_eq_some]
rfl
#align part_enat.get_eq_iff_eq_coe PartENat.get_eq_iff_eq_coe
theorem dom_of_le_of_dom {x y : PartENat} : x ≤ y → y.Dom → x.Dom := fun ⟨h, _⟩ => h
#align part_enat.dom_of_le_of_dom PartENat.dom_of_le_of_dom
theorem dom_of_le_some {x : PartENat} {y : ℕ} (h : x ≤ some y) : x.Dom :=
dom_of_le_of_dom h trivial
#align part_enat.dom_of_le_some PartENat.dom_of_le_some
theorem dom_of_le_natCast {x : PartENat} {y : ℕ} (h : x ≤ y) : x.Dom := by
exact dom_of_le_some h
#align part_enat.dom_of_le_coe PartENat.dom_of_le_natCast
instance decidableLe (x y : PartENat) [Decidable x.Dom] [Decidable y.Dom] : Decidable (x ≤ y) :=
if hx : x.Dom then
decidable_of_decidable_of_iff (by rw [le_def])
else
if hy : y.Dom then isFalse fun h => hx <| dom_of_le_of_dom h hy
else isTrue ⟨fun h => (hy h).elim, fun h => (hy h).elim⟩
#align part_enat.decidable_le PartENat.decidableLe
-- Porting note: Removed. Use `Nat.castAddMonoidHom` instead.
#noalign part_enat.coe_hom
#noalign part_enat.coe_coe_hom
instance partialOrder : PartialOrder PartENat where
le := (· ≤ ·)
le_refl _ := ⟨id, fun _ => le_rfl⟩
le_trans := fun _ _ _ ⟨hxy₁, hxy₂⟩ ⟨hyz₁, hyz₂⟩ =>
⟨hxy₁ ∘ hyz₁, fun _ => le_trans (hxy₂ _) (hyz₂ _)⟩
lt_iff_le_not_le _ _ := Iff.rfl
le_antisymm := fun _ _ ⟨hxy₁, hxy₂⟩ ⟨hyx₁, hyx₂⟩ =>
Part.ext' ⟨hyx₁, hxy₁⟩ fun _ _ => le_antisymm (hxy₂ _) (hyx₂ _)
theorem lt_def (x y : PartENat) : x < y ↔ ∃ hx : x.Dom, ∀ hy : y.Dom, x.get hx < y.get hy := by
rw [lt_iff_le_not_le, le_def, le_def, not_exists]
constructor
· rintro ⟨⟨hyx, H⟩, h⟩
by_cases hx : x.Dom
· use hx
intro hy
specialize H hy
specialize h fun _ => hy
rw [not_forall] at h
cases' h with hx' h
rw [not_le] at h
exact h
· specialize h fun hx' => (hx hx').elim
rw [not_forall] at h
cases' h with hx' h
exact (hx hx').elim
· rintro ⟨hx, H⟩
exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩
#align part_enat.lt_def PartENat.lt_def
noncomputable instance orderedAddCommMonoid : OrderedAddCommMonoid PartENat :=
{ PartENat.partialOrder, PartENat.addCommMonoid with
add_le_add_left := fun a b ⟨h₁, h₂⟩ c =>
PartENat.casesOn c (by simp [top_add]) fun c =>
⟨fun h => And.intro (dom_natCast _) (h₁ h.2), fun h => by
simpa only [coe_add_get] using add_le_add_left (h₂ _) c⟩ }
instance semilatticeSup : SemilatticeSup PartENat :=
{ PartENat.partialOrder with
sup := (· ⊔ ·)
le_sup_left := fun _ _ => ⟨And.left, fun _ => le_sup_left⟩
le_sup_right := fun _ _ => ⟨And.right, fun _ => le_sup_right⟩
sup_le := fun _ _ _ ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ =>
⟨fun hz => ⟨hx₁ hz, hy₁ hz⟩, fun _ => sup_le (hx₂ _) (hy₂ _)⟩ }
#align part_enat.semilattice_sup PartENat.semilatticeSup
instance orderBot : OrderBot PartENat where
bot := ⊥
bot_le _ := ⟨fun _ => trivial, fun _ => Nat.zero_le _⟩
#align part_enat.order_bot PartENat.orderBot
instance orderTop : OrderTop PartENat where
top := ⊤
le_top _ := ⟨fun h => False.elim h, fun hy => False.elim hy⟩
#align part_enat.order_top PartENat.orderTop
instance : ZeroLEOneClass PartENat where
zero_le_one := bot_le
/-- Alias of `Nat.cast_le` specialized to `PartENat` --/
theorem coe_le_coe {x y : ℕ} : (x : PartENat) ≤ y ↔ x ≤ y := Nat.cast_le
#align part_enat.coe_le_coe PartENat.coe_le_coe
/-- Alias of `Nat.cast_lt` specialized to `PartENat` --/
theorem coe_lt_coe {x y : ℕ} : (x : PartENat) < y ↔ x < y := Nat.cast_lt
#align part_enat.coe_lt_coe PartENat.coe_lt_coe
@[simp]
theorem get_le_get {x y : PartENat} {hx : x.Dom} {hy : y.Dom} : x.get hx ≤ y.get hy ↔ x ≤ y := by
conv =>
lhs
rw [← coe_le_coe, natCast_get, natCast_get]
#align part_enat.get_le_get PartENat.get_le_get
theorem le_coe_iff (x : PartENat) (n : ℕ) : x ≤ n ↔ ∃ h : x.Dom, x.get h ≤ n := by
show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n
simp only [forall_prop_of_true, dom_natCast, get_natCast']
#align part_enat.le_coe_iff PartENat.le_coe_iff
| Mathlib/Data/Nat/PartENat.lean | 329 | 330 | theorem lt_coe_iff (x : PartENat) (n : ℕ) : x < n ↔ ∃ h : x.Dom, x.get h < n := by |
simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast]
|
/-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison, Johannes Hölzl, Reid Barton
-/
import Mathlib.CategoryTheory.Category.Init
import Mathlib.Combinatorics.Quiver.Basic
import Mathlib.Tactic.PPWithUniv
import Mathlib.Tactic.Common
#align_import category_theory.category.basic from "leanprover-community/mathlib"@"2efd2423f8d25fa57cf7a179f5d8652ab4d0df44"
/-!
# Categories
Defines a category, as a type class parametrised by the type of objects.
## Notations
Introduces notations in the `CategoryTheory` scope
* `X ⟶ Y` for the morphism spaces (type as `\hom`),
* `𝟙 X` for the identity morphism on `X` (type as `\b1`),
* `f ≫ g` for composition in the 'arrows' convention (type as `\gg`).
Users may like to add `g ⊚ f` for composition in the standard convention, using
```lean
local notation g ` ⊚ `:80 f:80 := category.comp f g -- type as \oo
```
## Porting note
I am experimenting with using the `aesop` tactic as a replacement for `tidy`.
-/
library_note "CategoryTheory universes"
/--
The typeclass `Category C` describes morphisms associated to objects of type `C : Type u`.
The universe levels of the objects and morphisms are independent, and will often need to be
specified explicitly, as `Category.{v} C`.
Typically any concrete example will either be a `SmallCategory`, where `v = u`,
which can be introduced as
```
universe u
variable {C : Type u} [SmallCategory C]
```
or a `LargeCategory`, where `u = v+1`, which can be introduced as
```
universe u
variable {C : Type (u+1)} [LargeCategory C]
```
In order for the library to handle these cases uniformly,
we generally work with the unconstrained `Category.{v u}`,
for which objects live in `Type u` and morphisms live in `Type v`.
Because the universe parameter `u` for the objects can be inferred from `C`
when we write `Category C`, while the universe parameter `v` for the morphisms
can not be automatically inferred, through the category theory library
we introduce universe parameters with morphism levels listed first,
as in
```
universe v u
```
or
```
universe v₁ v₂ u₁ u₂
```
when multiple independent universes are needed.
This has the effect that we can simply write `Category.{v} C`
(that is, only specifying a single parameter) while `u` will be inferred.
Often, however, it's not even necessary to include the `.{v}`.
(Although it was in earlier versions of Lean.)
If it is omitted a "free" universe will be used.
-/
namespace Std.Tactic.Ext
open Lean Elab Tactic
/-- A wrapper for `ext` that we can pass to `aesop`. -/
def extCore' : TacticM Unit := do
evalTactic (← `(tactic| ext))
end Std.Tactic.Ext
universe v u
namespace CategoryTheory
/-- A preliminary structure on the way to defining a category,
containing the data, but none of the axioms. -/
@[pp_with_univ]
class CategoryStruct (obj : Type u) extends Quiver.{v + 1} obj : Type max u (v + 1) where
/-- The identity morphism on an object. -/
id : ∀ X : obj, Hom X X
/-- Composition of morphisms in a category, written `f ≫ g`. -/
comp : ∀ {X Y Z : obj}, (X ⟶ Y) → (Y ⟶ Z) → (X ⟶ Z)
#align category_theory.category_struct CategoryTheory.CategoryStruct
initialize_simps_projections CategoryStruct (-toQuiver_Hom)
/-- Notation for the identity morphism in a category. -/
scoped notation "𝟙" => CategoryStruct.id -- type as \b1
/-- Notation for composition of morphisms in a category. -/
scoped infixr:80 " ≫ " => CategoryStruct.comp -- type as \gg
/-- Close the main goal with `sorry` if its type contains `sorry`, and fail otherwise. -/
syntax (name := sorryIfSorry) "sorry_if_sorry" : tactic
open Lean Meta Elab.Tactic in
@[tactic sorryIfSorry, inherit_doc sorryIfSorry] def evalSorryIfSorry : Tactic := fun _ => do
let goalType ← getMainTarget
if goalType.hasSorry then
closeMainGoal (← mkSorry goalType true)
else
throwError "The goal does not contain `sorry`"
/--
A thin wrapper for `aesop` which adds the `CategoryTheory` rule set and
allows `aesop` to look through semireducible definitions when calling `intros`.
It also turns on `zetaDelta` in the `simp` config, allowing `aesop_cat` to unfold any `let`s.
This tactic fails when it is unable to solve the goal, making it suitable for
use in auto-params.
-/
macro (name := aesop_cat) "aesop_cat" c:Aesop.tactic_clause* : tactic =>
`(tactic|
first | sorry_if_sorry |
aesop $c* (config := { introsTransparency? := some .default, terminal := true })
(simp_config := { decide := true, zetaDelta := true })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))
/--
We also use `aesop_cat?` to pass along a `Try this` suggestion when using `aesop_cat`
-/
macro (name := aesop_cat?) "aesop_cat?" c:Aesop.tactic_clause* : tactic =>
`(tactic|
first | sorry_if_sorry |
aesop? $c* (config := { introsTransparency? := some .default, terminal := true })
(simp_config := { decide := true, zetaDelta := true })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))
/--
A variant of `aesop_cat` which does not fail when it is unable to solve the
goal. Use this only for exploration! Nonterminal `aesop` is even worse than
nonterminal `simp`.
-/
macro (name := aesop_cat_nonterminal) "aesop_cat_nonterminal" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c* (config := { introsTransparency? := some .default, warnOnNonterminal := false })
(simp_config := { decide := true, zetaDelta := true })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))
-- We turn on `ext` inside `aesop_cat`.
attribute [aesop safe tactic (rule_sets := [CategoryTheory])] Std.Tactic.Ext.extCore'
-- We turn on the mathlib version of `rfl` inside `aesop_cat`.
attribute [aesop safe tactic (rule_sets := [CategoryTheory])] Mathlib.Tactic.rflTac
-- Porting note:
-- Workaround for issue discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Failure.20of.20TC.20search.20in.20.60simp.60.20with.20.60etaExperiment.60.2E
-- now that etaExperiment is always on.
attribute [aesop safe (rule_sets := [CategoryTheory])] Subsingleton.elim
/-- The typeclass `Category C` describes morphisms associated to objects of type `C`.
The universe levels of the objects and morphisms are unconstrained, and will often need to be
specified explicitly, as `Category.{v} C`. (See also `LargeCategory` and `SmallCategory`.)
See <https://stacks.math.columbia.edu/tag/0014>.
-/
@[pp_with_univ]
class Category (obj : Type u) extends CategoryStruct.{v} obj : Type max u (v + 1) where
/-- Identity morphisms are left identities for composition. -/
id_comp : ∀ {X Y : obj} (f : X ⟶ Y), 𝟙 X ≫ f = f := by aesop_cat
/-- Identity morphisms are right identities for composition. -/
comp_id : ∀ {X Y : obj} (f : X ⟶ Y), f ≫ 𝟙 Y = f := by aesop_cat
/-- Composition in a category is associative. -/
assoc : ∀ {W X Y Z : obj} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z), (f ≫ g) ≫ h = f ≫ g ≫ h := by
aesop_cat
#align category_theory.category CategoryTheory.Category
#align category_theory.category.assoc CategoryTheory.Category.assoc
#align category_theory.category.comp_id CategoryTheory.Category.comp_id
#align category_theory.category.id_comp CategoryTheory.Category.id_comp
attribute [simp] Category.id_comp Category.comp_id Category.assoc
attribute [trans] CategoryStruct.comp
example {C} [Category C] {X Y : C} (f : X ⟶ Y) : 𝟙 X ≫ f = f := by simp
example {C} [Category C] {X Y : C} (f : X ⟶ Y) : f ≫ 𝟙 Y = f := by simp
/-- A `LargeCategory` has objects in one universe level higher than the universe level of
the morphisms. It is useful for examples such as the category of types, or the category
of groups, etc.
-/
abbrev LargeCategory (C : Type (u + 1)) : Type (u + 1) := Category.{u} C
#align category_theory.large_category CategoryTheory.LargeCategory
/-- A `SmallCategory` has objects and morphisms in the same universe level.
-/
abbrev SmallCategory (C : Type u) : Type (u + 1) := Category.{u} C
#align category_theory.small_category CategoryTheory.SmallCategory
section
variable {C : Type u} [Category.{v} C] {X Y Z : C}
initialize_simps_projections Category (-Hom)
/-- postcompose an equation between morphisms by another morphism -/
theorem eq_whisker {f g : X ⟶ Y} (w : f = g) (h : Y ⟶ Z) : f ≫ h = g ≫ h := by rw [w]
#align category_theory.eq_whisker CategoryTheory.eq_whisker
/-- precompose an equation between morphisms by another morphism -/
theorem whisker_eq (f : X ⟶ Y) {g h : Y ⟶ Z} (w : g = h) : f ≫ g = f ≫ h := by rw [w]
#align category_theory.whisker_eq CategoryTheory.whisker_eq
/--
Notation for whiskering an equation by a morphism (on the right).
If `f g : X ⟶ Y` and `w : f = g` and `h : Y ⟶ Z`, then `w =≫ h : f ≫ h = g ≫ h`.
-/
scoped infixr:80 " =≫ " => eq_whisker
/--
Notation for whiskering an equation by a morphism (on the left).
If `g h : Y ⟶ Z` and `w : g = h` and `h : X ⟶ Y`, then `f ≫= w : f ≫ g = f ≫ h`.
-/
scoped infixr:80 " ≫= " => whisker_eq
theorem eq_of_comp_left_eq {f g : X ⟶ Y} (w : ∀ {Z : C} (h : Y ⟶ Z), f ≫ h = g ≫ h) :
f = g := by
convert w (𝟙 Y) <;> simp
#align category_theory.eq_of_comp_left_eq CategoryTheory.eq_of_comp_left_eq
theorem eq_of_comp_right_eq {f g : Y ⟶ Z} (w : ∀ {X : C} (h : X ⟶ Y), h ≫ f = h ≫ g) :
f = g := by
convert w (𝟙 Y) <;> simp
#align category_theory.eq_of_comp_right_eq CategoryTheory.eq_of_comp_right_eq
theorem eq_of_comp_left_eq' (f g : X ⟶ Y)
(w : (fun {Z} (h : Y ⟶ Z) => f ≫ h) = fun {Z} (h : Y ⟶ Z) => g ≫ h) : f = g :=
eq_of_comp_left_eq @fun Z h => by convert congr_fun (congr_fun w Z) h
#align category_theory.eq_of_comp_left_eq' CategoryTheory.eq_of_comp_left_eq'
theorem eq_of_comp_right_eq' (f g : Y ⟶ Z)
(w : (fun {X} (h : X ⟶ Y) => h ≫ f) = fun {X} (h : X ⟶ Y) => h ≫ g) : f = g :=
eq_of_comp_right_eq @fun X h => by convert congr_fun (congr_fun w X) h
#align category_theory.eq_of_comp_right_eq' CategoryTheory.eq_of_comp_right_eq'
theorem id_of_comp_left_id (f : X ⟶ X) (w : ∀ {Y : C} (g : X ⟶ Y), f ≫ g = g) : f = 𝟙 X := by
convert w (𝟙 X)
simp
#align category_theory.id_of_comp_left_id CategoryTheory.id_of_comp_left_id
theorem id_of_comp_right_id (f : X ⟶ X) (w : ∀ {Y : C} (g : Y ⟶ X), g ≫ f = g) : f = 𝟙 X := by
convert w (𝟙 X)
simp
#align category_theory.id_of_comp_right_id CategoryTheory.id_of_comp_right_id
theorem comp_ite {P : Prop} [Decidable P] {X Y Z : C} (f : X ⟶ Y) (g g' : Y ⟶ Z) :
(f ≫ if P then g else g') = if P then f ≫ g else f ≫ g' := by aesop
#align category_theory.comp_ite CategoryTheory.comp_ite
theorem ite_comp {P : Prop} [Decidable P] {X Y Z : C} (f f' : X ⟶ Y) (g : Y ⟶ Z) :
(if P then f else f') ≫ g = if P then f ≫ g else f' ≫ g := by aesop
#align category_theory.ite_comp CategoryTheory.ite_comp
theorem comp_dite {P : Prop} [Decidable P]
{X Y Z : C} (f : X ⟶ Y) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) :
(f ≫ if h : P then g h else g' h) = if h : P then f ≫ g h else f ≫ g' h := by aesop
#align category_theory.comp_dite CategoryTheory.comp_dite
theorem dite_comp {P : Prop} [Decidable P]
{X Y Z : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (g : Y ⟶ Z) :
(if h : P then f h else f' h) ≫ g = if h : P then f h ≫ g else f' h ≫ g := by aesop
#align category_theory.dite_comp CategoryTheory.dite_comp
/-- A morphism `f` is an epimorphism if it can be cancelled when precomposed:
`f ≫ g = f ≫ h` implies `g = h`.
See <https://stacks.math.columbia.edu/tag/003B>.
-/
class Epi (f : X ⟶ Y) : Prop where
/-- A morphism `f` is an epimorphism if it can be cancelled when precomposed. -/
left_cancellation : ∀ {Z : C} (g h : Y ⟶ Z), f ≫ g = f ≫ h → g = h
#align category_theory.epi CategoryTheory.Epi
/-- A morphism `f` is a monomorphism if it can be cancelled when postcomposed:
`g ≫ f = h ≫ f` implies `g = h`.
See <https://stacks.math.columbia.edu/tag/003B>.
-/
class Mono (f : X ⟶ Y) : Prop where
/-- A morphism `f` is a monomorphism if it can be cancelled when postcomposed. -/
right_cancellation : ∀ {Z : C} (g h : Z ⟶ X), g ≫ f = h ≫ f → g = h
#align category_theory.mono CategoryTheory.Mono
instance (X : C) : Epi (𝟙 X) :=
⟨fun g h w => by aesop⟩
instance (X : C) : Mono (𝟙 X) :=
⟨fun g h w => by aesop⟩
theorem cancel_epi (f : X ⟶ Y) [Epi f] {g h : Y ⟶ Z} : f ≫ g = f ≫ h ↔ g = h :=
⟨fun p => Epi.left_cancellation g h p, congr_arg _⟩
#align category_theory.cancel_epi CategoryTheory.cancel_epi
theorem cancel_mono (f : X ⟶ Y) [Mono f] {g h : Z ⟶ X} : g ≫ f = h ≫ f ↔ g = h :=
-- Porting note: in Lean 3 we could just write `congr_arg _` here.
⟨fun p => Mono.right_cancellation g h p, congr_arg (fun k => k ≫ f)⟩
#align category_theory.cancel_mono CategoryTheory.cancel_mono
theorem cancel_epi_id (f : X ⟶ Y) [Epi f] {h : Y ⟶ Y} : f ≫ h = f ↔ h = 𝟙 Y := by
convert cancel_epi f
simp
#align category_theory.cancel_epi_id CategoryTheory.cancel_epi_id
theorem cancel_mono_id (f : X ⟶ Y) [Mono f] {g : X ⟶ X} : g ≫ f = f ↔ g = 𝟙 X := by
convert cancel_mono f
simp
#align category_theory.cancel_mono_id CategoryTheory.cancel_mono_id
theorem epi_comp {X Y Z : C} (f : X ⟶ Y) [Epi f] (g : Y ⟶ Z) [Epi g] : Epi (f ≫ g) := by
constructor
intro Z a b w
apply (cancel_epi g).1
apply (cancel_epi f).1
simpa using w
#align category_theory.epi_comp CategoryTheory.epi_comp
| Mathlib/CategoryTheory/Category/Basic.lean | 333 | 338 | theorem mono_comp {X Y Z : C} (f : X ⟶ Y) [Mono f] (g : Y ⟶ Z) [Mono g] : Mono (f ≫ g) := by |
constructor
intro Z a b w
apply (cancel_mono f).1
apply (cancel_mono g).1
simpa using w
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.CliffordAlgebra.Even
import Mathlib.LinearAlgebra.QuadraticForm.Prod
import Mathlib.Tactic.LiftLets
#align_import linear_algebra.clifford_algebra.even_equiv from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2"
/-!
# Isomorphisms with the even subalgebra of a Clifford algebra
This file provides some notable isomorphisms regarding the even subalgebra, `CliffordAlgebra.even`.
## Main definitions
* `CliffordAlgebra.equivEven`: Every Clifford algebra is isomorphic as an algebra to the even
subalgebra of a Clifford algebra with one more dimension.
* `CliffordAlgebra.EquivEven.Q'`: The quadratic form used by this "one-up" algebra.
* `CliffordAlgebra.toEven`: The simp-normal form of the forward direction of this isomorphism.
* `CliffordAlgebra.ofEven`: The simp-normal form of the reverse direction of this isomorphism.
* `CliffordAlgebra.evenEquivEvenNeg`: Every even subalgebra is isomorphic to the even subalgebra
of the Clifford algebra with negated quadratic form.
* `CliffordAlgebra.evenToNeg`: The simp-normal form of each direction of this isomorphism.
## Main results
* `CliffordAlgebra.coe_toEven_reverse_involute`: the behavior of `CliffordAlgebra.toEven` on the
"Clifford conjugate", that is `CliffordAlgebra.reverse` composed with
`CliffordAlgebra.involute`.
-/
namespace CliffordAlgebra
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
variable (Q : QuadraticForm R M)
/-! ### Constructions needed for `CliffordAlgebra.equivEven` -/
namespace EquivEven
/-- The quadratic form on the augmented vector space `M × R` sending `v + r•e0` to `Q v - r^2`. -/
abbrev Q' : QuadraticForm R (M × R) :=
Q.prod <| -@QuadraticForm.sq R _
set_option linter.uppercaseLean3 false in
#align clifford_algebra.equiv_even.Q' CliffordAlgebra.EquivEven.Q'
theorem Q'_apply (m : M × R) : Q' Q m = Q m.1 - m.2 * m.2 :=
(sub_eq_add_neg _ _).symm
set_option linter.uppercaseLean3 false in
#align clifford_algebra.equiv_even.Q'_apply CliffordAlgebra.EquivEven.Q'_apply
/-- The unit vector in the new dimension -/
def e0 : CliffordAlgebra (Q' Q) :=
ι (Q' Q) (0, 1)
#align clifford_algebra.equiv_even.e0 CliffordAlgebra.EquivEven.e0
/-- The embedding from the existing vector space -/
def v : M →ₗ[R] CliffordAlgebra (Q' Q) :=
ι (Q' Q) ∘ₗ LinearMap.inl _ _ _
#align clifford_algebra.equiv_even.v CliffordAlgebra.EquivEven.v
| Mathlib/LinearAlgebra/CliffordAlgebra/EvenEquiv.lean | 69 | 71 | theorem ι_eq_v_add_smul_e0 (m : M) (r : R) : ι (Q' Q) (m, r) = v Q m + r • e0 Q := by |
rw [e0, v, LinearMap.comp_apply, LinearMap.inl_apply, ← LinearMap.map_smul, Prod.smul_mk,
smul_zero, smul_eq_mul, mul_one, ← LinearMap.map_add, Prod.mk_add_mk, zero_add, add_zero]
|
/-
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]
| Mathlib/RingTheory/FractionalIdeal/Operations.lean | 350 | 351 | theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by |
simpa only [Ideal.one_eq_top] using coeIdeal_inj
|
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.ULift
import Mathlib.Data.ZMod.Defs
import Mathlib.SetTheory.Cardinal.PartENat
#align_import set_theory.cardinal.finite from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8"
/-!
# Finite Cardinality Functions
## Main Definitions
* `Nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `Nat.card α = 0`.
* `PartENat.card α` is the cardinality of `α` as an extended natural number
(using `Part ℕ`). If `α` is infinite, `PartENat.card α = ⊤`.
-/
set_option autoImplicit true
open Cardinal Function
noncomputable section
variable {α β : Type*}
namespace Nat
/-- `Nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `Nat.card α = 0`. -/
protected def card (α : Type*) : ℕ :=
toNat (mk α)
#align nat.card Nat.card
@[simp]
theorem card_eq_fintype_card [Fintype α] : Nat.card α = Fintype.card α :=
mk_toNat_eq_card
#align nat.card_eq_fintype_card Nat.card_eq_fintype_card
/-- Because this theorem takes `Fintype α` as a non-instance argument, it can be used in particular
when `Fintype.card` ends up with different instance than the one found by inference -/
theorem _root_.Fintype.card_eq_nat_card {_ : Fintype α} : Fintype.card α = Nat.card α :=
mk_toNat_eq_card.symm
lemma card_eq_finsetCard (s : Finset α) : Nat.card s = s.card := by
simp only [Nat.card_eq_fintype_card, Fintype.card_coe]
lemma card_eq_card_toFinset (s : Set α) [Fintype s] : Nat.card s = s.toFinset.card := by
simp only [← Nat.card_eq_finsetCard, s.mem_toFinset]
lemma card_eq_card_finite_toFinset {s : Set α} (hs : s.Finite) : Nat.card s = hs.toFinset.card := by
simp only [← Nat.card_eq_finsetCard, hs.mem_toFinset]
@[simp] theorem card_of_isEmpty [IsEmpty α] : Nat.card α = 0 := by simp [Nat.card]
#align nat.card_of_is_empty Nat.card_of_isEmpty
@[simp] lemma card_eq_zero_of_infinite [Infinite α] : Nat.card α = 0 := mk_toNat_of_infinite
#align nat.card_eq_zero_of_infinite Nat.card_eq_zero_of_infinite
lemma _root_.Set.Infinite.card_eq_zero {s : Set α} (hs : s.Infinite) : Nat.card s = 0 :=
@card_eq_zero_of_infinite _ hs.to_subtype
lemma card_eq_zero : Nat.card α = 0 ↔ IsEmpty α ∨ Infinite α := by
simp [Nat.card, mk_eq_zero_iff, aleph0_le_mk_iff]
lemma card_ne_zero : Nat.card α ≠ 0 ↔ Nonempty α ∧ Finite α := by simp [card_eq_zero, not_or]
lemma card_pos_iff : 0 < Nat.card α ↔ Nonempty α ∧ Finite α := by
simp [Nat.card, mk_eq_zero_iff, mk_lt_aleph0_iff]
@[simp] lemma card_pos [Nonempty α] [Finite α] : 0 < Nat.card α := card_pos_iff.2 ⟨‹_›, ‹_›⟩
theorem finite_of_card_ne_zero (h : Nat.card α ≠ 0) : Finite α := (card_ne_zero.1 h).2
#align nat.finite_of_card_ne_zero Nat.finite_of_card_ne_zero
theorem card_congr (f : α ≃ β) : Nat.card α = Nat.card β :=
Cardinal.toNat_congr f
#align nat.card_congr Nat.card_congr
lemma card_le_card_of_injective {α : Type u} {β : Type v} [Finite β] (f : α → β)
(hf : Injective f) : Nat.card α ≤ Nat.card β := by
simpa using toNat_le_toNat (lift_mk_le_lift_mk_of_injective hf) (by simp [lt_aleph0_of_finite])
lemma card_le_card_of_surjective {α : Type u} {β : Type v} [Finite α] (f : α → β)
(hf : Surjective f) : Nat.card β ≤ Nat.card α := by
have : lift.{u} #β ≤ lift.{v} #α := mk_le_of_surjective (ULift.map_surjective.2 hf)
simpa using toNat_le_toNat this (by simp [lt_aleph0_of_finite])
theorem card_eq_of_bijective (f : α → β) (hf : Function.Bijective f) : Nat.card α = Nat.card β :=
card_congr (Equiv.ofBijective f hf)
#align nat.card_eq_of_bijective Nat.card_eq_of_bijective
theorem card_eq_of_equiv_fin {α : Type*} {n : ℕ} (f : α ≃ Fin n) : Nat.card α = n := by
simpa only [card_eq_fintype_card, Fintype.card_fin] using card_congr f
#align nat.card_eq_of_equiv_fin Nat.card_eq_of_equiv_fin
section Set
open Set
variable {s t : Set α}
lemma card_mono (ht : t.Finite) (h : s ⊆ t) : Nat.card s ≤ Nat.card t :=
toNat_le_toNat (mk_le_mk_of_subset h) ht.lt_aleph0
lemma card_image_le (hs : s.Finite) : Nat.card (f '' s) ≤ Nat.card s :=
have := hs.to_subtype; card_le_card_of_surjective (imageFactorization f s) surjective_onto_image
lemma card_image_of_injOn (hf : s.InjOn f) : Nat.card (f '' s) = Nat.card s := by
classical
obtain hs | hs := s.finite_or_infinite
· have := hs.fintype
have := fintypeImage s f
simp_rw [Nat.card_eq_fintype_card, Set.card_image_of_inj_on hf]
· have := hs.to_subtype
have := (hs.image hf).to_subtype
simp [Nat.card_eq_zero_of_infinite]
lemma card_image_of_injective (hf : Injective f) (s : Set α) :
Nat.card (f '' s) = Nat.card s := card_image_of_injOn hf.injOn
lemma card_image_equiv (e : α ≃ β) : Nat.card (e '' s) = Nat.card s :=
Nat.card_congr (e.image s).symm
lemma card_preimage_of_injOn {s : Set β} (hf : (f ⁻¹' s).InjOn f) (hsf : s ⊆ range f) :
Nat.card (f ⁻¹' s) = Nat.card s := by
rw [← Nat.card_image_of_injOn hf, image_preimage_eq_iff.2 hsf]
lemma card_preimage_of_injective {s : Set β} (hf : Injective f) (hsf : s ⊆ range f) :
Nat.card (f ⁻¹' s) = Nat.card s := card_preimage_of_injOn hf.injOn hsf
end Set
/-- If the cardinality is positive, that means it is a finite type, so there is
an equivalence between `α` and `Fin (Nat.card α)`. See also `Finite.equivFin`. -/
def equivFinOfCardPos {α : Type*} (h : Nat.card α ≠ 0) : α ≃ Fin (Nat.card α) := by
cases fintypeOrInfinite α
· simpa only [card_eq_fintype_card] using Fintype.equivFin α
· simp only [card_eq_zero_of_infinite, ne_eq, not_true_eq_false] at h
#align nat.equiv_fin_of_card_pos Nat.equivFinOfCardPos
theorem card_of_subsingleton (a : α) [Subsingleton α] : Nat.card α = 1 := by
letI := Fintype.ofSubsingleton a
rw [card_eq_fintype_card, Fintype.card_ofSubsingleton a]
#align nat.card_of_subsingleton Nat.card_of_subsingleton
-- @[simp] -- Porting note (#10618): simp can prove this
theorem card_unique [Unique α] : Nat.card α = 1 :=
card_of_subsingleton default
#align nat.card_unique Nat.card_unique
theorem card_eq_one_iff_unique : Nat.card α = 1 ↔ Subsingleton α ∧ Nonempty α :=
Cardinal.toNat_eq_one_iff_unique
#align nat.card_eq_one_iff_unique Nat.card_eq_one_iff_unique
theorem card_eq_two_iff : Nat.card α = 2 ↔ ∃ x y : α, x ≠ y ∧ {x, y} = @Set.univ α :=
toNat_eq_ofNat.trans mk_eq_two_iff
#align nat.card_eq_two_iff Nat.card_eq_two_iff
theorem card_eq_two_iff' (x : α) : Nat.card α = 2 ↔ ∃! y, y ≠ x :=
toNat_eq_ofNat.trans (mk_eq_two_iff' x)
#align nat.card_eq_two_iff' Nat.card_eq_two_iff'
@[simp]
theorem card_sum [Finite α] [Finite β] : Nat.card (α ⊕ β) = Nat.card α + Nat.card β := by
have := Fintype.ofFinite α
have := Fintype.ofFinite β
simp_rw [Nat.card_eq_fintype_card, Fintype.card_sum]
@[simp]
theorem card_prod (α β : Type*) : Nat.card (α × β) = Nat.card α * Nat.card β := by
simp only [Nat.card, mk_prod, toNat_mul, toNat_lift]
#align nat.card_prod Nat.card_prod
@[simp]
theorem card_ulift (α : Type*) : Nat.card (ULift α) = Nat.card α :=
card_congr Equiv.ulift
#align nat.card_ulift Nat.card_ulift
@[simp]
theorem card_plift (α : Type*) : Nat.card (PLift α) = Nat.card α :=
card_congr Equiv.plift
#align nat.card_plift Nat.card_plift
theorem card_pi {β : α → Type*} [Fintype α] : Nat.card (∀ a, β a) = ∏ a, Nat.card (β a) := by
simp_rw [Nat.card, mk_pi, prod_eq_of_fintype, toNat_lift, map_prod]
#align nat.card_pi Nat.card_pi
theorem card_fun [Finite α] : Nat.card (α → β) = Nat.card β ^ Nat.card α := by
haveI := Fintype.ofFinite α
rw [Nat.card_pi, Finset.prod_const, Finset.card_univ, ← Nat.card_eq_fintype_card]
#align nat.card_fun Nat.card_fun
@[simp]
theorem card_zmod (n : ℕ) : Nat.card (ZMod n) = n := by
cases n
· exact @Nat.card_eq_zero_of_infinite _ Int.infinite
· rw [Nat.card_eq_fintype_card, ZMod.card]
#align nat.card_zmod Nat.card_zmod
end Nat
namespace Set
lemma card_singleton_prod (a : α) (t : Set β) : Nat.card ({a} ×ˢ t) = Nat.card t := by
rw [singleton_prod, Nat.card_image_of_injective (Prod.mk.inj_left a)]
lemma card_prod_singleton (s : Set α) (b : β) : Nat.card (s ×ˢ {b}) = Nat.card s := by
rw [prod_singleton, Nat.card_image_of_injective (Prod.mk.inj_right b)]
end Set
namespace PartENat
/-- `PartENat.card α` is the cardinality of `α` as an extended natural number.
If `α` is infinite, `PartENat.card α = ⊤`. -/
def card (α : Type*) : PartENat :=
toPartENat (mk α)
#align part_enat.card PartENat.card
@[simp]
theorem card_eq_coe_fintype_card [Fintype α] : card α = Fintype.card α :=
mk_toPartENat_eq_coe_card
#align part_enat.card_eq_coe_fintype_card PartENat.card_eq_coe_fintype_card
@[simp]
theorem card_eq_top_of_infinite [Infinite α] : card α = ⊤ :=
mk_toPartENat_of_infinite
#align part_enat.card_eq_top_of_infinite PartENat.card_eq_top_of_infinite
@[simp]
theorem card_sum (α β : Type*) :
PartENat.card (α ⊕ β) = PartENat.card α + PartENat.card β := by
simp only [PartENat.card, Cardinal.mk_sum, map_add, Cardinal.toPartENat_lift]
theorem card_congr {α : Type*} {β : Type*} (f : α ≃ β) : PartENat.card α = PartENat.card β :=
Cardinal.toPartENat_congr f
#align part_enat.card_congr PartENat.card_congr
@[simp] lemma card_ulift (α : Type*) : card (ULift α) = card α := card_congr Equiv.ulift
#align part_enat.card_ulift PartENat.card_ulift
@[simp] lemma card_plift (α : Type*) : card (PLift α) = card α := card_congr Equiv.plift
#align part_enat.card_plift PartENat.card_plift
theorem card_image_of_injOn {α : Type u} {β : Type v} {f : α → β} {s : Set α} (h : Set.InjOn f s) :
card (f '' s) = card s :=
card_congr (Equiv.Set.imageOfInjOn f s h).symm
#align part_enat.card_image_of_inj_on PartENat.card_image_of_injOn
theorem card_image_of_injective {α : Type u} {β : Type v} (f : α → β) (s : Set α)
(h : Function.Injective f) : card (f '' s) = card s := card_image_of_injOn h.injOn
#align part_enat.card_image_of_injective PartENat.card_image_of_injective
-- Should I keep the 6 following lemmas ?
-- TODO: Add ofNat, zero, and one versions for simp confluence
@[simp]
theorem _root_.Cardinal.natCast_le_toPartENat_iff {n : ℕ} {c : Cardinal} :
↑n ≤ toPartENat c ↔ ↑n ≤ c := by
rw [← toPartENat_natCast n, toPartENat_le_iff_of_le_aleph0 (le_of_lt (nat_lt_aleph0 n))]
#align cardinal.coe_nat_le_to_part_enat_iff Cardinal.natCast_le_toPartENat_iff
@[simp]
theorem _root_.Cardinal.toPartENat_le_natCast_iff {c : Cardinal} {n : ℕ} :
toPartENat c ≤ n ↔ c ≤ n := by
rw [← toPartENat_natCast n, toPartENat_le_iff_of_lt_aleph0 (nat_lt_aleph0 n)]
#align cardinal.to_part_enat_le_coe_nat_iff Cardinal.toPartENat_le_natCast_iff
@[simp]
theorem _root_.Cardinal.natCast_eq_toPartENat_iff {n : ℕ} {c : Cardinal} :
↑n = toPartENat c ↔ ↑n = c := by
rw [le_antisymm_iff, le_antisymm_iff, Cardinal.toPartENat_le_natCast_iff,
Cardinal.natCast_le_toPartENat_iff]
#align cardinal.coe_nat_eq_to_part_enat_iff Cardinal.natCast_eq_toPartENat_iff
@[simp]
theorem _root_.Cardinal.toPartENat_eq_natCast_iff {c : Cardinal} {n : ℕ} :
Cardinal.toPartENat c = n ↔ c = n := by
rw [eq_comm, Cardinal.natCast_eq_toPartENat_iff, eq_comm]
#align cardinal.to_part_nat_eq_coe_nat_iff_eq Cardinal.toPartENat_eq_natCast_iff
@[simp]
theorem _root_.Cardinal.natCast_lt_toPartENat_iff {n : ℕ} {c : Cardinal} :
↑n < toPartENat c ↔ ↑n < c := by
simp only [← not_le, Cardinal.toPartENat_le_natCast_iff]
#align part_enat.coe_nat_lt_coe_iff_lt Cardinal.natCast_lt_toPartENat_iff
@[simp]
theorem _root_.Cardinal.toPartENat_lt_natCast_iff {n : ℕ} {c : Cardinal} :
toPartENat c < ↑n ↔ c < ↑n := by
simp only [← not_le, Cardinal.natCast_le_toPartENat_iff]
#align lt_coe_nat_iff_lt Cardinal.toPartENat_lt_natCast_iff
theorem card_eq_zero_iff_empty (α : Type*) : card α = 0 ↔ IsEmpty α := by
rw [← Cardinal.mk_eq_zero_iff]
conv_rhs => rw [← Nat.cast_zero]
simp only [← Cardinal.toPartENat_eq_natCast_iff]
simp only [PartENat.card, Nat.cast_zero]
#align part_enat.card_eq_zero_iff_empty PartENat.card_eq_zero_iff_empty
theorem card_le_one_iff_subsingleton (α : Type*) : card α ≤ 1 ↔ Subsingleton α := by
rw [← le_one_iff_subsingleton]
conv_rhs => rw [← Nat.cast_one]
rw [← Cardinal.toPartENat_le_natCast_iff]
simp only [PartENat.card, Nat.cast_one]
#align part_enat.card_le_one_iff_subsingleton PartENat.card_le_one_iff_subsingleton
| Mathlib/SetTheory/Cardinal/Finite.lean | 310 | 314 | theorem one_lt_card_iff_nontrivial (α : Type*) : 1 < card α ↔ Nontrivial α := by |
rw [← Cardinal.one_lt_iff_nontrivial]
conv_rhs => rw [← Nat.cast_one]
rw [← natCast_lt_toPartENat_iff]
simp only [PartENat.card, Nat.cast_one]
|
/-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Probability.Kernel.Composition
import Mathlib.MeasureTheory.Integral.SetIntegral
#align_import probability.kernel.integral_comp_prod from "leanprover-community/mathlib"@"c0d694db494dd4f9aa57f2714b6e4c82b4ebc113"
/-!
# Bochner integral of a function against the composition-product of two kernels
We prove properties of the composition-product of two kernels. If `κ` is an s-finite kernel from
`α` to `β` and `η` is an s-finite kernel from `α × β` to `γ`, we can form their composition-product
`κ ⊗ₖ η : kernel α (β × γ)`. We proved in `ProbabilityTheory.kernel.lintegral_compProd` that it
verifies `∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`. In this file, we
prove the same equality for the Bochner integral.
## Main statements
* `ProbabilityTheory.integral_compProd`: the integral against the composition-product is
`∫ z, f z ∂((κ ⊗ₖ η) a) = ∫ x, ∫ y, f (x, y) ∂(η (a, x)) ∂(κ a)`
## Implementation details
This file is to a large extent a copy of part of
`Mathlib/MeasureTheory/Constructions/Prod/Basic.lean`. The product of
two measures is a particular case of composition-product of kernels and it turns out that once the
measurablity of the Lebesgue integral of a kernel is proved, almost all proofs about integrals
against products of measures extend with minimal modifications to the composition-product of two
kernels.
-/
noncomputable section
open scoped Topology ENNReal MeasureTheory ProbabilityTheory
open Set Function Real ENNReal MeasureTheory Filter ProbabilityTheory ProbabilityTheory.kernel
variable {α β γ E : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{mγ : MeasurableSpace γ} [NormedAddCommGroup E] {κ : kernel α β} [IsSFiniteKernel κ]
{η : kernel (α × β) γ} [IsSFiniteKernel η] {a : α}
namespace ProbabilityTheory
theorem hasFiniteIntegral_prod_mk_left (a : α) {s : Set (β × γ)} (h2s : (κ ⊗ₖ η) a s ≠ ∞) :
HasFiniteIntegral (fun b => (η (a, b) (Prod.mk b ⁻¹' s)).toReal) (κ a) := by
let t := toMeasurable ((κ ⊗ₖ η) a) s
simp_rw [HasFiniteIntegral, ennnorm_eq_ofReal toReal_nonneg]
calc
∫⁻ b, ENNReal.ofReal (η (a, b) (Prod.mk b ⁻¹' s)).toReal ∂κ a
_ ≤ ∫⁻ b, η (a, b) (Prod.mk b ⁻¹' t) ∂κ a := by
refine lintegral_mono_ae ?_
filter_upwards [ae_kernel_lt_top a h2s] with b hb
rw [ofReal_toReal hb.ne]
exact measure_mono (preimage_mono (subset_toMeasurable _ _))
_ ≤ (κ ⊗ₖ η) a t := le_compProd_apply _ _ _ _
_ = (κ ⊗ₖ η) a s := measure_toMeasurable s
_ < ⊤ := h2s.lt_top
#align probability_theory.has_finite_integral_prod_mk_left ProbabilityTheory.hasFiniteIntegral_prod_mk_left
| Mathlib/Probability/Kernel/IntegralCompProd.lean | 64 | 68 | theorem integrable_kernel_prod_mk_left (a : α) {s : Set (β × γ)} (hs : MeasurableSet s)
(h2s : (κ ⊗ₖ η) a s ≠ ∞) : Integrable (fun b => (η (a, b) (Prod.mk b ⁻¹' s)).toReal) (κ a) := by |
constructor
· exact (measurable_kernel_prod_mk_left' hs a).ennreal_toReal.aestronglyMeasurable
· exact hasFiniteIntegral_prod_mk_left a h2s
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Scott Morrison
-/
import Mathlib.CategoryTheory.Subobject.Lattice
#align_import category_theory.subobject.limits from "leanprover-community/mathlib"@"956af7c76589f444f2e1313911bad16366ea476d"
/-!
# Specific subobjects
We define `equalizerSubobject`, `kernelSubobject` and `imageSubobject`, which are the subobjects
represented by the equalizer, kernel and image of (a pair of) morphism(s) and provide conditions
for `P.factors f`, where `P` is one of these special subobjects.
TODO: Add conditions for when `P` is a pullback subobject.
TODO: an iff characterisation of `(imageSubobject f).Factors h`
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Subobject Opposite
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace CategoryTheory
namespace Limits
section Equalizer
variable (f g : X ⟶ Y) [HasEqualizer f g]
/-- The equalizer of morphisms `f g : X ⟶ Y` as a `Subobject X`. -/
abbrev equalizerSubobject : Subobject X :=
Subobject.mk (equalizer.ι f g)
#align category_theory.limits.equalizer_subobject CategoryTheory.Limits.equalizerSubobject
/-- The underlying object of `equalizerSubobject f g` is (up to isomorphism!)
the same as the chosen object `equalizer f g`. -/
def equalizerSubobjectIso : (equalizerSubobject f g : C) ≅ equalizer f g :=
Subobject.underlyingIso (equalizer.ι f g)
#align category_theory.limits.equalizer_subobject_iso CategoryTheory.Limits.equalizerSubobjectIso
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow :
(equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = (equalizerSubobject f g).arrow := by
simp [equalizerSubobjectIso]
#align category_theory.limits.equalizer_subobject_arrow CategoryTheory.Limits.equalizerSubobject_arrow
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow' :
(equalizerSubobjectIso f g).inv ≫ (equalizerSubobject f g).arrow = equalizer.ι f g := by
simp [equalizerSubobjectIso]
#align category_theory.limits.equalizer_subobject_arrow' CategoryTheory.Limits.equalizerSubobject_arrow'
@[reassoc]
theorem equalizerSubobject_arrow_comp :
(equalizerSubobject f g).arrow ≫ f = (equalizerSubobject f g).arrow ≫ g := by
rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition]
#align category_theory.limits.equalizer_subobject_arrow_comp CategoryTheory.Limits.equalizerSubobject_arrow_comp
theorem equalizerSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = h ≫ g) :
(equalizerSubobject f g).Factors h :=
⟨equalizer.lift h w, by simp⟩
#align category_theory.limits.equalizer_subobject_factors CategoryTheory.Limits.equalizerSubobject_factors
theorem equalizerSubobject_factors_iff {W : C} (h : W ⟶ X) :
(equalizerSubobject f g).Factors h ↔ h ≫ f = h ≫ g :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp,
Category.assoc],
equalizerSubobject_factors f g h⟩
#align category_theory.limits.equalizer_subobject_factors_iff CategoryTheory.Limits.equalizerSubobject_factors_iff
end Equalizer
section Kernel
variable [HasZeroMorphisms C] (f : X ⟶ Y) [HasKernel f]
/-- The kernel of a morphism `f : X ⟶ Y` as a `Subobject X`. -/
abbrev kernelSubobject : Subobject X :=
Subobject.mk (kernel.ι f)
#align category_theory.limits.kernel_subobject CategoryTheory.Limits.kernelSubobject
/-- The underlying object of `kernelSubobject f` is (up to isomorphism!)
the same as the chosen object `kernel f`. -/
def kernelSubobjectIso : (kernelSubobject f : C) ≅ kernel f :=
Subobject.underlyingIso (kernel.ι f)
#align category_theory.limits.kernel_subobject_iso CategoryTheory.Limits.kernelSubobjectIso
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow :
(kernelSubobjectIso f).hom ≫ kernel.ι f = (kernelSubobject f).arrow := by
simp [kernelSubobjectIso]
#align category_theory.limits.kernel_subobject_arrow CategoryTheory.Limits.kernelSubobject_arrow
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow' :
(kernelSubobjectIso f).inv ≫ (kernelSubobject f).arrow = kernel.ι f := by
simp [kernelSubobjectIso]
#align category_theory.limits.kernel_subobject_arrow' CategoryTheory.Limits.kernelSubobject_arrow'
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow_comp : (kernelSubobject f).arrow ≫ f = 0 := by
rw [← kernelSubobject_arrow]
simp only [Category.assoc, kernel.condition, comp_zero]
#align category_theory.limits.kernel_subobject_arrow_comp CategoryTheory.Limits.kernelSubobject_arrow_comp
theorem kernelSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
(kernelSubobject f).Factors h :=
⟨kernel.lift _ h w, by simp⟩
#align category_theory.limits.kernel_subobject_factors CategoryTheory.Limits.kernelSubobject_factors
theorem kernelSubobject_factors_iff {W : C} (h : W ⟶ X) :
(kernelSubobject f).Factors h ↔ h ≫ f = 0 :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, kernelSubobject_arrow_comp,
comp_zero],
kernelSubobject_factors f h⟩
#align category_theory.limits.kernel_subobject_factors_iff CategoryTheory.Limits.kernelSubobject_factors_iff
/-- A factorisation of `h : W ⟶ X` through `kernelSubobject f`, assuming `h ≫ f = 0`. -/
def factorThruKernelSubobject {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : W ⟶ kernelSubobject f :=
(kernelSubobject f).factorThru h (kernelSubobject_factors f h w)
#align category_theory.limits.factor_thru_kernel_subobject CategoryTheory.Limits.factorThruKernelSubobject
@[simp]
theorem factorThruKernelSubobject_comp_arrow {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobject f).arrow = h := by
dsimp [factorThruKernelSubobject]
simp
#align category_theory.limits.factor_thru_kernel_subobject_comp_arrow CategoryTheory.Limits.factorThruKernelSubobject_comp_arrow
@[simp]
theorem factorThruKernelSubobject_comp_kernelSubobjectIso {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobjectIso f).hom = kernel.lift f h w :=
(cancel_mono (kernel.ι f)).1 <| by simp
#align category_theory.limits.factor_thru_kernel_subobject_comp_kernel_subobject_iso CategoryTheory.Limits.factorThruKernelSubobject_comp_kernelSubobjectIso
section
variable {f} {X' Y' : C} {f' : X' ⟶ Y'} [HasKernel f']
/-- A commuting square induces a morphism between the kernel subobjects. -/
def kernelSubobjectMap (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobject f : C) ⟶ (kernelSubobject f' : C) :=
Subobject.factorThru _ ((kernelSubobject f).arrow ≫ sq.left)
(kernelSubobject_factors _ _ (by simp [sq.w]))
#align category_theory.limits.kernel_subobject_map CategoryTheory.Limits.kernelSubobjectMap
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobjectMap_arrow (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernelSubobjectMap sq ≫ (kernelSubobject f').arrow = (kernelSubobject f).arrow ≫ sq.left := by
simp [kernelSubobjectMap]
#align category_theory.limits.kernel_subobject_map_arrow CategoryTheory.Limits.kernelSubobjectMap_arrow
@[simp]
theorem kernelSubobjectMap_id : kernelSubobjectMap (𝟙 (Arrow.mk f)) = 𝟙 _ := by aesop_cat
#align category_theory.limits.kernel_subobject_map_id CategoryTheory.Limits.kernelSubobjectMap_id
@[simp]
theorem kernelSubobjectMap_comp {X'' Y'' : C} {f'' : X'' ⟶ Y''} [HasKernel f'']
(sq : Arrow.mk f ⟶ Arrow.mk f') (sq' : Arrow.mk f' ⟶ Arrow.mk f'') :
kernelSubobjectMap (sq ≫ sq') = kernelSubobjectMap sq ≫ kernelSubobjectMap sq' := by
aesop_cat
#align category_theory.limits.kernel_subobject_map_comp CategoryTheory.Limits.kernelSubobjectMap_comp
@[reassoc]
theorem kernel_map_comp_kernelSubobjectIso_inv (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernel.map f f' sq.1 sq.2 sq.3.symm ≫ (kernelSubobjectIso _).inv =
(kernelSubobjectIso _).inv ≫ kernelSubobjectMap sq := by aesop_cat
#align category_theory.limits.kernel_map_comp_kernel_subobject_iso_inv CategoryTheory.Limits.kernel_map_comp_kernelSubobjectIso_inv
@[reassoc]
theorem kernelSubobjectIso_comp_kernel_map (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobjectIso _).hom ≫ kernel.map f f' sq.1 sq.2 sq.3.symm =
kernelSubobjectMap sq ≫ (kernelSubobjectIso _).hom := by
simp [← Iso.comp_inv_eq, kernel_map_comp_kernelSubobjectIso_inv]
#align category_theory.limits.kernel_subobject_iso_comp_kernel_map CategoryTheory.Limits.kernelSubobjectIso_comp_kernel_map
end
@[simp]
theorem kernelSubobject_zero {A B : C} : kernelSubobject (0 : A ⟶ B) = ⊤ :=
(isIso_iff_mk_eq_top _).mp (by infer_instance)
#align category_theory.limits.kernel_subobject_zero CategoryTheory.Limits.kernelSubobject_zero
instance isIso_kernelSubobject_zero_arrow : IsIso (kernelSubobject (0 : X ⟶ Y)).arrow :=
(isIso_arrow_iff_eq_top _).mpr kernelSubobject_zero
#align category_theory.limits.is_iso_kernel_subobject_zero_arrow CategoryTheory.Limits.isIso_kernelSubobject_zero_arrow
theorem le_kernelSubobject (A : Subobject X) (h : A.arrow ≫ f = 0) : A ≤ kernelSubobject f :=
Subobject.le_mk_of_comm (kernel.lift f A.arrow h) (by simp)
#align category_theory.limits.le_kernel_subobject CategoryTheory.Limits.le_kernelSubobject
/-- The isomorphism between the kernel of `f ≫ g` and the kernel of `g`,
when `f` is an isomorphism.
-/
def kernelSubobjectIsoComp {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobject (f ≫ g) : C) ≅ (kernelSubobject g : C) :=
kernelSubobjectIso _ ≪≫ kernelIsIsoComp f g ≪≫ (kernelSubobjectIso _).symm
#align category_theory.limits.kernel_subobject_iso_comp CategoryTheory.Limits.kernelSubobjectIsoComp
@[simp]
theorem kernelSubobjectIsoComp_hom_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).hom ≫ (kernelSubobject g).arrow =
(kernelSubobject (f ≫ g)).arrow ≫ f := by
simp [kernelSubobjectIsoComp]
#align category_theory.limits.kernel_subobject_iso_comp_hom_arrow CategoryTheory.Limits.kernelSubobjectIsoComp_hom_arrow
@[simp]
theorem kernelSubobjectIsoComp_inv_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).inv ≫ (kernelSubobject (f ≫ g)).arrow =
(kernelSubobject g).arrow ≫ inv f := by
simp [kernelSubobjectIsoComp]
#align category_theory.limits.kernel_subobject_iso_comp_inv_arrow CategoryTheory.Limits.kernelSubobjectIsoComp_inv_arrow
/-- The kernel of `f` is always a smaller subobject than the kernel of `f ≫ h`. -/
theorem kernelSubobject_comp_le (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [HasKernel (f ≫ h)] :
kernelSubobject f ≤ kernelSubobject (f ≫ h) :=
le_kernelSubobject _ _ (by simp)
#align category_theory.limits.kernel_subobject_comp_le CategoryTheory.Limits.kernelSubobject_comp_le
/-- Postcomposing by a monomorphism does not change the kernel subobject. -/
@[simp]
theorem kernelSubobject_comp_mono (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
kernelSubobject (f ≫ h) = kernelSubobject f :=
le_antisymm (le_kernelSubobject _ _ ((cancel_mono h).mp (by simp))) (kernelSubobject_comp_le f h)
#align category_theory.limits.kernel_subobject_comp_mono CategoryTheory.Limits.kernelSubobject_comp_mono
instance kernelSubobject_comp_mono_isIso (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
IsIso (Subobject.ofLE _ _ (kernelSubobject_comp_le f h)) := by
rw [ofLE_mk_le_mk_of_comm (kernelCompMono f h).inv]
· infer_instance
· simp
#align category_theory.limits.kernel_subobject_comp_mono_is_iso CategoryTheory.Limits.kernelSubobject_comp_mono_isIso
/-- Taking cokernels is an order-reversing map from the subobjects of `X` to the quotient objects
of `X`. -/
@[simps]
def cokernelOrderHom [HasCokernels C] (X : C) : Subobject X →o (Subobject (op X))ᵒᵈ where
toFun :=
Subobject.lift (fun A f _ => Subobject.mk (cokernel.π f).op)
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ (Iso.op ?_) (Quiver.Hom.unop_inj ?_)
· exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _)
(isCokernelEpiComp (colimit.isColimit _) i.hom rfl)).symm
· simp only [Iso.comp_inv_eq, Iso.op_hom, Iso.symm_hom, unop_comp, Quiver.Hom.unop_op,
colimit.comp_coconePointUniqueUpToIso_hom, Cofork.ofπ_ι_app,
coequalizer.cofork_π])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (cokernel.desc f (cokernel.π g) ?_).op ?_
· rw [← Subobject.ofMkLEMk_comp h, Category.assoc, cokernel.condition, comp_zero]
· exact Quiver.Hom.unop_inj (cokernel.π_desc _ _ _)
#align category_theory.limits.cokernel_order_hom CategoryTheory.Limits.cokernelOrderHom
/-- Taking kernels is an order-reversing map from the quotient objects of `X` to the subobjects of
`X`. -/
@[simps]
def kernelOrderHom [HasKernels C] (X : C) : (Subobject (op X))ᵒᵈ →o Subobject X where
toFun :=
Subobject.lift (fun A f _ => Subobject.mk (kernel.ι f.unop))
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ ?_ ?_
· exact
IsLimit.conePointUniqueUpToIso (limit.isLimit _)
(isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) i.unop.hom rfl)
· dsimp
simp only [← Iso.eq_inv_comp, limit.conePointUniqueUpToIso_inv_comp,
Fork.ofι_π_app])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (kernel.lift g.unop (kernel.ι f.unop) ?_) ?_
· rw [← Subobject.ofMkLEMk_comp h, unop_comp, kernel.condition_assoc, zero_comp]
· exact Quiver.Hom.op_inj (by simp)
#align category_theory.limits.kernel_order_hom CategoryTheory.Limits.kernelOrderHom
end Kernel
section Image
variable (f : X ⟶ Y) [HasImage f]
/-- The image of a morphism `f g : X ⟶ Y` as a `Subobject Y`. -/
abbrev imageSubobject : Subobject Y :=
Subobject.mk (image.ι f)
#align category_theory.limits.image_subobject CategoryTheory.Limits.imageSubobject
/-- The underlying object of `imageSubobject f` is (up to isomorphism!)
the same as the chosen object `image f`. -/
def imageSubobjectIso : (imageSubobject f : C) ≅ image f :=
Subobject.underlyingIso (image.ι f)
#align category_theory.limits.image_subobject_iso CategoryTheory.Limits.imageSubobjectIso
@[reassoc (attr := simp)]
theorem imageSubobject_arrow :
(imageSubobjectIso f).hom ≫ image.ι f = (imageSubobject f).arrow := by simp [imageSubobjectIso]
#align category_theory.limits.image_subobject_arrow CategoryTheory.Limits.imageSubobject_arrow
@[reassoc (attr := simp)]
theorem imageSubobject_arrow' :
(imageSubobjectIso f).inv ≫ (imageSubobject f).arrow = image.ι f := by simp [imageSubobjectIso]
#align category_theory.limits.image_subobject_arrow' CategoryTheory.Limits.imageSubobject_arrow'
/-- A factorisation of `f : X ⟶ Y` through `imageSubobject f`. -/
def factorThruImageSubobject : X ⟶ imageSubobject f :=
factorThruImage f ≫ (imageSubobjectIso f).inv
#align category_theory.limits.factor_thru_image_subobject CategoryTheory.Limits.factorThruImageSubobject
instance [HasEqualizers C] : Epi (factorThruImageSubobject f) := by
dsimp [factorThruImageSubobject]
apply epi_comp
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem imageSubobject_arrow_comp : factorThruImageSubobject f ≫ (imageSubobject f).arrow = f := by
simp [factorThruImageSubobject, imageSubobject_arrow]
#align category_theory.limits.image_subobject_arrow_comp CategoryTheory.Limits.imageSubobject_arrow_comp
theorem imageSubobject_arrow_comp_eq_zero [HasZeroMorphisms C] {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z}
[HasImage f] [Epi (factorThruImageSubobject f)] (h : f ≫ g = 0) :
(imageSubobject f).arrow ≫ g = 0 :=
zero_of_epi_comp (factorThruImageSubobject f) <| by simp [h]
#align category_theory.limits.image_subobject_arrow_comp_eq_zero CategoryTheory.Limits.imageSubobject_arrow_comp_eq_zero
theorem imageSubobject_factors_comp_self {W : C} (k : W ⟶ X) : (imageSubobject f).Factors (k ≫ f) :=
⟨k ≫ factorThruImage f, by simp⟩
#align category_theory.limits.image_subobject_factors_comp_self CategoryTheory.Limits.imageSubobject_factors_comp_self
@[simp]
theorem factorThruImageSubobject_comp_self {W : C} (k : W ⟶ X) (h) :
(imageSubobject f).factorThru (k ≫ f) h = k ≫ factorThruImageSubobject f := by
ext
simp
#align category_theory.limits.factor_thru_image_subobject_comp_self CategoryTheory.Limits.factorThruImageSubobject_comp_self
@[simp]
theorem factorThruImageSubobject_comp_self_assoc {W W' : C} (k : W ⟶ W') (k' : W' ⟶ X) (h) :
(imageSubobject f).factorThru (k ≫ k' ≫ f) h = k ≫ k' ≫ factorThruImageSubobject f := by
ext
simp
#align category_theory.limits.factor_thru_image_subobject_comp_self_assoc CategoryTheory.Limits.factorThruImageSubobject_comp_self_assoc
/-- The image of `h ≫ f` is always a smaller subobject than the image of `f`. -/
theorem imageSubobject_comp_le {X' : C} (h : X' ⟶ X) (f : X ⟶ Y) [HasImage f] [HasImage (h ≫ f)] :
imageSubobject (h ≫ f) ≤ imageSubobject f :=
Subobject.mk_le_mk_of_comm (image.preComp h f) (by simp)
#align category_theory.limits.image_subobject_comp_le CategoryTheory.Limits.imageSubobject_comp_le
section
open ZeroObject
variable [HasZeroMorphisms C] [HasZeroObject C]
@[simp]
theorem imageSubobject_zero_arrow : (imageSubobject (0 : X ⟶ Y)).arrow = 0 := by
rw [← imageSubobject_arrow]
simp
#align category_theory.limits.image_subobject_zero_arrow CategoryTheory.Limits.imageSubobject_zero_arrow
@[simp]
theorem imageSubobject_zero {A B : C} : imageSubobject (0 : A ⟶ B) = ⊥ :=
Subobject.eq_of_comm (imageSubobjectIso _ ≪≫ imageZero ≪≫ Subobject.botCoeIsoZero.symm) (by simp)
#align category_theory.limits.image_subobject_zero CategoryTheory.Limits.imageSubobject_zero
end
section
variable [HasEqualizers C]
attribute [local instance] epi_comp
/-- The morphism `imageSubobject (h ≫ f) ⟶ imageSubobject f`
is an epimorphism when `h` is an epimorphism.
In general this does not imply that `imageSubobject (h ≫ f) = imageSubobject f`,
although it will when the ambient category is abelian.
-/
instance imageSubobject_comp_le_epi_of_epi {X' : C} (h : X' ⟶ X) [Epi h] (f : X ⟶ Y) [HasImage f]
[HasImage (h ≫ f)] : Epi (Subobject.ofLE _ _ (imageSubobject_comp_le h f)) := by
rw [ofLE_mk_le_mk_of_comm (image.preComp h f)]
· infer_instance
· simp
#align category_theory.limits.image_subobject_comp_le_epi_of_epi CategoryTheory.Limits.imageSubobject_comp_le_epi_of_epi
end
section
variable [HasEqualizers C]
/-- Postcomposing by an isomorphism gives an isomorphism between image subobjects. -/
def imageSubobjectCompIso (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] :
(imageSubobject (f ≫ h) : C) ≅ (imageSubobject f : C) :=
imageSubobjectIso _ ≪≫ (image.compIso _ _).symm ≪≫ (imageSubobjectIso _).symm
#align category_theory.limits.image_subobject_comp_iso CategoryTheory.Limits.imageSubobjectCompIso
@[reassoc (attr := simp)]
| Mathlib/CategoryTheory/Subobject/Limits.lean | 412 | 415 | theorem imageSubobjectCompIso_hom_arrow (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] :
(imageSubobjectCompIso f h).hom ≫ (imageSubobject f).arrow =
(imageSubobject (f ≫ h)).arrow ≫ inv h := by |
simp [imageSubobjectCompIso]
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury G. Kudryashov
-/
import Mathlib.Logic.Function.Basic
import Mathlib.Tactic.MkIffOfInductiveProp
#align_import data.sum.basic from "leanprover-community/mathlib"@"bd9851ca476957ea4549eb19b40e7b5ade9428cc"
/-!
# Additional lemmas about sum types
Most of the former contents of this file have been moved to Batteries.
-/
universe u v w x
variable {α : Type u} {α' : Type w} {β : Type v} {β' : Type x} {γ δ : Type*}
namespace Sum
#align sum.forall Sum.forall
#align sum.exists Sum.exists
theorem exists_sum {γ : α ⊕ β → Sort*} (p : (∀ ab, γ ab) → Prop) :
(∃ fab, p fab) ↔ (∃ fa fb, p (Sum.rec fa fb)) := by
rw [← not_forall_not, forall_sum]
simp
theorem inl_injective : Function.Injective (inl : α → Sum α β) := fun _ _ ↦ inl.inj
#align sum.inl_injective Sum.inl_injective
theorem inr_injective : Function.Injective (inr : β → Sum α β) := fun _ _ ↦ inr.inj
#align sum.inr_injective Sum.inr_injective
theorem sum_rec_congr (P : α ⊕ β → Sort*) (f : ∀ i, P (inl i)) (g : ∀ i, P (inr i))
{x y : α ⊕ β} (h : x = y) :
@Sum.rec _ _ _ f g x = cast (congr_arg P h.symm) (@Sum.rec _ _ _ f g y) := by cases h; rfl
section get
#align sum.is_left Sum.isLeft
#align sum.is_right Sum.isRight
#align sum.get_left Sum.getLeft?
#align sum.get_right Sum.getRight?
variable {x y : Sum α β}
#align sum.get_left_eq_none_iff Sum.getLeft?_eq_none_iff
#align sum.get_right_eq_none_iff Sum.getRight?_eq_none_iff
theorem eq_left_iff_getLeft_eq {a : α} : x = inl a ↔ ∃ h, x.getLeft h = a := by
cases x <;> simp
theorem eq_right_iff_getRight_eq {b : β} : x = inr b ↔ ∃ h, x.getRight h = b := by
cases x <;> simp
#align sum.get_left_eq_some_iff Sum.getLeft?_eq_some_iff
#align sum.get_right_eq_some_iff Sum.getRight?_eq_some_iff
theorem getLeft_eq_getLeft? (h₁ : x.isLeft) (h₂ : x.getLeft?.isSome) :
x.getLeft h₁ = x.getLeft?.get h₂ := by simp [← getLeft?_eq_some_iff]
theorem getRight_eq_getRight? (h₁ : x.isRight) (h₂ : x.getRight?.isSome) :
x.getRight h₁ = x.getRight?.get h₂ := by simp [← getRight?_eq_some_iff]
#align sum.bnot_is_left Sum.bnot_isLeft
#align sum.is_left_eq_ff Sum.isLeft_eq_false
#align sum.not_is_left Sum.not_isLeft
#align sum.bnot_is_right Sum.bnot_isRight
#align sum.is_right_eq_ff Sum.isRight_eq_false
#align sum.not_is_right Sum.not_isRight
#align sum.is_left_iff Sum.isLeft_iff
#align sum.is_right_iff Sum.isRight_iff
@[simp] theorem isSome_getLeft?_iff_isLeft : x.getLeft?.isSome ↔ x.isLeft := by
rw [isLeft_iff, Option.isSome_iff_exists]; simp
@[simp] theorem isSome_getRight?_iff_isRight : x.getRight?.isSome ↔ x.isRight := by
rw [isRight_iff, Option.isSome_iff_exists]; simp
end get
#align sum.inl.inj_iff Sum.inl.inj_iff
#align sum.inr.inj_iff Sum.inr.inj_iff
#align sum.inl_ne_inr Sum.inl_ne_inr
#align sum.inr_ne_inl Sum.inr_ne_inl
#align sum.elim Sum.elim
#align sum.elim_inl Sum.elim_inl
#align sum.elim_inr Sum.elim_inr
#align sum.elim_comp_inl Sum.elim_comp_inl
#align sum.elim_comp_inr Sum.elim_comp_inr
#align sum.elim_inl_inr Sum.elim_inl_inr
#align sum.comp_elim Sum.comp_elim
#align sum.elim_comp_inl_inr Sum.elim_comp_inl_inr
#align sum.map Sum.map
#align sum.map_inl Sum.map_inl
#align sum.map_inr Sum.map_inr
#align sum.map_map Sum.map_map
#align sum.map_comp_map Sum.map_comp_map
#align sum.map_id_id Sum.map_id_id
#align sum.elim_map Sum.elim_map
#align sum.elim_comp_map Sum.elim_comp_map
#align sum.is_left_map Sum.isLeft_map
#align sum.is_right_map Sum.isRight_map
#align sum.get_left_map Sum.getLeft?_map
#align sum.get_right_map Sum.getRight?_map
open Function (update update_eq_iff update_comp_eq_of_injective update_comp_eq_of_forall_ne)
@[simp]
theorem update_elim_inl [DecidableEq α] [DecidableEq (Sum α β)] {f : α → γ} {g : β → γ} {i : α}
{x : γ} : update (Sum.elim f g) (inl i) x = Sum.elim (update f i x) g :=
update_eq_iff.2 ⟨by simp, by simp (config := { contextual := true })⟩
#align sum.update_elim_inl Sum.update_elim_inl
@[simp]
theorem update_elim_inr [DecidableEq β] [DecidableEq (Sum α β)] {f : α → γ} {g : β → γ} {i : β}
{x : γ} : update (Sum.elim f g) (inr i) x = Sum.elim f (update g i x) :=
update_eq_iff.2 ⟨by simp, by simp (config := { contextual := true })⟩
#align sum.update_elim_inr Sum.update_elim_inr
@[simp]
theorem update_inl_comp_inl [DecidableEq α] [DecidableEq (Sum α β)] {f : Sum α β → γ} {i : α}
{x : γ} : update f (inl i) x ∘ inl = update (f ∘ inl) i x :=
update_comp_eq_of_injective _ inl_injective _ _
#align sum.update_inl_comp_inl Sum.update_inl_comp_inl
@[simp]
theorem update_inl_apply_inl [DecidableEq α] [DecidableEq (Sum α β)] {f : Sum α β → γ} {i j : α}
{x : γ} : update f (inl i) x (inl j) = update (f ∘ inl) i x j := by
rw [← update_inl_comp_inl, Function.comp_apply]
#align sum.update_inl_apply_inl Sum.update_inl_apply_inl
@[simp]
theorem update_inl_comp_inr [DecidableEq (Sum α β)] {f : Sum α β → γ} {i : α} {x : γ} :
update f (inl i) x ∘ inr = f ∘ inr :=
(update_comp_eq_of_forall_ne _ _) fun _ ↦ inr_ne_inl
#align sum.update_inl_comp_inr Sum.update_inl_comp_inr
theorem update_inl_apply_inr [DecidableEq (Sum α β)] {f : Sum α β → γ} {i : α} {j : β} {x : γ} :
update f (inl i) x (inr j) = f (inr j) :=
Function.update_noteq inr_ne_inl _ _
#align sum.update_inl_apply_inr Sum.update_inl_apply_inr
@[simp]
theorem update_inr_comp_inl [DecidableEq (Sum α β)] {f : Sum α β → γ} {i : β} {x : γ} :
update f (inr i) x ∘ inl = f ∘ inl :=
(update_comp_eq_of_forall_ne _ _) fun _ ↦ inl_ne_inr
#align sum.update_inr_comp_inl Sum.update_inr_comp_inl
theorem update_inr_apply_inl [DecidableEq (Sum α β)] {f : Sum α β → γ} {i : α} {j : β} {x : γ} :
update f (inr j) x (inl i) = f (inl i) :=
Function.update_noteq inl_ne_inr _ _
#align sum.update_inr_apply_inl Sum.update_inr_apply_inl
@[simp]
theorem update_inr_comp_inr [DecidableEq β] [DecidableEq (Sum α β)] {f : Sum α β → γ} {i : β}
{x : γ} : update f (inr i) x ∘ inr = update (f ∘ inr) i x :=
update_comp_eq_of_injective _ inr_injective _ _
#align sum.update_inr_comp_inr Sum.update_inr_comp_inr
@[simp]
theorem update_inr_apply_inr [DecidableEq β] [DecidableEq (Sum α β)] {f : Sum α β → γ} {i j : β}
{x : γ} : update f (inr i) x (inr j) = update (f ∘ inr) i x j := by
rw [← update_inr_comp_inr, Function.comp_apply]
#align sum.update_inr_apply_inr Sum.update_inr_apply_inr
#align sum.swap Sum.swap
#align sum.swap_inl Sum.swap_inl
#align sum.swap_inr Sum.swap_inr
#align sum.swap_swap Sum.swap_swap
#align sum.swap_swap_eq Sum.swap_swap_eq
@[simp]
theorem swap_leftInverse : Function.LeftInverse (@swap α β) swap :=
swap_swap
#align sum.swap_left_inverse Sum.swap_leftInverse
@[simp]
theorem swap_rightInverse : Function.RightInverse (@swap α β) swap :=
swap_swap
#align sum.swap_right_inverse Sum.swap_rightInverse
#align sum.is_left_swap Sum.isLeft_swap
#align sum.is_right_swap Sum.isRight_swap
#align sum.get_left_swap Sum.getLeft?_swap
#align sum.get_right_swap Sum.getRight?_swap
mk_iff_of_inductive_prop Sum.LiftRel Sum.liftRel_iff
namespace LiftRel
#align sum.lift_rel Sum.LiftRel
#align sum.lift_rel_inl_inl Sum.liftRel_inl_inl
#align sum.not_lift_rel_inl_inr Sum.not_liftRel_inl_inr
#align sum.not_lift_rel_inr_inl Sum.not_liftRel_inr_inl
#align sum.lift_rel_inr_inr Sum.liftRel_inr_inr
#align sum.lift_rel.mono Sum.LiftRel.mono
#align sum.lift_rel.mono_left Sum.LiftRel.mono_left
#align sum.lift_rel.mono_right Sum.LiftRel.mono_right
#align sum.lift_rel.swap Sum.LiftRel.swap
#align sum.lift_rel_swap_iff Sum.liftRel_swap_iff
variable {r : α → γ → Prop} {s : β → δ → Prop} {x : Sum α β} {y : Sum γ δ}
{a : α} {b : β} {c : γ} {d : δ}
theorem isLeft_congr (h : LiftRel r s x y) : x.isLeft ↔ y.isLeft := by cases h <;> rfl
theorem isRight_congr (h : LiftRel r s x y) : x.isRight ↔ y.isRight := by cases h <;> rfl
theorem isLeft_left (h : LiftRel r s x (inl c)) : x.isLeft := by cases h; rfl
theorem isLeft_right (h : LiftRel r s (inl a) y) : y.isLeft := by cases h; rfl
theorem isRight_left (h : LiftRel r s x (inr d)) : x.isRight := by cases h; rfl
theorem isRight_right (h : LiftRel r s (inr b) y) : y.isRight := by cases h; rfl
theorem exists_of_isLeft_left (h₁ : LiftRel r s x y) (h₂ : x.isLeft) :
∃ a c, r a c ∧ x = inl a ∧ y = inl c := by
rcases isLeft_iff.mp h₂ with ⟨_, rfl⟩
simp only [liftRel_iff, false_and, and_false, exists_false, or_false] at h₁
exact h₁
theorem exists_of_isLeft_right (h₁ : LiftRel r s x y) (h₂ : y.isLeft) :
∃ a c, r a c ∧ x = inl a ∧ y = inl c := exists_of_isLeft_left h₁ ((isLeft_congr h₁).mpr h₂)
theorem exists_of_isRight_left (h₁ : LiftRel r s x y) (h₂ : x.isRight) :
∃ b d, s b d ∧ x = inr b ∧ y = inr d := by
rcases isRight_iff.mp h₂ with ⟨_, rfl⟩
simp only [liftRel_iff, false_and, and_false, exists_false, false_or] at h₁
exact h₁
theorem exists_of_isRight_right (h₁ : LiftRel r s x y) (h₂ : y.isRight) :
∃ b d, s b d ∧ x = inr b ∧ y = inr d :=
exists_of_isRight_left h₁ ((isRight_congr h₁).mpr h₂)
end LiftRel
section Lex
#align sum.lex.inl Sum.Lex.inl
#align sum.lex.inr Sum.Lex.inr
#align sum.lex.sep Sum.Lex.sep
#align sum.lex Sum.Lex
#align sum.lex_inl_inl Sum.lex_inl_inl
#align sum.lex_inr_inr Sum.lex_inr_inr
#align sum.lex_inr_inl Sum.lex_inr_inl
#align sum.lift_rel.lex Sum.LiftRel.lex
#align sum.lift_rel_subrelation_lex Sum.liftRel_subrelation_lex
#align sum.lex.mono_left Sum.Lex.mono_left
#align sum.lex.mono_right Sum.Lex.mono_right
#align sum.lex_acc_inl Sum.lex_acc_inl
#align sum.lex_acc_inr Sum.lex_acc_inr
#align sum.lex_wf Sum.lex_wf
end Lex
end Sum
open Sum
namespace Function
theorem Injective.sum_elim {f : α → γ} {g : β → γ} (hf : Injective f) (hg : Injective g)
(hfg : ∀ a b, f a ≠ g b) : Injective (Sum.elim f g)
| inl _, inl _, h => congr_arg inl <| hf h
| inl _, inr _, h => (hfg _ _ h).elim
| inr _, inl _, h => (hfg _ _ h.symm).elim
| inr _, inr _, h => congr_arg inr <| hg h
#align function.injective.sum_elim Function.Injective.sum_elim
theorem Injective.sum_map {f : α → β} {g : α' → β'} (hf : Injective f) (hg : Injective g) :
Injective (Sum.map f g)
| inl _, inl _, h => congr_arg inl <| hf <| inl.inj h
| inr _, inr _, h => congr_arg inr <| hg <| inr.inj h
#align function.injective.sum_map Function.Injective.sum_map
theorem Surjective.sum_map {f : α → β} {g : α' → β'} (hf : Surjective f) (hg : Surjective g) :
Surjective (Sum.map f g)
| inl y =>
let ⟨x, hx⟩ := hf y
⟨inl x, congr_arg inl hx⟩
| inr y =>
let ⟨x, hx⟩ := hg y
⟨inr x, congr_arg inr hx⟩
#align function.surjective.sum_map Function.Surjective.sum_map
theorem Bijective.sum_map {f : α → β} {g : α' → β'} (hf : Bijective f) (hg : Bijective g) :
Bijective (Sum.map f g) :=
⟨hf.injective.sum_map hg.injective, hf.surjective.sum_map hg.surjective⟩
#align function.bijective.sum_map Function.Bijective.sum_map
end Function
namespace Sum
open Function
@[simp]
theorem map_injective {f : α → γ} {g : β → δ} :
Injective (Sum.map f g) ↔ Injective f ∧ Injective g :=
⟨fun h =>
⟨fun a₁ a₂ ha => inl_injective <| @h (inl a₁) (inl a₂) (congr_arg inl ha : _), fun b₁ b₂ hb =>
inr_injective <| @h (inr b₁) (inr b₂) (congr_arg inr hb : _)⟩,
fun h => h.1.sum_map h.2⟩
#align sum.map_injective Sum.map_injective
@[simp]
theorem map_surjective {f : α → γ} {g : β → δ} :
Surjective (Sum.map f g) ↔ Surjective f ∧ Surjective g :=
⟨ fun h => ⟨
(fun c => by
obtain ⟨a | b, h⟩ := h (inl c)
· exact ⟨a, inl_injective h⟩
· cases h),
(fun d => by
obtain ⟨a | b, h⟩ := h (inr d)
· cases h
· exact ⟨b, inr_injective h⟩)⟩,
fun h => h.1.sum_map h.2⟩
#align sum.map_surjective Sum.map_surjective
@[simp]
theorem map_bijective {f : α → γ} {g : β → δ} :
Bijective (Sum.map f g) ↔ Bijective f ∧ Bijective g :=
(map_injective.and map_surjective).trans <| and_and_and_comm
#align sum.map_bijective Sum.map_bijective
#align sum.elim_const_const Sum.elim_const_const
#align sum.elim_lam_const_lam_const Sum.elim_lam_const_lam_const
theorem elim_update_left [DecidableEq α] [DecidableEq β] (f : α → γ) (g : β → γ) (i : α) (c : γ) :
Sum.elim (Function.update f i c) g = Function.update (Sum.elim f g) (inl i) c := by
ext x
rcases x with x | x
· by_cases h : x = i
· subst h
simp
· simp [h]
· simp
#align sum.elim_update_left Sum.elim_update_left
| Mathlib/Data/Sum/Basic.lean | 343 | 351 | theorem elim_update_right [DecidableEq α] [DecidableEq β] (f : α → γ) (g : β → γ) (i : β) (c : γ) :
Sum.elim f (Function.update g i c) = Function.update (Sum.elim f g) (inr i) c := by |
ext x
rcases x with x | x
· simp
· by_cases h : x = i
· subst h
simp
· simp [h]
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Funext
import Mathlib.Algebra.Ring.ULift
import Mathlib.RingTheory.WittVector.Basic
#align_import ring_theory.witt_vector.is_poly from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
/-!
# The `is_poly` predicate
`WittVector.IsPoly` is a (type-valued) predicate on functions `f : Π R, 𝕎 R → 𝕎 R`.
It asserts that there is a family of polynomials `φ : ℕ → MvPolynomial ℕ ℤ`,
such that the `n`th coefficient of `f x` is equal to `φ n` evaluated on the coefficients of `x`.
Many operations on Witt vectors satisfy this predicate (or an analogue for higher arity functions).
We say that such a function `f` is a *polynomial function*.
The power of satisfying this predicate comes from `WittVector.IsPoly.ext`.
It shows that if `φ` and `ψ` witness that `f` and `g` are polynomial functions,
then `f = g` not merely when `φ = ψ`, but in fact it suffices to prove
```
∀ n, bind₁ φ (wittPolynomial p _ n) = bind₁ ψ (wittPolynomial p _ n)
```
(in other words, when evaluating the Witt polynomials on `φ` and `ψ`, we get the same values)
which will then imply `φ = ψ` and hence `f = g`.
Even though this sufficient condition looks somewhat intimidating,
it is rather pleasant to check in practice;
more so than direct checking of `φ = ψ`.
In practice, we apply this technique to show that the composition of `WittVector.frobenius`
and `WittVector.verschiebung` is equal to multiplication by `p`.
## Main declarations
* `WittVector.IsPoly`, `WittVector.IsPoly₂`:
two predicates that assert that a unary/binary function on Witt vectors
is polynomial in the coefficients of the input values.
* `WittVector.IsPoly.ext`, `WittVector.IsPoly₂.ext`:
two polynomial functions are equal if their families of polynomials are equal
after evaluating the Witt polynomials on them.
* `WittVector.IsPoly.comp` (+ many variants) show that unary/binary compositions
of polynomial functions are polynomial.
* `WittVector.idIsPoly`, `WittVector.negIsPoly`,
`WittVector.addIsPoly₂`, `WittVector.mulIsPoly₂`:
several well-known operations are polynomial functions
(for Verschiebung, Frobenius, and multiplication by `p`, see their respective files).
## On higher arity analogues
Ideally, there should be a predicate `IsPolyₙ` for functions of higher arity,
together with `IsPolyₙ.comp` that shows how such functions compose.
Since mathlib does not have a library on composition of higher arity functions,
we have only implemented the unary and binary variants so far.
Nullary functions (a.k.a. constants) are treated
as constant functions and fall under the unary case.
## Tactics
There are important metaprograms defined in this file:
the tactics `ghost_simp` and `ghost_calc` and the attribute `@[ghost_simps]`.
These are used in combination to discharge proofs of identities between polynomial functions.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
Any lemma doing "ring equation rewriting" with polynomial functions should be tagged
`@[ghost_simps]`, e.g.
```lean
@[ghost_simps]
lemma bind₁_frobenius_poly_wittPolynomial (n : ℕ) :
bind₁ (frobenius_poly p) (wittPolynomial p ℤ n) = (wittPolynomial p ℤ (n+1))
```
Proofs of identities between polynomial functions will often follow the pattern
```lean
ghost_calc _
<minor preprocessing>
ghost_simp
```
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
universe u
variable {p : ℕ} {R S : Type u} {σ idx : Type*} [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
open MvPolynomial
open Function (uncurry)
variable (p)
noncomputable section
/-!
### The `IsPoly` predicate
-/
theorem poly_eq_of_wittPolynomial_bind_eq' [Fact p.Prime] (f g : ℕ → MvPolynomial (idx × ℕ) ℤ)
(h : ∀ n, bind₁ f (wittPolynomial p _ n) = bind₁ g (wittPolynomial p _ n)) : f = g := by
ext1 n
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [← Function.funext_iff] at h
replace h :=
congr_arg (fun fam => bind₁ (MvPolynomial.map (Int.castRingHom ℚ) ∘ fam) (xInTermsOfW p ℚ n)) h
simpa only [Function.comp, map_bind₁, map_wittPolynomial, ← bind₁_bind₁,
bind₁_wittPolynomial_xInTermsOfW, bind₁_X_right] using h
#align witt_vector.poly_eq_of_witt_polynomial_bind_eq' WittVector.poly_eq_of_wittPolynomial_bind_eq'
theorem poly_eq_of_wittPolynomial_bind_eq [Fact p.Prime] (f g : ℕ → MvPolynomial ℕ ℤ)
(h : ∀ n, bind₁ f (wittPolynomial p _ n) = bind₁ g (wittPolynomial p _ n)) : f = g := by
ext1 n
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [← Function.funext_iff] at h
replace h :=
congr_arg (fun fam => bind₁ (MvPolynomial.map (Int.castRingHom ℚ) ∘ fam) (xInTermsOfW p ℚ n)) h
simpa only [Function.comp, map_bind₁, map_wittPolynomial, ← bind₁_bind₁,
bind₁_wittPolynomial_xInTermsOfW, bind₁_X_right] using h
#align witt_vector.poly_eq_of_witt_polynomial_bind_eq WittVector.poly_eq_of_wittPolynomial_bind_eq
-- Ideally, we would generalise this to n-ary functions
-- But we don't have a good theory of n-ary compositions in mathlib
/--
A function `f : Π R, 𝕎 R → 𝕎 R` that maps Witt vectors to Witt vectors over arbitrary base rings
is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th
coefficient of `f x` is given by evaluating `φₙ` at the coefficients of `x`.
See also `WittVector.IsPoly₂` for the binary variant.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
-/
class IsPoly (f : ∀ ⦃R⦄ [CommRing R], WittVector p R → 𝕎 R) : Prop where mk' ::
poly :
∃ φ : ℕ → MvPolynomial ℕ ℤ,
∀ ⦃R⦄ [CommRing R] (x : 𝕎 R), (f x).coeff = fun n => aeval x.coeff (φ n)
#align witt_vector.is_poly WittVector.IsPoly
/-- The identity function on Witt vectors is a polynomial function. -/
instance idIsPoly : IsPoly p fun _ _ => id :=
⟨⟨X, by intros; simp only [aeval_X, id]⟩⟩
#align witt_vector.id_is_poly WittVector.idIsPoly
instance idIsPolyI' : IsPoly p fun _ _ a => a :=
WittVector.idIsPoly _
#align witt_vector.id_is_poly_i' WittVector.idIsPolyI'
namespace IsPoly
instance : Inhabited (IsPoly p fun _ _ => id) :=
⟨WittVector.idIsPoly p⟩
variable {p}
| Mathlib/RingTheory/WittVector/IsPoly.lean | 172 | 195 | theorem ext [Fact p.Prime] {f g} (hf : IsPoly p f) (hg : IsPoly p g)
(h : ∀ (R : Type u) [_Rcr : CommRing R] (x : 𝕎 R) (n : ℕ),
ghostComponent n (f x) = ghostComponent n (g x)) :
∀ (R : Type u) [_Rcr : CommRing R] (x : 𝕎 R), f x = g x := by |
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
intros
ext n
rw [hf, hg, poly_eq_of_wittPolynomial_bind_eq p φ ψ]
intro k
apply MvPolynomial.funext
intro x
simp only [hom_bind₁]
specialize h (ULift ℤ) (mk p fun i => ⟨x i⟩) k
simp only [ghostComponent_apply, aeval_eq_eval₂Hom] at h
apply (ULift.ringEquiv.symm : ℤ ≃+* _).injective
simp only [← RingEquiv.coe_toRingHom, map_eval₂Hom]
convert h using 1
all_goals
simp only [hf, hg, MvPolynomial.eval, map_eval₂Hom]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext1
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
simp only [coeff_mk]; rfl
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis
-/
import Mathlib.Analysis.InnerProductSpace.Basic
import Mathlib.LinearAlgebra.SesquilinearForm
#align_import analysis.inner_product_space.orthogonal from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Orthogonal complements of submodules
In this file, the `orthogonal` complement of a submodule `K` is defined, and basic API established.
Some of the more subtle results about the orthogonal complement are delayed to
`Analysis.InnerProductSpace.Projection`.
See also `BilinForm.orthogonal` for orthogonality with respect to a general bilinear form.
## Notation
The orthogonal complement of a submodule `K` is denoted by `Kᗮ`.
The proposition that two submodules are orthogonal, `Submodule.IsOrtho`, is denoted by `U ⟂ V`.
Note this is not the same unicode symbol as `⊥` (`Bot`).
-/
variable {𝕜 E F : Type*} [RCLike 𝕜]
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
namespace Submodule
variable (K : Submodule 𝕜 E)
/-- The subspace of vectors orthogonal to a given subspace. -/
def orthogonal : Submodule 𝕜 E where
carrier := { v | ∀ u ∈ K, ⟪u, v⟫ = 0 }
zero_mem' _ _ := inner_zero_right _
add_mem' hx hy u hu := by rw [inner_add_right, hx u hu, hy u hu, add_zero]
smul_mem' c x hx u hu := by rw [inner_smul_right, hx u hu, mul_zero]
#align submodule.orthogonal Submodule.orthogonal
@[inherit_doc]
notation:1200 K "ᗮ" => orthogonal K
/-- When a vector is in `Kᗮ`. -/
theorem mem_orthogonal (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪u, v⟫ = 0 :=
Iff.rfl
#align submodule.mem_orthogonal Submodule.mem_orthogonal
/-- When a vector is in `Kᗮ`, with the inner product the
other way round. -/
theorem mem_orthogonal' (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪v, u⟫ = 0 := by
simp_rw [mem_orthogonal, inner_eq_zero_symm]
#align submodule.mem_orthogonal' Submodule.mem_orthogonal'
variable {K}
/-- A vector in `K` is orthogonal to one in `Kᗮ`. -/
theorem inner_right_of_mem_orthogonal {u v : E} (hu : u ∈ K) (hv : v ∈ Kᗮ) : ⟪u, v⟫ = 0 :=
(K.mem_orthogonal v).1 hv u hu
#align submodule.inner_right_of_mem_orthogonal Submodule.inner_right_of_mem_orthogonal
/-- A vector in `Kᗮ` is orthogonal to one in `K`. -/
theorem inner_left_of_mem_orthogonal {u v : E} (hu : u ∈ K) (hv : v ∈ Kᗮ) : ⟪v, u⟫ = 0 := by
rw [inner_eq_zero_symm]; exact inner_right_of_mem_orthogonal hu hv
#align submodule.inner_left_of_mem_orthogonal Submodule.inner_left_of_mem_orthogonal
/-- A vector is in `(𝕜 ∙ u)ᗮ` iff it is orthogonal to `u`. -/
theorem mem_orthogonal_singleton_iff_inner_right {u v : E} : v ∈ (𝕜 ∙ u)ᗮ ↔ ⟪u, v⟫ = 0 := by
refine ⟨inner_right_of_mem_orthogonal (mem_span_singleton_self u), ?_⟩
intro hv w hw
rw [mem_span_singleton] at hw
obtain ⟨c, rfl⟩ := hw
simp [inner_smul_left, hv]
#align submodule.mem_orthogonal_singleton_iff_inner_right Submodule.mem_orthogonal_singleton_iff_inner_right
/-- A vector in `(𝕜 ∙ u)ᗮ` is orthogonal to `u`. -/
theorem mem_orthogonal_singleton_iff_inner_left {u v : E} : v ∈ (𝕜 ∙ u)ᗮ ↔ ⟪v, u⟫ = 0 := by
rw [mem_orthogonal_singleton_iff_inner_right, inner_eq_zero_symm]
#align submodule.mem_orthogonal_singleton_iff_inner_left Submodule.mem_orthogonal_singleton_iff_inner_left
| Mathlib/Analysis/InnerProductSpace/Orthogonal.lean | 86 | 90 | theorem sub_mem_orthogonal_of_inner_left {x y : E} (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x - y ∈ Kᗮ := by |
rw [mem_orthogonal']
intro u hu
rw [inner_sub_left, sub_eq_zero]
exact h ⟨u, hu⟩
|
/-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Combinatorics.Hall.Basic
import Mathlib.Data.Fintype.BigOperators
import Mathlib.SetTheory.Cardinal.Finite
#align_import combinatorics.configuration from "leanprover-community/mathlib"@"d2d8742b0c21426362a9dacebc6005db895ca963"
/-!
# Configurations of Points and lines
This file introduces abstract configurations of points and lines, and proves some basic properties.
## Main definitions
* `Configuration.Nondegenerate`: Excludes certain degenerate configurations,
and imposes uniqueness of intersection points.
* `Configuration.HasPoints`: A nondegenerate configuration in which
every pair of lines has an intersection point.
* `Configuration.HasLines`: A nondegenerate configuration in which
every pair of points has a line through them.
* `Configuration.lineCount`: The number of lines through a given point.
* `Configuration.pointCount`: The number of lines through a given line.
## Main statements
* `Configuration.HasLines.card_le`: `HasLines` implies `|P| ≤ |L|`.
* `Configuration.HasPoints.card_le`: `HasPoints` implies `|L| ≤ |P|`.
* `Configuration.HasLines.hasPoints`: `HasLines` and `|P| = |L|` implies `HasPoints`.
* `Configuration.HasPoints.hasLines`: `HasPoints` and `|P| = |L|` implies `HasLines`.
Together, these four statements say that any two of the following properties imply the third:
(a) `HasLines`, (b) `HasPoints`, (c) `|P| = |L|`.
-/
open Finset
namespace Configuration
variable (P L : Type*) [Membership P L]
/-- A type synonym. -/
def Dual :=
P
#align configuration.dual Configuration.Dual
-- Porting note: was `this` instead of `h`
instance [h : Inhabited P] : Inhabited (Dual P) :=
h
instance [Finite P] : Finite (Dual P) :=
‹Finite P›
-- Porting note: was `this` instead of `h`
instance [h : Fintype P] : Fintype (Dual P) :=
h
-- Porting note (#11215): TODO: figure out if this is needed.
set_option synthInstance.checkSynthOrder false in
instance : Membership (Dual L) (Dual P) :=
⟨Function.swap (Membership.mem : P → L → Prop)⟩
/-- A configuration is nondegenerate if:
1) there does not exist a line that passes through all of the points,
2) there does not exist a point that is on all of the lines,
3) there is at most one line through any two points,
4) any two lines have at most one intersection point.
Conditions 3 and 4 are equivalent. -/
class Nondegenerate : Prop where
exists_point : ∀ l : L, ∃ p, p ∉ l
exists_line : ∀ p, ∃ l : L, p ∉ l
eq_or_eq : ∀ {p₁ p₂ : P} {l₁ l₂ : L}, p₁ ∈ l₁ → p₂ ∈ l₁ → p₁ ∈ l₂ → p₂ ∈ l₂ → p₁ = p₂ ∨ l₁ = l₂
#align configuration.nondegenerate Configuration.Nondegenerate
/-- A nondegenerate configuration in which every pair of lines has an intersection point. -/
class HasPoints extends Nondegenerate P L where
mkPoint : ∀ {l₁ l₂ : L}, l₁ ≠ l₂ → P
mkPoint_ax : ∀ {l₁ l₂ : L} (h : l₁ ≠ l₂), mkPoint h ∈ l₁ ∧ mkPoint h ∈ l₂
#align configuration.has_points Configuration.HasPoints
/-- A nondegenerate configuration in which every pair of points has a line through them. -/
class HasLines extends Nondegenerate P L where
mkLine : ∀ {p₁ p₂ : P}, p₁ ≠ p₂ → L
mkLine_ax : ∀ {p₁ p₂ : P} (h : p₁ ≠ p₂), p₁ ∈ mkLine h ∧ p₂ ∈ mkLine h
#align configuration.has_lines Configuration.HasLines
open Nondegenerate
open HasPoints (mkPoint mkPoint_ax)
open HasLines (mkLine mkLine_ax)
instance Dual.Nondegenerate [Nondegenerate P L] : Nondegenerate (Dual L) (Dual P) where
exists_point := @exists_line P L _ _
exists_line := @exists_point P L _ _
eq_or_eq := @fun l₁ l₂ p₁ p₂ h₁ h₂ h₃ h₄ => (@eq_or_eq P L _ _ p₁ p₂ l₁ l₂ h₁ h₃ h₂ h₄).symm
instance Dual.hasLines [HasPoints P L] : HasLines (Dual L) (Dual P) :=
{ Dual.Nondegenerate _ _ with
mkLine := @mkPoint P L _ _
mkLine_ax := @mkPoint_ax P L _ _ }
instance Dual.hasPoints [HasLines P L] : HasPoints (Dual L) (Dual P) :=
{ Dual.Nondegenerate _ _ with
mkPoint := @mkLine P L _ _
mkPoint_ax := @mkLine_ax P L _ _ }
theorem HasPoints.existsUnique_point [HasPoints P L] (l₁ l₂ : L) (hl : l₁ ≠ l₂) :
∃! p, p ∈ l₁ ∧ p ∈ l₂ :=
⟨mkPoint hl, mkPoint_ax hl, fun _ hp =>
(eq_or_eq hp.1 (mkPoint_ax hl).1 hp.2 (mkPoint_ax hl).2).resolve_right hl⟩
#align configuration.has_points.exists_unique_point Configuration.HasPoints.existsUnique_point
theorem HasLines.existsUnique_line [HasLines P L] (p₁ p₂ : P) (hp : p₁ ≠ p₂) :
∃! l : L, p₁ ∈ l ∧ p₂ ∈ l :=
HasPoints.existsUnique_point (Dual L) (Dual P) p₁ p₂ hp
#align configuration.has_lines.exists_unique_line Configuration.HasLines.existsUnique_line
variable {P L}
/-- If a nondegenerate configuration has at least as many points as lines, then there exists
an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/
theorem Nondegenerate.exists_injective_of_card_le [Nondegenerate P L] [Fintype P] [Fintype L]
(h : Fintype.card L ≤ Fintype.card P) : ∃ f : L → P, Function.Injective f ∧ ∀ l, f l ∉ l := by
classical
let t : L → Finset P := fun l => Set.toFinset { p | p ∉ l }
suffices ∀ s : Finset L, s.card ≤ (s.biUnion t).card by
-- Hall's marriage theorem
obtain ⟨f, hf1, hf2⟩ := (Finset.all_card_le_biUnion_card_iff_exists_injective t).mp this
exact ⟨f, hf1, fun l => Set.mem_toFinset.mp (hf2 l)⟩
intro s
by_cases hs₀ : s.card = 0
-- If `s = ∅`, then `s.card = 0 ≤ (s.bUnion t).card`
· simp_rw [hs₀, zero_le]
by_cases hs₁ : s.card = 1
-- If `s = {l}`, then pick a point `p ∉ l`
· obtain ⟨l, rfl⟩ := Finset.card_eq_one.mp hs₁
obtain ⟨p, hl⟩ := exists_point l
rw [Finset.card_singleton, Finset.singleton_biUnion, Nat.one_le_iff_ne_zero]
exact Finset.card_ne_zero_of_mem (Set.mem_toFinset.mpr hl)
suffices (s.biUnion t)ᶜ.card ≤ sᶜ.card by
-- Rephrase in terms of complements (uses `h`)
rw [Finset.card_compl, Finset.card_compl, tsub_le_iff_left] at this
replace := h.trans this
rwa [← add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left (le_add_left s.card_le_univ),
add_le_add_iff_right] at this
have hs₂ : (s.biUnion t)ᶜ.card ≤ 1 := by
-- At most one line through two points of `s`
refine Finset.card_le_one_iff.mpr @fun p₁ p₂ hp₁ hp₂ => ?_
simp_rw [t, Finset.mem_compl, Finset.mem_biUnion, not_exists, not_and,
Set.mem_toFinset, Set.mem_setOf_eq, Classical.not_not] at hp₁ hp₂
obtain ⟨l₁, l₂, hl₁, hl₂, hl₃⟩ :=
Finset.one_lt_card_iff.mp (Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hs₀, hs₁⟩)
exact (eq_or_eq (hp₁ l₁ hl₁) (hp₂ l₁ hl₁) (hp₁ l₂ hl₂) (hp₂ l₂ hl₂)).resolve_right hl₃
by_cases hs₃ : sᶜ.card = 0
· rw [hs₃, Nat.le_zero]
rw [Finset.card_compl, tsub_eq_zero_iff_le, LE.le.le_iff_eq (Finset.card_le_univ _), eq_comm,
Finset.card_eq_iff_eq_univ] at hs₃ ⊢
rw [hs₃]
rw [Finset.eq_univ_iff_forall] at hs₃ ⊢
exact fun p =>
Exists.elim (exists_line p)-- If `s = univ`, then show `s.bUnion t = univ`
fun l hl => Finset.mem_biUnion.mpr ⟨l, Finset.mem_univ l, Set.mem_toFinset.mpr hl⟩
· exact hs₂.trans (Nat.one_le_iff_ne_zero.mpr hs₃)
#align configuration.nondegenerate.exists_injective_of_card_le Configuration.Nondegenerate.exists_injective_of_card_le
-- If `s < univ`, then consequence of `hs₂`
variable (L)
/-- Number of points on a given line. -/
noncomputable def lineCount (p : P) : ℕ :=
Nat.card { l : L // p ∈ l }
#align configuration.line_count Configuration.lineCount
variable (P) {L}
/-- Number of lines through a given point. -/
noncomputable def pointCount (l : L) : ℕ :=
Nat.card { p : P // p ∈ l }
#align configuration.point_count Configuration.pointCount
variable (L)
theorem sum_lineCount_eq_sum_pointCount [Fintype P] [Fintype L] :
∑ p : P, lineCount L p = ∑ l : L, pointCount P l := by
classical
simp only [lineCount, pointCount, Nat.card_eq_fintype_card, ← Fintype.card_sigma]
apply Fintype.card_congr
calc
(Σp, { l : L // p ∈ l }) ≃ { x : P × L // x.1 ∈ x.2 } :=
(Equiv.subtypeProdEquivSigmaSubtype (· ∈ ·)).symm
_ ≃ { x : L × P // x.2 ∈ x.1 } := (Equiv.prodComm P L).subtypeEquiv fun x => Iff.rfl
_ ≃ Σl, { p // p ∈ l } := Equiv.subtypeProdEquivSigmaSubtype fun (l : L) (p : P) => p ∈ l
#align configuration.sum_line_count_eq_sum_point_count Configuration.sum_lineCount_eq_sum_pointCount
variable {P L}
| Mathlib/Combinatorics/Configuration.lean | 200 | 214 | theorem HasLines.pointCount_le_lineCount [HasLines P L] {p : P} {l : L} (h : p ∉ l)
[Finite { l : L // p ∈ l }] : pointCount P l ≤ lineCount L p := by |
by_cases hf : Infinite { p : P // p ∈ l }
· exact (le_of_eq Nat.card_eq_zero_of_infinite).trans (zero_le (lineCount L p))
haveI := fintypeOfNotInfinite hf
cases nonempty_fintype { l : L // p ∈ l }
rw [lineCount, pointCount, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card]
have : ∀ p' : { p // p ∈ l }, p ≠ p' := fun p' hp' => h ((congr_arg (· ∈ l) hp').mpr p'.2)
exact
Fintype.card_le_of_injective (fun p' => ⟨mkLine (this p'), (mkLine_ax (this p')).1⟩)
fun p₁ p₂ hp =>
Subtype.ext
((eq_or_eq p₁.2 p₂.2 (mkLine_ax (this p₁)).2
((congr_arg _ (Subtype.ext_iff.mp hp)).mpr (mkLine_ax (this p₂)).2)).resolve_right
fun h' => (congr_arg (¬p ∈ ·) h').mp h (mkLine_ax (this p₁)).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, Sébastien Gouëzel,
Rémy Degenne
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv
import Mathlib.Analysis.Calculus.FDeriv.Extend
import Mathlib.Analysis.Calculus.Deriv.Prod
import Mathlib.Analysis.SpecialFunctions.Log.Deriv
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv
#align_import analysis.special_functions.pow.deriv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-!
# Derivatives of power function on `ℂ`, `ℝ`, `ℝ≥0`, and `ℝ≥0∞`
We also prove differentiability and provide derivatives for the power functions `x ^ y`.
-/
noncomputable section
open scoped Classical Real Topology NNReal ENNReal Filter
open Filter
namespace Complex
theorem hasStrictFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) :
HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2)
((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ +
(p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p := by
have A : p.1 ≠ 0 := slitPlane_ne_zero hp
have : (fun x : ℂ × ℂ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) :=
((isOpen_ne.preimage continuous_fst).eventually_mem A).mono fun p hp =>
cpow_def_of_ne_zero hp _
rw [cpow_sub _ _ A, cpow_one, mul_div_left_comm, mul_smul, mul_smul]
refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm
simpa only [cpow_def_of_ne_zero A, div_eq_mul_inv, mul_smul, add_comm, smul_add] using
((hasStrictFDerivAt_fst.clog hp).mul hasStrictFDerivAt_snd).cexp
#align complex.has_strict_fderiv_at_cpow Complex.hasStrictFDerivAt_cpow
theorem hasStrictFDerivAt_cpow' {x y : ℂ} (hp : x ∈ slitPlane) :
HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2)
((y * x ^ (y - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ +
(x ^ y * log x) • ContinuousLinearMap.snd ℂ ℂ ℂ) (x, y) :=
@hasStrictFDerivAt_cpow (x, y) hp
#align complex.has_strict_fderiv_at_cpow' Complex.hasStrictFDerivAt_cpow'
theorem hasStrictDerivAt_const_cpow {x y : ℂ} (h : x ≠ 0 ∨ y ≠ 0) :
HasStrictDerivAt (fun y => x ^ y) (x ^ y * log x) y := by
rcases em (x = 0) with (rfl | hx)
· replace h := h.neg_resolve_left rfl
rw [log_zero, mul_zero]
refine (hasStrictDerivAt_const _ 0).congr_of_eventuallyEq ?_
exact (isOpen_ne.eventually_mem h).mono fun y hy => (zero_cpow hy).symm
· simpa only [cpow_def_of_ne_zero hx, mul_one] using
((hasStrictDerivAt_id y).const_mul (log x)).cexp
#align complex.has_strict_deriv_at_const_cpow Complex.hasStrictDerivAt_const_cpow
theorem hasFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) :
HasFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2)
((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ +
(p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p :=
(hasStrictFDerivAt_cpow hp).hasFDerivAt
#align complex.has_fderiv_at_cpow Complex.hasFDerivAt_cpow
end Complex
section fderiv
open Complex
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : E → ℂ} {f' g' : E →L[ℂ] ℂ}
{x : E} {s : Set E} {c : ℂ}
theorem HasStrictFDerivAt.cpow (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x)
(h0 : f x ∈ slitPlane) : HasStrictFDerivAt (fun x => f x ^ g x)
((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := by
convert (@hasStrictFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prod hg)
#align has_strict_fderiv_at.cpow HasStrictFDerivAt.cpow
theorem HasStrictFDerivAt.const_cpow (hf : HasStrictFDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
HasStrictFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') x :=
(hasStrictDerivAt_const_cpow h0).comp_hasStrictFDerivAt x hf
#align has_strict_fderiv_at.const_cpow HasStrictFDerivAt.const_cpow
theorem HasFDerivAt.cpow (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x)
(h0 : f x ∈ slitPlane) : HasFDerivAt (fun x => f x ^ g x)
((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := by
convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prod hg)
#align has_fderiv_at.cpow HasFDerivAt.cpow
theorem HasFDerivAt.const_cpow (hf : HasFDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
HasFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') x :=
(hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivAt x hf
#align has_fderiv_at.const_cpow HasFDerivAt.const_cpow
theorem HasFDerivWithinAt.cpow (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x)
(h0 : f x ∈ slitPlane) : HasFDerivWithinAt (fun x => f x ^ g x)
((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') s x := by
convert
(@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp_hasFDerivWithinAt x (hf.prod hg)
#align has_fderiv_within_at.cpow HasFDerivWithinAt.cpow
theorem HasFDerivWithinAt.const_cpow (hf : HasFDerivWithinAt f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
HasFDerivWithinAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') s x :=
(hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivWithinAt x hf
#align has_fderiv_within_at.const_cpow HasFDerivWithinAt.const_cpow
theorem DifferentiableAt.cpow (hf : DifferentiableAt ℂ f x) (hg : DifferentiableAt ℂ g x)
(h0 : f x ∈ slitPlane) : DifferentiableAt ℂ (fun x => f x ^ g x) x :=
(hf.hasFDerivAt.cpow hg.hasFDerivAt h0).differentiableAt
#align differentiable_at.cpow DifferentiableAt.cpow
theorem DifferentiableAt.const_cpow (hf : DifferentiableAt ℂ f x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
DifferentiableAt ℂ (fun x => c ^ f x) x :=
(hf.hasFDerivAt.const_cpow h0).differentiableAt
#align differentiable_at.const_cpow DifferentiableAt.const_cpow
theorem DifferentiableWithinAt.cpow (hf : DifferentiableWithinAt ℂ f s x)
(hg : DifferentiableWithinAt ℂ g s x) (h0 : f x ∈ slitPlane) :
DifferentiableWithinAt ℂ (fun x => f x ^ g x) s x :=
(hf.hasFDerivWithinAt.cpow hg.hasFDerivWithinAt h0).differentiableWithinAt
#align differentiable_within_at.cpow DifferentiableWithinAt.cpow
theorem DifferentiableWithinAt.const_cpow (hf : DifferentiableWithinAt ℂ f s x)
(h0 : c ≠ 0 ∨ f x ≠ 0) : DifferentiableWithinAt ℂ (fun x => c ^ f x) s x :=
(hf.hasFDerivWithinAt.const_cpow h0).differentiableWithinAt
#align differentiable_within_at.const_cpow DifferentiableWithinAt.const_cpow
theorem DifferentiableOn.cpow (hf : DifferentiableOn ℂ f s) (hg : DifferentiableOn ℂ g s)
(h0 : Set.MapsTo f s slitPlane) : DifferentiableOn ℂ (fun x ↦ f x ^ g x) s :=
fun x hx ↦ (hf x hx).cpow (hg x hx) (h0 hx)
theorem DifferentiableOn.const_cpow (hf : DifferentiableOn ℂ f s)
(h0 : c ≠ 0 ∨ ∀ x ∈ s, f x ≠ 0) : DifferentiableOn ℂ (fun x ↦ c ^ f x) s :=
fun x hx ↦ (hf x hx).const_cpow (h0.imp_right fun h ↦ h x hx)
theorem Differentiable.cpow (hf : Differentiable ℂ f) (hg : Differentiable ℂ g)
(h0 : ∀ x, f x ∈ slitPlane) : Differentiable ℂ (fun x ↦ f x ^ g x) :=
fun x ↦ (hf x).cpow (hg x) (h0 x)
theorem Differentiable.const_cpow (hf : Differentiable ℂ f)
(h0 : c ≠ 0 ∨ ∀ x, f x ≠ 0) : Differentiable ℂ (fun x ↦ c ^ f x) :=
fun x ↦ (hf x).const_cpow (h0.imp_right fun h ↦ h x)
end fderiv
section deriv
open Complex
variable {f g : ℂ → ℂ} {s : Set ℂ} {f' g' x c : ℂ}
/-- A private lemma that rewrites the output of lemmas like `HasFDerivAt.cpow` to the form
expected by lemmas like `HasDerivAt.cpow`. -/
private theorem aux : ((g x * f x ^ (g x - 1)) • (1 : ℂ →L[ℂ] ℂ).smulRight f' +
(f x ^ g x * log (f x)) • (1 : ℂ →L[ℂ] ℂ).smulRight g') 1 =
g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g' := by
simp only [Algebra.id.smul_eq_mul, one_mul, ContinuousLinearMap.one_apply,
ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.add_apply, Pi.smul_apply,
ContinuousLinearMap.coe_smul']
nonrec theorem HasStrictDerivAt.cpow (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x)
(h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ g x)
(g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by
simpa using (hf.cpow hg h0).hasStrictDerivAt
#align has_strict_deriv_at.cpow HasStrictDerivAt.cpow
theorem HasStrictDerivAt.const_cpow (hf : HasStrictDerivAt f f' x) (h : c ≠ 0 ∨ f x ≠ 0) :
HasStrictDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x :=
(hasStrictDerivAt_const_cpow h).comp x hf
#align has_strict_deriv_at.const_cpow HasStrictDerivAt.const_cpow
theorem Complex.hasStrictDerivAt_cpow_const (h : x ∈ slitPlane) :
HasStrictDerivAt (fun z : ℂ => z ^ c) (c * x ^ (c - 1)) x := by
simpa only [mul_zero, add_zero, mul_one] using
(hasStrictDerivAt_id x).cpow (hasStrictDerivAt_const x c) h
#align complex.has_strict_deriv_at_cpow_const Complex.hasStrictDerivAt_cpow_const
theorem HasStrictDerivAt.cpow_const (hf : HasStrictDerivAt f f' x)
(h0 : f x ∈ slitPlane) :
HasStrictDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x :=
(Complex.hasStrictDerivAt_cpow_const h0).comp x hf
#align has_strict_deriv_at.cpow_const HasStrictDerivAt.cpow_const
theorem HasDerivAt.cpow (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x)
(h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ g x)
(g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by
simpa only [aux] using (hf.hasFDerivAt.cpow hg h0).hasDerivAt
#align has_deriv_at.cpow HasDerivAt.cpow
theorem HasDerivAt.const_cpow (hf : HasDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
HasDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x :=
(hasStrictDerivAt_const_cpow h0).hasDerivAt.comp x hf
#align has_deriv_at.const_cpow HasDerivAt.const_cpow
theorem HasDerivAt.cpow_const (hf : HasDerivAt f f' x) (h0 : f x ∈ slitPlane) :
HasDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x :=
(Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp x hf
#align has_deriv_at.cpow_const HasDerivAt.cpow_const
theorem HasDerivWithinAt.cpow (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x)
(h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ g x)
(g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') s x := by
simpa only [aux] using (hf.hasFDerivWithinAt.cpow hg h0).hasDerivWithinAt
#align has_deriv_within_at.cpow HasDerivWithinAt.cpow
theorem HasDerivWithinAt.const_cpow (hf : HasDerivWithinAt f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
HasDerivWithinAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') s x :=
(hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasDerivWithinAt x hf
#align has_deriv_within_at.const_cpow HasDerivWithinAt.const_cpow
theorem HasDerivWithinAt.cpow_const (hf : HasDerivWithinAt f f' s x)
(h0 : f x ∈ slitPlane) :
HasDerivWithinAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') s x :=
(Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp_hasDerivWithinAt x hf
#align has_deriv_within_at.cpow_const HasDerivWithinAt.cpow_const
/-- Although `fun x => x ^ r` for fixed `r` is *not* complex-differentiable along the negative real
line, it is still real-differentiable, and the derivative is what one would formally expect. -/
theorem hasDerivAt_ofReal_cpow {x : ℝ} (hx : x ≠ 0) {r : ℂ} (hr : r ≠ -1) :
HasDerivAt (fun y : ℝ => (y : ℂ) ^ (r + 1) / (r + 1)) (x ^ r) x := by
rw [Ne, ← add_eq_zero_iff_eq_neg, ← Ne] at hr
rcases lt_or_gt_of_ne hx.symm with (hx | hx)
· -- easy case : `0 < x`
-- Porting note: proof used to be
-- convert (((hasDerivAt_id (x : ℂ)).cpow_const _).div_const (r + 1)).comp_ofReal using 1
-- · rw [add_sub_cancel, id.def, mul_one, mul_comm, mul_div_cancel _ hr]
-- · rw [id.def, ofReal_re]; exact Or.inl hx
apply HasDerivAt.comp_ofReal (e := fun y => (y : ℂ) ^ (r + 1) / (r + 1))
convert HasDerivAt.div_const (𝕜 := ℂ) ?_ (r + 1) using 1
· exact (mul_div_cancel_right₀ _ hr).symm
· convert HasDerivAt.cpow_const ?_ ?_ using 1
· rw [add_sub_cancel_right, mul_comm]; exact (mul_one _).symm
· exact hasDerivAt_id (x : ℂ)
· simp [hx]
· -- harder case : `x < 0`
have : ∀ᶠ y : ℝ in 𝓝 x,
(y : ℂ) ^ (r + 1) / (r + 1) = (-y : ℂ) ^ (r + 1) * exp (π * I * (r + 1)) / (r + 1) := by
refine Filter.eventually_of_mem (Iio_mem_nhds hx) fun y hy => ?_
rw [ofReal_cpow_of_nonpos (le_of_lt hy)]
refine HasDerivAt.congr_of_eventuallyEq ?_ this
rw [ofReal_cpow_of_nonpos (le_of_lt hx)]
suffices HasDerivAt (fun y : ℝ => (-↑y) ^ (r + 1) * exp (↑π * I * (r + 1)))
((r + 1) * (-↑x) ^ r * exp (↑π * I * r)) x by
convert this.div_const (r + 1) using 1
conv_rhs => rw [mul_assoc, mul_comm, mul_div_cancel_right₀ _ hr]
rw [mul_add ((π : ℂ) * _), mul_one, exp_add, exp_pi_mul_I, mul_comm (_ : ℂ) (-1 : ℂ),
neg_one_mul]
simp_rw [mul_neg, ← neg_mul, ← ofReal_neg]
suffices HasDerivAt (fun y : ℝ => (↑(-y) : ℂ) ^ (r + 1)) (-(r + 1) * ↑(-x) ^ r) x by
convert this.neg.mul_const _ using 1; ring
suffices HasDerivAt (fun y : ℝ => (y : ℂ) ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) (-x) by
convert @HasDerivAt.scomp ℝ _ ℂ _ _ x ℝ _ _ _ _ _ _ _ _ this (hasDerivAt_neg x) using 1
rw [real_smul, ofReal_neg 1, ofReal_one]; ring
suffices HasDerivAt (fun y : ℂ => y ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) ↑(-x) by
exact this.comp_ofReal
conv in ↑_ ^ _ => rw [(by ring : r = r + 1 - 1)]
convert HasDerivAt.cpow_const ?_ ?_ using 1
· rw [add_sub_cancel_right, add_sub_cancel_right]; exact (mul_one _).symm
· exact hasDerivAt_id ((-x : ℝ) : ℂ)
· simp [hx]
#align has_deriv_at_of_real_cpow hasDerivAt_ofReal_cpow
end deriv
namespace Real
variable {x y z : ℝ}
/-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ × ℝ` such that `0 < p.fst`. -/
theorem hasStrictFDerivAt_rpow_of_pos (p : ℝ × ℝ) (hp : 0 < p.1) :
HasStrictFDerivAt (fun x : ℝ × ℝ => x.1 ^ x.2)
((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℝ ℝ ℝ +
(p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℝ ℝ ℝ) p := by
have : (fun x : ℝ × ℝ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) :=
(continuousAt_fst.eventually (lt_mem_nhds hp)).mono fun p hp => rpow_def_of_pos hp _
refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm
convert ((hasStrictFDerivAt_fst.log hp.ne').mul hasStrictFDerivAt_snd).exp using 1
rw [rpow_sub_one hp.ne', ← rpow_def_of_pos hp, smul_add, smul_smul, mul_div_left_comm,
div_eq_mul_inv, smul_smul, smul_smul, mul_assoc, add_comm]
#align real.has_strict_fderiv_at_rpow_of_pos Real.hasStrictFDerivAt_rpow_of_pos
/-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ × ℝ` such that `p.fst < 0`. -/
theorem hasStrictFDerivAt_rpow_of_neg (p : ℝ × ℝ) (hp : p.1 < 0) :
HasStrictFDerivAt (fun x : ℝ × ℝ => x.1 ^ x.2)
((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℝ ℝ ℝ +
(p.1 ^ p.2 * log p.1 - exp (log p.1 * p.2) * sin (p.2 * π) * π) •
ContinuousLinearMap.snd ℝ ℝ ℝ) p := by
have : (fun x : ℝ × ℝ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) * cos (x.2 * π) :=
(continuousAt_fst.eventually (gt_mem_nhds hp)).mono fun p hp => rpow_def_of_neg hp _
refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm
convert ((hasStrictFDerivAt_fst.log hp.ne).mul hasStrictFDerivAt_snd).exp.mul
(hasStrictFDerivAt_snd.mul_const π).cos using 1
simp_rw [rpow_sub_one hp.ne, smul_add, ← add_assoc, smul_smul, ← add_smul, ← mul_assoc,
mul_comm (cos _), ← rpow_def_of_neg hp]
rw [div_eq_mul_inv, add_comm]; congr 2 <;> ring
#align real.has_strict_fderiv_at_rpow_of_neg Real.hasStrictFDerivAt_rpow_of_neg
/-- The function `fun (x, y) => x ^ y` is infinitely smooth at `(x, y)` unless `x = 0`. -/
theorem contDiffAt_rpow_of_ne (p : ℝ × ℝ) (hp : p.1 ≠ 0) {n : ℕ∞} :
ContDiffAt ℝ n (fun p : ℝ × ℝ => p.1 ^ p.2) p := by
cases' hp.lt_or_lt with hneg hpos
exacts
[(((contDiffAt_fst.log hneg.ne).mul contDiffAt_snd).exp.mul
(contDiffAt_snd.mul contDiffAt_const).cos).congr_of_eventuallyEq
((continuousAt_fst.eventually (gt_mem_nhds hneg)).mono fun p hp => rpow_def_of_neg hp _),
((contDiffAt_fst.log hpos.ne').mul contDiffAt_snd).exp.congr_of_eventuallyEq
((continuousAt_fst.eventually (lt_mem_nhds hpos)).mono fun p hp => rpow_def_of_pos hp _)]
#align real.cont_diff_at_rpow_of_ne Real.contDiffAt_rpow_of_ne
theorem differentiableAt_rpow_of_ne (p : ℝ × ℝ) (hp : p.1 ≠ 0) :
DifferentiableAt ℝ (fun p : ℝ × ℝ => p.1 ^ p.2) p :=
(contDiffAt_rpow_of_ne p hp).differentiableAt le_rfl
#align real.differentiable_at_rpow_of_ne Real.differentiableAt_rpow_of_ne
theorem _root_.HasStrictDerivAt.rpow {f g : ℝ → ℝ} {f' g' : ℝ} (hf : HasStrictDerivAt f f' x)
(hg : HasStrictDerivAt g g' x) (h : 0 < f x) : HasStrictDerivAt (fun x => f x ^ g x)
(f' * g x * f x ^ (g x - 1) + g' * f x ^ g x * Real.log (f x)) x := by
convert (hasStrictFDerivAt_rpow_of_pos ((fun x => (f x, g x)) x) h).comp_hasStrictDerivAt x
(hf.prod hg) using 1
simp [mul_assoc, mul_comm, mul_left_comm]
#align has_strict_deriv_at.rpow HasStrictDerivAt.rpow
theorem hasStrictDerivAt_rpow_const_of_ne {x : ℝ} (hx : x ≠ 0) (p : ℝ) :
HasStrictDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by
cases' hx.lt_or_lt with hx hx
· have := (hasStrictFDerivAt_rpow_of_neg (x, p) hx).comp_hasStrictDerivAt x
((hasStrictDerivAt_id x).prod (hasStrictDerivAt_const _ _))
convert this using 1; simp
· simpa using (hasStrictDerivAt_id x).rpow (hasStrictDerivAt_const x p) hx
#align real.has_strict_deriv_at_rpow_const_of_ne Real.hasStrictDerivAt_rpow_const_of_ne
theorem hasStrictDerivAt_const_rpow {a : ℝ} (ha : 0 < a) (x : ℝ) :
HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a) x := by
simpa using (hasStrictDerivAt_const _ _).rpow (hasStrictDerivAt_id x) ha
#align real.has_strict_deriv_at_const_rpow Real.hasStrictDerivAt_const_rpow
lemma differentiableAt_rpow_const_of_ne (p : ℝ) {x : ℝ} (hx : x ≠ 0) :
DifferentiableAt ℝ (fun x => x ^ p) x :=
(hasStrictDerivAt_rpow_const_of_ne hx p).differentiableAt
lemma differentiableOn_rpow_const (p : ℝ) :
DifferentiableOn ℝ (fun x => (x : ℝ) ^ p) {0}ᶜ :=
fun _ hx => (Real.differentiableAt_rpow_const_of_ne p hx).differentiableWithinAt
/-- This lemma says that `fun x => a ^ x` is strictly differentiable for `a < 0`. Note that these
values of `a` are outside of the "official" domain of `a ^ x`, and we may redefine `a ^ x`
for negative `a` if some other definition will be more convenient. -/
theorem hasStrictDerivAt_const_rpow_of_neg {a x : ℝ} (ha : a < 0) :
HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a - exp (log a * x) * sin (x * π) * π) x := by
simpa using (hasStrictFDerivAt_rpow_of_neg (a, x) ha).comp_hasStrictDerivAt x
((hasStrictDerivAt_const _ _).prod (hasStrictDerivAt_id _))
#align real.has_strict_deriv_at_const_rpow_of_neg Real.hasStrictDerivAt_const_rpow_of_neg
end Real
namespace Real
variable {z x y : ℝ}
| Mathlib/Analysis/SpecialFunctions/Pow/Deriv.lean | 366 | 374 | theorem hasDerivAt_rpow_const {x p : ℝ} (h : x ≠ 0 ∨ 1 ≤ p) :
HasDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by |
rcases ne_or_eq x 0 with (hx | rfl)
· exact (hasStrictDerivAt_rpow_const_of_ne hx _).hasDerivAt
replace h : 1 ≤ p := h.neg_resolve_left rfl
apply hasDerivAt_of_hasDerivAt_of_ne fun x hx =>
(hasStrictDerivAt_rpow_const_of_ne hx p).hasDerivAt
exacts [continuousAt_id.rpow_const (Or.inr (zero_le_one.trans h)),
continuousAt_const.mul (continuousAt_id.rpow_const (Or.inr (sub_nonneg.2 h)))]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Regular.Pow
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Data.Finsupp.Antidiagonal
import Mathlib.Order.SymmDiff
import Mathlib.RingTheory.Adjoin.Basic
#align_import data.mv_polynomial.basic from "leanprover-community/mathlib"@"c8734e8953e4b439147bd6f75c2163f6d27cdce6"
/-!
# Multivariate polynomials
This file defines polynomial rings over a base ring (or even semiring),
with variables from a general type `σ` (which could be infinite).
## Important definitions
Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary
type. This file creates the type `MvPolynomial σ R`, which mathematicians
might denote $R[X_i : i \in σ]$. It is the type of multivariate
(a.k.a. multivariable) polynomials, with variables
corresponding to the terms in `σ`, and coefficients in `R`.
### Notation
In the definitions below, we use the following notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `a : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
### Definitions
* `MvPolynomial σ R` : the type of polynomials with variables of type `σ` and coefficients
in the commutative semiring `R`
* `monomial s a` : the monomial which mathematically would be denoted `a * X^s`
* `C a` : the constant polynomial with value `a`
* `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`.
* `coeff s p` : the coefficient of `s` in `p`.
* `eval₂ (f : R → S₁) (g : σ → S₁) p` : given a semiring homomorphism from `R` to another
semiring `S₁`, and a map `σ → S₁`, evaluates `p` at this valuation, returning a term of type `S₁`.
Note that `eval₂` can be made using `eval` and `map` (see below), and it has been suggested
that sticking to `eval` and `map` might make the code less brittle.
* `eval (g : σ → R) p` : given a map `σ → R`, evaluates `p` at this valuation,
returning a term of type `R`
* `map (f : R → S₁) p` : returns the multivariate polynomial obtained from `p` by the change of
coefficient semiring corresponding to `f`
## Implementation notes
Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite
support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`.
The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all
monomials in the variables, and the function to `R` sends a monomial to its coefficient in
the polynomial being represented.
## Tags
polynomial, multivariate polynomial, multivariable polynomial
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
open scoped Pointwise
universe u v w x
variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x}
/-- Multivariate polynomial, where `σ` is the index set of the variables and
`R` is the coefficient ring -/
def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] :=
AddMonoidAlgebra R (σ →₀ ℕ)
#align mv_polynomial MvPolynomial
namespace MvPolynomial
-- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws
-- tons of warnings in this file, and it's easier to just disable them globally in the file
set_option linter.uppercaseLean3 false
variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
section Instances
instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] :
DecidableEq (MvPolynomial σ R) :=
Finsupp.instDecidableEq
#align mv_polynomial.decidable_eq_mv_polynomial MvPolynomial.decidableEqMvPolynomial
instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) :=
AddMonoidAlgebra.commSemiring
instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) :=
⟨0⟩
instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] :
DistribMulAction R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.distribMulAction
instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] :
SMulZeroClass R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulZeroClass
instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] :
FaithfulSMul R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.faithfulSMul
instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.module
instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.isScalarTower
instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.smulCommClass
instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁]
[IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isCentralScalar
instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] :
Algebra R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.algebra
instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] :
IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isScalarTower_self _
#align mv_polynomial.is_scalar_tower_right MvPolynomial.isScalarTower_right
instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] :
SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulCommClass_self _
#align mv_polynomial.smul_comm_class_right MvPolynomial.smulCommClass_right
/-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/
instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) :=
AddMonoidAlgebra.unique
#align mv_polynomial.unique MvPolynomial.unique
end Instances
variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R}
/-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/
def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R :=
lsingle s
#align mv_polynomial.monomial MvPolynomial.monomial
theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a :=
rfl
#align mv_polynomial.single_eq_monomial MvPolynomial.single_eq_monomial
theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) :=
AddMonoidAlgebra.mul_def
#align mv_polynomial.mul_def MvPolynomial.mul_def
/-- `C a` is the constant polynomial with value `a` -/
def C : R →+* MvPolynomial σ R :=
{ singleZeroRingHom with toFun := monomial 0 }
#align mv_polynomial.C MvPolynomial.C
variable (R σ)
@[simp]
theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C :=
rfl
#align mv_polynomial.algebra_map_eq MvPolynomial.algebraMap_eq
variable {R σ}
/-- `X n` is the degree `1` monomial $X_n$. -/
def X (n : σ) : MvPolynomial σ R :=
monomial (Finsupp.single n 1) 1
#align mv_polynomial.X MvPolynomial.X
theorem monomial_left_injective {r : R} (hr : r ≠ 0) :
Function.Injective fun s : σ →₀ ℕ => monomial s r :=
Finsupp.single_left_injective hr
#align mv_polynomial.monomial_left_injective MvPolynomial.monomial_left_injective
@[simp]
theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) :
monomial s r = monomial t r ↔ s = t :=
Finsupp.single_left_inj hr
#align mv_polynomial.monomial_left_inj MvPolynomial.monomial_left_inj
theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a :=
rfl
#align mv_polynomial.C_apply MvPolynomial.C_apply
-- Porting note (#10618): `simp` can prove this
theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _
#align mv_polynomial.C_0 MvPolynomial.C_0
-- Porting note (#10618): `simp` can prove this
theorem C_1 : C 1 = (1 : MvPolynomial σ R) :=
rfl
#align mv_polynomial.C_1 MvPolynomial.C_1
theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by
-- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas
show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _
simp [C_apply, single_mul_single]
#align mv_polynomial.C_mul_monomial MvPolynomial.C_mul_monomial
-- Porting note (#10618): `simp` can prove this
theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' :=
Finsupp.single_add _ _ _
#align mv_polynomial.C_add MvPolynomial.C_add
-- Porting note (#10618): `simp` can prove this
theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' :=
C_mul_monomial.symm
#align mv_polynomial.C_mul MvPolynomial.C_mul
-- Porting note (#10618): `simp` can prove this
theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n :=
map_pow _ _ _
#align mv_polynomial.C_pow MvPolynomial.C_pow
theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] :
Function.Injective (C : R → MvPolynomial σ R) :=
Finsupp.single_injective _
#align mv_polynomial.C_injective MvPolynomial.C_injective
theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] :
Function.Surjective (C : R → MvPolynomial σ R) := by
refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩
simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0),
single_eq_same]
rfl
#align mv_polynomial.C_surjective MvPolynomial.C_surjective
@[simp]
theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) :
(C r : MvPolynomial σ R) = C s ↔ r = s :=
(C_injective σ R).eq_iff
#align mv_polynomial.C_inj MvPolynomial.C_inj
instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] :
Nontrivial (MvPolynomial σ R) :=
inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ))
instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] :
Infinite (MvPolynomial σ R) :=
Infinite.of_injective C (C_injective _ _)
#align mv_polynomial.infinite_of_infinite MvPolynomial.infinite_of_infinite
instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R]
[Nontrivial R] : Infinite (MvPolynomial σ R) :=
Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ))
<| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _)
#align mv_polynomial.infinite_of_nonempty MvPolynomial.infinite_of_nonempty
theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by
induction n <;> simp [Nat.succ_eq_add_one, *]
#align mv_polynomial.C_eq_coe_nat MvPolynomial.C_eq_coe_nat
theorem C_mul' : MvPolynomial.C a * p = a • p :=
(Algebra.smul_def a p).symm
#align mv_polynomial.C_mul' MvPolynomial.C_mul'
theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p :=
C_mul'.symm
#align mv_polynomial.smul_eq_C_mul MvPolynomial.smul_eq_C_mul
| Mathlib/Algebra/MvPolynomial/Basic.lean | 284 | 285 | theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by |
rw [← C_mul', mul_one]
|
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
import Mathlib.Analysis.Complex.CauchyIntegral
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Β(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : ℂ` with `s ∉ {-n : n ∈ ℕ}` we have `Γ s ≠ 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n → ∞` of the sequence
`n ↦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Γ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = π / sin π s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Γ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * √π`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Β (u, v)`, defined as `∫ x:ℝ in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : ℂ) : ℂ :=
∫ x : ℝ in (0)..1, (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : ℂ} (hu : 0 < re u) (v : ℂ) :
IntervalIntegrable (fun x =>
(x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1) : ℝ → ℂ) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
· refine intervalIntegral.intervalIntegrable_cpow' ?_
rwa [sub_re, one_re, ← zero_sub, sub_lt_sub_iff_right]
· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : ℝ) ≤ 1 / 2)] at hx
apply ContinuousAt.cpow
· exact (continuous_const.sub continuous_ofReal).continuousAt
· exact continuousAt_const
· norm_cast
exact ofReal_mem_slitPlane.2 <| by linarith only [hx.2]
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : ℂ} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1) : ℝ → ℂ) volume 0 1 := by
refine (betaIntegral_convergent_left hu v).trans ?_
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> · push_cast; ring
· norm_num
· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : ℂ) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : ℝ => (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, ← intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel_right, neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, ← sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : ℂ} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
· rwa [sub_re, one_re, ← sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : ℂ) {a : ℝ} (ha : 0 < a) :
∫ x in (0)..a, (x : ℂ) ^ (s - 1) * ((a : ℂ) - x) ^ (t - 1) =
(a : ℂ) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : ℂ) ≠ 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : ℂ) ^ (s + t - 1) = a * ((a : ℂ) ^ (s - 1) * (a : ℂ) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, ← intervalIntegral.integral_const_mul, ← real_smul, ← zero_div a, ←
div_self ha.ne', ← intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine setIntegral_congr measurableSet_Ioc fun x hx => ?_
rw [mul_mul_mul_comm]
congr 1
· rw [← mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel₀ _ ha']
· rw [(by norm_cast : (1 : ℂ) - ↑(x / a) = ↑(1 - x / a)), ←
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel₀ _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : ℂ} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul ℝ ℂ)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, ← conv_int, ← integral_mul_right (betaIntegral _ _)]
refine setIntegral_congr measurableSet_Ioi fun x hx => ?_
rw [mul_assoc, ← betaIntegral_scaled s t hx, ← intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
rw [← Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
| Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean | 155 | 209 | theorem betaIntegral_recurrence {u v : ℂ} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by |
-- NB: If we knew `Gamma (u + v + 1) ≠ 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : ℝ → ℂ := fun x => (x : ℂ) ^ u * (1 - (x : ℂ)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine (ContinuousAt.continuousOn fun x hx => ?_).mul (ContinuousAt.continuousOn fun x hx => ?_)
· refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
· refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : ∀ x : ℝ, x ∈ Ioo (0 : ℝ) 1 →
HasDerivAt F (u * ((x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ v) -
v * ((x : ℂ) ^ u * (1 - (x : ℂ)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : ℂ => y ^ u) (u * (x : ℂ) ^ (u - 1)) ↑x := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : ℂ)) (Or.inl ?_)
· simp only [id_eq, mul_one] at this
exact this
· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : ℂ => (1 - y) ^ v) (-v * (1 - (x : ℂ)) ^ (v - 1)) ↑x := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : ℂ))) (Or.inl ?_)
swap; · rw [id, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id] at A
have B : HasDerivAt (fun y : ℂ => 1 - y) (-1) ↑x := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (↑x) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel_right, add_sub_cancel_right] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [F, mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne,
true_and_iff, sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [F, mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
· rw [betaIntegral, betaIntegral, ← sub_eq_zero]
convert int_ev <;> ring
· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
|
/-
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.FieldTheory.Finiteness
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition
import Mathlib.LinearAlgebra.Dimension.DivisionRing
#align_import linear_algebra.finite_dimensional from "leanprover-community/mathlib"@"e95e4f92c8f8da3c7f693c3ec948bcf9b6683f51"
/-!
# Finite dimensional vector spaces
Definition and basic properties of finite dimensional vector spaces, of their dimensions, and
of linear maps on such spaces.
## Main definitions
Assume `V` is a vector space over a division ring `K`. There are (at least) three equivalent
definitions of finite-dimensionality of `V`:
- it admits a finite basis.
- it is finitely generated.
- it is noetherian, i.e., every subspace is finitely generated.
We introduce a typeclass `FiniteDimensional K V` capturing this property. For ease of transfer of
proof, it is defined using the second point of view, i.e., as `Finite`. However, we prove
that all these points of view are equivalent, with the following lemmas
(in the namespace `FiniteDimensional`):
- `fintypeBasisIndex` states that a finite-dimensional
vector space has a finite basis
- `FiniteDimensional.finBasis` and `FiniteDimensional.finBasisOfFinrankEq`
are bases for finite dimensional vector spaces, where the index type
is `Fin`
- `of_fintype_basis` states that the existence of a basis indexed by a
finite type implies finite-dimensionality
- `of_finite_basis` states that the existence of a basis indexed by a
finite set implies finite-dimensionality
- `IsNoetherian.iff_fg` states that the space is finite-dimensional if and only if
it is noetherian
We make use of `finrank`, the dimension of a finite dimensional space, returning a `Nat`, as
opposed to `Module.rank`, which returns a `Cardinal`. When the space has infinite dimension, its
`finrank` is by convention set to `0`. `finrank` is not defined using `FiniteDimensional`.
For basic results that do not need the `FiniteDimensional` class, import
`Mathlib.LinearAlgebra.Finrank`.
Preservation of finite-dimensionality and formulas for the dimension are given for
- submodules
- quotients (for the dimension of a quotient, see `finrank_quotient_add_finrank`)
- linear equivs, in `LinearEquiv.finiteDimensional`
- image under a linear map (the rank-nullity formula is in `finrank_range_add_finrank_ker`)
Basic properties of linear maps of a finite-dimensional vector space are given. Notably, the
equivalence of injectivity and surjectivity is proved in `LinearMap.injective_iff_surjective`,
and the equivalence between left-inverse and right-inverse in `LinearMap.mul_eq_one_comm`
and `LinearMap.comp_eq_id_comm`.
## Implementation notes
Most results are deduced from the corresponding results for the general dimension (as a cardinal),
in `Mathlib.LinearAlgebra.Dimension`. Not all results have been ported yet.
You should not assume that there has been any effort to state lemmas as generally as possible.
Plenty of the results hold for general fg modules or notherian modules, and they can be found in
`Mathlib.LinearAlgebra.FreeModule.Finite.Rank` and `Mathlib.RingTheory.Noetherian`.
-/
universe u v v' w
open Cardinal Submodule Module Function
/-- `FiniteDimensional` vector spaces are defined to be finite modules.
Use `FiniteDimensional.of_fintype_basis` to prove finite dimension from another definition. -/
abbrev FiniteDimensional (K V : Type*) [DivisionRing K] [AddCommGroup V] [Module K V] :=
Module.Finite K V
#align finite_dimensional FiniteDimensional
variable {K : Type u} {V : Type v}
namespace FiniteDimensional
open IsNoetherian
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- If the codomain of an injective linear map is finite dimensional, the domain must be as well. -/
theorem of_injective (f : V →ₗ[K] V₂) (w : Function.Injective f) [FiniteDimensional K V₂] :
FiniteDimensional K V :=
have : IsNoetherian K V₂ := IsNoetherian.iff_fg.mpr ‹_›
Module.Finite.of_injective f w
#align finite_dimensional.of_injective FiniteDimensional.of_injective
/-- If the domain of a surjective linear map is finite dimensional, the codomain must be as well. -/
theorem of_surjective (f : V →ₗ[K] V₂) (w : Function.Surjective f) [FiniteDimensional K V] :
FiniteDimensional K V₂ :=
Module.Finite.of_surjective f w
#align finite_dimensional.of_surjective FiniteDimensional.of_surjective
variable (K V)
instance finiteDimensional_pi {ι : Type*} [Finite ι] : FiniteDimensional K (ι → K) :=
Finite.pi
#align finite_dimensional.finite_dimensional_pi FiniteDimensional.finiteDimensional_pi
instance finiteDimensional_pi' {ι : Type*} [Finite ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)]
[∀ i, Module K (M i)] [∀ i, FiniteDimensional K (M i)] : FiniteDimensional K (∀ i, M i) :=
Finite.pi
#align finite_dimensional.finite_dimensional_pi' FiniteDimensional.finiteDimensional_pi'
/-- A finite dimensional vector space over a finite field is finite -/
noncomputable def fintypeOfFintype [Fintype K] [FiniteDimensional K V] : Fintype V :=
Module.fintypeOfFintype (@finsetBasis K V _ _ _ (iff_fg.2 inferInstance))
#align finite_dimensional.fintype_of_fintype FiniteDimensional.fintypeOfFintype
theorem finite_of_finite [Finite K] [FiniteDimensional K V] : Finite V := by
cases nonempty_fintype K
haveI := fintypeOfFintype K V
infer_instance
#align finite_dimensional.finite_of_finite FiniteDimensional.finite_of_finite
variable {K V}
/-- If a vector space has a finite basis, then it is finite-dimensional. -/
theorem of_fintype_basis {ι : Type w} [Finite ι] (h : Basis ι K V) : FiniteDimensional K V :=
Module.Finite.of_basis h
#align finite_dimensional.of_fintype_basis FiniteDimensional.of_fintype_basis
/-- If a vector space is `FiniteDimensional`, all bases are indexed by a finite type -/
noncomputable def fintypeBasisIndex {ι : Type*} [FiniteDimensional K V] (b : Basis ι K V) :
Fintype ι :=
@Fintype.ofFinite _ (Module.Finite.finite_basis b)
#align finite_dimensional.fintype_basis_index FiniteDimensional.fintypeBasisIndex
/-- If a vector space is `FiniteDimensional`, `Basis.ofVectorSpace` is indexed by
a finite type. -/
noncomputable instance [FiniteDimensional K V] : Fintype (Basis.ofVectorSpaceIndex K V) := by
letI : IsNoetherian K V := IsNoetherian.iff_fg.2 inferInstance
infer_instance
/-- If a vector space has a basis indexed by elements of a finite set, then it is
finite-dimensional. -/
theorem of_finite_basis {ι : Type w} {s : Set ι} (h : Basis s K V) (hs : Set.Finite s) :
FiniteDimensional K V :=
haveI := hs.fintype
of_fintype_basis h
#align finite_dimensional.of_finite_basis FiniteDimensional.of_finite_basis
/-- A subspace of a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_submodule [FiniteDimensional K V] (S : Submodule K V) :
FiniteDimensional K S := by
letI : IsNoetherian K V := iff_fg.2 ?_
· exact
iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2
(lt_of_le_of_lt (rank_submodule_le _) (_root_.rank_lt_aleph0 K V)))
· infer_instance
#align finite_dimensional.finite_dimensional_submodule FiniteDimensional.finiteDimensional_submodule
/-- A quotient of a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_quotient [FiniteDimensional K V] (S : Submodule K V) :
FiniteDimensional K (V ⧸ S) :=
Module.Finite.quotient K S
#align finite_dimensional.finite_dimensional_quotient FiniteDimensional.finiteDimensional_quotient
variable (K V)
/-- In a finite-dimensional space, its dimension (seen as a cardinal) coincides with its
`finrank`. This is a copy of `finrank_eq_rank _ _` which creates easier typeclass searches. -/
theorem finrank_eq_rank' [FiniteDimensional K V] : (finrank K V : Cardinal.{v}) = Module.rank K V :=
finrank_eq_rank _ _
#align finite_dimensional.finrank_eq_rank' FiniteDimensional.finrank_eq_rank'
variable {K V}
theorem finrank_of_infinite_dimensional (h : ¬FiniteDimensional K V) : finrank K V = 0 :=
FiniteDimensional.finrank_of_not_finite h
#align finite_dimensional.finrank_of_infinite_dimensional FiniteDimensional.finrank_of_infinite_dimensional
theorem of_finrank_pos (h : 0 < finrank K V) : FiniteDimensional K V :=
Module.finite_of_finrank_pos h
#align finite_dimensional.finite_dimensional_of_finrank FiniteDimensional.of_finrank_pos
theorem of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) :
FiniteDimensional K V :=
Module.finite_of_finrank_eq_succ hn
#align finite_dimensional.finite_dimensional_of_finrank_eq_succ FiniteDimensional.of_finrank_eq_succ
/-- We can infer `FiniteDimensional K V` in the presence of `[Fact (finrank K V = n + 1)]`. Declare
this as a local instance where needed. -/
theorem of_fact_finrank_eq_succ (n : ℕ) [hn : Fact (finrank K V = n + 1)] :
FiniteDimensional K V :=
of_finrank_eq_succ hn.out
#align finite_dimensional.fact_finite_dimensional_of_finrank_eq_succ FiniteDimensional.of_fact_finrank_eq_succ
theorem finiteDimensional_iff_of_rank_eq_nsmul {W} [AddCommGroup W] [Module K W] {n : ℕ}
(hn : n ≠ 0) (hVW : Module.rank K V = n • Module.rank K W) :
FiniteDimensional K V ↔ FiniteDimensional K W :=
Module.finite_iff_of_rank_eq_nsmul hn hVW
#align finite_dimensional.finite_dimensional_iff_of_rank_eq_nsmul FiniteDimensional.finiteDimensional_iff_of_rank_eq_nsmul
/-- If a vector space is finite-dimensional, then the cardinality of any basis is equal to its
`finrank`. -/
theorem finrank_eq_card_basis' [FiniteDimensional K V] {ι : Type w} (h : Basis ι K V) :
(finrank K V : Cardinal.{w}) = #ι :=
Module.mk_finrank_eq_card_basis h
#align finite_dimensional.finrank_eq_card_basis' FiniteDimensional.finrank_eq_card_basis'
theorem _root_.LinearIndependent.lt_aleph0_of_finiteDimensional {ι : Type w} [FiniteDimensional K V]
{v : ι → V} (h : LinearIndependent K v) : #ι < ℵ₀ :=
h.lt_aleph0_of_finite
#align finite_dimensional.lt_aleph_0_of_linear_independent LinearIndependent.lt_aleph0_of_finiteDimensional
@[deprecated (since := "2023-12-27")]
alias lt_aleph0_of_linearIndependent := LinearIndependent.lt_aleph0_of_finiteDimensional
/-- If a submodule has maximal dimension in a finite dimensional space, then it is equal to the
whole space. -/
theorem _root_.Submodule.eq_top_of_finrank_eq [FiniteDimensional K V] {S : Submodule K V}
(h : finrank K S = finrank K V) : S = ⊤ := by
haveI : IsNoetherian K V := iff_fg.2 inferInstance
set bS := Basis.ofVectorSpace K S with bS_eq
have : LinearIndependent K ((↑) : ((↑) '' Basis.ofVectorSpaceIndex K S : Set V) → V) :=
LinearIndependent.image_subtype (f := Submodule.subtype S)
(by simpa [bS] using bS.linearIndependent) (by simp)
set b := Basis.extend this with b_eq
-- Porting note: `letI` now uses `this` so we need to give different names
letI i1 : Fintype (this.extend _) :=
(LinearIndependent.set_finite_of_isNoetherian (by simpa [b] using b.linearIndependent)).fintype
letI i2 : Fintype (((↑) : S → V) '' Basis.ofVectorSpaceIndex K S) :=
(LinearIndependent.set_finite_of_isNoetherian this).fintype
letI i3 : Fintype (Basis.ofVectorSpaceIndex K S) :=
(LinearIndependent.set_finite_of_isNoetherian
(by simpa [bS] using bS.linearIndependent)).fintype
have : (↑) '' Basis.ofVectorSpaceIndex K S = this.extend (Set.subset_univ _) :=
Set.eq_of_subset_of_card_le (this.subset_extend _)
(by
rw [Set.card_image_of_injective _ Subtype.coe_injective, ← finrank_eq_card_basis bS, ←
finrank_eq_card_basis b, h])
rw [← b.span_eq, b_eq, Basis.coe_extend, Subtype.range_coe, ← this, ← Submodule.coeSubtype,
span_image]
have := bS.span_eq
rw [bS_eq, Basis.coe_ofVectorSpace, Subtype.range_coe] at this
rw [this, Submodule.map_top (Submodule.subtype S), range_subtype]
#align finite_dimensional.eq_top_of_finrank_eq Submodule.eq_top_of_finrank_eq
#align submodule.eq_top_of_finrank_eq Submodule.eq_top_of_finrank_eq
variable (K)
instance finiteDimensional_self : FiniteDimensional K K := inferInstance
#align finite_dimensional.finite_dimensional_self FiniteDimensional.finiteDimensional_self
/-- The submodule generated by a finite set is finite-dimensional. -/
theorem span_of_finite {A : Set V} (hA : Set.Finite A) : FiniteDimensional K (Submodule.span K A) :=
Module.Finite.span_of_finite K hA
#align finite_dimensional.span_of_finite FiniteDimensional.span_of_finite
/-- The submodule generated by a single element is finite-dimensional. -/
instance span_singleton (x : V) : FiniteDimensional K (K ∙ x) :=
Module.Finite.span_singleton K x
#align finite_dimensional.span_singleton FiniteDimensional.span_singleton
/-- The submodule generated by a finset is finite-dimensional. -/
instance span_finset (s : Finset V) : FiniteDimensional K (span K (s : Set V)) :=
Module.Finite.span_finset K s
#align finite_dimensional.span_finset FiniteDimensional.span_finset
/-- Pushforwards of finite-dimensional submodules are finite-dimensional. -/
instance (f : V →ₗ[K] V₂) (p : Submodule K V) [FiniteDimensional K p] :
FiniteDimensional K (p.map f) :=
Module.Finite.map _ _
variable {K}
section
open Finset
section
variable {L : Type*} [LinearOrderedField L]
variable {W : Type v} [AddCommGroup W] [Module L W]
/-- A slight strengthening of `exists_nontrivial_relation_sum_zero_of_rank_succ_lt_card`
available when working over an ordered field:
we can ensure a positive coefficient, not just a nonzero coefficient.
-/
theorem exists_relation_sum_zero_pos_coefficient_of_finrank_succ_lt_card [FiniteDimensional L W]
{t : Finset W} (h : finrank L W + 1 < t.card) :
∃ f : W → L, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, 0 < f x := by
obtain ⟨f, sum, total, nonzero⟩ :=
Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card h
exact ⟨f, sum, total, exists_pos_of_sum_zero_of_exists_nonzero f total nonzero⟩
#align finite_dimensional.exists_relation_sum_zero_pos_coefficient_of_rank_succ_lt_card FiniteDimensional.exists_relation_sum_zero_pos_coefficient_of_finrank_succ_lt_card
end
end
/-- In a vector space with dimension 1, each set {v} is a basis for `v ≠ 0`. -/
@[simps repr_apply]
noncomputable def basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V)
(hv : v ≠ 0) : Basis ι K V :=
let b := FiniteDimensional.basisUnique ι h
let h : b.repr v default ≠ 0 := mt FiniteDimensional.basisUnique_repr_eq_zero_iff.mp hv
Basis.ofRepr
{ toFun := fun w => Finsupp.single default (b.repr w default / b.repr v default)
invFun := fun f => f default • v
map_add' := by simp [add_div]
map_smul' := by simp [mul_div]
left_inv := fun w => by
apply_fun b.repr using b.repr.toEquiv.injective
apply_fun Equiv.finsuppUnique
simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,
smul_eq_mul, Pi.smul_apply, Equiv.finsuppUnique_apply]
exact div_mul_cancel₀ _ h
right_inv := fun f => by
ext
simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,
RingHom.id_apply, smul_eq_mul, Pi.smul_apply]
exact mul_div_cancel_right₀ _ h }
#align finite_dimensional.basis_singleton FiniteDimensional.basisSingleton
@[simp]
theorem basisSingleton_apply (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0)
(i : ι) : basisSingleton ι h v hv i = v := by
cases Unique.uniq ‹Unique ι› i
simp [basisSingleton]
#align finite_dimensional.basis_singleton_apply FiniteDimensional.basisSingleton_apply
@[simp]
theorem range_basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0) :
Set.range (basisSingleton ι h v hv) = {v} := by rw [Set.range_unique, basisSingleton_apply]
#align finite_dimensional.range_basis_singleton FiniteDimensional.range_basisSingleton
end DivisionRing
section Tower
variable (F K A : Type*) [DivisionRing F] [DivisionRing K] [AddCommGroup A]
variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A]
theorem trans [FiniteDimensional F K] [FiniteDimensional K A] : FiniteDimensional F A :=
Module.Finite.trans K A
#align finite_dimensional.trans FiniteDimensional.trans
end Tower
end FiniteDimensional
section ZeroRank
variable [DivisionRing K] [AddCommGroup V] [Module K V]
open FiniteDimensional
theorem FiniteDimensional.of_rank_eq_nat {n : ℕ} (h : Module.rank K V = n) :
FiniteDimensional K V :=
Module.finite_of_rank_eq_nat h
#align finite_dimensional_of_rank_eq_nat FiniteDimensional.of_rank_eq_nat
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_nat := FiniteDimensional.of_rank_eq_nat
theorem FiniteDimensional.of_rank_eq_zero (h : Module.rank K V = 0) : FiniteDimensional K V :=
Module.finite_of_rank_eq_zero h
#align finite_dimensional_of_rank_eq_zero FiniteDimensional.of_rank_eq_zero
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_zero := FiniteDimensional.of_rank_eq_zero
theorem FiniteDimensional.of_rank_eq_one (h : Module.rank K V = 1) : FiniteDimensional K V :=
Module.finite_of_rank_eq_one h
#align finite_dimensional_of_rank_eq_one FiniteDimensional.of_rank_eq_one
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_one := FiniteDimensional.of_rank_eq_one
variable (K V)
instance finiteDimensional_bot : FiniteDimensional K (⊥ : Submodule K V) :=
of_rank_eq_zero <| by simp
#align finite_dimensional_bot finiteDimensional_bot
variable {K V}
end ZeroRank
namespace Submodule
open IsNoetherian FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
/-- A submodule is finitely generated if and only if it is finite-dimensional -/
theorem fg_iff_finiteDimensional (s : Submodule K V) : s.FG ↔ FiniteDimensional K s :=
⟨fun h => Module.finite_def.2 <| (fg_top s).2 h, fun h => (fg_top s).1 <| Module.finite_def.1 h⟩
#align submodule.fg_iff_finite_dimensional Submodule.fg_iff_finiteDimensional
/-- A submodule contained in a finite-dimensional submodule is
finite-dimensional. -/
theorem finiteDimensional_of_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (h : S₁ ≤ S₂) :
FiniteDimensional K S₁ :=
haveI : IsNoetherian K S₂ := iff_fg.2 inferInstance
iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2
(lt_of_le_of_lt (rank_le_of_submodule _ _ h) (rank_lt_aleph0 K S₂)))
#align submodule.finite_dimensional_of_le Submodule.finiteDimensional_of_le
/-- The inf of two submodules, the first finite-dimensional, is
finite-dimensional. -/
instance finiteDimensional_inf_left (S₁ S₂ : Submodule K V) [FiniteDimensional K S₁] :
FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=
finiteDimensional_of_le inf_le_left
#align submodule.finite_dimensional_inf_left Submodule.finiteDimensional_inf_left
/-- The inf of two submodules, the second finite-dimensional, is
finite-dimensional. -/
instance finiteDimensional_inf_right (S₁ S₂ : Submodule K V) [FiniteDimensional K S₂] :
FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=
finiteDimensional_of_le inf_le_right
#align submodule.finite_dimensional_inf_right Submodule.finiteDimensional_inf_right
/-- The sup of two finite-dimensional submodules is
finite-dimensional. -/
instance finiteDimensional_sup (S₁ S₂ : Submodule K V) [h₁ : FiniteDimensional K S₁]
[h₂ : FiniteDimensional K S₂] : FiniteDimensional K (S₁ ⊔ S₂ : Submodule K V) := by
unfold FiniteDimensional at *
rw [finite_def] at *
exact (fg_top _).2 (((fg_top S₁).1 h₁).sup ((fg_top S₂).1 h₂))
#align submodule.finite_dimensional_sup Submodule.finiteDimensional_sup
/-- The submodule generated by a finite supremum of finite dimensional submodules is
finite-dimensional.
Note that strictly this only needs `∀ i ∈ s, FiniteDimensional K (S i)`, but that doesn't
work well with typeclass search. -/
instance finiteDimensional_finset_sup {ι : Type*} (s : Finset ι) (S : ι → Submodule K V)
[∀ i, FiniteDimensional K (S i)] : FiniteDimensional K (s.sup S : Submodule K V) := by
refine
@Finset.sup_induction _ _ _ _ s S (fun i => FiniteDimensional K ↑i) (finiteDimensional_bot K V)
?_ fun i _ => by infer_instance
intro S₁ hS₁ S₂ hS₂
exact Submodule.finiteDimensional_sup S₁ S₂
#align submodule.finite_dimensional_finset_sup Submodule.finiteDimensional_finset_sup
/-- The submodule generated by a supremum of finite dimensional submodules, indexed by a finite
sort is finite-dimensional. -/
instance finiteDimensional_iSup {ι : Sort*} [Finite ι] (S : ι → Submodule K V)
[∀ i, FiniteDimensional K (S i)] : FiniteDimensional K ↑(⨆ i, S i) := by
cases nonempty_fintype (PLift ι)
rw [← iSup_plift_down, ← Finset.sup_univ_eq_iSup]
exact Submodule.finiteDimensional_finset_sup _ _
#align submodule.finite_dimensional_supr Submodule.finiteDimensional_iSup
/-- In a finite-dimensional vector space, the dimensions of a submodule and of the corresponding
quotient add up to the dimension of the space. -/
theorem finrank_quotient_add_finrank [FiniteDimensional K V] (s : Submodule K V) :
finrank K (V ⧸ s) + finrank K s = finrank K V := by
have := rank_quotient_add_rank s
rw [← finrank_eq_rank, ← finrank_eq_rank, ← finrank_eq_rank] at this
exact mod_cast this
#align submodule.finrank_quotient_add_finrank Submodule.finrank_quotient_add_finrank
/-- The dimension of a strict submodule is strictly bounded by the dimension of the ambient
space. -/
theorem finrank_lt [FiniteDimensional K V] {s : Submodule K V} (h : s < ⊤) :
finrank K s < finrank K V := by
rw [← s.finrank_quotient_add_finrank, add_comm]
exact Nat.lt_add_of_pos_right (finrank_pos_iff.mpr (Quotient.nontrivial_of_lt_top _ h))
#align submodule.finrank_lt Submodule.finrank_lt
/-- The sum of the dimensions of s + t and s ∩ t is the sum of the dimensions of s and t -/
theorem finrank_sup_add_finrank_inf_eq (s t : Submodule K V) [FiniteDimensional K s]
[FiniteDimensional K t] :
finrank K ↑(s ⊔ t) + finrank K ↑(s ⊓ t) = finrank K ↑s + finrank K ↑t := by
have key : Module.rank K ↑(s ⊔ t) + Module.rank K ↑(s ⊓ t) = Module.rank K s + Module.rank K t :=
rank_sup_add_rank_inf_eq s t
repeat rw [← finrank_eq_rank] at key
norm_cast at key
#align submodule.finrank_sup_add_finrank_inf_eq Submodule.finrank_sup_add_finrank_inf_eq
theorem finrank_add_le_finrank_add_finrank (s t : Submodule K V) [FiniteDimensional K s]
[FiniteDimensional K t] : finrank K (s ⊔ t : Submodule K V) ≤ finrank K s + finrank K t := by
rw [← finrank_sup_add_finrank_inf_eq]
exact self_le_add_right _ _
#align submodule.finrank_add_le_finrank_add_finrank Submodule.finrank_add_le_finrank_add_finrank
theorem eq_top_of_disjoint [FiniteDimensional K V] (s t : Submodule K V)
(hdim : finrank K s + finrank K t = finrank K V) (hdisjoint : Disjoint s t) : s ⊔ t = ⊤ := by
have h_finrank_inf : finrank K ↑(s ⊓ t) = 0 := by
rw [disjoint_iff_inf_le, le_bot_iff] at hdisjoint
rw [hdisjoint, finrank_bot]
apply eq_top_of_finrank_eq
rw [← hdim]
convert s.finrank_sup_add_finrank_inf_eq t
rw [h_finrank_inf]
rfl
#align submodule.eq_top_of_disjoint Submodule.eq_top_of_disjoint
theorem finrank_add_finrank_le_of_disjoint [FiniteDimensional K V]
{s t : Submodule K V} (hdisjoint : Disjoint s t) :
finrank K s + finrank K t ≤ finrank K V := by
rw [← Submodule.finrank_sup_add_finrank_inf_eq s t, hdisjoint.eq_bot, finrank_bot, add_zero]
exact Submodule.finrank_le _
end DivisionRing
end Submodule
namespace LinearEquiv
open FiniteDimensional
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- Finite dimensionality is preserved under linear equivalence. -/
protected theorem finiteDimensional (f : V ≃ₗ[K] V₂) [FiniteDimensional K V] :
FiniteDimensional K V₂ :=
Module.Finite.equiv f
#align linear_equiv.finite_dimensional LinearEquiv.finiteDimensional
variable {R M M₂ : Type*} [Ring R] [AddCommGroup M] [AddCommGroup M₂]
variable [Module R M] [Module R M₂]
end LinearEquiv
section
variable [DivisionRing K] [AddCommGroup V] [Module K V]
instance finiteDimensional_finsupp {ι : Type*} [Finite ι] [FiniteDimensional K V] :
FiniteDimensional K (ι →₀ V) :=
Module.Finite.finsupp
#align finite_dimensional_finsupp finiteDimensional_finsupp
end
namespace FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- If a submodule is contained in a finite-dimensional
submodule with the same or smaller dimension, they are equal. -/
theorem eq_of_le_of_finrank_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂)
(hd : finrank K S₂ ≤ finrank K S₁) : S₁ = S₂ := by
rw [← LinearEquiv.finrank_eq (Submodule.comapSubtypeEquivOfLe hle)] at hd
exact le_antisymm hle (Submodule.comap_subtype_eq_top.1
(eq_top_of_finrank_eq (le_antisymm (comap (Submodule.subtype S₂) S₁).finrank_le hd)))
#align finite_dimensional.eq_of_le_of_finrank_le FiniteDimensional.eq_of_le_of_finrank_le
/-- If a submodule is contained in a finite-dimensional
submodule with the same dimension, they are equal. -/
theorem eq_of_le_of_finrank_eq {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂)
(hd : finrank K S₁ = finrank K S₂) : S₁ = S₂ :=
eq_of_le_of_finrank_le hle hd.ge
#align finite_dimensional.eq_of_le_of_finrank_eq FiniteDimensional.eq_of_le_of_finrank_eq
section Subalgebra
variable {K L : Type*} [Field K] [Ring L] [Algebra K L] {F E : Subalgebra K L}
[hfin : FiniteDimensional K E] (h_le : F ≤ E)
/-- If a subalgebra is contained in a finite-dimensional
subalgebra with the same or smaller dimension, they are equal. -/
theorem _root_.Subalgebra.eq_of_le_of_finrank_le (h_finrank : finrank K E ≤ finrank K F) : F = E :=
haveI : Module.Finite K (Subalgebra.toSubmodule E) := hfin
Subalgebra.toSubmodule_injective <| FiniteDimensional.eq_of_le_of_finrank_le h_le h_finrank
/-- If a subalgebra is contained in a finite-dimensional
subalgebra with the same dimension, they are equal. -/
theorem _root_.Subalgebra.eq_of_le_of_finrank_eq (h_finrank : finrank K F = finrank K E) : F = E :=
Subalgebra.eq_of_le_of_finrank_le h_le h_finrank.ge
end Subalgebra
variable [FiniteDimensional K V] [FiniteDimensional K V₂]
/-- Given isomorphic subspaces `p q` of vector spaces `V` and `V₁` respectively,
`p.quotient` is isomorphic to `q.quotient`. -/
noncomputable def LinearEquiv.quotEquivOfEquiv {p : Subspace K V} {q : Subspace K V₂}
(f₁ : p ≃ₗ[K] q) (f₂ : V ≃ₗ[K] V₂) : (V ⧸ p) ≃ₗ[K] V₂ ⧸ q :=
LinearEquiv.ofFinrankEq _ _
(by
rw [← @add_right_cancel_iff _ _ _ (finrank K p), Submodule.finrank_quotient_add_finrank,
LinearEquiv.finrank_eq f₁, Submodule.finrank_quotient_add_finrank,
LinearEquiv.finrank_eq f₂])
#align finite_dimensional.linear_equiv.quot_equiv_of_equiv FiniteDimensional.LinearEquiv.quotEquivOfEquiv
-- TODO: generalize to the case where one of `p` and `q` is finite-dimensional.
/-- Given the subspaces `p q`, if `p.quotient ≃ₗ[K] q`, then `q.quotient ≃ₗ[K] p` -/
noncomputable def LinearEquiv.quotEquivOfQuotEquiv {p q : Subspace K V} (f : (V ⧸ p) ≃ₗ[K] q) :
(V ⧸ q) ≃ₗ[K] p :=
LinearEquiv.ofFinrankEq _ _ <|
add_right_cancel <| by
rw [Submodule.finrank_quotient_add_finrank, ← LinearEquiv.finrank_eq f, add_comm,
Submodule.finrank_quotient_add_finrank]
#align finite_dimensional.linear_equiv.quot_equiv_of_quot_equiv FiniteDimensional.LinearEquiv.quotEquivOfQuotEquiv
end DivisionRing
end FiniteDimensional
namespace LinearMap
open FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- On a finite-dimensional space, an injective linear map is surjective. -/
theorem surjective_of_injective [FiniteDimensional K V] {f : V →ₗ[K] V} (hinj : Injective f) :
Surjective f := by
have h := rank_range_of_injective _ hinj
rw [← finrank_eq_rank, ← finrank_eq_rank, natCast_inj] at h
exact range_eq_top.1 (eq_top_of_finrank_eq h)
#align linear_map.surjective_of_injective LinearMap.surjective_of_injective
/-- The image under an onto linear map of a finite-dimensional space is also finite-dimensional. -/
theorem finiteDimensional_of_surjective [FiniteDimensional K V] (f : V →ₗ[K] V₂)
(hf : LinearMap.range f = ⊤) : FiniteDimensional K V₂ :=
Module.Finite.of_surjective f <| range_eq_top.1 hf
#align linear_map.finite_dimensional_of_surjective LinearMap.finiteDimensional_of_surjective
/-- The range of a linear map defined on a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_range [FiniteDimensional K V] (f : V →ₗ[K] V₂) :
FiniteDimensional K (LinearMap.range f) :=
Module.Finite.range f
#align linear_map.finite_dimensional_range LinearMap.finiteDimensional_range
/-- On a finite-dimensional space, a linear map is injective if and only if it is surjective. -/
theorem injective_iff_surjective [FiniteDimensional K V] {f : V →ₗ[K] V} :
Injective f ↔ Surjective f :=
⟨surjective_of_injective, fun hsurj =>
let ⟨g, hg⟩ := f.exists_rightInverse_of_surjective (range_eq_top.2 hsurj)
have : Function.RightInverse g f := LinearMap.ext_iff.1 hg
(leftInverse_of_surjective_of_rightInverse (surjective_of_injective this.injective)
this).injective⟩
#align linear_map.injective_iff_surjective LinearMap.injective_iff_surjective
lemma injOn_iff_surjOn {p : Submodule K V} [FiniteDimensional K p]
{f : V →ₗ[K] V} (h : ∀ x ∈ p, f x ∈ p) :
Set.InjOn f p ↔ Set.SurjOn f p p := by
rw [Set.injOn_iff_injective, ← Set.MapsTo.restrict_surjective_iff h]
change Injective (f.domRestrict p) ↔ Surjective (f.restrict h)
simp [disjoint_iff, ← injective_iff_surjective]
theorem ker_eq_bot_iff_range_eq_top [FiniteDimensional K V] {f : V →ₗ[K] V} :
LinearMap.ker f = ⊥ ↔ LinearMap.range f = ⊤ := by
rw [range_eq_top, ker_eq_bot, injective_iff_surjective]
#align linear_map.ker_eq_bot_iff_range_eq_top LinearMap.ker_eq_bot_iff_range_eq_top
/-- In a finite-dimensional space, if linear maps are inverse to each other on one side then they
are also inverse to each other on the other side. -/
theorem mul_eq_one_of_mul_eq_one [FiniteDimensional K V] {f g : V →ₗ[K] V} (hfg : f * g = 1) :
g * f = 1 := by
have ginj : Injective g :=
HasLeftInverse.injective ⟨f, fun x => show (f * g) x = (1 : V →ₗ[K] V) x by rw [hfg]⟩
let ⟨i, hi⟩ :=
g.exists_rightInverse_of_surjective (range_eq_top.2 (injective_iff_surjective.1 ginj))
have : f * (g * i) = f * 1 := congr_arg _ hi
rw [← mul_assoc, hfg, one_mul, mul_one] at this; rwa [← this]
#align linear_map.mul_eq_one_of_mul_eq_one LinearMap.mul_eq_one_of_mul_eq_one
/-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if
they are inverse to each other on the other side. -/
theorem mul_eq_one_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f * g = 1 ↔ g * f = 1 :=
⟨mul_eq_one_of_mul_eq_one, mul_eq_one_of_mul_eq_one⟩
#align linear_map.mul_eq_one_comm LinearMap.mul_eq_one_comm
/-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if
they are inverse to each other on the other side. -/
theorem comp_eq_id_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f.comp g = id ↔ g.comp f = id :=
mul_eq_one_comm
#align linear_map.comp_eq_id_comm LinearMap.comp_eq_id_comm
/-- rank-nullity theorem : the dimensions of the kernel and the range of a linear map add up to
the dimension of the source space. -/
theorem finrank_range_add_finrank_ker [FiniteDimensional K V] (f : V →ₗ[K] V₂) :
finrank K (LinearMap.range f) + finrank K (LinearMap.ker f) = finrank K V := by
rw [← f.quotKerEquivRange.finrank_eq]
exact Submodule.finrank_quotient_add_finrank _
#align linear_map.finrank_range_add_finrank_ker LinearMap.finrank_range_add_finrank_ker
lemma ker_ne_bot_of_finrank_lt [FiniteDimensional K V] [FiniteDimensional K V₂] {f : V →ₗ[K] V₂}
(h : finrank K V₂ < finrank K V) :
LinearMap.ker f ≠ ⊥ := by
have h₁ := f.finrank_range_add_finrank_ker
have h₂ : finrank K (LinearMap.range f) ≤ finrank K V₂ := (LinearMap.range f).finrank_le
suffices 0 < finrank K (LinearMap.ker f) from Submodule.one_le_finrank_iff.mp this
omega
theorem comap_eq_sup_ker_of_disjoint {p : Submodule K V} [FiniteDimensional K p] {f : V →ₗ[K] V}
(h : ∀ x ∈ p, f x ∈ p) (h' : Disjoint p (ker f)) :
p.comap f = p ⊔ ker f := by
refine le_antisymm (fun x hx ↦ ?_) (sup_le_iff.mpr ⟨h, ker_le_comap _⟩)
obtain ⟨⟨y, hy⟩, hxy⟩ :=
surjective_of_injective ((injective_restrict_iff_disjoint h).mpr h') ⟨f x, hx⟩
replace hxy : f y = f x := by simpa [Subtype.ext_iff] using hxy
exact Submodule.mem_sup.mpr ⟨y, hy, x - y, by simp [hxy], add_sub_cancel y x⟩
theorem ker_comp_eq_of_commute_of_disjoint_ker [FiniteDimensional K V] {f g : V →ₗ[K] V}
(h : Commute f g) (h' : Disjoint (ker f) (ker g)) :
ker (f ∘ₗ g) = ker f ⊔ ker g := by
suffices ∀ x, f x = 0 → f (g x) = 0 by rw [ker_comp, comap_eq_sup_ker_of_disjoint _ h']; simpa
intro x hx
rw [← comp_apply, ← mul_eq_comp, h.eq, mul_apply, hx, _root_.map_zero]
theorem ker_noncommProd_eq_of_supIndep_ker [FiniteDimensional K V] {ι : Type*} {f : ι → V →ₗ[K] V}
(s : Finset ι) (comm) (h : s.SupIndep fun i ↦ ker (f i)) :
ker (s.noncommProd f comm) = ⨆ i ∈ s, ker (f i) := by
classical
induction' s using Finset.induction_on with i s hi ih
· set_option tactic.skipAssignedInstances false in
simpa using LinearMap.ker_id
replace ih : ker (Finset.noncommProd s f <| Set.Pairwise.mono (s.subset_insert i) comm) =
⨆ x ∈ s, ker (f x) := ih _ (h.subset (s.subset_insert i))
rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ hi, mul_eq_comp,
ker_comp_eq_of_commute_of_disjoint_ker]
· simp_rw [Finset.mem_insert_coe, iSup_insert, Finset.mem_coe, ih]
· exact s.noncommProd_commute _ _ _ fun j hj ↦
comm (s.mem_insert_self i) (Finset.mem_insert_of_mem hj) (by aesop)
· replace h := Finset.supIndep_iff_disjoint_erase.mp h i (s.mem_insert_self i)
simpa [ih, hi, Finset.sup_eq_iSup] using h
end DivisionRing
end LinearMap
namespace LinearEquiv
open FiniteDimensional
variable [DivisionRing K] [AddCommGroup V] [Module K V]
variable [FiniteDimensional K V]
/-- The linear equivalence corresponding to an injective endomorphism. -/
noncomputable def ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) : V ≃ₗ[K] V :=
LinearEquiv.ofBijective f ⟨h_inj, LinearMap.injective_iff_surjective.mp h_inj⟩
#align linear_equiv.of_injective_endo LinearEquiv.ofInjectiveEndo
@[simp]
theorem coe_ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) :
⇑(ofInjectiveEndo f h_inj) = f :=
rfl
#align linear_equiv.coe_of_injective_endo LinearEquiv.coe_ofInjectiveEndo
@[simp]
theorem ofInjectiveEndo_right_inv (f : V →ₗ[K] V) (h_inj : Injective f) :
f * (ofInjectiveEndo f h_inj).symm = 1 :=
LinearMap.ext <| (ofInjectiveEndo f h_inj).apply_symm_apply
#align linear_equiv.of_injective_endo_right_inv LinearEquiv.ofInjectiveEndo_right_inv
@[simp]
theorem ofInjectiveEndo_left_inv (f : V →ₗ[K] V) (h_inj : Injective f) :
((ofInjectiveEndo f h_inj).symm : V →ₗ[K] V) * f = 1 :=
LinearMap.ext <| (ofInjectiveEndo f h_inj).symm_apply_apply
#align linear_equiv.of_injective_endo_left_inv LinearEquiv.ofInjectiveEndo_left_inv
end LinearEquiv
namespace LinearMap
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem isUnit_iff_ker_eq_bot [FiniteDimensional K V] (f : V →ₗ[K] V) :
IsUnit f ↔ (LinearMap.ker f) = ⊥ := by
constructor
· rintro ⟨u, rfl⟩
exact LinearMap.ker_eq_bot_of_inverse u.inv_mul
· intro h_inj
rw [ker_eq_bot] at h_inj
exact ⟨⟨f, (LinearEquiv.ofInjectiveEndo f h_inj).symm.toLinearMap,
LinearEquiv.ofInjectiveEndo_right_inv f h_inj, LinearEquiv.ofInjectiveEndo_left_inv f h_inj⟩,
rfl⟩
#align linear_map.is_unit_iff_ker_eq_bot LinearMap.isUnit_iff_ker_eq_bot
theorem isUnit_iff_range_eq_top [FiniteDimensional K V] (f : V →ₗ[K] V) :
IsUnit f ↔ (LinearMap.range f) = ⊤ := by
rw [isUnit_iff_ker_eq_bot, ker_eq_bot_iff_range_eq_top]
#align linear_map.is_unit_iff_range_eq_top LinearMap.isUnit_iff_range_eq_top
end LinearMap
open Module FiniteDimensional
section
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem finrank_zero_iff_forall_zero [FiniteDimensional K V] : finrank K V = 0 ↔ ∀ x : V, x = 0 :=
FiniteDimensional.finrank_zero_iff.trans (subsingleton_iff_forall_eq 0)
#align finrank_zero_iff_forall_zero finrank_zero_iff_forall_zero
/-- If `ι` is an empty type and `V` is zero-dimensional, there is a unique `ι`-indexed basis. -/
noncomputable def basisOfFinrankZero [FiniteDimensional K V] {ι : Type*} [IsEmpty ι]
(hV : finrank K V = 0) : Basis ι K V :=
haveI : Subsingleton V := finrank_zero_iff.1 hV
Basis.empty _
#align basis_of_finrank_zero basisOfFinrankZero
end
namespace LinearMap
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
theorem injective_iff_surjective_of_finrank_eq_finrank [FiniteDimensional K V]
[FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} :
Function.Injective f ↔ Function.Surjective f := by
have := finrank_range_add_finrank_ker f
rw [← ker_eq_bot, ← range_eq_top]; refine ⟨fun h => ?_, fun h => ?_⟩
· rw [h, finrank_bot, add_zero, H] at this
exact eq_top_of_finrank_eq this
· rw [h, finrank_top, H] at this
exact Submodule.finrank_eq_zero.1 (add_right_injective _ this)
#align linear_map.injective_iff_surjective_of_finrank_eq_finrank LinearMap.injective_iff_surjective_of_finrank_eq_finrank
theorem ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank [FiniteDimensional K V]
[FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} :
LinearMap.ker f = ⊥ ↔ LinearMap.range f = ⊤ := by
rw [range_eq_top, ker_eq_bot, injective_iff_surjective_of_finrank_eq_finrank H]
#align linear_map.ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank LinearMap.ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank
/-- Given a linear map `f` between two vector spaces with the same dimension, if
`ker f = ⊥` then `linearEquivOfInjective` is the induced isomorphism
between the two vector spaces. -/
noncomputable def linearEquivOfInjective [FiniteDimensional K V] [FiniteDimensional K V₂]
(f : V →ₗ[K] V₂) (hf : Injective f) (hdim : finrank K V = finrank K V₂) : V ≃ₗ[K] V₂ :=
LinearEquiv.ofBijective f
⟨hf, (LinearMap.injective_iff_surjective_of_finrank_eq_finrank hdim).mp hf⟩
#align linear_map.linear_equiv_of_injective LinearMap.linearEquivOfInjective
@[simp]
theorem linearEquivOfInjective_apply [FiniteDimensional K V] [FiniteDimensional K V₂]
{f : V →ₗ[K] V₂} (hf : Injective f) (hdim : finrank K V = finrank K V₂) (x : V) :
f.linearEquivOfInjective hf hdim x = f x :=
rfl
#align linear_map.linear_equiv_of_injective_apply LinearMap.linearEquivOfInjective_apply
end LinearMap
section
lemma FiniteDimensional.exists_mul_eq_one (F : Type*) {K : Type*} [Field F] [Ring K] [IsDomain K]
[Algebra F K] [FiniteDimensional F K] {x : K} (H : x ≠ 0) : ∃ y, x * y = 1 := by
have : Function.Surjective (LinearMap.mulLeft F x) :=
LinearMap.injective_iff_surjective.1 fun y z => ((mul_right_inj' H).1 : x * y = x * z → y = z)
exact this 1
/-- A domain that is module-finite as an algebra over a field is a division ring. -/
noncomputable def divisionRingOfFiniteDimensional (F K : Type*) [Field F] [Ring K] [IsDomain K]
[Algebra F K] [FiniteDimensional F K] : DivisionRing K where
__ := ‹IsDomain K›
inv x :=
letI := Classical.decEq K
if H : x = 0 then 0 else Classical.choose <| FiniteDimensional.exists_mul_eq_one F H
mul_inv_cancel x hx := show x * dite _ (h := _) _ = _ by
rw [dif_neg hx]
exact (Classical.choose_spec (FiniteDimensional.exists_mul_eq_one F hx) :)
inv_zero := dif_pos rfl
nnqsmul := _
qsmul := _
#align division_ring_of_finite_dimensional divisionRingOfFiniteDimensional
/-- An integral domain that is module-finite as an algebra over a field is a field. -/
noncomputable def fieldOfFiniteDimensional (F K : Type*) [Field F] [h : CommRing K] [IsDomain K]
[Algebra F K] [FiniteDimensional F K] : Field K :=
{ divisionRingOfFiniteDimensional F K with
toCommRing := h }
#align field_of_finite_dimensional fieldOfFiniteDimensional
end
namespace Submodule
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
theorem finrank_mono [FiniteDimensional K V] : Monotone fun s : Submodule K V => finrank K s :=
fun _ _ => finrank_le_finrank_of_le
#align submodule.finrank_mono Submodule.finrank_mono
theorem finrank_lt_finrank_of_lt {s t : Submodule K V} [FiniteDimensional K t] (hst : s < t) :
finrank K s < finrank K t :=
(comapSubtypeEquivOfLe hst.le).finrank_eq.symm.trans_lt <|
finrank_lt (le_top.lt_of_ne <| hst.not_le ∘ comap_subtype_eq_top.1)
#align submodule.finrank_lt_finrank_of_lt Submodule.finrank_lt_finrank_of_lt
theorem finrank_strictMono [FiniteDimensional K V] :
StrictMono fun s : Submodule K V => finrank K s := fun _ _ => finrank_lt_finrank_of_lt
#align submodule.finrank_strict_mono Submodule.finrank_strictMono
theorem finrank_add_eq_of_isCompl [FiniteDimensional K V] {U W : Submodule K V} (h : IsCompl U W) :
finrank K U + finrank K W = finrank K V := by
rw [← finrank_sup_add_finrank_inf_eq, h.codisjoint.eq_top, h.disjoint.eq_bot, finrank_bot,
add_zero]
exact finrank_top _ _
#align submodule.finrank_add_eq_of_is_compl Submodule.finrank_add_eq_of_isCompl
end DivisionRing
end Submodule
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
section Span
open Submodule
theorem finrank_span_singleton {v : V} (hv : v ≠ 0) : finrank K (K ∙ v) = 1 := by
apply le_antisymm
· exact finrank_span_le_card ({v} : Set V)
· rw [Nat.succ_le_iff, finrank_pos_iff]
use ⟨v, mem_span_singleton_self v⟩, 0
simp [hv]
#align finrank_span_singleton finrank_span_singleton
/-- In a one-dimensional space, any vector is a multiple of any nonzero vector -/
lemma exists_smul_eq_of_finrank_eq_one
(h : finrank K V = 1) {x : V} (hx : x ≠ 0) (y : V) :
∃ (c : K), c • x = y := by
have : Submodule.span K {x} = ⊤ := by
have : FiniteDimensional K V := .of_finrank_eq_succ h
apply eq_top_of_finrank_eq
rw [h]
exact finrank_span_singleton hx
have : y ∈ Submodule.span K {x} := by rw [this]; exact mem_top
exact mem_span_singleton.1 this
theorem Set.finrank_mono [FiniteDimensional K V] {s t : Set V} (h : s ⊆ t) :
s.finrank K ≤ t.finrank K :=
Submodule.finrank_mono (span_mono h)
#align set.finrank_mono Set.finrank_mono
end Span
section Basis
theorem LinearIndependent.span_eq_top_of_card_eq_finrank' {ι : Type*}
[Fintype ι] [FiniteDimensional K V] {b : ι → V} (lin_ind : LinearIndependent K b)
(card_eq : Fintype.card ι = finrank K V) : span K (Set.range b) = ⊤ := by
by_contra ne_top
rw [← finrank_span_eq_card lin_ind] at card_eq
exact ne_of_lt (Submodule.finrank_lt <| lt_top_iff_ne_top.2 ne_top) card_eq
theorem LinearIndependent.span_eq_top_of_card_eq_finrank {ι : Type*} [Nonempty ι]
[Fintype ι] {b : ι → V} (lin_ind : LinearIndependent K b)
(card_eq : Fintype.card ι = finrank K V) : span K (Set.range b) = ⊤ :=
have : FiniteDimensional K V := .of_finrank_pos <| card_eq ▸ Fintype.card_pos
lin_ind.span_eq_top_of_card_eq_finrank' card_eq
#align span_eq_top_of_linear_independent_of_card_eq_finrank LinearIndependent.span_eq_top_of_card_eq_finrank
@[deprecated (since := "2024-02-14")]
alias span_eq_top_of_linearIndependent_of_card_eq_finrank :=
LinearIndependent.span_eq_top_of_card_eq_finrank
/-- A linear independent family of `finrank K V` vectors forms a basis. -/
@[simps! repr_apply]
noncomputable def basisOfLinearIndependentOfCardEqFinrank {ι : Type*} [Nonempty ι] [Fintype ι]
{b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) :
Basis ι K V :=
Basis.mk lin_ind <| (lin_ind.span_eq_top_of_card_eq_finrank card_eq).ge
#align basis_of_linear_independent_of_card_eq_finrank basisOfLinearIndependentOfCardEqFinrank
@[simp]
theorem coe_basisOfLinearIndependentOfCardEqFinrank {ι : Type*} [Nonempty ι] [Fintype ι]
{b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) :
⇑(basisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = b :=
Basis.coe_mk _ _
#align coe_basis_of_linear_independent_of_card_eq_finrank coe_basisOfLinearIndependentOfCardEqFinrank
/-- A linear independent finset of `finrank K V` vectors forms a basis. -/
@[simps! repr_apply]
noncomputable def finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty)
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.card = finrank K V) : Basis s K V :=
@basisOfLinearIndependentOfCardEqFinrank _ _ _ _ _ _
⟨(⟨hs.choose, hs.choose_spec⟩ : s)⟩ _ _ lin_ind (_root_.trans (Fintype.card_coe _) card_eq)
#align finset_basis_of_linear_independent_of_card_eq_finrank finsetBasisOfLinearIndependentOfCardEqFinrank
@[simp]
theorem coe_finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty)
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.card = finrank K V) :
⇑(finsetBasisOfLinearIndependentOfCardEqFinrank hs lin_ind card_eq) = ((↑) : s → V) := by
-- Porting note: added to make the next line unify the `_`s
rw [finsetBasisOfLinearIndependentOfCardEqFinrank]
exact Basis.coe_mk _ _
#align coe_finset_basis_of_linear_independent_of_card_eq_finrank coe_finsetBasisOfLinearIndependentOfCardEqFinrank
/-- A linear independent set of `finrank K V` vectors forms a basis. -/
@[simps! repr_apply]
noncomputable def setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s]
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.toFinset.card = finrank K V) :
Basis s K V :=
basisOfLinearIndependentOfCardEqFinrank lin_ind (_root_.trans s.toFinset_card.symm card_eq)
#align set_basis_of_linear_independent_of_card_eq_finrank setBasisOfLinearIndependentOfCardEqFinrank
@[simp]
theorem coe_setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s]
(lin_ind : LinearIndependent K ((↑) : s → V)) (card_eq : s.toFinset.card = finrank K V) :
⇑(setBasisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = ((↑) : s → V) := by
-- Porting note: added to make the next line unify the `_`s
rw [setBasisOfLinearIndependentOfCardEqFinrank]
exact Basis.coe_mk _ _
#align coe_set_basis_of_linear_independent_of_card_eq_finrank coe_setBasisOfLinearIndependentOfCardEqFinrank
end Basis
/-!
We now give characterisations of `finrank K V = 1` and `finrank K V ≤ 1`.
-/
section finrank_eq_one
/-- A vector space with a nonzero vector `v` has dimension 1 iff `v` spans.
-/
theorem finrank_eq_one_iff_of_nonzero (v : V) (nz : v ≠ 0) :
finrank K V = 1 ↔ span K ({v} : Set V) = ⊤ :=
⟨fun h => by simpa using (basisSingleton Unit h v nz).span_eq, fun s =>
finrank_eq_card_basis
(Basis.mk (linearIndependent_singleton nz)
(by
convert s.ge -- Porting note: added `.ge` to make things easier for `convert`
simp))⟩
#align finrank_eq_one_iff_of_nonzero finrank_eq_one_iff_of_nonzero
/-- A module with a nonzero vector `v` has dimension 1 iff every vector is a multiple of `v`.
-/
theorem finrank_eq_one_iff_of_nonzero' (v : V) (nz : v ≠ 0) :
finrank K V = 1 ↔ ∀ w : V, ∃ c : K, c • v = w := by
rw [finrank_eq_one_iff_of_nonzero v nz]
apply span_singleton_eq_top_iff
#align finrank_eq_one_iff_of_nonzero' finrank_eq_one_iff_of_nonzero'
-- We use the `LinearMap.CompatibleSMul` typeclass here, to encompass two situations:
-- * `A = K`
-- * `[Field K] [Algebra K A] [IsScalarTower K A V] [IsScalarTower K A W]`
theorem surjective_of_nonzero_of_finrank_eq_one {W A : Type*} [Semiring A] [Module A V]
[AddCommGroup W] [Module K W] [Module A W] [LinearMap.CompatibleSMul V W K A]
(h : finrank K W = 1) {f : V →ₗ[A] W} (w : f ≠ 0) : Surjective f := by
change Surjective (f.restrictScalars K)
obtain ⟨v, n⟩ := DFunLike.ne_iff.mp w
intro z
obtain ⟨c, rfl⟩ := (finrank_eq_one_iff_of_nonzero' (f v) n).mp h z
exact ⟨c • v, by simp⟩
#align surjective_of_nonzero_of_finrank_eq_one surjective_of_nonzero_of_finrank_eq_one
/-- Any `K`-algebra module that is 1-dimensional over `K` is simple. -/
theorem is_simple_module_of_finrank_eq_one {A} [Semiring A] [Module A V] [SMul K A]
[IsScalarTower K A V] (h : finrank K V = 1) : IsSimpleOrder (Submodule A V) := by
haveI := nontrivial_of_finrank_eq_succ h
refine ⟨fun S => or_iff_not_imp_left.2 fun hn => ?_⟩
rw [← restrictScalars_inj K] at hn ⊢
haveI : FiniteDimensional _ _ := .of_finrank_eq_succ h
refine eq_top_of_finrank_eq ((Submodule.finrank_le _).antisymm ?_)
simpa only [h, finrank_bot] using Submodule.finrank_strictMono (Ne.bot_lt hn)
#align is_simple_module_of_finrank_eq_one is_simple_module_of_finrank_eq_one
end finrank_eq_one
end DivisionRing
section SubalgebraRank
open Module
variable {F E : Type*} [Field F] [Ring E] [Algebra F E]
/-
porting note:
Some of the lemmas in this section can be made faster by adding these short-cut instances
```lean4
instance (S : Subalgebra F E) : AddCommMonoid { x // x ∈ S } := inferInstance
instance (S : Subalgebra F E) : AddCommGroup { x // x ∈ S } := inferInstance
```
However, this approach doesn't scale very well, so we should consider holding off on adding
them until we have no choice.
-/
/-- A `Subalgebra` is `FiniteDimensional` iff it is `FiniteDimensional` as a submodule. -/
theorem Subalgebra.finiteDimensional_toSubmodule {S : Subalgebra F E} :
FiniteDimensional F (Subalgebra.toSubmodule S) ↔ FiniteDimensional F S :=
Iff.rfl
#align subalgebra.finite_dimensional_to_submodule Subalgebra.finiteDimensional_toSubmodule
alias ⟨FiniteDimensional.of_subalgebra_toSubmodule, FiniteDimensional.subalgebra_toSubmodule⟩ :=
Subalgebra.finiteDimensional_toSubmodule
#align finite_dimensional.of_subalgebra_to_submodule FiniteDimensional.of_subalgebra_toSubmodule
#align finite_dimensional.subalgebra_to_submodule FiniteDimensional.subalgebra_toSubmodule
instance FiniteDimensional.finiteDimensional_subalgebra [FiniteDimensional F E]
(S : Subalgebra F E) : FiniteDimensional F S :=
FiniteDimensional.of_subalgebra_toSubmodule inferInstance
#align finite_dimensional.finite_dimensional_subalgebra FiniteDimensional.finiteDimensional_subalgebra
@[deprecated Subalgebra.finite_bot (since := "2024-04-11")]
theorem Subalgebra.finiteDimensional_bot : FiniteDimensional F (⊥ : Subalgebra F E) :=
Subalgebra.finite_bot
#align subalgebra.finite_dimensional_bot Subalgebra.finiteDimensional_bot
theorem Subalgebra.isSimpleOrder_of_finrank (hr : finrank F E = 2) :
IsSimpleOrder (Subalgebra F E) :=
let i := nontrivial_of_finrank_pos (zero_lt_two.trans_eq hr.symm)
{ toNontrivial :=
⟨⟨⊥, ⊤, fun h => by cases hr.symm.trans (Subalgebra.bot_eq_top_iff_finrank_eq_one.1 h)⟩⟩
eq_bot_or_eq_top := by
intro S
haveI : FiniteDimensional F E := .of_finrank_eq_succ hr
haveI : FiniteDimensional F S :=
FiniteDimensional.finiteDimensional_submodule (Subalgebra.toSubmodule S)
have : finrank F S ≤ 2 := hr ▸ S.toSubmodule.finrank_le
have : 0 < finrank F S := finrank_pos_iff.mpr inferInstance
interval_cases h : finrank F { x // x ∈ S }
· left
exact Subalgebra.eq_bot_of_finrank_one h
· right
rw [← hr] at h
rw [← Algebra.toSubmodule_eq_top]
exact eq_top_of_finrank_eq h }
#align subalgebra.is_simple_order_of_finrank Subalgebra.isSimpleOrder_of_finrank
end SubalgebraRank
namespace Module
namespace End
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem exists_ker_pow_eq_ker_pow_succ [FiniteDimensional K V] (f : End K V) :
∃ k : ℕ, k ≤ finrank K V ∧ LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ) := by
classical
by_contra h_contra
simp_rw [not_exists, not_and] at h_contra
have h_le_ker_pow : ∀ n : ℕ, n ≤ (finrank K V).succ →
n ≤ finrank K (LinearMap.ker (f ^ n)) := by
intro n hn
induction' n with n ih
· exact zero_le (finrank _ _)
· have h_ker_lt_ker : LinearMap.ker (f ^ n) < LinearMap.ker (f ^ n.succ) := by
refine lt_of_le_of_ne ?_ (h_contra n (Nat.le_of_succ_le_succ hn))
rw [pow_succ']
apply LinearMap.ker_le_ker_comp
have h_finrank_lt_finrank :
finrank K (LinearMap.ker (f ^ n)) < finrank K (LinearMap.ker (f ^ n.succ)) := by
apply Submodule.finrank_lt_finrank_of_lt h_ker_lt_ker
calc
n.succ ≤ (finrank K ↑(LinearMap.ker (f ^ n))).succ :=
Nat.succ_le_succ (ih (Nat.le_of_succ_le hn))
_ ≤ finrank K ↑(LinearMap.ker (f ^ n.succ)) := Nat.succ_le_of_lt h_finrank_lt_finrank
have h_any_n_lt : ∀ n, n ≤ (finrank K V).succ → n ≤ finrank K V := fun n hn =>
(h_le_ker_pow n hn).trans (Submodule.finrank_le _)
show False
exact Nat.not_succ_le_self _ (h_any_n_lt (finrank K V).succ (finrank K V).succ.le_refl)
#align module.End.exists_ker_pow_eq_ker_pow_succ Module.End.exists_ker_pow_eq_ker_pow_succ
theorem ker_pow_constant {f : End K V} {k : ℕ}
(h : LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ)) :
∀ m, LinearMap.ker (f ^ k) = LinearMap.ker (f ^ (k + m))
| 0 => by simp
| m + 1 => by
apply le_antisymm
· rw [add_comm, pow_add]
apply LinearMap.ker_le_ker_comp
· rw [ker_pow_constant h m, add_comm m 1, ← add_assoc, pow_add, pow_add f k m,
LinearMap.mul_eq_comp, LinearMap.mul_eq_comp, LinearMap.ker_comp, LinearMap.ker_comp, h,
Nat.add_one]
#align module.End.ker_pow_constant Module.End.ker_pow_constant
theorem ker_pow_eq_ker_pow_finrank_of_le [FiniteDimensional K V] {f : End K V} {m : ℕ}
(hm : finrank K V ≤ m) : LinearMap.ker (f ^ m) = LinearMap.ker (f ^ finrank K V) := by
obtain ⟨k, h_k_le, hk⟩ :
∃ k, k ≤ finrank K V ∧ LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ) :=
exists_ker_pow_eq_ker_pow_succ f
calc
LinearMap.ker (f ^ m) = LinearMap.ker (f ^ (k + (m - k))) := by
rw [add_tsub_cancel_of_le (h_k_le.trans hm)]
_ = LinearMap.ker (f ^ k) := by rw [ker_pow_constant hk _]
_ = LinearMap.ker (f ^ (k + (finrank K V - k))) := ker_pow_constant hk (finrank K V - k)
_ = LinearMap.ker (f ^ finrank K V) := by rw [add_tsub_cancel_of_le h_k_le]
#align module.End.ker_pow_eq_ker_pow_finrank_of_le Module.End.ker_pow_eq_ker_pow_finrank_of_le
| Mathlib/LinearAlgebra/FiniteDimensional.lean | 1,203 | 1,208 | theorem ker_pow_le_ker_pow_finrank [FiniteDimensional K V] (f : End K V) (m : ℕ) :
LinearMap.ker (f ^ m) ≤ LinearMap.ker (f ^ finrank K V) := by |
by_cases h_cases : m < finrank K V
· rw [← add_tsub_cancel_of_le (Nat.le_of_lt h_cases), add_comm, pow_add]
apply LinearMap.ker_le_ker_comp
· rw [ker_pow_eq_ker_pow_finrank_of_le (le_of_not_lt h_cases)]
|
/-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Deprecated.Subring
#align_import deprecated.subfield from "leanprover-community/mathlib"@"bd9851ca476957ea4549eb19b40e7b5ade9428cc"
/-!
# Unbundled subfields (deprecated)
This file is deprecated, and is no longer imported by anything in mathlib other than other
deprecated files, and test files. You should not need to import it.
This file defines predicates for unbundled subfields. Instead of using this file, please use
`Subfield`, defined in `FieldTheory.Subfield`, for subfields of fields.
## Main definitions
`IsSubfield (S : Set F) : Prop` : the predicate that `S` is the underlying set of a subfield
of the field `F`. The bundled variant `Subfield F` should be used in preference to this.
## Tags
IsSubfield, subfield
-/
variable {F : Type*} [Field F] (S : Set F)
/-- `IsSubfield (S : Set F)` is the predicate saying that a given subset of a field is
the set underlying a subfield. This structure is deprecated; use the bundled variant
`Subfield F` to model subfields of a field. -/
structure IsSubfield extends IsSubring S : Prop where
inv_mem : ∀ {x : F}, x ∈ S → x⁻¹ ∈ S
#align is_subfield IsSubfield
theorem IsSubfield.div_mem {S : Set F} (hS : IsSubfield S) {x y : F} (hx : x ∈ S) (hy : y ∈ S) :
x / y ∈ S := by
rw [div_eq_mul_inv]
exact hS.toIsSubring.toIsSubmonoid.mul_mem hx (hS.inv_mem hy)
#align is_subfield.div_mem IsSubfield.div_mem
theorem IsSubfield.pow_mem {a : F} {n : ℤ} {s : Set F} (hs : IsSubfield s) (h : a ∈ s) :
a ^ n ∈ s := by
cases' n with n n
· suffices a ^ (n : ℤ) ∈ s by exact this
rw [zpow_natCast]
exact hs.toIsSubring.toIsSubmonoid.pow_mem h
· rw [zpow_negSucc]
exact hs.inv_mem (hs.toIsSubring.toIsSubmonoid.pow_mem h)
#align is_subfield.pow_mem IsSubfield.pow_mem
theorem Univ.isSubfield : IsSubfield (@Set.univ F) :=
{ Univ.isSubmonoid, IsAddSubgroup.univ_addSubgroup with
inv_mem := fun _ ↦ trivial }
#align univ.is_subfield Univ.isSubfield
theorem Preimage.isSubfield {K : Type*} [Field K] (f : F →+* K) {s : Set K} (hs : IsSubfield s) :
IsSubfield (f ⁻¹' s) :=
{ f.isSubring_preimage hs.toIsSubring with
inv_mem := fun {a} (ha : f a ∈ s) ↦ show f a⁻¹ ∈ s by
rw [map_inv₀]
exact hs.inv_mem ha }
#align preimage.is_subfield Preimage.isSubfield
theorem Image.isSubfield {K : Type*} [Field K] (f : F →+* K) {s : Set F} (hs : IsSubfield s) :
IsSubfield (f '' s) :=
{ f.isSubring_image hs.toIsSubring with
inv_mem := fun ⟨x, xmem, ha⟩ ↦ ⟨x⁻¹, hs.inv_mem xmem, ha ▸ map_inv₀ f x⟩ }
#align image.is_subfield Image.isSubfield
| Mathlib/Deprecated/Subfield.lean | 75 | 77 | theorem Range.isSubfield {K : Type*} [Field K] (f : F →+* K) : IsSubfield (Set.range f) := by |
rw [← Set.image_univ]
apply Image.isSubfield _ Univ.isSubfield
|
/-
Copyright (c) 2020 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Polynomial.Degree.Definitions
import Mathlib.Data.ENat.Basic
#align_import data.polynomial.degree.trailing_degree from "leanprover-community/mathlib"@"302eab4f46abb63de520828de78c04cb0f9b5836"
/-!
# Trailing degree of univariate polynomials
## Main definitions
* `trailingDegree p`: the multiplicity of `X` in the polynomial `p`
* `natTrailingDegree`: a variant of `trailingDegree` that takes values in the natural numbers
* `trailingCoeff`: the coefficient at index `natTrailingDegree p`
Converts most results about `degree`, `natDegree` and `leadingCoeff` to results about the bottom
end of a polynomial
-/
noncomputable section
open Function Polynomial Finsupp Finset
open scoped Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `trailingDegree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest
`X`-exponent in `p`.
`trailingDegree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears
in `p`, otherwise
`trailingDegree 0 = ⊤`. -/
def trailingDegree (p : R[X]) : ℕ∞ :=
p.support.min
#align polynomial.trailing_degree Polynomial.trailingDegree
theorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q :=
InvImage.wf trailingDegree wellFounded_lt
#align polynomial.trailing_degree_lt_wf Polynomial.trailingDegree_lt_wf
/-- `natTrailingDegree p` forces `trailingDegree p` to `ℕ`, by defining
`natTrailingDegree ⊤ = 0`. -/
def natTrailingDegree (p : R[X]) : ℕ :=
(trailingDegree p).getD 0
#align polynomial.nat_trailing_degree Polynomial.natTrailingDegree
/-- `trailingCoeff p` gives the coefficient of the smallest power of `X` in `p`-/
def trailingCoeff (p : R[X]) : R :=
coeff p (natTrailingDegree p)
#align polynomial.trailing_coeff Polynomial.trailingCoeff
/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/
def TrailingMonic (p : R[X]) :=
trailingCoeff p = (1 : R)
#align polynomial.trailing_monic Polynomial.TrailingMonic
theorem TrailingMonic.def : TrailingMonic p ↔ trailingCoeff p = 1 :=
Iff.rfl
#align polynomial.trailing_monic.def Polynomial.TrailingMonic.def
instance TrailingMonic.decidable [DecidableEq R] : Decidable (TrailingMonic p) :=
inferInstanceAs <| Decidable (trailingCoeff p = (1 : R))
#align polynomial.trailing_monic.decidable Polynomial.TrailingMonic.decidable
@[simp]
theorem TrailingMonic.trailingCoeff {p : R[X]} (hp : p.TrailingMonic) : trailingCoeff p = 1 :=
hp
#align polynomial.trailing_monic.trailing_coeff Polynomial.TrailingMonic.trailingCoeff
@[simp]
theorem trailingDegree_zero : trailingDegree (0 : R[X]) = ⊤ :=
rfl
#align polynomial.trailing_degree_zero Polynomial.trailingDegree_zero
@[simp]
theorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 :=
rfl
#align polynomial.trailing_coeff_zero Polynomial.trailingCoeff_zero
@[simp]
theorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 :=
rfl
#align polynomial.nat_trailing_degree_zero Polynomial.natTrailingDegree_zero
theorem trailingDegree_eq_top : trailingDegree p = ⊤ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]⟩
#align polynomial.trailing_degree_eq_top Polynomial.trailingDegree_eq_top
theorem trailingDegree_eq_natTrailingDegree (hp : p ≠ 0) :
trailingDegree p = (natTrailingDegree p : ℕ∞) := by
let ⟨n, hn⟩ :=
not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt trailingDegree_eq_top.1 hp))
have hn : trailingDegree p = n := Classical.not_not.1 hn
rw [natTrailingDegree, hn]
rfl
#align polynomial.trailing_degree_eq_nat_trailing_degree Polynomial.trailingDegree_eq_natTrailingDegree
theorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
rw [trailingDegree_eq_natTrailingDegree hp]
exact WithTop.coe_eq_coe
#align polynomial.trailing_degree_eq_iff_nat_trailing_degree_eq Polynomial.trailingDegree_eq_iff_natTrailingDegree_eq
theorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
constructor
· intro H
rwa [← trailingDegree_eq_iff_natTrailingDegree_eq]
rintro rfl
rw [trailingDegree_zero] at H
exact Option.noConfusion H
· intro H
rwa [trailingDegree_eq_iff_natTrailingDegree_eq]
rintro rfl
rw [natTrailingDegree_zero] at H
rw [H] at hn
exact lt_irrefl _ hn
#align polynomial.trailing_degree_eq_iff_nat_trailing_degree_eq_of_pos Polynomial.trailingDegree_eq_iff_natTrailingDegree_eq_of_pos
theorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : ℕ}
(h : trailingDegree p = n) : natTrailingDegree p = n :=
have hp0 : p ≠ 0 := fun hp0 => by rw [hp0] at h; exact Option.noConfusion h
Option.some_inj.1 <|
show (natTrailingDegree p : ℕ∞) = n by rwa [← trailingDegree_eq_natTrailingDegree hp0]
#align polynomial.nat_trailing_degree_eq_of_trailing_degree_eq_some Polynomial.natTrailingDegree_eq_of_trailingDegree_eq_some
@[simp]
| Mathlib/Algebra/Polynomial/Degree/TrailingDegree.lean | 141 | 145 | theorem natTrailingDegree_le_trailingDegree : ↑(natTrailingDegree p) ≤ trailingDegree p := by |
by_cases hp : p = 0;
· rw [hp, trailingDegree_zero]
exact le_top
rw [trailingDegree_eq_natTrailingDegree hp]
|
/-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Batteries.Data.Rat.Basic
import Batteries.Tactic.SeqFocus
/-! # Additional lemmas about the Rational Numbers -/
namespace Rat
theorem ext : {p q : Rat} → p.num = q.num → p.den = q.den → p = q
| ⟨_,_,_,_⟩, ⟨_,_,_,_⟩, rfl, rfl => rfl
@[simp] theorem mk_den_one {r : Int} :
⟨r, 1, Nat.one_ne_zero, (Nat.coprime_one_right _)⟩ = (r : Rat) := rfl
@[simp] theorem zero_num : (0 : Rat).num = 0 := rfl
@[simp] theorem zero_den : (0 : Rat).den = 1 := rfl
@[simp] theorem one_num : (1 : Rat).num = 1 := rfl
@[simp] theorem one_den : (1 : Rat).den = 1 := rfl
@[simp] theorem maybeNormalize_eq {num den g} (den_nz reduced) :
maybeNormalize num den g den_nz reduced =
{ num := num.div g, den := den / g, den_nz, reduced } := by
unfold maybeNormalize; split
· subst g; simp
· rfl
theorem normalize.reduced' {num : Int} {den g : Nat} (den_nz : den ≠ 0)
(e : g = num.natAbs.gcd den) : (num / g).natAbs.Coprime (den / g) := by
rw [← Int.div_eq_ediv_of_dvd (e ▸ Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))]
exact normalize.reduced den_nz e
theorem normalize_eq {num den} (den_nz) : normalize num den den_nz =
{ num := num / num.natAbs.gcd den
den := den / num.natAbs.gcd den
den_nz := normalize.den_nz den_nz rfl
reduced := normalize.reduced' den_nz rfl } := by
simp only [normalize, maybeNormalize_eq,
Int.div_eq_ediv_of_dvd (Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))]
@[simp] theorem normalize_zero (nz) : normalize 0 d nz = 0 := by
simp [normalize, Int.zero_div, Int.natAbs_zero, Nat.div_self (Nat.pos_of_ne_zero nz)]; rfl
theorem mk_eq_normalize (num den nz c) : ⟨num, den, nz, c⟩ = normalize num den nz := by
simp [normalize_eq, c.gcd_eq_one]
theorem normalize_self (r : Rat) : normalize r.num r.den r.den_nz = r := (mk_eq_normalize ..).symm
theorem normalize_mul_left {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) :
normalize (↑a * n) (a * d) (Nat.mul_ne_zero a0 d0) = normalize n d d0 := by
simp [normalize_eq, mk'.injEq, Int.natAbs_mul, Nat.gcd_mul_left,
Nat.mul_div_mul_left _ _ (Nat.pos_of_ne_zero a0), Int.ofNat_mul,
Int.mul_ediv_mul_of_pos _ _ (Int.ofNat_pos.2 <| Nat.pos_of_ne_zero a0)]
theorem normalize_mul_right {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) :
normalize (n * a) (d * a) (Nat.mul_ne_zero d0 a0) = normalize n d d0 := by
rw [← normalize_mul_left (d0 := d0) a0]; congr 1 <;> [apply Int.mul_comm; apply Nat.mul_comm]
theorem normalize_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
normalize n₁ d₁ z₁ = normalize n₂ d₂ z₂ ↔ n₁ * d₂ = n₂ * d₁ := by
constructor <;> intro h
· simp only [normalize_eq, mk'.injEq] at h
have' hn₁ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₁.natAbs d₁
have' hn₂ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₂.natAbs d₂
have' hd₁ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₁.natAbs d₁
have' hd₂ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₂.natAbs d₂
rw [← Int.ediv_mul_cancel (Int.dvd_trans hd₂ (Int.dvd_mul_left ..)),
Int.mul_ediv_assoc _ hd₂, ← Int.ofNat_ediv, ← h.2, Int.ofNat_ediv,
← Int.mul_ediv_assoc _ hd₁, Int.mul_ediv_assoc' _ hn₁,
Int.mul_right_comm, h.1, Int.ediv_mul_cancel hn₂]
· rw [← normalize_mul_right _ z₂, ← normalize_mul_left z₂ z₁, Int.mul_comm d₁, h]
theorem maybeNormalize_eq_normalize {num : Int} {den g : Nat} (den_nz reduced)
(hn : ↑g ∣ num) (hd : g ∣ den) :
maybeNormalize num den g den_nz reduced = normalize num den (mt (by simp [·]) den_nz) := by
simp only [maybeNormalize_eq, mk_eq_normalize, Int.div_eq_ediv_of_dvd hn]
have : g ≠ 0 := mt (by simp [·]) den_nz
rw [← normalize_mul_right _ this, Int.ediv_mul_cancel hn]
congr 1; exact Nat.div_mul_cancel hd
@[simp] theorem normalize_eq_zero (d0 : d ≠ 0) : normalize n d d0 = 0 ↔ n = 0 := by
have' := normalize_eq_iff d0 Nat.one_ne_zero
rw [normalize_zero (d := 1)] at this; rw [this]; simp
theorem normalize_num_den' (num den nz) : ∃ d : Nat, d ≠ 0 ∧
num = (normalize num den nz).num * d ∧ den = (normalize num den nz).den * d := by
refine ⟨num.natAbs.gcd den, Nat.gcd_ne_zero_right nz, ?_⟩
simp [normalize_eq, Int.ediv_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..),
Nat.div_mul_cancel (Nat.gcd_dvd_right ..)]
theorem normalize_num_den (h : normalize n d z = ⟨n', d', z', c⟩) :
∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := by
have := normalize_num_den' n d z; rwa [h] at this
theorem normalize_eq_mkRat {num den} (den_nz) : normalize num den den_nz = mkRat num den := by
simp [mkRat, den_nz]
theorem mkRat_num_den (z : d ≠ 0) (h : mkRat n d = ⟨n', d', z', c⟩) :
∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m :=
normalize_num_den ((normalize_eq_mkRat z).symm ▸ h)
theorem mkRat_def (n d) : mkRat n d = if d0 : d = 0 then 0 else normalize n d d0 := rfl
| .lake/packages/batteries/Batteries/Data/Rat/Lemmas.lean | 107 | 108 | theorem mkRat_self (a : Rat) : mkRat a.num a.den = a := by |
rw [← normalize_eq_mkRat a.den_nz, normalize_self]
|
/-
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.Algebra.BigOperators.Option
import Mathlib.Analysis.BoxIntegral.Box.Basic
import Mathlib.Data.Set.Pairwise.Lattice
#align_import analysis.box_integral.partition.basic from "leanprover-community/mathlib"@"84dc0bd6619acaea625086d6f53cb35cdd554219"
/-!
# Partitions of rectangular boxes in `ℝⁿ`
In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in
`ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set
of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ι)` to
store the set of boxes.
Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a
structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ι)` that stores a collection of boxes
such that
* each box `J ∈ boxes` is a subbox of `I`;
* the boxes are pairwise disjoint as sets in `ℝⁿ`.
Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `π.IsPartition` means that the
boxes of `π` actually cover the whole `I`. We also define some operations on prepartitions:
* `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes;
* `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box.
We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all
`I : BoxIntegral.Box ι`.
## Tags
rectangular box, partition
-/
open Set Finset Function
open scoped Classical
open NNReal
noncomputable section
namespace BoxIntegral
variable {ι : Type*}
/-- A prepartition of `I : BoxIntegral.Box ι` is a finite set of pairwise disjoint subboxes of
`I`. -/
structure Prepartition (I : Box ι) where
/-- The underlying set of boxes -/
boxes : Finset (Box ι)
/-- Each box is a sub-box of `I` -/
le_of_mem' : ∀ J ∈ boxes, J ≤ I
/-- The boxes in a prepartition are pairwise disjoint. -/
pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ι → Set (ι → ℝ)))
#align box_integral.prepartition BoxIntegral.Prepartition
namespace Prepartition
variable {I J J₁ J₂ : Box ι} (π : Prepartition I) {π₁ π₂ : Prepartition I} {x : ι → ℝ}
instance : Membership (Box ι) (Prepartition I) :=
⟨fun J π => J ∈ π.boxes⟩
@[simp]
theorem mem_boxes : J ∈ π.boxes ↔ J ∈ π := Iff.rfl
#align box_integral.prepartition.mem_boxes BoxIntegral.Prepartition.mem_boxes
@[simp]
theorem mem_mk {s h₁ h₂} : J ∈ (mk s h₁ h₂ : Prepartition I) ↔ J ∈ s := Iff.rfl
#align box_integral.prepartition.mem_mk BoxIntegral.Prepartition.mem_mk
theorem disjoint_coe_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (h : J₁ ≠ J₂) :
Disjoint (J₁ : Set (ι → ℝ)) J₂ :=
π.pairwiseDisjoint h₁ h₂ h
#align box_integral.prepartition.disjoint_coe_of_mem BoxIntegral.Prepartition.disjoint_coe_of_mem
theorem eq_of_mem_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hx₁ : x ∈ J₁) (hx₂ : x ∈ J₂) : J₁ = J₂ :=
by_contra fun H => (π.disjoint_coe_of_mem h₁ h₂ H).le_bot ⟨hx₁, hx₂⟩
#align box_integral.prepartition.eq_of_mem_of_mem BoxIntegral.Prepartition.eq_of_mem_of_mem
theorem eq_of_le_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle₁ : J ≤ J₁) (hle₂ : J ≤ J₂) : J₁ = J₂ :=
π.eq_of_mem_of_mem h₁ h₂ (hle₁ J.upper_mem) (hle₂ J.upper_mem)
#align box_integral.prepartition.eq_of_le_of_le BoxIntegral.Prepartition.eq_of_le_of_le
theorem eq_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle : J₁ ≤ J₂) : J₁ = J₂ :=
π.eq_of_le_of_le h₁ h₂ le_rfl hle
#align box_integral.prepartition.eq_of_le BoxIntegral.Prepartition.eq_of_le
theorem le_of_mem (hJ : J ∈ π) : J ≤ I :=
π.le_of_mem' J hJ
#align box_integral.prepartition.le_of_mem BoxIntegral.Prepartition.le_of_mem
theorem lower_le_lower (hJ : J ∈ π) : I.lower ≤ J.lower :=
Box.antitone_lower (π.le_of_mem hJ)
#align box_integral.prepartition.lower_le_lower BoxIntegral.Prepartition.lower_le_lower
theorem upper_le_upper (hJ : J ∈ π) : J.upper ≤ I.upper :=
Box.monotone_upper (π.le_of_mem hJ)
#align box_integral.prepartition.upper_le_upper BoxIntegral.Prepartition.upper_le_upper
theorem injective_boxes : Function.Injective (boxes : Prepartition I → Finset (Box ι)) := by
rintro ⟨s₁, h₁, h₁'⟩ ⟨s₂, h₂, h₂'⟩ (rfl : s₁ = s₂)
rfl
#align box_integral.prepartition.injective_boxes BoxIntegral.Prepartition.injective_boxes
@[ext]
theorem ext (h : ∀ J, J ∈ π₁ ↔ J ∈ π₂) : π₁ = π₂ :=
injective_boxes <| Finset.ext h
#align box_integral.prepartition.ext BoxIntegral.Prepartition.ext
/-- The singleton prepartition `{J}`, `J ≤ I`. -/
@[simps]
def single (I J : Box ι) (h : J ≤ I) : Prepartition I :=
⟨{J}, by simpa, by simp⟩
#align box_integral.prepartition.single BoxIntegral.Prepartition.single
@[simp]
theorem mem_single {J'} (h : J ≤ I) : J' ∈ single I J h ↔ J' = J :=
mem_singleton
#align box_integral.prepartition.mem_single BoxIntegral.Prepartition.mem_single
/-- We say that `π ≤ π'` if each box of `π` is a subbox of some box of `π'`. -/
instance : LE (Prepartition I) :=
⟨fun π π' => ∀ ⦃I⦄, I ∈ π → ∃ I' ∈ π', I ≤ I'⟩
instance partialOrder : PartialOrder (Prepartition I) where
le := (· ≤ ·)
le_refl π I hI := ⟨I, hI, le_rfl⟩
le_trans π₁ π₂ π₃ h₁₂ h₂₃ I₁ hI₁ :=
let ⟨I₂, hI₂, hI₁₂⟩ := h₁₂ hI₁
let ⟨I₃, hI₃, hI₂₃⟩ := h₂₃ hI₂
⟨I₃, hI₃, hI₁₂.trans hI₂₃⟩
le_antisymm := by
suffices ∀ {π₁ π₂ : Prepartition I}, π₁ ≤ π₂ → π₂ ≤ π₁ → π₁.boxes ⊆ π₂.boxes from
fun π₁ π₂ h₁ h₂ => injective_boxes (Subset.antisymm (this h₁ h₂) (this h₂ h₁))
intro π₁ π₂ h₁ h₂ J hJ
rcases h₁ hJ with ⟨J', hJ', hle⟩; rcases h₂ hJ' with ⟨J'', hJ'', hle'⟩
obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle')
obtain rfl : J' = J := le_antisymm ‹_› ‹_›
assumption
instance : OrderTop (Prepartition I) where
top := single I I le_rfl
le_top π J hJ := ⟨I, by simp, π.le_of_mem hJ⟩
instance : OrderBot (Prepartition I) where
bot := ⟨∅,
fun _ hJ => (Finset.not_mem_empty _ hJ).elim,
fun _ hJ => (Set.not_mem_empty _ <| Finset.coe_empty ▸ hJ).elim⟩
bot_le _ _ hJ := (Finset.not_mem_empty _ hJ).elim
instance : Inhabited (Prepartition I) := ⟨⊤⟩
theorem le_def : π₁ ≤ π₂ ↔ ∀ J ∈ π₁, ∃ J' ∈ π₂, J ≤ J' := Iff.rfl
#align box_integral.prepartition.le_def BoxIntegral.Prepartition.le_def
@[simp]
theorem mem_top : J ∈ (⊤ : Prepartition I) ↔ J = I :=
mem_singleton
#align box_integral.prepartition.mem_top BoxIntegral.Prepartition.mem_top
@[simp]
theorem top_boxes : (⊤ : Prepartition I).boxes = {I} := rfl
#align box_integral.prepartition.top_boxes BoxIntegral.Prepartition.top_boxes
@[simp]
theorem not_mem_bot : J ∉ (⊥ : Prepartition I) :=
Finset.not_mem_empty _
#align box_integral.prepartition.not_mem_bot BoxIntegral.Prepartition.not_mem_bot
@[simp]
theorem bot_boxes : (⊥ : Prepartition I).boxes = ∅ := rfl
#align box_integral.prepartition.bot_boxes BoxIntegral.Prepartition.bot_boxes
/-- An auxiliary lemma used to prove that the same point can't belong to more than
`2 ^ Fintype.card ι` closed boxes of a prepartition. -/
theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ι → ℝ) :
InjOn (fun J : Box ι => { i | J.lower i = x i }) { J | J ∈ π ∧ x ∈ Box.Icc J } := by
rintro J₁ ⟨h₁, hx₁⟩ J₂ ⟨h₂, hx₂⟩ (H : { i | J₁.lower i = x i } = { i | J₂.lower i = x i })
suffices ∀ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (J₂.lower i) (J₂.upper i)).Nonempty by
choose y hy₁ hy₂ using this
exact π.eq_of_mem_of_mem h₁ h₂ hy₁ hy₂
intro i
simp only [Set.ext_iff, mem_setOf] at H
rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁
· have hi₂ : J₂.lower i = x i := (H _).1 hi₁
have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i
have H₂ : x i < J₂.upper i := by simpa only [hi₂] using J₂.lower_lt_upper i
rw [Ioc_inter_Ioc, hi₁, hi₂, sup_idem, Set.nonempty_Ioc]
exact lt_min H₁ H₂
· have hi₂ : J₂.lower i < x i := (hx₂.1 i).lt_of_ne (mt (H _).2 hi₁.ne)
exact ⟨x i, ⟨hi₁, hx₁.2 i⟩, ⟨hi₂, hx₂.2 i⟩⟩
#align box_integral.prepartition.inj_on_set_of_mem_Icc_set_of_lower_eq BoxIntegral.Prepartition.injOn_setOf_mem_Icc_setOf_lower_eq
/-- The set of boxes of a prepartition that contain `x` in their closures has cardinality
at most `2 ^ Fintype.card ι`. -/
theorem card_filter_mem_Icc_le [Fintype ι] (x : ι → ℝ) :
(π.boxes.filter fun J : Box ι => x ∈ Box.Icc J).card ≤ 2 ^ Fintype.card ι := by
rw [← Fintype.card_set]
refine Finset.card_le_card_of_inj_on (fun J : Box ι => { i | J.lower i = x i })
(fun _ _ => Finset.mem_univ _) ?_
simpa only [Finset.mem_filter] using π.injOn_setOf_mem_Icc_setOf_lower_eq x
#align box_integral.prepartition.card_filter_mem_Icc_le BoxIntegral.Prepartition.card_filter_mem_Icc_le
/-- Given a prepartition `π : BoxIntegral.Prepartition I`, `π.iUnion` is the part of `I` covered by
the boxes of `π`. -/
protected def iUnion : Set (ι → ℝ) :=
⋃ J ∈ π, ↑J
#align box_integral.prepartition.Union BoxIntegral.Prepartition.iUnion
theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl
#align box_integral.prepartition.Union_def BoxIntegral.Prepartition.iUnion_def
theorem iUnion_def' : π.iUnion = ⋃ J ∈ π.boxes, ↑J := rfl
#align box_integral.prepartition.Union_def' BoxIntegral.Prepartition.iUnion_def'
-- Porting note: Previous proof was `:= Set.mem_iUnion₂`
@[simp]
theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by
convert Set.mem_iUnion₂
rw [Box.mem_coe, exists_prop]
#align box_integral.prepartition.mem_Union BoxIntegral.Prepartition.mem_iUnion
@[simp]
theorem iUnion_single (h : J ≤ I) : (single I J h).iUnion = J := by simp [iUnion_def]
#align box_integral.prepartition.Union_single BoxIntegral.Prepartition.iUnion_single
@[simp]
theorem iUnion_top : (⊤ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion]
#align box_integral.prepartition.Union_top BoxIntegral.Prepartition.iUnion_top
@[simp]
theorem iUnion_eq_empty : π₁.iUnion = ∅ ↔ π₁ = ⊥ := by
simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false]
#align box_integral.prepartition.Union_eq_empty BoxIntegral.Prepartition.iUnion_eq_empty
@[simp]
theorem iUnion_bot : (⊥ : Prepartition I).iUnion = ∅ :=
iUnion_eq_empty.2 rfl
#align box_integral.prepartition.Union_bot BoxIntegral.Prepartition.iUnion_bot
theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion :=
subset_biUnion_of_mem h
#align box_integral.prepartition.subset_Union BoxIntegral.Prepartition.subset_iUnion
theorem iUnion_subset : π.iUnion ⊆ I :=
iUnion₂_subset π.le_of_mem'
#align box_integral.prepartition.Union_subset BoxIntegral.Prepartition.iUnion_subset
@[mono]
theorem iUnion_mono (h : π₁ ≤ π₂) : π₁.iUnion ⊆ π₂.iUnion := fun _ hx =>
let ⟨_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx
let ⟨J₂, hJ₂, hle⟩ := h hJ₁
π₂.mem_iUnion.2 ⟨J₂, hJ₂, hle hx⟩
#align box_integral.prepartition.Union_mono BoxIntegral.Prepartition.iUnion_mono
theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion π₂.iUnion) :
Disjoint π₁.boxes π₂.boxes :=
Finset.disjoint_left.2 fun J h₁ h₂ =>
Disjoint.le_bot (h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂)) ⟨J.upper_mem, J.upper_mem⟩
#align box_integral.prepartition.disjoint_boxes_of_disjoint_Union BoxIntegral.Prepartition.disjoint_boxes_of_disjoint_iUnion
theorem le_iff_nonempty_imp_le_and_iUnion_subset :
π₁ ≤ π₂ ↔
(∀ J ∈ π₁, ∀ J' ∈ π₂, (J ∩ J' : Set (ι → ℝ)).Nonempty → J ≤ J') ∧ π₁.iUnion ⊆ π₂.iUnion := by
constructor
· refine fun H => ⟨fun J hJ J' hJ' Hne => ?_, iUnion_mono H⟩
rcases H hJ with ⟨J'', hJ'', Hle⟩
rcases Hne with ⟨x, hx, hx'⟩
rwa [π₂.eq_of_mem_of_mem hJ' hJ'' hx' (Hle hx)]
· rintro ⟨H, HU⟩ J hJ
simp only [Set.subset_def, mem_iUnion] at HU
rcases HU J.upper ⟨J, hJ, J.upper_mem⟩ with ⟨J₂, hJ₂, hx⟩
exact ⟨J₂, hJ₂, H _ hJ _ hJ₂ ⟨_, J.upper_mem, hx⟩⟩
#align box_integral.prepartition.le_iff_nonempty_imp_le_and_Union_subset BoxIntegral.Prepartition.le_iff_nonempty_imp_le_and_iUnion_subset
theorem eq_of_boxes_subset_iUnion_superset (h₁ : π₁.boxes ⊆ π₂.boxes) (h₂ : π₂.iUnion ⊆ π₁.iUnion) :
π₁ = π₂ :=
le_antisymm (fun J hJ => ⟨J, h₁ hJ, le_rfl⟩) <|
le_iff_nonempty_imp_le_and_iUnion_subset.2
⟨fun _ hJ₁ _ hJ₂ Hne =>
(π₂.eq_of_mem_of_mem hJ₁ (h₁ hJ₂) Hne.choose_spec.1 Hne.choose_spec.2).le, h₂⟩
#align box_integral.prepartition.eq_of_boxes_subset_Union_superset BoxIntegral.Prepartition.eq_of_boxes_subset_iUnion_superset
/-- Given a prepartition `π` of a box `I` and a collection of prepartitions `πi J` of all boxes
`J ∈ π`, returns the prepartition of `I` into the union of the boxes of all `πi J`.
Though we only use the values of `πi` on the boxes of `π`, we require `πi` to be a globally defined
function. -/
@[simps]
def biUnion (πi : ∀ J : Box ι, Prepartition J) : Prepartition I where
boxes := π.boxes.biUnion fun J => (πi J).boxes
le_of_mem' J hJ := by
simp only [Finset.mem_biUnion, exists_prop, mem_boxes] at hJ
rcases hJ with ⟨J', hJ', hJ⟩
exact ((πi J').le_of_mem hJ).trans (π.le_of_mem hJ')
pairwiseDisjoint := by
simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_biUnion]
rintro J₁' ⟨J₁, hJ₁, hJ₁'⟩ J₂' ⟨J₂, hJ₂, hJ₂'⟩ Hne
rw [Function.onFun, Set.disjoint_left]
rintro x hx₁ hx₂; apply Hne
obtain rfl : J₁ = J₂ :=
π.eq_of_mem_of_mem hJ₁ hJ₂ ((πi J₁).le_of_mem hJ₁' hx₁) ((πi J₂).le_of_mem hJ₂' hx₂)
exact (πi J₁).eq_of_mem_of_mem hJ₁' hJ₂' hx₁ hx₂
#align box_integral.prepartition.bUnion BoxIntegral.Prepartition.biUnion
variable {πi πi₁ πi₂ : ∀ J : Box ι, Prepartition J}
@[simp]
theorem mem_biUnion : J ∈ π.biUnion πi ↔ ∃ J' ∈ π, J ∈ πi J' := by simp [biUnion]
#align box_integral.prepartition.mem_bUnion BoxIntegral.Prepartition.mem_biUnion
theorem biUnion_le (πi : ∀ J, Prepartition J) : π.biUnion πi ≤ π := fun _ hJ =>
let ⟨J', hJ', hJ⟩ := π.mem_biUnion.1 hJ
⟨J', hJ', (πi J').le_of_mem hJ⟩
#align box_integral.prepartition.bUnion_le BoxIntegral.Prepartition.biUnion_le
@[simp]
theorem biUnion_top : (π.biUnion fun _ => ⊤) = π := by
ext
simp
#align box_integral.prepartition.bUnion_top BoxIntegral.Prepartition.biUnion_top
@[congr]
theorem biUnion_congr (h : π₁ = π₂) (hi : ∀ J ∈ π₁, πi₁ J = πi₂ J) :
π₁.biUnion πi₁ = π₂.biUnion πi₂ := by
subst π₂
ext J
simp only [mem_biUnion]
constructor <;> exact fun ⟨J', h₁, h₂⟩ => ⟨J', h₁, hi J' h₁ ▸ h₂⟩
#align box_integral.prepartition.bUnion_congr BoxIntegral.Prepartition.biUnion_congr
theorem biUnion_congr_of_le (h : π₁ = π₂) (hi : ∀ J ≤ I, πi₁ J = πi₂ J) :
π₁.biUnion πi₁ = π₂.biUnion πi₂ :=
biUnion_congr h fun J hJ => hi J (π₁.le_of_mem hJ)
#align box_integral.prepartition.bUnion_congr_of_le BoxIntegral.Prepartition.biUnion_congr_of_le
@[simp]
theorem iUnion_biUnion (πi : ∀ J : Box ι, Prepartition J) :
(π.biUnion πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := by simp [Prepartition.iUnion]
#align box_integral.prepartition.Union_bUnion BoxIntegral.Prepartition.iUnion_biUnion
@[simp]
theorem sum_biUnion_boxes {M : Type*} [AddCommMonoid M] (π : Prepartition I)
(πi : ∀ J, Prepartition J) (f : Box ι → M) :
(∑ J ∈ π.boxes.biUnion fun J => (πi J).boxes, f J) =
∑ J ∈ π.boxes, ∑ J' ∈ (πi J).boxes, f J' := by
refine Finset.sum_biUnion fun J₁ h₁ J₂ h₂ hne => Finset.disjoint_left.2 fun J' h₁' h₂' => ?_
exact hne (π.eq_of_le_of_le h₁ h₂ ((πi J₁).le_of_mem h₁') ((πi J₂).le_of_mem h₂'))
#align box_integral.prepartition.sum_bUnion_boxes BoxIntegral.Prepartition.sum_biUnion_boxes
/-- Given a box `J ∈ π.biUnion πi`, returns the box `J' ∈ π` such that `J ∈ πi J'`.
For `J ∉ π.biUnion πi`, returns `I`. -/
def biUnionIndex (πi : ∀ (J : Box ι), Prepartition J) (J : Box ι) : Box ι :=
if hJ : J ∈ π.biUnion πi then (π.mem_biUnion.1 hJ).choose else I
#align box_integral.prepartition.bUnion_index BoxIntegral.Prepartition.biUnionIndex
theorem biUnionIndex_mem (hJ : J ∈ π.biUnion πi) : π.biUnionIndex πi J ∈ π := by
rw [biUnionIndex, dif_pos hJ]
exact (π.mem_biUnion.1 hJ).choose_spec.1
#align box_integral.prepartition.bUnion_index_mem BoxIntegral.Prepartition.biUnionIndex_mem
theorem biUnionIndex_le (πi : ∀ J, Prepartition J) (J : Box ι) : π.biUnionIndex πi J ≤ I := by
by_cases hJ : J ∈ π.biUnion πi
· exact π.le_of_mem (π.biUnionIndex_mem hJ)
· rw [biUnionIndex, dif_neg hJ]
#align box_integral.prepartition.bUnion_index_le BoxIntegral.Prepartition.biUnionIndex_le
theorem mem_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ∈ πi (π.biUnionIndex πi J) := by
convert (π.mem_biUnion.1 hJ).choose_spec.2 <;> exact dif_pos hJ
#align box_integral.prepartition.mem_bUnion_index BoxIntegral.Prepartition.mem_biUnionIndex
theorem le_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ≤ π.biUnionIndex πi J :=
le_of_mem _ (π.mem_biUnionIndex hJ)
#align box_integral.prepartition.le_bUnion_index BoxIntegral.Prepartition.le_biUnionIndex
/-- Uniqueness property of `BoxIntegral.Prepartition.biUnionIndex`. -/
theorem biUnionIndex_of_mem (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : π.biUnionIndex πi J' = J :=
have : J' ∈ π.biUnion πi := π.mem_biUnion.2 ⟨J, hJ, hJ'⟩
π.eq_of_le_of_le (π.biUnionIndex_mem this) hJ (π.le_biUnionIndex this) (le_of_mem _ hJ')
#align box_integral.prepartition.bUnion_index_of_mem BoxIntegral.Prepartition.biUnionIndex_of_mem
theorem biUnion_assoc (πi : ∀ J, Prepartition J) (πi' : Box ι → ∀ J : Box ι, Prepartition J) :
(π.biUnion fun J => (πi J).biUnion (πi' J)) =
(π.biUnion πi).biUnion fun J => πi' (π.biUnionIndex πi J) J := by
ext J
simp only [mem_biUnion, exists_prop]
constructor
· rintro ⟨J₁, hJ₁, J₂, hJ₂, hJ⟩
refine ⟨J₂, ⟨J₁, hJ₁, hJ₂⟩, ?_⟩
rwa [π.biUnionIndex_of_mem hJ₁ hJ₂]
· rintro ⟨J₁, ⟨J₂, hJ₂, hJ₁⟩, hJ⟩
refine ⟨J₂, hJ₂, J₁, hJ₁, ?_⟩
rwa [π.biUnionIndex_of_mem hJ₂ hJ₁] at hJ
#align box_integral.prepartition.bUnion_assoc BoxIntegral.Prepartition.biUnion_assoc
/-- Create a `BoxIntegral.Prepartition` from a collection of possibly empty boxes by filtering out
the empty one if it exists. -/
def ofWithBot (boxes : Finset (WithBot (Box ι)))
(le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I)
(pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) :
Prepartition I where
boxes := Finset.eraseNone boxes
le_of_mem' J hJ := by
rw [mem_eraseNone] at hJ
simpa only [WithBot.some_eq_coe, WithBot.coe_le_coe] using le_of_mem _ hJ
pairwiseDisjoint J₁ h₁ J₂ h₂ hne := by
simp only [mem_coe, mem_eraseNone] at h₁ h₂
exact Box.disjoint_coe.1 (pairwise_disjoint h₁ h₂ (mt Option.some_inj.1 hne))
#align box_integral.prepartition.of_with_bot BoxIntegral.Prepartition.ofWithBot
@[simp]
theorem mem_ofWithBot {boxes : Finset (WithBot (Box ι))} {h₁ h₂} :
J ∈ (ofWithBot boxes h₁ h₂ : Prepartition I) ↔ (J : WithBot (Box ι)) ∈ boxes :=
mem_eraseNone
#align box_integral.prepartition.mem_of_with_bot BoxIntegral.Prepartition.mem_ofWithBot
@[simp]
theorem iUnion_ofWithBot (boxes : Finset (WithBot (Box ι)))
(le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I)
(pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) :
(ofWithBot boxes le_of_mem pairwise_disjoint).iUnion = ⋃ J ∈ boxes, ↑J := by
suffices ⋃ (J : Box ι) (_ : ↑J ∈ boxes), ↑J = ⋃ J ∈ boxes, (J : Set (ι → ℝ)) by
simpa [ofWithBot, Prepartition.iUnion]
simp only [← Box.biUnion_coe_eq_coe, @iUnion_comm _ _ (Box ι), @iUnion_comm _ _ (@Eq _ _ _),
iUnion_iUnion_eq_right]
#align box_integral.prepartition.Union_of_with_bot BoxIntegral.Prepartition.iUnion_ofWithBot
theorem ofWithBot_le {boxes : Finset (WithBot (Box ι))}
{le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint}
(H : ∀ J ∈ boxes, J ≠ ⊥ → ∃ J' ∈ π, J ≤ ↑J') :
ofWithBot boxes le_of_mem pairwise_disjoint ≤ π := by
have : ∀ J : Box ι, ↑J ∈ boxes → ∃ J' ∈ π, J ≤ J' := fun J hJ => by
simpa only [WithBot.coe_le_coe] using H J hJ WithBot.coe_ne_bot
simpa [ofWithBot, le_def]
#align box_integral.prepartition.of_with_bot_le BoxIntegral.Prepartition.ofWithBot_le
theorem le_ofWithBot {boxes : Finset (WithBot (Box ι))}
{le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint}
(H : ∀ J ∈ π, ∃ J' ∈ boxes, ↑J ≤ J') : π ≤ ofWithBot boxes le_of_mem pairwise_disjoint := by
intro J hJ
rcases H J hJ with ⟨J', J'mem, hle⟩
lift J' to Box ι using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hle
exact ⟨J', mem_ofWithBot.2 J'mem, WithBot.coe_le_coe.1 hle⟩
#align box_integral.prepartition.le_of_with_bot BoxIntegral.Prepartition.le_ofWithBot
theorem ofWithBot_mono {boxes₁ : Finset (WithBot (Box ι))}
{le_of_mem₁ : ∀ J ∈ boxes₁, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint₁ : Set.Pairwise (boxes₁ : Set (WithBot (Box ι))) Disjoint}
{boxes₂ : Finset (WithBot (Box ι))} {le_of_mem₂ : ∀ J ∈ boxes₂, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint₂ : Set.Pairwise (boxes₂ : Set (WithBot (Box ι))) Disjoint}
(H : ∀ J ∈ boxes₁, J ≠ ⊥ → ∃ J' ∈ boxes₂, J ≤ J') :
ofWithBot boxes₁ le_of_mem₁ pairwise_disjoint₁ ≤
ofWithBot boxes₂ le_of_mem₂ pairwise_disjoint₂ :=
le_ofWithBot _ fun J hJ => H J (mem_ofWithBot.1 hJ) WithBot.coe_ne_bot
#align box_integral.prepartition.of_with_bot_mono BoxIntegral.Prepartition.ofWithBot_mono
theorem sum_ofWithBot {M : Type*} [AddCommMonoid M] (boxes : Finset (WithBot (Box ι)))
(le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I)
(pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) (f : Box ι → M) :
(∑ J ∈ (ofWithBot boxes le_of_mem pairwise_disjoint).boxes, f J) =
∑ J ∈ boxes, Option.elim' 0 f J :=
Finset.sum_eraseNone _ _
#align box_integral.prepartition.sum_of_with_bot BoxIntegral.Prepartition.sum_ofWithBot
/-- Restrict a prepartition to a box. -/
def restrict (π : Prepartition I) (J : Box ι) : Prepartition J :=
ofWithBot (π.boxes.image fun J' : Box ι => J ⊓ J')
(fun J' hJ' => by
rcases Finset.mem_image.1 hJ' with ⟨J', -, rfl⟩
exact inf_le_left)
(by
simp only [Set.Pairwise, onFun, Finset.mem_coe, Finset.mem_image]
rintro _ ⟨J₁, h₁, rfl⟩ _ ⟨J₂, h₂, rfl⟩ Hne
have : J₁ ≠ J₂ := by
rintro rfl
exact Hne rfl
exact ((Box.disjoint_coe.2 <| π.disjoint_coe_of_mem h₁ h₂ this).inf_left' _).inf_right' _)
#align box_integral.prepartition.restrict BoxIntegral.Prepartition.restrict
@[simp]
theorem mem_restrict : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : WithBot (Box ι)) = ↑J ⊓ ↑J' := by
simp [restrict, eq_comm]
#align box_integral.prepartition.mem_restrict BoxIntegral.Prepartition.mem_restrict
theorem mem_restrict' : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : Set (ι → ℝ)) = ↑J ∩ ↑J' := by
simp only [mem_restrict, ← Box.withBotCoe_inj, Box.coe_inf, Box.coe_coe]
#align box_integral.prepartition.mem_restrict' BoxIntegral.Prepartition.mem_restrict'
@[mono]
theorem restrict_mono {π₁ π₂ : Prepartition I} (Hle : π₁ ≤ π₂) : π₁.restrict J ≤ π₂.restrict J := by
refine ofWithBot_mono fun J₁ hJ₁ hne => ?_
rw [Finset.mem_image] at hJ₁; rcases hJ₁ with ⟨J₁, hJ₁, rfl⟩
rcases Hle hJ₁ with ⟨J₂, hJ₂, hle⟩
exact ⟨_, Finset.mem_image_of_mem _ hJ₂, inf_le_inf_left _ <| WithBot.coe_le_coe.2 hle⟩
#align box_integral.prepartition.restrict_mono BoxIntegral.Prepartition.restrict_mono
theorem monotone_restrict : Monotone fun π : Prepartition I => restrict π J :=
fun _ _ => restrict_mono
#align box_integral.prepartition.monotone_restrict BoxIntegral.Prepartition.monotone_restrict
/-- Restricting to a larger box does not change the set of boxes. We cannot claim equality
of prepartitions because they have different types. -/
theorem restrict_boxes_of_le (π : Prepartition I) (h : I ≤ J) : (π.restrict J).boxes = π.boxes := by
simp only [restrict, ofWithBot, eraseNone_eq_biUnion]
refine Finset.image_biUnion.trans ?_
refine (Finset.biUnion_congr rfl ?_).trans Finset.biUnion_singleton_eq_self
intro J' hJ'
rw [inf_of_le_right, ← WithBot.some_eq_coe, Option.toFinset_some]
exact WithBot.coe_le_coe.2 ((π.le_of_mem hJ').trans h)
#align box_integral.prepartition.restrict_boxes_of_le BoxIntegral.Prepartition.restrict_boxes_of_le
@[simp]
theorem restrict_self : π.restrict I = π :=
injective_boxes <| restrict_boxes_of_le π le_rfl
#align box_integral.prepartition.restrict_self BoxIntegral.Prepartition.restrict_self
@[simp]
theorem iUnion_restrict : (π.restrict J).iUnion = (J : Set (ι → ℝ)) ∩ (π.iUnion) := by
simp [restrict, ← inter_iUnion, ← iUnion_def]
#align box_integral.prepartition.Union_restrict BoxIntegral.Prepartition.iUnion_restrict
@[simp]
theorem restrict_biUnion (πi : ∀ J, Prepartition J) (hJ : J ∈ π) :
(π.biUnion πi).restrict J = πi J := by
refine (eq_of_boxes_subset_iUnion_superset (fun J₁ h₁ => ?_) ?_).symm
· refine (mem_restrict _).2 ⟨J₁, π.mem_biUnion.2 ⟨J, hJ, h₁⟩, (inf_of_le_right ?_).symm⟩
exact WithBot.coe_le_coe.2 (le_of_mem _ h₁)
· simp only [iUnion_restrict, iUnion_biUnion, Set.subset_def, Set.mem_inter_iff, Set.mem_iUnion]
rintro x ⟨hxJ, J₁, h₁, hx⟩
obtain rfl : J = J₁ := π.eq_of_mem_of_mem hJ h₁ hxJ (iUnion_subset _ hx)
exact hx
#align box_integral.prepartition.restrict_bUnion BoxIntegral.Prepartition.restrict_biUnion
theorem biUnion_le_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} :
π.biUnion πi ≤ π' ↔ ∀ J ∈ π, πi J ≤ π'.restrict J := by
constructor <;> intro H J hJ
· rw [← π.restrict_biUnion πi hJ]
exact restrict_mono H
· rw [mem_biUnion] at hJ
rcases hJ with ⟨J₁, h₁, hJ⟩
rcases H J₁ h₁ hJ with ⟨J₂, h₂, Hle⟩
rcases π'.mem_restrict.mp h₂ with ⟨J₃, h₃, H⟩
exact ⟨J₃, h₃, Hle.trans <| WithBot.coe_le_coe.1 <| H.trans_le inf_le_right⟩
#align box_integral.prepartition.bUnion_le_iff BoxIntegral.Prepartition.biUnion_le_iff
theorem le_biUnion_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} :
π' ≤ π.biUnion πi ↔ π' ≤ π ∧ ∀ J ∈ π, π'.restrict J ≤ πi J := by
refine ⟨fun H => ⟨H.trans (π.biUnion_le πi), fun J hJ => ?_⟩, ?_⟩
· rw [← π.restrict_biUnion πi hJ]
exact restrict_mono H
· rintro ⟨H, Hi⟩ J' hJ'
rcases H hJ' with ⟨J, hJ, hle⟩
have : J' ∈ π'.restrict J :=
π'.mem_restrict.2 ⟨J', hJ', (inf_of_le_right <| WithBot.coe_le_coe.2 hle).symm⟩
rcases Hi J hJ this with ⟨Ji, hJi, hlei⟩
exact ⟨Ji, π.mem_biUnion.2 ⟨J, hJ, hJi⟩, hlei⟩
#align box_integral.prepartition.le_bUnion_iff BoxIntegral.Prepartition.le_biUnion_iff
instance inf : Inf (Prepartition I) :=
⟨fun π₁ π₂ => π₁.biUnion fun J => π₂.restrict J⟩
theorem inf_def (π₁ π₂ : Prepartition I) : π₁ ⊓ π₂ = π₁.biUnion fun J => π₂.restrict J := rfl
#align box_integral.prepartition.inf_def BoxIntegral.Prepartition.inf_def
@[simp]
theorem mem_inf {π₁ π₂ : Prepartition I} :
J ∈ π₁ ⊓ π₂ ↔ ∃ J₁ ∈ π₁, ∃ J₂ ∈ π₂, (J : WithBot (Box ι)) = ↑J₁ ⊓ ↑J₂ := by
simp only [inf_def, mem_biUnion, mem_restrict]
#align box_integral.prepartition.mem_inf BoxIntegral.Prepartition.mem_inf
@[simp]
theorem iUnion_inf (π₁ π₂ : Prepartition I) : (π₁ ⊓ π₂).iUnion = π₁.iUnion ∩ π₂.iUnion := by
simp only [inf_def, iUnion_biUnion, iUnion_restrict, ← iUnion_inter, ← iUnion_def]
#align box_integral.prepartition.Union_inf BoxIntegral.Prepartition.iUnion_inf
instance : SemilatticeInf (Prepartition I) :=
{ Prepartition.inf,
Prepartition.partialOrder with
inf_le_left := fun π₁ _ => π₁.biUnion_le _
inf_le_right := fun _ _ => (biUnion_le_iff _).2 fun _ _ => le_rfl
le_inf := fun _ π₁ _ h₁ h₂ => π₁.le_biUnion_iff.2 ⟨h₁, fun _ _ => restrict_mono h₂⟩ }
/-- The prepartition with boxes `{J ∈ π | p J}`. -/
@[simps]
def filter (π : Prepartition I) (p : Box ι → Prop) : Prepartition I where
boxes := π.boxes.filter p
le_of_mem' _ hJ := π.le_of_mem (mem_filter.1 hJ).1
pairwiseDisjoint _ h₁ _ h₂ := π.disjoint_coe_of_mem (mem_filter.1 h₁).1 (mem_filter.1 h₂).1
#align box_integral.prepartition.filter BoxIntegral.Prepartition.filter
@[simp]
theorem mem_filter {p : Box ι → Prop} : J ∈ π.filter p ↔ J ∈ π ∧ p J :=
Finset.mem_filter
#align box_integral.prepartition.mem_filter BoxIntegral.Prepartition.mem_filter
theorem filter_le (π : Prepartition I) (p : Box ι → Prop) : π.filter p ≤ π := fun J hJ =>
let ⟨hπ, _⟩ := π.mem_filter.1 hJ
⟨J, hπ, le_rfl⟩
#align box_integral.prepartition.filter_le BoxIntegral.Prepartition.filter_le
| Mathlib/Analysis/BoxIntegral/Partition/Basic.lean | 611 | 613 | theorem filter_of_true {p : Box ι → Prop} (hp : ∀ J ∈ π, p J) : π.filter p = π := by |
ext J
simpa using hp J
|
/-
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
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)
#align polynomial.eq_zero_of_dvd_of_nat_degree_lt Polynomial.eq_zero_of_dvd_of_natDegree_lt
theorem not_dvd_of_degree_lt {p q : R[X]} (h0 : q ≠ 0) (hl : q.degree < p.degree) : ¬p ∣ q := by
by_contra hcontra
exact h0 (eq_zero_of_dvd_of_degree_lt hcontra hl)
#align polynomial.not_dvd_of_degree_lt Polynomial.not_dvd_of_degree_lt
theorem not_dvd_of_natDegree_lt {p q : R[X]} (h0 : q ≠ 0) (hl : q.natDegree < p.natDegree) :
¬p ∣ q := by
by_contra hcontra
exact h0 (eq_zero_of_dvd_of_natDegree_lt hcontra hl)
#align polynomial.not_dvd_of_nat_degree_lt Polynomial.not_dvd_of_natDegree_lt
/-- This lemma is useful for working with the `intDegree` of a rational function. -/
theorem natDegree_sub_eq_of_prod_eq {p₁ p₂ q₁ q₂ : R[X]} (hp₁ : p₁ ≠ 0) (hq₁ : q₁ ≠ 0)
(hp₂ : p₂ ≠ 0) (hq₂ : q₂ ≠ 0) (h_eq : p₁ * q₂ = p₂ * q₁) :
(p₁.natDegree : ℤ) - q₁.natDegree = (p₂.natDegree : ℤ) - q₂.natDegree := by
rw [sub_eq_sub_iff_add_eq_add]
norm_cast
rw [← natDegree_mul hp₁ hq₂, ← natDegree_mul hp₂ hq₁, h_eq]
#align polynomial.nat_degree_sub_eq_of_prod_eq Polynomial.natDegree_sub_eq_of_prod_eq
theorem natDegree_eq_zero_of_isUnit (h : IsUnit p) : natDegree p = 0 := by
nontriviality R
obtain ⟨q, hq⟩ := h.exists_right_inv
have := natDegree_mul (left_ne_zero_of_mul_eq_one hq) (right_ne_zero_of_mul_eq_one hq)
rw [hq, natDegree_one, eq_comm, add_eq_zero_iff] at this
exact this.1
#align polynomial.nat_degree_eq_zero_of_is_unit Polynomial.natDegree_eq_zero_of_isUnit
theorem degree_eq_zero_of_isUnit [Nontrivial R] (h : IsUnit p) : degree p = 0 :=
(natDegree_eq_zero_iff_degree_le_zero.mp <| natDegree_eq_zero_of_isUnit h).antisymm
(zero_le_degree_iff.mpr h.ne_zero)
#align polynomial.degree_eq_zero_of_is_unit Polynomial.degree_eq_zero_of_isUnit
@[simp]
theorem degree_coe_units [Nontrivial R] (u : R[X]ˣ) : degree (u : R[X]) = 0 :=
degree_eq_zero_of_isUnit ⟨u, rfl⟩
#align polynomial.degree_coe_units Polynomial.degree_coe_units
/-- Characterization of a unit of a polynomial ring over an integral domain `R`.
See `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent` when `R` is a commutative ring. -/
theorem isUnit_iff : IsUnit p ↔ ∃ r : R, IsUnit r ∧ C r = p :=
⟨fun hp =>
⟨p.coeff 0,
let h := eq_C_of_natDegree_eq_zero (natDegree_eq_zero_of_isUnit hp)
⟨isUnit_C.1 (h ▸ hp), h.symm⟩⟩,
fun ⟨_, hr, hrp⟩ => hrp ▸ isUnit_C.2 hr⟩
#align polynomial.is_unit_iff Polynomial.isUnit_iff
| Mathlib/Algebra/Polynomial/RingDivision.lean | 226 | 231 | theorem not_isUnit_of_degree_pos (p : R[X])
(hpl : 0 < p.degree) : ¬ IsUnit p := by |
cases subsingleton_or_nontrivial R
· simp [Subsingleton.elim p 0] at hpl
intro h
simp [degree_eq_zero_of_isUnit h] at hpl
|
/-
Copyright (c) 2023 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.RepresentationTheory.GroupCohomology.Basic
import Mathlib.RepresentationTheory.Invariants
/-!
# The low-degree cohomology of a `k`-linear `G`-representation
Let `k` be a commutative ring and `G` a group. This file gives simple expressions for
the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2.
In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be
the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is
unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract
cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries.
We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`.
Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`,
we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an
element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the
scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The
multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case;
unfortunately `@[to_additive]` can't deal with scalar actions.
The file also contains an identification between the definitions in
`RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and
`groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`.
## Main definitions
* `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`.
* `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo
1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`).
* `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo
2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`).
* `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the
representation on `A` is trivial.
* `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism
`groupCohomology A n ≅ groupCohomology.Hn A`.
## TODO
* The relationship between `H2` and group extensions
* The inflation-restriction exact sequence
* Nonabelian group cohomology
-/
universe v u
noncomputable section
open CategoryTheory Limits Representation
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G)
namespace groupCohomology
section Cochains
/-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `A` as a `k`-module. -/
def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A :=
LinearEquiv.funUnique (Fin 0 → G) k A
/-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G, A)` as a `k`-module. -/
def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A :=
LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm
/-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G², A)` as a `k`-module. -/
def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A :=
LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm
/-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G³, A)` as a `k`-module. -/
def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A :=
LinearEquiv.funCongrLeft k A <| ((Equiv.piFinSucc 2 G).trans
((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm
end Cochains
section Differentials
/-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/
@[simps]
def dZero : A →ₗ[k] G → A where
toFun m g := A.ρ g m - m
map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl
map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub]
theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by
ext x
simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, Function.funext_iff]
rfl
@[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by
ext
simp only [dZero_apply, apply_eq_self, sub_self, LinearMap.zero_apply, Pi.zero_apply]
/-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends
`(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
@[simps]
def dOne : (G → A) →ₗ[k] G × G → A where
toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1
map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm]
map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub]
/-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends
`(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/
@[simps]
def dTwo : (G × G → A) →ₗ[k] G × G × G → A where
toFun f g :=
A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1)
map_add' x y :=
funext fun g => by
dsimp
rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm,
add_sub_assoc, add_sub_assoc]
map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub]
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `dZero` gives a simpler expression for the 0th differential: that is, the following
square commutes:
```
C⁰(G, A) ---d⁰---> C¹(G, A)
| |
| |
| |
v v
A ---- dZero ---> Fun(G, A)
```
where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively.
-/
theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) =
oneCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 0 1 := by
ext x y
show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _
simp_rw [Fin.coe_fin_one, zero_add, pow_one, neg_smul, one_smul,
Finset.sum_singleton, sub_eq_add_neg]
rcongr i <;> exact Fin.elim0 i
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `dOne` gives a simpler expression for the 1st differential: that is, the following
square commutes:
```
C¹(G, A) ---d¹-----> C²(G, A)
| |
| |
| |
v v
Fun(G, A) -dOne-> Fun(G × G, A)
```
where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively.
-/
theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A =
twoCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 1 2 := by
ext x y
show A.ρ y.1 (x _) - x _ + x _ = _ + _
rw [Fin.sum_univ_two]
simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one,
Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc]
rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `dTwo` gives a simpler expression for the 2nd differential: that is, the following
square commutes:
```
C²(G, A) -------d²-----> C³(G, A)
| |
| |
| |
v v
Fun(G × G, A) --dTwo--> Fun(G × G × G, A)
```
where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively.
-/
theorem dTwo_comp_eq :
dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 2 3 := by
ext x y
show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _
dsimp
rw [Fin.sum_univ_three]
simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul,
one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one]
rcongr i <;> fin_cases i <;> rfl
theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by
ext x g
simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub,
map_mul, LinearMap.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self]
rfl
theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by
show ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A) = _
have h1 : _ ≫ ModuleCat.ofHom (dOne A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dOne_comp_eq A)
have h2 : _ ≫ ModuleCat.ofHom (dTwo A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dTwo_comp_eq A)
simp only [← LinearEquiv.toModuleIso_hom] at h1 h2
simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1,
Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero]
end Differentials
section Cocycles
/-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map
`Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A)
/-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map
`Fun(G × G, A) → Fun(G × G × G, A)` sending
`(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/
def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A)
variable {A}
theorem mem_oneCocycles_def (f : G → A) :
f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 :=
LinearMap.mem_ker.trans <| by
rw [Function.funext_iff]
simp only [dOne_apply, Pi.zero_apply, Prod.forall]
theorem mem_oneCocycles_iff (f : G → A) :
f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by
simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm]
@[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f.1 1 = 0 := by
have := (mem_oneCocycles_def f.1).1 f.2 1 1
simpa only [map_one, LinearMap.one_apply, mul_one, sub_self, zero_add] using this
@[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) :
A.ρ g (f.1 g⁻¹) = - f.1 g := by
rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_self g,
(mem_oneCocycles_iff f.1).1 f.2 g g⁻¹]
theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) :
f.1 (g * h) = f.1 g + f.1 h := by
rw [(mem_oneCocycles_iff f.1).1 f.2, apply_eq_self A.ρ g (f.1 h), add_comm]
theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) :
f ∘ Additive.ofMul ∈ oneCocycles A :=
(mem_oneCocycles_iff _).2 fun g h => by
simp only [Function.comp_apply, ofMul_mul, map_add,
oneCocycles_map_mul_of_isTrivial, apply_eq_self A.ρ g (f (Additive.ofMul h)),
add_comm (f (Additive.ofMul g))]
variable (A)
/-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the
group homs `G → A`. -/
@[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] :
oneCocycles A ≃ₗ[k] Additive G →+ A where
toFun f :=
{ toFun := f.1 ∘ Additive.toMul
map_zero' := oneCocycles_map_one f
map_add' := oneCocycles_map_mul_of_isTrivial f }
map_add' x y := rfl
map_smul' r x := rfl
invFun f :=
{ val := f
property := mem_oneCocycles_of_addMonoidHom f }
left_inv f := by ext; rfl
right_inv f := by ext; rfl
variable {A}
theorem mem_twoCocycles_def (f : G × G → A) :
f ∈ twoCocycles A ↔ ∀ g h j : G,
A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 :=
LinearMap.mem_ker.trans <| by
rw [Function.funext_iff]
simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall]
theorem mem_twoCocycles_iff (f : G × G → A) :
f ∈ twoCocycles A ↔ ∀ g h j : G,
f (g * h, j) + f (g, h) =
A.ρ g (f (h, j)) + f (g, h * j) := by
simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm,
add_comm (f (_ * _, _))]
theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) :
f.1 (1, g) = f.1 (1, 1) := by
have := ((mem_twoCocycles_iff f.1).1 f.2 1 1 g).symm
simpa only [map_one, LinearMap.one_apply, one_mul, add_right_inj, this]
theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) :
f.1 (g, 1) = A.ρ g (f.1 (1, 1)) := by
have := (mem_twoCocycles_iff f.1).1 f.2 g 1 1
simpa only [mul_one, add_left_inj, this]
lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) :
A.ρ g (f.1 (g⁻¹, g)) - f.1 (g, g⁻¹)
= f.1 (1, 1) - f.1 (g, 1) := by
have := (mem_twoCocycles_iff f.1).1 f.2 g g⁻¹ g
simp only [mul_right_inv, mul_left_inv, twoCocycles_map_one_fst _ g]
at this
exact sub_eq_sub_iff_add_eq_add.2 this.symm
end Cocycles
section Coboundaries
/-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map
`A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/
def oneCoboundaries : Submodule k (oneCocycles A) :=
LinearMap.range ((dZero A).codRestrict (oneCocycles A) fun c =>
LinearMap.ext_iff.1 (dOne_comp_dZero A) c)
/-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map
`Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
def twoCoboundaries : Submodule k (twoCocycles A) :=
LinearMap.range ((dOne A).codRestrict (twoCocycles A) fun c =>
LinearMap.ext_iff.1 (dTwo_comp_dOne.{u} A) c)
variable {A}
/-- Makes a 1-coboundary out of `f ∈ Im(d⁰)`. -/
def oneCoboundariesOfMemRange {f : G → A} (h : f ∈ LinearMap.range (dZero A)) :
oneCoboundaries A :=
⟨⟨f, LinearMap.range_le_ker_iff.2 (dOne_comp_dZero A) h⟩,
by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩⟩
theorem oneCoboundaries_of_mem_range_apply {f : G → A} (h : f ∈ LinearMap.range (dZero A)) :
(oneCoboundariesOfMemRange h).1.1 = f := rfl
/-- Makes a 1-coboundary out of `f : G → A` and `x` such that
`ρ(g)(x) - x = f(g)` for all `g : G`. -/
def oneCoboundariesOfEq {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) :
oneCoboundaries A :=
oneCoboundariesOfMemRange ⟨x, by ext g; exact hf g⟩
theorem oneCoboundariesOfEq_apply {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) :
(oneCoboundariesOfEq hf).1.1 = f := rfl
| Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean | 345 | 347 | theorem mem_range_of_mem_oneCoboundaries {f : oneCocycles A} (h : f ∈ oneCoboundaries A) :
f.1 ∈ LinearMap.range (dZero A) := by |
rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩
|
/-
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.Calculus.ContDiff.RCLike
import Mathlib.MeasureTheory.Measure.Hausdorff
#align_import topology.metric_space.hausdorff_dimension from "leanprover-community/mathlib"@"8f9fea08977f7e450770933ee6abb20733b47c92"
/-!
# Hausdorff dimension
The Hausdorff dimension of a set `X` in an (extended) metric space is the unique number
`dimH s : ℝ≥0∞` such that for any `d : ℝ≥0` we have
- `μH[d] s = 0` if `dimH s < d`, and
- `μH[d] s = ∞` if `d < dimH s`.
In this file we define `dimH s` to be the Hausdorff dimension of `s`, then prove some basic
properties of Hausdorff dimension.
## Main definitions
* `MeasureTheory.dimH`: the Hausdorff dimension of a set. For the Hausdorff dimension of the whole
space we use `MeasureTheory.dimH (Set.univ : Set X)`.
## Main results
### Basic properties of Hausdorff dimension
* `hausdorffMeasure_of_lt_dimH`, `dimH_le_of_hausdorffMeasure_ne_top`,
`le_dimH_of_hausdorffMeasure_eq_top`, `hausdorffMeasure_of_dimH_lt`, `measure_zero_of_dimH_lt`,
`le_dimH_of_hausdorffMeasure_ne_zero`, `dimH_of_hausdorffMeasure_ne_zero_ne_top`: various forms
of the characteristic property of the Hausdorff dimension;
* `dimH_union`: the Hausdorff dimension of the union of two sets is the maximum of their Hausdorff
dimensions.
* `dimH_iUnion`, `dimH_bUnion`, `dimH_sUnion`: the Hausdorff dimension of a countable union of sets
is the supremum of their Hausdorff dimensions;
* `dimH_empty`, `dimH_singleton`, `Set.Subsingleton.dimH_zero`, `Set.Countable.dimH_zero` : `dimH s
= 0` whenever `s` is countable;
### (Pre)images under (anti)lipschitz and Hölder continuous maps
* `HolderWith.dimH_image_le` etc: if `f : X → Y` is Hölder continuous with exponent `r > 0`, then
for any `s`, `dimH (f '' s) ≤ dimH s / r`. We prove versions of this statement for `HolderWith`,
`HolderOnWith`, and locally Hölder maps, as well as for `Set.image` and `Set.range`.
* `LipschitzWith.dimH_image_le` etc: Lipschitz continuous maps do not increase the Hausdorff
dimension of sets.
* for a map that is known to be both Lipschitz and antilipschitz (e.g., for an `Isometry` or
a `ContinuousLinearEquiv`) we also prove `dimH (f '' s) = dimH s`.
### Hausdorff measure in `ℝⁿ`
* `Real.dimH_of_nonempty_interior`: if `s` is a set in a finite dimensional real vector space `E`
with nonempty interior, then the Hausdorff dimension of `s` is equal to the dimension of `E`.
* `dense_compl_of_dimH_lt_finrank`: if `s` is a set in a finite dimensional real vector space `E`
with Hausdorff dimension strictly less than the dimension of `E`, the `s` has a dense complement.
* `ContDiff.dense_compl_range_of_finrank_lt_finrank`: the complement to the range of a `C¹`
smooth map is dense provided that the dimension of the domain is strictly less than the dimension
of the codomain.
## Notations
We use the following notation localized in `MeasureTheory`. It is defined in
`MeasureTheory.Measure.Hausdorff`.
- `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d`
## Implementation notes
* The definition of `dimH` explicitly uses `borel X` as a measurable space structure. This way we
can formulate lemmas about Hausdorff dimension without assuming that the environment has a
`[MeasurableSpace X]` instance that is equal but possibly not defeq to `borel X`.
Lemma `dimH_def` unfolds this definition using whatever `[MeasurableSpace X]` instance we have in
the environment (as long as it is equal to `borel X`).
* The definition `dimH` is irreducible; use API lemmas or `dimH_def` instead.
## Tags
Hausdorff measure, Hausdorff dimension, dimension
-/
open scoped MeasureTheory ENNReal NNReal Topology
open MeasureTheory MeasureTheory.Measure Set TopologicalSpace FiniteDimensional Filter
variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y]
/-- Hausdorff dimension of a set in an (e)metric space. -/
@[irreducible] noncomputable def dimH (s : Set X) : ℝ≥0∞ := by
borelize X; exact ⨆ (d : ℝ≥0) (_ : @hausdorffMeasure X _ _ ⟨rfl⟩ d s = ∞), d
set_option linter.uppercaseLean3 false in
#align dimH dimH
/-!
### Basic properties
-/
section Measurable
variable [MeasurableSpace X] [BorelSpace X]
/-- Unfold the definition of `dimH` using `[MeasurableSpace X] [BorelSpace X]` from the
environment. -/
theorem dimH_def (s : Set X) : dimH s = ⨆ (d : ℝ≥0) (_ : μH[d] s = ∞), (d : ℝ≥0∞) := by
borelize X; rw [dimH]
set_option linter.uppercaseLean3 false in
#align dimH_def dimH_def
theorem hausdorffMeasure_of_lt_dimH {s : Set X} {d : ℝ≥0} (h : ↑d < dimH s) : μH[d] s = ∞ := by
simp only [dimH_def, lt_iSup_iff] at h
rcases h with ⟨d', hsd', hdd'⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hdd'
exact top_unique (hsd' ▸ hausdorffMeasure_mono hdd'.le _)
set_option linter.uppercaseLean3 false in
#align hausdorff_measure_of_lt_dimH hausdorffMeasure_of_lt_dimH
theorem dimH_le {s : Set X} {d : ℝ≥0∞} (H : ∀ d' : ℝ≥0, μH[d'] s = ∞ → ↑d' ≤ d) : dimH s ≤ d :=
(dimH_def s).trans_le <| iSup₂_le H
set_option linter.uppercaseLean3 false in
#align dimH_le dimH_le
theorem dimH_le_of_hausdorffMeasure_ne_top {s : Set X} {d : ℝ≥0} (h : μH[d] s ≠ ∞) : dimH s ≤ d :=
le_of_not_lt <| mt hausdorffMeasure_of_lt_dimH h
set_option linter.uppercaseLean3 false in
#align dimH_le_of_hausdorff_measure_ne_top dimH_le_of_hausdorffMeasure_ne_top
theorem le_dimH_of_hausdorffMeasure_eq_top {s : Set X} {d : ℝ≥0} (h : μH[d] s = ∞) :
↑d ≤ dimH s := by
rw [dimH_def]; exact le_iSup₂ (α := ℝ≥0∞) d h
set_option linter.uppercaseLean3 false in
#align le_dimH_of_hausdorff_measure_eq_top le_dimH_of_hausdorffMeasure_eq_top
theorem hausdorffMeasure_of_dimH_lt {s : Set X} {d : ℝ≥0} (h : dimH s < d) : μH[d] s = 0 := by
rw [dimH_def] at h
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨d', hsd', hd'd⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hd'd
exact (hausdorffMeasure_zero_or_top hd'd s).resolve_right fun h₂ => hsd'.not_le <|
le_iSup₂ (α := ℝ≥0∞) d' h₂
set_option linter.uppercaseLean3 false in
#align hausdorff_measure_of_dimH_lt hausdorffMeasure_of_dimH_lt
theorem measure_zero_of_dimH_lt {μ : Measure X} {d : ℝ≥0} (h : μ ≪ μH[d]) {s : Set X}
(hd : dimH s < d) : μ s = 0 :=
h <| hausdorffMeasure_of_dimH_lt hd
set_option linter.uppercaseLean3 false in
#align measure_zero_of_dimH_lt measure_zero_of_dimH_lt
theorem le_dimH_of_hausdorffMeasure_ne_zero {s : Set X} {d : ℝ≥0} (h : μH[d] s ≠ 0) : ↑d ≤ dimH s :=
le_of_not_lt <| mt hausdorffMeasure_of_dimH_lt h
set_option linter.uppercaseLean3 false in
#align le_dimH_of_hausdorff_measure_ne_zero le_dimH_of_hausdorffMeasure_ne_zero
theorem dimH_of_hausdorffMeasure_ne_zero_ne_top {d : ℝ≥0} {s : Set X} (h : μH[d] s ≠ 0)
(h' : μH[d] s ≠ ∞) : dimH s = d :=
le_antisymm (dimH_le_of_hausdorffMeasure_ne_top h') (le_dimH_of_hausdorffMeasure_ne_zero h)
set_option linter.uppercaseLean3 false in
#align dimH_of_hausdorff_measure_ne_zero_ne_top dimH_of_hausdorffMeasure_ne_zero_ne_top
end Measurable
@[mono]
theorem dimH_mono {s t : Set X} (h : s ⊆ t) : dimH s ≤ dimH t := by
borelize X
exact dimH_le fun d hd => le_dimH_of_hausdorffMeasure_eq_top <| top_unique <| hd ▸ measure_mono h
set_option linter.uppercaseLean3 false in
#align dimH_mono dimH_mono
theorem dimH_subsingleton {s : Set X} (h : s.Subsingleton) : dimH s = 0 := by
borelize X
apply le_antisymm _ (zero_le _)
refine dimH_le_of_hausdorffMeasure_ne_top ?_
exact ((hausdorffMeasure_le_one_of_subsingleton h le_rfl).trans_lt ENNReal.one_lt_top).ne
set_option linter.uppercaseLean3 false in
#align dimH_subsingleton dimH_subsingleton
alias Set.Subsingleton.dimH_zero := dimH_subsingleton
set_option linter.uppercaseLean3 false in
#align set.subsingleton.dimH_zero Set.Subsingleton.dimH_zero
@[simp]
theorem dimH_empty : dimH (∅ : Set X) = 0 :=
subsingleton_empty.dimH_zero
set_option linter.uppercaseLean3 false in
#align dimH_empty dimH_empty
@[simp]
theorem dimH_singleton (x : X) : dimH ({x} : Set X) = 0 :=
subsingleton_singleton.dimH_zero
set_option linter.uppercaseLean3 false in
#align dimH_singleton dimH_singleton
@[simp]
theorem dimH_iUnion {ι : Sort*} [Countable ι] (s : ι → Set X) :
dimH (⋃ i, s i) = ⨆ i, dimH (s i) := by
borelize X
refine le_antisymm (dimH_le fun d hd => ?_) (iSup_le fun i => dimH_mono <| subset_iUnion _ _)
contrapose! hd
have : ∀ i, μH[d] (s i) = 0 := fun i =>
hausdorffMeasure_of_dimH_lt ((le_iSup (fun i => dimH (s i)) i).trans_lt hd)
rw [measure_iUnion_null this]
exact ENNReal.zero_ne_top
set_option linter.uppercaseLean3 false in
#align dimH_Union dimH_iUnion
@[simp]
theorem dimH_bUnion {s : Set ι} (hs : s.Countable) (t : ι → Set X) :
dimH (⋃ i ∈ s, t i) = ⨆ i ∈ s, dimH (t i) := by
haveI := hs.toEncodable
rw [biUnion_eq_iUnion, dimH_iUnion, ← iSup_subtype'']
set_option linter.uppercaseLean3 false in
#align dimH_bUnion dimH_bUnion
@[simp]
theorem dimH_sUnion {S : Set (Set X)} (hS : S.Countable) : dimH (⋃₀ S) = ⨆ s ∈ S, dimH s := by
rw [sUnion_eq_biUnion, dimH_bUnion hS]
set_option linter.uppercaseLean3 false in
#align dimH_sUnion dimH_sUnion
@[simp]
theorem dimH_union (s t : Set X) : dimH (s ∪ t) = max (dimH s) (dimH t) := by
rw [union_eq_iUnion, dimH_iUnion, iSup_bool_eq, cond, cond, ENNReal.sup_eq_max]
set_option linter.uppercaseLean3 false in
#align dimH_union dimH_union
theorem dimH_countable {s : Set X} (hs : s.Countable) : dimH s = 0 :=
biUnion_of_singleton s ▸ by simp only [dimH_bUnion hs, dimH_singleton, ENNReal.iSup_zero_eq_zero]
set_option linter.uppercaseLean3 false in
#align dimH_countable dimH_countable
alias Set.Countable.dimH_zero := dimH_countable
set_option linter.uppercaseLean3 false in
#align set.countable.dimH_zero Set.Countable.dimH_zero
theorem dimH_finite {s : Set X} (hs : s.Finite) : dimH s = 0 :=
hs.countable.dimH_zero
set_option linter.uppercaseLean3 false in
#align dimH_finite dimH_finite
alias Set.Finite.dimH_zero := dimH_finite
set_option linter.uppercaseLean3 false in
#align set.finite.dimH_zero Set.Finite.dimH_zero
@[simp]
theorem dimH_coe_finset (s : Finset X) : dimH (s : Set X) = 0 :=
s.finite_toSet.dimH_zero
set_option linter.uppercaseLean3 false in
#align dimH_coe_finset dimH_coe_finset
alias Finset.dimH_zero := dimH_coe_finset
set_option linter.uppercaseLean3 false in
#align finset.dimH_zero Finset.dimH_zero
/-!
### Hausdorff dimension as the supremum of local Hausdorff dimensions
-/
section
variable [SecondCountableTopology X]
/-- If `r` is less than the Hausdorff dimension of a set `s` in an (extended) metric space with
second countable topology, then there exists a point `x ∈ s` such that every neighborhood
`t` of `x` within `s` has Hausdorff dimension greater than `r`. -/
theorem exists_mem_nhdsWithin_lt_dimH_of_lt_dimH {s : Set X} {r : ℝ≥0∞} (h : r < dimH s) :
∃ x ∈ s, ∀ t ∈ 𝓝[s] x, r < dimH t := by
contrapose! h; choose! t htx htr using h
rcases countable_cover_nhdsWithin htx with ⟨S, hSs, hSc, hSU⟩
calc
dimH s ≤ dimH (⋃ x ∈ S, t x) := dimH_mono hSU
_ = ⨆ x ∈ S, dimH (t x) := dimH_bUnion hSc _
_ ≤ r := iSup₂_le fun x hx => htr x <| hSs hx
set_option linter.uppercaseLean3 false in
#align exists_mem_nhds_within_lt_dimH_of_lt_dimH exists_mem_nhdsWithin_lt_dimH_of_lt_dimH
/-- In an (extended) metric space with second countable topology, the Hausdorff dimension
of a set `s` is the supremum over `x ∈ s` of the limit superiors of `dimH t` along
`(𝓝[s] x).smallSets`. -/
| Mathlib/Topology/MetricSpace/HausdorffDimension.lean | 285 | 293 | theorem bsupr_limsup_dimH (s : Set X) : ⨆ x ∈ s, limsup dimH (𝓝[s] x).smallSets = dimH s := by |
refine le_antisymm (iSup₂_le fun x _ => ?_) ?_
· refine limsup_le_of_le isCobounded_le_of_bot ?_
exact eventually_smallSets.2 ⟨s, self_mem_nhdsWithin, fun t => dimH_mono⟩
· refine le_of_forall_ge_of_dense fun r hr => ?_
rcases exists_mem_nhdsWithin_lt_dimH_of_lt_dimH hr with ⟨x, hxs, hxr⟩
refine le_iSup₂_of_le x hxs ?_; rw [limsup_eq]; refine le_sInf fun b hb => ?_
rcases eventually_smallSets.1 hb with ⟨t, htx, ht⟩
exact (hxr t htx).le.trans (ht t Subset.rfl)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.