Context stringlengths 227 76.5k | target stringlengths 0 11.6k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 16 3.69k |
|---|---|---|---|---|
/-
Copyright (c) 2021 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Analysis.Convex.Cone.Basic
import Mathlib.Analysis.InnerProductSpace.Projection
/-!
# Convex cones in inner product spaces
We define `Set.innerDualCone` to be the cone consisting of all points `y` such that for
all points `x` in a given set `0 ≤ ⟪ x, y ⟫`.
## Main statements
We prove the following theorems:
* `ConvexCone.innerDualCone_of_innerDualCone_eq_self`:
The `innerDualCone` of the `innerDualCone` of a nonempty, closed, convex cone is itself.
* `ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`:
This variant of the
[hyperplane separation theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem)
states that given a nonempty, closed, convex cone `K` in a complete, real inner product space `H`
and a point `b` disjoint from it, there is a vector `y` which separates `b` from `K` in the sense
that for all points `x` in `K`, `0 ≤ ⟪x, y⟫_ℝ` and `⟪y, b⟫_ℝ < 0`. This is also a geometric
interpretation of the
[Farkas lemma](https://en.wikipedia.org/wiki/Farkas%27_lemma#Geometric_interpretation).
-/
open Set LinearMap Pointwise
/-! ### The dual cone -/
section Dual
variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] (s t : Set H)
open RealInnerProductSpace
/-- The dual cone is the cone consisting of all points `y` such that for
all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. -/
def Set.innerDualCone (s : Set H) : ConvexCone ℝ H where
carrier := { y | ∀ x ∈ s, 0 ≤ ⟪x, y⟫ }
smul_mem' c hc y hy x hx := by
rw [real_inner_smul_right]
exact mul_nonneg hc.le (hy x hx)
add_mem' u hu v hv x hx := by
rw [inner_add_right]
exact add_nonneg (hu x hx) (hv x hx)
@[simp]
theorem mem_innerDualCone (y : H) (s : Set H) : y ∈ s.innerDualCone ↔ ∀ x ∈ s, 0 ≤ ⟪x, y⟫ :=
Iff.rfl
@[simp]
theorem innerDualCone_empty : (∅ : Set H).innerDualCone = ⊤ :=
eq_top_iff.mpr fun _ _ _ => False.elim
/-- Dual cone of the convex cone {0} is the total space. -/
@[simp]
theorem innerDualCone_zero : (0 : Set H).innerDualCone = ⊤ :=
eq_top_iff.mpr fun _ _ y (hy : y = 0) => hy.symm ▸ (inner_zero_left _).ge
/-- Dual cone of the total space is the convex cone {0}. -/
@[simp]
theorem innerDualCone_univ : (univ : Set H).innerDualCone = 0 := by
suffices ∀ x : H, x ∈ (univ : Set H).innerDualCone → x = 0 by
apply SetLike.coe_injective
exact eq_singleton_iff_unique_mem.mpr ⟨fun x _ => (inner_zero_right _).ge, this⟩
exact fun x hx => by simpa [← real_inner_self_nonpos] using hx (-x) (mem_univ _)
variable {s t} in
@[gcongr]
theorem innerDualCone_le_innerDualCone (h : t ⊆ s) : s.innerDualCone ≤ t.innerDualCone :=
fun _ hy x hx => hy x (h hx)
theorem pointed_innerDualCone : s.innerDualCone.Pointed := fun x _ => by rw [inner_zero_right]
/-- The inner dual cone of a singleton is given by the preimage of the positive cone under the
linear map `fun y ↦ ⟪x, y⟫`. -/
theorem innerDualCone_singleton (x : H) :
({x} : Set H).innerDualCone = (ConvexCone.positive ℝ ℝ).comap (innerₛₗ ℝ x) :=
ConvexCone.ext fun _ => forall_eq
theorem innerDualCone_union (s t : Set H) :
(s ∪ t).innerDualCone = s.innerDualCone ⊓ t.innerDualCone :=
le_antisymm (le_inf (fun _ hx _ hy => hx _ <| Or.inl hy) fun _ hx _ hy => hx _ <| Or.inr hy)
fun _ hx _ => Or.rec (hx.1 _) (hx.2 _)
theorem innerDualCone_insert (x : H) (s : Set H) :
(insert x s).innerDualCone = Set.innerDualCone {x} ⊓ s.innerDualCone := by
rw [insert_eq, innerDualCone_union]
theorem innerDualCone_iUnion {ι : Sort*} (f : ι → Set H) :
(⋃ i, f i).innerDualCone = ⨅ i, (f i).innerDualCone := by
refine le_antisymm (le_iInf fun i x hx y hy => hx _ <| mem_iUnion_of_mem _ hy) ?_
intro x hx y hy
rw [ConvexCone.mem_iInf] at hx
obtain ⟨j, hj⟩ := mem_iUnion.mp hy
exact hx _ _ hj
theorem innerDualCone_sUnion (S : Set (Set H)) :
(⋃₀ S).innerDualCone = sInf (Set.innerDualCone '' S) := by
simp_rw [sInf_image, sUnion_eq_biUnion, innerDualCone_iUnion]
/-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/
theorem innerDualCone_eq_iInter_innerDualCone_singleton :
(s.innerDualCone : Set H) = ⋂ i : s, (({↑i} : Set H).innerDualCone : Set H) := by
| rw [← ConvexCone.coe_iInf, ← innerDualCone_iUnion, iUnion_of_singleton_coe]
theorem isClosed_innerDualCone : IsClosed (s.innerDualCone : Set H) := by
-- reduce the problem to showing that dual cone of a singleton `{x}` is closed
rw [innerDualCone_eq_iInter_innerDualCone_singleton]
apply isClosed_iInter
intro x
| Mathlib/Analysis/Convex/Cone/InnerDual.lean | 110 | 116 |
/-
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.Bochner.Basic
import Mathlib.MeasureTheory.Integral.Bochner.L1
import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/Bochner.lean | 1,901 | 1,916 | |
/-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Module.LocalizedModule.Submodule
import Mathlib.LinearAlgebra.Dimension.DivisionRing
import Mathlib.RingTheory.IsTensorProduct
import Mathlib.RingTheory.Localization.BaseChange
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.OreLocalization.OreSet
/-!
# Rank of localization
## Main statements
- `IsLocalizedModule.lift_rank_eq`: `rank_Rₚ Mₚ = rank R M`.
- `rank_quotient_add_rank_of_isDomain`: The **rank-nullity theorem** for commutative domains.
-/
open Cardinal Module nonZeroDivisors
section CommRing
universe uR uS uT uM uN uP
variable {R : Type uR} (S : Type uS) {M : Type uM} {N : Type uN}
variable [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N] [Algebra R S] [Module S N] [IsScalarTower R S N]
variable (p : Submonoid R) [IsLocalization p S] (f : M →ₗ[R] N) [IsLocalizedModule p f]
variable (hp : p ≤ R⁰)
section
include hp
section
include f
lemma IsLocalizedModule.lift_rank_eq :
Cardinal.lift.{uM} (Module.rank R N) = Cardinal.lift.{uN} (Module.rank R M) := by
cases subsingleton_or_nontrivial R
· simp only [rank_subsingleton, lift_one]
apply le_antisymm <;>
rw [Module.rank_def, lift_iSup (bddAbove_range _)] <;>
apply ciSup_le' <;>
intro ⟨s, hs⟩
exacts [(IsLocalizedModule.linearIndependent_lift p f hs).choose_spec.cardinal_lift_le_rank,
hs.of_isLocalizedModule_of_isRegular p f (le_nonZeroDivisors_iff_isRegular.mp hp)
|>.cardinal_lift_le_rank]
lemma IsLocalizedModule.finrank_eq : finrank R N = finrank R M := by
simpa using congr_arg toNat (lift_rank_eq p f hp)
end
lemma IsLocalizedModule.rank_eq {N : Type uM} [AddCommGroup N] [Module R N] (f : M →ₗ[R] N)
[IsLocalizedModule p f] : Module.rank R N = Module.rank R M := by
simpa using lift_rank_eq p f hp
lemma IsLocalization.rank_eq : Module.rank S N = Module.rank R N := by
cases subsingleton_or_nontrivial R
· have := (algebraMap R S).codomain_trivial; simp only [rank_subsingleton, lift_one]
have inj := IsLocalization.injective S hp
apply le_antisymm <;> (rw [Module.rank]; apply ciSup_le'; intro ⟨s, hs⟩)
· have := (faithfulSMul_iff_algebraMap_injective R S).mpr inj
exact (hs.restrict_scalars' R).cardinal_le_rank
· have := inj.nontrivial
exact (hs.localization S p).cardinal_le_rank
end
variable (R M) in
theorem exists_set_linearIndependent_of_isDomain [IsDomain R] :
∃ s : Set M, #s = Module.rank R M ∧ LinearIndepOn R id s := by
obtain ⟨w, hw⟩ :=
IsLocalizedModule.linearIndependent_lift R⁰ (LocalizedModule.mkLinearMap R⁰ M) <|
Module.Free.chooseBasis (FractionRing R) (LocalizedModule R⁰ M)
|>.linearIndependent.restrict_scalars' _
refine ⟨Set.range w, ?_, (linearIndepOn_id_range_iff hw.injective).mpr hw⟩
apply Cardinal.lift_injective.{max uR uM}
rw [Cardinal.mk_range_eq_of_injective hw.injective, ← Module.Free.rank_eq_card_chooseBasisIndex,
IsLocalization.rank_eq (FractionRing R) R⁰ le_rfl,
IsLocalizedModule.lift_rank_eq R⁰ (LocalizedModule.mkLinearMap R⁰ M) le_rfl]
|
/-- The **rank-nullity theorem** for commutative domains. Also see `rank_quotient_add_rank`. -/
theorem rank_quotient_add_rank_of_isDomain [IsDomain R] (M' : Submodule R M) :
Module.rank R (M ⧸ M') + Module.rank R M' = Module.rank R M := by
apply lift_injective.{max uR uM}
simp_rw [lift_add, ← IsLocalizedModule.lift_rank_eq R⁰ (M'.toLocalized R⁰) le_rfl,
← IsLocalizedModule.lift_rank_eq R⁰ (LocalizedModule.mkLinearMap R⁰ M) le_rfl,
← IsLocalizedModule.lift_rank_eq R⁰ (M'.toLocalizedQuotient R⁰) le_rfl,
← IsLocalization.rank_eq (FractionRing R) R⁰ le_rfl,
| Mathlib/LinearAlgebra/Dimension/Localization.lean | 85 | 93 |
/-
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.MeasureTheory.Measure.Decomposition.RadonNikodym
/-!
# Exponentially tilted measures
The exponential tilting of a measure `μ` on `α` by a function `f : α → ℝ` is the measure with
density `x ↦ exp (f x) / ∫ y, exp (f y) ∂μ` with respect to `μ`. This is sometimes also called
the Esscher transform.
The definition is mostly used for `f` linear, in which case the exponentially tilted measure belongs
to the natural exponential family of the base measure. Exponentially tilted measures for general `f`
can be used for example to establish variational expressions for the Kullback-Leibler divergence.
## Main definitions
* `Measure.tilted μ f`: exponential tilting of `μ` by `f`, equal to
`μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ))`.
-/
open Real
open scoped ENNReal NNReal
namespace MeasureTheory
variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} {f : α → ℝ}
/-- Exponentially tilted measure. When `x ↦ exp (f x)` is integrable, `μ.tilted f` is the
probability measure with density with respect to `μ` proportional to `exp (f x)`. Otherwise it is 0.
-/
noncomputable
def Measure.tilted (μ : Measure α) (f : α → ℝ) : Measure α :=
μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ))
@[simp]
lemma tilted_of_not_integrable (hf : ¬ Integrable (fun x ↦ exp (f x)) μ) : μ.tilted f = 0 := by
rw [Measure.tilted, integral_undef hf]
simp
@[simp]
lemma tilted_of_not_aemeasurable (hf : ¬ AEMeasurable f μ) : μ.tilted f = 0 := by
refine tilted_of_not_integrable ?_
suffices ¬ AEMeasurable (fun x ↦ exp (f x)) μ by exact fun h ↦ this h.1.aemeasurable
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h)
@[simp]
lemma tilted_zero_measure (f : α → ℝ) : (0 : Measure α).tilted f = 0 := by simp [Measure.tilted]
@[simp]
lemma tilted_const' (μ : Measure α) (c : ℝ) :
μ.tilted (fun _ ↦ c) = (μ Set.univ)⁻¹ • μ := by
cases eq_zero_or_neZero μ with
| inl h => rw [h]; simp
| inr h0 =>
simp only [Measure.tilted, withDensity_const, integral_const, smul_eq_mul]
by_cases h_univ : μ Set.univ = ∞
· simp only [measureReal_def, h_univ, ENNReal.toReal_top, zero_mul, div_zero,
ENNReal.ofReal_zero, zero_smul, ENNReal.inv_top]
congr
rw [div_eq_mul_inv, mul_inv, mul_comm, mul_assoc, inv_mul_cancel₀ (exp_pos _).ne', mul_one,
measureReal_def, ← ENNReal.toReal_inv, ENNReal.ofReal_toReal]
simp [h0.out]
lemma tilted_const (μ : Measure α) [IsProbabilityMeasure μ] (c : ℝ) :
μ.tilted (fun _ ↦ c) = μ := by simp
@[simp]
lemma tilted_zero' (μ : Measure α) : μ.tilted 0 = (μ Set.univ)⁻¹ • μ := by
change μ.tilted (fun _ ↦ 0) = (μ Set.univ)⁻¹ • μ
simp
lemma tilted_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ.tilted 0 = μ := by simp
lemma tilted_congr {g : α → ℝ} (hfg : f =ᵐ[μ] g) :
μ.tilted f = μ.tilted g := by
have h_int_eq : ∫ x, exp (f x) ∂μ = ∫ x, exp (g x) ∂μ := by
refine integral_congr_ae ?_
filter_upwards [hfg] with x hx
rw [hx]
refine withDensity_congr_ae ?_
filter_upwards [hfg] with x hx
rw [h_int_eq, hx]
lemma tilted_eq_withDensity_nnreal (μ : Measure α) (f : α → ℝ) :
μ.tilted f = μ.withDensity (fun x ↦ ((↑) : ℝ≥0 → ℝ≥0∞)
(⟨exp (f x) / ∫ x, exp (f x) ∂μ, by positivity⟩ : ℝ≥0)) := by
rw [Measure.tilted]
congr with x
rw [ENNReal.ofReal_eq_coe_nnreal]
lemma tilted_apply' (μ : Measure α) (f : α → ℝ) {s : Set α} (hs : MeasurableSet s) :
μ.tilted f s = ∫⁻ a in s, ENNReal.ofReal (exp (f a) / ∫ x, exp (f x) ∂μ) ∂μ := by
rw [Measure.tilted, withDensity_apply _ hs]
lemma tilted_apply (μ : Measure α) [SFinite μ] (f : α → ℝ) (s : Set α) :
μ.tilted f s = ∫⁻ a in s, ENNReal.ofReal (exp (f a) / ∫ x, exp (f x) ∂μ) ∂μ := by
rw [Measure.tilted, withDensity_apply' _ s]
lemma tilted_apply_eq_ofReal_integral' {s : Set α} (f : α → ℝ) (hs : MeasurableSet s) :
μ.tilted f s = ENNReal.ofReal (∫ a in s, exp (f a) / ∫ x, exp (f x) ∂μ ∂μ) := by
by_cases hf : Integrable (fun x ↦ exp (f x)) μ
· rw [tilted_apply' _ _ hs, ← ofReal_integral_eq_lintegral_ofReal]
· exact hf.integrableOn.div_const _
· exact ae_of_all _ (fun _ ↦ by positivity)
· simp only [hf, not_false_eq_true, tilted_of_not_integrable, Measure.coe_zero,
Pi.zero_apply, integral_undef hf, div_zero, integral_zero, ENNReal.ofReal_zero]
lemma tilted_apply_eq_ofReal_integral [SFinite μ] (f : α → ℝ) (s : Set α) :
μ.tilted f s = ENNReal.ofReal (∫ a in s, exp (f a) / ∫ x, exp (f x) ∂μ ∂μ) := by
by_cases hf : Integrable (fun x ↦ exp (f x)) μ
· rw [tilted_apply _ _, ← ofReal_integral_eq_lintegral_ofReal]
· exact hf.integrableOn.div_const _
· exact ae_of_all _ (fun _ ↦ by positivity)
· simp [tilted_of_not_integrable hf, integral_undef hf]
lemma isProbabilityMeasure_tilted [NeZero μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
IsProbabilityMeasure (μ.tilted f) := by
constructor
simp_rw [tilted_apply' _ _ MeasurableSet.univ, setLIntegral_univ,
ENNReal.ofReal_div_of_pos (integral_exp_pos hf), div_eq_mul_inv]
rw [lintegral_mul_const'' _ hf.1.aemeasurable.ennreal_ofReal,
← ofReal_integral_eq_lintegral_ofReal hf (ae_of_all _ fun _ ↦ (exp_pos _).le),
ENNReal.mul_inv_cancel]
· simp only [ne_eq, ENNReal.ofReal_eq_zero, not_le]
exact integral_exp_pos hf
· simp
instance isZeroOrProbabilityMeasure_tilted : IsZeroOrProbabilityMeasure (μ.tilted f) := by
rcases eq_zero_or_neZero μ with hμ | hμ
· simp only [hμ, tilted_zero_measure]
infer_instance
by_cases hf : Integrable (fun x ↦ exp (f x)) μ
· have := isProbabilityMeasure_tilted hf
infer_instance
· simp only [hf, not_false_eq_true, tilted_of_not_integrable]
infer_instance
section lintegral
lemma setLIntegral_tilted' (f : α → ℝ) (g : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) :
∫⁻ x in s, g x ∂(μ.tilted f)
= ∫⁻ x in s, ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) * g x ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [Measure.tilted, setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀]
· simp only [Pi.mul_apply]
· refine AEMeasurable.restrict ?_
exact ((measurable_exp.comp_aemeasurable hf).div_const _).ennreal_ofReal
· exact hs
· filter_upwards
simp only [ENNReal.ofReal_lt_top, implies_true]
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
lintegral_zero_measure]
rw [integral_undef hf']
simp
lemma setLIntegral_tilted [SFinite μ] (f : α → ℝ) (g : α → ℝ≥0∞) (s : Set α) :
∫⁻ x in s, g x ∂(μ.tilted f)
= ∫⁻ x in s, ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) * g x ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [Measure.tilted, setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀']
· simp only [Pi.mul_apply]
· refine AEMeasurable.restrict ?_
exact ((measurable_exp.comp_aemeasurable hf).div_const _).ennreal_ofReal
· filter_upwards
simp only [ENNReal.ofReal_lt_top, implies_true]
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
lintegral_zero_measure]
rw [integral_undef hf']
simp
lemma lintegral_tilted (f : α → ℝ) (g : α → ℝ≥0∞) :
∫⁻ x, g x ∂(μ.tilted f)
= ∫⁻ x, ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) * (g x) ∂μ := by
rw [← setLIntegral_univ, setLIntegral_tilted' f g MeasurableSet.univ, setLIntegral_univ]
end lintegral
section integral
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
lemma setIntegral_tilted' (f : α → ℝ) (g : α → E) {s : Set α} (hs : MeasurableSet s) :
∫ x in s, g x ∂(μ.tilted f) = ∫ x in s, (exp (f x) / ∫ x, exp (f x) ∂μ) • (g x) ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [tilted_eq_withDensity_nnreal, setIntegral_withDensity_eq_setIntegral_smul₀ _ _ hs]
· congr
· suffices AEMeasurable (fun x ↦ exp (f x) / ∫ x, exp (f x) ∂μ) μ by
rw [← aemeasurable_coe_nnreal_real_iff]
refine AEMeasurable.restrict ?_
simpa only [NNReal.coe_mk]
exact (measurable_exp.comp_aemeasurable hf).div_const _
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
integral_zero_measure]
rw [integral_undef hf']
simp
lemma setIntegral_tilted [SFinite μ] (f : α → ℝ) (g : α → E) (s : Set α) :
∫ x in s, g x ∂(μ.tilted f) = ∫ x in s, (exp (f x) / ∫ x, exp (f x) ∂μ) • (g x) ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [tilted_eq_withDensity_nnreal, setIntegral_withDensity_eq_setIntegral_smul₀']
· congr
· suffices AEMeasurable (fun x ↦ exp (f x) / ∫ x, exp (f x) ∂μ) μ by
rw [← aemeasurable_coe_nnreal_real_iff]
refine AEMeasurable.restrict ?_
simpa only [NNReal.coe_mk]
exact (measurable_exp.comp_aemeasurable hf).div_const _
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
integral_zero_measure]
rw [integral_undef hf']
simp
lemma integral_tilted (f : α → ℝ) (g : α → E) :
∫ x, g x ∂(μ.tilted f) = ∫ x, (exp (f x) / ∫ x, exp (f x) ∂μ) • (g x) ∂μ := by
rw [← setIntegral_univ, setIntegral_tilted' f g MeasurableSet.univ, setIntegral_univ]
end integral
lemma integral_exp_tilted (f g : α → ℝ) :
∫ x, exp (g x) ∂(μ.tilted f) = (∫ x, exp ((f + g) x) ∂μ) / ∫ x, exp (f x) ∂μ := by
cases eq_zero_or_neZero μ with
| inl h => rw [h]; simp
| inr h0 =>
rw [integral_tilted f]
simp_rw [smul_eq_mul]
have : ∀ x, (exp (f x) / ∫ x, exp (f x) ∂μ) * exp (g x)
= (exp ((f + g) x) / ∫ x, exp (f x) ∂μ) := by
intro x
rw [Pi.add_apply, exp_add]
ring
simp_rw [this, div_eq_mul_inv]
rw [integral_mul_const]
lemma tilted_tilted (hf : Integrable (fun x ↦ exp (f x)) μ) (g : α → ℝ) :
(μ.tilted f).tilted g = μ.tilted (f + g) := by
cases eq_zero_or_neZero μ with
| inl h => simp [h]
| inr h0 =>
ext1 s hs
rw [tilted_apply' _ _ hs, tilted_apply' _ _ hs, setLIntegral_tilted' f _ hs]
congr with x
rw [← ENNReal.ofReal_mul (by positivity),
integral_exp_tilted f, Pi.add_apply, exp_add]
congr 1
simp only [Pi.add_apply]
field_simp
ring_nf
congr 1
rw [mul_assoc, mul_inv_cancel₀, mul_one]
exact (integral_exp_pos hf).ne'
lemma tilted_comm (hf : Integrable (fun x ↦ exp (f x)) μ) {g : α → ℝ}
(hg : Integrable (fun x ↦ exp (g x)) μ) :
(μ.tilted f).tilted g = (μ.tilted g).tilted f := by
rw [tilted_tilted hf, add_comm, tilted_tilted hg]
@[simp]
lemma tilted_neg_same' (hf : Integrable (fun x ↦ exp (f x)) μ) :
(μ.tilted f).tilted (-f) = (μ Set.univ)⁻¹ • μ := by
rw [tilted_tilted hf]; simp
@[simp]
lemma tilted_neg_same [IsProbabilityMeasure μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
(μ.tilted f).tilted (-f) = μ := by
simp [hf]
lemma tilted_absolutelyContinuous (μ : Measure α) (f : α → ℝ) : μ.tilted f ≪ μ :=
withDensity_absolutelyContinuous _ _
lemma absolutelyContinuous_tilted (hf : Integrable (fun x ↦ exp (f x)) μ) : μ ≪ μ.tilted f := by
cases eq_zero_or_neZero μ with
| inl h => simp only [h, tilted_zero_measure]; exact fun _ _ ↦ by simp
| inr h0 =>
refine withDensity_absolutelyContinuous' ?_ ?_
· exact (hf.1.aemeasurable.div_const _).ennreal_ofReal
· filter_upwards
simp only [ne_eq, ENNReal.ofReal_eq_zero, not_le]
exact fun _ ↦ div_pos (exp_pos _) (integral_exp_pos hf)
lemma integrable_tilted_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
{f : α → ℝ} (hf : Integrable (fun x ↦ exp (f x)) μ) (g : α → E) :
Integrable g (μ.tilted f) ↔ Integrable (fun x ↦ exp (f x) • g x) μ := by
by_cases hμ : μ = 0
· simp [hμ]
have hf_meas : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
rw [Measure.tilted, integrable_withDensity_iff_integrable_smul₀' (by fun_prop) (by simp)]
calc Integrable (fun x ↦ (ENNReal.ofReal (exp (f x) / ∫ a, exp (f a) ∂μ)).toReal • g x) μ
_ ↔ Integrable (fun x ↦ (exp (f x) / ∫ a, exp (f a) ∂μ) • g x) μ := by
congr! with a
rw [ENNReal.toReal_ofReal]
positivity
_ ↔ Integrable (fun x ↦ (∫ a, exp (f a) ∂μ)⁻¹ • exp (f x) • g x) μ := by
congr! 2 with a
rw [smul_smul, div_eq_inv_mul]
_ ↔ Integrable (fun x ↦ exp (f x) • g x) μ := by
rw [integrable_fun_smul_iff]
simp only [ne_eq, inv_eq_zero]
have : NeZero μ := ⟨hμ⟩
exact (integral_exp_pos hf).ne'
lemma rnDeriv_tilted_right (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν]
(hf : Integrable (fun x ↦ exp (f x)) ν) :
μ.rnDeriv (ν.tilted f)
=ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (- f x) * ∫ x, exp (f x) ∂ν) * μ.rnDeriv ν x := by
cases eq_zero_or_neZero ν with
| inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
| inr h0 =>
refine (Measure.rnDeriv_withDensity_right μ ν ?_ ?_ ?_).trans ?_
· exact (hf.1.aemeasurable.div_const _).ennreal_ofReal
· filter_upwards
simp only [ne_eq, ENNReal.ofReal_eq_zero, not_le]
exact fun _ ↦ div_pos (exp_pos _) (integral_exp_pos hf)
· refine ae_of_all _ (by simp)
· filter_upwards with x
congr
rw [← ENNReal.ofReal_inv_of_pos, inv_div', ← exp_neg, div_eq_mul_inv, inv_inv]
exact div_pos (exp_pos _) (integral_exp_pos hf)
lemma toReal_rnDeriv_tilted_right (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν]
(hf : Integrable (fun x ↦ exp (f x)) ν) :
(fun x ↦ (μ.rnDeriv (ν.tilted f) x).toReal)
=ᵐ[ν] fun x ↦ exp (- f x) * (∫ x, exp (f x) ∂ν) * (μ.rnDeriv ν x).toReal := by
filter_upwards [rnDeriv_tilted_right μ ν hf] with x hx
rw [hx]
simp only [ENNReal.toReal_mul, gt_iff_lt, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff]
exact Or.inl (by positivity)
variable (μ) in
lemma rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν] (hfν : AEMeasurable f ν) :
(μ.tilted f).rnDeriv ν
=ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ)) * μ.rnDeriv ν x := by
let g := fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ))
refine Measure.rnDeriv_withDensity_left (μ := μ) (ν := ν) (f := g) ?_ ?_
· exact ((measurable_exp.comp_aemeasurable hfν).div_const _).ennreal_ofReal
· exact ae_of_all _ (fun x ↦ by simp [g])
|
variable (μ) in
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
(hfν : AEMeasurable f ν) :
(fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
| Mathlib/MeasureTheory/Measure/Tilted.lean | 349 | 353 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky
-/
import Mathlib.Data.Fintype.Card
import Mathlib.Algebra.Group.Commute.Basic
import Mathlib.Algebra.Group.End
import Mathlib.Data.Finset.NoncommProd
/-!
# support of a permutation
## Main definitions
In the following, `f g : Equiv.Perm α`.
* `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed
either by `f`, or by `g`.
Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint.
* `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`.
* `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`.
Assume `α` is a Fintype:
* `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has
strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`.
(Equivalently, `f.support` has at least 2 elements.)
-/
open Equiv Finset Function
namespace Equiv.Perm
variable {α : Type*}
section Disjoint
/-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e.,
every element is fixed either by `f`, or by `g`. -/
def Disjoint (f g : Perm α) :=
∀ x, f x = x ∨ g x = x
variable {f g h : Perm α}
@[symm]
theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self]
theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm
instance : IsSymm (Perm α) Disjoint :=
⟨Disjoint.symmetric⟩
theorem disjoint_comm : Disjoint f g ↔ Disjoint g f :=
⟨Disjoint.symm, Disjoint.symm⟩
theorem Disjoint.commute (h : Disjoint f g) : Commute f g :=
Equiv.ext fun x =>
(h x).elim
(fun hf =>
(h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by
simp [mul_apply, hf, g.injective hg])
fun hg =>
(h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by
simp [mul_apply, hf, hg]
@[simp]
theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl
@[simp]
theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl
theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x :=
Iff.rfl
@[simp]
theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩
ext x
rcases h x with hx | hx <;> simp [hx]
theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by
intro x
rw [inv_eq_iff_eq, eq_comm]
exact h x
theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ :=
h.symm.inv_left.symm
@[simp]
theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by
refine ⟨fun h => ?_, Disjoint.inv_left⟩
convert h.inv_left
@[simp]
theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by
rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm]
theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x =>
by cases H1 x <;> cases H2 x <;> simp [*]
theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by
rw [disjoint_comm]
exact H1.symm.mul_left H2.symm
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it `@[simp]`
theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g :=
(h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq]
theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) :=
(disjoint_conj h).2 H
theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) :
Disjoint f l.prod := by
induction' l with g l ih
· exact disjoint_one_right _
· rw [List.prod_cons]
exact (h _ List.mem_cons_self).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg))
theorem disjoint_noncommProd_right {ι : Type*} {k : ι → Perm α} {s : Finset ι}
(hs : Set.Pairwise s fun i j ↦ Commute (k i) (k j))
(hg : ∀ i ∈ s, g.Disjoint (k i)) :
Disjoint g (s.noncommProd k (hs)) :=
noncommProd_induction s k hs g.Disjoint (fun _ _ ↦ Disjoint.mul_right) (disjoint_one_right g) hg
open scoped List in
theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) :
l₁.prod = l₂.prod :=
hp.prod_eq' <| hl.imp Disjoint.commute
theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l)
(h2 : l.Pairwise Disjoint) : l.Nodup := by
refine List.Pairwise.imp_of_mem ?_ h2
intro τ σ h_mem _ h_disjoint _
subst τ
suffices (σ : Perm α) = 1 by
rw [this] at h_mem
exact h1 h_mem
exact ext fun a => or_self_iff.mp (h_disjoint a)
theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x
| 0 => rfl
| n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n]
theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x
| (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n
| Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx]
theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x
| 0 => Or.inl rfl
| n + 1 =>
(pow_apply_eq_of_apply_apply_eq_self hffx n).elim
(fun h => Or.inr (by rw [pow_succ', mul_apply, h]))
fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx])
theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x
| (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n
| Int.negSucc n => by
rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm,
inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm]
exact pow_apply_eq_of_apply_apply_eq_self hffx _
theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} :
(σ * τ) a = a ↔ σ a = a ∧ τ a = a := by
refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩
rcases hστ a with hσ | hτ
· exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩
· exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩
theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) :
σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by
simp_rw [Perm.ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and]
theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) :
Disjoint (σ ^ m) (τ ^ n) := fun x =>
Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m)
(fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x)
theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) :
Disjoint (σ ^ m) (τ ^ n) :=
hστ.zpow_disjoint_zpow m n
end Disjoint
section IsSwap
variable [DecidableEq α]
/-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/
def IsSwap (f : Perm α) : Prop :=
∃ x y, x ≠ y ∧ f = swap x y
@[simp]
theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) :
ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y :=
Equiv.ext fun z => by
by_cases hz : p z
· rw [swap_apply_def, ofSubtype_apply_of_mem _ hz]
split_ifs with hzx hzy
· simp_rw [hzx, Subtype.coe_eta, swap_apply_left]
· simp_rw [hzy, Subtype.coe_eta, swap_apply_right]
· rw [swap_apply_of_ne_of_ne] <;>
simp [Subtype.ext_iff, *]
· rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne]
· intro h
apply hz
rw [h]
exact Subtype.prop x
intro h
apply hz
rw [h]
exact Subtype.prop y
theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)}
(h : f.IsSwap) : (ofSubtype f).IsSwap :=
let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h
⟨x, y, by
simp only [Ne, Subtype.ext_iff] at hxy
exact hxy.1, by
rw [hxy.2, ofSubtype_swap_eq]⟩
theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) :
f y ≠ y ∧ y ≠ x := by
simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at *
by_cases h : f y = x
· constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne]
· split_ifs at hy with h <;> try { simp [*] at * }
end IsSwap
section support
section Set
variable (p q : Perm α)
theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by
ext x
simp only [Set.mem_setOf_eq, Ne]
rw [inv_def, symm_apply_eq, eq_comm]
theorem set_support_apply_mem {p : Perm α} {a : α} :
p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp
theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by
intro x
simp only [Set.mem_setOf_eq, Ne]
intro hx H
simp [zpow_apply_eq_self_of_apply_eq_self H] at hx
theorem set_support_mul_subset : { x | (p * q) x ≠ x } ⊆ { x | p x ≠ x } ∪ { x | q x ≠ x } := by
intro x
simp only [Perm.coe_mul, Function.comp_apply, Ne, Set.mem_union, Set.mem_setOf_eq]
by_cases hq : q x = x <;> simp [hq]
end Set
@[simp]
theorem apply_pow_apply_eq_iff (f : Perm α) (n : ℕ) {x : α} :
f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by
rw [← mul_apply, Commute.self_pow f, mul_apply, apply_eq_iff_eq]
@[simp]
theorem apply_zpow_apply_eq_iff (f : Perm α) (n : ℤ) {x : α} :
f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by
rw [← mul_apply, Commute.self_zpow f, mul_apply, apply_eq_iff_eq]
variable [DecidableEq α] [Fintype α] {f g : Perm α}
/-- The `Finset` of nonfixed points of a permutation. -/
def support (f : Perm α) : Finset α := {x | f x ≠ x}
@[simp]
theorem mem_support {x : α} : x ∈ f.support ↔ f x ≠ x := by
rw [support, mem_filter, and_iff_right (mem_univ x)]
theorem not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp
theorem coe_support_eq_set_support (f : Perm α) : (f.support : Set α) = { x | f x ≠ x } := by
ext
simp
@[simp]
theorem support_eq_empty_iff {σ : Perm α} : σ.support = ∅ ↔ σ = 1 := by
simp_rw [Finset.ext_iff, mem_support, Finset.not_mem_empty, iff_false, not_not,
Equiv.Perm.ext_iff, one_apply]
@[simp]
theorem support_one : (1 : Perm α).support = ∅ := by rw [support_eq_empty_iff]
@[simp]
theorem support_refl : support (Equiv.refl α) = ∅ :=
support_one
theorem support_congr (h : f.support ⊆ g.support) (h' : ∀ x ∈ g.support, f x = g x) : f = g := by
ext x
by_cases hx : x ∈ g.support
· exact h' x hx
· rw [not_mem_support.mp hx, ← not_mem_support]
exact fun H => hx (h H)
/-- If g and c commute, then g stabilizes the support of c -/
theorem mem_support_iff_of_commute {g c : Perm α} (hgc : Commute g c) (x : α) :
x ∈ c.support ↔ g x ∈ c.support := by
simp only [mem_support, not_iff_not, ← mul_apply]
rw [← hgc, mul_apply, Equiv.apply_eq_iff_eq]
theorem support_mul_le (f g : Perm α) : (f * g).support ≤ f.support ⊔ g.support := fun x => by
simp only [sup_eq_union]
rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not]
rintro ⟨hf, hg⟩
rw [hg, hf]
theorem exists_mem_support_of_mem_support_prod {l : List (Perm α)} {x : α}
(hx : x ∈ l.prod.support) : ∃ f : Perm α, f ∈ l ∧ x ∈ f.support := by
contrapose! hx
simp_rw [mem_support, not_not] at hx ⊢
induction' l with f l ih
· rfl
· rw [List.prod_cons, mul_apply, ih, hx]
· simp only [List.find?, List.mem_cons, true_or]
intros f' hf'
refine hx f' ?_
simp only [List.find?, List.mem_cons]
exact Or.inr hf'
theorem support_pow_le (σ : Perm α) (n : ℕ) : (σ ^ n).support ≤ σ.support := fun _ h1 =>
mem_support.mpr fun h2 => mem_support.mp h1 (pow_apply_eq_self_of_apply_eq_self h2 n)
@[simp]
theorem support_inv (σ : Perm α) : support σ⁻¹ = σ.support := by
simp_rw [Finset.ext_iff, mem_support, not_iff_not, inv_eq_iff_eq.trans eq_comm, imp_true_iff]
theorem apply_mem_support {x : α} : f x ∈ f.support ↔ x ∈ f.support := by
rw [mem_support, mem_support, Ne, Ne, apply_eq_iff_eq]
/-- The support of a permutation is invariant -/
theorem isInvariant_of_support_le {c : Perm α} {s : Finset α} (hcs : c.support ≤ s) (x : α) :
x ∈ s ↔ c x ∈ s := by
by_cases hx' : x ∈ c.support
· simp only [hcs hx', true_iff, hcs (apply_mem_support.mpr hx')]
· rw [not_mem_support.mp hx']
/-- A permutation c is the extension of a restriction of g to s
iff its support is contained in s and its restriction is that of g -/
lemma ofSubtype_eq_iff {g c : Equiv.Perm α} {s : Finset α}
(hg : ∀ x, x ∈ s ↔ g x ∈ s) :
ofSubtype (g.subtypePerm hg) = c ↔
c.support ≤ s ∧
∀ (hc' : ∀ x, x ∈ s ↔ c x ∈ s), c.subtypePerm hc' = g.subtypePerm hg := by
simp only [Equiv.ext_iff, subtypePerm_apply, Subtype.mk.injEq, Subtype.forall]
constructor
· intro h
constructor
· intro a ha
by_contra ha'
rw [mem_support, ← h a, ofSubtype_apply_of_not_mem (p := (· ∈ s)) _ ha'] at ha
exact ha rfl
· intro _ a ha
rw [← h a, ofSubtype_apply_of_mem (p := (· ∈ s)) _ ha, subtypePerm_apply]
· rintro ⟨hc, h⟩ a
specialize h (isInvariant_of_support_le hc)
by_cases ha : a ∈ s
· rw [h a ha, ofSubtype_apply_of_mem (p := (· ∈ s)) _ ha, subtypePerm_apply]
· rw [ofSubtype_apply_of_not_mem (p := (· ∈ s)) _ ha, eq_comm, ← not_mem_support]
exact Finset.not_mem_mono hc ha
theorem support_ofSubtype {p : α → Prop} [DecidablePred p] (u : Perm (Subtype p)) :
(ofSubtype u).support = u.support.map (Function.Embedding.subtype p) := by
ext x
simp only [mem_support, ne_eq, Finset.mem_map, Function.Embedding.coe_subtype, Subtype.exists,
exists_and_right, exists_eq_right, not_iff_comm, not_exists, not_not]
by_cases hx : p x
· simp only [forall_prop_of_true hx, ofSubtype_apply_of_mem u hx, ← Subtype.coe_inj]
· simp only [forall_prop_of_false hx, true_iff, ofSubtype_apply_of_not_mem u hx]
theorem mem_support_of_mem_noncommProd_support {α β : Type*} [DecidableEq β] [Fintype β]
{s : Finset α} {f : α → Perm β}
{comm : (s : Set α).Pairwise (Commute on f)} {x : β} (hx : x ∈ (s.noncommProd f comm).support) :
∃ a ∈ s, x ∈ (f a).support := by
contrapose! hx
classical
revert hx comm s
apply Finset.induction
· simp
· intro a s ha ih comm hs
rw [Finset.noncommProd_insert_of_not_mem s a f comm ha]
apply mt (Finset.mem_of_subset (support_mul_le _ _))
rw [Finset.sup_eq_union, Finset.not_mem_union]
exact ⟨hs a (s.mem_insert_self a), ih (fun a ha ↦ hs a (Finset.mem_insert_of_mem ha))⟩
theorem pow_apply_mem_support {n : ℕ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by
simp only [mem_support, ne_eq, apply_pow_apply_eq_iff]
theorem zpow_apply_mem_support {n : ℤ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by
simp only [mem_support, ne_eq, apply_zpow_apply_eq_iff]
theorem pow_eq_on_of_mem_support (h : ∀ x ∈ f.support ∩ g.support, f x = g x) (k : ℕ) :
∀ x ∈ f.support ∩ g.support, (f ^ k) x = (g ^ k) x := by
induction' k with k hk
· simp
· intro x hx
rw [pow_succ, mul_apply, pow_succ, mul_apply, h _ hx, hk]
rwa [mem_inter, apply_mem_support, ← h _ hx, apply_mem_support, ← mem_inter]
theorem disjoint_iff_disjoint_support : Disjoint f g ↔ _root_.Disjoint f.support g.support := by
simp [disjoint_iff_eq_or_eq, disjoint_iff, disjoint_iff, Finset.ext_iff, not_and_or,
imp_iff_not_or]
theorem Disjoint.disjoint_support (h : Disjoint f g) : _root_.Disjoint f.support g.support :=
disjoint_iff_disjoint_support.1 h
theorem Disjoint.support_mul (h : Disjoint f g) : (f * g).support = f.support ∪ g.support := by
refine le_antisymm (support_mul_le _ _) fun a => ?_
rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not]
exact
(h a).elim (fun hf h => ⟨hf, f.apply_eq_iff_eq.mp (h.trans hf.symm)⟩) fun hg h =>
⟨(congr_arg f hg).symm.trans h, hg⟩
theorem support_prod_of_pairwise_disjoint (l : List (Perm α)) (h : l.Pairwise Disjoint) :
l.prod.support = (l.map support).foldr (· ⊔ ·) ⊥ := by
induction' l with hd tl hl
· simp
· rw [List.pairwise_cons] at h
have : Disjoint hd tl.prod := disjoint_prod_right _ h.left
simp [this.support_mul, hl h.right]
theorem support_noncommProd {ι : Type*} {k : ι → Perm α} {s : Finset ι}
(hs : Set.Pairwise s fun i j ↦ Disjoint (k i) (k j)) :
(s.noncommProd k (hs.imp (fun _ _ ↦ Perm.Disjoint.commute))).support =
s.biUnion fun i ↦ (k i).support := by
classical
induction s using Finset.induction_on with
| empty => simp
| insert i s hi hrec =>
have hs' : (s : Set ι).Pairwise fun i j ↦ Disjoint (k i) (k j) :=
hs.mono (by simp only [Finset.coe_insert, Set.subset_insert])
rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ hi, Finset.biUnion_insert]
rw [Equiv.Perm.Disjoint.support_mul, hrec hs']
apply disjoint_noncommProd_right
intro j hj
apply hs _ _ (ne_of_mem_of_not_mem hj hi).symm <;>
simp only [Finset.coe_insert, Set.mem_insert_iff, Finset.mem_coe, hj, or_true, true_or]
theorem support_prod_le (l : List (Perm α)) : l.prod.support ≤ (l.map support).foldr (· ⊔ ·) ⊥ := by
induction' l with hd tl hl
· simp
· rw [List.prod_cons, List.map_cons, List.foldr_cons]
refine (support_mul_le hd tl.prod).trans ?_
exact sup_le_sup le_rfl hl
theorem support_zpow_le (σ : Perm α) (n : ℤ) : (σ ^ n).support ≤ σ.support := fun _ h1 =>
mem_support.mpr fun h2 => mem_support.mp h1 (zpow_apply_eq_self_of_apply_eq_self h2 n)
@[simp]
theorem support_swap {x y : α} (h : x ≠ y) : support (swap x y) = {x, y} := by
ext z
by_cases hx : z = x
any_goals simpa [hx] using h.symm
by_cases hy : z = y
· simpa [swap_apply_of_ne_of_ne, hx, hy] using h
· simp [swap_apply_of_ne_of_ne, hx, hy]
theorem support_swap_iff (x y : α) : support (swap x y) = {x, y} ↔ x ≠ y := by
refine ⟨fun h => ?_, fun h => support_swap h⟩
rintro rfl
simp [Finset.ext_iff] at h
theorem support_swap_mul_swap {x y z : α} (h : List.Nodup [x, y, z]) :
support (swap x y * swap y z) = {x, y, z} := by
simp only [List.not_mem_nil, and_true, List.mem_cons, not_false_iff, List.nodup_cons,
List.mem_singleton, and_self_iff, List.nodup_nil] at h
push_neg at h
apply le_antisymm
· convert support_mul_le (swap x y) (swap y z) using 1
rw [support_swap h.left.left, support_swap h.right.left]
simp [Finset.ext_iff]
· intro
simp only [mem_insert, mem_singleton]
rintro (rfl | rfl | rfl | _) <;>
simp [swap_apply_of_ne_of_ne, h.left.left, h.left.left.symm, h.left.right.symm,
h.left.right.left.symm, h.right.left.symm]
theorem support_swap_mul_ge_support_diff (f : Perm α) (x y : α) :
f.support \ {x, y} ≤ (swap x y * f).support := by
intro
simp only [and_imp, Perm.coe_mul, Function.comp_apply, Ne, mem_support, mem_insert, mem_sdiff,
mem_singleton]
push_neg
rintro ha ⟨hx, hy⟩ H
rw [swap_apply_eq_iff, swap_apply_of_ne_of_ne hx hy] at H
exact ha H
theorem support_swap_mul_eq (f : Perm α) (x : α) (h : f (f x) ≠ x) :
(swap x (f x) * f).support = f.support \ {x} := by
by_cases hx : f x = x
· simp [hx, sdiff_singleton_eq_erase, not_mem_support.mpr hx, erase_eq_of_not_mem]
ext z
by_cases hzx : z = x
· simp [hzx]
by_cases hzf : z = f x
· simp [hzf, hx, h, swap_apply_of_ne_of_ne]
by_cases hzfx : f z = x
· simp [Ne.symm hzx, hzx, Ne.symm hzf, hzfx]
· simp [Ne.symm hzx, hzx, Ne.symm hzf, hzfx, f.injective.ne hzx, swap_apply_of_ne_of_ne]
theorem mem_support_swap_mul_imp_mem_support_ne {x y : α} (hy : y ∈ support (swap x (f x) * f)) :
y ∈ support f ∧ y ≠ x := by
simp only [mem_support, swap_apply_def, mul_apply, f.injective.eq_iff] at *
by_cases h : f y = x
· constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne]
· split_ifs at hy with heq
· subst heq; exact ⟨h, hy⟩
· exact ⟨hy, heq⟩
theorem Disjoint.mem_imp (h : Disjoint f g) {x : α} (hx : x ∈ f.support) : x ∉ g.support :=
disjoint_left.mp h.disjoint_support hx
theorem eq_on_support_mem_disjoint {l : List (Perm α)} (h : f ∈ l) (hl : l.Pairwise Disjoint) :
∀ x ∈ f.support, f x = l.prod x := by
induction' l with hd tl IH
· simp at h
· intro x hx
rw [List.pairwise_cons] at hl
rw [List.mem_cons] at h
rcases h with (rfl | h)
· rw [List.prod_cons, mul_apply,
not_mem_support.mp ((disjoint_prod_right tl hl.left).mem_imp hx)]
· rw [List.prod_cons, mul_apply, ← IH h hl.right _ hx, eq_comm, ← not_mem_support]
refine (hl.left _ h).symm.mem_imp ?_
simpa using hx
theorem Disjoint.mono {x y : Perm α} (h : Disjoint f g) (hf : x.support ≤ f.support)
(hg : y.support ≤ g.support) : Disjoint x y := by
rw [disjoint_iff_disjoint_support] at h ⊢
exact h.mono hf hg
theorem support_le_prod_of_mem {l : List (Perm α)} (h : f ∈ l) (hl : l.Pairwise Disjoint) :
f.support ≤ l.prod.support := by
intro x hx
rwa [mem_support, ← eq_on_support_mem_disjoint h hl _ hx, ← mem_support]
section ExtendDomain
variable {β : Type*} [DecidableEq β] [Fintype β] {p : β → Prop} [DecidablePred p]
@[simp]
theorem support_extend_domain (f : α ≃ Subtype p) {g : Perm α} :
support (g.extendDomain f) = g.support.map f.asEmbedding := by
ext b
simp only [exists_prop, Function.Embedding.coeFn_mk, toEmbedding_apply, mem_map, Ne,
Function.Embedding.trans_apply, mem_support]
by_cases pb : p b
· rw [extendDomain_apply_subtype _ _ pb]
constructor
· rintro h
refine ⟨f.symm ⟨b, pb⟩, ?_, by simp⟩
contrapose! h
simp [h]
· rintro ⟨a, ha, hb⟩
contrapose! ha
obtain rfl : a = f.symm ⟨b, pb⟩ := by
rw [eq_symm_apply]
exact Subtype.coe_injective hb
rw [eq_symm_apply]
exact Subtype.coe_injective ha
· rw [extendDomain_apply_not_subtype _ _ pb]
simp only [not_exists, false_iff, not_and, eq_self_iff_true, not_true]
rintro a _ rfl
exact pb (Subtype.prop _)
theorem card_support_extend_domain (f : α ≃ Subtype p) {g : Perm α} :
#(g.extendDomain f).support = #g.support := by simp
end ExtendDomain
section Card
theorem card_support_eq_zero {f : Perm α} : #f.support = 0 ↔ f = 1 := by
rw [Finset.card_eq_zero, support_eq_empty_iff]
theorem one_lt_card_support_of_ne_one {f : Perm α} (h : f ≠ 1) : 1 < #f.support := by
simp_rw [one_lt_card_iff, mem_support, ← not_or]
contrapose! h
ext a
specialize h (f a) a
rwa [apply_eq_iff_eq, or_self_iff, or_self_iff] at h
theorem card_support_ne_one (f : Perm α) : #f.support ≠ 1 := by
by_cases h : f = 1
· exact ne_of_eq_of_ne (card_support_eq_zero.mpr h) zero_ne_one
· exact ne_of_gt (one_lt_card_support_of_ne_one h)
@[simp]
theorem card_support_le_one {f : Perm α} : #f.support ≤ 1 ↔ f = 1 := by
rw [le_iff_lt_or_eq, Nat.lt_succ_iff, Nat.le_zero, card_support_eq_zero, or_iff_not_imp_right,
imp_iff_right f.card_support_ne_one]
theorem two_le_card_support_of_ne_one {f : Perm α} (h : f ≠ 1) : 2 ≤ #f.support :=
one_lt_card_support_of_ne_one h
theorem card_support_swap_mul {f : Perm α} {x : α} (hx : f x ≠ x) :
| #(swap x (f x) * f).support < #f.support :=
Finset.card_lt_card
⟨fun _ hz => (mem_support_swap_mul_imp_mem_support_ne hz).left, fun h =>
| Mathlib/GroupTheory/Perm/Support.lean | 606 | 608 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.ModEq
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Circular
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `Archimedean`
`LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ico a (a + p)`.
* `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`.
* `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ioc a (a + p)`.
* `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α]
{p : α} (hp : 0 < p)
{a b c : α} {n : ℤ}
section
include hp
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/
def toIcoDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod]
@[simp]
theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
@[simp]
theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
@[simp]
theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩
theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩
theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by
rw [add_comm, toIcoDiv_add_zsmul, add_comm]
/-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/
@[simp]
theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by
rw [add_comm, toIocDiv_add_zsmul, add_comm]
/-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/
@[simp]
theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1
@[simp]
theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1
@[simp]
theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1
@[simp]
theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1
@[simp]
theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
@[simp]
theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
@[simp]
theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
@[simp]
theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
@[simp]
theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1
@[simp]
theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1
@[simp]
theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
@[simp]
theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1
theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) :
toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by
apply toIcoDiv_eq_of_sub_zsmul_mem_Ico
rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm]
exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b
theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) :
toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm]
exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b
theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) :
toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg]
theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) :
toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg]
theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by
suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by
rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this
rw [← neg_eq_iff_eq_neg, eq_comm]
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b)
rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho
rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc
refine ⟨ho, hc.trans_eq ?_⟩
rw [neg_add, neg_add_cancel_right]
theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b)
theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by
rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right]
theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b)
@[simp]
theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by
rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul]
abel
@[simp]
theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by
simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by
rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul]
abel
@[simp]
theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by
simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) :
toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul', add_comm]
@[simp]
theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) :
toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul', add_comm]
@[simp]
theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul']
@[simp]
theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul']
@[simp]
theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1
@[simp]
theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by
simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1
@[simp]
theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1
@[simp]
theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by
simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1
@[simp]
theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right]
@[simp]
theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_right', add_comm]
@[simp]
theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_right]
@[simp]
theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_right', add_comm]
@[simp]
theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1
@[simp]
theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by
simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1
@[simp]
theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1
@[simp]
theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by
simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1
theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm]
theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm]
theorem toIcoMod_add_right_eq_add (a b c : α) :
toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by
simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub]
theorem toIocMod_add_right_eq_add (a b c : α) :
toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by
simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub]
theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by
simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul]
abel
theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by
simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b)
theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by
simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul]
abel
theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by
simpa only [neg_neg] using toIocMod_neg hp (-a) (-b)
theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by
refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩
· conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c]
rw [h, sub_smul]
abel
· rcases h with ⟨z, hz⟩
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIcoMod_zsmul_add]
theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by
refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩
· conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c]
rw [h, sub_smul]
abel
· rcases h with ⟨z, hz⟩
rw [sub_eq_iff_eq_add] at hz
rw [hz, toIocMod_zsmul_add]
/-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/
section IcoIoc
namespace AddCommGroup
theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a :=
modEq_iff_eq_add_zsmul.trans
⟨by
rintro ⟨n, rfl⟩
rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩
theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by
refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩
· rintro ⟨z, rfl⟩
rw [toIocMod_add_zsmul, toIocMod_apply_left]
· rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add']
alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left
alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right
variable (a b)
open List in
theorem tfae_modEq :
TFAE
[a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b,
toIcoMod hp a b + p = toIocMod hp a b] := by
rw [modEq_iff_toIcoMod_eq_left hp]
tfae_have 3 → 2 := by
rw [← not_exists, not_imp_not]
exact fun ⟨i, hi⟩ =>
((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans
((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm
tfae_have 4 → 3
| | h => by
rw [← h, Ne, eq_comm, add_eq_left]
| Mathlib/Algebra/Order/ToIntervalMod.lean | 525 | 526 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.List.Sublists
import Mathlib.Data.List.Zip
import Mathlib.Data.Multiset.Bind
import Mathlib.Data.Multiset.Range
/-!
# The powerset of a multiset
-/
namespace Multiset
open List
variable {α : Type*}
/-! ### powerset -/
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: Write a more efficient version
/-- A helper function for the powerset of a multiset. Given a list `l`, returns a list
of sublists of `l` as multisets. -/
def powersetAux (l : List α) : List (Multiset α) :=
(sublists l).map (↑)
theorem powersetAux_eq_map_coe {l : List α} : powersetAux l = (sublists l).map (↑) :=
rfl
@[simp]
theorem mem_powersetAux {l : List α} {s} : s ∈ powersetAux l ↔ s ≤ ↑l :=
Quotient.inductionOn s <| by simp [powersetAux_eq_map_coe, Subperm, and_comm]
/-- Helper function for the powerset of a multiset. Given a list `l`, returns a list
of sublists of `l` (using `sublists'`), as multisets. -/
def powersetAux' (l : List α) : List (Multiset α) :=
(sublists' l).map (↑)
theorem powersetAux_perm_powersetAux' {l : List α} : powersetAux l ~ powersetAux' l := by
rw [powersetAux_eq_map_coe]; exact (sublists_perm_sublists' _).map _
@[simp]
theorem powersetAux'_nil : powersetAux' (@nil α) = [0] :=
rfl
@[simp]
theorem powersetAux'_cons (a : α) (l : List α) :
powersetAux' (a :: l) = powersetAux' l ++ List.map (cons a) (powersetAux' l) := by
simp [powersetAux']
theorem powerset_aux'_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux' l₁ ~ powersetAux' l₂ := by
induction p with
| nil => simp
| cons _ _ IH =>
simp only [powersetAux'_cons]
exact IH.append (IH.map _)
| swap a b =>
| simp only [powersetAux'_cons, map_append, List.map_map, append_assoc]
apply Perm.append_left
rw [← append_assoc, ← append_assoc,
(by funext s; simp [cons_swap] : cons b ∘ cons a = cons a ∘ cons b)]
exact perm_append_comm.append_right _
| trans _ _ IH₁ IH₂ => exact IH₁.trans IH₂
theorem powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux l₁ ~ powersetAux l₂ :=
powersetAux_perm_powersetAux'.trans <|
(powerset_aux'_perm p).trans powersetAux_perm_powersetAux'.symm
| Mathlib/Data/Multiset/Powerset.lean | 60 | 70 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Yaël Dillies, Yuyang Zhao
-/
import Mathlib.Algebra.Order.Ring.Unbundled.Basic
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.NatCast
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Ring.Defs
import Mathlib.Tactic.Tauto
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Ordered rings and semirings
This file develops the basics of ordered (semi)rings.
Each typeclass here comprises
* an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`)
* an order class (`PartialOrder`, `LinearOrder`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`+` respects `<`" means "strict monotonicity of addition"
* "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number".
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses
* `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`.
* `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects
`<`.
* `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect
`≤`.
* `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+`
and `*` respect `<`.
* `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+`
respects `≤` and `*` respects `<`.
* `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*`
respects `<`.
* `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects
`≤` and `*` respects `<`.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `OrderedSemiring`
- `OrderedAddCommMonoid` & multiplication & `*` respects `≤`
- `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤`
* `StrictOrderedSemiring`
- `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommSemiring`
- `OrderedSemiring` & commutativity of multiplication
- `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommSemiring`
- `StrictOrderedSemiring` & commutativity of multiplication
- `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedRing`
- `OrderedSemiring` & additive inverses
- `OrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedRing`
- `StrictOrderedSemiring` & additive inverses
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommRing`
- `OrderedRing` & commutativity of multiplication
- `OrderedCommSemiring` & additive inverses
- `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommRing`
- `StrictOrderedCommSemiring` & additive inverses
- `StrictOrderedRing` & commutativity of multiplication
- `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality
* `LinearOrderedSemiring`
- `StrictOrderedSemiring` & totality of the order
- `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<`
* `LinearOrderedCommSemiring`
- `StrictOrderedCommSemiring` & totality of the order
- `LinearOrderedSemiring` & commutativity of multiplication
* `LinearOrderedRing`
- `StrictOrderedRing` & totality of the order
- `LinearOrderedSemiring` & additive inverses
- `LinearOrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & `IsDomain` & linear order structure
* `LinearOrderedCommRing`
- `StrictOrderedCommRing` & totality of the order
- `LinearOrderedRing` & commutativity of multiplication
- `LinearOrderedCommSemiring` & additive inverses
- `CommRing` & `IsDomain` & linear order structure
-/
assert_not_exists MonoidHom
open Function
universe u
variable {R : Type u}
-- TODO: assume weaker typeclasses
/-- An ordered semiring is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
class IsOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedAddMonoid R, ZeroLEOneClass R where
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
attribute [instance 100] IsOrderedRing.toZeroLEOneClass
/-- A strict ordered semiring is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
class IsStrictOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedCancelAddMonoid R, ZeroLEOneClass R, Nontrivial R where
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the left
by a positive element `0 < c` to obtain `c * a < c * b`. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the right
by a positive element `0 < c` to obtain `a * c < b * c`. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
attribute [instance 100] IsStrictOrderedRing.toZeroLEOneClass
attribute [instance 100] IsStrictOrderedRing.toNontrivial
lemma IsOrderedRing.of_mul_nonneg [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] (mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b) :
IsOrderedRing R where
mul_le_mul_of_nonneg_left a b c ab hc := by
simpa only [mul_sub, sub_nonneg] using mul_nonneg _ _ hc (sub_nonneg.2 ab)
mul_le_mul_of_nonneg_right a b c ab hc := by
simpa only [sub_mul, sub_nonneg] using mul_nonneg _ _ (sub_nonneg.2 ab) hc
lemma IsStrictOrderedRing.of_mul_pos [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] [Nontrivial R] (mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b) :
IsStrictOrderedRing R where
mul_lt_mul_of_pos_left a b c ab hc := by
simpa only [mul_sub, sub_pos] using mul_pos _ _ hc (sub_pos.2 ab)
mul_lt_mul_of_pos_right a b c ab hc := by
simpa only [sub_mul, sub_pos] using mul_pos _ _ (sub_pos.2 ab) hc
section IsOrderedRing
variable [Semiring R] [PartialOrder R] [IsOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toPosMulMono : PosMulMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_left _ _ _ h x.2
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toMulPosMono : MulPosMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_right _ _ _ h x.2
end IsOrderedRing
/-- Turn an ordered domain into a strict ordered ring. -/
lemma IsOrderedRing.toIsStrictOrderedRing (R : Type*)
[Ring R] [PartialOrder R] [IsOrderedRing R] [NoZeroDivisors R] [Nontrivial R] :
IsStrictOrderedRing R :=
.of_mul_pos fun _ _ ap bp ↦ (mul_nonneg ap.le bp.le).lt_of_ne' (mul_ne_zero ap.ne' bp.ne')
section IsStrictOrderedRing
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toPosMulStrictMono : PosMulStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_left _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toMulPosStrictMono : MulPosStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_right _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toIsOrderedRing : IsOrderedRing R where
__ := ‹IsStrictOrderedRing R›
mul_le_mul_of_nonneg_left _ _ _ := mul_le_mul_of_nonneg_left
mul_le_mul_of_nonneg_right _ _ _ := mul_le_mul_of_nonneg_right
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toCharZero :
CharZero R where
cast_injective :=
(strictMono_nat_of_lt_succ fun n ↦ by rw [Nat.cast_succ]; apply lt_add_one).injective
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toNoMaxOrder : NoMaxOrder R :=
⟨fun a => ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩
end IsStrictOrderedRing
section LinearOrder
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [ExistsAddOfLE R]
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.noZeroDivisors : NoZeroDivisors R where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := by
contrapose! hab
obtain ha | ha := hab.1.lt_or_lt <;> obtain hb | hb := hab.2.lt_or_lt
exacts [(mul_pos_of_neg_of_neg ha hb).ne', (mul_neg_of_neg_of_pos ha hb).ne,
(mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne']
-- Note that we can't use `NoZeroDivisors.to_isDomain` since we are merely in a semiring.
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.isDomain : IsDomain R where
mul_left_cancel_of_ne_zero {a b c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_left ha).injective h, (strictMono_mul_left_of_pos ha).injective h]
mul_right_cancel_of_ne_zero {b a c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_right ha).injective h, (strictMono_mul_right_of_pos ha).injective h]
end LinearOrder
/-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the
`zero_le_one` field. -/
set_option linter.deprecated false in
/-- An `OrderedSemiring` is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedSemiring (R : Type u) extends Semiring R, OrderedAddCommMonoid R where
/-- `0 ≤ 1` in any ordered semiring. -/
protected zero_le_one : (0 : R) ≤ 1
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
set_option linter.deprecated false in
/-- An `OrderedCommSemiring` is a commutative semiring with a partial order such that addition is
monotone and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommSemiring (R : Type u) extends OrderedSemiring R, CommSemiring R where
mul_le_mul_of_nonneg_right a b c ha hc :=
-- parentheses ensure this generates an `optParam` rather than an `autoParam`
(by simpa only [mul_comm] using mul_le_mul_of_nonneg_left a b c ha hc)
set_option linter.deprecated false in
/-- An `OrderedRing` is a ring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R where
/-- `0 ≤ 1` in any ordered ring. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of non-negative elements is non-negative. -/
protected mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b
set_option linter.deprecated false in
/-- An `OrderedCommRing` is a commutative ring with a partial order such that addition is monotone
and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommRing (R : Type u) extends OrderedRing R, CommRing R
set_option linter.deprecated false in
/-- A `StrictOrderedSemiring` is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedSemiring (R : Type u) extends Semiring R, OrderedCancelAddCommMonoid R,
Nontrivial R where
/-- In a strict ordered semiring, `0 ≤ 1`. -/
protected zero_le_one : (0 : R) ≤ 1
/-- Left multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- Right multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
set_option linter.deprecated false in
/-- A `StrictOrderedCommSemiring` is a commutative semiring with a partial order such that
addition is strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommSemiring (R : Type u) extends StrictOrderedSemiring R, CommSemiring R
set_option linter.deprecated false in
/-- A `StrictOrderedRing` is a ring with a partial order such that addition is strictly monotone
and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R, Nontrivial R where
/-- In a strict ordered ring, `0 ≤ 1`. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of two positive elements is positive. -/
protected mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b
set_option linter.deprecated false in
/-- A `StrictOrderedCommRing` is a commutative ring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommRing (R : Type*) extends StrictOrderedRing R, CommRing R
/- It's not entirely clear we should assume `Nontrivial` at this point; it would be reasonable to
explore changing this, but be warned that the instances involving `Domain` may cause typeclass
search loops. -/
set_option linter.deprecated false in
/-- A `LinearOrderedSemiring` is a nontrivial semiring with a linear order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedSemiring (R : Type u) extends StrictOrderedSemiring R,
LinearOrderedAddCommMonoid R
set_option linter.deprecated false in
/-- A `LinearOrderedCommSemiring` is a nontrivial commutative semiring with a linear order such
that addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommSemiring (R : Type*) extends StrictOrderedCommSemiring R,
LinearOrderedSemiring R
set_option linter.deprecated false in
/-- A `LinearOrderedRing` is a ring with a linear order such that addition is monotone and
multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedRing (R : Type u) extends StrictOrderedRing R, LinearOrder R
set_option linter.deprecated false in
/-- A `LinearOrderedCommRing` is a commutative ring with a linear order such that addition is
monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommRing (R : Type u) extends LinearOrderedRing R, CommMonoid R
attribute [nolint docBlame]
StrictOrderedSemiring.toOrderedCancelAddCommMonoid
StrictOrderedCommSemiring.toCommSemiring
LinearOrderedSemiring.toLinearOrderedAddCommMonoid
LinearOrderedRing.toLinearOrder
OrderedSemiring.toOrderedAddCommMonoid
OrderedCommSemiring.toCommSemiring
StrictOrderedCommRing.toCommRing
OrderedRing.toOrderedAddCommGroup
OrderedCommRing.toCommRing
StrictOrderedRing.toOrderedAddCommGroup
LinearOrderedCommSemiring.toLinearOrderedSemiring
LinearOrderedCommRing.toCommMonoid
section OrderedRing
variable [Ring R] [PartialOrder R] [IsOrderedRing R] {a b c : R}
lemma one_add_le_one_sub_mul_one_add (h : a + b + b * c ≤ c) : 1 + a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_add_le_one_add_mul_one_sub (h : a + c + b * c ≤ b) : 1 + a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_sub_le_one_sub_mul_one_add (h : b + b * c ≤ a + c) : 1 - a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, sub_le_sub_iff, add_assoc, add_comm c]
gcongr
lemma one_sub_le_one_add_mul_one_sub (h : c + b * c ≤ a + b) : 1 - a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, sub_le_sub_iff, add_assoc, add_comm b]
gcongr
end OrderedRing
| Mathlib/Algebra/Order/Ring/Defs.lean | 732 | 737 | |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Multiset.ZeroCons
/-!
# Basic results on multisets
-/
-- No algebra should be required
assert_not_exists Monoid
universe v
open List Subtype Nat Function
variable {α : Type*} {β : Type v} {γ : Type*}
namespace Multiset
/-! ### `Multiset.toList` -/
section ToList
/-- Produces a list of the elements in the multiset using choice. -/
noncomputable def toList (s : Multiset α) :=
s.out
@[simp, norm_cast]
theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s :=
s.out_eq'
@[simp]
theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by
rw [← coe_eq_zero, coe_toList]
theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := by simp
@[simp]
theorem toList_zero : (Multiset.toList 0 : List α) = [] :=
toList_eq_nil.mpr rfl
@[simp]
theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by
rw [← mem_coe, coe_toList]
@[simp]
theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by
rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton]
@[simp]
theorem toList_singleton (a : α) : ({a} : Multiset α).toList = [a] :=
Multiset.toList_eq_singleton_iff.2 rfl
@[simp]
theorem length_toList (s : Multiset α) : s.toList.length = card s := by
rw [← coe_card, coe_toList]
end ToList
/-! ### Induction principles -/
/-- The strong induction principle for multisets. -/
@[elab_as_elim]
def strongInductionOn {p : Multiset α → Sort*} (s : Multiset α) (ih : ∀ s, (∀ t < s, p t) → p s) :
p s :=
(ih s) fun t _h =>
strongInductionOn t ih
termination_by card s
decreasing_by exact card_lt_card _h
theorem strongInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) (H) :
@strongInductionOn _ p s H = H s fun t _h => @strongInductionOn _ p t H := by
rw [strongInductionOn]
@[elab_as_elim]
theorem case_strongInductionOn {p : Multiset α → Prop} (s : Multiset α) (h₀ : p 0)
(h₁ : ∀ a s, (∀ t ≤ s, p t) → p (a ::ₘ s)) : p s :=
Multiset.strongInductionOn s fun s =>
Multiset.induction_on s (fun _ => h₀) fun _a _s _ ih =>
(h₁ _ _) fun _t h => ih _ <| lt_of_le_of_lt h <| lt_cons_self _ _
/-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than
`n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of
cardinality less than `n`, starting from multisets of card `n` and iterating. This
can be used either to define data, or to prove properties. -/
def strongDownwardInduction {p : Multiset α → Sort*} {n : ℕ}
(H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁)
(s : Multiset α) :
card s ≤ n → p s :=
H s fun {t} ht _h =>
strongDownwardInduction H t ht
termination_by n - card s
decreasing_by simp_wf; have := (card_lt_card _h); omega
theorem strongDownwardInduction_eq {p : Multiset α → Sort*} {n : ℕ}
(H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁)
(s : Multiset α) :
strongDownwardInduction H s = H s fun ht _hst => strongDownwardInduction H _ ht := by
rw [strongDownwardInduction]
/-- Analogue of `strongDownwardInduction` with order of arguments swapped. -/
@[elab_as_elim]
def strongDownwardInductionOn {p : Multiset α → Sort*} {n : ℕ} :
∀ s : Multiset α,
(∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) →
card s ≤ n → p s :=
fun s H => strongDownwardInduction H s
theorem strongDownwardInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) {n : ℕ}
(H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) :
s.strongDownwardInductionOn H = H s fun {t} ht _h => t.strongDownwardInductionOn H ht := by
dsimp only [strongDownwardInductionOn]
rw [strongDownwardInduction]
section Choose
variable (p : α → Prop) [DecidablePred p] (l : Multiset α)
/-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `chooseX p l hp` returns
that `a` together with proofs of `a ∈ l` and `p a`. -/
def chooseX : ∀ _hp : ∃! a, a ∈ l ∧ p a, { a // a ∈ l ∧ p a } :=
Quotient.recOn l (fun l' ex_unique => List.chooseX p l' (ExistsUnique.exists ex_unique))
(by
intros a b _
funext hp
suffices all_equal : ∀ x y : { t // t ∈ b ∧ p t }, x = y by
apply all_equal
rintro ⟨x, px⟩ ⟨y, py⟩
rcases hp with ⟨z, ⟨_z_mem_l, _pz⟩, z_unique⟩
congr
calc
x = z := z_unique x px
_ = y := (z_unique y py).symm
)
/-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `choose p l hp` returns
that `a`. -/
def choose (hp : ∃! a, a ∈ l ∧ p a) : α :=
chooseX p l hp
theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
variable (α) in
/-- The equivalence between lists and multisets of a subsingleton type. -/
def subsingletonEquiv [Subsingleton α] : List α ≃ Multiset α where
toFun := ofList
invFun :=
(Quot.lift id) fun (a b : List α) (h : a ~ b) =>
(List.ext_get h.length_eq) fun _ _ _ => Subsingleton.elim _ _
left_inv _ := rfl
right_inv m := Quot.inductionOn m fun _ => rfl
@[simp]
theorem coe_subsingletonEquiv [Subsingleton α] :
(subsingletonEquiv α : List α → Multiset α) = ofList :=
rfl
section SizeOf
set_option linter.deprecated false in
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Multiset α} (hx : x ∈ s) :
SizeOf.sizeOf x < SizeOf.sizeOf s := by
induction s using Quot.inductionOn
exact List.sizeOf_lt_sizeOf_of_mem hx
end SizeOf
end Multiset
| Mathlib/Data/Multiset/Basic.lean | 2,609 | 2,612 | |
/-
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.Data.Matrix.Notation
import Mathlib.Data.Fin.Tuple.Reflection
/-!
# Lemmas for concrete matrices `Matrix (Fin m) (Fin n) α`
This file contains alternative definitions of common operators on matrices that expand
definitionally to the expected expression when evaluated on `!![]` notation.
This allows "proof by reflection", where we prove `A = !![A 0 0, A 0 1; A 1 0, A 1 1]` by defining
`Matrix.etaExpand A` to be equal to the RHS definitionally, and then prove that
`A = eta_expand A`.
The definitions in this file should normally not be used directly; the intent is for the
corresponding `*_eq` lemmas to be used in a place where they are definitionally unfolded.
## Main definitions
* `Matrix.transposeᵣ`
* `dotProductᵣ`
* `Matrix.mulᵣ`
* `Matrix.mulVecᵣ`
* `Matrix.vecMulᵣ`
* `Matrix.etaExpand`
-/
open Matrix
namespace Matrix
variable {l m n : ℕ} {α : Type*}
/-- `∀` with better defeq for `∀ x : Matrix (Fin m) (Fin n) α, P x`. -/
def Forall : ∀ {m n} (_ : Matrix (Fin m) (Fin n) α → Prop), Prop
| 0, _, P => P (of ![])
| _ + 1, _, P => FinVec.Forall fun r => Forall fun A => P (of (Matrix.vecCons r A))
/-- This can be used to prove
```lean
example (P : Matrix (Fin 2) (Fin 3) α → Prop) :
(∀ x, P x) ↔ ∀ a b c d e f, P !![a, b, c; d, e, f] :=
(forall_iff _).symm
```
-/
theorem forall_iff : ∀ {m n} (P : Matrix (Fin m) (Fin n) α → Prop), Forall P ↔ ∀ x, P x
| 0, _, _ => Iff.symm Fin.forall_fin_zero_pi
| m + 1, n, P => by
simp only [Forall, FinVec.forall_iff, forall_iff]
exact Iff.symm Fin.forall_fin_succ_pi
example (P : Matrix (Fin 2) (Fin 3) α → Prop) :
(∀ x, P x) ↔ ∀ a b c d e f, P !![a, b, c; d, e, f] :=
(forall_iff _).symm
/-- `∃` with better defeq for `∃ x : Matrix (Fin m) (Fin n) α, P x`. -/
def Exists : ∀ {m n} (_ : Matrix (Fin m) (Fin n) α → Prop), Prop
| 0, _, P => P (of ![])
| _ + 1, _, P => FinVec.Exists fun r => Exists fun A => P (of (Matrix.vecCons r A))
/-- This can be used to prove
```lean
example (P : Matrix (Fin 2) (Fin 3) α → Prop) :
(∃ x, P x) ↔ ∃ a b c d e f, P !![a, b, c; d, e, f] :=
(exists_iff _).symm
```
-/
theorem exists_iff : ∀ {m n} (P : Matrix (Fin m) (Fin n) α → Prop), Exists P ↔ ∃ x, P x
| 0, _, _ => Iff.symm Fin.exists_fin_zero_pi
| m + 1, n, P => by
simp only [Exists, FinVec.exists_iff, exists_iff]
exact Iff.symm Fin.exists_fin_succ_pi
example (P : Matrix (Fin 2) (Fin 3) α → Prop) :
(∃ x, P x) ↔ ∃ a b c d e f, P !![a, b, c; d, e, f] :=
(exists_iff _).symm
/-- `Matrix.transpose` with better defeq for `Fin` -/
def transposeᵣ : ∀ {m n}, Matrix (Fin m) (Fin n) α → Matrix (Fin n) (Fin m) α
| _, 0, _ => of ![]
| _, _ + 1, A =>
of <| vecCons (FinVec.map (fun v : Fin _ → α => v 0) A) (transposeᵣ (A.submatrix id Fin.succ))
/-- This can be used to prove
```lean
example (a b c d : α) : transpose !![a, b; c, d] = !![a, c; b, d] := (transposeᵣ_eq _).symm
```
-/
@[simp]
theorem transposeᵣ_eq : ∀ {m n} (A : Matrix (Fin m) (Fin n) α), transposeᵣ A = transpose A
| _, 0, _ => Subsingleton.elim _ _
| m, n + 1, A =>
Matrix.ext fun i j => by
simp_rw [transposeᵣ, transposeᵣ_eq]
refine i.cases ?_ fun i => ?_
· dsimp
rw [FinVec.map_eq, Function.comp_apply]
· simp only [of_apply, Matrix.cons_val_succ]
rfl
example (a b c d : α) : transpose !![a, b; c, d] = !![a, c; b, d] :=
(transposeᵣ_eq _).symm
/-- `dotProduct` with better defeq for `Fin` -/
def dotProductᵣ [Mul α] [Add α] [Zero α] {m} (a b : Fin m → α) : α :=
FinVec.sum <| FinVec.seq (FinVec.map (· * ·) a) b
/-- This can be used to prove
```lean
example (a b c d : α) [Mul α] [AddCommMonoid α] :
dot_product ![a, b] ![c, d] = a * c + b * d :=
(dot_productᵣ_eq _ _).symm
```
-/
@[simp]
theorem dotProductᵣ_eq [Mul α] [AddCommMonoid α] {m} (a b : Fin m → α) :
dotProductᵣ a b = dotProduct a b := by
simp_rw [dotProductᵣ, dotProduct, FinVec.sum_eq, FinVec.seq_eq, FinVec.map_eq,
Function.comp_apply]
example (a b c d : α) [Mul α] [AddCommMonoid α] : dotProduct ![a, b] ![c, d] = a * c + b * d :=
(dotProductᵣ_eq _ _).symm
/-- `Matrix.mul` with better defeq for `Fin` -/
def mulᵣ [Mul α] [Add α] [Zero α] (A : Matrix (Fin l) (Fin m) α) (B : Matrix (Fin m) (Fin n) α) :
| Matrix (Fin l) (Fin n) α :=
of <| FinVec.map (fun v₁ => FinVec.map (fun v₂ => dotProductᵣ v₁ v₂) Bᵀ) A
/-- This can be used to prove
| Mathlib/Data/Matrix/Reflection.lean | 132 | 135 |
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Quotients
import Mathlib.Order.Filter.Finite
import Mathlib.Order.Filter.Germ.Basic
import Mathlib.Order.Filter.Ultrafilter.Defs
/-!
# Ultraproducts and Łoś's Theorem
## Main Definitions
- `FirstOrder.Language.Ultraproduct.Structure` is the ultraproduct structure on `Filter.Product`.
## Main Results
- Łoś's Theorem: `FirstOrder.Language.Ultraproduct.sentence_realize`. An ultraproduct models a
sentence `φ` if and only if the set of structures in the product that model `φ` is in the
ultrafilter.
## Tags
ultraproduct, Los's theorem
-/
universe u v
variable {α : Type*} (M : α → Type*) (u : Ultrafilter α)
open FirstOrder Filter
open Filter
namespace FirstOrder
namespace Language
open Structure
variable {L : Language.{u, v}} [∀ a, L.Structure (M a)]
namespace Ultraproduct
instance setoidPrestructure : L.Prestructure ((u : Filter α).productSetoid M) :=
{ (u : Filter α).productSetoid M with
toStructure :=
{ funMap := fun {_} f x a => funMap f fun i => x i a
RelMap := fun {_} r x => ∀ᶠ a : α in u, RelMap r fun i => x i a }
fun_equiv := fun {n} f x y xy => by
refine mem_of_superset (iInter_mem.2 xy) fun a ha => ?_
simp only [Set.mem_iInter, Set.mem_setOf_eq] at ha
simp only [Set.mem_setOf_eq, ha]
rel_equiv := fun {n} r x y xy => by
rw [← iff_eq_eq]
refine ⟨fun hx => ?_, fun hy => ?_⟩
· refine mem_of_superset (inter_mem hx (iInter_mem.2 xy)) ?_
rintro a ⟨ha1, ha2⟩
simp only [Set.mem_iInter, Set.mem_setOf_eq] at *
rw [← funext ha2]
exact ha1
· refine mem_of_superset (inter_mem hy (iInter_mem.2 xy)) ?_
rintro a ⟨ha1, ha2⟩
simp only [Set.mem_iInter, Set.mem_setOf_eq] at *
rw [funext ha2]
exact ha1 }
variable {M} {u}
instance «structure» : L.Structure ((u : Filter α).Product M) :=
Language.quotientStructure
theorem funMap_cast {n : ℕ} (f : L.Functions n) (x : Fin n → ∀ a, M a) :
(funMap f fun i => (x i : (u : Filter α).Product M)) =
(fun a => funMap f fun i => x i a : (u : Filter α).Product M) := by
apply funMap_quotient_mk'
theorem term_realize_cast {β : Type*} (x : β → ∀ a, M a) (t : L.Term β) :
(t.realize fun i => (x i : (u : Filter α).Product M)) =
(fun a => t.realize fun i => x i a : (u : Filter α).Product M) := by
convert @Term.realize_quotient_mk' L _ ((u : Filter α).productSetoid M)
(Ultraproduct.setoidPrestructure M u) _ t x using 2
ext a
induction t with
| var => rfl
| func _ _ t_ih => simp only [Term.realize, t_ih]; rfl
variable [∀ a : α, Nonempty (M a)]
theorem boundedFormula_realize_cast {β : Type*} {n : ℕ} (φ : L.BoundedFormula β n)
(x : β → ∀ a, M a) (v : Fin n → ∀ a, M a) :
(φ.Realize (fun i : β => (x i : (u : Filter α).Product M))
| (fun i => (v i : (u : Filter α).Product M))) ↔
∀ᶠ a : α in u, φ.Realize (fun i : β => x i a) fun i => v i a := by
letI := (u : Filter α).productSetoid M
induction φ with
| falsum => simp only [BoundedFormula.Realize, eventually_const]
| equal =>
have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a :=
fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl
simp only [BoundedFormula.Realize, h2, term_realize_cast]
erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm,
term_realize_cast, term_realize_cast]
exact Quotient.eq''
| rel =>
have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a :=
fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl
simp only [BoundedFormula.Realize, h2]
erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm]
conv_lhs => enter [2, i]; erw [term_realize_cast]
apply relMap_quotient_mk'
| imp _ _ ih ih' =>
simp only [BoundedFormula.Realize, ih v, ih' v]
rw [Ultrafilter.eventually_imp]
| @all k φ ih =>
simp only [BoundedFormula.Realize]
apply Iff.trans (b := ∀ m : ∀ a : α, M a,
φ.Realize (fun i : β => (x i : (u : Filter α).Product M))
(Fin.snoc (((↑) : (∀ a, M a) → (u : Filter α).Product M) ∘ v)
(m : (u : Filter α).Product M)))
· exact Quotient.forall
have h' :
∀ (m : ∀ a, M a) (a : α),
(fun i : Fin (k + 1) => (Fin.snoc v m : _ → ∀ a, M a) i a) =
Fin.snoc (fun i : Fin k => v i a) (m a) := by
refine fun m a => funext (Fin.reverseInduction ?_ fun i _ => ?_)
· simp only [Fin.snoc_last]
· simp only [Fin.snoc_castSucc]
simp only [← Fin.comp_snoc]
simp only [Function.comp_def, ih, h']
refine ⟨fun h => ?_, fun h m => ?_⟩
· contrapose! h
simp_rw [← Ultrafilter.eventually_not, not_forall] at h
refine
⟨fun a : α =>
Classical.epsilon fun m : M a =>
¬φ.Realize (fun i => x i a) (Fin.snoc (fun i => v i a) m),
?_⟩
rw [← Ultrafilter.eventually_not]
exact Filter.mem_of_superset h fun a ha => Classical.epsilon_spec ha
· rw [Filter.eventually_iff] at *
| Mathlib/ModelTheory/Ultraproducts.lean | 95 | 143 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Operations
/-!
# Results about division in extended non-negative reals
This file establishes basic properties related to the inversion and division operations on `ℝ≥0∞`.
For instance, as a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation
with integer exponent.
## Main results
A few order isomorphisms are worthy of mention:
- `OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ`: The map `x ↦ x⁻¹` as an order isomorphism to the dual.
- `orderIsoIicOneBirational : ℝ≥0∞ ≃o Iic (1 : ℝ≥0∞)`: The birational order isomorphism between
`ℝ≥0∞` and the unit interval `Set.Iic (1 : ℝ≥0∞)` given by `x ↦ (x⁻¹ + 1)⁻¹` with inverse
`x ↦ (x⁻¹ - 1)⁻¹`
- `orderIsoIicCoe (a : ℝ≥0) : Iic (a : ℝ≥0∞) ≃o Iic a`: Order isomorphism between an initial
interval in `ℝ≥0∞` and an initial interval in `ℝ≥0` given by the identity map.
- `orderIsoUnitIntervalBirational : ℝ≥0∞ ≃o Icc (0 : ℝ) 1`: An order isomorphism between
the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational`
composed with the identity order isomorphism between `Iic (1 : ℝ≥0∞)` and `Icc (0 : ℝ) 1`.
-/
assert_not_exists Finset
open Set NNReal
namespace ENNReal
noncomputable section Inv
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
protected theorem div_eq_inv_mul : a / b = b⁻¹ * a := by rw [div_eq_mul_inv, mul_comm]
@[simp] theorem inv_zero : (0 : ℝ≥0∞)⁻¹ = ∞ :=
show sInf { b : ℝ≥0∞ | 1 ≤ 0 * b } = ∞ by simp
@[simp] theorem inv_top : ∞⁻¹ = 0 :=
bot_unique <| le_of_forall_gt_imp_ge_of_dense fun a (h : 0 < a) => sInf_le <| by
simp [*, h.ne', top_mul]
theorem coe_inv_le : (↑r⁻¹ : ℝ≥0∞) ≤ (↑r)⁻¹ :=
le_sInf fun b (hb : 1 ≤ ↑r * b) =>
coe_le_iff.2 <| by
rintro b rfl
apply NNReal.inv_le_of_le_mul
rwa [← coe_mul, ← coe_one, coe_le_coe] at hb
@[simp, norm_cast]
theorem coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ℝ≥0∞) = (↑r)⁻¹ :=
coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [← coe_mul, mul_inv_cancel₀ hr, coe_one]
@[norm_cast]
theorem coe_inv_two : ((2⁻¹ : ℝ≥0) : ℝ≥0∞) = 2⁻¹ := by rw [coe_inv _root_.two_ne_zero, coe_two]
@[simp, norm_cast]
theorem coe_div (hr : r ≠ 0) : (↑(p / r) : ℝ≥0∞) = p / r := by
rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr]
lemma coe_div_le : ↑(p / r) ≤ (p / r : ℝ≥0∞) := by
simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _
theorem div_zero (h : a ≠ 0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h]
instance : DivInvOneMonoid ℝ≥0∞ :=
{ inferInstanceAs (DivInvMonoid ℝ≥0∞) with
inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one }
protected theorem inv_pow : ∀ {a : ℝ≥0∞} {n : ℕ}, (a ^ n)⁻¹ = a⁻¹ ^ n
| _, 0 => by simp only [pow_zero, inv_one]
| ⊤, n + 1 => by simp [top_pow]
| (a : ℝ≥0), n + 1 => by
rcases eq_or_ne a 0 with (rfl | ha)
· simp [top_pow]
· have := pow_ne_zero (n + 1) ha
norm_cast
rw [inv_pow]
protected theorem mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a * a⁻¹ = 1 := by
lift a to ℝ≥0 using ht
norm_cast at h0; norm_cast
exact mul_inv_cancel₀ h0
protected theorem inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 :=
mul_comm a a⁻¹ ▸ ENNReal.mul_inv_cancel h0 ht
/-- See `ENNReal.inv_mul_cancel_left` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma inv_mul_cancel_left' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) :
a⁻¹ * (a * b) = b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp_all
obtain rfl | ha := eq_or_ne a ⊤
· simp_all
· simp [← mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_left'` for a stronger version. -/
protected lemma inv_mul_cancel_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a⁻¹ * (a * b) = b :=
ENNReal.inv_mul_cancel_left' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_left` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma mul_inv_cancel_left' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) :
a * (a⁻¹ * b) = b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp_all
obtain rfl | ha := eq_or_ne a ⊤
· simp_all
· simp [← mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_left'` for a stronger version. -/
protected lemma mul_inv_cancel_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * (a⁻¹ * b) = b :=
ENNReal.mul_inv_cancel_left' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma mul_inv_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b * b⁻¹ = a := by
obtain rfl | hb₀ := eq_or_ne b 0
· simp_all
obtain rfl | hb := eq_or_ne b ⊤
· simp_all
· simp [mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_right'` for a stronger version. -/
protected lemma mul_inv_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b * b⁻¹ = a :=
ENNReal.mul_inv_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.inv_mul_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma inv_mul_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b⁻¹ * b = a := by
obtain rfl | hb₀ := eq_or_ne b 0
· simp_all
obtain rfl | hb := eq_or_ne b ⊤
· simp_all
· simp [mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_right'` for a stronger version. -/
protected lemma inv_mul_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b⁻¹ * b = a :=
ENNReal.inv_mul_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.mul_div_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma mul_div_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b / b = a := ENNReal.mul_inv_cancel_right' hb₀ hb
/-- See `ENNReal.mul_div_cancel_right'` for a stronger version. -/
protected lemma mul_div_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b / b = a :=
ENNReal.mul_div_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.div_mul_cancel` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma div_mul_cancel' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) : b / a * a = b :=
ENNReal.inv_mul_cancel_right' ha₀ ha
/-- See `ENNReal.div_mul_cancel'` for a stronger version. -/
protected lemma div_mul_cancel (ha₀ : a ≠ 0) (ha : a ≠ ∞) : b / a * a = b :=
ENNReal.div_mul_cancel' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_div_cancel` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma mul_div_cancel' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) : a * (b / a) = b := by
rw [mul_comm, ENNReal.div_mul_cancel' ha₀ ha]
/-- See `ENNReal.mul_div_cancel'` for a stronger version. -/
protected lemma mul_div_cancel (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * (b / a) = b :=
ENNReal.mul_div_cancel' (by simp [ha₀]) (by simp [ha])
protected theorem mul_comm_div : a / b * c = a * (c / b) := by
simp only [div_eq_mul_inv, mul_left_comm, mul_comm, mul_assoc]
protected theorem mul_div_right_comm : a * b / c = a / c * b := by
simp only [div_eq_mul_inv, mul_right_comm]
instance : InvolutiveInv ℝ≥0∞ where
inv_inv a := by
by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm]
@[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one]
@[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_inj
theorem inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp
@[aesop (rule_sets := [finiteness]) safe apply]
protected alias ⟨_, Finiteness.inv_ne_top⟩ := ENNReal.inv_ne_top
@[simp]
theorem inv_lt_top {x : ℝ≥0∞} : x⁻¹ < ∞ ↔ 0 < x := by
simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero]
theorem div_lt_top {x y : ℝ≥0∞} (h1 : x ≠ ∞) (h2 : y ≠ 0) : x / y < ∞ :=
mul_lt_top h1.lt_top (inv_ne_top.mpr h2).lt_top
@[simp]
protected theorem inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ :=
inv_top ▸ inv_inj
protected theorem inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp
protected theorem div_pos (ha : a ≠ 0) (hb : b ≠ ∞) : 0 < a / b :=
ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb
protected theorem inv_mul_le_iff {x y z : ℝ≥0∞} (h1 : x ≠ 0) (h2 : x ≠ ∞) :
x⁻¹ * y ≤ z ↔ y ≤ x * z := by
rw [← mul_le_mul_left h1 h2, ← mul_assoc, ENNReal.mul_inv_cancel h1 h2, one_mul]
protected theorem mul_inv_le_iff {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x * y⁻¹ ≤ z ↔ x ≤ z * y := by
rw [mul_comm, ENNReal.inv_mul_le_iff h1 h2, mul_comm]
protected theorem div_le_iff {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x / y ≤ z ↔ x ≤ z * y := by
rw [div_eq_mul_inv, ENNReal.mul_inv_le_iff h1 h2]
protected theorem div_le_iff' {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x / y ≤ z ↔ x ≤ y * z := by
rw [mul_comm, ENNReal.div_le_iff h1 h2]
protected theorem mul_inv {a b : ℝ≥0∞} (ha : a ≠ 0 ∨ b ≠ ∞) (hb : a ≠ ∞ ∨ b ≠ 0) :
(a * b)⁻¹ = a⁻¹ * b⁻¹ := by
induction' b with b
· replace ha : a ≠ 0 := ha.neg_resolve_right rfl
simp [ha]
induction' a with a
· replace hb : b ≠ 0 := coe_ne_zero.1 (hb.neg_resolve_left rfl)
simp [hb]
by_cases h'a : a = 0
· simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne,
not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero]
by_cases h'b : b = 0
· simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff,
mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero]
rw [← ENNReal.coe_mul, ← ENNReal.coe_inv, ← ENNReal.coe_inv h'a, ← ENNReal.coe_inv h'b, ←
ENNReal.coe_mul, mul_inv_rev, mul_comm]
simp [h'a, h'b]
protected theorem inv_div {a b : ℝ≥0∞} (htop : b ≠ ∞ ∨ a ≠ ∞) (hzero : b ≠ 0 ∨ a ≠ 0) :
(a / b)⁻¹ = b / a := by
rw [← ENNReal.inv_ne_zero] at htop
rw [← ENNReal.inv_ne_top] at hzero
rw [ENNReal.div_eq_inv_mul, ENNReal.div_eq_inv_mul, ENNReal.mul_inv htop hzero, mul_comm, inv_inv]
protected theorem mul_div_mul_left (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) :
c * a / (c * b) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', one_mul]
protected theorem mul_div_mul_right (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) :
a * c / (b * c) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', mul_one]
protected theorem sub_div (h : 0 < b → b < a → c ≠ 0) : (a - b) / c = a / c - b / c := by
simp_rw [div_eq_mul_inv]
exact ENNReal.sub_mul (by simpa using h)
@[simp]
protected theorem inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ :=
pos_iff_ne_zero.trans ENNReal.inv_ne_zero
theorem inv_strictAnti : StrictAnti (Inv.inv : ℝ≥0∞ → ℝ≥0∞) := by
intro a b h
lift a to ℝ≥0 using h.ne_top
induction b; · simp
rw [coe_lt_coe] at h
rcases eq_or_ne a 0 with (rfl | ha); · simp [h]
rw [← coe_inv h.ne_bot, ← coe_inv ha, coe_lt_coe]
exact NNReal.inv_lt_inv ha h
@[simp]
protected theorem inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a :=
inv_strictAnti.lt_iff_lt
theorem inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by
simpa only [inv_inv] using @ENNReal.inv_lt_inv a b⁻¹
theorem lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by
simpa only [inv_inv] using @ENNReal.inv_lt_inv a⁻¹ b
@[simp]
protected theorem inv_le_inv : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
inv_strictAnti.le_iff_le
theorem inv_le_iff_inv_le : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by
simpa only [inv_inv] using @ENNReal.inv_le_inv a b⁻¹
theorem le_inv_iff_le_inv : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by
simpa only [inv_inv] using @ENNReal.inv_le_inv a⁻¹ b
@[gcongr] protected theorem inv_le_inv' (h : a ≤ b) : b⁻¹ ≤ a⁻¹ :=
ENNReal.inv_strictAnti.antitone h
@[gcongr] protected theorem inv_lt_inv' (h : a < b) : b⁻¹ < a⁻¹ := ENNReal.inv_strictAnti h
@[simp]
protected theorem inv_le_one : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [inv_le_iff_inv_le, inv_one]
protected theorem one_le_inv : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [le_inv_iff_le_inv, inv_one]
@[simp]
protected theorem inv_lt_one : a⁻¹ < 1 ↔ 1 < a := by rw [inv_lt_iff_inv_lt, inv_one]
@[simp]
protected theorem one_lt_inv : 1 < a⁻¹ ↔ a < 1 := by rw [lt_inv_iff_lt_inv, inv_one]
/-- The inverse map `fun x ↦ x⁻¹` is an order isomorphism between `ℝ≥0∞` and its `OrderDual` -/
@[simps! apply]
def _root_.OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ where
map_rel_iff' := ENNReal.inv_le_inv
toEquiv := (Equiv.inv ℝ≥0∞).trans OrderDual.toDual
@[simp]
theorem _root_.OrderIso.invENNReal_symm_apply (a : ℝ≥0∞ᵒᵈ) :
OrderIso.invENNReal.symm a = (OrderDual.ofDual a)⁻¹ :=
rfl
@[simp] theorem div_top : a / ∞ = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero]
theorem top_div : ∞ / a = if a = ∞ then 0 else ∞ := by simp [div_eq_mul_inv, top_mul']
theorem top_div_of_ne_top (h : a ≠ ∞) : ∞ / a = ∞ := by simp [top_div, h]
@[simp] theorem top_div_coe : ∞ / p = ∞ := top_div_of_ne_top coe_ne_top
theorem top_div_of_lt_top (h : a < ∞) : ∞ / a = ∞ := top_div_of_ne_top h.ne
@[simp] protected theorem zero_div : 0 / a = 0 := zero_mul a⁻¹
theorem div_eq_top : a / b = ∞ ↔ a ≠ 0 ∧ b = 0 ∨ a = ∞ ∧ b ≠ ∞ := by
simp [div_eq_mul_inv, ENNReal.mul_eq_top]
protected theorem le_div_iff_mul_le (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) :
a ≤ c / b ↔ a * b ≤ c := by
induction' b with b
· lift c to ℝ≥0 using ht.neg_resolve_left rfl
rw [div_top, nonpos_iff_eq_zero]
rcases eq_or_ne a 0 with (rfl | ha) <;> simp [*]
rcases eq_or_ne b 0 with (rfl | hb)
· have hc : c ≠ 0 := h0.neg_resolve_left rfl
simp [div_zero hc]
· rw [← coe_ne_zero] at hb
rw [← ENNReal.mul_le_mul_right hb coe_ne_top, ENNReal.div_mul_cancel hb coe_ne_top]
protected theorem div_le_iff_le_mul (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) :
a / b ≤ c ↔ a ≤ c * b := by
suffices a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹ by simpa [div_eq_mul_inv]
refine (ENNReal.le_div_iff_mul_le ?_ ?_).symm <;> simpa
protected theorem lt_div_iff_mul_lt (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) :
c < a / b ↔ c * b < a :=
lt_iff_lt_of_le_iff_le (ENNReal.div_le_iff_le_mul hb0 hbt)
theorem div_le_of_le_mul (h : a ≤ b * c) : a / c ≤ b := by
by_cases h0 : c = 0
· have : a = 0 := by simpa [h0] using h
simp [*]
by_cases hinf : c = ∞; · simp [hinf]
exact (ENNReal.div_le_iff_le_mul (Or.inl h0) (Or.inl hinf)).2 h
theorem div_le_of_le_mul' (h : a ≤ b * c) : a / b ≤ c :=
div_le_of_le_mul <| mul_comm b c ▸ h
@[simp] protected theorem div_self_le_one : a / a ≤ 1 := div_le_of_le_mul <| by rw [one_mul]
@[simp] protected lemma mul_inv_le_one (a : ℝ≥0∞) : a * a⁻¹ ≤ 1 := ENNReal.div_self_le_one
@[simp] protected lemma inv_mul_le_one (a : ℝ≥0∞) : a⁻¹ * a ≤ 1 := by simp [mul_comm]
@[simp] lemma mul_inv_ne_top (a : ℝ≥0∞) : a * a⁻¹ ≠ ⊤ :=
ne_top_of_le_ne_top one_ne_top a.mul_inv_le_one
@[simp] lemma inv_mul_ne_top (a : ℝ≥0∞) : a⁻¹ * a ≠ ⊤ := by simp [mul_comm]
theorem mul_le_of_le_div (h : a ≤ b / c) : a * c ≤ b := by
rw [← inv_inv c]
exact div_le_of_le_mul h
theorem mul_le_of_le_div' (h : a ≤ b / c) : c * a ≤ b :=
mul_comm a c ▸ mul_le_of_le_div h
protected theorem div_lt_iff (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) : c / b < a ↔ c < a * b :=
lt_iff_lt_of_le_iff_le <| ENNReal.le_div_iff_mul_le h0 ht
theorem mul_lt_of_lt_div (h : a < b / c) : a * c < b := by
contrapose! h
exact ENNReal.div_le_of_le_mul h
theorem mul_lt_of_lt_div' (h : a < b / c) : c * a < b :=
mul_comm a c ▸ mul_lt_of_lt_div h
theorem div_lt_of_lt_mul (h : a < b * c) : a / c < b :=
mul_lt_of_lt_div <| by rwa [div_eq_mul_inv, inv_inv]
theorem div_lt_of_lt_mul' (h : a < b * c) : a / b < c :=
div_lt_of_lt_mul <| by rwa [mul_comm]
theorem inv_le_iff_le_mul (h₁ : b = ∞ → a ≠ 0) (h₂ : a = ∞ → b ≠ 0) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by
rw [← one_div, ENNReal.div_le_iff_le_mul, mul_comm]
exacts [or_not_of_imp h₁, not_or_of_imp h₂]
@[simp 900]
theorem le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 := by
rw [← one_div, ENNReal.le_div_iff_mul_le] <;>
· right
simp
@[gcongr] protected theorem div_le_div (hab : a ≤ b) (hdc : d ≤ c) : a / c ≤ b / d :=
div_eq_mul_inv b d ▸ div_eq_mul_inv a c ▸ mul_le_mul' hab (ENNReal.inv_le_inv.mpr hdc)
@[gcongr] protected theorem div_le_div_left (h : a ≤ b) (c : ℝ≥0∞) : c / b ≤ c / a :=
ENNReal.div_le_div le_rfl h
@[gcongr] protected theorem div_le_div_right (h : a ≤ b) (c : ℝ≥0∞) : a / c ≤ b / c :=
ENNReal.div_le_div h le_rfl
protected theorem eq_inv_of_mul_eq_one_left (h : a * b = 1) : a = b⁻¹ := by
rw [← mul_one a, ← ENNReal.mul_inv_cancel (right_ne_zero_of_mul_eq_one h), ← mul_assoc, h,
one_mul]
rintro rfl
simp [left_ne_zero_of_mul_eq_one h] at h
theorem mul_le_iff_le_inv {a b r : ℝ≥0∞} (hr₀ : r ≠ 0) (hr₁ : r ≠ ∞) : r * a ≤ b ↔ a ≤ r⁻¹ * b := by
rw [← @ENNReal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, ENNReal.mul_inv_cancel hr₀ hr₁,
one_mul]
theorem le_of_forall_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r < x → ↑r ≤ y) : x ≤ y := by
refine le_of_forall_lt_imp_le_of_dense fun r hr => ?_
lift r to ℝ≥0 using ne_top_of_lt hr
exact h r hr
lemma eq_of_forall_nnreal_iff {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r ≤ x ↔ ↑r ≤ y) : x = y :=
le_antisymm (le_of_forall_nnreal_lt fun _r hr ↦ (h _).1 hr.le)
(le_of_forall_nnreal_lt fun _r hr ↦ (h _).2 hr.le)
theorem le_of_forall_pos_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, 0 < r → ↑r < x → ↑r ≤ y) : x ≤ y :=
le_of_forall_nnreal_lt fun r hr =>
(zero_le r).eq_or_lt.elim (fun h => h ▸ zero_le _) fun h0 => h r h0 hr
theorem eq_top_of_forall_nnreal_le {x : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r ≤ x) : x = ∞ :=
top_unique <| le_of_forall_nnreal_lt fun r _ => h r
protected theorem add_div : (a + b) / c = a / c + b / c :=
right_distrib a b c⁻¹
protected theorem div_add_div_same {a b c : ℝ≥0∞} : a / c + b / c = (a + b) / c :=
ENNReal.add_div.symm
protected theorem div_self (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 :=
ENNReal.mul_inv_cancel h0 hI
theorem mul_div_le : a * (b / a) ≤ b :=
mul_le_of_le_div' le_rfl
theorem eq_div_iff (ha : a ≠ 0) (ha' : a ≠ ∞) : b = c / a ↔ a * b = c :=
⟨fun h => by rw [h, ENNReal.mul_div_cancel ha ha'], fun h => by
rw [← h, mul_div_assoc, ENNReal.mul_div_cancel ha ha']⟩
protected theorem div_eq_div_iff (ha : a ≠ 0) (ha' : a ≠ ∞) (hb : b ≠ 0) (hb' : b ≠ ∞) :
c / b = d / a ↔ a * c = b * d := by
rw [eq_div_iff ha ha']
conv_rhs => rw [eq_comm]
rw [← eq_div_iff hb hb', mul_div_assoc, eq_comm]
theorem div_eq_one_iff {a b : ℝ≥0∞} (hb₀ : b ≠ 0) (hb₁ : b ≠ ∞) : a / b = 1 ↔ a = b :=
⟨fun h => by rw [← (eq_div_iff hb₀ hb₁).mp h.symm, mul_one], fun h =>
h.symm ▸ ENNReal.div_self hb₀ hb₁⟩
theorem inv_two_add_inv_two : (2 : ℝ≥0∞)⁻¹ + 2⁻¹ = 1 := by
rw [← two_mul, ← div_eq_mul_inv, ENNReal.div_self two_ne_zero ofNat_ne_top]
theorem inv_three_add_inv_three : (3 : ℝ≥0∞)⁻¹ + 3⁻¹ + 3⁻¹ = 1 := by
rw [← ENNReal.mul_inv_cancel three_ne_zero ofNat_ne_top]
ring
@[simp]
protected theorem add_halves (a : ℝ≥0∞) : a / 2 + a / 2 = a := by
rw [div_eq_mul_inv, ← mul_add, inv_two_add_inv_two, mul_one]
@[simp]
theorem add_thirds (a : ℝ≥0∞) : a / 3 + a / 3 + a / 3 = a := by
rw [div_eq_mul_inv, ← mul_add, ← mul_add, inv_three_add_inv_three, mul_one]
@[simp] theorem div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = ∞ := by simp [div_eq_mul_inv]
@[simp] theorem div_pos_iff : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ∞ := by simp [pos_iff_ne_zero, not_or]
protected lemma div_ne_zero : a / b ≠ 0 ↔ a ≠ 0 ∧ b ≠ ∞ := by
rw [← pos_iff_ne_zero, div_pos_iff]
protected lemma div_mul (a : ℝ≥0∞) (h0 : b ≠ 0 ∨ c ≠ 0) (htop : b ≠ ∞ ∨ c ≠ ∞) :
a / b * c = a / (b / c) := by
simp only [div_eq_mul_inv]
rw [ENNReal.mul_inv, inv_inv]
· ring
· simpa
· simpa
protected lemma mul_div_mul_comm (hc : c ≠ 0 ∨ d ≠ ∞) (hd : c ≠ ∞ ∨ d ≠ 0) :
a * b / (c * d) = a / c * (b / d) := by
simp only [div_eq_mul_inv, ENNReal.mul_inv hc hd]
ring
protected theorem half_pos (h : a ≠ 0) : 0 < a / 2 :=
ENNReal.div_pos h ofNat_ne_top
protected theorem one_half_lt_one : (2⁻¹ : ℝ≥0∞) < 1 :=
ENNReal.inv_lt_one.2 <| one_lt_two
protected theorem half_lt_self (hz : a ≠ 0) (ht : a ≠ ∞) : a / 2 < a := by
lift a to ℝ≥0 using ht
rw [coe_ne_zero] at hz
rw [← coe_two, ← coe_div, coe_lt_coe]
exacts [NNReal.half_lt_self hz, two_ne_zero' _]
protected theorem half_le_self : a / 2 ≤ a :=
le_add_self.trans_eq <| ENNReal.add_halves _
theorem sub_half (h : a ≠ ∞) : a - a / 2 = a / 2 := ENNReal.sub_eq_of_eq_add' h a.add_halves.symm
@[simp]
theorem one_sub_inv_two : (1 : ℝ≥0∞) - 2⁻¹ = 2⁻¹ := by
rw [← one_div, sub_half one_ne_top]
private lemma exists_lt_mul_left {a b c : ℝ≥0∞} (hc : c < a * b) : ∃ a' < a, c < a' * b := by
obtain ⟨a', hc, ha'⟩ := exists_between (ENNReal.div_lt_of_lt_mul hc)
exact ⟨_, ha', (ENNReal.div_lt_iff (.inl <| by rintro rfl; simp at *)
(.inr <| by rintro rfl; simp at *)).1 hc⟩
private lemma exists_lt_mul_right {a b c : ℝ≥0∞} (hc : c < a * b) : ∃ b' < b, c < a * b' := by
simp_rw [mul_comm a] at hc ⊢; exact exists_lt_mul_left hc
lemma mul_le_of_forall_lt {a b c : ℝ≥0∞} (h : ∀ a' < a, ∀ b' < b, a' * b' ≤ c) : a * b ≤ c := by
refine le_of_forall_lt_imp_le_of_dense fun d hd ↦ ?_
obtain ⟨a', ha', hd⟩ := exists_lt_mul_left hd
obtain ⟨b', hb', hd⟩ := exists_lt_mul_right hd
exact le_trans hd.le <| h _ ha' _ hb'
lemma le_mul_of_forall_lt {a b c : ℝ≥0∞} (h₁ : a ≠ 0 ∨ b ≠ ∞) (h₂ : a ≠ ∞ ∨ b ≠ 0)
(h : ∀ a' > a, ∀ b' > b, c ≤ a' * b') : c ≤ a * b := by
rw [← ENNReal.inv_le_inv, ENNReal.mul_inv h₁ h₂]
exact mul_le_of_forall_lt fun a' ha' b' hb' ↦ ENNReal.le_inv_iff_le_inv.1 <|
(h _ (ENNReal.lt_inv_iff_lt_inv.1 ha') _ (ENNReal.lt_inv_iff_lt_inv.1 hb')).trans_eq
(ENNReal.mul_inv (Or.inr hb'.ne_top) (Or.inl ha'.ne_top)).symm
/-- The birational order isomorphism between `ℝ≥0∞` and the unit interval `Set.Iic (1 : ℝ≥0∞)`. -/
@[simps! apply_coe]
def orderIsoIicOneBirational : ℝ≥0∞ ≃o Iic (1 : ℝ≥0∞) := by
refine StrictMono.orderIsoOfRightInverse
(fun x => ⟨(x⁻¹ + 1)⁻¹, ENNReal.inv_le_one.2 <| le_add_self⟩)
(fun x y hxy => ?_) (fun x => (x.1⁻¹ - 1)⁻¹) fun x => Subtype.ext ?_
· simpa only [Subtype.mk_lt_mk, ENNReal.inv_lt_inv, ENNReal.add_lt_add_iff_right one_ne_top]
· have : (1 : ℝ≥0∞) ≤ x.1⁻¹ := ENNReal.one_le_inv.2 x.2
simp only [inv_inv, Subtype.coe_mk, tsub_add_cancel_of_le this]
@[simp]
theorem orderIsoIicOneBirational_symm_apply (x : Iic (1 : ℝ≥0∞)) :
orderIsoIicOneBirational.symm x = (x.1⁻¹ - 1)⁻¹ :=
rfl
/-- Order isomorphism between an initial interval in `ℝ≥0∞` and an initial interval in `ℝ≥0`. -/
@[simps! apply_coe]
def orderIsoIicCoe (a : ℝ≥0) : Iic (a : ℝ≥0∞) ≃o Iic a :=
OrderIso.symm
{ toFun := fun x => ⟨x, coe_le_coe.2 x.2⟩
invFun := fun x => ⟨ENNReal.toNNReal x, coe_le_coe.1 <| coe_toNNReal_le_self.trans x.2⟩
left_inv := fun _ => Subtype.ext <| toNNReal_coe _
right_inv := fun x => Subtype.ext <| coe_toNNReal (ne_top_of_le_ne_top coe_ne_top x.2)
map_rel_iff' := fun {_ _} => by
simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, coe_le_coe, Subtype.coe_le_coe] }
@[simp]
theorem orderIsoIicCoe_symm_apply_coe (a : ℝ≥0) (b : Iic a) :
((orderIsoIicCoe a).symm b : ℝ≥0∞) = b :=
rfl
/-- An order isomorphism between the extended nonnegative real numbers and the unit interval. -/
def orderIsoUnitIntervalBirational : ℝ≥0∞ ≃o Icc (0 : ℝ) 1 :=
orderIsoIicOneBirational.trans <| (orderIsoIicCoe 1).trans <| (NNReal.orderIsoIccZeroCoe 1).symm
@[simp]
theorem orderIsoUnitIntervalBirational_apply_coe (x : ℝ≥0∞) :
(orderIsoUnitIntervalBirational x : ℝ) = (x⁻¹ + 1)⁻¹.toReal :=
rfl
theorem exists_inv_nat_lt {a : ℝ≥0∞} (h : a ≠ 0) : ∃ n : ℕ, (n : ℝ≥0∞)⁻¹ < a :=
inv_inv a ▸ by simp only [ENNReal.inv_lt_inv, ENNReal.exists_nat_gt (inv_ne_top.2 h)]
theorem exists_nat_pos_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) : ∃ n > 0, b < (n : ℕ) * a :=
let ⟨n, hn⟩ := ENNReal.exists_nat_gt (div_lt_top hb ha).ne
⟨n, Nat.cast_pos.1 ((zero_le _).trans_lt hn), by
rwa [← ENNReal.div_lt_iff (Or.inl ha) (Or.inr hb)]⟩
theorem exists_nat_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) : ∃ n : ℕ, b < n * a :=
(exists_nat_pos_mul_gt ha hb).imp fun _ => And.right
theorem exists_nat_pos_inv_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) :
∃ n > 0, ((n : ℕ) : ℝ≥0∞)⁻¹ * a < b := by
rcases exists_nat_pos_mul_gt hb ha with ⟨n, npos, hn⟩
use n, npos
rw [← ENNReal.div_eq_inv_mul]
exact div_lt_of_lt_mul' hn
theorem exists_nnreal_pos_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) : ∃ n > 0, ↑(n : ℝ≥0) * a < b := by
rcases exists_nat_pos_inv_mul_lt ha hb with ⟨n, npos : 0 < n, hn⟩
use (n : ℝ≥0)⁻¹
simp [*, npos.ne', zero_lt_one]
theorem exists_inv_two_pow_lt (ha : a ≠ 0) : ∃ n : ℕ, 2⁻¹ ^ n < a := by
rcases exists_inv_nat_lt ha with ⟨n, hn⟩
refine ⟨n, lt_trans ?_ hn⟩
rw [← ENNReal.inv_pow, ENNReal.inv_lt_inv]
norm_cast
exact n.lt_two_pow_self
@[simp, norm_cast]
theorem coe_zpow (hr : r ≠ 0) (n : ℤ) : (↑(r ^ n) : ℝ≥0∞) = (r : ℝ≥0∞) ^ n := by
rcases n with n | n
· simp only [Int.ofNat_eq_coe, coe_pow, zpow_natCast]
· have : r ^ n.succ ≠ 0 := pow_ne_zero (n + 1) hr
simp only [zpow_negSucc, coe_inv this, coe_pow]
theorem zpow_pos (ha : a ≠ 0) (h'a : a ≠ ∞) (n : ℤ) : 0 < a ^ n := by
cases n
· simpa using ENNReal.pow_pos ha.bot_lt _
· simp only [h'a, pow_eq_top_iff, zpow_negSucc, Ne, not_false, ENNReal.inv_pos, false_and,
not_false_eq_true]
theorem zpow_lt_top (ha : a ≠ 0) (h'a : a ≠ ∞) (n : ℤ) : a ^ n < ∞ := by
cases n
· simpa using ENNReal.pow_lt_top h'a.lt_top
· simp only [ENNReal.pow_pos ha.bot_lt, zpow_negSucc, inv_lt_top]
theorem exists_mem_Ico_zpow {x y : ℝ≥0∞} (hx : x ≠ 0) (h'x : x ≠ ∞) (hy : 1 < y) (h'y : y ≠ ⊤) :
∃ n : ℤ, x ∈ Ico (y ^ n) (y ^ (n + 1)) := by
lift x to ℝ≥0 using h'x
lift y to ℝ≥0 using h'y
have A : y ≠ 0 := by simpa only [Ne, coe_eq_zero] using (zero_lt_one.trans hy).ne'
obtain ⟨n, hn, h'n⟩ : ∃ n : ℤ, y ^ n ≤ x ∧ x < y ^ (n + 1) := by
refine NNReal.exists_mem_Ico_zpow ?_ (one_lt_coe_iff.1 hy)
simpa only [Ne, coe_eq_zero] using hx
refine ⟨n, ?_, ?_⟩
· rwa [← ENNReal.coe_zpow A, ENNReal.coe_le_coe]
· rwa [← ENNReal.coe_zpow A, ENNReal.coe_lt_coe]
theorem exists_mem_Ioc_zpow {x y : ℝ≥0∞} (hx : x ≠ 0) (h'x : x ≠ ∞) (hy : 1 < y) (h'y : y ≠ ⊤) :
| ∃ n : ℤ, x ∈ Ioc (y ^ n) (y ^ (n + 1)) := by
lift x to ℝ≥0 using h'x
lift y to ℝ≥0 using h'y
have A : y ≠ 0 := by simpa only [Ne, coe_eq_zero] using (zero_lt_one.trans hy).ne'
obtain ⟨n, hn, h'n⟩ : ∃ n : ℤ, y ^ n < x ∧ x ≤ y ^ (n + 1) := by
refine NNReal.exists_mem_Ioc_zpow ?_ (one_lt_coe_iff.1 hy)
simpa only [Ne, coe_eq_zero] using hx
refine ⟨n, ?_, ?_⟩
· rwa [← ENNReal.coe_zpow A, ENNReal.coe_lt_coe]
· rwa [← ENNReal.coe_zpow A, ENNReal.coe_le_coe]
theorem Ioo_zero_top_eq_iUnion_Ico_zpow {y : ℝ≥0∞} (hy : 1 < y) (h'y : y ≠ ⊤) :
Ioo (0 : ℝ≥0∞) (∞ : ℝ≥0∞) = ⋃ n : ℤ, Ico (y ^ n) (y ^ (n + 1)) := by
| Mathlib/Data/ENNReal/Inv.lean | 650 | 662 |
/-
Copyright (c) 2019 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Module.Submodule.Equiv
import Mathlib.Algebra.Module.Equiv.Basic
import Mathlib.Algebra.Module.Rat
import Mathlib.Data.Bracket
import Mathlib.Tactic.Abel
/-!
# Lie algebras
This file defines Lie rings and Lie algebras over a commutative ring together with their
modules, morphisms and equivalences, as well as various lemmas to make these definitions usable.
## Main definitions
* `LieRing`
* `LieAlgebra`
* `LieRingModule`
* `LieModule`
* `LieHom`
* `LieEquiv`
* `LieModuleHom`
* `LieModuleEquiv`
## Notation
Working over a fixed commutative ring `R`, we introduce the notations:
* `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras,
* `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras,
* `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`,
* `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`.
## Implementation notes
Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules,
are partially unbundled.
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975)
## Tags
lie bracket, jacobi identity, lie ring, lie algebra, lie module
-/
universe u v w w₁ w₂
open Function
/-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the
Jacobi identity. -/
class LieRing (L : Type v) extends AddCommGroup L, Bracket L L where
/-- A Lie ring bracket is additive in its first component. -/
protected add_lie : ∀ x y z : L, ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆
/-- A Lie ring bracket is additive in its second component. -/
protected lie_add : ∀ x y z : L, ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆
/-- A Lie ring bracket vanishes on the diagonal in L × L. -/
protected lie_self : ∀ x : L, ⁅x, x⁆ = 0
/-- A Lie ring bracket satisfies a Leibniz / Jacobi identity. -/
protected leibniz_lie : ∀ x y z : L, ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆
/-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi
identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/
@[ext] class LieAlgebra (R : Type u) (L : Type v) [CommRing R] [LieRing L] extends Module R L where
/-- A Lie algebra bracket is compatible with scalar multiplication in its second argument.
The compatibility in the first argument is not a class property, but follows since every
Lie algebra has a natural Lie module action on itself, see `LieModule`. -/
protected lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆
/-- A Lie ring module is an additive group, together with an additive action of a
Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms.
(For representations of Lie *algebras* see `LieModule`.) -/
class LieRingModule (L : Type v) (M : Type w) [LieRing L] [AddCommGroup M] extends Bracket L M where
/-- A Lie ring module bracket is additive in its first component. -/
protected add_lie : ∀ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆
/-- A Lie ring module bracket is additive in its second component. -/
protected lie_add : ∀ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆
/-- A Lie ring module bracket satisfies a Leibniz / Jacobi identity. -/
protected leibniz_lie : ∀ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆
/-- A Lie module is a module over a commutative ring, together with a linear action of a Lie
algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/
class LieModule (R : Type u) (L : Type v) (M : Type w) [CommRing R] [LieRing L] [LieAlgebra R L]
[AddCommGroup M] [Module R M] [LieRingModule L M] : Prop where
/-- A Lie module bracket is compatible with scalar multiplication in its first argument. -/
protected smul_lie : ∀ (t : R) (x : L) (m : M), ⁅t • x, m⁆ = t • ⁅x, m⁆
/-- A Lie module bracket is compatible with scalar multiplication in its second argument. -/
protected lie_smul : ∀ (t : R) (x : L) (m : M), ⁅x, t • m⁆ = t • ⁅x, m⁆
/-- A tower of Lie bracket actions encapsulates the Leibniz rule for Lie bracket actions.
More precisely, it does so in a relative setting:
Let `L₁` and `L₂` be two types with Lie bracket actions on a type `M` endowed with an addition,
and additionally assume a Lie bracket action of `L₁` on `L₂`.
Then the Leibniz rule asserts for all `x : L₁`, `y : L₂`, and `m : M` that
`⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆` holds.
Common examples include the case where `L₁` is a Lie subalgebra of `L₂`
and the case where `L₂` is a Lie ideal of `L₁`. -/
class IsLieTower (L₁ L₂ M : Type*) [Bracket L₁ L₂] [Bracket L₁ M] [Bracket L₂ M] [Add M] where
protected leibniz_lie (x : L₁) (y : L₂) (m : M) : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆
section IsLieTower
variable {L₁ L₂ M : Type*} [Bracket L₁ L₂] [Bracket L₁ M] [Bracket L₂ M]
lemma leibniz_lie [Add M] [IsLieTower L₁ L₂ M] (x : L₁) (y : L₂) (m : M) :
⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := IsLieTower.leibniz_lie x y m
lemma lie_swap_lie [Bracket L₂ L₁] [AddCommGroup M] [IsLieTower L₁ L₂ M] [IsLieTower L₂ L₁ M]
(x : L₁) (y : L₂) (m : M) : ⁅⁅x, y⁆, m⁆ = -⁅⁅y, x⁆, m⁆ := by
have h1 := leibniz_lie x y m
have h2 := leibniz_lie y x m
convert congr($h1.symm - $h2) using 1 <;> simp only [add_sub_cancel_right, sub_add_cancel_right]
end IsLieTower
section BasicProperties
theorem LieAlgebra.toModule_injective (L : Type*) [LieRing L] :
Function.Injective (@LieAlgebra.toModule _ _ _ _ : LieAlgebra ℚ L → Module ℚ L) := by
rintro ⟨h₁⟩ ⟨h₂⟩ heq
congr
instance (L : Type*) [LieRing L] : Subsingleton (LieAlgebra ℚ L) :=
LieAlgebra.toModule_injective L |>.subsingleton
variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁}
variable [CommRing R] [LieRing L] [LieAlgebra R L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N]
variable (t : R) (x y z : L) (m n : M)
@[simp]
theorem add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ :=
LieRingModule.add_lie x y m
@[simp]
theorem lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ :=
LieRingModule.lie_add x m n
@[simp]
theorem smul_lie : ⁅t • x, m⁆ = t • ⁅x, m⁆ :=
LieModule.smul_lie t x m
@[simp]
theorem lie_smul : ⁅x, t • m⁆ = t • ⁅x, m⁆ :=
LieModule.lie_smul t x m
instance : IsLieTower L L M where
leibniz_lie x y m := LieRingModule.leibniz_lie x y m
@[simp]
theorem lie_zero : ⁅x, 0⁆ = (0 : M) :=
(AddMonoidHom.mk' _ (lie_add x)).map_zero
@[simp]
theorem zero_lie : ⁅(0 : L), m⁆ = 0 :=
(AddMonoidHom.mk' (fun x : L => ⁅x, m⁆) fun x y => add_lie x y m).map_zero
@[simp]
theorem lie_self : ⁅x, x⁆ = 0 :=
LieRing.lie_self x
instance lieRingSelfModule : LieRingModule L L :=
{ (inferInstance : LieRing L) with }
@[simp]
theorem lie_skew : -⁅y, x⁆ = ⁅x, y⁆ := by
have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0 := by rw [← lie_add]; apply lie_self
simpa [neg_eq_iff_add_eq_zero] using h
/-- Every Lie algebra is a module over itself. -/
instance lieAlgebraSelfModule : LieModule R L L where
smul_lie t x m := by rw [← lie_skew, ← lie_skew x m, LieAlgebra.lie_smul, smul_neg]
lie_smul := by apply LieAlgebra.lie_smul
@[simp]
theorem neg_lie : ⁅-x, m⁆ = -⁅x, m⁆ := by
rw [← sub_eq_zero, sub_neg_eq_add, ← add_lie]
simp
@[simp]
theorem lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ := by
rw [← sub_eq_zero, sub_neg_eq_add, ← lie_add]
simp
@[simp]
theorem sub_lie : ⁅x - y, m⁆ = ⁅x, m⁆ - ⁅y, m⁆ := by simp [sub_eq_add_neg]
@[simp]
theorem lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ := by simp [sub_eq_add_neg]
@[simp]
theorem nsmul_lie (n : ℕ) : ⁅n • x, m⁆ = n • ⁅x, m⁆ :=
AddMonoidHom.map_nsmul
{ toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ }
_ _
@[simp]
theorem lie_nsmul (n : ℕ) : ⁅x, n • m⁆ = n • ⁅x, m⁆ :=
AddMonoidHom.map_nsmul
{ toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _}
_ _
theorem zsmul_lie (a : ℤ) : ⁅a • x, m⁆ = a • ⁅x, m⁆ :=
AddMonoidHom.map_zsmul
{ toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ }
_ _
theorem lie_zsmul (a : ℤ) : ⁅x, a • m⁆ = a • ⁅x, m⁆ :=
AddMonoidHom.map_zsmul
{ toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _ }
_ _
@[simp]
lemma lie_lie : ⁅⁅x, y⁆, m⁆ = ⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆ := by rw [leibniz_lie, add_sub_cancel_right]
theorem lie_jacobi : ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 := by
rw [← neg_neg ⁅x, y⁆, lie_neg z, lie_skew y x, ← lie_skew, lie_lie]
abel
instance LieRing.instLieAlgebra : LieAlgebra ℤ L where lie_smul n x y := lie_zsmul x y n
instance : LieModule ℤ L M where
smul_lie n x m := zsmul_lie x m n
lie_smul n x m := lie_zsmul x m n
instance LinearMap.instLieRingModule : LieRingModule L (M →ₗ[R] N) where
bracket x f :=
{ toFun := fun m => ⁅x, f m⁆ - f ⁅x, m⁆
map_add' := fun m n => by
simp only [lie_add, LinearMap.map_add]
abel
map_smul' := fun t m => by
simp only [smul_sub, LinearMap.map_smul, lie_smul, RingHom.id_apply] }
add_lie x y f := by
ext n
simp only [add_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.add_apply, LinearMap.map_add]
abel
lie_add x f g := by
ext n
simp only [LinearMap.coe_mk, AddHom.coe_mk, lie_add, LinearMap.add_apply]
abel
leibniz_lie x y f := by
ext n
simp only [lie_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.map_sub, LinearMap.add_apply,
lie_sub]
abel
@[simp]
theorem LieHom.lie_apply (f : M →ₗ[R] N) (x : L) (m : M) : ⁅x, f⁆ m = ⁅x, f m⁆ - f ⁅x, m⁆ :=
rfl
instance LinearMap.instLieModule : LieModule R L (M →ₗ[R] N) where
smul_lie t x f := by
ext n
simp only [smul_sub, smul_lie, LinearMap.smul_apply, LieHom.lie_apply, LinearMap.map_smul]
lie_smul t x f := by
ext n
simp only [smul_sub, LinearMap.smul_apply, LieHom.lie_apply, lie_smul]
/-- We could avoid defining this by instead defining a `LieRingModule L R` instance with a zero
bracket and relying on `LinearMap.instLieRingModule`. We do not do this because in the case that
`L = R` we would have a non-defeq diamond via `Ring.instBracket`. -/
instance Module.Dual.instLieRingModule : LieRingModule L (M →ₗ[R] R) where
bracket := fun x f ↦
{ toFun := fun m ↦ - f ⁅x, m⁆
map_add' := by simp [-neg_add_rev, neg_add]
map_smul' := by simp }
add_lie := fun x y m ↦ by ext n; simp [-neg_add_rev, neg_add]
lie_add := fun x m n ↦ by ext p; simp [-neg_add_rev, neg_add]
leibniz_lie := fun x m n ↦ by ext p; simp
@[simp] lemma Module.Dual.lie_apply (f : M →ₗ[R] R) : ⁅x, f⁆ m = - f ⁅x, m⁆ := rfl
instance Module.Dual.instLieModule : LieModule R L (M →ₗ[R] R) where
smul_lie := fun t x m ↦ by ext n; simp
lie_smul := fun t x m ↦ by ext n; simp
variable (L) in
/-- It is sometimes useful to regard a `LieRing` as a `NonUnitalNonAssocRing`. -/
def LieRing.toNonUnitalNonAssocRing : NonUnitalNonAssocRing L :=
{ mul := Bracket.bracket
left_distrib := lie_add
right_distrib := add_lie
zero_mul := zero_lie
mul_zero := lie_zero }
variable {ι κ : Type*}
theorem sum_lie (s : Finset ι) (f : ι → L) (a : L) : ⁅∑ i ∈ s, f i, a⁆ = ∑ i ∈ s, ⁅f i, a⁆ :=
let _i := LieRing.toNonUnitalNonAssocRing L
s.sum_mul f a
theorem lie_sum (s : Finset ι) (f : ι → L) (a : L) : ⁅a, ∑ i ∈ s, f i⁆ = ∑ i ∈ s, ⁅a, f i⁆ :=
let _i := LieRing.toNonUnitalNonAssocRing L
s.mul_sum f a
theorem sum_lie_sum {κ : Type*} (s : Finset ι) (t : Finset κ) (f : ι → L) (g : κ → L) :
⁅(∑ i ∈ s, f i), ∑ j ∈ t, g j⁆ = ∑ i ∈ s, ∑ j ∈ t, ⁅f i, g j⁆ :=
let _i := LieRing.toNonUnitalNonAssocRing L
s.sum_mul_sum t f g
end BasicProperties
/-- A morphism of Lie algebras (denoted as `L₁ →ₗ⁅R⁆ L₂`)
is a linear map respecting the bracket operations. -/
structure LieHom (R L L' : Type*) [CommRing R] [LieRing L] [LieAlgebra R L]
[LieRing L'] [LieAlgebra R L'] extends L →ₗ[R] L' where
/-- A morphism of Lie algebras is compatible with brackets. -/
map_lie' : ∀ {x y : L}, toFun ⁅x, y⁆ = ⁅toFun x, toFun y⁆
@[inherit_doc]
notation:25 L " →ₗ⁅" R:25 "⁆ " L':0 => LieHom R L L'
namespace LieHom
variable {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variable [CommRing R]
variable [LieRing L₁] [LieAlgebra R L₁]
variable [LieRing L₂] [LieAlgebra R L₂]
variable [LieRing L₃] [LieAlgebra R L₃]
attribute [coe] LieHom.toLinearMap
instance : Coe (L₁ →ₗ⁅R⁆ L₂) (L₁ →ₗ[R] L₂) :=
⟨LieHom.toLinearMap⟩
instance : FunLike (L₁ →ₗ⁅R⁆ L₂) L₁ L₂ where
coe f := f.toFun
coe_injective' x y h := by
cases x; cases y; simp at h; simp [h]
initialize_simps_projections LieHom (toFun → apply)
@[simp, norm_cast]
theorem coe_toLinearMap (f : L₁ →ₗ⁅R⁆ L₂) : ⇑(f : L₁ →ₗ[R] L₂) = f :=
rfl
@[simp]
theorem toFun_eq_coe (f : L₁ →ₗ⁅R⁆ L₂) : f.toFun = ⇑f :=
rfl
@[simp]
theorem map_smul (f : L₁ →ₗ⁅R⁆ L₂) (c : R) (x : L₁) : f (c • x) = c • f x :=
LinearMap.map_smul (f : L₁ →ₗ[R] L₂) c x
@[simp]
theorem map_add (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x + y) = f x + f y :=
LinearMap.map_add (f : L₁ →ₗ[R] L₂) x y
@[simp]
theorem map_sub (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x - y) = f x - f y :=
LinearMap.map_sub (f : L₁ →ₗ[R] L₂) x y
@[simp]
theorem map_neg (f : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f (-x) = -f x :=
LinearMap.map_neg (f : L₁ →ₗ[R] L₂) x
@[simp]
theorem map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ :=
LieHom.map_lie' f
@[simp]
theorem map_zero (f : L₁ →ₗ⁅R⁆ L₂) : f 0 = 0 :=
(f : L₁ →ₗ[R] L₂).map_zero
/-- The identity map is a morphism of Lie algebras. -/
def id : L₁ →ₗ⁅R⁆ L₁ :=
{ (LinearMap.id : L₁ →ₗ[R] L₁) with map_lie' := rfl }
@[simp, norm_cast]
theorem coe_id : ⇑(id : L₁ →ₗ⁅R⁆ L₁) = _root_.id :=
rfl
theorem id_apply (x : L₁) : (id : L₁ →ₗ⁅R⁆ L₁) x = x :=
rfl
/-- The constant 0 map is a Lie algebra morphism. -/
instance : Zero (L₁ →ₗ⁅R⁆ L₂) :=
⟨{ (0 : L₁ →ₗ[R] L₂) with map_lie' := by simp }⟩
@[norm_cast, simp]
theorem coe_zero : ((0 : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = 0 :=
rfl
theorem zero_apply (x : L₁) : (0 : L₁ →ₗ⁅R⁆ L₂) x = 0 :=
rfl
/-- The identity map is a Lie algebra morphism. -/
instance : One (L₁ →ₗ⁅R⁆ L₁) :=
⟨id⟩
@[simp]
theorem coe_one : ((1 : L₁ →ₗ⁅R⁆ L₁) : L₁ → L₁) = _root_.id :=
rfl
theorem one_apply (x : L₁) : (1 : L₁ →ₗ⁅R⁆ L₁) x = x :=
rfl
instance : Inhabited (L₁ →ₗ⁅R⁆ L₂) :=
⟨0⟩
theorem coe_injective : @Function.Injective (L₁ →ₗ⁅R⁆ L₂) (L₁ → L₂) (↑) := by
rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h
congr
@[ext]
theorem ext {f g : L₁ →ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g :=
coe_injective <| funext h
theorem congr_fun {f g : L₁ →ₗ⁅R⁆ L₂} (h : f = g) (x : L₁) : f x = g x :=
h ▸ rfl
@[simp]
theorem mk_coe (f : L₁ →ₗ⁅R⁆ L₂) (h₁ h₂ h₃) : (⟨⟨⟨f, h₁⟩, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) = f := by
ext
rfl
@[simp]
theorem coe_mk (f : L₁ → L₂) (h₁ h₂ h₃) : ((⟨⟨⟨f, h₁⟩, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = f :=
rfl
/-- The composition of morphisms is a morphism. -/
def comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ⁅R⁆ L₃ :=
{ LinearMap.comp f.toLinearMap g.toLinearMap with
map_lie' := by
intros x y
simp }
theorem comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f.comp g x = f (g x) :=
rfl
@[norm_cast, simp]
theorem coe_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : (f.comp g : L₁ → L₃) = f ∘ g :=
rfl
@[norm_cast, simp]
theorem toLinearMap_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) :
(f.comp g : L₁ →ₗ[R] L₃) = (f : L₂ →ₗ[R] L₃).comp (g : L₁ →ₗ[R] L₂) :=
rfl
@[deprecated (since := "2024-12-30")] alias coe_linearMap_comp := toLinearMap_comp
@[simp]
theorem comp_id (f : L₁ →ₗ⁅R⁆ L₂) : f.comp (id : L₁ →ₗ⁅R⁆ L₁) = f :=
rfl
@[simp]
theorem id_comp (f : L₁ →ₗ⁅R⁆ L₂) : (id : L₂ →ₗ⁅R⁆ L₂).comp f = f :=
rfl
/-- The inverse of a bijective morphism is a morphism. -/
def inverse (f : L₁ →ₗ⁅R⁆ L₂) (g : L₂ → L₁) (h₁ : Function.LeftInverse g f)
(h₂ : Function.RightInverse g f) : L₂ →ₗ⁅R⁆ L₁ :=
{ LinearMap.inverse f.toLinearMap g h₁ h₂ with
map_lie' := by
intros x y
calc
g ⁅x, y⁆ = g ⁅f (g x), f (g y)⁆ := by conv_lhs => rw [← h₂ x, ← h₂ y]
_ = g (f ⁅g x, g y⁆) := by rw [map_lie]
_ = ⁅g x, g y⁆ := h₁ _
}
end LieHom
section ModulePullBack
variable {R : Type u} {L₁ : Type v} {L₂ : Type w} (M : Type w₁)
variable [CommRing R] [LieRing L₁] [LieAlgebra R L₁] [LieRing L₂] [LieAlgebra R L₂]
variable [AddCommGroup M] [LieRingModule L₂ M]
variable (f : L₁ →ₗ⁅R⁆ L₂)
/-- A Lie ring module may be pulled back along a morphism of Lie algebras.
See note [reducible non-instances]. -/
def LieRingModule.compLieHom : LieRingModule L₁ M where
bracket x m := ⁅f x, m⁆
lie_add x := lie_add (f x)
add_lie x y m := by simp only [LieHom.map_add, add_lie]
leibniz_lie x y m := by simp only [lie_lie, sub_add_cancel, LieHom.map_lie]
theorem LieRingModule.compLieHom_apply (x : L₁) (m : M) :
haveI := LieRingModule.compLieHom M f
⁅x, m⁆ = ⁅f x, m⁆ :=
rfl
/-- A Lie module may be pulled back along a morphism of Lie algebras. -/
theorem LieModule.compLieHom [Module R M] [LieModule R L₂ M] :
@LieModule R L₁ M _ _ _ _ _ (LieRingModule.compLieHom M f) :=
{ __ := LieRingModule.compLieHom M f
smul_lie := fun t x m => by
simp only [LieRingModule.compLieHom_apply, smul_lie, LieHom.map_smul]
lie_smul := fun t x m => by
simp only [LieRingModule.compLieHom_apply, lie_smul] }
end ModulePullBack
/-- An equivalence of Lie algebras (denoted as `L₁ ≃ₗ⁅R⁆ L₂`) is a morphism
which is also a linear equivalence.
We could instead define an equivalence to be a morphism which is also a (plain) equivalence.
However, it is more convenient to define via linear equivalence to get `.toLinearEquiv` for free. -/
structure LieEquiv (R : Type u) (L : Type v) (L' : Type w) [CommRing R] [LieRing L] [LieAlgebra R L]
[LieRing L'] [LieAlgebra R L'] extends L →ₗ⁅R⁆ L' where
/-- The inverse function of an equivalence of Lie algebras -/
invFun : L' → L
/-- The inverse function of an equivalence of Lie algebras is a left inverse of the underlying
function. -/
left_inv : Function.LeftInverse invFun toLieHom.toFun
/-- The inverse function of an equivalence of Lie algebras is a right inverse of the underlying
function. -/
right_inv : Function.RightInverse invFun toLieHom.toFun
@[inherit_doc]
notation:50 L " ≃ₗ⁅" R "⁆ " L' => LieEquiv R L L'
namespace LieEquiv
variable {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variable [CommRing R] [LieRing L₁] [LieRing L₂] [LieRing L₃]
variable [LieAlgebra R L₁] [LieAlgebra R L₂] [LieAlgebra R L₃]
/-- Consider an equivalence of Lie algebras as a linear equivalence. -/
def toLinearEquiv (f : L₁ ≃ₗ⁅R⁆ L₂) : L₁ ≃ₗ[R] L₂ :=
{ f.toLieHom, f with }
instance hasCoeToLieHom : Coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ →ₗ⁅R⁆ L₂) :=
⟨toLieHom⟩
instance hasCoeToLinearEquiv : Coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ ≃ₗ[R] L₂) :=
⟨toLinearEquiv⟩
instance : EquivLike (L₁ ≃ₗ⁅R⁆ L₂) L₁ L₂ where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' f g h₁ h₂ := by cases f; cases g; simp at h₁ h₂; simp [*]
theorem coe_toLieHom (e : L₁ ≃ₗ⁅R⁆ L₂) : ⇑(e : L₁ →ₗ⁅R⁆ L₂) = e :=
rfl
@[deprecated (since := "2024-12-30")] alias coe_to_lieHom := coe_toLieHom
@[simp]
theorem coe_toLinearEquiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ⇑(e : L₁ ≃ₗ[R] L₂) = e :=
rfl
@[deprecated (since := "2024-12-30")] alias coe_to_linearEquiv := coe_toLinearEquiv
@[simp]
theorem toLinearEquiv_mk (f : L₁ →ₗ⁅R⁆ L₂) (g h₁ h₂) :
(mk f g h₁ h₂ : L₁ ≃ₗ[R] L₂) =
{ f with
invFun := g
left_inv := h₁
right_inv := h₂ } :=
rfl
@[deprecated (since := "2024-12-30")] alias to_linearEquiv_mk := toLinearEquiv_mk
theorem toLinearEquiv_injective : Injective ((↑) : (L₁ ≃ₗ⁅R⁆ L₂) → L₁ ≃ₗ[R] L₂) := by
rintro ⟨⟨⟨⟨f, -⟩, -⟩, -⟩, f_inv⟩ ⟨⟨⟨⟨g, -⟩, -⟩, -⟩, g_inv⟩
intro h
simp only [toLinearEquiv_mk, LinearEquiv.mk.injEq, LinearMap.mk.injEq, AddHom.mk.injEq] at h
congr
exacts [h.1, h.2]
@[deprecated (since := "2024-12-30")] alias coe_linearEquiv_injective := toLinearEquiv_injective
theorem coe_injective : @Injective (L₁ ≃ₗ⁅R⁆ L₂) (L₁ → L₂) (↑) :=
LinearEquiv.coe_injective.comp toLinearEquiv_injective
@[ext]
theorem ext {f g : L₁ ≃ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g :=
coe_injective <| funext h
instance : One (L₁ ≃ₗ⁅R⁆ L₁) :=
⟨{ (1 : L₁ ≃ₗ[R] L₁) with map_lie' := rfl }⟩
@[simp]
theorem one_apply (x : L₁) : (1 : L₁ ≃ₗ⁅R⁆ L₁) x = x :=
rfl
instance : Inhabited (L₁ ≃ₗ⁅R⁆ L₁) :=
⟨1⟩
lemma map_lie (e : L₁ ≃ₗ⁅R⁆ L₂) (x y : L₁) : e ⁅x, y⁆ = ⁅e x, e y⁆ :=
LieHom.map_lie e.toLieHom x y
/-- Lie algebra equivalences are reflexive. -/
def refl : L₁ ≃ₗ⁅R⁆ L₁ :=
1
@[simp]
theorem refl_apply (x : L₁) : (refl : L₁ ≃ₗ⁅R⁆ L₁) x = x :=
rfl
/-- Lie algebra equivalences are symmetric. -/
@[symm]
def symm (e : L₁ ≃ₗ⁅R⁆ L₂) : L₂ ≃ₗ⁅R⁆ L₁ :=
{ LieHom.inverse e.toLieHom e.invFun e.left_inv e.right_inv, e.toLinearEquiv.symm with }
@[simp]
theorem symm_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.symm = e := rfl
theorem symm_bijective : Function.Bijective (LieEquiv.symm : (L₁ ≃ₗ⁅R⁆ L₂) → L₂ ≃ₗ⁅R⁆ L₁) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp]
theorem apply_symm_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e (e.symm x) = x :=
e.toLinearEquiv.apply_symm_apply
@[simp]
theorem symm_apply_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e.symm (e x) = x :=
e.toLinearEquiv.symm_apply_apply
@[simp]
theorem refl_symm : (refl : L₁ ≃ₗ⁅R⁆ L₁).symm = refl :=
rfl
/-- Lie algebra equivalences are transitive. -/
@[trans]
def trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) : L₁ ≃ₗ⁅R⁆ L₃ :=
{ LieHom.comp e₂.toLieHom e₁.toLieHom, LinearEquiv.trans e₁.toLinearEquiv e₂.toLinearEquiv with }
@[simp]
theorem self_trans_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.trans e.symm = refl :=
ext e.symm_apply_apply
@[simp]
theorem symm_trans_self (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.trans e = refl :=
e.symm.self_trans_symm
@[simp]
theorem trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₁) : (e₁.trans e₂) x = e₂ (e₁ x) :=
rfl
@[simp]
theorem symm_trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) :
(e₁.trans e₂).symm = e₂.symm.trans e₁.symm :=
rfl
protected theorem bijective (e : L₁ ≃ₗ⁅R⁆ L₂) : Function.Bijective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.toLinearEquiv.bijective
protected theorem injective (e : L₁ ≃ₗ⁅R⁆ L₂) : Function.Injective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.toLinearEquiv.injective
protected theorem surjective (e : L₁ ≃ₗ⁅R⁆ L₂) :
Function.Surjective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.toLinearEquiv.surjective
/-- A bijective morphism of Lie algebras yields an equivalence of Lie algebras. -/
@[simps!]
noncomputable def ofBijective (f : L₁ →ₗ⁅R⁆ L₂) (h : Function.Bijective f) : L₁ ≃ₗ⁅R⁆ L₂ :=
{ LinearEquiv.ofBijective (f : L₁ →ₗ[R] L₂)
h with
toFun := f
map_lie' := by intros x y; exact f.map_lie x y }
end LieEquiv
section LieModuleMorphisms
variable (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) (P : Type w₂)
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [AddCommGroup N] [AddCommGroup P]
variable [Module R M] [Module R N] [Module R P]
variable [LieRingModule L M] [LieRingModule L N] [LieRingModule L P]
/-- A morphism of Lie algebra modules (denoted as `M →ₗ⁅R,L⁆ N`) is a linear map
which commutes with the action of the Lie algebra. -/
structure LieModuleHom extends M →ₗ[R] N where
/-- A module of Lie algebra modules is compatible with the action of the Lie algebra on the
modules. -/
map_lie' : ∀ {x : L} {m : M}, toFun ⁅x, m⁆ = ⁅x, toFun m⁆
@[inherit_doc]
notation:25 M " →ₗ⁅" R "," L:25 "⁆ " N:0 => LieModuleHom R L M N
namespace LieModuleHom
variable {R L M N P}
attribute [coe] LieModuleHom.toLinearMap
instance : CoeOut (M →ₗ⁅R,L⁆ N) (M →ₗ[R] N) :=
⟨LieModuleHom.toLinearMap⟩
instance : FunLike (M →ₗ⁅R, L⁆ N) M N where
coe f := f.toFun
coe_injective' x y h := by cases x; cases y; simp at h; simp [h]
initialize_simps_projections LieModuleHom (toFun → apply)
@[simp, norm_cast]
theorem coe_toLinearMap (f : M →ₗ⁅R,L⁆ N) : ((f : M →ₗ[R] N) : M → N) = f :=
rfl
@[simp]
theorem map_smul (f : M →ₗ⁅R,L⁆ N) (c : R) (x : M) : f (c • x) = c • f x :=
LinearMap.map_smul (f : M →ₗ[R] N) c x
@[simp]
theorem map_add (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x + y) = f x + f y :=
LinearMap.map_add (f : M →ₗ[R] N) x y
@[simp]
theorem map_sub (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x - y) = f x - f y :=
LinearMap.map_sub (f : M →ₗ[R] N) x y
@[simp]
theorem map_neg (f : M →ₗ⁅R,L⁆ N) (x : M) : f (-x) = -f x :=
LinearMap.map_neg (f : M →ₗ[R] N) x
@[simp]
theorem map_lie (f : M →ₗ⁅R,L⁆ N) (x : L) (m : M) : f ⁅x, m⁆ = ⁅x, f m⁆ :=
LieModuleHom.map_lie' f
variable [LieAlgebra R L] [LieModule R L N] [LieModule R L P] in
theorem map_lie₂ (f : M →ₗ⁅R,L⁆ N →ₗ[R] P) (x : L) (m : M) (n : N) :
⁅x, f m n⁆ = f ⁅x, m⁆ n + f m ⁅x, n⁆ := by simp only [sub_add_cancel, map_lie, LieHom.lie_apply]
@[simp]
theorem map_zero (f : M →ₗ⁅R,L⁆ N) : f 0 = 0 :=
LinearMap.map_zero (f : M →ₗ[R] N)
/-- The identity map is a morphism of Lie modules. -/
def id : M →ₗ⁅R,L⁆ M :=
{ (LinearMap.id : M →ₗ[R] M) with map_lie' := rfl }
@[simp, norm_cast]
theorem coe_id : ((id : M →ₗ⁅R,L⁆ M) : M → M) = _root_.id :=
rfl
theorem id_apply (x : M) : (id : M →ₗ⁅R,L⁆ M) x = x :=
rfl
/-- The constant 0 map is a Lie module morphism. -/
instance : Zero (M →ₗ⁅R,L⁆ N) :=
⟨{ (0 : M →ₗ[R] N) with map_lie' := by simp }⟩
@[norm_cast, simp]
theorem coe_zero : ⇑(0 : M →ₗ⁅R,L⁆ N) = 0 :=
rfl
theorem zero_apply (m : M) : (0 : M →ₗ⁅R,L⁆ N) m = 0 :=
rfl
/-- The identity map is a Lie module morphism. -/
instance : One (M →ₗ⁅R,L⁆ M) :=
⟨id⟩
instance : Inhabited (M →ₗ⁅R,L⁆ N) :=
⟨0⟩
theorem coe_injective : @Function.Injective (M →ₗ⁅R,L⁆ N) (M → N) (↑) := by
rintro ⟨⟨⟨f, _⟩⟩⟩ ⟨⟨⟨g, _⟩⟩⟩ h
congr
@[ext]
theorem ext {f g : M →ₗ⁅R,L⁆ N} (h : ∀ m, f m = g m) : f = g :=
coe_injective <| funext h
theorem congr_fun {f g : M →ₗ⁅R,L⁆ N} (h : f = g) (x : M) : f x = g x :=
h ▸ rfl
@[simp]
theorem mk_coe (f : M →ₗ⁅R,L⁆ N) (h) : (⟨f, h⟩ : M →ₗ⁅R,L⁆ N) = f := by
rfl
@[simp]
theorem coe_mk (f : M →ₗ[R] N) (h) : ((⟨f, h⟩ : M →ₗ⁅R,L⁆ N) : M → N) = f := by
rfl
@[norm_cast]
theorem coe_linear_mk (f : M →ₗ[R] N) (h) : ((⟨f, h⟩ : M →ₗ⁅R,L⁆ N) : M →ₗ[R] N) = f := by
rfl
/-- The composition of Lie module morphisms is a morphism. -/
def comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : M →ₗ⁅R,L⁆ P :=
{ LinearMap.comp f.toLinearMap g.toLinearMap with
map_lie' := by
intros x m
simp }
theorem comp_apply (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) (m : M) : f.comp g m = f (g m) :=
rfl
@[norm_cast, simp]
theorem coe_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : ⇑(f.comp g) = f ∘ g :=
rfl
@[norm_cast, simp]
theorem toLinearMap_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) :
(f.comp g : M →ₗ[R] P) = (f : N →ₗ[R] P).comp (g : M →ₗ[R] N) :=
rfl
@[deprecated (since := "2024-12-30")] alias coe_linearMap_comp := toLinearMap_comp
/-- The inverse of a bijective morphism of Lie modules is a morphism of Lie modules. -/
def inverse (f : M →ₗ⁅R,L⁆ N) (g : N → M) (h₁ : Function.LeftInverse g f)
(h₂ : Function.RightInverse g f) : N →ₗ⁅R,L⁆ M :=
{ LinearMap.inverse f.toLinearMap g h₁ h₂ with
map_lie' := by
intros x n
calc
g ⁅x, n⁆ = g ⁅x, f (g n)⁆ := by rw [h₂]
_ = g (f ⁅x, g n⁆) := by rw [map_lie]
_ = ⁅x, g n⁆ := h₁ _
}
instance : Add (M →ₗ⁅R,L⁆ N) where
add f g := { (f : M →ₗ[R] N) + (g : M →ₗ[R] N) with map_lie' := by simp }
|
instance : Sub (M →ₗ⁅R,L⁆ N) where
| Mathlib/Algebra/Lie/Basic.lean | 824 | 825 |
/-
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.Data.Fintype.Order
import Mathlib.MeasureTheory.Function.AEEqFun
import Mathlib.MeasureTheory.Function.LpSeminorm.Defs
import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
import Mathlib.MeasureTheory.Integral.Lebesgue.Countable
import Mathlib.MeasureTheory.Integral.Lebesgue.Sub
/-!
# Basic theorems about ℒp space
-/
noncomputable section
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology ComplexConjugate
variable {α ε ε' E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm ε] [ENorm ε']
namespace MeasureTheory
section Lp
section Top
theorem MemLp.eLpNorm_lt_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ < ∞ :=
hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_lt_top := MemLp.eLpNorm_lt_top
theorem MemLp.eLpNorm_ne_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ ≠ ∞ :=
ne_of_lt hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_ne_top := MemLp.eLpNorm_ne_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : α → ε} (hq0_lt : 0 < q)
(hfq : eLpNorm' f q μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ q ∂μ < ∞ := by
rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt]
exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq)
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' :=
lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hfp : eLpNorm f p μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ p.toReal ∂μ < ∞ := by
apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
· exact ENNReal.toReal_pos hp_ne_zero hp_ne_top
· simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top :=
lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top
theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) : eLpNorm f p μ < ∞ ↔ ∫⁻ a, (‖f a‖ₑ) ^ p.toReal ∂μ < ∞ :=
⟨lintegral_rpow_enorm_lt_top_of_eLpNorm_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 [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using
ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩
@[deprecated (since := "2025-02-04")] alias
eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top
end Top
section Zero
@[simp]
theorem eLpNorm'_exponent_zero {f : α → ε} : eLpNorm' f 0 μ = 1 := by
rw [eLpNorm', div_zero, ENNReal.rpow_zero]
@[simp]
theorem eLpNorm_exponent_zero {f : α → ε} : eLpNorm f 0 μ = 0 := by simp [eLpNorm]
@[simp]
theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace ε] {f : α → ε} :
MemLp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [MemLp, eLpNorm_exponent_zero]
@[deprecated (since := "2025-02-21")]
alias memℒp_zero_iff_aestronglyMeasurable := memLp_zero_iff_aestronglyMeasurable
section ENormedAddMonoid
variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε]
@[simp]
theorem eLpNorm'_zero (hp0_lt : 0 < q) : eLpNorm' (0 : α → ε) q μ = 0 := by
simp [eLpNorm'_eq_lintegral_enorm, hp0_lt]
@[simp]
theorem eLpNorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : eLpNorm' (0 : α → ε) q μ = 0 := by
rcases le_or_lt 0 q with hq0 | hq_neg
· exact eLpNorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm)
· simp [eLpNorm'_eq_lintegral_enorm, ENNReal.rpow_eq_zero_iff, hμ, hq_neg]
@[simp]
theorem eLpNormEssSup_zero : eLpNormEssSup (0 : α → ε) μ = 0 := by
simp [eLpNormEssSup, ← bot_eq_zero', essSup_const_bot]
@[simp]
theorem eLpNorm_zero : eLpNorm (0 : α → ε) p μ = 0 := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp only [h_top, eLpNorm_exponent_top, eLpNormEssSup_zero]
rw [← Ne] at h0
simp [eLpNorm_eq_eLpNorm' h0 h_top, ENNReal.toReal_pos h0 h_top]
@[simp]
theorem eLpNorm_zero' : eLpNorm (fun _ : α => (0 : ε)) p μ = 0 := eLpNorm_zero
@[simp] lemma MemLp.zero : MemLp (0 : α → ε) p μ :=
⟨aestronglyMeasurable_zero, by rw [eLpNorm_zero]; exact ENNReal.coe_lt_top⟩
@[simp] lemma MemLp.zero' : MemLp (fun _ : α => (0 : ε)) p μ := MemLp.zero
@[deprecated (since := "2025-02-21")]
alias Memℒp.zero' := MemLp.zero'
@[deprecated (since := "2025-01-21")] alias zero_memℒp := MemLp.zero
@[deprecated (since := "2025-01-21")] alias zero_mem_ℒp := MemLp.zero'
variable [MeasurableSpace α]
theorem eLpNorm'_measure_zero_of_pos {f : α → ε} (hq_pos : 0 < q) :
eLpNorm' f q (0 : Measure α) = 0 := by simp [eLpNorm', hq_pos]
theorem eLpNorm'_measure_zero_of_exponent_zero {f : α → ε} : eLpNorm' f 0 (0 : Measure α) = 1 := by
simp [eLpNorm']
theorem eLpNorm'_measure_zero_of_neg {f : α → ε} (hq_neg : q < 0) :
eLpNorm' f q (0 : Measure α) = ∞ := by simp [eLpNorm', hq_neg]
end ENormedAddMonoid
@[simp]
theorem eLpNormEssSup_measure_zero {f : α → ε} : eLpNormEssSup f (0 : Measure α) = 0 := by
simp [eLpNormEssSup]
@[simp]
theorem eLpNorm_measure_zero {f : α → ε} : eLpNorm 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 [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', ENNReal.toReal_pos h0 h_top]
section ContinuousENorm
variable {ε : Type*} [TopologicalSpace ε] [ContinuousENorm ε]
@[simp] lemma memLp_measure_zero {f : α → ε} : MemLp f p (0 : Measure α) := by
simp [MemLp]
@[deprecated (since := "2025-02-21")]
alias memℒp_measure_zero := memLp_measure_zero
end ContinuousENorm
end Zero
section Neg
@[simp]
theorem eLpNorm'_neg (f : α → F) (q : ℝ) (μ : Measure α) : eLpNorm' (-f) q μ = eLpNorm' f q μ := by
simp [eLpNorm'_eq_lintegral_enorm]
@[simp]
theorem eLpNorm_neg (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : eLpNorm (-f) p μ = eLpNorm f p μ := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp [h_top, eLpNormEssSup_eq_essSup_enorm]
simp [eLpNorm_eq_eLpNorm' h0 h_top]
lemma eLpNorm_sub_comm (f g : α → E) (p : ℝ≥0∞) (μ : Measure α) :
eLpNorm (f - g) p μ = eLpNorm (g - f) p μ := by simp [← eLpNorm_neg (f := f - g)]
theorem MemLp.neg {f : α → E} (hf : MemLp f p μ) : MemLp (-f) p μ :=
⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩
@[deprecated (since := "2025-02-21")]
alias Memℒp.neg := MemLp.neg
theorem memLp_neg_iff {f : α → E} : MemLp (-f) p μ ↔ MemLp f p μ :=
⟨fun h => neg_neg f ▸ h.neg, MemLp.neg⟩
@[deprecated (since := "2025-02-21")]
alias memℒp_neg_iff := memLp_neg_iff
end Neg
section Const
variable {ε' ε'' : Type*} [TopologicalSpace ε'] [ContinuousENorm ε']
[TopologicalSpace ε''] [ENormedAddMonoid ε'']
theorem eLpNorm'_const (c : ε) (hq_pos : 0 < q) :
eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by
rw [eLpNorm'_eq_lintegral_enorm, 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]
-- Generalising this to ENormedAddMonoid requires a case analysis whether ‖c‖ₑ = ⊤,
-- and will happen in a future PR.
theorem eLpNorm'_const' [IsFiniteMeasure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) :
eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by
rw [eLpNorm'_eq_lintegral_enorm, 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]
simp [hc_ne_zero]
theorem eLpNormEssSup_const (c : ε) (hμ : μ ≠ 0) : eLpNormEssSup (fun _ : α => c) μ = ‖c‖ₑ := by
rw [eLpNormEssSup_eq_essSup_enorm, essSup_const _ hμ]
theorem eLpNorm'_const_of_isProbabilityMeasure (c : ε) (hq_pos : 0 < q) [IsProbabilityMeasure μ] :
eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ := by simp [eLpNorm'_const c hq_pos, measure_univ]
theorem eLpNorm_const (c : ε) (h0 : p ≠ 0) (hμ : μ ≠ 0) :
eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by
by_cases h_top : p = ∞
· simp [h_top, eLpNormEssSup_const c hμ]
simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top]
theorem eLpNorm_const' (c : ε) (h0 : p ≠ 0) (h_top : p ≠ ∞) :
eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by
simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top]
-- NB. If ‖c‖ₑ = ∞ and μ is finite, this claim is false: the right has side is true,
-- but the left hand side is false (as the norm is infinite).
theorem eLpNorm_const_lt_top_iff_enorm {c : ε''} (hc' : ‖c‖ₑ ≠ ∞)
{p : ℝ≥0∞} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
eLpNorm (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, ENNReal.zero_lt_top,
eLpNorm_measure_zero]
by_cases hc : c = 0
· simp only [hc, true_or, eq_self_iff_true, ENNReal.zero_lt_top, eLpNorm_zero']
rw [eLpNorm_const' c hp_ne_zero hp_ne_top]
obtain hμ_top | hμ_ne_top := eq_or_ne (μ .univ) ∞
· simp [hc, hμ_top, hp]
rw [ENNReal.mul_lt_top_iff]
simpa [hμ, hc, hμ_ne_top, hμ_ne_top.lt_top, hc, hc'.lt_top] using
ENNReal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_ne_top
theorem eLpNorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
eLpNorm (fun _ : α => c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ :=
eLpNorm_const_lt_top_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top
theorem memLp_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) [IsFiniteMeasure μ] :
MemLp (fun _ : α ↦ c) p μ := by
refine ⟨aestronglyMeasurable_const, ?_⟩
by_cases h0 : p = 0
· simp [h0]
by_cases hμ : μ = 0
· simp [hμ]
rw [eLpNorm_const c h0 hμ]
exact ENNReal.mul_lt_top hc.lt_top (ENNReal.rpow_lt_top_of_nonneg (by simp)
(measure_ne_top μ Set.univ))
theorem memLp_const (c : E) [IsFiniteMeasure μ] : MemLp (fun _ : α => c) p μ :=
memLp_const_enorm enorm_ne_top
@[deprecated (since := "2025-02-21")]
alias memℒp_const := memLp_const
theorem memLp_top_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) :
MemLp (fun _ : α ↦ c) ∞ μ :=
⟨aestronglyMeasurable_const, by by_cases h : μ = 0 <;> simp [eLpNorm_const _, h, hc.lt_top]⟩
theorem memLp_top_const (c : E) : MemLp (fun _ : α => c) ∞ μ :=
memLp_top_const_enorm enorm_ne_top
@[deprecated (since := "2025-02-21")]
alias memℒp_top_const := memLp_top_const
theorem memLp_const_iff_enorm
{p : ℝ≥0∞} {c : ε''} (hc : ‖c‖ₑ ≠ ⊤) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp (fun _ : α ↦ c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := by
simp_all [MemLp, aestronglyMeasurable_const,
eLpNorm_const_lt_top_iff_enorm hc hp_ne_zero hp_ne_top]
theorem memLp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp (fun _ : α => c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ :=
memLp_const_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top
@[deprecated (since := "2025-02-21")]
alias memℒp_const_iff := memLp_const_iff
end Const
variable {f : α → F}
lemma eLpNorm'_mono_enorm_ae {f : α → ε} {g : α → ε'} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) :
eLpNorm' f q μ ≤ eLpNorm' g q μ := by
simp only [eLpNorm'_eq_lintegral_enorm]
gcongr ?_ ^ (1/q)
refine lintegral_mono_ae (h.mono fun x hx => ?_)
gcongr
lemma eLpNorm'_mono_nnnorm_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
eLpNorm' f q μ ≤ eLpNorm' g q μ := by
simp only [eLpNorm'_eq_lintegral_enorm]
gcongr ?_ ^ (1/q)
refine lintegral_mono_ae (h.mono fun x hx => ?_)
dsimp [enorm]
gcongr
theorem eLpNorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) :
eLpNorm' f q μ ≤ eLpNorm' g q μ :=
eLpNorm'_mono_enorm_ae hq (by simpa only [enorm_le_iff_norm_le] using h)
theorem eLpNorm'_congr_enorm_ae {f g : α → ε} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ = ‖g x‖ₑ) :
eLpNorm' f q μ = eLpNorm' g q μ := by
have : (‖f ·‖ₑ ^ q) =ᵐ[μ] (‖g ·‖ₑ ^ q) := hfg.mono fun x hx ↦ by simp [hx]
simp only [eLpNorm'_eq_lintegral_enorm, lintegral_congr_ae this]
theorem eLpNorm'_congr_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) :
eLpNorm' f q μ = eLpNorm' g q μ := by
have : (‖f ·‖ₑ ^ q) =ᵐ[μ] (‖g ·‖ₑ ^ q) := hfg.mono fun x hx ↦ by simp [enorm, hx]
simp only [eLpNorm'_eq_lintegral_enorm, lintegral_congr_ae this]
theorem eLpNorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) :
eLpNorm' f q μ = eLpNorm' g q μ :=
eLpNorm'_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx
theorem eLpNorm'_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) : eLpNorm' f q μ = eLpNorm' g q μ :=
eLpNorm'_congr_enorm_ae (hfg.fun_comp _)
theorem eLpNormEssSup_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) :
eLpNormEssSup f μ = eLpNormEssSup g μ :=
essSup_congr_ae (hfg.fun_comp enorm)
theorem eLpNormEssSup_mono_enorm_ae {f g : α → ε} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) :
eLpNormEssSup f μ ≤ eLpNormEssSup g μ :=
| essSup_mono_ae <| hfg
theorem eLpNormEssSup_mono_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) :
eLpNormEssSup f μ ≤ eLpNormEssSup g μ :=
essSup_mono_ae <| hfg.mono fun _x hx => ENNReal.coe_le_coe.mpr hx
| Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean | 359 | 364 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Tape
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.PFun
import Mathlib.Computability.PostTuringMachine
/-!
# Turing machines
The files `PostTuringMachine.lean` and `TuringMachine.lean` define
a sequence of simple machine languages, starting with Turing machines and working
up to more complex languages based on Wang B-machines.
`PostTuringMachine.lean` covers the TM0 model and TM1 model;
`TuringMachine.lean` adds the TM2 model.
## Naming conventions
Each model of computation in this file shares a naming convention for the elements of a model of
computation. These are the parameters for the language:
* `Γ` is the alphabet on the tape.
* `Λ` is the set of labels, or internal machine states.
* `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and
later models achieve this by mixing it into `Λ`.
* `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks.
All of these variables denote "essentially finite" types, but for technical reasons it is
convenient to allow them to be infinite anyway. When using an infinite type, we will be interested
to prove that only finitely many values of the type are ever interacted with.
Given these parameters, there are a few common structures for the model that arise:
* `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is
finite, and for later models it is an infinite inductive type representing "possible program
texts".
* `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with
its environment.
* `Machine` is the set of all machines in the model. Usually this is approximately a function
`Λ → Stmt`, although different models have different ways of halting and other actions.
* `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step.
If `step c = none`, then `c` is a terminal state, and the result of the computation is read off
from `c`. Because of the type of `step`, these models are all deterministic by construction.
* `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model;
in most cases it is `List Γ`.
* `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from
`init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to
the final state to obtain the result. The type `Output` depends on the model.
* `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and
can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input
cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when
convenient, and prove that only finitely many of these states are actually accessible. This
formalizes "essentially finite" mentioned above.
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Relation
open Nat (iterate)
open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply'
iterate_zero_apply)
namespace Turing
/-!
## The TM2 model
The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite)
collection of stacks, each with elements of different types (the alphabet of stack `k : K` is
`Γ k`). The statements are:
* `push k (f : σ → Γ k) q` puts `f a` on the `k`-th stack, then does `q`.
* `pop k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, and removes this element from the stack, then does `q`.
* `peek k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, then does `q`.
* `load (f : σ → σ) q` reads nothing but applies `f` to the internal state, then does `q`.
* `branch (f : σ → Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`.
* `goto (f : σ → Λ)` jumps to label `f a`.
* `halt` halts on the next step.
The configuration is a tuple `(l, var, stk)` where `l : Option Λ` is the current label to run or
`none` for the halting state, `var : σ` is the (finite) internal state, and `stk : ∀ k, List (Γ k)`
is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not
`ListBlank`s, they have definite ends that can be detected by the `pop` command.)
Given a designated stack `k` and a value `L : List (Γ k)`, the initial configuration has all the
stacks empty except the designated "input" stack; in `eval` this designated stack also functions
as the output stack.
-/
namespace TM2
variable {K : Type*}
-- Index type of stacks
variable (Γ : K → Type*)
-- Type of stack elements
variable (Λ : Type*)
-- Type of function labels
variable (σ : Type*)
-- Type of variable settings
/-- The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. -/
inductive Stmt
| push : ∀ k, (σ → Γ k) → Stmt → Stmt
| peek : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| pop : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| load : (σ → σ) → Stmt → Stmt
| branch : (σ → Bool) → Stmt → Stmt → Stmt
| goto : (σ → Λ) → Stmt
| halt : Stmt
open Stmt
instance Stmt.inhabited : Inhabited (Stmt Γ Λ σ) :=
⟨halt⟩
/-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of
local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite
size.) -/
structure Cfg where
/-- The current label to run (or `none` for the halting state) -/
l : Option Λ
/-- The internal state -/
var : σ
/-- The (finite) collection of internal stacks -/
stk : ∀ k, List (Γ k)
instance Cfg.inhabited [Inhabited σ] : Inhabited (Cfg Γ Λ σ) :=
⟨⟨default, default, default⟩⟩
variable {Γ Λ σ}
section
variable [DecidableEq K]
/-- The step function for the TM2 model. -/
def stepAux : Stmt Γ Λ σ → σ → (∀ k, List (Γ k)) → Cfg Γ Λ σ
| push k f q, v, S => stepAux q v (update S k (f v :: S k))
| peek k f q, v, S => stepAux q (f v (S k).head?) S
| pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail)
| load a q, v, S => stepAux q (a v) S
| branch f q₁ q₂, v, S => cond (f v) (stepAux q₁ v S) (stepAux q₂ v S)
| goto f, v, S => ⟨some (f v), v, S⟩
| halt, v, S => ⟨none, v, S⟩
/-- The step function for the TM2 model. -/
def step (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ)
| ⟨none, _, _⟩ => none
| ⟨some l, v, S⟩ => some (stepAux (M l) v S)
attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3
stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2
/-- The (reflexive) reachability relation for the TM2 model. -/
def Reaches (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Cfg Γ Λ σ → Prop :=
ReflTransGen fun a b ↦ b ∈ step M a
end
/-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/
def SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop
| push _ _ q => SupportsStmt S q
| peek _ _ q => SupportsStmt S q
| pop _ _ q => SupportsStmt S q
| load _ q => SupportsStmt S q
| branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂
| goto l => ∀ v, l v ∈ S
| halt => True
section
open scoped Classical in
/-- The set of subtree statements in a statement. -/
noncomputable def stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ)
| Q@(push _ _ q) => insert Q (stmts₁ q)
| Q@(peek _ _ q) => insert Q (stmts₁ q)
| Q@(pop _ _ q) => insert Q (stmts₁ q)
| Q@(load _ q) => insert Q (stmts₁ q)
| Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂)
| Q@(goto _) => {Q}
| Q@halt => {Q}
theorem stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by
cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁]
theorem stmts₁_trans {q₁ q₂ : Stmt Γ Λ σ} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by
classical
intro h₁₂ q₀ h₀₁
induction q₂ with (
simp only [stmts₁] at h₁₂ ⊢
simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂)
| branch f q₁ q₂ IH₁ IH₂ =>
rcases h₁₂ with (rfl | h₁₂ | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂))
· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IH₂ h₁₂))
| goto l => subst h₁₂; exact h₀₁
| halt => subst h₁₂; exact h₀₁
| load _ q IH | _ _ _ q IH =>
rcases h₁₂ with (rfl | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (IH h₁₂)
theorem stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h : q₁ ∈ stmts₁ q₂)
(hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by
induction q₂ with
simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton]
at h hs
| branch f q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2]
| goto l => subst h; exact hs
| halt => subst h; trivial
| load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs]
open scoped Classical in
/-- The set of statements accessible from initial set `S` of labels. -/
noncomputable def stmts (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) : Finset (Option (Stmt Γ Λ σ)) :=
Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q))
theorem stmts_trans {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h₁ : q₁ ∈ stmts₁ q₂) :
some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_trans h₂ h₁⟩
end
variable [Inhabited Λ]
/-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in
`S` jump only to other states in `S`. -/
def Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) :=
default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q)
theorem stmts_supportsStmt {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q : Stmt Γ Λ σ}
(ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls)
variable [DecidableEq K]
theorem step_supports (M : Λ → Stmt Γ Λ σ) {S : Finset Λ} (ss : Supports M S) :
∀ {c c' : Cfg Γ Λ σ}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S
| ⟨some l₁, v, T⟩, c', h₁, h₂ => by
replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂)
simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c'
revert h₂; induction M l₁ generalizing v T with intro hs
| branch p q₁' q₂' IH₁ IH₂ =>
unfold stepAux; cases p v
· exact IH₂ _ _ hs.2
· exact IH₁ _ _ hs.1
| goto => exact Finset.some_mem_insertNone.2 (hs _)
| halt => apply Multiset.mem_cons_self
| load _ _ IH | _ _ _ _ IH => exact IH _ _ hs
variable [Inhabited σ]
/-- The initial state of the TM2 model. The input is provided on a designated stack. -/
def init (k : K) (L : List (Γ k)) : Cfg Γ Λ σ :=
⟨some default, default, update (fun _ ↦ []) k L⟩
/-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/
def eval (M : Λ → Stmt Γ Λ σ) (k : K) (L : List (Γ k)) : Part (List (Γ k)) :=
(Turing.eval (step M) (init k L)).map fun c ↦ c.stk k
end TM2
/-!
## TM2 emulator in TM1
To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a
TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of
stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack
1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this:
```
bottom: ... | _ | T | _ | _ | _ | _ | ...
stack 1: ... | _ | b | a | _ | _ | _ | ...
stack 2: ... | _ | f | e | d | c | _ | ...
```
where a tape element is a vertical slice through the diagram. Here the alphabet is
`Γ' := Bool × ∀ k, Option (Γ k)`, where:
* `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the
tail of all stacks. It is never modified.
* `stk k : Option (Γ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is
the blank value). Note that the head of the stack is at the far end; this is so that push and pop
don't have to do any shifting.
In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions,
it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the
end of the appropriate stack, make its changes, and then return to the bottom. So the states are:
* `normal (l : Λ)`: waiting at `bottom` to execute function `l`
* `go k (s : StAct k) (q : Stmt₂)`: travelling to the right to get to the end of stack `k` in
order to perform stack action `s`, and later continue with executing `q`
* `ret (q : Stmt₂)`: travelling to the left after having performed a stack action, and executing
`q` once we arrive
Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the
length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)`
steps to run when emulated in TM1, where `m` is the length of the input.
-/
namespace TM2to1
-- A displaced lemma proved in unnecessary generality
theorem stk_nth_val {K : Type*} {Γ : K → Type*} {L : ListBlank (∀ k, Option (Γ k))} {k S} (n)
(hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) :
L.nth n k = S.reverse[n]? := by
rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk,
List.getI_eq_iget_getElem?, List.getElem?_map]
cases S.reverse[n]? <;> rfl
variable (K : Type*)
variable (Γ : K → Type*)
variable {Λ σ : Type*}
/-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom,
plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/
def Γ' :=
Bool × ∀ k, Option (Γ k)
variable {K Γ}
instance Γ'.inhabited : Inhabited (Γ' K Γ) :=
⟨⟨false, fun _ ↦ none⟩⟩
instance Γ'.fintype [DecidableEq K] [Fintype K] [∀ k, Fintype (Γ k)] : Fintype (Γ' K Γ) :=
instFintypeProd _ _
/-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function
to express the program state in terms of a tape with only the stacks themselves. -/
def addBottom (L : ListBlank (∀ k, Option (Γ k))) : ListBlank (Γ' K Γ) :=
ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩)
theorem addBottom_map (L : ListBlank (∀ k, Option (Γ k))) :
(addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by
simp only [addBottom, ListBlank.map_cons]
convert ListBlank.cons_head_tail L
generalize ListBlank.tail L = L'
refine L'.induction_on fun l ↦ ?_; simp
theorem addBottom_modifyNth (f : (∀ k, Option (Γ k)) → ∀ k, Option (Γ k))
(L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
(addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by
cases n <;>
simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons]
congr; symm; apply ListBlank.map_modifyNth; intro; rfl
theorem addBottom_nth_snd (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth n).2 = L.nth n := by
conv => rhs; rw [← addBottom_map L, ListBlank.nth_map]
theorem addBottom_nth_succ_fst (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth (n + 1)).1 = false := by
rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map]
theorem addBottom_head_fst (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).head.1 = true := by
rw [addBottom, ListBlank.head_cons]
variable (K Γ σ) in
/-- A stack action is a command that interacts with the top of a stack. Our default position
is at the bottom of all the stacks, so we have to hold on to this action while going to the end
to modify the stack. -/
inductive StAct (k : K)
| push : (σ → Γ k) → StAct k
| peek : (σ → Option (Γ k) → σ) → StAct k
| pop : (σ → Option (Γ k) → σ) → StAct k
instance StAct.inhabited {k : K} : Inhabited (StAct K Γ σ k) :=
⟨StAct.peek fun s _ ↦ s⟩
section
open StAct
/-- The TM2 statement corresponding to a stack action. -/
def stRun {k : K} : StAct K Γ σ k → TM2.Stmt Γ Λ σ → TM2.Stmt Γ Λ σ
| push f => TM2.Stmt.push k f
| peek f => TM2.Stmt.peek k f
| pop f => TM2.Stmt.pop k f
/-- The effect of a stack action on the local variables, given the value of the stack. -/
def stVar {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → σ
| push _ => v
| peek f => f v l.head?
| pop f => f v l.head?
/-- The effect of a stack action on the stack. -/
def stWrite {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → List (Γ k)
| push f => f v :: l
| peek _ => l
| pop _ => l.tail
/-- We have partitioned the TM2 statements into "stack actions", which require going to the end
of the stack, and all other actions, which do not. This is a modified recursor which lumps the
stack actions into one. -/
@[elab_as_elim]
def stmtStRec.{l} {motive : TM2.Stmt Γ Λ σ → Sort l}
(run : ∀ (k) (s : StAct K Γ σ k) (q) (_ : motive q), motive (stRun s q))
(load : ∀ (a q) (_ : motive q), motive (TM2.Stmt.load a q))
(branch : ∀ (p q₁ q₂) (_ : motive q₁) (_ : motive q₂), motive (TM2.Stmt.branch p q₁ q₂))
(goto : ∀ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : ∀ n, motive n
| TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.branch _ q₁ q₂ =>
branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt q₂)
| TM2.Stmt.goto _ => goto _
| TM2.Stmt.halt => halt
theorem supports_run (S : Finset Λ) {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by
cases s <;> rfl
end
variable (K Γ Λ σ)
/-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the
next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and
return to the bottom, respectively. -/
inductive Λ'
| normal : Λ → Λ'
| go (k : K) : StAct K Γ σ k → TM2.Stmt Γ Λ σ → Λ'
| ret : TM2.Stmt Γ Λ σ → Λ'
variable {K Γ Λ σ}
open Λ'
instance Λ'.inhabited [Inhabited Λ] : Inhabited (Λ' K Γ Λ σ) :=
⟨normal default⟩
open TM1.Stmt
section
variable [DecidableEq K]
/-- The program corresponding to state transitions at the end of a stack. Here we start out just
after the top of the stack, and should end just after the new top of the stack. -/
def trStAct {k : K} (q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ) :
StAct K Γ σ k → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| StAct.push f => (write fun a s ↦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q
| StAct.peek f => move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| move Dir.right q
| StAct.pop f =>
branch (fun a _ ↦ a.1) (load (fun _ s ↦ f s none) q)
(move Dir.left <|
(load fun a s ↦ f s (a.2 k)) <| write (fun a _ ↦ (a.1, update a.2 k none)) q)
/-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty
except for the input stack, and the stack bottom mark is set at the head. -/
def trInit (k : K) (L : List (Γ k)) : List (Γ' K Γ) :=
let L' : List (Γ' K Γ) := L.reverse.map fun a ↦ (false, update (fun _ ↦ none) k (some a))
(true, L'.headI.2) :: L'.tail
theorem step_run {k : K} (q : TM2.Stmt Γ Λ σ) (v : σ) (S : ∀ k, List (Γ k)) : ∀ s : StAct K Γ σ k,
TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s))
| StAct.push _ => rfl
| StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl
| StAct.pop _ => rfl
end
/-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents,
but stack actions are deferred by going to the corresponding `go` state, so that we can find the
appropriate stack top. -/
def trNormal : TM2.Stmt Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| TM2.Stmt.push k f q => goto fun _ _ ↦ go k (StAct.push f) q
| TM2.Stmt.peek k f q => goto fun _ _ ↦ go k (StAct.peek f) q
| TM2.Stmt.pop k f q => goto fun _ _ ↦ go k (StAct.pop f) q
| TM2.Stmt.load a q => load (fun _ ↦ a) (trNormal q)
| TM2.Stmt.branch f q₁ q₂ => branch (fun _ ↦ f) (trNormal q₁) (trNormal q₂)
| TM2.Stmt.goto l => goto fun _ s ↦ normal (l s)
| TM2.Stmt.halt => halt
theorem trNormal_run {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
trNormal (stRun s q) = goto fun _ _ ↦ go k s q := by
cases s <;> rfl
section
open scoped Classical in
/-- The set of machine states accessible from an initial TM2 statement. -/
noncomputable def trStmts₁ : TM2.Stmt Γ Λ σ → Finset (Λ' K Γ Λ σ)
| TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.load _ q => trStmts₁ q
| TM2.Stmt.branch _ q₁ q₂ => trStmts₁ q₁ ∪ trStmts₁ q₂
| _ => ∅
theorem trStmts₁_run {k : K} {s : StAct K Γ σ k} {q : TM2.Stmt Γ Λ σ} :
open scoped Classical in
trStmts₁ (stRun s q) = {go k s q, ret q} ∪ trStmts₁ q := by
cases s <;> simp only [trStmts₁, stRun]
theorem tr_respects_aux₂ [DecidableEq K] {k : K} {q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ} {v : σ}
{S : ∀ k, List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))}
(hL : ∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) :
let v' := stVar v (S k) o
let Sk' := stWrite v (S k) o
let S' := update S k Sk'
∃ L' : ListBlank (∀ k, Option (Γ k)),
(∀ k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) ∧
TM1.stepAux (trStAct q o) v
((Tape.move Dir.right)^[(S k).length] (Tape.mk' ∅ (addBottom L))) =
TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' ∅ (addBottom L'))) := by
simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux]
| push f =>
have := Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k (some (f v)))
refine
⟨_, fun k' ↦ ?_, by
-- Porting note: `rw [...]` to `erw [...]; rfl`.
-- https://github.com/leanprover-community/mathlib4/issues/5164
rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this]
erw [addBottom_modifyNth fun a ↦ update a k (some (f v))]
rw [Nat.add_one, iterate_succ']
rfl⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
· subst k'
split_ifs with h
<;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map]
· rw [List.getI_eq_getElem _, List.getElem_append_right] <;>
simp only [List.length_append, List.length_reverse, List.length_map, ← h,
Nat.sub_self, List.length_singleton, List.getElem_singleton,
le_refl, Nat.lt_succ_self]
rw [← proj_map_nth, hL, ListBlank.nth_mk]
rcases lt_or_gt_of_ne h with h | h
· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL]
rw [Function.update_of_ne h']
| peek f =>
rw [Function.update_eq_self]
use L, hL; rw [Tape.move_left_right]; congr
cases e : S k; · rfl
rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left,
Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e,
List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length]
rfl
| pop f =>
rcases e : S k with - | ⟨hd, tl⟩
· simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length,
Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil]
rw [← e, Function.update_eq_self]
exact ⟨L, hL, by rw [addBottom_head_fst, cond]⟩
· refine
⟨_, fun k' ↦ ?_, by
erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst,
cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head,
| Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k none),
addBottom_modifyNth fun a ↦ update a k none, addBottom_nth_snd,
stk_nth_val _ (hL k), e,
show (List.cons hd tl).reverse[tl.length]? = some hd by
| Mathlib/Computability/TuringMachine.lean | 584 | 587 |
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.AlgebraicTopology.DoldKan.Faces
import Mathlib.CategoryTheory.Idempotents.Basic
/-!
# Construction of projections for the Dold-Kan correspondence
In this file, we construct endomorphisms `P q : K[X] ⟶ K[X]` for all
`q : ℕ`. We study how they behave with respect to face maps with the lemmas
`HigherFacesVanish.of_P`, `HigherFacesVanish.comp_P_eq_self` and
`comp_P_eq_self_iff`.
Then, we show that they are projections (see `P_f_idem`
and `P_idem`). They are natural transformations (see `natTransP`
and `P_f_naturality`) and are compatible with the application
of additive functors (see `map_P`).
By passing to the limit, these endomorphisms `P q` shall be used in `PInfty.lean`
in order to define `PInfty : K[X] ⟶ K[X]`.
(See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.)
-/
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Preadditive
CategoryTheory.SimplicialObject Opposite CategoryTheory.Idempotents
open Simplicial DoldKan
noncomputable section
namespace AlgebraicTopology
namespace DoldKan
variable {C : Type*} [Category C] [Preadditive C] {X : SimplicialObject C}
/-- This is the inductive definition of the projections `P q : K[X] ⟶ K[X]`,
with `P 0 := 𝟙 _` and `P (q+1) := P q ≫ (𝟙 _ + Hσ q)`. -/
noncomputable def P : ℕ → (K[X] ⟶ K[X])
| 0 => 𝟙 _
| q + 1 => P q ≫ (𝟙 _ + Hσ q)
lemma P_zero : (P 0 : K[X] ⟶ K[X]) = 𝟙 _ := rfl
lemma P_succ (q : ℕ) : (P (q+1) : K[X] ⟶ K[X]) = P q ≫ (𝟙 _ + Hσ q) := rfl
/-- All the `P q` coincide with `𝟙 _` in degree 0. -/
@[simp]
theorem P_f_0_eq (q : ℕ) : ((P q).f 0 : X _⦋0⦌ ⟶ X _⦋0⦌) = 𝟙 _ := by
induction' q with q hq
· rfl
· simp only [P_succ, HomologicalComplex.add_f_apply, HomologicalComplex.comp_f,
HomologicalComplex.id_f, id_comp, hq, Hσ_eq_zero, add_zero]
/-- `Q q` is the complement projection associated to `P q` -/
def Q (q : ℕ) : K[X] ⟶ K[X] :=
𝟙 _ - P q
theorem P_add_Q (q : ℕ) : P q + Q q = 𝟙 K[X] := by
rw [Q]
abel
theorem P_add_Q_f (q n : ℕ) : (P q).f n + (Q q).f n = 𝟙 (X _⦋n⦌) :=
HomologicalComplex.congr_hom (P_add_Q q) n
@[simp]
theorem Q_zero : (Q 0 : K[X] ⟶ _) = 0 :=
sub_self _
theorem Q_succ (q : ℕ) : (Q (q + 1) : K[X] ⟶ _) = Q q - P q ≫ Hσ q := by
simp only [Q, P_succ, comp_add, comp_id]
abel
/-- All the `Q q` coincide with `0` in degree 0. -/
@[simp]
theorem Q_f_0_eq (q : ℕ) : ((Q q).f 0 : X _⦋0⦌ ⟶ X _⦋0⦌) = 0 := by
simp only [HomologicalComplex.sub_f_apply, HomologicalComplex.id_f, Q, P_f_0_eq, sub_self]
namespace HigherFacesVanish
/-- This lemma expresses the vanishing of
`(P q).f (n+1) ≫ X.δ k : X _⦋n+1⦌ ⟶ X _⦋n⦌` when `k≠0` and `k≥n-q+2` -/
theorem of_P : ∀ q n : ℕ, HigherFacesVanish q ((P q).f (n + 1) : X _⦋n + 1⦌ ⟶ X _⦋n + 1⦌)
| 0 => fun n j hj₁ => by omega
| q + 1 => fun n => by
simp only [P_succ]
exact (of_P q n).induction
@[reassoc]
theorem comp_P_eq_self {Y : C} {n q : ℕ} {φ : Y ⟶ X _⦋n + 1⦌} (v : HigherFacesVanish q φ) :
φ ≫ (P q).f (n + 1) = φ := by
induction' q with q hq
· simp only [P_zero]
apply comp_id
· simp only [P_succ, comp_add, HomologicalComplex.comp_f, HomologicalComplex.add_f_apply,
comp_id, ← assoc, hq v.of_succ, add_eq_left]
by_cases hqn : n < q
· exact v.of_succ.comp_Hσ_eq_zero hqn
· obtain ⟨a, ha⟩ := Nat.le.dest (not_lt.mp hqn)
have hnaq : n = a + q := by omega
simp only [v.of_succ.comp_Hσ_eq hnaq, neg_eq_zero, ← assoc]
have eq := v ⟨a, by omega⟩ (by
simp only [hnaq, Nat.succ_eq_add_one, add_assoc]
rfl)
simp only [Fin.succ_mk] at eq
simp only [eq, zero_comp]
end HigherFacesVanish
theorem comp_P_eq_self_iff {Y : C} {n q : ℕ} {φ : Y ⟶ X _⦋n + 1⦌} :
φ ≫ (P q).f (n + 1) = φ ↔ HigherFacesVanish q φ := by
| constructor
· intro hφ
rw [← hφ]
apply HigherFacesVanish.of_comp
apply HigherFacesVanish.of_P
· exact HigherFacesVanish.comp_P_eq_self
@[reassoc (attr := simp)]
theorem P_f_idem (q n : ℕ) : ((P q).f n : X _⦋n⦌ ⟶ _) ≫ (P q).f n = (P q).f n := by
rcases n with (_|n)
· rw [P_f_0_eq q, comp_id]
· exact (HigherFacesVanish.of_P q n).comp_P_eq_self
@[reassoc (attr := simp)]
theorem Q_f_idem (q n : ℕ) : ((Q q).f n : X _⦋n⦌ ⟶ _) ≫ (Q q).f n = (Q q).f n :=
idem_of_id_sub_idem _ (P_f_idem q n)
| Mathlib/AlgebraicTopology/DoldKan/Projections.lean | 118 | 134 |
/-
Copyright (c) 2024 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.MeasureTheory.Integral.PeakFunction
import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform
/-!
# Fourier inversion formula
In a finite-dimensional real inner product space, we show the Fourier inversion formula, i.e.,
`𝓕⁻ (𝓕 f) v = f v` if `f` and `𝓕 f` are integrable, and `f` is continuous at `v`. This is proved
in `MeasureTheory.Integrable.fourier_inversion`. See also `Continuous.fourier_inversion`
giving `𝓕⁻ (𝓕 f) = f` under an additional continuity assumption for `f`.
We use the following proof. A naïve computation gives
`𝓕⁻ (𝓕 f) v
= ∫_w exp (2 I π ⟪w, v⟫) 𝓕 f (w) dw
= ∫_w exp (2 I π ⟪w, v⟫) ∫_x, exp (-2 I π ⟪w, x⟫) f x dx) dw
= ∫_x (∫_ w, exp (2 I π ⟪w, v - x⟫ dw) f x dx `
However, the Fubini step does not make sense for lack of integrability, and the middle integral
`∫_ w, exp (2 I π ⟪w, v - x⟫ dw` (which one would like to be a Dirac at `v - x`) is not defined.
To gain integrability, one multiplies with a Gaussian function `exp (-c⁻¹ ‖w‖^2)`, with a large
(but finite) `c`. As this function converges pointwise to `1` when `c → ∞`, we get
`∫_w exp (2 I π ⟪w, v⟫) 𝓕 f (w) dw = lim_c ∫_w exp (-c⁻¹ ‖w‖^2 + 2 I π ⟪w, v⟫) 𝓕 f (w) dw`.
One can perform Fubini on the right hand side for fixed `c`, writing the integral as
`∫_x (∫_w exp (-c⁻¹‖w‖^2 + 2 I π ⟪w, v - x⟫ dw)) f x dx`.
The middle factor is the Fourier transform of a more and more flat function
(converging to the constant `1`), hence it becomes more and more concentrated, around the
point `v`. (Morally, it converges to the Dirac at `v`). Moreover, it has integral one.
Therefore, multiplying by `f` and integrating, one gets a term converging to `f v` as `c → ∞`.
Since it also converges to `𝓕⁻ (𝓕 f) v`, this proves the result.
To check the concentration property of the middle factor and the fact that it has integral one, we
rely on the explicit computation of the Fourier transform of Gaussians.
-/
open Filter MeasureTheory Complex Module Metric Real Bornology
open scoped Topology FourierTransform RealInnerProductSpace Complex
variable {V E : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
[MeasurableSpace V] [BorelSpace V] [FiniteDimensional ℝ V]
[NormedAddCommGroup E] [NormedSpace ℂ E] {f : V → E}
namespace Real
lemma tendsto_integral_cexp_sq_smul (hf : Integrable f) :
Tendsto (fun (c : ℝ) ↦ (∫ v : V, cexp (- c⁻¹ * ‖v‖^2) • f v))
atTop (𝓝 (∫ v : V, f v)) := by
apply tendsto_integral_filter_of_dominated_convergence _ _ _ hf.norm
· filter_upwards with v
nth_rewrite 2 [show f v = cexp (- (0 : ℝ) * ‖v‖^2) • f v by simp]
apply (Tendsto.cexp _).smul_const
exact tendsto_inv_atTop_zero.ofReal.neg.mul_const _
· filter_upwards with c using
AEStronglyMeasurable.smul (Continuous.aestronglyMeasurable (by fun_prop)) hf.1
· filter_upwards [Ici_mem_atTop (0 : ℝ)] with c (hc : 0 ≤ c)
filter_upwards with v
simp only [ofReal_inv, neg_mul, norm_smul]
norm_cast
conv_rhs => rw [← one_mul (‖f v‖)]
gcongr
simp only [norm_eq_abs, abs_exp, exp_le_one_iff, Left.neg_nonpos_iff]
positivity
variable [CompleteSpace E]
lemma tendsto_integral_gaussian_smul (hf : Integrable f) (h'f : Integrable (𝓕 f)) (v : V) :
Tendsto (fun (c : ℝ) ↦
∫ w : V, ((π * c) ^ (finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * c * ‖v - w‖ ^ 2)) • f w)
atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by
have A : Tendsto (fun (c : ℝ) ↦ (∫ w : V, cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫)
• (𝓕 f) w)) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by
have : Integrable (fun w ↦ 𝐞 ⟪w, v⟫ • (𝓕 f) w) := by
have B : Continuous fun p : V × V => (- innerₗ V) p.1 p.2 := continuous_inner.neg
simpa using
(VectorFourier.fourierIntegral_convergent_iff Real.continuous_fourierChar B v).2 h'f
convert tendsto_integral_cexp_sq_smul this using 4 with c w
· rw [Submonoid.smul_def, Real.fourierChar_apply, smul_smul, ← Complex.exp_add, real_inner_comm]
congr 3
simp only [ofReal_mul, ofReal_ofNat]
ring
· simp [fourierIntegralInv_eq]
have B : Tendsto (fun (c : ℝ) ↦ (∫ w : V,
𝓕 (fun w ↦ cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫)) w • f w)) atTop
(𝓝 (𝓕⁻ (𝓕 f) v)) := by
apply A.congr'
filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
have J : Integrable (fun w ↦ cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫)) :=
GaussianFourier.integrable_cexp_neg_mul_sq_norm_add (by simpa) _ _
simpa using (VectorFourier.integral_fourierIntegral_smul_eq_flip (L := innerₗ V)
Real.continuous_fourierChar continuous_inner J hf).symm
apply B.congr'
filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
congr with w
rw [fourierIntegral_gaussian_innerProductSpace' (by simpa)]
congr
· simp
· simp; ring
lemma tendsto_integral_gaussian_smul' (hf : Integrable f) {v : V} (h'f : ContinuousAt f v) :
Tendsto (fun (c : ℝ) ↦
∫ w : V, ((π * c : ℂ) ^ (finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * c * ‖v - w‖ ^ 2)) • f w)
atTop (𝓝 (f v)) := by
let φ : V → ℝ := fun w ↦ π ^ (finrank ℝ V / 2 : ℝ) * Real.exp (-π^2 * ‖w‖^2)
have A : Tendsto (fun (c : ℝ) ↦ ∫ w : V, (c ^ finrank ℝ V * φ (c • (v - w))) • f w)
atTop (𝓝 (f v)) := by
apply tendsto_integral_comp_smul_smul_of_integrable'
· exact fun x ↦ by positivity
· rw [integral_const_mul, GaussianFourier.integral_rexp_neg_mul_sq_norm (by positivity)]
nth_rewrite 2 [← pow_one π]
rw [← rpow_natCast, ← rpow_natCast, ← rpow_sub pi_pos, ← rpow_mul pi_nonneg,
← rpow_add pi_pos]
ring_nf
exact rpow_zero _
· have A : Tendsto (fun (w : V) ↦ π^2 * ‖w‖^2) (cobounded V) atTop := by
rw [tendsto_const_mul_atTop_of_pos (by positivity)]
apply (tendsto_pow_atTop two_ne_zero).comp tendsto_norm_cobounded_atTop
have B := tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (finrank ℝ V / 2) 1
zero_lt_one |>.comp A |>.const_mul (π ^ (-finrank ℝ V / 2 : ℝ))
rw [mul_zero] at B
convert B using 2 with x
simp only [neg_mul, one_mul, Function.comp_apply, ← mul_assoc, ← rpow_natCast, φ]
congr 1
rw [mul_rpow (by positivity) (by positivity), ← rpow_mul pi_nonneg,
← rpow_mul (norm_nonneg _), ← mul_assoc, ← rpow_add pi_pos, mul_comm]
congr <;> ring
· exact hf
· exact h'f
have B : Tendsto
(fun (c : ℝ) ↦ ∫ w : V, ((c^(1/2 : ℝ)) ^ finrank ℝ V * φ ((c^(1/2 : ℝ)) • (v - w))) • f w)
atTop (𝓝 (f v)) :=
A.comp (tendsto_rpow_atTop (by norm_num))
apply B.congr'
filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
congr with w
rw [← coe_smul]
congr
rw [ofReal_mul, ofReal_mul, ofReal_exp, ← mul_assoc]
congr
· rw [mul_cpow_ofReal_nonneg pi_nonneg hc.le, ← rpow_natCast, ← rpow_mul hc.le, mul_comm,
ofReal_cpow pi_nonneg, ofReal_cpow hc.le]
simp [div_eq_inv_mul]
· norm_cast
simp only [one_div, norm_smul, Real.norm_eq_abs, mul_pow, sq_abs, neg_mul, neg_inj,
← rpow_natCast, ← rpow_mul hc.le, mul_assoc]
norm_num
end Real
variable [CompleteSpace E]
/-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product
space is integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕⁻ (𝓕 f) = f` at
continuity points of `f`. -/
theorem MeasureTheory.Integrable.fourier_inversion
(hf : Integrable f) (h'f : Integrable (𝓕 f)) {v : V}
(hv : ContinuousAt f v) : 𝓕⁻ (𝓕 f) v = f v :=
tendsto_nhds_unique (Real.tendsto_integral_gaussian_smul hf h'f v)
(Real.tendsto_integral_gaussian_smul' hf hv)
/-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product
space is continuous, integrable, and its Fourier transform `𝓕 f` is also integrable,
then `𝓕⁻ (𝓕 f) = f`. -/
| theorem Continuous.fourier_inversion (h : Continuous f)
(hf : Integrable f) (h'f : Integrable (𝓕 f)) :
𝓕⁻ (𝓕 f) = f := by
ext v
exact hf.fourier_inversion h'f h.continuousAt
| Mathlib/Analysis/Fourier/Inversion.lean | 168 | 172 |
/-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
-/
import Mathlib.Algebra.NeZero
import Mathlib.Data.Int.DivMod
import Mathlib.Logic.Embedding.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Tactic.Common
import Mathlib.Tactic.Attr.Register
/-!
# The finite type with `n` elements
`Fin n` is the type whose elements are natural numbers smaller than `n`.
This file expands on the development in the core library.
## Main definitions
### Induction principles
* `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`.
Further definitions and eliminators can be found in `Init.Data.Fin.Lemmas`
### Embeddings and isomorphisms
* `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`;
* `Fin.succEmb` : `Fin.succ` as an `Embedding`;
* `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`;
* `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`;
* `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`;
* `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`;
* `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right,
generalizes `Fin.succ`;
* `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left;
### Other casts
* `Fin.divNat i` : divides `i : Fin (m * n)` by `n`;
* `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`;
-/
assert_not_exists Monoid Finset
open Fin Nat Function
attribute [simp] Fin.succ_ne_zero Fin.castSucc_lt_last
/-- Elimination principle for the empty set `Fin 0`, dependent version. -/
def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x :=
x.elim0
namespace Fin
@[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} :
(⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 :=
mk.inj_iff
@[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} :
1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by
simp [eq_comm]
instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where
prf k hk := ⟨⟨k, hk⟩, rfl⟩
/-- A dependent variant of `Fin.elim0`. -/
def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _)
variable {n m : ℕ}
--variable {a b : Fin n} -- this *really* breaks stuff
theorem val_injective : Function.Injective (@Fin.val n) :=
@Fin.eq_of_val_eq n
/-- If you actually have an element of `Fin n`, then the `n` is always positive -/
lemma size_positive : Fin n → 0 < n := Fin.pos
lemma size_positive' [Nonempty (Fin n)] : 0 < n :=
‹Nonempty (Fin n)›.elim Fin.pos
protected theorem prop (a : Fin n) : a.val < n :=
a.2
lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by
simp [Fin.lt_iff_le_and_ne, le_last]
lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 :=
Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab
lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n :=
Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last
/-- Equivalence between `Fin n` and `{ i // i < n }`. -/
@[simps apply symm_apply]
def equivSubtype : Fin n ≃ { i // i < n } where
toFun a := ⟨a.1, a.2⟩
invFun a := ⟨a.1, a.2⟩
left_inv := fun ⟨_, _⟩ => rfl
right_inv := fun ⟨_, _⟩ => rfl
section coe
/-!
### coercions and constructions
-/
theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b :=
Fin.ext_iff.symm
theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 :=
Fin.ext_iff.not
theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' :=
Fin.ext_iff
-- syntactic tautologies now
/-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element,
then they coincide (in the heq sense). -/
protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} :
HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by
subst h
simp [funext_iff]
/-- Assume `k = l` and `k' = l'`.
If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair,
then they coincide (in the heq sense). -/
protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l')
{f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} :
HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by
subst h
subst h'
simp [funext_iff]
/-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires
`k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/
protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} :
HEq i j ↔ (i : ℕ) = (j : ℕ) := by
subst h
simp [val_eq_val]
end coe
section Order
/-!
### order
-/
theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b :=
Iff.rfl
/-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b :=
Iff.rfl
/-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b :=
Iff.rfl
theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp
theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp
/-- The inclusion map `Fin n → ℕ` is an embedding. -/
@[simps -fullyApplied apply]
def valEmbedding : Fin n ↪ ℕ :=
⟨val, val_injective⟩
@[simp]
theorem equivSubtype_symm_trans_valEmbedding :
equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) :=
rfl
/-- Use the ordering on `Fin n` for checking recursive definitions.
For example, the following definition is not accepted by the termination checker,
unless we declare the `WellFoundedRelation` instance:
```lean
def factorial {n : ℕ} : Fin n → ℕ
| ⟨0, _⟩ := 1
| ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩
```
-/
instance {n : ℕ} : WellFoundedRelation (Fin n) :=
measure (val : Fin n → ℕ)
@[deprecated (since := "2025-02-24")]
alias val_zero' := val_zero
/-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem mk_zero' (n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl
/--
The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a :=
Nat.zero_le a.val
@[simp, norm_cast]
theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by
rw [Fin.ext_iff, val_zero]
theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0 :=
val_eq_zero_iff.not
@[simp, norm_cast]
theorem val_pos_iff [NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a := by
rw [← val_fin_lt, val_zero]
/--
The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by
rw [← val_pos_iff, Nat.pos_iff_ne_zero, val_ne_zero_iff]
@[simp] lemma cast_eq_self (a : Fin n) : a.cast rfl = a := rfl
@[simp] theorem cast_eq_zero {k l : ℕ} [NeZero k] [NeZero l]
(h : k = l) (x : Fin k) : Fin.cast h x = 0 ↔ x = 0 := by
simp [← val_eq_zero_iff]
lemma cast_injective {k l : ℕ} (h : k = l) : Injective (Fin.cast h) :=
fun a b hab ↦ by simpa [← val_eq_val] using hab
theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero
theorem one_lt_last [NeZero n] : 1 < last (n + 1) := by
rw [lt_iff_val_lt_val, val_one, val_last, Nat.lt_add_left_iff_pos, Nat.pos_iff_ne_zero]
exact NeZero.ne n
end Order
/-! ### Coercions to `ℤ` and the `fin_omega` tactic. -/
open Int
theorem coe_int_sub_eq_ite {n : Nat} (u v : Fin n) :
((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n := by
rw [Fin.sub_def]
split
· rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
· rw [natCast_emod, Int.emod_eq_of_lt] <;> omega
theorem coe_int_sub_eq_mod {n : Nat} (u v : Fin n) :
((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n := by
rw [coe_int_sub_eq_ite]
split
· rw [Int.emod_eq_of_lt] <;> omega
· rw [Int.emod_eq_add_self_emod, Int.emod_eq_of_lt] <;> omega
theorem coe_int_add_eq_ite {n : Nat} (u v : Fin n) :
((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n := by
rw [Fin.add_def]
split
· rw [natCast_emod, Int.emod_eq_of_lt] <;> omega
· rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
theorem coe_int_add_eq_mod {n : Nat} (u v : Fin n) :
((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n := by
rw [coe_int_add_eq_ite]
split
· rw [Int.emod_eq_of_lt] <;> omega
· rw [Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
-- Write `a + b` as `if (a + b : ℕ) < n then (a + b : ℤ) else (a + b : ℤ) - n` and
-- similarly `a - b` as `if (b : ℕ) ≤ a then (a - b : ℤ) else (a - b : ℤ) + n`.
attribute [fin_omega] coe_int_sub_eq_ite coe_int_add_eq_ite
-- Rewrite inequalities in `Fin` to inequalities in `ℕ`
attribute [fin_omega] Fin.lt_iff_val_lt_val Fin.le_iff_val_le_val
-- Rewrite `1 : Fin (n + 2)` to `1 : ℤ`
attribute [fin_omega] val_one
/--
Preprocessor for `omega` to handle inequalities in `Fin`.
Note that this involves a lot of case splitting, so may be slow.
-/
-- Further adjustment to the simp set can probably make this more powerful.
-- Please experiment and PR updates!
macro "fin_omega" : tactic => `(tactic|
{ try simp only [fin_omega, ← Int.ofNat_lt, ← Int.ofNat_le] at *
omega })
section Add
/-!
### addition, numerals, and coercion from Nat
-/
@[simp]
theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n :=
rfl
@[deprecated val_one' (since := "2025-03-10")]
theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) :=
rfl
instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where
exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩
theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by
rcases n with (_ | _ | n) <;>
simp [Fin.nontrivial, not_nontrivial, Nat.succ_le_iff]
section Monoid
instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) :=
haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance
inferInstance
@[simp]
theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 :=
rfl
instance instNatCast [NeZero n] : NatCast (Fin n) where
natCast i := Fin.ofNat' n i
lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl
end Monoid
theorem val_add_eq_ite {n : ℕ} (a b : Fin n) :
(↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by
rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2),
Nat.mod_eq_of_lt (show ↑b < n from b.2)]
theorem val_add_eq_of_add_lt {n : ℕ} {a b : Fin n} (huv : a.val + b.val < n) :
(a + b).val = a.val + b.val := by
rw [val_add]
simp [Nat.mod_eq_of_lt huv]
lemma intCast_val_sub_eq_sub_add_ite {n : ℕ} (a b : Fin n) :
((a - b).val : ℤ) = a.val - b.val + if b ≤ a then 0 else n := by
split <;> fin_omega
lemma one_le_of_ne_zero {n : ℕ} [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n)
cases n with
| zero => simp only [Nat.reduceAdd, Fin.isValue, Fin.zero_le]
| succ n => rwa [Fin.le_iff_val_le_val, Fin.val_one, Nat.one_le_iff_ne_zero, val_ne_zero_iff]
lemma val_sub_one_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1 := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n)
rw [Fin.sub_val_of_le (one_le_of_ne_zero hi), Fin.val_one', Nat.mod_eq_of_lt
(Nat.succ_le_iff.mpr (nontrivial_iff_two_le.mp <| nontrivial_of_ne i 0 hi))]
section OfNatCoe
@[simp]
theorem ofNat'_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : Fin.ofNat' n a = a :=
rfl
@[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl
/-- Converting an in-range number to `Fin (n + 1)` produces a result
whose value is the original number. -/
theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a :=
Nat.mod_eq_of_lt h
/-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results
in the same value. -/
@[simp, norm_cast] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a :=
Fin.ext <| val_cast_of_lt a.isLt
-- This is a special case of `CharP.cast_eq_zero` that doesn't require typeclass search
@[simp high] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp
@[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by
simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero]
@[simp]
theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp
theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by
rw [Fin.natCast_eq_last]
exact Fin.le_last i
variable {a b : ℕ}
lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by
rw [← Nat.lt_succ_iff] at han hbn
simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn]
lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by
rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn]
lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b :=
(natCast_le_natCast (hab.trans hbn) hbn).2 hab
lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b :=
(natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab
end OfNatCoe
end Add
section Succ
/-!
### succ and casts into larger Fin types
-/
lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [Fin.ext_iff]
/-- `Fin.succ` as an `Embedding` -/
def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where
toFun := succ
inj' := succ_injective _
@[simp]
theorem coe_succEmb : ⇑(succEmb n) = Fin.succ :=
rfl
@[deprecated (since := "2025-04-12")]
alias val_succEmb := coe_succEmb
@[simp]
theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 :=
⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩
theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) :
∃ y, Fin.succ y = x := exists_succ_eq.mpr h
@[simp]
theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by
cases n
· exact (NeZero.ne 0 rfl).elim
· rfl
theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _
theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos'
/--
The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by
cases n
· exact (NeZero.ne 0 rfl).elim
· rfl
-- Version of `succ_one_eq_two` to be used by `dsimp`.
-- Note the `'` swapped around due to a move to std4.
/--
The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 :=
⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩
-- TODO: Move to Batteries
@[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by
simp [Fin.ext_iff]
@[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [Fin.ext_iff]
attribute [simp] castSucc_inj
lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) :=
fun _ _ hab ↦ Fin.ext (congr_arg val hab :)
lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _
lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _
/-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/
@[simps apply]
def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where
toFun := castLE h
inj' := castLE_injective _
@[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl
/- The next proof can be golfed a lot using `Fintype.card`.
It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency
(not done yet). -/
lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by
refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩
induction n generalizing m with
| zero => exact m.zero_le
| succ n ihn =>
obtain ⟨e⟩ := h
rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne'
with ⟨m, rfl⟩
refine Nat.succ_le_succ <| ihn ⟨?_⟩
refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero),
fun i j h ↦ ?_⟩
simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h
lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n :=
⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩),
fun h ↦ h ▸ ⟨.refl _⟩⟩
@[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) :
i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) :=
rfl
@[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) :
Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) :=
rfl
@[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id :=
rfl
@[simp]
theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } :=
Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩
@[simp]
theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) :
((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by
rw [← coe_castLE h]
exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _)
theorem leftInverse_cast (eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq) :=
fun _ => rfl
theorem rightInverse_cast (eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq) :=
fun _ => rfl
@[simp]
theorem cast_inj (eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b := by
simp [← val_inj]
@[simp]
theorem cast_lt_cast (eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b :=
Iff.rfl
@[simp]
theorem cast_le_cast (eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b :=
Iff.rfl
/-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/
@[simps]
def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where
toFun := Fin.cast eq
invFun := Fin.cast eq.symm
left_inv := leftInverse_cast eq
right_inv := rightInverse_cast eq
@[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) :
finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl
@[simp]
lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp
@[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl
@[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl
lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl
/-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp
/-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
theorem cast_eq_cast (h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by
subst h
ext
rfl
/-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`.
See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/
def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m)
@[simp]
lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl
lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl
/-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/
def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _
@[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl
lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl
theorem castSucc_le_succ {n} (i : Fin n) : i.castSucc ≤ i.succ := Nat.le_succ i
@[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := .rfl
@[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by
rw [le_castSucc_iff, succ_lt_succ_iff]
@[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by
rw [castSucc_lt_iff_succ_le, succ_le_succ_iff]
theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n}
(hl : castSucc i < a) (hu : b < succ i) : b < a := by
simp [Fin.lt_def, -val_fin_lt] at *; omega
theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by
simp [Fin.lt_def, -val_fin_lt]; omega
theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by
rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le]
exact p.castSucc_lt_or_lt_succ i
theorem eq_castSucc_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) :
∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h
@[deprecated (since := "2025-02-06")]
alias exists_castSucc_eq_of_ne_last := eq_castSucc_of_ne_last
theorem forall_fin_succ' {P : Fin (n + 1) → Prop} :
(∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) :=
⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩
-- to match `Fin.eq_zero_or_eq_succ`
theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) :
(∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩)
@[simp]
theorem castSucc_ne_last {n : ℕ} (i : Fin n) : i.castSucc ≠ .last n :=
Fin.ne_of_lt i.castSucc_lt_last
theorem exists_fin_succ' {P : Fin (n + 1) → Prop} :
(∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) :=
⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h,
fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩
/--
The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := rfl
@[simp]
theorem castSucc_pos_iff [NeZero n] {i : Fin n} : 0 < castSucc i ↔ 0 < i := by simp [← val_pos_iff]
/-- `castSucc i` is positive when `i` is positive.
The `Fin.castSucc_pos` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis. -/
alias ⟨_, castSucc_pos'⟩ := castSucc_pos_iff
/--
The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 :=
Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm
/--
The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 :=
not_iff_not.mpr <| castSucc_eq_zero_iff' a
theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucc i ≠ 0 := by
cases n
· exact i.elim0
· rw [castSucc_ne_zero_iff', Ne, Fin.ext_iff]
exact ((zero_le _).trans_lt h).ne'
theorem succ_ne_last_iff (a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n :=
not_iff_not.mpr <| succ_eq_last_succ
theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succ i ≠ last n := by
cases n
· exact i.elim0
· rw [succ_ne_last_iff, Ne, Fin.ext_iff]
exact ((le_last _).trans_lt' h).ne
@[norm_cast, simp]
theorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by
ext
exact val_cast_of_lt (Nat.lt.step a.is_lt)
theorem coe_succ_lt_iff_lt {n : ℕ} {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k := by
simp only [coe_eq_castSucc, castSucc_lt_castSucc_iff]
@[simp]
theorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) =
({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega)
@[simp]
theorem coe_of_injective_castSucc_symm {n : ℕ} (i : Fin n.succ) (hi) :
((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i := by
rw [← coe_castSucc]
exact congr_arg val (Equiv.apply_ofInjective_symm _ _)
/-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/
@[simps! apply]
def addNatEmb (m) : Fin n ↪ Fin (n + m) where
toFun := (addNat · m)
inj' a b := by simp [Fin.ext_iff]
/-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/
@[simps! apply]
def natAddEmb (n) {m} : Fin m ↪ Fin (n + m) where
toFun := natAdd n
inj' a b := by simp [Fin.ext_iff]
theorem castSucc_castAdd (i : Fin n) : castSucc (castAdd m i) = castAdd (m + 1) i := rfl
theorem castSucc_natAdd (i : Fin m) : castSucc (natAdd n i) = natAdd n (castSucc i) := rfl
theorem succ_castAdd (i : Fin n) : succ (castAdd m i) =
if h : i.succ = last _ then natAdd n (0 : Fin (m + 1))
else castAdd (m + 1) ⟨i.1 + 1, lt_of_le_of_ne i.2 (Fin.val_ne_iff.mpr h)⟩ := by
split_ifs with h
exacts [Fin.ext (congr_arg Fin.val h :), rfl]
theorem succ_natAdd (i : Fin m) : succ (natAdd n i) = natAdd n (succ i) := rfl
end Succ
section Pred
/-!
### pred
-/
theorem pred_one' [NeZero n] (h := (zero_ne_one' (n := n)).symm) :
Fin.pred (1 : Fin (n + 1)) h = 0 := by
simp_rw [Fin.ext_iff, coe_pred, val_one', val_zero, Nat.sub_eq_zero_iff_le, Nat.mod_le]
theorem pred_last (h := Fin.ext_iff.not.2 last_pos'.ne') :
pred (last (n + 1)) h = last n := by simp_rw [← succ_last, pred_succ]
theorem pred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi < j ↔ i < succ j := by
rw [← succ_lt_succ_iff, succ_pred]
theorem lt_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i := by
rw [← succ_lt_succ_iff, succ_pred]
theorem pred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi ≤ j ↔ i ≤ succ j := by
rw [← succ_le_succ_iff, succ_pred]
theorem le_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i := by
rw [← succ_le_succ_iff, succ_pred]
theorem castSucc_pred_eq_pred_castSucc {a : Fin (n + 1)} (ha : a ≠ 0)
(ha' := castSucc_ne_zero_iff.mpr ha) :
(a.pred ha).castSucc = (castSucc a).pred ha' := rfl
theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) :
(a.pred ha).castSucc + 1 = a := by
cases a using cases
· exact (ha rfl).elim
· rw [pred_succ, coeSucc_eq_succ]
theorem le_pred_castSucc_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) :
b ≤ (castSucc a).pred ha ↔ b < a := by
rw [le_pred_iff, succ_le_castSucc_iff]
theorem pred_castSucc_lt_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) :
(castSucc a).pred ha < b ↔ a ≤ b := by
rw [pred_lt_iff, castSucc_lt_succ_iff]
theorem pred_castSucc_lt {a : Fin (n + 1)} (ha : castSucc a ≠ 0) :
(castSucc a).pred ha < a := by rw [pred_castSucc_lt_iff, le_def]
theorem le_castSucc_pred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) :
b ≤ castSucc (a.pred ha) ↔ b < a := by
rw [castSucc_pred_eq_pred_castSucc, le_pred_castSucc_iff]
theorem castSucc_pred_lt_iff {a b : Fin (n + 1)} (ha : a ≠ 0) :
castSucc (a.pred ha) < b ↔ a ≤ b := by
rw [castSucc_pred_eq_pred_castSucc, pred_castSucc_lt_iff]
theorem castSucc_pred_lt {a : Fin (n + 1)} (ha : a ≠ 0) :
castSucc (a.pred ha) < a := by rw [castSucc_pred_lt_iff, le_def]
end Pred
section CastPred
/-- `castPred i` sends `i : Fin (n + 1)` to `Fin n` as long as i ≠ last n. -/
@[inline] def castPred (i : Fin (n + 1)) (h : i ≠ last n) : Fin n := castLT i (val_lt_last h)
@[simp]
lemma castLT_eq_castPred (i : Fin (n + 1)) (h : i < last _) (h' := Fin.ext_iff.not.2 h.ne) :
castLT i h = castPred i h' := rfl
@[simp]
lemma coe_castPred (i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ℕ) = i := rfl
@[simp]
theorem castPred_castSucc {i : Fin n} (h' := Fin.ext_iff.not.2 (castSucc_lt_last i).ne) :
castPred (castSucc i) h' = i := rfl
@[simp]
theorem castSucc_castPred (i : Fin (n + 1)) (h : i ≠ last n) :
castSucc (i.castPred h) = i := by
rcases exists_castSucc_eq.mpr h with ⟨y, rfl⟩
rw [castPred_castSucc]
theorem castPred_eq_iff_eq_castSucc (i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) :
castPred i hi = j ↔ i = castSucc j :=
⟨fun h => by rw [← h, castSucc_castPred], fun h => by simp_rw [h, castPred_castSucc]⟩
@[simp]
theorem castPred_mk (i : ℕ) (h₁ : i < n) (h₂ := h₁.trans (Nat.lt_succ_self _))
(h₃ : ⟨i, h₂⟩ ≠ last _ := (ne_iff_vne _ _).mpr (val_last _ ▸ h₁.ne)) :
castPred ⟨i, h₂⟩ h₃ = ⟨i, h₁⟩ := rfl
@[simp]
theorem castPred_le_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
castPred i hi ≤ castPred j hj ↔ i ≤ j := Iff.rfl
/-- A version of the right-to-left implication of `castPred_le_castPred_iff`
that deduces `i ≠ last n` from `i ≤ j` and `j ≠ last n`. -/
@[gcongr]
theorem castPred_le_castPred {i j : Fin (n + 1)} (h : i ≤ j) (hj : j ≠ last n) :
castPred i (by rw [← lt_last_iff_ne_last] at hj ⊢; exact Fin.lt_of_le_of_lt h hj) ≤
castPred j hj :=
h
@[simp]
theorem castPred_lt_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
castPred i hi < castPred j hj ↔ i < j := Iff.rfl
/-- A version of the right-to-left implication of `castPred_lt_castPred_iff`
that deduces `i ≠ last n` from `i < j`. -/
@[gcongr]
theorem castPred_lt_castPred {i j : Fin (n + 1)} (h : i < j) (hj : j ≠ last n) :
castPred i (ne_last_of_lt h) < castPred j hj := h
theorem castPred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
castPred i hi < j ↔ i < castSucc j := by
rw [← castSucc_lt_castSucc_iff, castSucc_castPred]
theorem lt_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
j < castPred i hi ↔ castSucc j < i := by
rw [← castSucc_lt_castSucc_iff, castSucc_castPred]
theorem castPred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
castPred i hi ≤ j ↔ i ≤ castSucc j := by
rw [← castSucc_le_castSucc_iff, castSucc_castPred]
theorem le_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
j ≤ castPred i hi ↔ castSucc j ≤ i := by
rw [← castSucc_le_castSucc_iff, castSucc_castPred]
@[simp]
theorem castPred_inj {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
castPred i hi = castPred j hj ↔ i = j := by
simp_rw [Fin.ext_iff, le_antisymm_iff, ← le_def, castPred_le_castPred_iff]
theorem castPred_zero' [NeZero n] (h := Fin.ext_iff.not.2 last_pos'.ne) :
castPred (0 : Fin (n + 1)) h = 0 := rfl
theorem castPred_zero (h := Fin.ext_iff.not.2 last_pos.ne) :
castPred (0 : Fin (n + 2)) h = 0 := rfl
@[simp]
theorem castPred_eq_zero [NeZero n] {i : Fin (n + 1)} (h : i ≠ last n) :
Fin.castPred i h = 0 ↔ i = 0 := by
rw [← castPred_zero', castPred_inj]
@[simp]
theorem castPred_one [NeZero n] (h := Fin.ext_iff.not.2 one_lt_last.ne) :
castPred (1 : Fin (n + 2)) h = 1 := by
cases n
· exact subsingleton_one.elim _ 1
· rfl
theorem succ_castPred_eq_castPred_succ {a : Fin (n + 1)} (ha : a ≠ last n)
(ha' := a.succ_ne_last_iff.mpr ha) :
(a.castPred ha).succ = (succ a).castPred ha' := rfl
theorem succ_castPred_eq_add_one {a : Fin (n + 1)} (ha : a ≠ last n) :
(a.castPred ha).succ = a + 1 := by
cases a using lastCases
· exact (ha rfl).elim
· rw [castPred_castSucc, coeSucc_eq_succ]
theorem castpred_succ_le_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) :
(succ a).castPred ha ≤ b ↔ a < b := by
rw [castPred_le_iff, succ_le_castSucc_iff]
theorem lt_castPred_succ_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) :
b < (succ a).castPred ha ↔ b ≤ a := by
rw [lt_castPred_iff, castSucc_lt_succ_iff]
theorem lt_castPred_succ {a : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) :
a < (succ a).castPred ha := by rw [lt_castPred_succ_iff, le_def]
theorem succ_castPred_le_iff {a b : Fin (n + 1)} (ha : a ≠ last n) :
succ (a.castPred ha) ≤ b ↔ a < b := by
rw [succ_castPred_eq_castPred_succ ha, castpred_succ_le_iff]
theorem lt_succ_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) :
b < succ (a.castPred ha) ↔ b ≤ a := by
rw [succ_castPred_eq_castPred_succ ha, lt_castPred_succ_iff]
theorem lt_succ_castPred {a : Fin (n + 1)} (ha : a ≠ last n) :
a < succ (a.castPred ha) := by rw [lt_succ_castPred_iff, le_def]
theorem castPred_le_pred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) (hb : b ≠ 0) :
castPred a ha ≤ pred b hb ↔ a < b := by
rw [le_pred_iff, succ_castPred_le_iff]
theorem pred_lt_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ last n) :
pred a ha < castPred b hb ↔ a ≤ b := by
rw [lt_castPred_iff, castSucc_pred_lt_iff ha]
theorem pred_lt_castPred {a : Fin (n + 1)} (h₁ : a ≠ 0) (h₂ : a ≠ last n) :
pred a h₁ < castPred a h₂ := by
rw [pred_lt_castPred_iff, le_def]
end CastPred
section SuccAbove
variable {p : Fin (n + 1)} {i j : Fin n}
/-- `succAbove p i` embeds `Fin n` into `Fin (n + 1)` with a hole around `p`. -/
def succAbove (p : Fin (n + 1)) (i : Fin n) : Fin (n + 1) :=
if castSucc i < p then i.castSucc else i.succ
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
embeds `i` by `castSucc` when the resulting `i.castSucc < p`. -/
lemma succAbove_of_castSucc_lt (p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) :
p.succAbove i = castSucc i := if_pos h
lemma succAbove_of_succ_le (p : Fin (n + 1)) (i : Fin n) (h : succ i ≤ p) :
p.succAbove i = castSucc i :=
succAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h)
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
embeds `i` by `succ` when the resulting `p < i.succ`. -/
lemma succAbove_of_le_castSucc (p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) :
p.succAbove i = i.succ := if_neg (Fin.not_lt.2 h)
lemma succAbove_of_lt_succ (p : Fin (n + 1)) (i : Fin n) (h : p < succ i) :
p.succAbove i = succ i := succAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h)
lemma succAbove_succ_of_lt (p i : Fin n) (h : p < i) : succAbove p.succ i = i.succ :=
succAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h)
lemma succAbove_succ_of_le (p i : Fin n) (h : i ≤ p) : succAbove p.succ i = i.castSucc :=
succAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h)
@[simp] lemma succAbove_succ_self (j : Fin n) : j.succ.succAbove j = j.castSucc :=
succAbove_succ_of_le _ _ Fin.le_rfl
lemma succAbove_castSucc_of_lt (p i : Fin n) (h : i < p) : succAbove p.castSucc i = i.castSucc :=
succAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h)
lemma succAbove_castSucc_of_le (p i : Fin n) (h : p ≤ i) : succAbove p.castSucc i = i.succ :=
succAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.2 h)
@[simp] lemma succAbove_castSucc_self (j : Fin n) : succAbove j.castSucc j = j.succ :=
succAbove_castSucc_of_le _ _ Fin.le_rfl
lemma succAbove_pred_of_lt (p i : Fin (n + 1)) (h : p < i)
(hi := Fin.ne_of_gt <| Fin.lt_of_le_of_lt p.zero_le h) : succAbove p (i.pred hi) = i := by
rw [succAbove_of_lt_succ _ _ (succ_pred _ _ ▸ h), succ_pred]
lemma succAbove_pred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hi : i ≠ 0) :
succAbove p (i.pred hi) = (i.pred hi).castSucc := succAbove_of_succ_le _ _ (succ_pred _ _ ▸ h)
@[simp] lemma succAbove_pred_self (p : Fin (n + 1)) (h : p ≠ 0) :
succAbove p (p.pred h) = (p.pred h).castSucc := succAbove_pred_of_le _ _ Fin.le_rfl h
lemma succAbove_castPred_of_lt (p i : Fin (n + 1)) (h : i < p)
(hi := Fin.ne_of_lt <| Nat.lt_of_lt_of_le h p.le_last) : succAbove p (i.castPred hi) = i := by
rw [succAbove_of_castSucc_lt _ _ (castSucc_castPred _ _ ▸ h), castSucc_castPred]
lemma succAbove_castPred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hi : i ≠ last n) :
succAbove p (i.castPred hi) = (i.castPred hi).succ :=
succAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h)
lemma succAbove_castPred_self (p : Fin (n + 1)) (h : p ≠ last n) :
succAbove p (p.castPred h) = (p.castPred h).succ := succAbove_castPred_of_le _ _ Fin.le_rfl h
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
never results in `p` itself -/
@[simp]
lemma succAbove_ne (p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p := by
rcases p.castSucc_lt_or_lt_succ i with (h | h)
· rw [succAbove_of_castSucc_lt _ _ h]
exact Fin.ne_of_lt h
· rw [succAbove_of_lt_succ _ _ h]
exact Fin.ne_of_gt h
@[simp]
lemma ne_succAbove (p : Fin (n + 1)) (i : Fin n) : p ≠ p.succAbove i := (succAbove_ne _ _).symm
/-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/
lemma succAbove_right_injective : Injective p.succAbove := by
rintro i j hij
unfold succAbove at hij
split_ifs at hij with hi hj hj
· exact castSucc_injective _ hij
· rw [hij] at hi
cases hj <| Nat.lt_trans j.castSucc_lt_succ hi
· rw [← hij] at hj
cases hi <| Nat.lt_trans i.castSucc_lt_succ hj
· exact succ_injective _ hij
/-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/
lemma succAbove_right_inj : p.succAbove i = p.succAbove j ↔ i = j :=
succAbove_right_injective.eq_iff
/-- `Fin.succAbove p` as an `Embedding`. -/
@[simps!]
def succAboveEmb (p : Fin (n + 1)) : Fin n ↪ Fin (n + 1) := ⟨p.succAbove, succAbove_right_injective⟩
@[simp, norm_cast] lemma coe_succAboveEmb (p : Fin (n + 1)) : p.succAboveEmb = p.succAbove := rfl
@[simp]
lemma succAbove_ne_zero_zero [NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0 := by
rw [Fin.succAbove_of_castSucc_lt]
· exact castSucc_zero'
· exact Fin.pos_iff_ne_zero.2 ha
lemma succAbove_eq_zero_iff [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) :
a.succAbove b = 0 ↔ b = 0 := by
rw [← succAbove_ne_zero_zero ha, succAbove_right_inj]
lemma succAbove_ne_zero [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) :
a.succAbove b ≠ 0 := mt (succAbove_eq_zero_iff ha).mp hb
/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around zero embeds by `succ`. -/
@[simp] lemma succAbove_zero : succAbove (0 : Fin (n + 1)) = Fin.succ := rfl
lemma succAbove_zero_apply (i : Fin n) : succAbove 0 i = succ i := by rw [succAbove_zero]
@[simp] lemma succAbove_ne_last_last {a : Fin (n + 2)} (h : a ≠ last (n + 1)) :
a.succAbove (last n) = last (n + 1) := by
rw [succAbove_of_lt_succ _ _ (succ_last _ ▸ lt_last_iff_ne_last.2 h), succ_last]
lemma succAbove_eq_last_iff {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) :
a.succAbove b = last _ ↔ b = last _ := by
rw [← succAbove_ne_last_last ha, succAbove_right_inj]
lemma succAbove_ne_last {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) (hb : b ≠ last _) :
a.succAbove b ≠ last _ := mt (succAbove_eq_last_iff ha).mp hb
/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around `last n` embeds by `castSucc`. -/
@[simp] lemma succAbove_last : succAbove (last n) = castSucc := by
ext; simp only [succAbove_of_castSucc_lt, castSucc_lt_last]
lemma succAbove_last_apply (i : Fin n) : succAbove (last n) i = castSucc i := by rw [succAbove_last]
/-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is greater
results in a value that is less than `p`. -/
lemma succAbove_lt_iff_castSucc_lt (p : Fin (n + 1)) (i : Fin n) :
p.succAbove i < p ↔ castSucc i < p := by
rcases castSucc_lt_or_lt_succ p i with H | H
· rwa [iff_true_right H, succAbove_of_castSucc_lt _ _ H]
· rw [castSucc_lt_iff_succ_le, iff_false_right (Fin.not_le.2 H), succAbove_of_lt_succ _ _ H]
exact Fin.not_lt.2 <| Fin.le_of_lt H
lemma succAbove_lt_iff_succ_le (p : Fin (n + 1)) (i : Fin n) :
p.succAbove i < p ↔ succ i ≤ p := by
rw [succAbove_lt_iff_castSucc_lt, castSucc_lt_iff_succ_le]
/-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is lesser
results in a value that is greater than `p`. -/
lemma lt_succAbove_iff_le_castSucc (p : Fin (n + 1)) (i : Fin n) :
p < p.succAbove i ↔ p ≤ castSucc i := by
rcases castSucc_lt_or_lt_succ p i with H | H
· rw [iff_false_right (Fin.not_le.2 H), succAbove_of_castSucc_lt _ _ H]
exact Fin.not_lt.2 <| Fin.le_of_lt H
· rwa [succAbove_of_lt_succ _ _ H, iff_true_left H, le_castSucc_iff]
lemma lt_succAbove_iff_lt_castSucc (p : Fin (n + 1)) (i : Fin n) :
p < p.succAbove i ↔ p < succ i := by rw [lt_succAbove_iff_le_castSucc, le_castSucc_iff]
/-- Embedding a positive `Fin n` results in a positive `Fin (n + 1)` -/
lemma succAbove_pos [NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i := by
by_cases H : castSucc i < p
· simpa [succAbove_of_castSucc_lt _ _ H] using castSucc_pos' h
· simp [succAbove_of_le_castSucc _ _ (Fin.not_lt.1 H)]
lemma castPred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : castSucc x < y)
(h' := Fin.ne_last_of_lt <| (succAbove_lt_iff_castSucc_lt ..).2 h) :
(y.succAbove x).castPred h' = x := by
rw [castPred_eq_iff_eq_castSucc, succAbove_of_castSucc_lt _ _ h]
lemma pred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : y ≤ castSucc x)
(h' := Fin.ne_zero_of_lt <| (lt_succAbove_iff_le_castSucc ..).2 h) :
(y.succAbove x).pred h' = x := by simp only [succAbove_of_le_castSucc _ _ h, pred_succ]
lemma exists_succAbove_eq {x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x := by
obtain hxy | hyx := Fin.lt_or_lt_of_ne h
exacts [⟨_, succAbove_castPred_of_lt _ _ hxy⟩, ⟨_, succAbove_pred_of_lt _ _ hyx⟩]
@[simp] lemma exists_succAbove_eq_iff {x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x :=
⟨by rintro ⟨y, rfl⟩; exact succAbove_ne _ _, exists_succAbove_eq⟩
/-- The range of `p.succAbove` is everything except `p`. -/
@[simp] lemma range_succAbove (p : Fin (n + 1)) : Set.range p.succAbove = {p}ᶜ :=
Set.ext fun _ => exists_succAbove_eq_iff
@[simp] lemma range_succ (n : ℕ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}ᶜ := by
rw [← succAbove_zero]; exact range_succAbove (0 : Fin (n + 1))
/-- `succAbove` is injective at the pivot -/
lemma succAbove_left_injective : Injective (@succAbove n) := fun _ _ h => by
simpa [range_succAbove] using congr_arg (fun f : Fin n → Fin (n + 1) => (Set.range f)ᶜ) h
/-- `succAbove` is injective at the pivot -/
@[simp] lemma succAbove_left_inj {x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y :=
succAbove_left_injective.eq_iff
@[simp] lemma zero_succAbove {n : ℕ} (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ := rfl
lemma succ_succAbove_zero {n : ℕ} [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0 := by simp
/-- `succ` commutes with `succAbove`. -/
@[simp] lemma succ_succAbove_succ {n : ℕ} (i : Fin (n + 1)) (j : Fin n) :
i.succ.succAbove j.succ = (i.succAbove j).succ := by
obtain h | h := i.lt_or_le (succ j)
· rw [succAbove_of_lt_succ _ _ h, succAbove_succ_of_lt _ _ h]
· rwa [succAbove_of_castSucc_lt _ _ h, succAbove_succ_of_le, succ_castSucc]
/-- `castSucc` commutes with `succAbove`. -/
@[simp]
lemma castSucc_succAbove_castSucc {n : ℕ} {i : Fin (n + 1)} {j : Fin n} :
i.castSucc.succAbove j.castSucc = (i.succAbove j).castSucc := by
rcases i.le_or_lt (castSucc j) with (h | h)
· rw [succAbove_of_le_castSucc _ _ h, succAbove_castSucc_of_le _ _ h, succ_castSucc]
· rw [succAbove_of_castSucc_lt _ _ h, succAbove_castSucc_of_lt _ _ h]
/-- `pred` commutes with `succAbove`. -/
lemma pred_succAbove_pred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0)
(hk := succAbove_ne_zero ha hb) :
(a.pred ha).succAbove (b.pred hb) = (a.succAbove b).pred hk := by
simp_rw [← succ_inj (b := pred (succAbove a b) hk), ← succ_succAbove_succ, succ_pred]
/-- `castPred` commutes with `succAbove`. -/
lemma castPred_succAbove_castPred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last (n + 1))
(hb : b ≠ last n) (hk := succAbove_ne_last ha hb) :
(a.castPred ha).succAbove (b.castPred hb) = (a.succAbove b).castPred hk := by
| simp_rw [← castSucc_inj (b := (a.succAbove b).castPred hk), ← castSucc_succAbove_castSucc,
castSucc_castPred]
| Mathlib/Data/Fin/Basic.lean | 1,149 | 1,151 |
/-
Copyright (c) 2024 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Analysis.Complex.LocallyUniformLimit
import Mathlib.NumberTheory.LSeries.Convergence
import Mathlib.Analysis.SpecialFunctions.Pow.Deriv
import Mathlib.Analysis.Complex.HalfPlane
/-!
# Differentiability and derivatives of L-series
## Main results
* We show that the `LSeries` of `f` is differentiable at `s` when `re s` is greater than
the abscissa of absolute convergence of `f` (`LSeries.hasDerivAt`) and that its derivative
there is the negative of the `LSeries` of the point-wise product `log * f` (`LSeries.deriv`).
* We prove similar results for iterated derivatives (`LSeries.iteratedDeriv`).
* We use this to show that `LSeries f` is holomorphic on the right half-plane of
absolute convergence (`LSeries.analyticOnNhd`).
## Implementation notes
We introduce `LSeries.logMul` as an abbreviation for the point-wise product `log * f`, to avoid
the problem that this expression does not type-check.
-/
open Complex LSeries
/-!
### The derivative of an L-series
-/
/-- The (point-wise) product of `log : ℕ → ℂ` with `f`. -/
noncomputable abbrev LSeries.logMul (f : ℕ → ℂ) (n : ℕ) : ℂ := log n * f n
| /-- The derivative of the terms of an L-series. -/
lemma LSeries.hasDerivAt_term (f : ℕ → ℂ) (n : ℕ) (s : ℂ) :
HasDerivAt (fun z ↦ term f z n) (-(term (logMul f) s n)) s := by
rcases eq_or_ne n 0 with rfl | hn
· simp [hasDerivAt_const]
simp_rw [term_of_ne_zero hn, ← neg_div, ← neg_mul, mul_comm, mul_div_assoc, div_eq_mul_inv,
← cpow_neg]
exact HasDerivAt.const_mul (f n) (by simpa only [mul_comm, ← mul_neg_one (log n), ← mul_assoc]
using (hasDerivAt_neg' s).const_cpow (Or.inl <| Nat.cast_ne_zero.mpr hn))
| Mathlib/NumberTheory/LSeries/Deriv.lean | 40 | 48 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Jakob von Raumer
-/
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
/-!
# Biproducts and binary biproducts
We introduce the notion of (finite) biproducts.
Binary biproducts are defined in `CategoryTheory.Limits.Shapes.BinaryBiproducts`.
These are slightly unusual relative to the other shapes in the library,
as they are simultaneously limits and colimits.
(Zero objects are similar; they are "biterminal".)
For results about biproducts in preadditive categories see
`CategoryTheory.Preadditive.Biproducts`.
For biproducts indexed by a `Fintype J`, a `bicone` consists of a cone point `X`
and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`,
such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
## Notation
As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for
a binary biproduct. We introduce `⨁ f` for the indexed biproduct.
## Implementation notes
Prior to https://github.com/leanprover-community/mathlib3/pull/14046,
`HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type.
As this had no pay-off (everything about limits is non-constructive in mathlib),
and occasional cost
(constructing decidability instances appropriate for constructions involving the indexing type),
we made everything classical.
-/
noncomputable section
universe w w' v u
open CategoryTheory Functor
namespace CategoryTheory.Limits
variable {J : Type w}
universe uC' uC uD' uD
variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C]
variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D]
open scoped Classical in
/-- A `c : Bicone F` is:
* an object `c.pt` and
* morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`,
* such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
-/
structure Bicone (F : J → C) where
pt : C
π : ∀ j, pt ⟶ F j
ι : ∀ j, F j ⟶ pt
ι_π : ∀ j j', ι j ≫ π j' =
if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop
attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π
@[reassoc (attr := simp)]
theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by
simpa using B.ι_π j j
@[reassoc (attr := simp)]
theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by
simpa [h] using B.ι_π j j'
variable {F : J → C}
/-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points
which commutes with the cone and cocone legs. -/
structure BiconeMorphism {F : J → C} (A B : Bicone F) where
/-- A morphism between the two vertex objects of the bicones -/
hom : A.pt ⟶ B.pt
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wπ : ∀ j : J, hom ≫ B.π j = A.π j := by aesop_cat
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by aesop_cat
attribute [reassoc (attr := simp)] BiconeMorphism.wι BiconeMorphism.wπ
/-- The category of bicones on a given diagram. -/
@[simps]
instance Bicone.category : Category (Bicone F) where
Hom A B := BiconeMorphism A B
comp f g := { hom := f.hom ≫ g.hom }
id B := { hom := 𝟙 B.pt }
-- Porting note: if we do not have `simps` automatically generate the lemma for simplifying
-- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical
-- morphism, rather than the underlying structure.
@[ext]
theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by
cases f
cases g
congr
namespace Bicones
/-- To give an isomorphism between cocones, it suffices to give an
isomorphism between their vertices which commutes with the cocone
maps. -/
@[aesop apply safe (rule_sets := [CategoryTheory]), simps]
def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt)
(wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by aesop_cat)
(wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by aesop_cat) : c ≅ c' where
hom := { hom := φ.hom }
inv :=
{ hom := φ.inv
wι := fun j => φ.comp_inv_eq.mpr (wι j).symm
wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm }
variable (F) in
| /-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/
@[simps]
def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] :
Bicone F ⥤ Bicone (G.obj ∘ F) where
| Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean | 122 | 125 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Fin.Fin2
import Mathlib.Data.PFun
import Mathlib.Data.Vector3
import Mathlib.NumberTheory.PellMatiyasevic
/-!
# Diophantine functions and Matiyasevic's theorem
Hilbert's tenth problem asked whether there exists an algorithm which for a given integer polynomial
determines whether this polynomial has integer solutions. It was answered in the negative in 1970,
the final step being completed by Matiyasevic who showed that the power function is Diophantine.
Here a function is called Diophantine if its graph is Diophantine as a set. A subset `S ⊆ ℕ ^ α` in
turn is called Diophantine if there exists an integer polynomial on `α ⊕ β` such that `v ∈ S` iff
there exists `t : ℕ^β` with `p (v, t) = 0`.
## Main definitions
* `IsPoly`: a predicate stating that a function is a multivariate integer polynomial.
* `Poly`: the type of multivariate integer polynomial functions.
* `Dioph`: a predicate stating that a set is Diophantine, i.e. a set `S ⊆ ℕ^α` is
Diophantine if there exists a polynomial on `α ⊕ β` such that `v ∈ S` iff there
exists `t : ℕ^β` with `p (v, t) = 0`.
* `DiophFn`: a predicate on a function stating that it is Diophantine in the sense that its graph
is Diophantine as a set.
## Main statements
* `pell_dioph` states that solutions to Pell's equation form a Diophantine set.
* `pow_dioph` states that the power function is Diophantine, a version of Matiyasevic's theorem.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevic's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Matiyasevic's theorem, Hilbert's tenth problem
## TODO
* Finish the solution of Hilbert's tenth problem.
* Connect `Poly` to `MvPolynomial`
-/
open Fin2 Function Nat Sum
local infixr:67 " ::ₒ " => Option.elim'
local infixr:65 " ⊗ " => Sum.elim
universe u
/-!
### Multivariate integer polynomials
Note that this duplicates `MvPolynomial`.
-/
section Polynomials
variable {α β : Type*}
/-- A predicate asserting that a function is a multivariate integer polynomial.
(We are being a bit lazy here by allowing many representations for multiplication,
rather than only allowing monomials and addition, but the definition is equivalent
and this is easier to use.) -/
inductive IsPoly : ((α → ℕ) → ℤ) → Prop
| proj : ∀ i, IsPoly fun x : α → ℕ => x i
| const : ∀ n : ℤ, IsPoly fun _ : α → ℕ => n
| sub : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x - g x
| mul : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x * g x
theorem IsPoly.neg {f : (α → ℕ) → ℤ} : IsPoly f → IsPoly (-f) := by
rw [← zero_sub]; exact (IsPoly.const 0).sub
theorem IsPoly.add {f g : (α → ℕ) → ℤ} (hf : IsPoly f) (hg : IsPoly g) : IsPoly (f + g) := by
rw [← sub_neg_eq_add]; exact hf.sub hg.neg
/-- The type of multivariate integer polynomials -/
| def Poly (α : Type u) := { f : (α → ℕ) → ℤ // IsPoly f }
| Mathlib/NumberTheory/Dioph.lean | 89 | 90 |
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Simon Hudon
-/
import Mathlib.Control.Functor.Multivariate
import Mathlib.Data.PFunctor.Multivariate.Basic
import Mathlib.Data.PFunctor.Multivariate.M
import Mathlib.Data.QPF.Multivariate.Basic
/-!
# The final co-algebra of a multivariate qpf is again a qpf.
For a `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with
regards to its last argument `αₙ`. The result is an `n`-ary functor: `Fix F (α₀,..,αₙ₋₁)`.
Making `Fix F` into a functor allows us to take the fixed point, compose with other functors
and take a fixed point again.
## Main definitions
* `Cofix.mk` - constructor
* `Cofix.dest` - destructor
* `Cofix.corec` - corecursor: useful for formulating infinite, productive computations
* `Cofix.bisim` - bisimulation: proof technique to show the equality of possibly infinite values
of `Cofix F α`
## Implementation notes
For `F` a QPF, we define `Cofix F α` in terms of the M-type of the polynomial functor `P` of `F`.
We define the relation `Mcongr` and take its quotient as the definition of `Cofix F α`.
`Mcongr` is taken as the weakest bisimulation on M-type. See
[avigad-carneiro-hudon2019] for more details.
## Reference
* Jeremy Avigad, Mario M. Carneiro and Simon Hudon.
[*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019]
-/
universe u
open MvFunctor
namespace MvQPF
open TypeVec MvPFunctor
open MvFunctor (LiftP LiftR)
variable {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F]
/-- `corecF` is used as a basis for defining the corecursor of `Cofix F α`. `corecF`
uses corecursion to construct the M-type generated by `q.P` and uses function on `F`
as a corecursive step -/
def corecF {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) : β → q.P.M α :=
M.corec _ fun x => repr (g x)
theorem corecF_eq {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) (x : β) :
M.dest q.P (corecF g x) = appendFun id (corecF g) <$$> repr (g x) := by
rw [corecF, M.dest_corec]
/-- Characterization of desirable equivalence relations on M-types -/
def IsPrecongr {α : TypeVec n} (r : q.P.M α → q.P.M α → Prop) : Prop :=
∀ ⦃x y⦄,
r x y →
abs (appendFun id (Quot.mk r) <$$> M.dest q.P x) =
abs (appendFun id (Quot.mk r) <$$> M.dest q.P y)
/-- Equivalence relation on M-types representing a value of type `Cofix F` -/
def Mcongr {α : TypeVec n} (x y : q.P.M α) : Prop :=
∃ r, IsPrecongr r ∧ r x y
/-- Greatest fixed point of functor F. The result is a functor with one fewer parameters
than the input. For `F a b c` a ternary functor, fix F is a binary functor such that
```lean
Cofix F a b = F a b (Cofix F a b)
```
-/
def Cofix (F : TypeVec (n + 1) → Type u) [MvQPF F] (α : TypeVec n) :=
Quot (@Mcongr _ F _ α)
instance {α : TypeVec n} [Inhabited q.P.A] [∀ i : Fin2 n, Inhabited (α i)] :
Inhabited (Cofix F α) :=
⟨Quot.mk _ default⟩
/-- maps every element of the W type to a canonical representative -/
def mRepr {α : TypeVec n} : q.P.M α → q.P.M α :=
corecF (abs ∘ M.dest q.P)
/-- the map function for the functor `Cofix F` -/
def Cofix.map {α β : TypeVec n} (g : α ⟹ β) : Cofix F α → Cofix F β :=
Quot.lift (fun x : q.P.M α => Quot.mk Mcongr (g <$$> x))
(by
rintro aa₁ aa₂ ⟨r, pr, ra₁a₂⟩; apply Quot.sound
let r' b₁ b₂ := ∃ a₁ a₂ : q.P.M α, r a₁ a₂ ∧ b₁ = g <$$> a₁ ∧ b₂ = g <$$> a₂
use r'; constructor
· show IsPrecongr r'
rintro b₁ b₂ ⟨a₁, a₂, ra₁a₂, b₁eq, b₂eq⟩
let u : Quot r → Quot r' :=
Quot.lift (fun x : q.P.M α => Quot.mk r' (g <$$> x))
(by
intro a₁ a₂ ra₁a₂
apply Quot.sound
exact ⟨a₁, a₂, ra₁a₂, rfl, rfl⟩)
have hu : (Quot.mk r' ∘ fun x : q.P.M α => g <$$> x) = u ∘ Quot.mk r := by
ext x
rfl
rw [b₁eq, b₂eq, M.dest_map, M.dest_map, ← q.P.comp_map, ← q.P.comp_map]
rw [← appendFun_comp, id_comp, hu, ← comp_id g, appendFun_comp]
rw [q.P.comp_map, q.P.comp_map, abs_map, pr ra₁a₂, ← abs_map]
show r' (g <$$> aa₁) (g <$$> aa₂); exact ⟨aa₁, aa₂, ra₁a₂, rfl, rfl⟩)
instance Cofix.mvfunctor : MvFunctor (Cofix F) where map := @Cofix.map _ _ _
/-- Corecursor for `Cofix F` -/
def Cofix.corec {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) : β → Cofix F α := fun x =>
Quot.mk _ (corecF g x)
/-- Destructor for `Cofix F` -/
def Cofix.dest {α : TypeVec n} : Cofix F α → F (α.append1 (Cofix F α)) :=
Quot.lift (fun x => appendFun id (Quot.mk Mcongr) <$$> abs (M.dest q.P x))
(by
rintro x y ⟨r, pr, rxy⟩
dsimp
have : ∀ x y, r x y → Mcongr x y := by
intro x y h
exact ⟨r, pr, h⟩
rw [← Quot.factor_mk_eq _ _ this]
conv =>
lhs
rw [appendFun_comp_id, comp_map, ← abs_map, pr rxy, abs_map, ← comp_map,
← appendFun_comp_id])
/-- Abstraction function for `cofix F α` -/
def Cofix.abs {α} : q.P.M α → Cofix F α :=
Quot.mk _
/-- Representation function for `Cofix F α` -/
def Cofix.repr {α} : Cofix F α → q.P.M α :=
M.corec _ <| q.repr ∘ Cofix.dest
/-- Corecursor for `Cofix F` -/
def Cofix.corec'₁ {α : TypeVec n} {β : Type u} (g : ∀ {X}, (β → X) → F (α.append1 X)) (x : β) :
Cofix F α :=
Cofix.corec (fun _ => g id) x
/-- More flexible corecursor for `Cofix F`. Allows the return of a fully formed
value instead of making a recursive call -/
def Cofix.corec' {α : TypeVec n} {β : Type u} (g : β → F (α.append1 (Cofix F α ⊕ β))) (x : β) :
Cofix F α :=
let f : (α ::: Cofix F α) ⟹ (α ::: (Cofix F α ⊕ β)) := id ::: Sum.inl
Cofix.corec (Sum.elim (MvFunctor.map f ∘ Cofix.dest) g) (Sum.inr x : Cofix F α ⊕ β)
/-- Corecursor for `Cofix F`. The shape allows recursive calls to
look like recursive calls. -/
def Cofix.corec₁ {α : TypeVec n} {β : Type u}
(g : ∀ {X}, (Cofix F α → X) → (β → X) → β → F (α ::: X)) (x : β) : Cofix F α :=
Cofix.corec' (fun x => g Sum.inl Sum.inr x) x
theorem Cofix.dest_corec {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) (x : β) :
Cofix.dest (Cofix.corec g x) = appendFun id (Cofix.corec g) <$$> g x := by
conv =>
lhs
rw [Cofix.dest, Cofix.corec]
dsimp
rw [corecF_eq, abs_map, abs_repr, ← comp_map, ← appendFun_comp]; rfl
/-- constructor for `Cofix F` -/
def Cofix.mk {α : TypeVec n} : F (α.append1 <| Cofix F α) → Cofix F α :=
Cofix.corec fun x => (appendFun id fun i : Cofix F α => Cofix.dest.{u} i) <$$> x
/-!
## Bisimulation principles for `Cofix F`
The following theorems are bisimulation principles. The general idea
is to use a bisimulation relation to prove the equality between
specific values of type `Cofix F α`.
A bisimulation relation `R` for values `x y : Cofix F α`:
* holds for `x y`: `R x y`
* for any values `x y` that satisfy `R`, their root has the same shape
and their children can be paired in such a way that they satisfy `R`.
-/
private theorem Cofix.bisim_aux {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h' : ∀ x, r x x)
(h : ∀ x y, r x y →
appendFun id (Quot.mk r) <$$> Cofix.dest x = appendFun id (Quot.mk r) <$$> Cofix.dest y) :
∀ x y, r x y → x = y := by
intro x
rcases x; clear x; rename M (P F) α => x
intro y
rcases y; clear y; rename M (P F) α => y
intro rxy
apply Quot.sound
let r' := fun x y => r (Quot.mk _ x) (Quot.mk _ y)
have hr' : r' = fun x y => r (Quot.mk _ x) (Quot.mk _ y) := rfl
have : IsPrecongr r' := by
intro a b r'ab
have h₀ :
appendFun id (Quot.mk r ∘ Quot.mk Mcongr) <$$> MvQPF.abs (M.dest q.P a) =
appendFun id (Quot.mk r ∘ Quot.mk Mcongr) <$$> MvQPF.abs (M.dest q.P b) := by
rw [appendFun_comp_id, comp_map, comp_map]; exact h _ _ r'ab
have h₁ : ∀ u v : q.P.M α, Mcongr u v → Quot.mk r' u = Quot.mk r' v := by
intro u v cuv
apply Quot.sound
dsimp [r', hr']
rw [Quot.sound cuv]
apply h'
let f : Quot r → Quot r' :=
Quot.lift (Quot.lift (Quot.mk r') h₁)
(by
intro c
apply Quot.inductionOn
(motive := fun c =>
∀b, r c b → Quot.lift (Quot.mk r') h₁ c = Quot.lift (Quot.mk r') h₁ b) c
clear c
intro c d
apply Quot.inductionOn
(motive := fun d => r (Quot.mk Mcongr c) d →
Quot.lift (Quot.mk r') h₁ (Quot.mk Mcongr c) = Quot.lift (Quot.mk r') h₁ d) d
clear d
intro d rcd; apply Quot.sound; apply rcd)
have : f ∘ Quot.mk r ∘ Quot.mk Mcongr = Quot.mk r' := rfl
rw [← this, appendFun_comp_id, q.P.comp_map, q.P.comp_map, abs_map, abs_map, abs_map, abs_map,
h₀]
exact ⟨r', this, rxy⟩
/-- Bisimulation principle using `map` and `Quot.mk` to match and relate children of two trees. -/
theorem Cofix.bisim_rel {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop)
(h : ∀ x y, r x y →
appendFun id (Quot.mk r) <$$> Cofix.dest x = appendFun id (Quot.mk r) <$$> Cofix.dest y) :
∀ x y, r x y → x = y := by
let r' (x y) := x = y ∨ r x y
intro x y rxy
apply Cofix.bisim_aux r'
· intro x
left
rfl
· intro x y r'xy
cases r'xy with
| inl h =>
rw [h]
| inr r'xy =>
have : ∀ x y, r x y → r' x y := fun x y h => Or.inr h
rw [← Quot.factor_mk_eq _ _ this]
dsimp [r']
rw [appendFun_comp_id]
rw [@comp_map _ _ q _ _ _ (appendFun id (Quot.mk r)),
@comp_map _ _ q _ _ _ (appendFun id (Quot.mk r))]
rw [h _ _ r'xy]
right; exact rxy
|
/-- Bisimulation principle using `LiftR` to match and relate children of two trees. -/
theorem Cofix.bisim {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop)
(h : ∀ x y, r x y → LiftR (RelLast α r) (Cofix.dest x) (Cofix.dest y)) :
∀ x y, r x y → x = y := by
apply Cofix.bisim_rel
intro x y rxy
rcases (liftR_iff (fun a b => RelLast α r b) (dest x) (dest y)).mp (h x y rxy)
with ⟨a, f₀, f₁, dxeq, dyeq, h'⟩
rw [dxeq, dyeq, ← abs_map, ← abs_map, MvPFunctor.map_eq, MvPFunctor.map_eq]
rw [← split_dropFun_lastFun f₀, ← split_dropFun_lastFun f₁]
rw [appendFun_comp_splitFun, appendFun_comp_splitFun]
rw [id_comp, id_comp]
congr 2 with (i j); rcases i with - | i
· apply Quot.sound
apply h' _ j
· change f₀ _ j = f₁ _ j
apply h' _ j
open MvFunctor
/-- Bisimulation principle using `LiftR'` to match and relate children of two trees. -/
theorem Cofix.bisim₂ {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop)
| Mathlib/Data/QPF/Multivariate/Constructions/Cofix.lean | 258 | 280 |
/-
Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Data.Nat.EvenOddRec
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.LinearCombination
/-!
# Elliptic divisibility sequences
This file defines the type of an elliptic divisibility sequence (EDS) and a few examples.
## Mathematical background
Let `R` be a commutative ring. An elliptic sequence is a sequence `W : ℤ → R` satisfying
`W(m + n)W(m - n)W(r)² = W(m + r)W(m - r)W(n)² - W(n + r)W(n - r)W(m)²` for any `m, n, r ∈ ℤ`.
A divisibility sequence is a sequence `W : ℤ → R` satisfying `W(m) ∣ W(n)` for any `m, n ∈ ℤ` such
that `m ∣ n`. An elliptic divisibility sequence is simply a divisibility sequence that is elliptic.
Some examples of EDSs include
* the identity sequence,
* certain terms of Lucas sequences, and
* division polynomials of elliptic curves.
## Main definitions
* `IsEllSequence`: a sequence indexed by integers is an elliptic sequence.
* `IsDivSequence`: a sequence indexed by integers is a divisibility sequence.
* `IsEllDivSequence`: a sequence indexed by integers is an EDS.
* `preNormEDS'`: the auxiliary sequence for a normalised EDS indexed by `ℕ`.
* `preNormEDS`: the auxiliary sequence for a normalised EDS indexed by `ℤ`.
* `normEDS`: the canonical example of a normalised EDS indexed by `ℤ`.
## Main statements
* TODO: prove that `normEDS` satisfies `IsEllDivSequence`.
* TODO: prove that a normalised sequence satisfying `IsEllDivSequence` can be given by `normEDS`.
## Implementation notes
The normalised EDS `normEDS b c d n` is defined in terms of the auxiliary sequence
`preNormEDS (b ^ 4) c d n`, which are equal when `n` is odd, and which differ by a factor of `b`
when `n` is even. This coincides with the definition in the references since both agree for
`normEDS b c d 2` and for `normEDS b c d 4`, and the correct factors of `b` are removed in
`normEDS b c d (2 * (m + 2) + 1)` and in `normEDS b c d (2 * (m + 3))`.
One reason is to avoid the necessity for ring division by `b` in the inductive definition of
`normEDS b c d (2 * (m + 3))`. The idea is that, it can be shown that `normEDS b c d (2 * (m + 3))`
always contains a factor of `b`, so it is possible to remove a factor of `b` *a posteriori*, but
stating this lemma requires first defining `normEDS b c d (2 * (m + 3))`, which requires having this
factor of `b` *a priori*. Another reason is to allow the definition of univariate `n`-division
polynomials of elliptic curves, omitting a factor of the bivariate `2`-division polynomial.
## References
M Ward, *Memoir on Elliptic Divisibility Sequences*
## Tags
elliptic, divisibility, sequence
-/
universe u v
variable {R : Type u} [CommRing R]
section IsEllDivSequence
variable (W : ℤ → R)
/-- The proposition that a sequence indexed by integers is an elliptic sequence. -/
def IsEllSequence : Prop :=
∀ m n r : ℤ, W (m + n) * W (m - n) * W r ^ 2 =
W (m + r) * W (m - r) * W n ^ 2 - W (n + r) * W (n - r) * W m ^ 2
/-- The proposition that a sequence indexed by integers is a divisibility sequence. -/
def IsDivSequence : Prop :=
∀ m n : ℕ, m ∣ n → W m ∣ W n
/-- The proposition that a sequence indexed by integers is an EDS. -/
def IsEllDivSequence : Prop :=
IsEllSequence W ∧ IsDivSequence W
lemma isEllSequence_id : IsEllSequence id :=
fun _ _ _ => by simp only [id_eq]; ring1
lemma isDivSequence_id : IsDivSequence id :=
fun _ _ => Int.ofNat_dvd.mpr
/-- The identity sequence is an EDS. -/
theorem isEllDivSequence_id : IsEllDivSequence id :=
⟨isEllSequence_id, isDivSequence_id⟩
variable {W}
lemma IsEllSequence.smul (h : IsEllSequence W) (x : R) : IsEllSequence (x • W) :=
fun m n r => by
linear_combination (norm := (simp only [Pi.smul_apply, smul_eq_mul]; ring1)) x ^ 4 * h m n r
lemma IsDivSequence.smul (h : IsDivSequence W) (x : R) : IsDivSequence (x • W) :=
fun m n r => mul_dvd_mul_left x <| h m n r
lemma IsEllDivSequence.smul (h : IsEllDivSequence W) (x : R) : IsEllDivSequence (x • W) :=
⟨h.left.smul x, h.right.smul x⟩
end IsEllDivSequence
/-- Strong recursion principle for a normalised EDS: if we have
* `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`,
* for all `m : ℕ` we can prove `P (2 * (m + 3))` from `P k` for all `k < 2 * (m + 3)`, and
* for all `m : ℕ` we can prove `P (2 * (m + 2) + 1)` from `P k` for all `k < 2 * (m + 2) + 1`,
then we have `P n` for all `n : ℕ`. -/
@[elab_as_elim]
noncomputable def normEDSRec' {P : ℕ → Sort u}
(zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4)
(even : ∀ m : ℕ, (∀ k < 2 * (m + 3), P k) → P (2 * (m + 3)))
(odd : ∀ m : ℕ, (∀ k < 2 * (m + 2) + 1, P k) → P (2 * (m + 2) + 1)) (n : ℕ) : P n :=
n.evenOddStrongRec (by rintro (_ | _ | _ | _) h; exacts [zero, two, four, even _ h])
(by rintro (_ | _ | _) h; exacts [one, three, odd _ h])
/-- Recursion principle for a normalised EDS: if we have
* `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`,
* for all `m : ℕ` we can prove `P (2 * (m + 3))` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`,
`P (m + 4)`, and `P (m + 5)`, and
* for all `m : ℕ` we can prove `P (2 * (m + 2) + 1)` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`,
and `P (m + 4)`,
then we have `P n` for all `n : ℕ`. -/
@[elab_as_elim]
noncomputable def normEDSRec {P : ℕ → Sort u}
(zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4)
(even : ∀ m : ℕ, P (m + 1) → P (m + 2) → P (m + 3) → P (m + 4) → P (m + 5) → P (2 * (m + 3)))
(odd : ∀ m : ℕ, P (m + 1) → P (m + 2) → P (m + 3) → P (m + 4) → P (2 * (m + 2) + 1)) (n : ℕ) :
P n :=
normEDSRec' zero one two three four
(fun _ ih => by apply even <;> exact ih _ <| by linarith only)
(fun _ ih => by apply odd <;> exact ih _ <| by linarith only) n
variable (b c d : R)
section PreNormEDS
/-- The auxiliary sequence for a normalised EDS `W : ℕ → R`, with initial values
`W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`. -/
def preNormEDS' (b c d : R) : ℕ → R
| 0 => 0
| 1 => 1
| 2 => 1
| 3 => c
| 4 => d
| (n + 5) => let m := n / 2
have h4 : m + 4 < n + 5 := Nat.lt_succ.mpr <| add_le_add_right (n.div_le_self 2) 4
have h3 : m + 3 < n + 5 := (lt_add_one _).trans h4
have h2 : m + 2 < n + 5 := (lt_add_one _).trans h3
have _ : m + 1 < n + 5 := (lt_add_one _).trans h2
if hn : Even n then
preNormEDS' b c d (m + 4) * preNormEDS' b c d (m + 2) ^ 3 * (if Even m then b else 1) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) ^ 3 * (if Even m then 1 else b)
else
have _ : m + 5 < n + 5 := add_lt_add_right
(Nat.div_lt_self (Nat.not_even_iff_odd.1 hn).pos <| Nat.lt_succ_self 1) 5
preNormEDS' b c d (m + 2) ^ 2 * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 5) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 4) ^ 2
@[simp]
lemma preNormEDS'_zero : preNormEDS' b c d 0 = 0 := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_one : preNormEDS' b c d 1 = 1 := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_two : preNormEDS' b c d 2 = 1 := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_three : preNormEDS' b c d 3 = c := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_four : preNormEDS' b c d 4 = d := by
rw [preNormEDS']
lemma preNormEDS'_odd (m : ℕ) : preNormEDS' b c d (2 * (m + 2) + 1) =
preNormEDS' b c d (m + 4) * preNormEDS' b c d (m + 2) ^ 3 * (if Even m then b else 1) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) ^ 3 * (if Even m then 1 else b) := by
rw [show 2 * (m + 2) + 1 = 2 * m + 5 by rfl, preNormEDS', dif_pos <| even_two_mul _]
simp only [m.mul_div_cancel_left two_pos]
lemma preNormEDS'_even (m : ℕ) : preNormEDS' b c d (2 * (m + 3)) =
preNormEDS' b c d (m + 2) ^ 2 * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 5) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 4) ^ 2 := by
rw [show 2 * (m + 3) = 2 * m + 1 + 5 by rfl, preNormEDS', dif_neg m.not_even_two_mul_add_one]
simp only [Nat.mul_add_div two_pos]
rfl
/-- The auxiliary sequence for a normalised EDS `W : ℤ → R`, with initial values
`W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`.
This extends `preNormEDS'` by defining its values at negative integers. -/
def preNormEDS (n : ℤ) : R :=
n.sign * preNormEDS' b c d n.natAbs
@[simp]
lemma preNormEDS_ofNat (n : ℕ) : preNormEDS b c d n = preNormEDS' b c d n := by
by_cases hn : n = 0
· rw [hn, preNormEDS, Nat.cast_zero, Int.sign_zero, Int.cast_zero, zero_mul, preNormEDS'_zero]
· rw [preNormEDS, Int.sign_natCast_of_ne_zero hn, Int.cast_one, one_mul, Int.natAbs_cast]
@[simp]
lemma preNormEDS_zero : preNormEDS b c d 0 = 0 := by
rw [← Nat.cast_zero, preNormEDS_ofNat, preNormEDS'_zero]
@[simp]
lemma preNormEDS_one : preNormEDS b c d 1 = 1 := by
rw [← Nat.cast_one, preNormEDS_ofNat, preNormEDS'_one]
@[simp]
lemma preNormEDS_two : preNormEDS b c d 2 = 1 := by
rw [← Nat.cast_two, preNormEDS_ofNat, preNormEDS'_two]
@[simp]
lemma preNormEDS_three : preNormEDS b c d 3 = c := by
rw [← Nat.cast_three, preNormEDS_ofNat, preNormEDS'_three]
@[simp]
lemma preNormEDS_four : preNormEDS b c d 4 = d := by
rw [← Nat.cast_four, preNormEDS_ofNat, preNormEDS'_four]
|
lemma preNormEDS_even_ofNat (m : ℕ) : preNormEDS b c d (2 * (m + 3)) =
preNormEDS b c d (m + 2) ^ 2 * preNormEDS b c d (m + 3) * preNormEDS b c d (m + 5) -
| Mathlib/NumberTheory/EllipticDivisibilitySequence.lean | 231 | 233 |
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.NumberTheory.LSeries.AbstractFuncEq
import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds
import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne
import Mathlib.NumberTheory.LSeries.MellinEqDirichlet
import Mathlib.NumberTheory.LSeries.Basic
import Mathlib.Analysis.Complex.RemovableSingularity
/-!
# Even Hurwitz zeta functions
In this file we study the functions on `ℂ` which are the meromorphic continuation of the following
series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter:
`hurwitzZetaEven a s = 1 / 2 * ∑' n : ℤ, 1 / |n + a| ^ s`
and
`cosZeta a s = ∑' n : ℕ, cos (2 * π * a * n) / |n| ^ s`.
Note that the term for `n = -a` in the first sum is omitted if `a` is an integer, and the term for
`n = 0` is omitted in the second sum (always).
Of course, we cannot *define* these functions by the above formulae (since existence of the
meromorphic continuation is not at all obvious); we in fact construct them as Mellin transforms of
various versions of the Jacobi theta function.
We also define completed versions of these functions with nicer functional equations (satisfying
`completedHurwitzZetaEven a s = Gammaℝ s * hurwitzZetaEven a s`, and similarly for `cosZeta`); and
modified versions with a subscript `0`, which are entire functions differing from the above by
multiples of `1 / s` and `1 / (1 - s)`.
## Main definitions and theorems
* `hurwitzZetaEven` and `cosZeta`: the zeta functions
* `completedHurwitzZetaEven` and `completedCosZeta`: completed variants
* `differentiableAt_hurwitzZetaEven` and `differentiableAt_cosZeta`:
differentiability away from `s = 1`
* `completedHurwitzZetaEven_one_sub`: the functional equation
`completedHurwitzZetaEven a (1 - s) = completedCosZeta a s`
* `hasSum_int_hurwitzZetaEven` and `hasSum_nat_cosZeta`: relation between the zeta functions and
the corresponding Dirichlet series for `1 < re s`.
-/
noncomputable section
open Complex Filter Topology Asymptotics Real Set MeasureTheory
namespace HurwitzZeta
section kernel_defs
/-!
## Definitions and elementary properties of kernels
-/
/-- Even Hurwitz zeta kernel (function whose Mellin transform will be the even part of the
completed Hurwit zeta function). See `evenKernel_def` for the defining formula, and
`hasSum_int_evenKernel` for an expression as a sum over `ℤ`. -/
@[irreducible] def evenKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic
(fun ξ : ℝ ↦ rexp (-π * ξ ^ 2 * x) * re (jacobiTheta₂ (ξ * I * x) (I * x))) 1 by
intro ξ
simp only [ofReal_add, ofReal_one, add_mul, one_mul, jacobiTheta₂_add_left']
have : cexp (-↑π * I * ((I * ↑x) + 2 * (↑ξ * I * ↑x))) = rexp (π * (x + 2 * ξ * x)) := by
ring_nf
simp [I_sq]
rw [this, re_ofReal_mul, ← mul_assoc, ← Real.exp_add]
congr
ring).lift a
lemma evenKernel_def (a x : ℝ) :
↑(evenKernel ↑a x) = cexp (-π * a ^ 2 * x) * jacobiTheta₂ (a * I * x) (I * x) := by
simp [evenKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
/-- For `x ≤ 0` the defining sum diverges, so the kernel is 0. -/
lemma evenKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : evenKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H a' => simp [← ofReal_inj, evenKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- Cosine Hurwitz zeta kernel. See `cosKernel_def` for the defining formula, and
`hasSum_int_cosKernel` for expression as a sum. -/
@[irreducible] def cosKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic (fun ξ : ℝ ↦ re (jacobiTheta₂ ξ (I * x))) 1 by
intro ξ; simp [jacobiTheta₂_add_left]).lift a
lemma cosKernel_def (a x : ℝ) : ↑(cosKernel ↑a x) = jacobiTheta₂ a (I * x) := by
simp [cosKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
lemma cosKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : cosKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← ofReal_inj, cosKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- For `a = 0`, both kernels agree. -/
lemma evenKernel_eq_cosKernel_of_zero : evenKernel 0 = cosKernel 0 := by
ext1 x
simp [← QuotientAddGroup.mk_zero, ← ofReal_inj, evenKernel_def, cosKernel_def]
@[simp]
lemma evenKernel_neg (a : UnitAddCircle) (x : ℝ) : evenKernel (-a) x = evenKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, evenKernel_def, jacobiTheta₂_neg_left]
@[simp]
lemma cosKernel_neg (a : UnitAddCircle) (x : ℝ) : cosKernel (-a) x = cosKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, cosKernel_def]
lemma continuousOn_evenKernel (a : UnitAddCircle) : ContinuousOn (evenKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (evenKernel a' x : ℂ))
simp only [evenKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ .mul (by fun_prop) ?_)
exact (continuousAt_jacobiTheta₂ (a' * I * x) <| by simpa).comp
(f := fun u : ℝ ↦ (a' * I * u, I * u)) (by fun_prop)
lemma continuousOn_cosKernel (a : UnitAddCircle) : ContinuousOn (cosKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (cosKernel a' x : ℂ))
simp only [cosKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ ?_)
exact (continuousAt_jacobiTheta₂ a' <| by simpa).comp
(f := fun u : ℝ ↦ ((a' : ℂ), I * u)) (by fun_prop)
lemma evenKernel_functional_equation (a : UnitAddCircle) (x : ℝ) :
evenKernel a x = 1 / x ^ (1 / 2 : ℝ) * cosKernel a (1 / x) := by
rcases le_or_lt x 0 with hx | hx
· rw [evenKernel_undef _ hx, cosKernel_undef, mul_zero]
exact div_nonpos_of_nonneg_of_nonpos zero_le_one hx
induction a using QuotientAddGroup.induction_on with | H a =>
rw [← ofReal_inj, ofReal_mul, evenKernel_def, cosKernel_def, jacobiTheta₂_functional_equation]
have h1 : I * ↑(1 / x) = -1 / (I * x) := by
push_cast
rw [← div_div, mul_one_div, div_I, neg_one_mul, neg_neg]
have hx' : I * x ≠ 0 := mul_ne_zero I_ne_zero (ofReal_ne_zero.mpr hx.ne')
have h2 : a * I * x / (I * x) = a := by
rw [div_eq_iff hx']
ring
have h3 : 1 / (-I * (I * x)) ^ (1 / 2 : ℂ) = 1 / ↑(x ^ (1 / 2 : ℝ)) := by
rw [neg_mul, ← mul_assoc, I_mul_I, neg_one_mul, neg_neg,ofReal_cpow hx.le, ofReal_div,
ofReal_one, ofReal_ofNat]
have h4 : -π * I * (a * I * x) ^ 2 / (I * x) = - (-π * a ^ 2 * x) := by
rw [mul_pow, mul_pow, I_sq, div_eq_iff hx']
ring
rw [h1, h2, h3, h4, ← mul_assoc, mul_comm (cexp _), mul_assoc _ (cexp _) (cexp _),
← Complex.exp_add, neg_add_cancel, Complex.exp_zero, mul_one, ofReal_div, ofReal_one]
end kernel_defs
section asymp
/-!
## Formulae for the kernels as sums
-/
lemma hasSum_int_evenKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ rexp (-π * (n + a) ^ 2 * t)) (evenKernel a t) := by
rw [← hasSum_ofReal, evenKernel_def]
have (n : ℤ) : cexp (-(π * (n + a) ^ 2 * t)) = cexp (-(π * a ^ 2 * t)) *
jacobiTheta₂_term n (a * I * t) (I * t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp
simpa [this] using (hasSum_jacobiTheta₂_term _ (by simpa)).mul_left _
lemma hasSum_int_cosKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t)) ↑(cosKernel a t) := by
rw [cosKernel_def a t]
have (n : ℤ) : cexp (2 * π * I * a * n) * cexp (-(π * n ^ 2 * t)) =
jacobiTheta₂_term n a (I * ↑t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp [sub_eq_add_neg]
simpa [this] using hasSum_jacobiTheta₂_term _ (by simpa)
/-- Modified version of `hasSum_int_evenKernel` omitting the constant term at `∞`. -/
lemma hasSum_int_evenKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n + a = 0 then 0 else rexp (-π * (n + a) ^ 2 * t))
(evenKernel a t - if (a : UnitAddCircle) = 0 then 1 else 0) := by
haveI := Classical.propDecidable -- speed up instance search for `if / then / else`
simp_rw [AddCircle.coe_eq_zero_iff, zsmul_one]
split_ifs with h
· obtain ⟨k, rfl⟩ := h
simpa [← Int.cast_add, add_eq_zero_iff_eq_neg]
using hasSum_ite_sub_hasSum (hasSum_int_evenKernel (k : ℝ) ht) (-k)
· suffices ∀ (n : ℤ), n + a ≠ 0 by simpa [this] using hasSum_int_evenKernel a ht
contrapose! h
let ⟨n, hn⟩ := h
exact ⟨-n, by simpa [neg_eq_iff_add_eq_zero]⟩
lemma hasSum_int_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n = 0 then 0 else cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t))
(↑(cosKernel a t) - 1) := by
simpa using hasSum_ite_sub_hasSum (hasSum_int_cosKernel a ht) 0
lemma hasSum_nat_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℕ ↦ 2 * Real.cos (2 * π * a * (n + 1)) * rexp (-π * (n + 1) ^ 2 * t))
(cosKernel a t - 1) := by
rw [← hasSum_ofReal, ofReal_sub, ofReal_one]
have := (hasSum_int_cosKernel a ht).nat_add_neg
rw [← hasSum_nat_add_iff' 1] at this
simp_rw [Finset.sum_range_one, Nat.cast_zero, neg_zero, Int.cast_zero, zero_pow two_ne_zero,
mul_zero, zero_mul, Complex.exp_zero, Real.exp_zero, ofReal_one, mul_one, Int.cast_neg,
Int.cast_natCast, neg_sq, ← add_mul, add_sub_assoc, ← sub_sub, sub_self, zero_sub,
← sub_eq_add_neg, mul_neg] at this
refine this.congr_fun fun n ↦ ?_
push_cast
rw [Complex.cos, mul_div_cancel₀ _ two_ne_zero]
congr 3 <;> ring
/-!
## Asymptotics of the kernels as `t → ∞`
-/
/-- The function `evenKernel a - L` has exponential decay at `+∞`, where `L = 1` if
`a = 0` and `L = 0` otherwise. -/
lemma isBigO_atTop_evenKernel_sub (a : UnitAddCircle) : ∃ p : ℝ, 0 < p ∧
(evenKernel a · - (if a = 0 then 1 else 0)) =O[atTop] (rexp <| -p * ·) := by
induction a using QuotientAddGroup.induction_on with | H b =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_int_zero_sub b
refine ⟨p, hp, (EventuallyEq.isBigO ?_).trans hp'⟩
filter_upwards [eventually_gt_atTop 0] with t h
simp [← (hasSum_int_evenKernel b h).tsum_eq, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int]
/-- The function `cosKernel a - 1` has exponential decay at `+∞`, for any `a`. -/
lemma isBigO_atTop_cosKernel_sub (a : UnitAddCircle) :
∃ p, 0 < p ∧ IsBigO atTop (cosKernel a · - 1) (fun x ↦ Real.exp (-p * x)) := by
induction a using QuotientAddGroup.induction_on with | H a =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_nat_zero_sub zero_le_one
refine ⟨p, hp, (Eventually.isBigO ?_).trans (hp'.const_mul_left 2)⟩
filter_upwards [eventually_gt_atTop 0] with t ht
simp only [eq_false_intro one_ne_zero, if_false, sub_zero,
← (hasSum_nat_cosKernel₀ a ht).tsum_eq, HurwitzKernelBounds.F_nat]
apply tsum_of_norm_bounded ((HurwitzKernelBounds.summable_f_nat 0 1 ht).hasSum.mul_left 2)
intro n
rw [norm_mul, norm_mul, norm_two, mul_assoc, mul_le_mul_iff_of_pos_left two_pos,
norm_of_nonneg (exp_pos _).le, HurwitzKernelBounds.f_nat, pow_zero, one_mul, Real.norm_eq_abs]
exact mul_le_of_le_one_left (exp_pos _).le (abs_cos_le_one _)
end asymp
section FEPair
/-!
## Construction of a FE-pair
-/
/-- A `WeakFEPair` structure with `f = evenKernel a` and `g = cosKernel a`. -/
def hurwitzEvenFEPair (a : UnitAddCircle) : WeakFEPair ℂ where
f := ofReal ∘ evenKernel a
g := ofReal ∘ cosKernel a
hf_int := (continuous_ofReal.comp_continuousOn (continuousOn_evenKernel a)).locallyIntegrableOn
measurableSet_Ioi
hg_int := (continuous_ofReal.comp_continuousOn (continuousOn_cosKernel a)).locallyIntegrableOn
measurableSet_Ioi
k := 1 / 2
hk := one_half_pos
ε := 1
hε := one_ne_zero
f₀ := if a = 0 then 1 else 0
hf_top r := by
let ⟨v, hv, hv'⟩ := isBigO_atTop_evenKernel_sub a
rw [← isBigO_norm_left] at hv' ⊢
conv at hv' =>
enter [2, x]; rw [← norm_real, ofReal_sub, apply_ite ((↑) : ℝ → ℂ), ofReal_one, ofReal_zero]
exact hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO
g₀ := 1
hg_top r := by
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_cosKernel_sub a
simpa using isBigO_ofReal_left.mpr <| hp'.trans (isLittleO_exp_neg_mul_rpow_atTop hp r).isBigO
h_feq x hx := by simp [← ofReal_mul, evenKernel_functional_equation, inv_rpow (le_of_lt hx)]
@[simp]
lemma hurwitzEvenFEPair_zero_symm :
(hurwitzEvenFEPair 0).symm = hurwitzEvenFEPair 0 := by
unfold hurwitzEvenFEPair WeakFEPair.symm
congr 1 <;> simp [evenKernel_eq_cosKernel_of_zero]
@[simp]
lemma hurwitzEvenFEPair_neg (a : UnitAddCircle) : hurwitzEvenFEPair (-a) = hurwitzEvenFEPair a := by
unfold hurwitzEvenFEPair
congr 1 <;> simp [Function.comp_def]
/-!
## Definition of the completed even Hurwitz zeta function
-/
/--
The meromorphic function of `s` which agrees with
`1 / 2 * Gamma (s / 2) * π ^ (-s / 2) * ∑' (n : ℤ), 1 / |n + a| ^ s` for `1 < re s`.
-/
def completedHurwitzZetaEven (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ (s / 2)) / 2
/-- The entire function differing from `completedHurwitzZetaEven a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedHurwitzZetaEven₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ₀ (s / 2)) / 2
lemma completedHurwitzZetaEven_eq (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a s =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s - 1 / (1 - s) := by
rw [completedHurwitzZetaEven, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· change completedHurwitzZetaEven₀ a s - (1 / (s / 2)) • (if a = 0 then 1 else 0) / 2 =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s
rw [smul_eq_mul, mul_comm, mul_div_assoc, div_div, div_mul_cancel₀ _ two_ne_zero, mul_one_div]
· change (1 / (↑(1 / 2 : ℝ) - s / 2)) • 1 / 2 = 1 / (1 - s)
push_cast
rw [smul_eq_mul, mul_one, ← sub_div, div_div, div_mul_cancel₀ _ two_ne_zero]
/--
The meromorphic function of `s` which agrees with
`Gamma (s / 2) * π ^ (-s / 2) * ∑' n : ℕ, cos (2 * π * a * n) / n ^ s` for `1 < re s`.
-/
def completedCosZeta (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ (s / 2)) / 2
/-- The entire function differing from `completedCosZeta a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedCosZeta₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ₀ (s / 2)) / 2
lemma completedCosZeta_eq (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a s =
completedCosZeta₀ a s - 1 / s - (if a = 0 then 1 else 0) / (1 - s) := by
rw [completedCosZeta, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· rw [completedCosZeta₀, WeakFEPair.symm, hurwitzEvenFEPair, smul_eq_mul, mul_one, div_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ)]
· simp_rw [WeakFEPair.symm, hurwitzEvenFEPair, push_cast, inv_one, smul_eq_mul,
mul_comm _ (if _ then _ else _), mul_div_assoc, div_div, ← sub_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ), mul_one_div]
/-!
## Parity and functional equations
-/
@[simp]
lemma completedHurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven (-a) s = completedHurwitzZetaEven a s := by
simp [completedHurwitzZetaEven]
@[simp]
lemma completedHurwitzZetaEven₀_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ (-a) s = completedHurwitzZetaEven₀ a s := by
simp [completedHurwitzZetaEven₀]
@[simp]
lemma completedCosZeta_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta (-a) s = completedCosZeta a s := by
simp [completedCosZeta]
@[simp]
lemma completedCosZeta₀_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ (-a) s = completedCosZeta₀ a s := by
simp [completedCosZeta₀]
/-- Functional equation for the even Hurwitz zeta function. -/
lemma completedHurwitzZetaEven_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a (1 - s) = completedCosZeta a s := by
rw [completedHurwitzZetaEven, completedCosZeta, sub_div,
(by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
/-- Functional equation for the even Hurwitz zeta function with poles removed. -/
lemma completedHurwitzZetaEven₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ a (1 - s) = completedCosZeta₀ a s := by
rw [completedHurwitzZetaEven₀, completedCosZeta₀, sub_div,
(by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation₀ (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
|
/-- Functional equation for the even Hurwitz zeta function (alternative form). -/
lemma completedCosZeta_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a (1 - s) = completedHurwitzZetaEven a s := by
rw [← completedHurwitzZetaEven_one_sub, sub_sub_cancel]
/-- Functional equation for the even Hurwitz zeta function with poles removed (alternative form). -/
lemma completedCosZeta₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ a (1 - s) = completedHurwitzZetaEven₀ a s := by
| Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean | 380 | 388 |
/-
Copyright (c) 2022 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Data.Finsupp.Lex
import Mathlib.Data.Finsupp.Multiset
import Mathlib.Order.GameAdd
/-!
# Termination of a hydra game
This file deals with the following version of the hydra game: each head of the hydra is
labelled by an element in a type `α`, and when you cut off one head with label `a`, it
grows back an arbitrary but finite number of heads, all labelled by elements smaller than
`a` with respect to a well-founded relation `r` on `α`. We show that no matter how (in
what order) you choose cut off the heads, the game always terminates, i.e. all heads will
eventually be cut off (but of course it can last arbitrarily long, i.e. takes an
arbitrary finite number of steps).
This result is stated as the well-foundedness of the `CutExpand` relation defined in
this file: we model the heads of the hydra as a multiset of elements of `α`, and the
valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset α`:
`CutExpand r s' s` is true iff `s'` is obtained by removing one head `a ∈ s` and
adding back an arbitrary multiset `t` of heads such that all `a' ∈ t` satisfy `r a' a`.
We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332.
TODO: formalize the relations corresponding to more powerful (e.g. Kirby–Paris and Buchholz)
hydras, and prove their well-foundedness.
-/
namespace Relation
open Multiset Prod
variable {α : Type*}
/-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s`
means that `s'` is obtained by removing one head `a ∈ s` and adding back an arbitrary
multiset `t` of heads such that all `a' ∈ t` satisfy `r a' a`.
This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires
`DecidableEq α`, so we use the equivalent condition `s' + {a} = s + t` instead, which
is also easier to verify for explicit multisets `s'`, `s` and `t`.
We also don't include the condition `a ∈ s` because `s' + {a} = s + t` already
guarantees `a ∈ s + t`, and if `r` is irreflexive then `a ∉ t`, which is the
case when `r` is well-founded, the case we are primarily interested in.
The lemma `Relation.cutExpand_iff` below converts between this convenient definition
and the direct translation when `r` is irreflexive. -/
def CutExpand (r : α → α → Prop) (s' s : Multiset α) : Prop :=
∃ (t : Multiset α) (a : α), (∀ a' ∈ t, r a' a) ∧ s' + {a} = s + t
variable {r : α → α → Prop}
theorem cutExpand_le_invImage_lex [DecidableEq α] [IsIrrefl α r] :
CutExpand r ≤ InvImage (Finsupp.Lex (rᶜ ⊓ (· ≠ ·)) (· < ·)) toFinsupp := by
rintro s t ⟨u, a, hr, he⟩
replace hr := fun a' ↦ mt (hr a')
classical
refine ⟨a, fun b h ↦ ?_, ?_⟩ <;> simp_rw [toFinsupp_apply]
· apply_fun count b at he
simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)]
using he
· apply_fun count a at he
simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)),
add_zero] at he
exact he ▸ Nat.lt_succ_self _
theorem cutExpand_singleton {s x} (h : ∀ x' ∈ s, r x' x) : CutExpand r s {x} :=
⟨s, x, h, add_comm s _⟩
theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} :=
cutExpand_singleton fun a h ↦ by rwa [mem_singleton.1 h]
theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) ↔ CutExpand r t u :=
exists₂_congr fun _ _ ↦ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff]
lemma cutExpand_add_right {s' s} (t) : CutExpand r (s' + t) (s + t) ↔ CutExpand r s' s := by
convert cutExpand_add_left t using 2 <;> apply add_comm
theorem cutExpand_add_single {a' a : α} (s : Multiset α) (h : r a' a) :
CutExpand r (s + {a'}) (s + {a}) :=
(cutExpand_add_left s).2 <| cutExpand_singleton_singleton h
theorem cutExpand_single_add {a' a : α} (h : r a' a) (s : Multiset α) :
CutExpand r ({a'} + s) ({a} + s) :=
(cutExpand_add_right s).2 <| cutExpand_singleton_singleton h
theorem cutExpand_iff [DecidableEq α] [IsIrrefl α r] {s' s : Multiset α} :
CutExpand r s' s ↔
∃ (t : Multiset α) (a : α), (∀ a' ∈ t, r a' a) ∧ a ∈ s ∧ s' = s.erase a + t := by
simp_rw [CutExpand, add_singleton_eq_iff]
refine exists₂_congr fun t a ↦ ⟨?_, ?_⟩
· rintro ⟨ht, ha, rfl⟩
obtain h | h := mem_add.1 ha
exacts [⟨ht, h, erase_add_left_pos t h⟩, (@irrefl α r _ a (ht a h)).elim]
· rintro ⟨ht, h, rfl⟩
exact ⟨ht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symm⟩
theorem not_cutExpand_zero [IsIrrefl α r] (s) : ¬CutExpand r s 0 := by
classical
rw [cutExpand_iff]
rintro ⟨_, _, _, ⟨⟩, _⟩
lemma cutExpand_zero {x} : CutExpand r 0 {x} := ⟨0, x, nofun, add_comm 0 _⟩
/-- For any relation `r` on `α`, multiset addition `Multiset α × Multiset α → Multiset α` is a
fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/
theorem cutExpand_fibration (r : α → α → Prop) :
Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s ↦ s.1 + s.2 := by
rintro ⟨s₁, s₂⟩ s ⟨t, a, hr, he⟩; dsimp at he ⊢
classical
obtain ⟨ha, rfl⟩ := add_singleton_eq_iff.1 he
rw [add_assoc, mem_add] at ha
obtain h | h := ha
· refine ⟨(s₁.erase a + t, s₂), GameAdd.fst ⟨t, a, hr, ?_⟩, ?_⟩
· rw [add_comm, ← add_assoc, singleton_add, cons_erase h]
· rw [add_assoc s₁, erase_add_left_pos _ h, add_right_comm, add_assoc]
· refine ⟨(s₁, (s₂ + t).erase a), GameAdd.snd ⟨t, a, hr, ?_⟩, ?_⟩
· rw [add_comm, singleton_add, cons_erase h]
· rw [add_assoc, erase_add_right_pos _ h]
/-- `CutExpand` preserves leftward-closedness under a relation. -/
lemma cutExpand_closed [IsIrrefl α r] (p : α → Prop)
(h : ∀ {a' a}, r a' a → p a → p a') {s' s : Multiset α} :
CutExpand r s' s → (∀ a ∈ s, p a) → ∀ a ∈ s', p a := by
classical
rw [cutExpand_iff]
rintro ⟨t, a, hr, ha, rfl⟩ hsp a' h'
obtain (h'|h') := mem_add.1 h'
exacts [hsp a' (mem_of_mem_erase h'), h (hr a' h') (hsp a ha)]
lemma cutExpand_double {a a₁ a₂} (h₁ : r a₁ a) (h₂ : r a₂ a) : CutExpand r {a₁, a₂} {a} :=
cutExpand_singleton <| by
simp only [insert_eq_cons, mem_cons, mem_singleton, forall_eq_or_imp, forall_eq]
tauto
lemma cutExpand_pair_left {a' a b} (hr : r a' a) : CutExpand r {a', b} {a, b} :=
(cutExpand_add_right {b}).2 (cutExpand_singleton_singleton hr)
lemma cutExpand_pair_right {a b' b} (hr : r b' b) : CutExpand r {a, b'} {a, b} :=
(cutExpand_add_left {a}).2 (cutExpand_singleton_singleton hr)
lemma cutExpand_double_left {a a₁ a₂ b} (h₁ : r a₁ a) (h₂ : r a₂ a) :
CutExpand r {a₁, a₂, b} {a, b} :=
(cutExpand_add_right {b}).2 (cutExpand_double h₁ h₂)
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are,
assuming `r` is irreflexive. -/
theorem acc_of_singleton [IsIrrefl α r] {s : Multiset α} (hs : ∀ a ∈ s, Acc (CutExpand r) {a}) :
Acc (CutExpand r) s := by
induction s using Multiset.induction with
| | empty => exact Acc.intro 0 fun s h ↦ (not_cutExpand_zero s h).elim
| cons a s ihs =>
rw [← s.singleton_add a]
rw [forall_mem_cons] at hs
exact (hs.1.prod_gameAdd <| ihs fun a ha ↦ hs.2 a ha).of_fibration _ (cutExpand_fibration r)
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`,
assuming `r` is irreflexive. -/
| Mathlib/Logic/Hydra.lean | 157 | 164 |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Basis
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`LinearAlgebra.Matrix.Determinant`.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `Basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
* `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable section
open Matrix LinearMap Submodule Set Function
universe u v w
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
variable (e : Basis ι R M)
section Conjugate
variable {A : Type*} [CommRing A]
variable {m n : Type*}
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R]
(e : (m → R) ≃ₗ[R] n → R) : m ≃ n :=
Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _)
namespace Matrix
variable [Fintype m] [Fintype n]
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n :=
equivOfPiLEquivPi (toLin'OfInv hMM' hM'M)
theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N * M) = det (M * N)`. -/
theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A}
{M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by
nontriviality A
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := indexEquivOfInv hMM' hM'M
rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm,
submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id]
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`.
See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/
theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) :
det (M * N * M') = det N := by
rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul]
end Matrix
end Conjugate
namespace LinearMap
/-! ### Determinant of a linear map -/
variable {A : Type*} [CommRing A] [Module A M]
variable {κ : Type*} [Fintype κ]
/-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/
theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M)
(f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by
rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b,
Matrix.det_conj_of_mul_eq_one] <;>
rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
/-- The determinant of an endomorphism given a basis.
See `LinearMap.det` for a version that populates the basis non-computably.
Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases,
there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s
type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma,
or avoid mentioning a basis at all using `LinearMap.det`.
-/
irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A :=
Trunc.lift
(fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A))
fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c
/-- Unfold lemma for `detAux`.
See also `detAux_def''` which allows you to vary the basis.
-/
theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) :
LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by
rw [detAux]
rfl
theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M)
(b' : Basis ι' A M) (f : M →ₗ[A] M) :
LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by
induction tb using Trunc.induction_on with
| h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b']
@[simp]
theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 :=
(LinearMap.detAux b).map_one
@[simp]
theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) :
LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g :=
(LinearMap.detAux b).map_mul f g
section
open scoped Classical in
-- Discourage the elaborator from unfolding `det` and producing a huge term by marking it
-- as irreducible.
/-- The determinant of an endomorphism independent of basis.
If there is no finite basis on `M`, the result is `1` instead.
-/
protected irreducible_def det : (M →ₗ[A] M) →* A :=
if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1
open scoped Classical in
theorem coe_det [DecidableEq M] :
⇑(LinearMap.det : (M →ₗ[A] M) →* A) =
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1 := by
ext
rw [LinearMap.det_def]
split_ifs
· congr -- use the correct `DecidableEq` instance
rfl
end
-- Auxiliary lemma, the `simp` normal form goes in the other direction
-- (using `LinearMap.det_toMatrix`)
theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M)
(f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩
rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption
@[simp]
theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) :
Matrix.det (toMatrix b b f) = LinearMap.det f := by
haveI := Classical.decEq M
rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange,
det_toMatrix_eq_det_toMatrix b b.reindexFinsetRange]
@[simp]
theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) :
Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix']
@[simp]
theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) :
LinearMap.det (Matrix.toLin b b f) = f.det := by
rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin]
@[simp]
theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by
simp only [← toLin_eq_toLin', det_toLin]
/-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and
`P 1`. -/
@[elab_as_elim]
theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M)
(hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) :
P (LinearMap.det f) := by
classical
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
obtain ⟨s, ⟨b⟩⟩ := H
rw [← det_toMatrix b]
exact hb s b
else
rwa [LinearMap.det_def, dif_neg H]
@[simp]
theorem det_comp (f g : M →ₗ[A] M) :
LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g :=
LinearMap.det.map_mul f g
@[simp]
theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 :=
LinearMap.det.map_one
/-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/
@[simp]
theorem det_smul [Module.Free A M] (c : A) (f : M →ₗ[A] M) :
LinearMap.det (c • f) = c ^ Module.finrank A M * LinearMap.det f := by
nontriviality A
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· have : Module.Finite A M := by
rcases H with ⟨s, ⟨hs⟩⟩
exact Module.Finite.of_basis hs
simp only [← det_toMatrix (Module.finBasis A M), LinearEquiv.map_smul,
Fintype.card_fin, Matrix.det_smul]
· classical
have : Module.finrank A M = 0 := finrank_eq_zero_of_not_exists_basis H
simp [coe_det, H, this]
theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) :
LinearMap.det (0 : M →ₗ[A] M) = 0 := by
haveI := Classical.decEq ι
cases nonempty_fintype ι
rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero]
/-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`,
and `0` otherwise. We give a formula that also works in infinite dimension, where we define
the determinant to be `1`. -/
@[simp]
theorem det_zero [Module.Free A M] :
LinearMap.det (0 : M →ₗ[A] M) = (0 : A) ^ Module.finrank A M := by
simp only [← zero_smul A (1 : M →ₗ[A] M), det_smul, mul_one, MonoidHom.map_one]
theorem det_eq_one_of_not_module_finite (h : ¬Module.Finite R M) (f : M →ₗ[R] M) : f.det = 1 := by
rw [LinearMap.det, dif_neg, MonoidHom.one_apply]
exact fun ⟨_, ⟨b⟩⟩ ↦ h (Module.Finite.of_basis b)
theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) :
LinearMap.det (f : M →ₗ[R] M) = 1 := by
have b : Basis (Fin 0) R M := Basis.empty M
rw [← f.det_toMatrix b]
exact Matrix.det_isEmpty
theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M]
[Module 𝕜 M] (h : Module.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) :
LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by
classical
refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl
intro s b
have : IsEmpty s := by
rw [← Fintype.card_eq_zero_iff]
exact (Module.finrank_eq_card_basis b).symm.trans h
exact Matrix.det_isEmpty
/-- Conjugating a linear map by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) :
LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· rcases H with ⟨s, ⟨b⟩⟩
rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e),
toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by
contrapose! H
rcases H with ⟨s, ⟨b⟩⟩
exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩
simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true]
/-- If a linear map is invertible, so is its determinant. -/
theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) :
IsUnit (LinearMap.det f) := by
obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv
have : LinearMap.det f * LinearMap.det g = 1 := by
simp only [← LinearMap.det_comp, hg, MonoidHom.map_one]
exact isUnit_of_mul_eq_one _ _ this
/-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/
theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M)
(hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
· classical simp [LinearMap.coe_det, H] at hf
/-- If the determinant of a map vanishes, then the map is not onto. -/
theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- If the determinant of a map vanishes, then the map is not injective. -/
theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- When the function is over the base ring, the determinant is the evaluation at `1`. -/
@[simp] lemma det_ring (f : R →ₗ[R] R) : f.det = f 1 := by
simp [← det_toMatrix (Basis.singleton Unit R)]
lemma det_mulLeft (a : R) : (mulLeft R a).det = a := by simp
lemma det_mulRight (a : R) : (mulRight R a).det = a := by simp
theorem det_prodMap [Module.Free R M] [Module.Free R M'] [Module.Finite R M] [Module.Finite R M']
(f : Module.End R M) (f' : Module.End R M') :
(prodMap f f').det = f.det * f'.det := by
let b := Module.Free.chooseBasis R M
let b' := Module.Free.chooseBasis R M'
rw [← det_toMatrix (b.prod b'), ← det_toMatrix b, ← det_toMatrix b', toMatrix_prodMap,
det_fromBlocks_zero₂₁, det_toMatrix]
omit [DecidableEq ι] in
theorem det_pi [Module.Free R M] [Module.Finite R M] (f : ι → M →ₗ[R] M) :
(LinearMap.pi (fun i ↦ (f i).comp (LinearMap.proj i))).det = ∏ i, (f i).det := by
classical
let b := Module.Free.chooseBasis R M
let B := (Pi.basis (fun _ : ι ↦ b)).reindex <|
(Equiv.sigmaEquivProd _ _).trans (Equiv.prodComm _ _)
simp_rw [← LinearMap.det_toMatrix B, ← LinearMap.det_toMatrix b]
have : ((LinearMap.toMatrix B B) (LinearMap.pi fun i ↦ f i ∘ₗ LinearMap.proj i)) =
Matrix.blockDiagonal (fun i ↦ LinearMap.toMatrix b b (f i)) := by
ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩
unfold B
simp_rw [LinearMap.toMatrix_apply', Matrix.blockDiagonal_apply, Basis.coe_reindex,
Function.comp_apply, Basis.repr_reindex_apply, Equiv.symm_trans_apply, Equiv.prodComm_symm,
Equiv.prodComm_apply, Equiv.sigmaEquivProd_symm_apply, Prod.swap_prod_mk, Pi.basis_apply,
Pi.basis_repr, LinearMap.pi_apply, LinearMap.coe_comp, Function.comp_apply,
LinearMap.toMatrix_apply', LinearMap.coe_proj, Function.eval, Pi.single_apply]
split_ifs with h
· rw [h]
· simp only [map_zero, Finsupp.coe_zero, Pi.zero_apply]
rw [this, Matrix.det_blockDiagonal]
end LinearMap
namespace LinearEquiv
/-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/
protected def det : (M ≃ₗ[R] M) →* Rˣ :=
(Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp
(LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom
@[simp]
theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) :=
rfl
@[simp]
theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) :=
rfl
@[simp]
theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 :=
Units.ext <| LinearMap.det_id
@[simp]
theorem det_trans (f g : M ≃ₗ[R] M) :
LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f :=
map_mul _ g f
@[simp]
theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ :=
map_inv _ f
/-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') :
LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by
rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj]
attribute [irreducible] LinearEquiv.det
end LinearEquiv
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
-- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism.
theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') :
IsUnit (LinearMap.toMatrix v v' f).det := by
apply isUnit_det_of_left_inverse
simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm
/-- Specialization of `LinearEquiv.isUnit_det` -/
theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
IsUnit (LinearMap.det (f : M →ₗ[A] M)) :=
isUnit_of_mul_eq_one _ _ f.det_mul_det_symm
/-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/
theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) :
LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by
field_simp [IsUnit.ne_zero f.isUnit_det']
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
@[simps]
def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where
toFun := f
map_add' := f.map_add
map_smul' := f.map_smul
invFun := toLin v' v (toMatrix v v' f)⁻¹
left_inv x :=
calc toLin v' v (toMatrix v v' f)⁻¹ (f x)
_ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by
rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply]
_ = x := by simp [h]
right_inv x :=
calc f (toLin v' v (toMatrix v v' f)⁻¹ x)
_ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by
rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v']
_ = x := by simp [h]
@[simp]
theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) :
(LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by
ext x
rfl
/-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose
determinant is nonzero. -/
abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M]
[FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M :=
have : IsUnit (LinearMap.toMatrix (Module.finBasis 𝕜 M)
(Module.finBasis 𝕜 M) f).det := by
rw [LinearMap.det_toMatrix]
exact isUnit_iff_ne_zero.2 hf
LinearEquiv.ofIsUnitDet this
theorem LinearMap.associated_det_of_eq_comp (e : M ≃ₗ[R] M) (f f' : M →ₗ[R] M)
(h : ∀ x, f x = f' (e x)) : Associated (LinearMap.det f) (LinearMap.det f') := by
suffices Associated (LinearMap.det (f' ∘ₗ ↑e)) (LinearMap.det f') by
convert this using 2
ext x
exact h x
rw [← mul_one (LinearMap.det f'), LinearMap.det_comp]
exact Associated.mul_left _ (associated_one_iff_isUnit.mpr e.isUnit_det')
theorem LinearMap.associated_det_comp_equiv {N : Type*} [AddCommGroup N] [Module R N]
(f : N →ₗ[R] M) (e e' : M ≃ₗ[R] N) :
Associated (LinearMap.det (f ∘ₗ ↑e)) (LinearMap.det (f ∘ₗ ↑e')) := by
refine LinearMap.associated_det_of_eq_comp (e.trans e'.symm) _ _ ?_
intro x
simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply,
LinearEquiv.apply_symm_apply]
/-- The determinant of a family of vectors with respect to some basis, as an alternating
multilinear map. -/
nonrec def Basis.det : M [⋀^ι]→ₗ[R] R where
toMultilinearMap :=
MultilinearMap.mk' (fun v ↦ det (e.toMatrix v))
(fun v i x y ↦ by
simp only [e.toMatrix_update, map_add, Finsupp.coe_add, det_updateCol_add])
(fun u i c x ↦ by
simp only [e.toMatrix_update, Algebra.id.smul_eq_mul, LinearEquiv.map_smul]
apply det_updateCol_smul)
map_eq_zero_of_eq' := by
intro v i j h hij
dsimp
rw [← Function.update_eq_self i v, h, ← det_transpose, e.toMatrix_update, ← updateRow_transpose,
← e.toMatrix_transpose_apply]
apply det_zero_of_row_eq hij
rw [updateRow_ne hij.symm, updateRow_self]
theorem Basis.det_apply (v : ι → M) : e.det v = Matrix.det (e.toMatrix v) :=
rfl
theorem Basis.det_self : e.det e = 1 := by simp [e.det_apply]
@[simp]
theorem Basis.det_isEmpty [IsEmpty ι] : e.det = AlternatingMap.constOfIsEmpty R M ι 1 := by
ext v
exact Matrix.det_isEmpty
/-- `Basis.det` is not the zero map. -/
theorem Basis.det_ne_zero [Nontrivial R] : e.det ≠ 0 := fun h => by simpa [h] using e.det_self
theorem Basis.smul_det {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M]
(g : G) (v : ι → M) :
(g • e).det v = e.det (g⁻¹ • v) := by
simp_rw [det_apply, toMatrix_smul_left]
theorem is_basis_iff_det {v : ι → M} :
LinearIndependent R v ∧ span R (Set.range v) = ⊤ ↔ IsUnit (e.det v) := by
constructor
· rintro ⟨hli, hspan⟩
set v' := Basis.mk hli hspan.ge
rw [e.det_apply]
convert LinearEquiv.isUnit_det (LinearEquiv.refl R M) v' e using 2
ext i j
| simp [v']
· intro h
rw [Basis.det_apply, Basis.toMatrix_eq_toMatrix_constr] at h
| Mathlib/LinearAlgebra/Determinant.lean | 534 | 536 |
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Analysis.InnerProductSpace.Convex
import Mathlib.Analysis.InnerProductSpace.PiL2
import Mathlib.Combinatorics.Additive.AP.Three.Defs
import Mathlib.Combinatorics.Pigeonhole
import Mathlib.Data.Complex.ExponentialBounds
/-!
# Behrend's bound on Roth numbers
This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of
`{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of
length `3`.
The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic
progressions (literally) because the corresponding ball is strictly convex. Thus we can take
integer points on that sphere and map them onto `ℕ` in a way that preserves arithmetic progressions
(`Behrend.map`).
## Main declarations
* `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant.
This is the set that we will map on `ℕ`.
* `Behrend.map`: Given a natural number `d`, `Behrend.map d : ℕⁿ → ℕ` reads off the coordinates as
digits in base `d`.
* `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of
`Behrend.sphere`.
* `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers.
## References
* [Bryan Gillespie, *Behrend’s Construction*]
(http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf)
* Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression"
* [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set)
## Tags
3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex
-/
assert_not_exists IsConformalMap Conformal
open Nat hiding log
open Finset Metric Real
open scoped Pointwise
/-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions.
The idea is that an arithmetic progression is contained on a line and the frontier of a strictly
convex set does not contain lines. -/
lemma threeAPFree_frontier {𝕜 E : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
[TopologicalSpace E]
[AddCommMonoid E] [Module 𝕜 E] {s : Set E} (hs₀ : IsClosed s) (hs₁ : StrictConvex 𝕜 s) :
ThreeAPFree (frontier s) := by
intro a ha b hb c hc habc
obtain rfl : (1 / 2 : 𝕜) • a + (1 / 2 : 𝕜) • c = b := by
rwa [← smul_add, one_div, inv_smul_eq_iff₀ (show (2 : 𝕜) ≠ 0 by norm_num), two_smul]
have :=
hs₁.eq (hs₀.frontier_subset ha) (hs₀.frontier_subset hc) one_half_pos one_half_pos
(add_halves _) hb.2
simp [this, ← add_smul]
ring_nf
simp
lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[StrictConvexSpace ℝ E] (x : E) (r : ℝ) : ThreeAPFree (sphere x r) := by
obtain rfl | hr := eq_or_ne r 0
· rw [sphere_zero]
exact threeAPFree_singleton _
· convert threeAPFree_frontier isClosed_closedBall (strictConvex_closedBall ℝ x r)
exact (frontier_closedBall _ hr).symm
namespace Behrend
variable {n d k N : ℕ} {x : Fin n → ℕ}
/-!
### Turning the sphere into 3AP-free set
We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of
integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and
`Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in
`Fin n → ℕ` into a set in `ℕ` using `Behrend.map`, which preserves `ThreeAPFree` because it is
an additive monoid homomorphism.
-/
/-- The box `{0, ..., d - 1}^n` as a `Finset`. -/
def box (n d : ℕ) : Finset (Fin n → ℕ) :=
Fintype.piFinset fun _ => range d
theorem mem_box : x ∈ box n d ↔ ∀ i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range]
@[simp]
theorem card_box : #(box n d) = d ^ n := by simp [box]
@[simp]
theorem box_zero : box (n + 1) 0 = ∅ := by simp [box]
/-- The intersection of the sphere of radius `√k` with the integer points in the positive
quadrant. -/
def sphere (n d k : ℕ) : Finset (Fin n → ℕ) := {x ∈ box n d | ∑ i, x i ^ 2 = k}
theorem sphere_zero_subset : sphere n d 0 ⊆ 0 := fun x => by simp [sphere, funext_iff]
@[simp]
theorem sphere_zero_right (n k : ℕ) : sphere (n + 1) 0 k = ∅ := by simp [sphere]
theorem sphere_subset_box : sphere n d k ⊆ box n d :=
filter_subset _ _
theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) :
‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = √↑k := by
rw [EuclideanSpace.norm_eq]
dsimp
simp_rw [abs_cast, ← cast_pow, ← cast_sum, (mem_filter.1 hx).2]
theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n → ℕ)) ⊆
(fun x : Fin n → ℕ => (WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)) ⁻¹'
Metric.sphere (0 : PiLp 2 fun _ : Fin n => ℝ) (√↑k) :=
fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx]
/-- The map that appears in Behrend's bound on Roth numbers. -/
@[simps]
def map (d : ℕ) : (Fin n → ℕ) →+ ℕ where
toFun a := ∑ i, a i * d ^ (i : ℕ)
map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero]
map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib]
theorem map_zero (d : ℕ) (a : Fin 0 → ℕ) : map d a = 0 := by simp [map]
theorem map_succ (a : Fin (n + 1) → ℕ) :
map d a = a 0 + (∑ x : Fin n, a x.succ * d ^ (x : ℕ)) * d := by
simp [map, Fin.sum_univ_succ, _root_.pow_succ, ← mul_assoc, ← sum_mul]
theorem map_succ' (a : Fin (n + 1) → ℕ) : map d a = a 0 + map d (a ∘ Fin.succ) * d :=
map_succ _
theorem map_monotone (d : ℕ) : Monotone (map d : (Fin n → ℕ) → ℕ) := fun x y h => by
dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i
theorem map_mod (a : Fin n.succ → ℕ) : map d a % d = a 0 % d := by
rw [map_succ, Nat.add_mul_mod_self_right]
theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) :
map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by
refine ⟨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩
have : x₁ 0 = x₂ 0 := by
rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h]
rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h
exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩
theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by
intro x₁ hx₁ x₂ hx₂ h
induction n with
| zero => simp [eq_iff_true_of_subsingleton]
| succ n ih =>
ext i
have x := (map_eq_iff hx₁ hx₂).1 h
exact Fin.cases x.1 (congr_fun <| ih (fun _ => hx₁ _) (fun _ => hx₂ _) x.2) i
theorem map_le_of_mem_box (hx : x ∈ box n d) :
map (2 * d - 1) x ≤ ∑ i : Fin n, (d - 1) * (2 * d - 1) ^ (i : ℕ) :=
map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _
nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n → ℕ)) := by
set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) :=
{ toFun := fun f => ((↑) : ℕ → ℝ) ∘ f
map_zero' := funext fun _ => cast_zero
map_add' := fun _ _ => funext fun _ => cast_add _ _ }
refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _))
cast_injective.comp_left.injOn (Set.subset_univ _) ?_
refine (threeAPFree_sphere 0 (√↑k)).mono (Set.image_subset_iff.2 fun x => ?_)
rw [Set.mem_preimage, mem_sphere_zero_iff_norm]
exact norm_of_mem_sphere
theorem threeAPFree_image_sphere :
ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by
rw [coe_image]
apply ThreeAPFree.image' (α := Fin n → ℕ) (β := ℕ) (s := sphere n d k) (map (2 * d - 1))
(map_injOn.mono _) threeAPFree_sphere
rw [Set.add_subset_iff]
rintro a ha b hb i
have hai := mem_box.1 (sphere_subset_box ha) i
have hbi := mem_box.1 (sphere_subset_box hb) i
rw [lt_tsub_iff_right, ← succ_le_iff, two_mul]
exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi)
theorem sum_sq_le_of_mem_box (hx : x ∈ box n d) : ∑ i : Fin n, x i ^ 2 ≤ n * (d - 1) ^ 2 := by
rw [mem_box] at hx
have : ∀ i, x i ^ 2 ≤ (d - 1) ^ 2 := fun i =>
Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _
exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [card_fin, smul_eq_mul])
theorem sum_eq : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) = ((2 * d + 1) ^ n - 1) / 2 := by
refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm
rw [← sum_range fun i => d * (2 * d + 1) ^ (i : ℕ), ← mul_sum, mul_right_comm, mul_comm d, ←
geom_sum_mul_add, add_tsub_cancel_right, mul_comm]
theorem sum_lt : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) < (2 * d + 1) ^ n :=
sum_eq.trans_lt <| (Nat.div_le_self _ 2).trans_lt <| pred_lt (pow_pos (succ_pos _) _).ne'
theorem card_sphere_le_rothNumberNat (n d k : ℕ) :
#(sphere n d k) ≤ rothNumberNat ((2 * d - 1) ^ n) := by
cases n
· dsimp; refine (card_le_univ _).trans_eq ?_; rfl
cases d
· simp
apply threeAPFree_image_sphere.le_rothNumberNat _ _ (card_image_of_injOn _)
· simp only [subset_iff, mem_image, and_imp, forall_exists_index, mem_range,
forall_apply_eq_imp_iff₂, sphere, mem_filter]
rintro _ x hx _ rfl
exact (map_le_of_mem_box hx).trans_lt sum_lt
apply map_injOn.mono fun x => ?_
simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul]
exact fun h _ i => (h i).trans_le le_self_add
/-!
### Optimization
Now that we know how to turn the integer points of any sphere into a 3AP-free set, we find a
sphere containing many integer points by the pigeonhole principle. This gives us an implicit bound
that we then optimize by tweaking the parameters. The (almost) optimal parameters are
`Behrend.nValue` and `Behrend.dValue`.
-/
theorem exists_large_sphere_aux (n d : ℕ) : ∃ k ∈ range (n * (d - 1) ^ 2 + 1),
(↑(d ^ n) / ((n * (d - 1) ^ 2 :) + 1) : ℝ) ≤ #(sphere n d k) := by
refine exists_le_card_fiber_of_nsmul_le_card_of_maps_to (fun x hx => ?_) nonempty_range_succ ?_
· rw [mem_range, Nat.lt_succ_iff]
exact sum_sq_le_of_mem_box hx
· rw [card_range, _root_.nsmul_eq_mul, mul_div_assoc', cast_add_one, mul_div_cancel_left₀,
card_box]
exact (cast_add_one_pos _).ne'
theorem exists_large_sphere (n d : ℕ) :
∃ k, ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≤ #(sphere n d k) := by
obtain ⟨k, -, hk⟩ := exists_large_sphere_aux n d
refine ⟨k, ?_⟩
obtain rfl | hn := n.eq_zero_or_pos
· simp
obtain rfl | hd := d.eq_zero_or_pos
· simp
refine (div_le_div_of_nonneg_left ?_ ?_ ?_).trans hk
· exact cast_nonneg _
· exact cast_add_one_pos _
simp only [← le_sub_iff_add_le', cast_mul, ← mul_sub, cast_pow, cast_sub hd, sub_sq, one_pow,
cast_one, mul_one, sub_add, sub_sub_self]
apply one_le_mul_of_one_le_of_one_le
· rwa [one_le_cast]
rw [_root_.le_sub_iff_add_le]
norm_num
exact one_le_cast.2 hd
theorem bound_aux' (n d : ℕ) : ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≤ rothNumberNat ((2 * d - 1) ^ n) :=
let ⟨_, h⟩ := exists_large_sphere n d
h.trans <| cast_le.2 <| card_sphere_le_rothNumberNat _ _ _
theorem bound_aux (hd : d ≠ 0) (hn : 2 ≤ n) :
(d ^ (n - 2 :) / n : ℝ) ≤ rothNumberNat ((2 * d - 1) ^ n) := by
convert bound_aux' n d using 1
rw [cast_mul, cast_pow, mul_comm, ← div_div, pow_sub₀ _ _ hn, ← div_eq_mul_inv, cast_pow]
rwa [cast_ne_zero]
open scoped Filter Topology
open Real
section NumericalBounds
theorem log_two_mul_two_le_sqrt_log_eight : log 2 * 2 ≤ √(log 8) := by
have : (8 : ℝ) = 2 ^ ((3 : ℕ) : ℝ) := by rw [rpow_natCast]; norm_num
rw [this, log_rpow zero_lt_two (3 : ℕ)]
apply le_sqrt_of_sq_le
rw [mul_pow, sq (log 2), mul_assoc, mul_comm]
refine mul_le_mul_of_nonneg_right ?_ (log_nonneg one_le_two)
rw [← le_div_iff₀]
on_goal 1 => apply log_two_lt_d9.le.trans
all_goals norm_num1
theorem two_div_one_sub_two_div_e_le_eight : 2 / (1 - 2 / exp 1) ≤ 8 := by
rw [div_le_iff₀, mul_sub, mul_one, mul_div_assoc', le_sub_comm, div_le_iff₀ (exp_pos _)]
· linarith [exp_one_gt_d9]
rw [sub_pos, div_lt_one] <;> exact exp_one_gt_d9.trans' (by norm_num)
theorem le_sqrt_log (hN : 4096 ≤ N) : log (2 / (1 - 2 / exp 1)) * (69 / 50) ≤ √(log ↑N) := by
have : (12 : ℕ) * log 2 ≤ log N := by
rw [← log_rpow zero_lt_two, rpow_natCast]
exact log_le_log (by positivity) (mod_cast hN)
refine (mul_le_mul_of_nonneg_right (log_le_log ?_ two_div_one_sub_two_div_e_le_eight) <| by
norm_num1).trans ?_
· refine div_pos zero_lt_two ?_
rw [sub_pos, div_lt_one (exp_pos _)]
exact exp_one_gt_d9.trans_le' (by norm_num1)
have l8 : log 8 = (3 : ℕ) * log 2 := by
rw [← log_rpow zero_lt_two, rpow_natCast]
norm_num
rw [l8]
apply le_sqrt_of_sq_le (le_trans _ this)
rw [mul_right_comm, mul_pow, sq (log 2), ← mul_assoc]
apply mul_le_mul_of_nonneg_right _ (log_nonneg one_le_two)
rw [← le_div_iff₀']
· exact log_two_lt_d9.le.trans (by norm_num1)
exact sq_pos_of_ne_zero (by norm_num1)
theorem exp_neg_two_mul_le {x : ℝ} (hx : 0 < x) : exp (-2 * x) < exp (2 - ⌈x⌉₊) / ⌈x⌉₊ := by
have h₁ := ceil_lt_add_one hx.le
have h₂ : 1 - x ≤ 2 - ⌈x⌉₊ := by linarith
calc
_ ≤ exp (1 - x) / (x + 1) := ?_
_ ≤ exp (2 - ⌈x⌉₊) / (x + 1) := by gcongr
_ < _ := by gcongr
rw [le_div_iff₀ (add_pos hx zero_lt_one), ← le_div_iff₀' (exp_pos _), ← exp_sub, neg_mul,
sub_neg_eq_add, two_mul, sub_add_add_cancel, add_comm _ x]
exact le_trans (le_add_of_nonneg_right zero_le_one) (add_one_le_exp _)
theorem div_lt_floor {x : ℝ} (hx : 2 / (1 - 2 / exp 1) ≤ x) : x / exp 1 < (⌊x / 2⌋₊ : ℝ) := by
apply lt_of_le_of_lt _ (sub_one_lt_floor _)
have : 0 < 1 - 2 / exp 1 := by
rw [sub_pos, div_lt_one (exp_pos _)]
exact lt_of_le_of_lt (by norm_num) exp_one_gt_d9
rwa [le_sub_comm, div_eq_mul_one_div x, div_eq_mul_one_div x, ← mul_sub, div_sub', ←
div_eq_mul_one_div, mul_div_assoc', one_le_div, ← div_le_iff₀ this]
· exact zero_lt_two
· exact two_ne_zero
theorem ceil_lt_mul {x : ℝ} (hx : 50 / 19 ≤ x) : (⌈x⌉₊ : ℝ) < 1.38 * x := by
refine (ceil_lt_add_one <| hx.trans' <| by norm_num).trans_le ?_
rw [← le_sub_iff_add_le', ← sub_one_mul]
have : (1.38 : ℝ) = 69 / 50 := by norm_num
rwa [this, show (69 / 50 - 1 : ℝ) = (50 / 19)⁻¹ by norm_num1, ←
div_eq_inv_mul, one_le_div]
norm_num1
end NumericalBounds
/-- The (almost) optimal value of `n` in `Behrend.bound_aux`. -/
noncomputable def nValue (N : ℕ) : ℕ :=
⌈√(log N)⌉₊
/-- The (almost) optimal value of `d` in `Behrend.bound_aux`. -/
noncomputable def dValue (N : ℕ) : ℕ := ⌊(N : ℝ) ^ (nValue N : ℝ)⁻¹ / 2⌋₊
theorem nValue_pos (hN : 2 ≤ N) : 0 < nValue N :=
ceil_pos.2 <| Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 <| hN
theorem three_le_nValue (hN : 64 ≤ N) : 3 ≤ nValue N := by
rw [nValue, ← lt_iff_add_one_le, lt_ceil, cast_two]
apply lt_sqrt_of_sq_lt
have : (2 : ℝ) ^ ((6 : ℕ) : ℝ) ≤ N := by
rw [rpow_natCast]
exact (cast_le.2 hN).trans' (by norm_num1)
apply lt_of_lt_of_le _ (log_le_log (rpow_pos_of_pos zero_lt_two _) this)
rw [log_rpow zero_lt_two, ← div_lt_iff₀']
· exact log_two_gt_d9.trans_le' (by norm_num1)
· norm_num1
theorem dValue_pos (hN₃ : 8 ≤ N) : 0 < dValue N := by
have hN₀ : 0 < (N : ℝ) := cast_pos.2 (succ_pos'.trans_le hN₃)
rw [dValue, floor_pos, ← log_le_log_iff zero_lt_one, log_one, log_div _ two_ne_zero, log_rpow hN₀,
inv_mul_eq_div, sub_nonneg, le_div_iff₀]
· have : (nValue N : ℝ) ≤ 2 * √(log N) := by
apply (ceil_lt_add_one <| sqrt_nonneg _).le.trans
rw [two_mul, add_le_add_iff_left]
apply le_sqrt_of_sq_le
rw [one_pow, le_log_iff_exp_le hN₀]
exact (exp_one_lt_d9.le.trans <| by norm_num).trans (cast_le.2 hN₃)
apply (mul_le_mul_of_nonneg_left this <| log_nonneg one_le_two).trans _
rw [← mul_assoc, ← le_div_iff₀ (Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 _), div_sqrt]
· apply log_two_mul_two_le_sqrt_log_eight.trans
apply Real.sqrt_le_sqrt
exact log_le_log (by norm_num) (mod_cast hN₃)
exact hN₃.trans_lt' (by norm_num)
· exact cast_pos.2 (nValue_pos <| hN₃.trans' <| by norm_num)
· exact (rpow_pos_of_pos hN₀ _).ne'
· exact div_pos (rpow_pos_of_pos hN₀ _) zero_lt_two
theorem le_N (hN : 2 ≤ N) : (2 * dValue N - 1) ^ nValue N ≤ N := by
have : (2 * dValue N - 1) ^ nValue N ≤ (2 * dValue N) ^ nValue N :=
Nat.pow_le_pow_left (Nat.sub_le _ _) _
apply this.trans
suffices ((2 * dValue N) ^ nValue N : ℝ) ≤ N from mod_cast this
suffices i : (2 * dValue N : ℝ) ≤ (N : ℝ) ^ (nValue N : ℝ)⁻¹ by
rw [← rpow_natCast]
apply (rpow_le_rpow (mul_nonneg zero_le_two (cast_nonneg _)) i (cast_nonneg _)).trans
rw [← rpow_mul (cast_nonneg _), inv_mul_cancel₀, rpow_one]
rw [cast_ne_zero]
apply (nValue_pos hN).ne'
rw [← le_div_iff₀']
· exact floor_le (div_nonneg (rpow_nonneg (cast_nonneg _) _) zero_le_two)
apply zero_lt_two
theorem bound (hN : 4096 ≤ N) : (N : ℝ) ^ (nValue N : ℝ)⁻¹ / exp 1 < dValue N := by
apply div_lt_floor _
rw [← log_le_log_iff, log_rpow, mul_comm, ← div_eq_mul_inv]
· apply le_trans _ (div_le_div_of_nonneg_left _ _ (ceil_lt_mul _).le)
· rw [mul_comm, ← div_div, div_sqrt, le_div_iff₀]
· norm_num; exact le_sqrt_log hN
· norm_num1
· apply log_nonneg
rw [one_le_cast]
exact hN.trans' (by norm_num1)
· rw [cast_pos, lt_ceil, cast_zero, Real.sqrt_pos]
refine log_pos ?_
rw [one_lt_cast]
exact hN.trans_lt' (by norm_num1)
apply le_sqrt_of_sq_le
have : (12 : ℕ) * log 2 ≤ log N := by
rw [← log_rpow zero_lt_two, rpow_natCast]
exact log_le_log (by positivity) (mod_cast hN)
refine le_trans ?_ this
rw [← div_le_iff₀']
· exact log_two_gt_d9.le.trans' (by norm_num1)
· norm_num1
· rw [cast_pos]
exact hN.trans_lt' (by norm_num1)
· refine div_pos zero_lt_two ?_
rw [sub_pos, div_lt_one (exp_pos _)]
exact lt_of_le_of_lt (by norm_num1) exp_one_gt_d9
positivity
theorem roth_lower_bound_explicit (hN : 4096 ≤ N) :
(N : ℝ) * exp (-4 * √(log N)) < rothNumberNat N := by
let n := nValue N
have hn : 0 < (n : ℝ) := cast_pos.2 (nValue_pos <| hN.trans' <| by norm_num1)
have hd : 0 < dValue N := dValue_pos (hN.trans' <| by norm_num1)
have hN₀ : 0 < (N : ℝ) := cast_pos.2 (hN.trans' <| by norm_num1)
have hn₂ : 2 < n := three_le_nValue <| hN.trans' <| by norm_num1
have : (2 * dValue N - 1) ^ n ≤ N := le_N (hN.trans' <| by norm_num1)
calc
_ ≤ (N ^ (nValue N : ℝ)⁻¹ / rexp 1 : ℝ) ^ (n - 2) / n := ?_
_ < _ := by gcongr; exacts [(tsub_pos_of_lt hn₂).ne', bound hN]
_ ≤ rothNumberNat ((2 * dValue N - 1) ^ n) := bound_aux hd.ne' hn₂.le
_ ≤ rothNumberNat N := mod_cast rothNumberNat.mono this
rw [← rpow_natCast, div_rpow (rpow_nonneg hN₀.le _) (exp_pos _).le, ← rpow_mul hN₀.le,
inv_mul_eq_div, cast_sub hn₂.le, cast_two, same_sub_div hn.ne', exp_one_rpow,
div_div, rpow_sub hN₀, rpow_one, div_div, div_eq_mul_inv]
refine mul_le_mul_of_nonneg_left ?_ (cast_nonneg _)
rw [mul_inv, mul_inv, ← exp_neg, ← rpow_neg (cast_nonneg _), neg_sub, ← div_eq_mul_inv]
have : exp (-4 * √(log N)) = exp (-2 * √(log N)) * exp (-2 * √(log N)) := by
rw [← exp_add, ← add_mul]
norm_num
rw [this]
refine mul_le_mul ?_ (exp_neg_two_mul_le <| Real.sqrt_pos.2 <| log_pos ?_).le (exp_pos _).le <|
rpow_nonneg (cast_nonneg _) _
· rw [← le_log_iff_exp_le (rpow_pos_of_pos hN₀ _), log_rpow hN₀, ← le_div_iff₀, mul_div_assoc,
div_sqrt, neg_mul, neg_le_neg_iff, div_mul_eq_mul_div, div_le_iff₀ hn]
· exact mul_le_mul_of_nonneg_left (le_ceil _) zero_le_two
refine Real.sqrt_pos.2 (log_pos ?_)
rw [one_lt_cast]
exact hN.trans_lt' (by norm_num1)
· rw [one_lt_cast]
exact hN.trans_lt' (by norm_num1)
theorem exp_four_lt : exp 4 < 64 := by
rw [show (64 : ℝ) = 2 ^ ((6 : ℕ) : ℝ) by rw [rpow_natCast]; norm_num1,
← lt_log_iff_exp_lt (rpow_pos_of_pos zero_lt_two _), log_rpow zero_lt_two, ← div_lt_iff₀']
· exact log_two_gt_d9.trans_le' (by norm_num1)
· norm_num
theorem four_zero_nine_six_lt_exp_sixteen : 4096 < exp 16 := by
rw [← log_lt_iff_lt_exp (show (0 : ℝ) < 4096 by norm_num), show (4096 : ℝ) = 2 ^ 12 by norm_cast,
← rpow_natCast, log_rpow zero_lt_two, cast_ofNat]
linarith [log_two_lt_d9]
theorem lower_bound_le_one' (hN : 2 ≤ N) (hN' : N ≤ 4096) :
(N : ℝ) * exp (-4 * √(log N)) ≤ 1 := by
rw [← log_le_log_iff (mul_pos (cast_pos.2 (zero_lt_two.trans_le hN)) (exp_pos _)) zero_lt_one,
log_one, log_mul (cast_pos.2 (zero_lt_two.trans_le hN)).ne' (exp_pos _).ne', log_exp, neg_mul, ←
sub_eq_add_neg, sub_nonpos, ←
div_le_iff₀ (Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 <| one_lt_two.trans_le hN), div_sqrt,
sqrt_le_left zero_le_four, log_le_iff_le_exp (cast_pos.2 (zero_lt_two.trans_le hN))]
norm_num1
apply le_trans _ four_zero_nine_six_lt_exp_sixteen.le
exact mod_cast hN'
theorem lower_bound_le_one (hN : 1 ≤ N) (hN' : N ≤ 4096) :
(N : ℝ) * exp (-4 * √(log N)) ≤ 1 := by
obtain rfl | hN := hN.eq_or_lt
· norm_num
· exact lower_bound_le_one' hN hN'
theorem roth_lower_bound : (N : ℝ) * exp (-4 * √(log N)) ≤ rothNumberNat N := by
obtain rfl | hN := Nat.eq_zero_or_pos N
· norm_num
obtain h₁ | h₁ := le_or_lt 4096 N
· exact (roth_lower_bound_explicit h₁).le
· apply (lower_bound_le_one hN h₁.le).trans
simpa using rothNumberNat.monotone hN
end Behrend
| Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean | 540 | 544 | |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.HomotopyCategory.Pretriangulated
import Mathlib.CategoryTheory.Triangulated.Triangulated
import Mathlib.CategoryTheory.ComposableArrows
/-! The triangulated structure on the homotopy category of complexes
In this file, we show that for any additive category `C`,
the pretriangulated category `HomotopyCategory C (ComplexShape.up ℤ)` is triangulated.
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Category Limits Pretriangulated ComposableArrows
variable {C : Type*} [Category C] [Preadditive C] [HasBinaryBiproducts C]
{X₁ X₂ X₃ : CochainComplex C ℤ} (f : X₁ ⟶ X₂) (g : X₂ ⟶ X₃)
namespace CochainComplex
open HomComplex mappingCone
/-- Given two composable morphisms `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` in the category
of cochain complexes, this is the canonical triangle
`mappingCone f ⟶ mappingCone (f ≫ g) ⟶ mappingCone g ⟶ (mappingCone f)⟦1⟧`. -/
@[simps! mor₁ mor₂ mor₃ obj₁ obj₂ obj₃]
noncomputable def mappingConeCompTriangle : Triangle (CochainComplex C ℤ) :=
Triangle.mk (map f (f ≫ g) (𝟙 X₁) g (by rw [id_comp]))
(map (f ≫ g) g f (𝟙 X₃) (by rw [comp_id]))
((triangle g).mor₃ ≫ (inr f)⟦1⟧')
/-- Given two composable morphisms `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` in the category
of cochain complexes, this is the canonical triangle
`mappingCone f ⟶ mappingCone (f ≫ g) ⟶ mappingCone g ⟶ (mappingCone f)⟦1⟧`
in the homotopy category. It is a distinguished triangle,
see `HomotopyCategory.mappingConeCompTriangleh_distinguished`. -/
noncomputable def mappingConeCompTriangleh :
Triangle (HomotopyCategory C (ComplexShape.up ℤ)) :=
(HomotopyCategory.quotient _ _).mapTriangle.obj (mappingConeCompTriangle f g)
@[reassoc]
lemma mappingConeCompTriangle_mor₃_naturality {Y₁ Y₂ Y₃ : CochainComplex C ℤ} (f' : Y₁ ⟶ Y₂)
(g' : Y₂ ⟶ Y₃) (φ : mk₂ f g ⟶ mk₂ f' g') :
map g g' (φ.app 1) (φ.app 2) (naturality' φ 1 2) ≫ (mappingConeCompTriangle f' g').mor₃ =
(mappingConeCompTriangle f g).mor₃ ≫
(map f f' (φ.app 0) (φ.app 1) (naturality' φ 0 1))⟦1⟧' := by
ext n
dsimp [map]
-- the following list of lemmas was obtained by doing simp? [ext_from_iff _ (n + 1) _ rfl]
simp only [Int.reduceNeg, Fin.isValue, assoc, inr_f_desc_f, HomologicalComplex.comp_f,
ext_from_iff _ (n + 1) _ rfl, inl_v_desc_f_assoc, Cochain.zero_cochain_comp_v, Cochain.ofHom_v,
inl_v_triangle_mor₃_f_assoc, triangle_obj₁, shiftFunctor_obj_X', shiftFunctor_obj_X,
shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, Preadditive.neg_comp,
id_comp, Preadditive.comp_neg, inr_f_desc_f_assoc, inr_f_triangle_mor₃_f_assoc, zero_comp,
comp_zero, and_self]
namespace MappingConeCompHomotopyEquiv
/-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this
is the canonical morphism (which is an homotopy equivalence) from `mappingCone g` to
the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)`. -/
noncomputable def hom :
mappingCone g ⟶ mappingCone (mappingConeCompTriangle f g).mor₁ :=
lift _ (descCocycle g (Cochain.ofHom (inr f)) 0 (zero_add 1) (by dsimp; simp))
(descCochain _ 0 (Cochain.ofHom (inr (f ≫ g))) (neg_add_cancel 1)) (by
ext p _ rfl
dsimp [mappingConeCompTriangle, map]
simp [ext_from_iff _ _ _ rfl, inl_v_d_assoc _ (p+1) p (p+2) (by omega) (by omega)])
/-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this
is the canonical morphism (which is an homotopy equivalence) from the mapping cone of
| the morphism `mappingCone f ⟶ mappingCone (f ≫ g)` to `mappingCone g`. -/
noncomputable def inv : mappingCone (mappingConeCompTriangle f g).mor₁ ⟶ mappingCone g :=
desc _ ((snd f).comp (inl g) (zero_add (-1)))
(desc _ ((Cochain.ofHom f).comp (inl g) (zero_add (-1))) (inr g) (by simp)) (by
| Mathlib/Algebra/Homology/HomotopyCategory/Triangulated.lean | 77 | 80 |
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SimpleGraph.Regularity.Bound
import Mathlib.Combinatorics.SimpleGraph.Regularity.Equitabilise
import Mathlib.Combinatorics.SimpleGraph.Regularity.Uniform
/-!
# Chunk of the increment partition for Szemerédi Regularity Lemma
In the proof of Szemerédi Regularity Lemma, we need to partition each part of a starting partition
to increase the energy. This file defines those partitions of parts and shows that they locally
increase the energy.
This entire file is internal to the proof of Szemerédi Regularity Lemma.
## Main declarations
* `SzemerediRegularity.chunk`: The partition of a part of the starting partition.
* `SzemerediRegularity.edgeDensity_chunk_uniform`: `chunk` does not locally decrease the edge
density between uniform parts too much.
* `SzemerediRegularity.edgeDensity_chunk_not_uniform`: `chunk` locally increases the edge density
between non-uniform parts.
## TODO
Once ported to mathlib4, this file will be a great golfing ground for Heather's new tactic
`gcongr`.
## References
[Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp]
-/
open Finpartition Finset Fintype Rel Nat
open scoped SzemerediRegularity.Positivity
namespace SzemerediRegularity
variable {α : Type*} [Fintype α] [DecidableEq α] {P : Finpartition (univ : Finset α)}
(hP : P.IsEquipartition) (G : SimpleGraph α) [DecidableRel G.Adj] (ε : ℝ) {U : Finset α}
(hU : U ∈ P.parts) (V : Finset α)
local notation3 "m" => (card α / stepBound #P.parts : ℕ)
/-!
### Definitions
We define `chunk`, the partition of a part, and `star`, the sets of parts of `chunk` that are
contained in the corresponding witness of non-uniformity.
-/
/-- The portion of `SzemerediRegularity.increment` which partitions `U`. -/
noncomputable def chunk : Finpartition U :=
if hUcard : #U = m * 4 ^ #P.parts + (card α / #P.parts - m * 4 ^ #P.parts) then
(atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₁ hUcard
else (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₂ hP hU hUcard
-- `hP` and `hU` are used to get that `U` has size
-- `m * 4 ^ #P.parts + a or m * 4 ^ #P.parts + a + 1`
/-- The portion of `SzemerediRegularity.chunk` which is contained in the witness of non-uniformity
of `U` and `V`. -/
noncomputable def star (V : Finset α) : Finset (Finset α) :=
{A ∈ (chunk hP G ε hU).parts | A ⊆ G.nonuniformWitness ε U V}
/-!
### Density estimates
We estimate the density between parts of `chunk`.
-/
theorem biUnion_star_subset_nonuniformWitness :
(star hP G ε hU V).biUnion id ⊆ G.nonuniformWitness ε U V :=
biUnion_subset_iff_forall_subset.2 fun _ hA => (mem_filter.1 hA).2
variable {hP G ε hU V} {𝒜 : Finset (Finset α)} {s : Finset α}
theorem star_subset_chunk : star hP G ε hU V ⊆ (chunk hP G ε hU).parts :=
filter_subset _ _
private theorem card_nonuniformWitness_sdiff_biUnion_star (hV : V ∈ P.parts) (hUV : U ≠ V)
(h₂ : ¬G.IsUniform ε U V) :
#(G.nonuniformWitness ε U V \ (star hP G ε hU V).biUnion id) ≤ 2 ^ (#P.parts - 1) * m := by
have hX : G.nonuniformWitness ε U V ∈ P.nonuniformWitnesses G ε U :=
nonuniformWitness_mem_nonuniformWitnesses h₂ hV hUV
have q : G.nonuniformWitness ε U V \ (star hP G ε hU V).biUnion id ⊆
{B ∈ (atomise U <| P.nonuniformWitnesses G ε U).parts |
B ⊆ G.nonuniformWitness ε U V ∧ B.Nonempty}.biUnion
fun B => B \ {A ∈ (chunk hP G ε hU).parts | A ⊆ B}.biUnion id := by
intro x hx
rw [← biUnion_filter_atomise hX (G.nonuniformWitness_subset h₂), star, mem_sdiff,
mem_biUnion] at hx
simp only [not_exists, mem_biUnion, and_imp, exists_prop, mem_filter,
not_and, mem_sdiff, id, mem_sdiff] at hx ⊢
obtain ⟨⟨B, hB₁, hB₂⟩, hx⟩ := hx
exact ⟨B, hB₁, hB₂, fun A hA AB => hx A hA <| AB.trans hB₁.2.1⟩
apply (card_le_card q).trans (card_biUnion_le.trans _)
trans ∑ B ∈ (atomise U <| P.nonuniformWitnesses G ε U).parts with
B ⊆ G.nonuniformWitness ε U V ∧ B.Nonempty, m
· suffices ∀ B ∈ (atomise U <| P.nonuniformWitnesses G ε U).parts,
#(B \ {A ∈ (chunk hP G ε hU).parts | A ⊆ B}.biUnion id) ≤ m by
exact sum_le_sum fun B hB => this B <| filter_subset _ _ hB
intro B hB
unfold chunk
split_ifs with h₁
· convert card_parts_equitabilise_subset_le _ (card_aux₁ h₁) hB
· convert card_parts_equitabilise_subset_le _ (card_aux₂ hP hU h₁) hB
rw [sum_const]
refine mul_le_mul_right' ?_ _
have t := card_filter_atomise_le_two_pow (s := U) hX
refine t.trans (pow_right_mono₀ (by norm_num) <| tsub_le_tsub_right ?_ _)
exact card_image_le.trans (card_le_card <| filter_subset _ _)
private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈ P.parts)
(hUV : U ≠ V) (hunif : ¬G.IsUniform ε U V) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
(hε₁ : ε ≤ 1) :
(1 - ε / 10) * #(G.nonuniformWitness ε U V) ≤ #((star hP G ε hU V).biUnion id) := by
have hP₁ : 0 < #P.parts := Finset.card_pos.2 ⟨_, hU⟩
have : (↑2 ^ #P.parts : ℝ) * m / (#U * ε) ≤ ε / 10 := by
rw [← div_div, div_le_iff₀']
swap
· sz_positivity
refine le_of_mul_le_mul_left ?_ (pow_pos zero_lt_two #P.parts)
calc
↑2 ^ #P.parts * ((↑2 ^ #P.parts * m : ℝ) / #U) =
((2 : ℝ) * 2) ^ #P.parts * m / #U := by
rw [mul_pow, ← mul_div_assoc, mul_assoc]
_ = ↑4 ^ #P.parts * m / #U := by norm_num
_ ≤ 1 := div_le_one_of_le₀ (pow_mul_m_le_card_part hP hU) (cast_nonneg _)
_ ≤ ↑2 ^ #P.parts * ε ^ 2 / 10 := by
refine (one_le_sq_iff₀ <| by positivity).1 ?_
rw [div_pow, mul_pow, pow_right_comm, ← pow_mul ε,
one_le_div (sq_pos_of_ne_zero <| by norm_num)]
calc
(↑10 ^ 2) = 100 := by norm_num
_ ≤ ↑4 ^ #P.parts * ε ^ 5 := hPε
_ ≤ ↑4 ^ #P.parts * ε ^ 4 :=
(mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (by sz_positivity) hε₁ <| le_succ _)
(by positivity))
_ = (↑2 ^ 2) ^ #P.parts * ε ^ (2 * 2) := by norm_num
_ = ↑2 ^ #P.parts * (ε * (ε / 10)) := by rw [mul_div_assoc, sq, mul_div_assoc]
calc
(↑1 - ε / 10) * #(G.nonuniformWitness ε U V) ≤
(↑1 - ↑2 ^ #P.parts * m / (#U * ε)) * #(G.nonuniformWitness ε U V) :=
mul_le_mul_of_nonneg_right (sub_le_sub_left this _) (cast_nonneg _)
_ = #(G.nonuniformWitness ε U V) -
↑2 ^ #P.parts * m / (#U * ε) * #(G.nonuniformWitness ε U V) := by
rw [sub_mul, one_mul]
_ ≤ #(G.nonuniformWitness ε U V) - ↑2 ^ (#P.parts - 1) * m := by
refine sub_le_sub_left ?_ _
have : (2 : ℝ) ^ #P.parts = ↑2 ^ (#P.parts - 1) * 2 := by
rw [← _root_.pow_succ, tsub_add_cancel_of_le (succ_le_iff.2 hP₁)]
rw [← mul_div_right_comm, this, mul_right_comm _ (2 : ℝ), mul_assoc, le_div_iff₀]
· refine mul_le_mul_of_nonneg_left ?_ (by positivity)
exact (G.le_card_nonuniformWitness hunif).trans
(le_mul_of_one_le_left (cast_nonneg _) one_le_two)
have := Finset.card_pos.mpr (P.nonempty_of_mem_parts hU)
sz_positivity
_ ≤ #((star hP G ε hU V).biUnion id) := by
rw [sub_le_comm, ←
cast_sub (card_le_card <| biUnion_star_subset_nonuniformWitness hP G ε hU V), ←
card_sdiff (biUnion_star_subset_nonuniformWitness hP G ε hU V)]
exact mod_cast card_nonuniformWitness_sdiff_biUnion_star hV hUV hunif
/-! ### `chunk` -/
theorem card_chunk (hm : m ≠ 0) : #(chunk hP G ε hU).parts = 4 ^ #P.parts := by
unfold chunk
split_ifs
· rw [card_parts_equitabilise _ _ hm, tsub_add_cancel_of_le]
exact le_of_lt a_add_one_le_four_pow_parts_card
· rw [card_parts_equitabilise _ _ hm, tsub_add_cancel_of_le a_add_one_le_four_pow_parts_card]
theorem card_eq_of_mem_parts_chunk (hs : s ∈ (chunk hP G ε hU).parts) :
#s = m ∨ #s = m + 1 := by
unfold chunk at hs
split_ifs at hs <;> exact card_eq_of_mem_parts_equitabilise hs
theorem m_le_card_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : m ≤ #s :=
(card_eq_of_mem_parts_chunk hs).elim ge_of_eq fun i => by simp [i]
| theorem card_le_m_add_one_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : #s ≤ m + 1 :=
(card_eq_of_mem_parts_chunk hs).elim (fun i => by simp [i]) fun i => i.le
theorem card_biUnion_star_le_m_add_one_card_star_mul :
| Mathlib/Combinatorics/SimpleGraph/Regularity/Chunk.lean | 188 | 191 |
/-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Algebra.Group.End
import Mathlib.Data.ZMod.Defs
import Mathlib.Tactic.Ring
/-!
# Racks and Quandles
This file defines racks and quandles, algebraic structures for sets
that bijectively act on themselves with a self-distributivity
property. If `R` is a rack and `act : R → (R ≃ R)` is the self-action,
then the self-distributivity is, equivalently, that
```
act (act x y) = act x * act y * (act x)⁻¹
```
where multiplication is composition in `R ≃ R` as a group.
Quandles are racks such that `act x x = x` for all `x`.
One example of a quandle (not yet in mathlib) is the action of a Lie
algebra on itself, defined by `act x y = Ad (exp x) y`.
Quandles and racks were independently developed by multiple
mathematicians. David Joyce introduced quandles in his thesis
[Joyce1982] to define an algebraic invariant of knot and link
complements that is analogous to the fundamental group of the
exterior, and he showed that the quandle associated to an oriented
knot is invariant up to orientation-reversed mirror image. Racks were
used by Fenn and Rourke for framed codimension-2 knots and
links in [FennRourke1992]. Unital shelves are discussed in [crans2017].
The name "rack" came from wordplay by Conway and Wraith for the "wrack
and ruin" of forgetting everything but the conjugation operation for a
group.
## Main definitions
* `Shelf` is a type with a self-distributive action
* `UnitalShelf` is a shelf with a left and right unit
* `Rack` is a shelf whose action for each element is invertible
* `Quandle` is a rack whose action for an element fixes that element
* `Quandle.conj` defines a quandle of a group acting on itself by conjugation.
* `ShelfHom` is homomorphisms of shelves, racks, and quandles.
* `Rack.EnvelGroup` gives the universal group the rack maps to as a conjugation quandle.
* `Rack.oppositeRack` gives the rack with the action replaced by its inverse.
## Main statements
* `Rack.EnvelGroup` is left adjoint to `Quandle.Conj` (`toEnvelGroup.map`).
The universality statements are `toEnvelGroup.univ` and `toEnvelGroup.univ_uniq`.
## Implementation notes
"Unital racks" are uninteresting (see `Rack.assoc_iff_id`, `UnitalShelf.assoc`), so we do not
define them.
## Notation
The following notation is localized in `quandles`:
* `x ◃ y` is `Shelf.act x y`
* `x ◃⁻¹ y` is `Rack.inv_act x y`
* `S →◃ S'` is `ShelfHom S S'`
Use `open quandles` to use these.
## TODO
* If `g` is the Lie algebra of a Lie group `G`, then `(x ◃ y) = Ad (exp x) x` forms a quandle.
* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,
forming a quandle.
* Alexander quandle with `a ◃ b = t * b + (1 - t) * b`, with `a` and `b` elements
of a module over `Z[t,t⁻¹]`.
* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by
`yH ◃ xH = yzy⁻¹xH`. Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts
transitively on `Q` as a set) is isomorphic to such a quandle.
There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].
## Tags
rack, quandle
-/
open MulOpposite
universe u v
/-- A *Shelf* is a structure with a self-distributive binary operation.
The binary operation is regarded as a left action of the type on itself.
-/
class Shelf (α : Type u) where
/-- The action of the `Shelf` over `α` -/
act : α → α → α
/-- A verification that `act` is self-distributive -/
self_distrib : ∀ {x y z : α}, act x (act y z) = act (act x y) (act x z)
/--
A *unital shelf* is a shelf equipped with an element `1` such that, for all elements `x`,
we have both `x ◃ 1` and `1 ◃ x` equal `x`.
-/
class UnitalShelf (α : Type u) extends Shelf α, One α where
one_act : ∀ a : α, act 1 a = a
act_one : ∀ a : α, act a 1 = a
/-- The type of homomorphisms between shelves.
This is also the notion of rack and quandle homomorphisms.
-/
@[ext]
structure ShelfHom (S₁ : Type*) (S₂ : Type*) [Shelf S₁] [Shelf S₂] where
/-- The function under the Shelf Homomorphism -/
toFun : S₁ → S₂
/-- The homomorphism property of a Shelf Homomorphism -/
map_act' : ∀ {x y : S₁}, toFun (Shelf.act x y) = Shelf.act (toFun x) (toFun y)
/-- A *rack* is an automorphic set (a set with an action on itself by
bijections) that is self-distributive. It is a shelf such that each
element's action is invertible.
The notations `x ◃ y` and `x ◃⁻¹ y` denote the action and the
inverse action, respectively, and they are right associative.
-/
class Rack (α : Type u) extends Shelf α where
/-- The inverse actions of the elements -/
invAct : α → α → α
/-- Proof of left inverse -/
left_inv : ∀ x, Function.LeftInverse (invAct x) (act x)
/-- Proof of right inverse -/
right_inv : ∀ x, Function.RightInverse (invAct x) (act x)
/-- Action of a Shelf -/
scoped[Quandles] infixr:65 " ◃ " => Shelf.act
/-- Inverse Action of a Rack -/
scoped[Quandles] infixr:65 " ◃⁻¹ " => Rack.invAct
/-- Shelf Homomorphism -/
scoped[Quandles] infixr:25 " →◃ " => ShelfHom
open Quandles
namespace UnitalShelf
open Shelf
variable {S : Type*} [UnitalShelf S]
/--
A monoid is *graphic* if, for all `x` and `y`, the *graphic identity*
`(x * y) * x = x * y` holds. For a unital shelf, this graphic
identity holds.
-/
lemma act_act_self_eq (x y : S) : (x ◃ y) ◃ x = x ◃ y := by
have h : (x ◃ y) ◃ x = (x ◃ y) ◃ (x ◃ 1) := by rw [act_one]
rw [h, ← Shelf.self_distrib, act_one]
lemma act_idem (x : S) : (x ◃ x) = x := by rw [← act_one x, ← Shelf.self_distrib, act_one]
lemma act_self_act_eq (x y : S) : x ◃ (x ◃ y) = x ◃ y := by
have h : x ◃ (x ◃ y) = (x ◃ 1) ◃ (x ◃ y) := by rw [act_one]
rw [h, ← Shelf.self_distrib, one_act]
/--
The associativity of a unital shelf comes for free.
-/
lemma assoc (x y z : S) : (x ◃ y) ◃ z = x ◃ y ◃ z := by
rw [self_distrib, self_distrib, act_act_self_eq, act_self_act_eq]
end UnitalShelf
namespace Rack
variable {R : Type*} [Rack R]
export Shelf (self_distrib)
/-- A rack acts on itself by equivalences. -/
def act' (x : R) : R ≃ R where
toFun := Shelf.act x
invFun := invAct x
left_inv := left_inv x
right_inv := right_inv x
@[simp]
theorem act'_apply (x y : R) : act' x y = x ◃ y :=
rfl
@[simp]
theorem act'_symm_apply (x y : R) : (act' x).symm y = x ◃⁻¹ y :=
rfl
@[simp]
theorem invAct_apply (x y : R) : (act' x)⁻¹ y = x ◃⁻¹ y :=
rfl
@[simp]
theorem invAct_act_eq (x y : R) : x ◃⁻¹ x ◃ y = y :=
left_inv x y
@[simp]
theorem act_invAct_eq (x y : R) : x ◃ x ◃⁻¹ y = y :=
right_inv x y
theorem left_cancel (x : R) {y y' : R} : x ◃ y = x ◃ y' ↔ y = y' := by
constructor
· apply (act' x).injective
rintro rfl
rfl
theorem left_cancel_inv (x : R) {y y' : R} : x ◃⁻¹ y = x ◃⁻¹ y' ↔ y = y' := by
constructor
· apply (act' x).symm.injective
rintro rfl
rfl
theorem self_distrib_inv {x y z : R} : x ◃⁻¹ y ◃⁻¹ z = (x ◃⁻¹ y) ◃⁻¹ x ◃⁻¹ z := by
rw [← left_cancel (x ◃⁻¹ y), right_inv, ← left_cancel x, right_inv, self_distrib]
repeat' rw [right_inv]
/-- The *adjoint action* of a rack on itself is `op'`, and the adjoint
action of `x ◃ y` is the conjugate of the action of `y` by the action
of `x`. It is another way to understand the self-distributivity axiom.
This is used in the natural rack homomorphism `toConj` from `R` to
`Conj (R ≃ R)` defined by `op'`.
-/
theorem ad_conj {R : Type*} [Rack R] (x y : R) : act' (x ◃ y) = act' x * act' y * (act' x)⁻¹ := by
rw [eq_mul_inv_iff_mul_eq]; ext z
apply self_distrib.symm
/-- The opposite rack, swapping the roles of `◃` and `◃⁻¹`.
-/
instance oppositeRack : Rack Rᵐᵒᵖ where
act x y := op (invAct (unop x) (unop y))
self_distrib := by
intro x y z
induction x
induction y
induction z
simp only [op_inj, unop_op, op_unop]
rw [self_distrib_inv]
invAct x y := op (Shelf.act (unop x) (unop y))
left_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp
right_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp
@[simp]
theorem op_act_op_eq {x y : R} : op x ◃ op y = op (x ◃⁻¹ y) :=
rfl
@[simp]
theorem op_invAct_op_eq {x y : R} : op x ◃⁻¹ op y = op (x ◃ y) :=
rfl
@[simp]
theorem self_act_act_eq {x y : R} : (x ◃ x) ◃ y = x ◃ y := by rw [← right_inv x y, ← self_distrib]
@[simp]
theorem self_invAct_invAct_eq {x y : R} : (x ◃⁻¹ x) ◃⁻¹ y = x ◃⁻¹ y := by
have h := @self_act_act_eq _ _ (op x) (op y)
simpa using h
@[simp]
theorem self_act_invAct_eq {x y : R} : (x ◃ x) ◃⁻¹ y = x ◃⁻¹ y := by
rw [← left_cancel (x ◃ x)]
rw [right_inv]
rw [self_act_act_eq]
rw [right_inv]
@[simp]
theorem self_invAct_act_eq {x y : R} : (x ◃⁻¹ x) ◃ y = x ◃ y := by
have h := @self_act_invAct_eq _ _ (op x) (op y)
simpa using h
theorem self_act_eq_iff_eq {x y : R} : x ◃ x = y ◃ y ↔ x = y := by
constructor; swap
· rintro rfl; rfl
intro h
trans (x ◃ x) ◃⁻¹ x ◃ x
· rw [← left_cancel (x ◃ x), right_inv, self_act_act_eq]
· rw [h, ← left_cancel (y ◃ y), right_inv, self_act_act_eq]
theorem self_invAct_eq_iff_eq {x y : R} : x ◃⁻¹ x = y ◃⁻¹ y ↔ x = y := by
| have h := @self_act_eq_iff_eq _ _ (op x) (op y)
| Mathlib/Algebra/Quandle.lean | 283 | 283 |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Subalgebra
import Mathlib.LinearAlgebra.Finsupp.Span
/-!
# Lie submodules of a Lie algebra
In this file we define Lie submodules, we construct the lattice structure on Lie submodules and we
use it to define various important operations, notably the Lie span of a subset of a Lie module.
## Main definitions
* `LieSubmodule`
* `LieSubmodule.wellFounded_of_noetherian`
* `LieSubmodule.lieSpan`
* `LieSubmodule.map`
* `LieSubmodule.comap`
## Tags
lie algebra, lie submodule, lie ideal, lattice structure
-/
universe u v w w₁ w₂
section LieSubmodule
variable (R : Type u) (L : Type v) (M : Type w)
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
/-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie module. -/
structure LieSubmodule extends Submodule R M where
lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier
attribute [nolint docBlame] LieSubmodule.toSubmodule
attribute [coe] LieSubmodule.toSubmodule
namespace LieSubmodule
variable {R L M}
variable (N N' : LieSubmodule R L M)
instance : SetLike (LieSubmodule R L M) M where
coe s := s.carrier
coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h
instance : AddSubgroupClass (LieSubmodule R L M) M where
add_mem {N} _ _ := N.add_mem'
zero_mem N := N.zero_mem'
neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx
instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where
smul_mem {s} c _ h := s.smul_mem' c h
/-- The zero module is a Lie submodule of any Lie module. -/
instance : Zero (LieSubmodule R L M) :=
⟨{ (0 : Submodule R M) with
lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩
instance : Inhabited (LieSubmodule R L M) :=
⟨0⟩
instance (priority := high) coeSort : CoeSort (LieSubmodule R L M) (Type w) where
coe N := { x : M // x ∈ N }
instance (priority := mid) coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) :=
⟨toSubmodule⟩
instance : CanLift (Submodule R M) (LieSubmodule R L M) (·)
(fun N ↦ ∀ {x : L} {m : M}, m ∈ N → ⁅x, m⁆ ∈ N) where
prf N hN := ⟨⟨N, hN⟩, rfl⟩
@[norm_cast]
theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N :=
rfl
theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) :=
Iff.rfl
theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} :
x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} :
x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p :=
Iff.rfl
@[simp]
theorem mem_toSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N :=
Iff.rfl
@[deprecated (since := "2024-12-30")] alias mem_coeSubmodule := mem_toSubmodule
theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N :=
Iff.rfl
@[simp]
protected theorem zero_mem : (0 : M) ∈ N :=
zero_mem N
@[simp]
theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 :=
Subtype.ext_iff_val
@[simp]
theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) :
((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S :=
rfl
theorem toSubmodule_mk (p : Submodule R M) (h) :
(({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl
@[deprecated (since := "2024-12-30")] alias coe_toSubmodule_mk := toSubmodule_mk
theorem toSubmodule_injective :
Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by
cases x; cases y; congr
@[deprecated (since := "2024-12-30")] alias coeSubmodule_injective := toSubmodule_injective
@[ext]
theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' :=
SetLike.ext h
@[simp]
theorem toSubmodule_inj : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' :=
toSubmodule_injective.eq_iff
@[deprecated (since := "2024-12-30")] alias coe_toSubmodule_inj := toSubmodule_inj
@[deprecated (since := "2024-12-29")] alias toSubmodule_eq_iff := toSubmodule_inj
/-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where
carrier := s
zero_mem' := by simp [hs]
add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y
smul_mem' := by exact hs.symm ▸ N.smul_mem'
lie_mem := by exact hs.symm ▸ N.lie_mem
@[simp]
theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s :=
rfl
theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
instance : LieRingModule L N where
bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩
add_lie := by intro x y m; apply SetCoe.ext; apply add_lie
lie_add := by intro x m n; apply SetCoe.ext; apply lie_add
leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie
@[simp, norm_cast]
theorem coe_zero : ((0 : N) : M) = (0 : M) :=
rfl
@[simp, norm_cast]
theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) :=
rfl
@[simp, norm_cast]
theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) :=
rfl
@[simp, norm_cast]
theorem coe_bracket (x : L) (m : N) :
(↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ :=
rfl
-- Copying instances from `Submodule` for correct discrimination keys
instance [IsNoetherian R M] (N : LieSubmodule R L M) : IsNoetherian R N :=
inferInstanceAs <| IsNoetherian R N.toSubmodule
instance [IsArtinian R M] (N : LieSubmodule R L M) : IsArtinian R N :=
inferInstanceAs <| IsArtinian R N.toSubmodule
instance [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R N :=
inferInstanceAs <| NoZeroSMulDivisors R N.toSubmodule
variable [LieAlgebra R L] [LieModule R L M]
instance instLieModule : LieModule R L N where
lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul
smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie
instance [Subsingleton M] : Unique (LieSubmodule R L M) :=
⟨⟨0⟩, fun _ ↦ (toSubmodule_inj _ _).mp (Subsingleton.elim _ _)⟩
end LieSubmodule
variable {R M}
theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) :
(∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by
constructor
· rintro ⟨N, rfl⟩ _ _; exact N.lie_mem
· intro h; use { p with lie_mem := @h }
namespace LieSubalgebra
variable {L}
variable [LieAlgebra R L]
variable (K : LieSubalgebra R L)
/-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains
a distinguished Lie submodule for the action of `K`, namely `K` itself. -/
def toLieSubmodule : LieSubmodule R K L :=
{ (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy }
@[simp]
theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl
variable {K}
@[simp]
theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K :=
Iff.rfl
end LieSubalgebra
end LieSubmodule
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w}
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
variable (N N' : LieSubmodule R L M)
section LatticeStructure
open Set
theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) :=
SetLike.coe_injective
@[simp, norm_cast]
theorem toSubmodule_le_toSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' :=
Iff.rfl
@[deprecated (since := "2024-12-30")]
alias coeSubmodule_le_coeSubmodule := toSubmodule_le_toSubmodule
instance : Bot (LieSubmodule R L M) :=
⟨0⟩
instance instUniqueBot : Unique (⊥ : LieSubmodule R L M) :=
inferInstanceAs <| Unique (⊥ : Submodule R M)
@[simp]
theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} :=
rfl
@[simp]
theorem bot_toSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ :=
rfl
@[deprecated (since := "2024-12-30")] alias bot_coeSubmodule := bot_toSubmodule
@[simp]
theorem toSubmodule_eq_bot : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_bot_iff := toSubmodule_eq_bot
@[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[simp]
theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 :=
mem_singleton_iff
instance : Top (LieSubmodule R L M) :=
⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩
@[simp]
theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ :=
rfl
@[simp]
theorem top_toSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ :=
rfl
@[deprecated (since := "2024-12-30")] alias top_coeSubmodule := top_toSubmodule
@[simp]
theorem toSubmodule_eq_top : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_top_iff := toSubmodule_eq_top
@[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[simp]
theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) :=
mem_univ x
instance : Min (LieSubmodule R L M) :=
⟨fun N N' ↦
{ (N ⊓ N' : Submodule R M) with
lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩
instance : InfSet (LieSubmodule R L M) :=
⟨fun S ↦
{ toSubmodule := sInf {(s : Submodule R M) | s ∈ S}
lie_mem := fun {x m} h ↦ by
simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq,
forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢
intro N hN; apply N.lie_mem (h N hN) }⟩
@[simp]
theorem inf_coe : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' :=
rfl
@[norm_cast, simp]
theorem inf_toSubmodule :
(↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) :=
rfl
@[deprecated (since := "2024-12-30")] alias inf_coe_toSubmodule := inf_toSubmodule
@[simp]
theorem sInf_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} :=
rfl
@[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule := sInf_toSubmodule
theorem sInf_toSubmodule_eq_iInf (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by
rw [sInf_toSubmodule, ← Set.image, sInf_image]
@[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule' := sInf_toSubmodule_eq_iInf
@[simp]
theorem iInf_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by
rw [iInf, sInf_toSubmodule]; ext; simp
@[deprecated (since := "2024-12-30")] alias iInf_coe_toSubmodule := iInf_toSubmodule
@[simp]
theorem sInf_coe (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by
rw [← LieSubmodule.coe_toSubmodule, sInf_toSubmodule, Submodule.sInf_coe]
ext m
simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp,
and_imp, SetLike.mem_coe, mem_toSubmodule]
@[simp]
theorem iInf_coe {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by
rw [iInf, sInf_coe]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq']
@[simp]
theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by
rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter]; rfl
instance : Max (LieSubmodule R L M) where
max N N' :=
{ toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M)
lie_mem := by
rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M))
change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)
rw [Submodule.mem_sup] at hm ⊢
obtain ⟨y, hy, z, hz, rfl⟩ := hm
exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ }
instance : SupSet (LieSubmodule R L M) where
sSup S :=
{ toSubmodule := sSup {(p : Submodule R M) | p ∈ S}
lie_mem := by
intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S})
change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S}
obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm
clear hm
classical
induction s using Finset.induction_on generalizing m with
| empty =>
replace hsm : m = 0 := by simpa using hsm
simp [hsm]
| insert q t hqt ih =>
rw [Finset.iSup_insert] at hsm
obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm
rw [lie_add]
refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu)
obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t)
suffices p ≤ sSup {(p : Submodule R M) | p ∈ S} by exact this (p.lie_mem hm')
exact le_sSup ⟨p, hp, rfl⟩ }
@[norm_cast, simp]
theorem sup_toSubmodule :
(↑(N ⊔ N') : Submodule R M) = (N : Submodule R M) ⊔ (N' : Submodule R M) := by
rfl
@[deprecated (since := "2024-12-30")] alias sup_coe_toSubmodule := sup_toSubmodule
@[simp]
theorem sSup_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = sSup {(s : Submodule R M) | s ∈ S} :=
rfl
@[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule := sSup_toSubmodule
theorem sSup_toSubmodule_eq_iSup (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = ⨆ N ∈ S, (N : Submodule R M) := by
rw [sSup_toSubmodule, ← Set.image, sSup_image]
@[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule' := sSup_toSubmodule_eq_iSup
@[simp]
theorem iSup_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨆ i, p i) : Submodule R M) = ⨆ i, (p i : Submodule R M) := by
rw [iSup, sSup_toSubmodule]; ext; simp [Submodule.mem_sSup, Submodule.mem_iSup]
@[deprecated (since := "2024-12-30")] alias iSup_coe_toSubmodule := iSup_toSubmodule
/-- The set of Lie submodules of a Lie module form a complete lattice. -/
instance : CompleteLattice (LieSubmodule R L M) :=
{ toSubmodule_injective.completeLattice toSubmodule sup_toSubmodule inf_toSubmodule
sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with
toPartialOrder := SetLike.instPartialOrder }
theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) :
b ∈ ⨆ i, N i :=
(le_iSup N i) h
@[elab_as_elim]
lemma iSup_induction {ι} (N : ι → LieSubmodule R L M) {motive : M → Prop} {x : M}
(hx : x ∈ ⨆ i, N i) (mem : ∀ i, ∀ y ∈ N i, motive y) (zero : motive 0)
(add : ∀ y z, motive y → motive z → motive (y + z)) : motive x := by
rw [← LieSubmodule.mem_toSubmodule, LieSubmodule.iSup_toSubmodule] at hx
exact Submodule.iSup_induction (motive := motive) (fun i ↦ (N i : Submodule R M)) hx mem zero add
@[elab_as_elim]
theorem iSup_induction' {ι} (N : ι → LieSubmodule R L M) {motive : (x : M) → (x ∈ ⨆ i, N i) → Prop}
(mem : ∀ (i) (x) (hx : x ∈ N i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _))
(add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) {x : M}
(hx : x ∈ ⨆ i, N i) : motive x hx := by
refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, N i) (hc : motive x hx) => hc
refine iSup_induction N (motive := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, N i), motive x hx) hx
(fun i x hx => ?_) ?_ fun x y => ?_
· exact ⟨_, mem _ _ hx⟩
· exact ⟨_, zero⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, add _ _ _ _ Cx Cy⟩
variable {N N'}
@[simp] lemma disjoint_toSubmodule :
Disjoint (N : Submodule R M) (N' : Submodule R M) ↔ Disjoint N N' := by
rw [disjoint_iff, disjoint_iff, ← toSubmodule_inj, inf_toSubmodule, bot_toSubmodule,
← disjoint_iff]
@[deprecated disjoint_toSubmodule (since := "2025-04-03")]
theorem disjoint_iff_toSubmodule :
Disjoint N N' ↔ Disjoint (N : Submodule R M) (N' : Submodule R M) := disjoint_toSubmodule.symm
@[deprecated (since := "2024-12-30")] alias disjoint_iff_coe_toSubmodule := disjoint_iff_toSubmodule
@[simp] lemma codisjoint_toSubmodule :
Codisjoint (N : Submodule R M) (N' : Submodule R M) ↔ Codisjoint N N' := by
rw [codisjoint_iff, codisjoint_iff, ← toSubmodule_inj, sup_toSubmodule,
top_toSubmodule, ← codisjoint_iff]
@[deprecated codisjoint_toSubmodule (since := "2025-04-03")]
theorem codisjoint_iff_toSubmodule :
Codisjoint N N' ↔ Codisjoint (N : Submodule R M) (N' : Submodule R M) :=
codisjoint_toSubmodule.symm
@[deprecated (since := "2024-12-30")]
alias codisjoint_iff_coe_toSubmodule := codisjoint_iff_toSubmodule
@[simp] lemma isCompl_toSubmodule :
IsCompl (N : Submodule R M) (N' : Submodule R M) ↔ IsCompl N N' := by
simp [isCompl_iff]
@[deprecated isCompl_toSubmodule (since := "2025-04-03")]
theorem isCompl_iff_toSubmodule :
IsCompl N N' ↔ IsCompl (N : Submodule R M) (N' : Submodule R M) := isCompl_toSubmodule.symm
@[deprecated (since := "2024-12-30")] alias isCompl_iff_coe_toSubmodule := isCompl_iff_toSubmodule
@[simp] lemma iSupIndep_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep (fun i ↦ (N i : Submodule R M)) ↔ iSupIndep N := by
simp [iSupIndep_def, ← disjoint_toSubmodule]
@[deprecated iSupIndep_toSubmodule (since := "2025-04-03")]
theorem iSupIndep_iff_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep N ↔ iSupIndep fun i ↦ (N i : Submodule R M) := iSupIndep_toSubmodule.symm
@[deprecated (since := "2024-12-30")]
alias iSupIndep_iff_coe_toSubmodule := iSupIndep_iff_toSubmodule
@[deprecated (since := "2024-11-24")]
alias independent_iff_toSubmodule := iSupIndep_iff_toSubmodule
@[deprecated (since := "2024-12-30")]
alias independent_iff_coe_toSubmodule := independent_iff_toSubmodule
@[simp] lemma iSup_toSubmodule_eq_top {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, (N i : Submodule R M) = ⊤ ↔ ⨆ i, N i = ⊤ := by
rw [← iSup_toSubmodule, ← top_toSubmodule (L := L), toSubmodule_inj]
@[deprecated iSup_toSubmodule_eq_top (since := "2025-04-03")]
theorem iSup_eq_top_iff_toSubmodule {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, N i = ⊤ ↔ ⨆ i, (N i : Submodule R M) = ⊤ := iSup_toSubmodule_eq_top.symm
| @[deprecated (since := "2024-12-30")]
alias iSup_eq_top_iff_coe_toSubmodule := iSup_eq_top_iff_toSubmodule
instance : Add (LieSubmodule R L M) where add := max
| Mathlib/Algebra/Lie/Submodule.lean | 528 | 532 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Batteries.Data.List.Perm
import Mathlib.Data.List.OfFn
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.TakeWhile
import Mathlib.Order.Fin.Basic
/-!
# Sorting algorithms on lists
In this file we define `List.Sorted r l` to be an alias for `List.Pairwise r l`.
This alias is preferred in the case that `r` is a `<` or `≤`-like relation.
Then we define the sorting algorithm
`List.insertionSort` and prove its correctness.
-/
open List.Perm
universe u v
namespace List
/-!
### The predicate `List.Sorted`
-/
section Sorted
variable {α : Type u} {r : α → α → Prop} {a : α} {l : List α}
/-- `Sorted r l` is the same as `List.Pairwise r l`, preferred in the case that `r`
is a `<` or `≤`-like relation (transitive and antisymmetric or asymmetric) -/
def Sorted :=
@Pairwise
instance decidableSorted [DecidableRel r] (l : List α) : Decidable (Sorted r l) :=
List.instDecidablePairwise _
protected theorem Sorted.le_of_lt [Preorder α] {l : List α} (h : l.Sorted (· < ·)) :
l.Sorted (· ≤ ·) :=
h.imp le_of_lt
protected theorem Sorted.lt_of_le [PartialOrder α] {l : List α} (h₁ : l.Sorted (· ≤ ·))
(h₂ : l.Nodup) : l.Sorted (· < ·) :=
h₁.imp₂ (fun _ _ => lt_of_le_of_ne) h₂
protected theorem Sorted.ge_of_gt [Preorder α] {l : List α} (h : l.Sorted (· > ·)) :
l.Sorted (· ≥ ·) :=
h.imp le_of_lt
protected theorem Sorted.gt_of_ge [PartialOrder α] {l : List α} (h₁ : l.Sorted (· ≥ ·))
(h₂ : l.Nodup) : l.Sorted (· > ·) :=
h₁.imp₂ (fun _ _ => lt_of_le_of_ne) <| by simp_rw [ne_comm]; exact h₂
@[simp]
theorem sorted_nil : Sorted r [] :=
Pairwise.nil
theorem Sorted.of_cons : Sorted r (a :: l) → Sorted r l :=
Pairwise.of_cons
theorem Sorted.tail {r : α → α → Prop} {l : List α} (h : Sorted r l) : Sorted r l.tail :=
Pairwise.tail h
theorem rel_of_sorted_cons {a : α} {l : List α} : Sorted r (a :: l) → ∀ b ∈ l, r a b :=
rel_of_pairwise_cons
nonrec theorem Sorted.cons {r : α → α → Prop} [IsTrans α r] {l : List α} {a b : α}
(hab : r a b) (h : Sorted r (b :: l)) : Sorted r (a :: b :: l) :=
h.cons <| forall_mem_cons.2 ⟨hab, fun _ hx => _root_.trans hab <| rel_of_sorted_cons h _ hx⟩
theorem sorted_cons_cons {r : α → α → Prop} [IsTrans α r] {l : List α} {a b : α} :
Sorted r (b :: a :: l) ↔ r b a ∧ Sorted r (a :: l) := by
constructor
· intro h
exact ⟨rel_of_sorted_cons h _ mem_cons_self, h.of_cons⟩
· rintro ⟨h, ha⟩
exact ha.cons h
theorem Sorted.head!_le [Inhabited α] [Preorder α] {a : α} {l : List α} (h : Sorted (· < ·) l)
(ha : a ∈ l) : l.head! ≤ a := by
rw [← List.cons_head!_tail (List.ne_nil_of_mem ha)] at h ha
cases ha
· exact le_rfl
· exact le_of_lt (rel_of_sorted_cons h a (by assumption))
theorem Sorted.le_head! [Inhabited α] [Preorder α] {a : α} {l : List α} (h : Sorted (· > ·) l)
(ha : a ∈ l) : a ≤ l.head! := by
rw [← List.cons_head!_tail (List.ne_nil_of_mem ha)] at h ha
cases ha
· exact le_rfl
· exact le_of_lt (rel_of_sorted_cons h a (by assumption))
@[simp]
theorem sorted_cons {a : α} {l : List α} : Sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ Sorted r l :=
pairwise_cons
protected theorem Sorted.nodup {r : α → α → Prop} [IsIrrefl α r] {l : List α} (h : Sorted r l) :
Nodup l :=
Pairwise.nodup h
protected theorem Sorted.filter {l : List α} (f : α → Bool) (h : Sorted r l) :
Sorted r (filter f l) :=
h.sublist filter_sublist
theorem eq_of_perm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (hp : l₁ ~ l₂) (hs₁ : Sorted r l₁)
(hs₂ : Sorted r l₂) : l₁ = l₂ := by
induction hs₁ generalizing l₂ with
| nil => exact hp.nil_eq
| @cons a l₁ h₁ hs₁ IH =>
have : a ∈ l₂ := hp.subset mem_cons_self
rcases append_of_mem this with ⟨u₂, v₂, rfl⟩
have hp' := (perm_cons a).1 (hp.trans perm_middle)
obtain rfl := IH hp' (hs₂.sublist <| by simp)
change a :: u₂ ++ v₂ = u₂ ++ ([a] ++ v₂)
rw [← append_assoc]
congr
have : ∀ x ∈ u₂, x = a := fun x m =>
antisymm ((pairwise_append.1 hs₂).2.2 _ m a mem_cons_self) (h₁ _ (by simp [m]))
rw [(@eq_replicate_iff _ a (length u₂ + 1) (a :: u₂)).2,
(@eq_replicate_iff _ a (length u₂ + 1) (u₂ ++ [a])).2] <;>
constructor <;>
simp [iff_true_intro this, or_comm]
theorem Sorted.eq_of_mem_iff [IsAntisymm α r] [IsIrrefl α r] {l₁ l₂ : List α}
(h₁ : Sorted r l₁) (h₂ : Sorted r l₂) (h : ∀ a : α, a ∈ l₁ ↔ a ∈ l₂) : l₁ = l₂ :=
eq_of_perm_of_sorted ((perm_ext_iff_of_nodup h₁.nodup h₂.nodup).2 h) h₁ h₂
theorem sublist_of_subperm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (hp : l₁ <+~ l₂)
(hs₁ : l₁.Sorted r) (hs₂ : l₂.Sorted r) : l₁ <+ l₂ := by
let ⟨_, h, h'⟩ := hp
rwa [← eq_of_perm_of_sorted h (hs₂.sublist h') hs₁]
@[simp 1100] -- Higher priority shortcut lemma.
theorem sorted_singleton (a : α) : Sorted r [a] := by
simp
theorem sorted_lt_range (n : ℕ) : Sorted (· < ·) (range n) := by
rw [Sorted, pairwise_iff_get]
simp
theorem sorted_replicate (n : ℕ) (a : α) : Sorted r (replicate n a) ↔ n ≤ 1 ∨ r a a :=
pairwise_replicate
theorem sorted_le_replicate (n : ℕ) (a : α) [Preorder α] : Sorted (· ≤ ·) (replicate n a) := by
simp [sorted_replicate]
theorem sorted_le_range (n : ℕ) : Sorted (· ≤ ·) (range n) :=
(sorted_lt_range n).le_of_lt
lemma sorted_lt_range' (a b) {s} (hs : s ≠ 0) :
Sorted (· < ·) (range' a b s) := by
induction b generalizing a with
| zero => simp
| succ n ih =>
rw [List.range'_succ]
refine List.sorted_cons.mpr ⟨fun b hb ↦ ?_, @ih (a + s)⟩
exact lt_of_lt_of_le (Nat.lt_add_of_pos_right (Nat.zero_lt_of_ne_zero hs))
(List.left_le_of_mem_range' hb)
lemma sorted_le_range' (a b s) :
Sorted (· ≤ ·) (range' a b s) := by
by_cases hs : s ≠ 0
· exact (sorted_lt_range' a b hs).le_of_lt
· rw [ne_eq, Decidable.not_not] at hs
simpa [hs] using sorted_le_replicate b a
theorem Sorted.rel_get_of_lt {l : List α} (h : l.Sorted r) {a b : Fin l.length} (hab : a < b) :
r (l.get a) (l.get b) :=
List.pairwise_iff_get.1 h _ _ hab
theorem Sorted.rel_get_of_le [IsRefl α r] {l : List α} (h : l.Sorted r) {a b : Fin l.length}
(hab : a ≤ b) : r (l.get a) (l.get b) := by
obtain rfl | hlt := Fin.eq_or_lt_of_le hab; exacts [refl _, h.rel_get_of_lt hlt]
theorem Sorted.rel_of_mem_take_of_mem_drop {l : List α} (h : List.Sorted r l) {k : ℕ} {x y : α}
(hx : x ∈ List.take k l) (hy : y ∈ List.drop k l) : r x y := by
obtain ⟨iy, hiy, rfl⟩ := getElem_of_mem hy
obtain ⟨ix, hix, rfl⟩ := getElem_of_mem hx
rw [getElem_take, getElem_drop]
rw [length_take] at hix
exact h.rel_get_of_lt (Nat.lt_add_right _ (Nat.lt_min.mp hix).left)
/--
If a list is sorted with respect to a decidable relation,
then it is sorted with respect to the corresponding Bool-valued relation.
-/
theorem Sorted.decide [DecidableRel r] (l : List α) (h : Sorted r l) :
Sorted (fun a b => decide (r a b) = true) l := by
refine h.imp fun {a b} h => by simpa using h
end Sorted
section Monotone
variable {n : ℕ} {α : Type u} {f : Fin n → α}
open scoped Relator in
theorem sorted_ofFn_iff {r : α → α → Prop} : (ofFn f).Sorted r ↔ ((· < ·) ⇒ r) f f := by
simp_rw [Sorted, pairwise_iff_get, get_ofFn, Relator.LiftFun]
exact Iff.symm (Fin.rightInverse_cast _).surjective.forall₂
variable [Preorder α]
/-- The list `List.ofFn f` is strictly sorted with respect to `(· ≤ ·)` if and only if `f` is
strictly monotone. -/
@[simp] theorem sorted_lt_ofFn_iff : (ofFn f).Sorted (· < ·) ↔ StrictMono f := sorted_ofFn_iff
/-- The list `List.ofFn f` is strictly sorted with respect to `(· ≥ ·)` if and only if `f` is
strictly antitone. -/
@[simp] theorem sorted_gt_ofFn_iff : (ofFn f).Sorted (· > ·) ↔ StrictAnti f := sorted_ofFn_iff
/-- The list `List.ofFn f` is sorted with respect to `(· ≤ ·)` if and only if `f` is monotone. -/
@[simp] theorem sorted_le_ofFn_iff : (ofFn f).Sorted (· ≤ ·) ↔ Monotone f :=
sorted_ofFn_iff.trans monotone_iff_forall_lt.symm
/-- The list obtained from a monotone tuple is sorted. -/
alias ⟨_, _root_.Monotone.ofFn_sorted⟩ := sorted_le_ofFn_iff
/-- The list `List.ofFn f` is sorted with respect to `(· ≥ ·)` if and only if `f` is antitone. -/
@[simp] theorem sorted_ge_ofFn_iff : (ofFn f).Sorted (· ≥ ·) ↔ Antitone f :=
sorted_ofFn_iff.trans antitone_iff_forall_lt.symm
/-- The list obtained from an antitone tuple is sorted. -/
alias ⟨_, _root_.Antitone.ofFn_sorted⟩ := sorted_ge_ofFn_iff
end Monotone
lemma Sorted.filterMap {α β : Type*} {p : α → Option β} {l : List α}
{r : α → α → Prop} {r' : β → β → Prop} (hl : l.Sorted r)
(hp : ∀ (a b : α) (c d : β), p a = some c → p b = some d → r a b → r' c d) :
(l.filterMap p).Sorted r' := by
induction l with
| nil => simp
| cons a l ih =>
rw [List.filterMap_cons]
cases ha : p a with
| none =>
exact ih (List.sorted_cons.mp hl).right
| some b =>
rw [List.sorted_cons]
refine ⟨fun x hx ↦ ?_, ih (List.sorted_cons.mp hl).right⟩
obtain ⟨u, hu, hu'⟩ := List.mem_filterMap.mp hx
exact hp a u b x ha hu' <| (List.sorted_cons.mp hl).left u hu
end List
open List
namespace RelEmbedding
variable {α β : Type*} {ra : α → α → Prop} {rb : β → β → Prop}
@[simp]
theorem sorted_listMap (e : ra ↪r rb) {l : List α} : (l.map e).Sorted rb ↔ l.Sorted ra := by
simp [Sorted, pairwise_map, e.map_rel_iff]
@[simp]
theorem sorted_swap_listMap (e : ra ↪r rb) {l : List α} :
(l.map e).Sorted (Function.swap rb) ↔ l.Sorted (Function.swap ra) := by
simp [Sorted, pairwise_map, e.map_rel_iff]
end RelEmbedding
namespace OrderEmbedding
variable {α β : Type*} [Preorder α] [Preorder β]
@[simp]
theorem sorted_lt_listMap (e : α ↪o β) {l : List α} :
(l.map e).Sorted (· < ·) ↔ l.Sorted (· < ·) :=
e.ltEmbedding.sorted_listMap
@[simp]
theorem sorted_gt_listMap (e : α ↪o β) {l : List α} :
(l.map e).Sorted (· > ·) ↔ l.Sorted (· > ·) :=
e.ltEmbedding.sorted_swap_listMap
end OrderEmbedding
namespace RelIso
variable {α β : Type*} {ra : α → α → Prop} {rb : β → β → Prop}
@[simp]
theorem sorted_listMap (e : ra ≃r rb) {l : List α} : (l.map e).Sorted rb ↔ l.Sorted ra :=
e.toRelEmbedding.sorted_listMap
@[simp]
theorem sorted_swap_listMap (e : ra ≃r rb) {l : List α} :
(l.map e).Sorted (Function.swap rb) ↔ l.Sorted (Function.swap ra) :=
e.toRelEmbedding.sorted_swap_listMap
end RelIso
namespace OrderIso
variable {α β : Type*} [Preorder α] [Preorder β]
@[simp]
theorem sorted_lt_listMap (e : α ≃o β) {l : List α} :
(l.map e).Sorted (· < ·) ↔ l.Sorted (· < ·) :=
e.toOrderEmbedding.sorted_lt_listMap
@[simp]
theorem sorted_gt_listMap (e : α ≃o β) {l : List α} :
(l.map e).Sorted (· > ·) ↔ l.Sorted (· > ·) :=
e.toOrderEmbedding.sorted_gt_listMap
end OrderIso
namespace StrictMono
variable {α β : Type*} [LinearOrder α] [Preorder β] {f : α → β} {l : List α}
theorem sorted_le_listMap (hf : StrictMono f) :
(l.map f).Sorted (· ≤ ·) ↔ l.Sorted (· ≤ ·) :=
(OrderEmbedding.ofStrictMono f hf).sorted_listMap
theorem sorted_ge_listMap (hf : StrictMono f) :
(l.map f).Sorted (· ≥ ·) ↔ l.Sorted (· ≥ ·) :=
(OrderEmbedding.ofStrictMono f hf).sorted_swap_listMap
theorem sorted_lt_listMap (hf : StrictMono f) :
(l.map f).Sorted (· < ·) ↔ l.Sorted (· < ·) :=
(OrderEmbedding.ofStrictMono f hf).sorted_lt_listMap
theorem sorted_gt_listMap (hf : StrictMono f) :
(l.map f).Sorted (· > ·) ↔ l.Sorted (· > ·) :=
(OrderEmbedding.ofStrictMono f hf).sorted_gt_listMap
end StrictMono
namespace StrictAnti
variable {α β : Type*} [LinearOrder α] [Preorder β] {f : α → β} {l : List α}
theorem sorted_le_listMap (hf : StrictAnti f) :
(l.map f).Sorted (· ≤ ·) ↔ l.Sorted (· ≥ ·) :=
hf.dual_right.sorted_ge_listMap
theorem sorted_ge_listMap (hf : StrictAnti f) :
(l.map f).Sorted (· ≥ ·) ↔ l.Sorted (· ≤ ·) :=
hf.dual_right.sorted_le_listMap
theorem sorted_lt_listMap (hf : StrictAnti f) :
(l.map f).Sorted (· < ·) ↔ l.Sorted (· > ·) :=
hf.dual_right.sorted_gt_listMap
theorem sorted_gt_listMap (hf : StrictAnti f) :
(l.map f).Sorted (· > ·) ↔ l.Sorted (· < ·) :=
hf.dual_right.sorted_lt_listMap
end StrictAnti
namespace List
section sort
variable {α : Type u} {β : Type v} (r : α → α → Prop) (s : β → β → Prop)
variable [DecidableRel r] [DecidableRel s]
local infixl:50 " ≼ " => r
local infixl:50 " ≼ " => s
/-! ### Insertion sort -/
section InsertionSort
/-- `orderedInsert a l` inserts `a` into `l` at such that
`orderedInsert a l` is sorted if `l` is. -/
@[simp]
def orderedInsert (a : α) : List α → List α
| [] => [a]
| b :: l => if a ≼ b then a :: b :: l else b :: orderedInsert a l
theorem orderedInsert_of_le {a b : α} (l : List α) (h : a ≼ b) :
orderedInsert r a (b :: l) = a :: b :: l :=
dif_pos h
/-- `insertionSort l` returns `l` sorted using the insertion sort algorithm. -/
@[simp]
def insertionSort : List α → List α
| [] => []
| b :: l => orderedInsert r b (insertionSort l)
-- A quick check that insertionSort is stable:
example :
insertionSort (fun m n => m / 10 ≤ n / 10) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12] =
[5, 7, 2, 17, 12, 27, 23, 43, 95, 98, 221, 567] := rfl
@[simp]
theorem orderedInsert_nil (a : α) : [].orderedInsert r a = [a] :=
rfl
theorem orderedInsert_length : ∀ (L : List α) (a : α), (L.orderedInsert r a).length = L.length + 1
| [], _ => rfl
| hd :: tl, a => by
dsimp [orderedInsert]
split_ifs <;> simp [orderedInsert_length tl]
/-- An alternative definition of `orderedInsert` using `takeWhile` and `dropWhile`. -/
theorem orderedInsert_eq_take_drop (a : α) :
∀ l : List α,
l.orderedInsert r a = (l.takeWhile fun b => ¬a ≼ b) ++ a :: l.dropWhile fun b => ¬a ≼ b
| [] => rfl
| b :: l => by
dsimp only [orderedInsert]
split_ifs with h <;> simp [takeWhile, dropWhile, *, orderedInsert_eq_take_drop a l]
theorem insertionSort_cons_eq_take_drop (a : α) (l : List α) :
insertionSort r (a :: l) =
((insertionSort r l).takeWhile fun b => ¬a ≼ b) ++
a :: (insertionSort r l).dropWhile fun b => ¬a ≼ b :=
orderedInsert_eq_take_drop r a _
@[simp]
theorem mem_orderedInsert {a b : α} {l : List α} :
a ∈ orderedInsert r b l ↔ a = b ∨ a ∈ l :=
match l with
| [] => by simp [orderedInsert]
| x :: xs => by
rw [orderedInsert]
split_ifs
· simp [orderedInsert]
· rw [mem_cons, mem_cons, mem_orderedInsert, or_left_comm]
theorem map_orderedInsert (f : α → β) (l : List α) (x : α)
(hl₁ : ∀ a ∈ l, a ≼ x ↔ f a ≼ f x) (hl₂ : ∀ a ∈ l, x ≼ a ↔ f x ≼ f a) :
(l.orderedInsert r x).map f = (l.map f).orderedInsert s (f x) := by
induction l with
| nil => simp
| cons x xs ih =>
rw [List.forall_mem_cons] at hl₁ hl₂
simp only [List.map, List.orderedInsert, ← hl₁.1, ← hl₂.1]
split_ifs
· rw [List.map, List.map]
· rw [List.map, ih (fun _ ha => hl₁.2 _ ha) (fun _ ha => hl₂.2 _ ha)]
section Correctness
open Perm
theorem perm_orderedInsert (a) : ∀ l : List α, orderedInsert r a l ~ a :: l
| [] => Perm.refl _
| b :: l => by
by_cases h : a ≼ b
· simp [orderedInsert, h]
· simpa [orderedInsert, h] using ((perm_orderedInsert a l).cons _).trans (Perm.swap _ _ _)
theorem orderedInsert_count [DecidableEq α] (L : List α) (a b : α) :
count a (L.orderedInsert r b) = count a L + if b = a then 1 else 0 := by
rw [(L.perm_orderedInsert r b).count_eq, count_cons]
simp
theorem perm_insertionSort : ∀ l : List α, insertionSort r l ~ l
| [] => Perm.nil
| b :: l => by
simpa [insertionSort] using (perm_orderedInsert _ _ _).trans ((perm_insertionSort l).cons b)
@[simp]
theorem mem_insertionSort {l : List α} {x : α} : x ∈ l.insertionSort r ↔ x ∈ l :=
(perm_insertionSort r l).mem_iff
@[simp]
theorem length_insertionSort (l : List α) : (insertionSort r l).length = l.length :=
(perm_insertionSort r _).length_eq
theorem insertionSort_cons {a : α} {l : List α} (h : ∀ b ∈ l, r a b) :
insertionSort r (a :: l) = a :: insertionSort r l := by
rw [insertionSort]
cases hi : insertionSort r l with
| nil => rfl
| cons b m =>
rw [orderedInsert_of_le]
apply h b <| (mem_insertionSort r).1 _
rw [hi]
exact mem_cons_self
theorem map_insertionSort (f : α → β) (l : List α) (hl : ∀ a ∈ l, ∀ b ∈ l, a ≼ b ↔ f a ≼ f b) :
(l.insertionSort r).map f = (l.map f).insertionSort s := by
induction l with
| nil => simp
| cons x xs ih =>
simp_rw [List.forall_mem_cons, forall_and] at hl
simp_rw [List.map, List.insertionSort]
rw [List.map_orderedInsert _ s, ih hl.2.2]
· simpa only [mem_insertionSort] using hl.2.1
· simpa only [mem_insertionSort] using hl.1.2
variable {r}
/-- If `l` is already `List.Sorted` with respect to `r`, then `insertionSort` does not change
it. -/
theorem Sorted.insertionSort_eq : ∀ {l : List α}, Sorted r l → insertionSort r l = l
| [], _ => rfl
| [_], _ => rfl
| a :: b :: l, h => by
| rw [insertionSort, Sorted.insertionSort_eq, orderedInsert, if_pos]
exacts [rel_of_sorted_cons h _ mem_cons_self, h.tail]
/-- For a reflexive relation, insert then erasing is the identity. -/
theorem erase_orderedInsert [DecidableEq α] [IsRefl α r] (x : α) (xs : List α) :
(xs.orderedInsert r x).erase x = xs := by
rw [orderedInsert_eq_take_drop, erase_append_right, List.erase_cons_head,
takeWhile_append_dropWhile]
intro h
| Mathlib/Data/List/Sort.lean | 504 | 512 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInf₂ fun i hi => ?_
calc
edist x y ≤ edist x i + edist i y := edist_triangle _ _ _
_ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff]
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_
have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 :=
ENNReal.lt_add_right h.ne ε0.ne'
obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ :=
infEdist_lt_iff.mp this
obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0
calc
infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves]
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 :=
⟨fun h => by
rw [← infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by
rw [← mem_closure_iff_infEdist_zero, h.closure_eq]
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x E ↔ x ∉ closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x (closure E) ↔ x ∉ closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) :
∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by
rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩
exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩
theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y
_ ≤ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
/-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
@[to_additive (attr := simp)]
theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) :
infEdist (c • x) (c • s) = infEdist x s :=
infEdist_image (isometry_smul _ _)
theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) :
∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by
obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one
let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n)
have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by
by_contra h
have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne'
exact this (infEdist_zero_of_mem h)
refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩
· show ⋃ n, F n = U
refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_
have : ¬x ∈ Uᶜ := by simpa using hx
rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this
have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this
have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) :=
ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one
rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩
simp only [mem_iUnion, mem_Ici, mem_preimage]
exact ⟨n, hn.le⟩
show Monotone F
intro m n hmn x hx
simp only [F, mem_Ici, mem_preimage] at hx ⊢
apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx
theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) :
∃ y ∈ s, infEdist x s = edist x y := by
have A : Continuous fun y => edist x y := continuous_const.edist continuous_id
obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn
exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩
theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) :
∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by
rcases s.eq_empty_or_nonempty with (rfl | hne)
· use 1
simp
obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn
have : 0 < infEdist x t :=
pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩
exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩
end InfEdist
/-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/
/-- The Hausdorff edistance between two sets is the smallest `r` such that each set
is contained in the `r`-neighborhood of the other one -/
irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ :=
(⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s
section HausdorffEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x : α} {s t u : Set α} {Φ : α → β}
/-- The Hausdorff edistance of a set to itself vanishes. -/
@[simp]
theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by
simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero]
exact fun x hx => infEdist_zero_of_mem hx
/-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/
theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by
simp only [hausdorffEdist_def]; apply sup_comm
/-- Bounding the Hausdorff edistance by bounding the edistance of any point
in each set to the other set -/
theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r)
(H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by
simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff]
exact ⟨H1, H2⟩
/-- Bounding the Hausdorff edistance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r)
(H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by
refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_)
· rcases H1 x xs with ⟨y, yt, hy⟩
exact le_trans (infEdist_le_edist_of_mem yt) hy
· rcases H2 x xt with ⟨y, ys, hy⟩
exact le_trans (infEdist_le_edist_of_mem ys) hy
/-- The distance to a set is controlled by the Hausdorff distance. -/
theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by
rw [hausdorffEdist_def]
refine le_trans ?_ le_sup_left
exact le_iSup₂ (α := ℝ≥0∞) x h
/-- If the Hausdorff distance is `< r`, then any point in one of the sets has
a corresponding point at distance `< r` in the other set. -/
theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) :
∃ y ∈ t, edist x y < r :=
infEdist_lt_iff.mp <|
calc
infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h
_ < r := H
/-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance
between `s` and `t`. -/
theorem infEdist_le_infEdist_add_hausdorffEdist :
infEdist x t ≤ infEdist x s + hausdorffEdist s t :=
ENNReal.le_of_forall_pos_le_add fun ε εpos h => by
have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x s < infEdist x s + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0
obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this
have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0
obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ :=
exists_edist_lt_of_hausdorffEdist_lt ys this
calc
infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le
_ = infEdist x s + hausdorffEdist s t + ε := by
simp [ENNReal.add_halves, add_comm, add_left_comm]
/-- The Hausdorff edistance is invariant under isometries. -/
theorem hausdorffEdist_image (h : Isometry Φ) :
hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by
simp only [hausdorffEdist_def, iSup_image, infEdist_image h]
/-- The Hausdorff distance is controlled by the diameter of the union. -/
theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) :
hausdorffEdist s t ≤ diam (s ∪ t) := by
rcases hs with ⟨x, xs⟩
rcases ht with ⟨y, yt⟩
refine hausdorffEdist_le_of_mem_edist ?_ ?_
· intro z hz
exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩
· intro z hz
exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩
/-- The Hausdorff distance satisfies the triangle inequality. -/
theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by
rw [hausdorffEdist_def]
simp only [sup_le_iff, iSup_le_iff]
constructor
· show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xs =>
calc
infEdist x u ≤ infEdist x t + hausdorffEdist t u :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist s t + hausdorffEdist t u :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _
· show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xu =>
calc
infEdist x s ≤ infEdist x t + hausdorffEdist t s :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist u t + hausdorffEdist t s :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _
_ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm]
/-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/
theorem hausdorffEdist_zero_iff_closure_eq_closure :
hausdorffEdist s t = 0 ↔ closure s = closure t := by
simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def,
← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff]
/-- The Hausdorff edistance between a set and its closure vanishes. -/
@[simp]
theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure]
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by
refine le_antisymm ?_ ?_
· calc
_ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle
_ = hausdorffEdist s t := by simp [hausdorffEdist_comm]
· calc
_ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle
_ = hausdorffEdist (closure s) t := by simp
|
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by
simp [@hausdorffEdist_comm _ _ s _]
/-- The Hausdorff edistance between sets or their closures is the same. -/
theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by
simp
/-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/
theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) :
hausdorffEdist s t = 0 ↔ s = t := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq]
/-- The Haudorff edistance to the empty set is infinite. -/
theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by
rcases ne with ⟨x, xs⟩
have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 374 | 392 |
/-
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, Kim Morrison
-/
import Mathlib.Algebra.Group.Indicator
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Tactic.FastInstance
import Mathlib.Algebra.Group.Equiv.Defs
/-!
# Type of functions with finite support
For any type `α` and any type `M` with zero, we define the type `Finsupp α M` (notation: `α →₀ M`)
of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere
on `α` except on a finite set.
Functions with finite support are used (at least) in the following parts of the library:
* `MonoidAlgebra R M` and `AddMonoidAlgebra R M` are defined as `M →₀ R`;
* polynomials and multivariate polynomials are defined as `AddMonoidAlgebra`s, hence they use
`Finsupp` under the hood;
* the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to
define linearly independent family `LinearIndependent`) is defined as a map
`Finsupp.linearCombination : (ι → M) → (ι →₀ R) →ₗ[R] M`.
Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined
in a different way in the library:
* `Multiset α ≃+ α →₀ ℕ`;
* `FreeAbelianGroup α ≃+ α →₀ ℤ`.
Most of the theory assumes that the range is a commutative additive monoid. This gives us the big
sum operator as a powerful way to construct `Finsupp` elements, which is defined in
`Mathlib.Algebra.BigOperators.Finsupp.Basic`.
Many constructions based on `α →₀ M` are `def`s rather than `abbrev`s to avoid reusing unwanted type
class instances. E.g., `MonoidAlgebra`, `AddMonoidAlgebra`, and types based on these two have
non-pointwise multiplication.
## Main declarations
* `Finsupp`: The type of finitely supported functions from `α` to `β`.
* `Finsupp.onFinset`: The restriction of a function to a `Finset` as a `Finsupp`.
* `Finsupp.mapRange`: Composition of a `ZeroHom` with a `Finsupp`.
* `Finsupp.embDomain`: Maps the domain of a `Finsupp` by an embedding.
* `Finsupp.zipWith`: Postcomposition of two `Finsupp`s with a function `f` such that `f 0 0 = 0`.
## Notations
This file adds `α →₀ M` as a global notation for `Finsupp α M`.
We also use the following convention for `Type*` variables in this file
* `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `Finsupp`
somewhere in the statement;
* `ι` : an auxiliary index type;
* `M`, `M'`, `N`, `P`: types with `Zero` or `(Add)(Comm)Monoid` structure; `M` is also used
for a (semi)module over a (semi)ring.
* `G`, `H`: groups (commutative or not, multiplicative or additive);
* `R`, `S`: (semi)rings.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* Expand the list of definitions and important lemmas to the module docstring.
-/
assert_not_exists CompleteLattice Submonoid
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
/-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that
`f x = 0` for all but finitely many `x`. -/
structure Finsupp (α : Type*) (M : Type*) [Zero M] where
/-- The support of a finitely supported function (aka `Finsupp`). -/
support : Finset α
/-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/
toFun : α → M
/-- The witness that the support of a `Finsupp` is indeed the exact locus where its
underlying function is nonzero. -/
mem_support_toFun : ∀ a, a ∈ support ↔ toFun a ≠ 0
@[inherit_doc]
infixr:25 " →₀ " => Finsupp
namespace Finsupp
/-! ### Basic declarations about `Finsupp` -/
section Basic
variable [Zero M]
instance instFunLike : FunLike (α →₀ M) α M :=
⟨toFun, by
rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g)
congr
ext a
exact (hf _).trans (hg _).symm⟩
@[ext]
theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext _ _ h
lemma ne_iff {f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff
@[simp, norm_cast]
theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f :=
rfl
instance instZero : Zero (α →₀ M) :=
⟨⟨∅, 0, fun _ => ⟨fun h ↦ (not_mem_empty _ h).elim, fun H => (H rfl).elim⟩⟩⟩
@[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl
theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 :=
rfl
@[simp]
theorem support_zero : (0 : α →₀ M).support = ∅ :=
rfl
instance instInhabited : Inhabited (α →₀ M) :=
⟨0⟩
@[simp]
theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0 :=
@(f.mem_support_toFun)
@[simp, norm_cast]
theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support :=
Set.ext fun _x => mem_support_iff.symm
theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 :=
not_iff_comm.1 mem_support_iff.symm
@[simp, norm_cast]
theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq]
theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x :=
⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ =>
ext fun a => by
classical
exact if h : a ∈ f.support then h₂ a h else by
have hf : f a = 0 := not_mem_support_iff.1 h
have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h
rw [hf, hg]⟩
@[simp]
theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
mod_cast @Function.support_eq_empty_iff _ _ _ f
theorem support_nonempty_iff {f : α →₀ M} : f.support.Nonempty ↔ f ≠ 0 := by
simp only [Finsupp.support_eq_empty, Finset.nonempty_iff_ne_empty, Ne]
theorem card_support_eq_zero {f : α →₀ M} : #f.support = 0 ↔ f = 0 := by simp
instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g =>
decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm
theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) :=
f.fun_support_eq.symm ▸ f.support.finite_toSet
theorem support_subset_iff {s : Set α} {f : α →₀ M} :
↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by
simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm
/-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`.
(All functions on a finite type are finitely supported.) -/
@[simps]
def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where
toFun := (⇑)
invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _
left_inv _f := ext fun _x => rfl
right_inv _f := rfl
@[simp]
theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f :=
equivFunOnFinite.symm_apply_apply f
@[simp]
lemma coe_equivFunOnFinite_symm {α} [Finite α] (f : α → M) : ⇑(equivFunOnFinite.symm f) = f := rfl
/--
If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`.
| -/
@[simps!]
| Mathlib/Data/Finsupp/Defs.lean | 203 | 204 |
/-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.Enum
import Mathlib.Tactic.TFAE
import Mathlib.Topology.Order.Monotone
/-!
### Topology of ordinals
We prove some miscellaneous results involving the order topology of ordinals.
### Main results
* `Ordinal.isClosed_iff_iSup` / `Ordinal.isClosed_iff_bsup`: A set of ordinals is closed iff it's
closed under suprema.
* `Ordinal.isNormal_iff_strictMono_and_continuous`: A characterization of normal ordinal
functions.
* `Ordinal.enumOrd_isNormal_iff_isClosed`: The function enumerating the ordinals of a set is
normal iff the set is closed.
-/
noncomputable section
universe u v
open Cardinal Order Topology
namespace Ordinal
variable {s : Set Ordinal.{u}} {a : Ordinal.{u}}
instance : TopologicalSpace Ordinal.{u} := Preorder.topology Ordinal.{u}
instance : OrderTopology Ordinal.{u} := ⟨rfl⟩
theorem isOpen_singleton_iff : IsOpen ({a} : Set Ordinal) ↔ ¬IsLimit a := by
refine ⟨fun h ha => ?_, fun ha => ?_⟩
· obtain ⟨b, c, hbc, hbc'⟩ :=
(mem_nhds_iff_exists_Ioo_subset' ⟨0, ha.pos⟩ ⟨_, lt_succ a⟩).1
(h.mem_nhds rfl)
have hba := ha.succ_lt hbc.1
exact hba.ne (hbc' ⟨lt_succ b, hba.trans hbc.2⟩)
· rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha')
· rw [← bot_eq_zero, ← Set.Iic_bot, ← Iio_succ]
exact isOpen_Iio
· rw [← Set.Icc_self, Icc_succ_left, ← Ioo_succ_right]
exact isOpen_Ioo
· exact (ha ha').elim
@[deprecated SuccOrder.nhdsGT (since := "2025-01-05")]
protected theorem nhdsGT (a : Ordinal) : 𝓝[>] a = ⊥ := SuccOrder.nhdsGT
@[deprecated (since := "2024-12-22")] alias nhds_right' := Ordinal.nhdsGT
@[deprecated SuccOrder.nhdsLT_eq_nhdsNE (since := "2025-01-05")]
theorem nhdsLT_eq_nhdsNE (a : Ordinal) : 𝓝[<] a = 𝓝[≠] a :=
SuccOrder.nhdsLT_eq_nhdsNE a
@[deprecated (since := "2024-12-22")] alias nhds_left'_eq_nhds_ne := nhdsLT_eq_nhdsNE
@[deprecated SuccOrder.nhdsLE_eq_nhds (since := "2025-01-05")]
theorem nhdsLE_eq_nhds (a : Ordinal) : 𝓝[≤] a = 𝓝 a :=
SuccOrder.nhdsLE_eq_nhds a
@[deprecated (since := "2024-12-22")] alias nhds_left_eq_nhds := nhdsLE_eq_nhds
@[deprecated SuccOrder.hasBasis_nhds_Ioc_of_exists_lt (since := "2025-01-05")]
theorem hasBasis_nhds_Ioc (h : a ≠ 0) : (𝓝 a).HasBasis (· < a) (Set.Ioc · a) :=
SuccOrder.hasBasis_nhds_Ioc_of_exists_lt ⟨0, Ordinal.pos_iff_ne_zero.2 h⟩
@[deprecated (since := "2024-12-22")] alias nhdsBasis_Ioc := hasBasis_nhds_Ioc
-- todo: generalize to a `SuccOrder`
theorem nhds_eq_pure : 𝓝 a = pure a ↔ ¬IsLimit a :=
(isOpen_singleton_iff_nhds_eq_pure _).symm.trans isOpen_singleton_iff
-- todo: generalize `Ordinal.IsLimit` and this lemma to a `SuccOrder`
theorem isOpen_iff : IsOpen s ↔ ∀ o ∈ s, IsLimit o → ∃ a < o, Set.Ioo a o ⊆ s := by
refine isOpen_iff_mem_nhds.trans <| forall₂_congr fun o ho => ?_
by_cases ho' : IsLimit o
· simp only [(SuccOrder.hasBasis_nhds_Ioc_of_exists_lt ⟨0, ho'.pos⟩).mem_iff, ho', true_implies]
refine exists_congr fun a => and_congr_right fun ha => ?_
simp only [← Set.Ioo_insert_right ha, Set.insert_subset_iff, ho, true_and]
· simp [nhds_eq_pure.2 ho', ho, ho']
open List Set in
theorem mem_closure_tfae (a : Ordinal.{u}) (s : Set Ordinal) :
TFAE [a ∈ closure s,
a ∈ closure (s ∩ Iic a),
(s ∩ Iic a).Nonempty ∧ sSup (s ∩ Iic a) = a,
∃ t, t ⊆ s ∧ t.Nonempty ∧ BddAbove t ∧ sSup t = a,
∃ (o : Ordinal.{u}), o ≠ 0 ∧ ∃ (f : ∀ x < o, Ordinal),
(∀ x hx, f x hx ∈ s) ∧ bsup.{u, u} o f = a,
∃ (ι : Type u), Nonempty ι ∧ ∃ f : ι → Ordinal, (∀ i, f i ∈ s) ∧ ⨆ i, f i = a] := by
tfae_have 1 → 2 := by
simpa only [mem_closure_iff_nhdsWithin_neBot, inter_comm s, nhdsWithin_inter',
SuccOrder.nhdsLE_eq_nhds] using id
tfae_have 2 → 3
| h => by
rcases (s ∩ Iic a).eq_empty_or_nonempty with he | hne
· simp [he] at h
· refine ⟨hne, (isLUB_of_mem_closure ?_ h).csSup_eq hne⟩
exact fun x hx => hx.2
tfae_have 3 → 4
| h => ⟨_, inter_subset_left, h.1, bddAbove_Iic.mono inter_subset_right, h.2⟩
tfae_have 4 → 5 := by
rintro ⟨t, hts, hne, hbdd, rfl⟩
have hlub : IsLUB t (sSup t) := isLUB_csSup hne hbdd
let ⟨y, hyt⟩ := hne
classical
refine ⟨succ (sSup t), succ_ne_zero _, fun x _ => if x ∈ t then x else y, fun x _ => ?_, ?_⟩
· simp only
split_ifs with h <;> exact hts ‹_›
· refine le_antisymm (bsup_le fun x _ => ?_) (csSup_le hne fun x hx => ?_)
· split_ifs <;> exact hlub.1 ‹_›
· refine (if_pos hx).symm.trans_le (le_bsup _ _ <| (hlub.1 hx).trans_lt (lt_succ _))
tfae_have 5 → 6 := by
rintro ⟨o, h₀, f, hfs, rfl⟩
exact ⟨_, toType_nonempty_iff_ne_zero.2 h₀, familyOfBFamily o f, fun _ => hfs _ _, rfl⟩
tfae_have 6 → 1 := by
rintro ⟨ι, hne, f, hfs, rfl⟩
exact closure_mono (range_subset_iff.2 hfs) <| csSup_mem_closure (range_nonempty f)
(bddAbove_range.{u, u} f)
tfae_finish
theorem mem_closure_iff_iSup :
a ∈ closure s ↔
∃ (ι : Type u) (_ : Nonempty ι) (f : ι → Ordinal), (∀ i, f i ∈ s) ∧ ⨆ i, f i = a := by
apply ((mem_closure_tfae a s).out 0 5).trans
simp_rw [exists_prop]
theorem mem_iff_iSup_of_isClosed (hs : IsClosed s) :
a ∈ s ↔ ∃ (ι : Type u) (_hι : Nonempty ι) (f : ι → Ordinal),
(∀ i, f i ∈ s) ∧ ⨆ i, f i = a := by
rw [← mem_closure_iff_iSup, hs.closure_eq]
theorem mem_closure_iff_bsup :
a ∈ closure s ↔
∃ (o : Ordinal) (_ho : o ≠ 0) (f : ∀ a < o, Ordinal),
(∀ i hi, f i hi ∈ s) ∧ bsup.{u, u} o f = a := by
apply ((mem_closure_tfae a s).out 0 4).trans
simp_rw [exists_prop]
theorem mem_closed_iff_bsup (hs : IsClosed s) :
a ∈ s ↔
∃ (o : Ordinal) (_ho : o ≠ 0) (f : ∀ a < o, Ordinal),
(∀ i hi, f i hi ∈ s) ∧ bsup.{u, u} o f = a := by
rw [← mem_closure_iff_bsup, hs.closure_eq]
theorem isClosed_iff_iSup :
IsClosed s ↔
∀ {ι : Type u}, Nonempty ι → ∀ f : ι → Ordinal, (∀ i, f i ∈ s) → ⨆ i, f i ∈ s := by
use fun hs ι hι f hf => (mem_iff_iSup_of_isClosed hs).2 ⟨ι, hι, f, hf, rfl⟩
rw [← closure_subset_iff_isClosed]
intro h x hx
rcases mem_closure_iff_iSup.1 hx with ⟨ι, hι, f, hf, rfl⟩
exact h hι f hf
| theorem isClosed_iff_bsup :
IsClosed s ↔
∀ {o : Ordinal}, o ≠ 0 → ∀ f : ∀ a < o, Ordinal,
(∀ i hi, f i hi ∈ s) → bsup.{u, u} o f ∈ s := by
rw [isClosed_iff_iSup]
refine ⟨fun H o ho f hf => H (toType_nonempty_iff_ne_zero.2 ho) _ ?_, fun H ι hι f hf => ?_⟩
· exact fun i => hf _ _
· rw [← Ordinal.sup, ← bsup_eq_sup]
apply H (type_ne_zero_iff_nonempty.2 hι)
exact fun i hi => hf _
| Mathlib/SetTheory/Ordinal/Topology.lean | 162 | 171 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Set.Sigma
import Mathlib.Order.CompleteLattice.Finset
/-!
# Finite sets in a sigma type
This file defines a few `Finset` constructions on `Σ i, α i`.
## Main declarations
* `Finset.sigma`: Given a finset `s` in `ι` and finsets `t i` in each `α i`, `s.sigma t` is the
finset of the dependent sum `Σ i, α i`
* `Finset.sigmaLift`: Lifts maps `α i → β i → Finset (γ i)` to a map
`Σ i, α i → Σ i, β i → Finset (Σ i, γ i)`.
## TODO
`Finset.sigmaLift` can be generalized to any alternative functor. But to make the generalization
worth it, we must first refactor the functor library so that the `alternative` instance for `Finset`
is computable and universe-polymorphic.
-/
open Function Multiset
variable {ι : Type*}
namespace Finset
section Sigma
variable {α : ι → Type*} {β : Type*} (s s₁ s₂ : Finset ι) (t t₁ t₂ : ∀ i, Finset (α i))
/-- `s.sigma t` is the finset of dependent pairs `⟨i, a⟩` such that `i ∈ s` and `a ∈ t i`. -/
protected def sigma : Finset (Σ i, α i) :=
⟨_, s.nodup.sigma fun i => (t i).nodup⟩
variable {s s₁ s₂ t t₁ t₂}
@[simp]
theorem mem_sigma {a : Σ i, α i} : a ∈ s.sigma t ↔ a.1 ∈ s ∧ a.2 ∈ t a.1 :=
Multiset.mem_sigma
@[simp, norm_cast]
theorem coe_sigma (s : Finset ι) (t : ∀ i, Finset (α i)) :
(s.sigma t : Set (Σ i, α i)) = (s : Set ι).sigma fun i ↦ (t i : Set (α i)) :=
Set.ext fun _ => mem_sigma
@[simp]
theorem sigma_nonempty : (s.sigma t).Nonempty ↔ ∃ i ∈ s, (t i).Nonempty := by simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.sigma_nonempty_of_exists_nonempty⟩ := sigma_nonempty
@[simp]
theorem sigma_eq_empty : s.sigma t = ∅ ↔ ∀ i ∈ s, t i = ∅ := by
simp only [← not_nonempty_iff_eq_empty, sigma_nonempty, not_exists, not_and]
@[mono]
theorem sigma_mono (hs : s₁ ⊆ s₂) (ht : ∀ i, t₁ i ⊆ t₂ i) : s₁.sigma t₁ ⊆ s₂.sigma t₂ :=
fun ⟨i, _⟩ h =>
let ⟨hi, ha⟩ := mem_sigma.1 h
mem_sigma.2 ⟨hs hi, ht i ha⟩
theorem pairwiseDisjoint_map_sigmaMk :
(s : Set ι).PairwiseDisjoint fun i => (t i).map (Embedding.sigmaMk i) := by
intro i _ j _ hij
rw [Function.onFun, disjoint_left]
simp_rw [mem_map, Function.Embedding.sigmaMk_apply]
rintro _ ⟨y, _, rfl⟩ ⟨z, _, hz'⟩
exact hij (congr_arg Sigma.fst hz'.symm)
@[simp]
theorem disjiUnion_map_sigma_mk :
s.disjiUnion (fun i => (t i).map (Embedding.sigmaMk i)) pairwiseDisjoint_map_sigmaMk =
s.sigma t :=
rfl
theorem sigma_eq_biUnion [DecidableEq (Σ i, α i)] (s : Finset ι) (t : ∀ i, Finset (α i)) :
s.sigma t = s.biUnion fun i => (t i).map <| Embedding.sigmaMk i := by
ext ⟨x, y⟩
simp [and_left_comm]
variable (s t) (f : (Σ i, α i) → β)
|
theorem sup_sigma [SemilatticeSup β] [OrderBot β] :
(s.sigma t).sup f = s.sup fun i => (t i).sup fun b => f ⟨i, b⟩ := by
simp only [le_antisymm_iff, Finset.sup_le_iff, mem_sigma, and_imp, Sigma.forall]
| Mathlib/Data/Finset/Sigma.lean | 91 | 94 |
/-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.FiniteMeasure
import Mathlib.MeasureTheory.Integral.Average
import Mathlib.MeasureTheory.Measure.Prod
/-!
# Probability measures
This file defines the type of probability measures on a given measurable space. When the underlying
space has a topology and the measurable space structure (sigma algebra) is finer than the Borel
sigma algebra, then the type of probability measures is equipped with the topology of convergence
in distribution (weak convergence of measures). The topology of convergence in distribution is the
coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued random variable `X`, the
expected value of `X` depends continuously on the choice of probability measure. This is a special
case of the topology of weak convergence of finite measures.
## Main definitions
The main definitions are
* the type `MeasureTheory.ProbabilityMeasure Ω` with the topology of convergence in
distribution (a.k.a. convergence in law, weak convergence of measures);
* `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`: Interpret a probability measure as
a finite measure;
* `MeasureTheory.FiniteMeasure.normalize`: Normalize a finite measure to a probability measure
(returns junk for the zero measure).
* `MeasureTheory.ProbabilityMeasure.map`: The push-forward `f* μ` of a probability measure
`μ` on `Ω` along a measurable function `f : Ω → Ω'`.
## Main results
* `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of
probability measures is characterized by the convergence of expected values of all bounded
continuous random variables. This shows that the chosen definition of topology coincides with
the common textbook definition of convergence in distribution, i.e., weak convergence of
measures. A similar characterization by the convergence of expected values (in the
`MeasureTheory.lintegral` sense) of all bounded continuous nonnegative random variables is
`MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto`.
* `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`: The convergence of finite
measures to a nonzero limit is characterized by the convergence of the probability-normalized
versions and of the total masses.
* `MeasureTheory.ProbabilityMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the
push-forward of probability measures `f* : ProbabilityMeasure Ω → ProbabilityMeasure Ω'` is
continuous.
* `MeasureTheory.ProbabilityMeasure.t2Space`: The topology of convergence in distribution is
Hausdorff on Borel spaces where indicators of closed sets have continuous decreasing
approximating sequences (in particular on any pseudo-metrizable spaces).
TODO:
* Probability measures form a convex space.
## Implementation notes
The topology of convergence in distribution on `MeasureTheory.ProbabilityMeasure Ω` is inherited
weak convergence of finite measures via the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
Like `MeasureTheory.FiniteMeasure Ω`, the implementation of `MeasureTheory.ProbabilityMeasure Ω`
is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the
composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`.
## References
* [Billingsley, *Convergence of probability measures*][billingsley1999]
## Tags
convergence in distribution, convergence in law, weak convergence of measures, probability measure
-/
noncomputable section
open Set Filter BoundedContinuousFunction Topology
open scoped ENNReal NNReal
namespace MeasureTheory
section ProbabilityMeasure
/-! ### Probability measures
In this section we define the type of probability measures on a measurable space `Ω`, denoted by
`MeasureTheory.ProbabilityMeasure Ω`.
If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma
algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.ProbabilityMeasure Ω` is
equipped with the topology of weak convergence of measures. Since every probability measure is a
finite measure, this is implemented as the induced topology from the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
-/
/-- Probability measures are defined as the subtype of measures that have the property of being
probability measures (i.e., their total mass is one). -/
def ProbabilityMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ :=
{ μ : Measure Ω // IsProbabilityMeasure μ }
namespace ProbabilityMeasure
variable {Ω : Type*} [MeasurableSpace Ω]
instance [Inhabited Ω] : Inhabited (ProbabilityMeasure Ω) :=
⟨⟨Measure.dirac default, Measure.dirac.isProbabilityMeasure⟩⟩
/-- Coercion from `MeasureTheory.ProbabilityMeasure Ω` to `MeasureTheory.Measure Ω`. -/
@[coe]
def toMeasure : ProbabilityMeasure Ω → Measure Ω := Subtype.val
/-- A probability measure can be interpreted as a measure. -/
instance : Coe (ProbabilityMeasure Ω) (MeasureTheory.Measure Ω) := { coe := toMeasure }
instance (μ : ProbabilityMeasure Ω) : IsProbabilityMeasure (μ : Measure Ω) :=
μ.prop
@[simp, norm_cast] lemma coe_mk (μ : Measure Ω) (hμ) : toMeasure ⟨μ, hμ⟩ = μ := rfl
@[simp]
theorem val_eq_to_measure (ν : ProbabilityMeasure Ω) : ν.val = (ν : Measure Ω) := rfl
theorem toMeasure_injective : Function.Injective ((↑) : ProbabilityMeasure Ω → Measure Ω) :=
Subtype.coe_injective
instance instFunLike : FunLike (ProbabilityMeasure Ω) (Set Ω) ℝ≥0 where
coe μ s := ((μ : Measure Ω) s).toNNReal
coe_injective' μ ν h := toMeasure_injective <| Measure.ext fun s _ ↦ by
simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s
lemma coeFn_def (μ : ProbabilityMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl
lemma coeFn_mk (μ : Measure Ω) (hμ) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl
@[simp, norm_cast]
lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl
@[simp, norm_cast]
theorem coeFn_univ (ν : ProbabilityMeasure Ω) : ν univ = 1 :=
congr_arg ENNReal.toNNReal ν.prop.measure_univ
theorem coeFn_univ_ne_zero (ν : ProbabilityMeasure Ω) : ν univ ≠ 0 := by
simp only [coeFn_univ, Ne, one_ne_zero, not_false_iff]
/-- A probability measure can be interpreted as a finite measure. -/
def toFiniteMeasure (μ : ProbabilityMeasure Ω) : FiniteMeasure Ω := ⟨μ, inferInstance⟩
@[simp] lemma coeFn_toFiniteMeasure (μ : ProbabilityMeasure Ω) : ⇑μ.toFiniteMeasure = μ := rfl
lemma toFiniteMeasure_apply (μ : ProbabilityMeasure Ω) (s : Set Ω) :
μ.toFiniteMeasure s = μ s := rfl
@[simp]
theorem toMeasure_comp_toFiniteMeasure_eq_toMeasure (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Measure Ω) = (ν : Measure Ω) := rfl
@[simp]
theorem coeFn_comp_toFiniteMeasure_eq_coeFn (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Set Ω → ℝ≥0) = (ν : Set Ω → ℝ≥0) := rfl
@[simp]
theorem toFiniteMeasure_apply_eq_apply (ν : ProbabilityMeasure Ω) (s : Set Ω) :
ν.toFiniteMeasure s = ν s := rfl
@[simp]
theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : ProbabilityMeasure Ω) (s : Set Ω) :
(ν s : ℝ≥0∞) = (ν : Measure Ω) s := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure,
toMeasure_comp_toFiniteMeasure_eq_toMeasure]
@[simp]
theorem null_iff_toMeasure_null (ν : ProbabilityMeasure Ω) (s : Set Ω) :
ν s = 0 ↔ (ν : Measure Ω) s = 0 :=
⟨fun h ↦ by rw [← ennreal_coeFn_eq_coeFn_toMeasure, h, ENNReal.coe_zero],
fun h ↦ congrArg ENNReal.toNNReal h⟩
theorem apply_mono (μ : ProbabilityMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn]
exact MeasureTheory.FiniteMeasure.apply_mono _ h
/-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable)
sets is the limit of the measures of the partial unions. -/
protected lemma tendsto_measure_iUnion_accumulate {ι : Type*} [Preorder ι]
[IsCountablyGenerated (atTop : Filter ι)] {μ : ProbabilityMeasure Ω} {f : ι → Set Ω} :
Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by
simpa [← ennreal_coeFn_eq_coeFn_toMeasure, ENNReal.tendsto_coe]
using tendsto_measure_iUnion_accumulate (μ := μ.toMeasure)
@[simp] theorem apply_le_one (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ s ≤ 1 := by
simpa using apply_mono μ (subset_univ s)
theorem nonempty (μ : ProbabilityMeasure Ω) : Nonempty Ω := by
by_contra maybe_empty
have zero : (μ : Measure Ω) univ = 0 := by
rw [univ_eq_empty_iff.mpr (not_nonempty_iff.mp maybe_empty), measure_empty]
rw [measure_univ] at zero
exact zero_ne_one zero.symm
@[ext]
theorem eq_of_forall_toMeasure_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by
apply toMeasure_injective
ext1 s s_mble
exact h s s_mble
theorem eq_of_forall_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by
ext1 s s_mble
simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble)
@[simp]
theorem mass_toFiniteMeasure (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.mass = 1 :=
μ.coeFn_univ
theorem toFiniteMeasure_nonzero (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure ≠ 0 := by
simp [← FiniteMeasure.mass_nonzero_iff]
/-- The type of probability measures is a measurable space when equipped with the Giry monad. -/
instance : MeasurableSpace (ProbabilityMeasure Ω) := Subtype.instMeasurableSpace
lemma measurableSet_isProbabilityMeasure :
MeasurableSet { μ : Measure Ω | IsProbabilityMeasure μ } := by
suffices { μ : Measure Ω | IsProbabilityMeasure μ } = (fun μ => μ univ) ⁻¹' {1} by
rw [this]
exact Measure.measurable_coe MeasurableSet.univ (measurableSet_singleton 1)
ext _
apply isProbabilityMeasure_iff
/-- The monoidal product is a measurable function from the product of probability spaces over
`α` and `β` into the type of probability spaces over `α × β`. Lemma 4.1 of [A synthetic approach to
Markov kernels, conditional independence and theorems on sufficient statistics][fritz2020]. -/
theorem measurable_prod {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :
Measurable (fun (μ : ProbabilityMeasure α × ProbabilityMeasure β)
↦ μ.1.toMeasure.prod μ.2.toMeasure) := by
apply Measurable.measure_of_isPiSystem_of_isProbabilityMeasure generateFrom_prod.symm
isPiSystem_prod _
simp only [mem_image2, mem_setOf_eq, forall_exists_index, and_imp]
intros _ u Hu v Hv Heq
simp_rw [← Heq, Measure.prod_prod]
apply Measurable.mul
· exact (Measure.measurable_coe Hu).comp (measurable_subtype_coe.comp measurable_fst)
· exact (Measure.measurable_coe Hv).comp (measurable_subtype_coe.comp measurable_snd)
section convergence_in_distribution
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
theorem testAgainstNN_lipschitz (μ : ProbabilityMeasure Ω) :
LipschitzWith 1 fun f : Ω →ᵇ ℝ≥0 ↦ μ.toFiniteMeasure.testAgainstNN f :=
μ.mass_toFiniteMeasure ▸ μ.toFiniteMeasure.testAgainstNN_lipschitz
/-- The topology of weak convergence on `MeasureTheory.ProbabilityMeasure Ω`. This is inherited
(induced) from the topology of weak convergence of finite measures via the inclusion
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/
instance : TopologicalSpace (ProbabilityMeasure Ω) :=
TopologicalSpace.induced toFiniteMeasure inferInstance
theorem toFiniteMeasure_continuous :
Continuous (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) :=
continuous_induced_dom
/-- Probability measures yield elements of the `WeakDual` of bounded continuous nonnegative
functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/
def toWeakDualBCNN : ProbabilityMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) :=
FiniteMeasure.toWeakDualBCNN ∘ toFiniteMeasure
@[simp]
theorem coe_toWeakDualBCNN (μ : ProbabilityMeasure Ω) :
⇑μ.toWeakDualBCNN = μ.toFiniteMeasure.testAgainstNN := rfl
@[simp]
theorem toWeakDualBCNN_apply (μ : ProbabilityMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
μ.toWeakDualBCNN f = (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal := rfl
theorem toWeakDualBCNN_continuous : Continuous fun μ : ProbabilityMeasure Ω ↦ μ.toWeakDualBCNN :=
FiniteMeasure.toWeakDualBCNN_continuous.comp toFiniteMeasure_continuous
/- Integration of (nonnegative bounded continuous) test functions against Borel probability
measures depends continuously on the measure. -/
theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) :
Continuous fun μ : ProbabilityMeasure Ω ↦ μ.toFiniteMeasure.testAgainstNN f :=
(FiniteMeasure.continuous_testAgainstNN_eval f).comp toFiniteMeasure_continuous
-- The canonical mapping from probability measures to finite measures is an embedding.
theorem toFiniteMeasure_isEmbedding (Ω : Type*) [MeasurableSpace Ω] [TopologicalSpace Ω]
[OpensMeasurableSpace Ω] :
IsEmbedding (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) where
eq_induced := rfl
injective _μ _ν h := Subtype.eq <| congr_arg FiniteMeasure.toMeasure h
@[deprecated (since := "2024-10-26")]
alias toFiniteMeasure_embedding := toFiniteMeasure_isEmbedding
theorem tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds {δ : Type*} (F : Filter δ)
{μs : δ → ProbabilityMeasure Ω} {μ₀ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ₀) ↔ Tendsto (toFiniteMeasure ∘ μs) F (𝓝 μ₀.toFiniteMeasure) :=
(toFiniteMeasure_isEmbedding Ω).tendsto_nhds_iff
/-- A characterization of weak convergence of probability measures by the condition that the
integrals of every continuous bounded nonnegative function converge to the integral of the function
against the limit measure. -/
theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0,
Tendsto (fun i ↦ ∫⁻ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds]
exact FiniteMeasure.tendsto_iff_forall_lintegral_tendsto
/-- The characterization of weak convergence of probability measures by the usual (defining)
condition that the integrals of every continuous bounded function converge to the integral of the
function against the limit measure. -/
theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ,
Tendsto (fun i ↦ ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by
simp [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds,
FiniteMeasure.tendsto_iff_forall_integral_tendsto]
theorem tendsto_iff_forall_integral_rclike_tendsto {γ : Type*} (𝕜 : Type*) [RCLike 𝕜]
{F : Filter γ} {μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ 𝕜,
Tendsto (fun i ↦ ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by
simp [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds,
FiniteMeasure.tendsto_iff_forall_integral_rclike_tendsto 𝕜]
lemma continuous_integral_boundedContinuousFunction
{α : Type*} [TopologicalSpace α] [MeasurableSpace α] [OpensMeasurableSpace α] (f : α →ᵇ ℝ) :
Continuous fun μ : ProbabilityMeasure α ↦ ∫ x, f x ∂μ := by
rw [continuous_iff_continuousAt]
intro μ
exact continuousAt_of_tendsto_nhds
(ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mp tendsto_id f)
end convergence_in_distribution -- section
section Hausdorff
variable [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [BorelSpace Ω]
variable (Ω)
/-- On topological spaces where indicators of closed sets have decreasing approximating sequences of
continuous functions (`HasOuterApproxClosed`), the topology of convergence in distribution of Borel
probability measures is Hausdorff (`T2Space`). -/
instance t2Space : T2Space (ProbabilityMeasure Ω) := (toFiniteMeasure_isEmbedding Ω).t2Space
end Hausdorff -- section
end ProbabilityMeasure
-- namespace
end ProbabilityMeasure
-- section
section NormalizeFiniteMeasure
/-! ### Normalization of finite measures to probability measures
This section is about normalizing finite measures to probability measures.
The weak convergence of finite measures to nonzero limit measures is characterized by
the convergence of the total mass and the convergence of the normalized probability
measures.
-/
namespace FiniteMeasure
variable {Ω : Type*} [Nonempty Ω] {m0 : MeasurableSpace Ω} (μ : FiniteMeasure Ω)
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
else
{ val := ↑(μ.mass⁻¹ • μ)
property := by
refine ⟨?_⟩
simp only [toMeasure_smul, Measure.coe_smul, Pi.smul_apply, Measure.nnreal_smul_coe_apply,
ENNReal.coe_inv zero, ennreal_mass]
rw [← Ne, ← ENNReal.coe_ne_zero, ennreal_mass] at zero
exact ENNReal.inv_mul_cancel zero μ.prop.measure_univ_lt_top.ne }
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
obtain rfl | h := eq_or_ne μ 0
· simp
have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
simp only [normalize, dif_neg mass_nonzero]
simp [ProbabilityMeasure.coe_mk, toMeasure_smul, mul_inv_cancel_left₀ mass_nonzero, coeFn_def]
|
theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by
apply eq_of_forall_apply_eq
| Mathlib/MeasureTheory/Measure/ProbabilityMeasure.lean | 395 | 397 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Order.Bounds.Defs
import Mathlib.Order.Directed
import Mathlib.Order.BoundedOrder.Monotone
import Mathlib.Order.Interval.Set.Basic
/-!
# Upper / lower bounds
In this file we prove various lemmas about upper/lower bounds of a set:
monotonicity, behaviour under `∪`, `∩`, `insert`,
and provide formulas for `∅`, `univ`, and intervals.
-/
open Function Set
open OrderDual (toDual ofDual)
universe u v
variable {α : Type u} {γ : Type v}
section
variable [Preorder α] {s t : Set α} {a b : α}
theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a :=
Iff.rfl
theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x :=
Iff.rfl
lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl
lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl
theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x :=
Iff.rfl
theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y :=
Iff.rfl
theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le
theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top
@[simp]
theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s :=
and_iff_left <| bot_mem_lowerBounds _
@[simp]
theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s :=
and_iff_left <| top_mem_upperBounds _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x`
is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/
theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by
simp [BddAbove, upperBounds, Set.Nonempty]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x`
is not less than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/
theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y :=
@not_bddAbove_iff' αᵒᵈ _ _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater
than `x`. A version for preorders is called `not_bddAbove_iff'`. -/
theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by
simp only [not_bddAbove_iff', not_le]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less
than `x`. A version for preorders is called `not_bddBelow_iff'`. -/
theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x :=
@not_bddAbove_iff αᵒᵈ _ _
@[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
@[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} :
BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} :
BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) :=
h
theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) :=
h
theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) :=
h
/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/
abbrev IsLeast.orderBot (h : IsLeast s a) :
OrderBot s where
bot := ⟨a, h.1⟩
bot_le := Subtype.forall.2 h.2
/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/
abbrev IsGreatest.orderTop (h : IsGreatest s a) :
OrderTop s where
top := ⟨a, h.1⟩
le_top := Subtype.forall.2 h.2
theorem isLUB_congr (h : upperBounds s = upperBounds t) : IsLUB s a ↔ IsLUB t a := by
rw [IsLUB, IsLUB, h]
theorem isGLB_congr (h : lowerBounds s = lowerBounds t) : IsGLB s a ↔ IsGLB t a := by
rw [IsGLB, IsGLB, h]
/-!
### Monotonicity
-/
theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s :=
fun _ hb _ h => hb <| hst h
theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s :=
fun _ hb _ h => hb <| hst h
theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s :=
fun ha _ h => le_trans (ha h) hab
theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s :=
fun hb _ h => le_trans hab (hb h)
theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
a ∈ upperBounds t → b ∈ upperBounds s := fun ha =>
upperBounds_mono_set hst <| upperBounds_mono_mem hab ha
theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb =>
lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb
/-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/
theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s :=
Nonempty.mono <| upperBounds_mono_set h
/-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/
theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s :=
Nonempty.mono <| lowerBounds_mono_set h
/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsLUB t a :=
⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩
/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsGLB t a :=
hs.dual.of_subset_of_superset hp hst htp
theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a :=
hb.2 (hst ha.1)
theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b :=
hb.2 (hst ha.1)
theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b :=
IsLeast.mono hb ha <| upperBounds_mono_set hst
theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a :=
IsGreatest.mono hb ha <| lowerBounds_mono_set hst
theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) :=
fun _ hx _ hy => hy hx
theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) :=
fun _ hx _ hy => hy hx
theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) :=
hs.mono (subset_upperBounds_lowerBounds s)
theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) :=
hs.mono (subset_lowerBounds_upperBounds s)
/-!
### Conversions
-/
theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a :=
Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩
theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a :=
h.dual.upperBounds_eq
theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a :=
h.isGLB.lowerBounds_eq
theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a :=
h.isLUB.upperBounds_eq
theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b :=
⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩
theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x :=
h.dual.lt_iff
theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by
rw [h.upperBounds_eq]
rfl
theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by
rw [h.lowerBounds_eq]
rfl
theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s :=
⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩
theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s :=
@isLUB_iff_le_iff αᵒᵈ _ _ _
/-- If `s` has a least upper bound, then it is bounded above. -/
theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s :=
⟨a, h.1⟩
/-- If `s` has a greatest lower bound, then it is bounded below. -/
theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s :=
⟨a, h.1⟩
/-- If `s` has a greatest element, then it is bounded above. -/
theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s :=
⟨a, h.2⟩
/-- If `s` has a least element, then it is bounded below. -/
theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s :=
⟨a, h.2⟩
theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty :=
⟨a, h.1⟩
theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty :=
⟨a, h.1⟩
/-!
### Union and intersection
-/
@[simp]
theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t :=
Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩)
fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht
@[simp]
theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t :=
@upperBounds_union αᵒᵈ _ s t
theorem union_upperBounds_subset_upperBounds_inter :
upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) :=
union_subset (upperBounds_mono_set inter_subset_left)
(upperBounds_mono_set inter_subset_right)
theorem union_lowerBounds_subset_lowerBounds_inter :
lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) :=
@union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t
theorem isLeast_union_iff {a : α} {s t : Set α} :
IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by
simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc]
theorem isGreatest_union_iff :
IsGreatest (s ∪ t) a ↔
IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a :=
@isLeast_union_iff αᵒᵈ _ a s t
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) :=
h.mono inter_subset_right
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) :=
h.mono inter_subset_right
/-- In a directed order, the union of bounded above sets is bounded above. -/
theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove s → BddAbove t → BddAbove (s ∪ t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b
rw [BddAbove, upperBounds_union]
exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩
/-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/
theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t :=
⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h =>
h.1.union h.2⟩
/-- In a codirected order, the union of bounded below sets is bounded below. -/
theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow s → BddBelow t → BddBelow (s ∪ t) :=
@BddAbove.union αᵒᵈ _ _ _ _
/-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/
theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t :=
@bddAbove_union αᵒᵈ _ _ _ _
/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,
then `a ⊔ b` is the least upper bound of `s ∪ t`. -/
theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) :
IsLUB (s ∪ t) (a ⊔ b) :=
⟨fun _ h =>
h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h,
fun _ hc =>
sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩
/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,
then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/
theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁)
(ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) :=
hs.dual.union ht
/-- If `a` is the least element of `s` and `b` is the least element of `t`,
then `min a b` is the least element of `s ∪ t`. -/
theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a)
(hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩
/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,
then `max a b` is the greatest element of `s ∪ t`. -/
theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a)
(hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩
theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) :
IsLUB (s ∩ Ici b) a :=
⟨fun _ hx => ha.1 hx.1, fun c hc =>
have hbc : b ≤ c := hc ⟨hb, le_rfl⟩
ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩
theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) :
IsGLB (s ∩ Iic b) a :=
ha.dual.inter_Ici_of_mem hb
theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) :
BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by
rw [bddAbove_def, exists_ge_and_iff_exists]
exact Monotone.ball fun x _ => monotone_le
theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) :
BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
bddAbove_iff_exists_ge (toDual x₀)
theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) :
∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x :=
(bddAbove_iff_exists_ge x₀).mp hs
theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) :
∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
(bddBelow_iff_exists_le x₀).mp hs
/-!
### Specific sets
#### Unbounded intervals
-/
theorem isLeast_Ici : IsLeast (Ici a) a :=
⟨left_mem_Ici, fun _ => id⟩
theorem isGreatest_Iic : IsGreatest (Iic a) a :=
⟨right_mem_Iic, fun _ => id⟩
theorem isLUB_Iic : IsLUB (Iic a) a :=
isGreatest_Iic.isLUB
theorem isGLB_Ici : IsGLB (Ici a) a :=
isLeast_Ici.isGLB
theorem upperBounds_Iic : upperBounds (Iic a) = Ici a :=
isLUB_Iic.upperBounds_eq
theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a :=
isGLB_Ici.lowerBounds_eq
theorem bddAbove_Iic : BddAbove (Iic a) :=
isLUB_Iic.bddAbove
theorem bddBelow_Ici : BddBelow (Ici a) :=
isGLB_Ici.bddBelow
theorem bddAbove_Iio : BddAbove (Iio a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem bddBelow_Ioi : BddBelow (Ioi a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a :=
(isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk
theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b :=
@lub_Iio_le αᵒᵈ _ _ a hb
theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) :
j = i ∨ Iio i = Iic j := by
rcases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i | hj_lt_i
· exact Or.inl hj_eq_i
· right
exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩
theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) :
j = i ∨ Ioi i = Ici j :=
@lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj
section
variable [LinearOrder γ]
theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by
by_cases h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i
· obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt
exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩
· refine ⟨i, fun j hj => le_of_lt hj, ?_⟩
rw [mem_lowerBounds]
by_contra h
refine h_exists_lt ?_
push_neg at h
exact h
theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j :=
@exists_lub_Iio γᵒᵈ _ i
variable [DenselyOrdered γ]
theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a :=
⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_lt_imp_le_of_dense hy⟩
theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a :=
@isLUB_Iio γᵒᵈ _ _ a
theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a :=
isLUB_Iio.upperBounds_eq
theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a :=
isGLB_Ioi.lowerBounds_eq
end
/-!
#### Singleton
-/
@[simp] theorem isGreatest_singleton : IsGreatest {a} a :=
⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩
@[simp] theorem isLeast_singleton : IsLeast {a} a :=
@isGreatest_singleton αᵒᵈ _ a
@[simp] theorem isLUB_singleton : IsLUB {a} a :=
isGreatest_singleton.isLUB
@[simp] theorem isGLB_singleton : IsGLB {a} a :=
isLeast_singleton.isGLB
@[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove
@[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow
@[simp]
theorem upperBounds_singleton : upperBounds {a} = Ici a :=
isLUB_singleton.upperBounds_eq
@[simp]
theorem lowerBounds_singleton : lowerBounds {a} = Iic a :=
isGLB_singleton.lowerBounds_eq
/-!
#### Bounded intervals
-/
theorem bddAbove_Icc : BddAbove (Icc a b) :=
⟨b, fun _ => And.right⟩
theorem bddBelow_Icc : BddBelow (Icc a b) :=
⟨a, fun _ => And.left⟩
theorem bddAbove_Ico : BddAbove (Ico a b) :=
bddAbove_Icc.mono Ico_subset_Icc_self
theorem bddBelow_Ico : BddBelow (Ico a b) :=
bddBelow_Icc.mono Ico_subset_Icc_self
theorem bddAbove_Ioc : BddAbove (Ioc a b) :=
bddAbove_Icc.mono Ioc_subset_Icc_self
theorem bddBelow_Ioc : BddBelow (Ioc a b) :=
bddBelow_Icc.mono Ioc_subset_Icc_self
theorem bddAbove_Ioo : BddAbove (Ioo a b) :=
bddAbove_Icc.mono Ioo_subset_Icc_self
theorem bddBelow_Ioo : BddBelow (Ioo a b) :=
bddBelow_Icc.mono Ioo_subset_Icc_self
theorem isGreatest_Icc (h : a ≤ b) : IsGreatest (Icc a b) b :=
⟨right_mem_Icc.2 h, fun _ => And.right⟩
theorem isLUB_Icc (h : a ≤ b) : IsLUB (Icc a b) b :=
(isGreatest_Icc h).isLUB
theorem upperBounds_Icc (h : a ≤ b) : upperBounds (Icc a b) = Ici b :=
(isLUB_Icc h).upperBounds_eq
theorem isLeast_Icc (h : a ≤ b) : IsLeast (Icc a b) a :=
⟨left_mem_Icc.2 h, fun _ => And.left⟩
theorem isGLB_Icc (h : a ≤ b) : IsGLB (Icc a b) a :=
(isLeast_Icc h).isGLB
theorem lowerBounds_Icc (h : a ≤ b) : lowerBounds (Icc a b) = Iic a :=
(isGLB_Icc h).lowerBounds_eq
theorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b :=
⟨right_mem_Ioc.2 h, fun _ => And.right⟩
theorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b :=
(isGreatest_Ioc h).isLUB
theorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b :=
(isLUB_Ioc h).upperBounds_eq
theorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a :=
⟨left_mem_Ico.2 h, fun _ => And.left⟩
theorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a :=
(isLeast_Ico h).isGLB
theorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a :=
(isGLB_Ico h).lowerBounds_eq
section
variable [SemilatticeSup γ] [DenselyOrdered γ]
theorem isGLB_Ioo {a b : γ} (h : a < b) : IsGLB (Ioo a b) a :=
⟨fun _ hx => hx.1.le, fun x hx => by
rcases eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ | h₂
· exact h₁.symm ▸ le_sup_left
obtain ⟨y, lty, ylt⟩ := exists_between h₂
apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim
obtain ⟨u, au, ub⟩ := exists_between h
apply (hx ⟨au, ub⟩).trans ub.le⟩
theorem lowerBounds_Ioo {a b : γ} (hab : a < b) : lowerBounds (Ioo a b) = Iic a :=
(isGLB_Ioo hab).lowerBounds_eq
theorem isGLB_Ioc {a b : γ} (hab : a < b) : IsGLB (Ioc a b) a :=
(isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self
theorem lowerBounds_Ioc {a b : γ} (hab : a < b) : lowerBounds (Ioc a b) = Iic a :=
(isGLB_Ioc hab).lowerBounds_eq
end
section
variable [SemilatticeInf γ] [DenselyOrdered γ]
theorem isLUB_Ioo {a b : γ} (hab : a < b) : IsLUB (Ioo a b) b := by
simpa only [Ioo_toDual] using isGLB_Ioo hab.dual
theorem upperBounds_Ioo {a b : γ} (hab : a < b) : upperBounds (Ioo a b) = Ici b :=
(isLUB_Ioo hab).upperBounds_eq
theorem isLUB_Ico {a b : γ} (hab : a < b) : IsLUB (Ico a b) b := by
simpa only [Ioc_toDual] using isGLB_Ioc hab.dual
theorem upperBounds_Ico {a b : γ} (hab : a < b) : upperBounds (Ico a b) = Ici b :=
(isLUB_Ico hab).upperBounds_eq
end
theorem bddBelow_iff_subset_Ici : BddBelow s ↔ ∃ a, s ⊆ Ici a :=
Iff.rfl
theorem bddAbove_iff_subset_Iic : BddAbove s ↔ ∃ a, s ⊆ Iic a :=
Iff.rfl
theorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ Icc a b := by
simp [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici,
bddAbove_iff_subset_Iic, exists_and_left, exists_and_right]
/-!
#### Univ
-/
@[simp] theorem isGreatest_univ_iff : IsGreatest univ a ↔ IsTop a := by
simp [IsGreatest, mem_upperBounds, IsTop]
theorem isGreatest_univ [OrderTop α] : IsGreatest (univ : Set α) ⊤ :=
isGreatest_univ_iff.2 isTop_top
@[simp]
theorem OrderTop.upperBounds_univ [PartialOrder γ] [OrderTop γ] :
upperBounds (univ : Set γ) = {⊤} := by rw [isGreatest_univ.upperBounds_eq, Ici_top]
theorem isLUB_univ [OrderTop α] : IsLUB (univ : Set α) ⊤ :=
isGreatest_univ.isLUB
@[simp]
theorem OrderBot.lowerBounds_univ [PartialOrder γ] [OrderBot γ] :
lowerBounds (univ : Set γ) = {⊥} :=
@OrderTop.upperBounds_univ γᵒᵈ _ _
@[simp] theorem isLeast_univ_iff : IsLeast univ a ↔ IsBot a :=
@isGreatest_univ_iff αᵒᵈ _ _
theorem isLeast_univ [OrderBot α] : IsLeast (univ : Set α) ⊥ :=
@isGreatest_univ αᵒᵈ _ _
theorem isGLB_univ [OrderBot α] : IsGLB (univ : Set α) ⊥ :=
isLeast_univ.isGLB
@[simp]
theorem NoTopOrder.upperBounds_univ [NoTopOrder α] : upperBounds (univ : Set α) = ∅ :=
eq_empty_of_subset_empty fun b hb =>
not_isTop b fun x => hb (mem_univ x)
@[deprecated (since := "2025-04-18")]
alias NoMaxOrder.upperBounds_univ := NoTopOrder.upperBounds_univ
@[simp]
theorem NoBotOrder.lowerBounds_univ [NoBotOrder α] : lowerBounds (univ : Set α) = ∅ :=
@NoTopOrder.upperBounds_univ αᵒᵈ _ _
@[deprecated (since := "2025-04-18")]
alias NoMinOrder.lowerBounds_univ := NoBotOrder.lowerBounds_univ
@[simp]
theorem not_bddAbove_univ [NoTopOrder α] : ¬BddAbove (univ : Set α) := by simp [BddAbove]
@[simp]
theorem not_bddBelow_univ [NoBotOrder α] : ¬BddBelow (univ : Set α) :=
@not_bddAbove_univ αᵒᵈ _ _
/-!
#### Empty set
-/
@[simp]
theorem upperBounds_empty : upperBounds (∅ : Set α) = univ := by
simp only [upperBounds, eq_univ_iff_forall, mem_setOf_eq, forall_mem_empty, forall_true_iff]
@[simp]
theorem lowerBounds_empty : lowerBounds (∅ : Set α) = univ :=
@upperBounds_empty αᵒᵈ _
@[simp]
theorem bddAbove_empty [Nonempty α] : BddAbove (∅ : Set α) := by
simp only [BddAbove, upperBounds_empty, univ_nonempty]
@[simp]
theorem bddBelow_empty [Nonempty α] : BddBelow (∅ : Set α) := by
simp only [BddBelow, lowerBounds_empty, univ_nonempty]
@[simp] theorem isGLB_empty_iff : IsGLB ∅ a ↔ IsTop a := by
simp [IsGLB]
@[simp] theorem isLUB_empty_iff : IsLUB ∅ a ↔ IsBot a :=
@isGLB_empty_iff αᵒᵈ _ _
theorem isGLB_empty [OrderTop α] : IsGLB ∅ (⊤ : α) :=
isGLB_empty_iff.2 isTop_top
theorem isLUB_empty [OrderBot α] : IsLUB ∅ (⊥ : α) :=
@isGLB_empty αᵒᵈ _ _
theorem IsLUB.nonempty [NoBotOrder α] (hs : IsLUB s a) : s.Nonempty :=
nonempty_iff_ne_empty.2 fun h =>
not_isBot a fun _ => hs.right <| by rw [h, upperBounds_empty]; exact mem_univ _
theorem IsGLB.nonempty [NoTopOrder α] (hs : IsGLB s a) : s.Nonempty :=
hs.dual.nonempty
theorem nonempty_of_not_bddAbove [ha : Nonempty α] (h : ¬BddAbove s) : s.Nonempty :=
(Nonempty.elim ha) fun x => (not_bddAbove_iff'.1 h x).imp fun _ ha => ha.1
theorem nonempty_of_not_bddBelow [Nonempty α] (h : ¬BddBelow s) : s.Nonempty :=
@nonempty_of_not_bddAbove αᵒᵈ _ _ _ h
/-!
#### insert
-/
/-- Adding a point to a set preserves its boundedness above. -/
@[simp]
theorem bddAbove_insert [IsDirected α (· ≤ ·)] {s : Set α} {a : α} :
BddAbove (insert a s) ↔ BddAbove s := by
simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and]
protected theorem BddAbove.insert [IsDirected α (· ≤ ·)] {s : Set α} (a : α) :
BddAbove s → BddAbove (insert a s) :=
bddAbove_insert.2
/-- Adding a point to a set preserves its boundedness below. -/
@[simp]
theorem bddBelow_insert [IsDirected α (· ≥ ·)] {s : Set α} {a : α} :
BddBelow (insert a s) ↔ BddBelow s := by
simp only [insert_eq, bddBelow_union, bddBelow_singleton, true_and]
protected theorem BddBelow.insert [IsDirected α (· ≥ ·)] {s : Set α} (a : α) :
BddBelow s → BddBelow (insert a s) :=
bddBelow_insert.2
protected theorem IsLUB.insert [SemilatticeSup γ] (a) {b} {s : Set γ} (hs : IsLUB s b) :
IsLUB (insert a s) (a ⊔ b) := by
rw [insert_eq]
exact isLUB_singleton.union hs
protected theorem IsGLB.insert [SemilatticeInf γ] (a) {b} {s : Set γ} (hs : IsGLB s b) :
IsGLB (insert a s) (a ⊓ b) := by
rw [insert_eq]
exact isGLB_singleton.union hs
protected theorem IsGreatest.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsGreatest s b) :
IsGreatest (insert a s) (max a b) := by
rw [insert_eq]
exact isGreatest_singleton.union hs
protected theorem IsLeast.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsLeast s b) :
IsLeast (insert a s) (min a b) := by
rw [insert_eq]
exact isLeast_singleton.union hs
@[simp]
theorem upperBounds_insert (a : α) (s : Set α) :
upperBounds (insert a s) = Ici a ∩ upperBounds s := by
rw [insert_eq, upperBounds_union, upperBounds_singleton]
@[simp]
theorem lowerBounds_insert (a : α) (s : Set α) :
lowerBounds (insert a s) = Iic a ∩ lowerBounds s := by
rw [insert_eq, lowerBounds_union, lowerBounds_singleton]
/-- When there is a global maximum, every set is bounded above. -/
@[simp]
protected theorem OrderTop.bddAbove [OrderTop α] (s : Set α) : BddAbove s :=
⟨⊤, fun a _ => OrderTop.le_top a⟩
/-- When there is a global minimum, every set is bounded below. -/
@[simp]
protected theorem OrderBot.bddBelow [OrderBot α] (s : Set α) : BddBelow s :=
⟨⊥, fun a _ => OrderBot.bot_le a⟩
/-- Sets 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 `bddDefault` in the statements,
in the form `(hA : BddAbove A := by bddDefault)`. -/
macro "bddDefault" : tactic =>
`(tactic| first
| apply OrderTop.bddAbove
| apply OrderBot.bddBelow)
/-!
#### Pair
-/
theorem isLUB_pair [SemilatticeSup γ] {a b : γ} : IsLUB {a, b} (a ⊔ b) :=
isLUB_singleton.insert _
theorem isGLB_pair [SemilatticeInf γ] {a b : γ} : IsGLB {a, b} (a ⊓ b) :=
isGLB_singleton.insert _
theorem isLeast_pair [LinearOrder γ] {a b : γ} : IsLeast {a, b} (min a b) :=
isLeast_singleton.insert _
theorem isGreatest_pair [LinearOrder γ] {a b : γ} : IsGreatest {a, b} (max a b) :=
isGreatest_singleton.insert _
/-!
#### Lower/upper bounds
-/
@[simp]
theorem isLUB_lowerBounds : IsLUB (lowerBounds s) a ↔ IsGLB s a :=
⟨fun H => ⟨fun _ hx => H.2 <| subset_upperBounds_lowerBounds s hx, H.1⟩, IsGreatest.isLUB⟩
@[simp]
theorem isGLB_upperBounds : IsGLB (upperBounds s) a ↔ IsLUB s a :=
@isLUB_lowerBounds αᵒᵈ _ _ _
end
/-!
### (In)equalities with the least upper bound and the greatest lower bound
-/
section Preorder
variable [Preorder α] {s : Set α} {a b : α}
theorem lowerBounds_le_upperBounds (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) :
s.Nonempty → a ≤ b
| ⟨_, hc⟩ => le_trans (ha hc) (hb hc)
theorem isGLB_le_isLUB (ha : IsGLB s a) (hb : IsLUB s b) (hs : s.Nonempty) : a ≤ b :=
lowerBounds_le_upperBounds ha.1 hb.1 hs
theorem isLUB_lt_iff (ha : IsLUB s a) : a < b ↔ ∃ c ∈ upperBounds s, c < b :=
⟨fun hb => ⟨a, ha.1, hb⟩, fun ⟨_, hcs, hcb⟩ => lt_of_le_of_lt (ha.2 hcs) hcb⟩
theorem lt_isGLB_iff (ha : IsGLB s a) : b < a ↔ ∃ c ∈ lowerBounds s, b < c :=
isLUB_lt_iff ha.dual
theorem le_of_isLUB_le_isGLB {x y} (ha : IsGLB s a) (hb : IsLUB s b) (hab : b ≤ a) (hx : x ∈ s)
(hy : y ∈ s) : x ≤ y :=
calc
x ≤ b := hb.1 hx
_ ≤ a := hab
_ ≤ y := ha.1 hy
end Preorder
section PartialOrder
variable [PartialOrder α] {s : Set α} {a b : α}
theorem IsLeast.unique (Ha : IsLeast s a) (Hb : IsLeast s b) : a = b :=
le_antisymm (Ha.right Hb.left) (Hb.right Ha.left)
theorem IsLeast.isLeast_iff_eq (Ha : IsLeast s a) : IsLeast s b ↔ a = b :=
Iff.intro Ha.unique fun h => h ▸ Ha
theorem IsGreatest.unique (Ha : IsGreatest s a) (Hb : IsGreatest s b) : a = b :=
le_antisymm (Hb.right Ha.left) (Ha.right Hb.left)
theorem IsGreatest.isGreatest_iff_eq (Ha : IsGreatest s a) : IsGreatest s b ↔ a = b :=
Iff.intro Ha.unique fun h => h ▸ Ha
theorem IsLUB.unique (Ha : IsLUB s a) (Hb : IsLUB s b) : a = b :=
IsLeast.unique Ha Hb
theorem IsGLB.unique (Ha : IsGLB s a) (Hb : IsGLB s b) : a = b :=
IsGreatest.unique Ha Hb
theorem Set.subsingleton_of_isLUB_le_isGLB (Ha : IsGLB s a) (Hb : IsLUB s b) (hab : b ≤ a) :
s.Subsingleton := fun _ hx _ hy =>
le_antisymm (le_of_isLUB_le_isGLB Ha Hb hab hx hy) (le_of_isLUB_le_isGLB Ha Hb hab hy hx)
theorem isGLB_lt_isLUB_of_ne (Ha : IsGLB s a) (Hb : IsLUB s b) {x y} (Hx : x ∈ s) (Hy : y ∈ s)
(Hxy : x ≠ y) : a < b :=
lt_iff_le_not_le.2
⟨lowerBounds_le_upperBounds Ha.1 Hb.1 ⟨x, Hx⟩, fun hab =>
Hxy <| Set.subsingleton_of_isLUB_le_isGLB Ha Hb hab Hx Hy⟩
end PartialOrder
section LinearOrder
variable [LinearOrder α] {s : Set α} {a b : α}
theorem lt_isLUB_iff (h : IsLUB s a) : b < a ↔ ∃ c ∈ s, b < c := by
simp_rw [← not_le, isLUB_le_iff h, mem_upperBounds, not_forall, not_le, exists_prop]
theorem isGLB_lt_iff (h : IsGLB s a) : a < b ↔ ∃ c ∈ s, c < b :=
lt_isLUB_iff h.dual
theorem IsLUB.exists_between (h : IsLUB s a) (hb : b < a) : ∃ c ∈ s, b < c ∧ c ≤ a :=
let ⟨c, hcs, hbc⟩ := (lt_isLUB_iff h).1 hb
⟨c, hcs, hbc, h.1 hcs⟩
theorem IsLUB.exists_between' (h : IsLUB s a) (h' : a ∉ s) (hb : b < a) : ∃ c ∈ s, b < c ∧ c < a :=
let ⟨c, hcs, hbc, hca⟩ := h.exists_between hb
⟨c, hcs, hbc, hca.lt_of_ne fun hac => h' <| hac ▸ hcs⟩
theorem IsGLB.exists_between (h : IsGLB s a) (hb : a < b) : ∃ c ∈ s, a ≤ c ∧ c < b :=
let ⟨c, hcs, hbc⟩ := (isGLB_lt_iff h).1 hb
⟨c, hcs, h.1 hcs, hbc⟩
theorem IsGLB.exists_between' (h : IsGLB s a) (h' : a ∉ s) (hb : a < b) : ∃ c ∈ s, a < c ∧ c < b :=
let ⟨c, hcs, hac, hcb⟩ := h.exists_between hb
⟨c, hcs, hac.lt_of_ne fun hac => h' <| hac.symm ▸ hcs, hcb⟩
end LinearOrder
theorem isGreatest_himp [GeneralizedHeytingAlgebra α] (a b : α) :
IsGreatest {w | w ⊓ a ≤ b} (a ⇨ b) := by
simp [IsGreatest, mem_upperBounds]
theorem isLeast_sdiff [GeneralizedCoheytingAlgebra α] (a b : α) :
IsLeast {w | a ≤ b ⊔ w} (a \ b) := by
simp [IsLeast, mem_lowerBounds]
theorem isGreatest_compl [HeytingAlgebra α] (a : α) :
IsGreatest {w | Disjoint w a} (aᶜ) := by
simpa only [himp_bot, disjoint_iff_inf_le] using isGreatest_himp a ⊥
theorem isLeast_hnot [CoheytingAlgebra α] (a : α) :
IsLeast {w | Codisjoint a w} (¬a) := by
simpa only [CoheytingAlgebra.top_sdiff, codisjoint_iff_le_sup] using isLeast_sdiff ⊤ a
| Mathlib/Order/Bounds/Basic.lean | 973 | 976 | |
/-
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
/-!
# 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.blocksFun : 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.blocksFun 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.
* `splitWrtComposition_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)>
-/
assert_not_exists Field
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
deriving DecidableEq
attribute [simp] Composition.blocks_sum
/-- 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
deriving DecidableEq
instance {n : ℕ} : Inhabited (CompositionAsSet n) :=
⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩
attribute [simp] CompositionAsSet.zero_mem CompositionAsSet.getLast_mem
/-!
### 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
theorem blocks_length : c.blocks.length = c.length :=
rfl
/-- 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
@[simp]
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
@[simp]
theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]
@[simp]
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h
theorem blocks_le {i : ℕ} (h : i ∈ c.blocks) : i ≤ n := by
rw [← c.blocks_sum]
exact List.le_sum_of_mem h
@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks[i] :=
c.one_le_blocks (get_mem (blocks c) _)
@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks[i] :=
c.one_le_blocks' h
@[simp]
theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
@[simp]
theorem blocksFun_le {n} (c : Composition n) (i : Fin c.length) :
c.blocksFun i ≤ n :=
c.blocks_le <| getElem_mem _
@[simp]
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
@[simp]
theorem blocks_eq_nil : c.blocks = [] ↔ n = 0 := by
constructor
· intro h
simpa using congr(List.sum $h)
· rintro rfl
rw [← length_eq_zero_iff, ← nonpos_iff_eq_zero]
exact c.length_le
protected theorem length_eq_zero : c.length = 0 ↔ n = 0 := by
simp
@[simp]
theorem length_pos_iff : 0 < c.length ↔ 0 < n := by
simp [pos_iff_ne_zero]
alias ⟨_, length_pos_of_pos⟩ := length_pos_iff
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : ℕ) : ℕ :=
(c.blocks.take i).sum
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_of_length_le h
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
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 _ _
theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i] := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
/-- 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
@[simp]
theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]
@[simp]
theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by
simp [boundary, Fin.ext_iff]
/-- 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
theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]
/-- 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⟩
/-- 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 _)
/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocksFun 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 i.2).symm
_ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2
_ = n := c.sizeUpTo_length
@[simp]
theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.embedding i j : ℕ) = c.sizeUpTo i + j :=
rfl
/-- `index_exists` asserts there is some `i` with `j < c.sizeUpTo (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]
/-- `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⟩
theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ :=
(Nat.find_spec (c.index_exists j.2)).1
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
/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with
`Fin (c.blocksFun (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 _ _⟩
@[simp]
theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) :=
rfl
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)
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
/-- 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
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
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
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
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]
/-- Equivalence between the disjoint union of the blocks (each of them seen as
`Fin (c.blocksFun 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
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]
/-- 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
/-! ### 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⟩
instance {n : ℕ} : Inhabited (Composition n) :=
⟨Composition.ones n⟩
@[simp]
theorem ones_length (n : ℕ) : (ones n).length = n :=
List.length_replicate
@[simp]
theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) :=
rfl
@[simp]
theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by
simp only [blocksFun, ones, get_eq_getElem, getElem_replicate]
@[simp]
theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by
simp [sizeUpTo, ones_blocks, take_replicate]
@[simp]
theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) :
(ones n).embedding i ⟨0, h⟩ = ⟨i, lt_of_lt_of_le i.2 (ones n).length_le⟩ := by
ext
simpa using i.2.le
theorem eq_ones_iff {c : Composition n} : c = ones n ↔ ∀ i ∈ c.blocks, i = 1 := by
constructor
· rintro rfl
exact fun i => eq_of_mem_replicate
· intro H
ext1
have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H
have : c.blocks.length = n := by
conv_rhs => rw [← c.blocks_sum, A]
simp
rw [A, this, ones_blocks]
theorem ne_ones_iff {c : Composition n} : c ≠ ones n ↔ ∃ i ∈ c.blocks, 1 < i := by
refine (not_congr eq_ones_iff).trans ?_
have : ∀ j ∈ c.blocks, j = 1 ↔ j ≤ 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj]
simp +contextual [this]
theorem eq_ones_iff_length {c : Composition n} : c = ones n ↔ c.length = n := by
constructor
· rintro rfl
exact ones_length n
· contrapose
intro H length_n
apply lt_irrefl n
calc
n = ∑ i : Fin c.length, 1 := by simp [length_n]
_ < ∑ i : Fin c.length, c.blocksFun i := by
{
obtain ⟨i, hi, i_blocks⟩ : ∃ i ∈ c.blocks, 1 < i := ne_ones_iff.1 H
rw [← ofFn_blocksFun, mem_ofFn' c.blocksFun, Set.mem_range] at hi
obtain ⟨j : Fin c.length, hj : c.blocksFun j = i⟩ := hi
rw [← hj] at i_blocks
exact Finset.sum_lt_sum (fun i _ => one_le_blocksFun c i) ⟨j, Finset.mem_univ _, i_blocks⟩
}
_ = n := c.sum_blocksFun
theorem eq_ones_iff_le_length {c : Composition n} : c = ones n ↔ n ≤ c.length := by
simp [eq_ones_iff_length, le_antisymm_iff, c.length_le]
| /-! ### The composition `Composition.single` -/
/-- The composition made of a single block of size `n`. -/
def single (n : ℕ) (h : 0 < n) : Composition n :=
| Mathlib/Combinatorics/Enumerative/Composition.lean | 518 | 521 |
/-
Copyright (c) 2023 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.Algebra.Group.Torsion
import Mathlib.Algebra.Polynomial.Smeval
import Mathlib.Algebra.Ring.NegOnePow
import Mathlib.Data.NNRat.Order
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.RingTheory.Polynomial.Pochhammer
import Mathlib.Tactic.FieldSimp
/-!
# Binomial rings
In this file we introduce the binomial property as a mixin, and define the `multichoose`
and `choose` functions generalizing binomial coefficients.
According to our main reference [elliott2006binomial] (which lists many equivalent conditions), a
binomial ring is a torsion-free commutative ring `R` such that for any `x ∈ R` and any `k ∈ ℕ`, the
product `x(x-1)⋯(x-k+1)` is divisible by `k!`. The torsion-free condition lets us divide by `k!`
unambiguously, so we get uniquely defined binomial coefficients.
The defining condition doesn't require commutativity or associativity, and we get a theory with
essentially the same power by replacing subtraction with addition. Thus, we consider any additive
commutative monoid with a notion of natural number exponents in which multiplication by positive
integers is injective, and demand that the evaluation of the ascending Pochhammer polynomial
`X(X+1)⋯(X+(k-1))` at any element is divisible by `k!`. The quotient is called `multichoose r k`,
because for `r` a natural number, it is the number of multisets of cardinality `k` taken from a type
of cardinality `n`.
## Definitions
* `BinomialRing`: a mixin class specifying a suitable `multichoose` function.
* `Ring.multichoose`: the quotient of an ascending Pochhammer evaluation by a factorial.
* `Ring.choose`: the quotient of a descending Pochhammer evaluation by a factorial.
## Results
* Basic results with choose and multichoose, e.g., `choose_zero_right`
* Relations between choose and multichoose, negated input.
* Fundamental recursion: `choose_succ_succ`
* Chu-Vandermonde identity: `add_choose_eq`
* Pochhammer API
## References
* [J. Elliott, *Binomial rings, integer-valued polynomials, and λ-rings*][elliott2006binomial]
## TODO
Further results in Elliot's paper:
* A CommRing is binomial if and only if it admits a λ-ring structure with trivial Adams operations.
* The free commutative binomial ring on a set `X` is the ring of integer-valued polynomials in the
variables `X`. (also, noncommutative version?)
* Given a commutative binomial ring `A` and an `A`-algebra `B` that is complete with respect to an
ideal `I`, formal exponentiation induces an `A`-module structure on the multiplicative subgroup
`1 + I`.
-/
section Multichoose
open Function Polynomial
/-- A binomial ring is a ring for which ascending Pochhammer evaluations are uniquely divisible by
suitable factorials. We define this notion as a mixin for additive commutative monoids with natural
number powers, but retain the ring name. We introduce `Ring.multichoose` as the uniquely defined
quotient. -/
class BinomialRing (R : Type*) [AddCommMonoid R] [Pow R ℕ] extends IsAddTorsionFree R where
/-- A multichoose function, giving the quotient of Pochhammer evaluations by factorials. -/
multichoose : R → ℕ → R
/-- The `n`th ascending Pochhammer polynomial evaluated at any element is divisible by `n!` -/
factorial_nsmul_multichoose (r : R) (n : ℕ) :
n.factorial • multichoose r n = (ascPochhammer ℕ n).smeval r
namespace Ring
variable {R : Type*} [AddCommMonoid R] [Pow R ℕ] [BinomialRing R]
@[deprecated (since := "2025-03-15")] protected alias nsmul_right_injective := nsmul_right_injective
@[deprecated (since := "2025-03-15")] protected alias nsmul_right_inj := nsmul_right_inj
/-- The multichoose function is the quotient of ascending Pochhammer evaluation by the corresponding
factorial. When applied to natural numbers, `multichoose k n` describes choosing a multiset of `n`
items from a type of size `k`, i.e., choosing with replacement. -/
def multichoose (r : R) (n : ℕ) : R := BinomialRing.multichoose r n
@[simp]
theorem multichoose_eq_multichoose (r : R) (n : ℕ) :
BinomialRing.multichoose r n = multichoose r n := rfl
| theorem factorial_nsmul_multichoose_eq_ascPochhammer (r : R) (n : ℕ) :
n.factorial • multichoose r n = (ascPochhammer ℕ n).smeval r :=
BinomialRing.factorial_nsmul_multichoose r n
@[simp]
| Mathlib/RingTheory/Binomial.lean | 93 | 97 |
/-
Copyright (c) 2023 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.DedekindDomain.Ideal
import Mathlib.RingTheory.Discriminant
import Mathlib.RingTheory.DedekindDomain.IntegralClosure
import Mathlib.NumberTheory.KummerDedekind
import Mathlib.RingTheory.IntegralClosure.IntegralRestrict
import Mathlib.RingTheory.Trace.Quotient
/-!
# The different ideal
## Main definition
- `Submodule.traceDual`: The dual `L`-sub `B`-module under the trace form.
- `FractionalIdeal.dual`: The dual fractional ideal under the trace form.
- `differentIdeal`: The different ideal of an extension of integral domains.
## Main results
- `conductor_mul_differentIdeal`:
If `L = K[x]`, with `x` integral over `A`, then `𝔣 * 𝔇 = (f'(x))`
with `f` being the minimal polynomial of `x`.
- `aeval_derivative_mem_differentIdeal`:
If `L = K[x]`, with `x` integral over `A`, then `f'(x) ∈ 𝔇`
with `f` being the minimal polynomial of `x`.
## TODO
- Show properties of the different ideal
-/
universe u
attribute [local instance] FractionRing.liftAlgebra FractionRing.isScalarTower_liftAlgebra
variable (A K : Type*) {L : Type u} {B} [CommRing A] [Field K] [CommRing B] [Field L]
variable [Algebra A K] [Algebra B L] [Algebra A B] [Algebra K L] [Algebra A L]
variable [IsScalarTower A K L] [IsScalarTower A B L]
open nonZeroDivisors IsLocalization Matrix Algebra
section BIsDomain
/-- Under the AKLB setting, `Iᵛ := traceDual A K (I : Submodule B L)` is the
`Submodule B L` such that `x ∈ Iᵛ ↔ ∀ y ∈ I, Tr(x, y) ∈ A` -/
noncomputable
def Submodule.traceDual (I : Submodule B L) : Submodule B L where
__ := (traceForm K L).dualSubmodule (I.restrictScalars A)
smul_mem' c x hx a ha := by
rw [traceForm_apply, smul_mul_assoc, mul_comm, ← smul_mul_assoc, mul_comm]
exact hx _ (Submodule.smul_mem _ c ha)
variable {A K}
local notation:max I:max "ᵛ" => Submodule.traceDual A K I
namespace Submodule
lemma mem_traceDual {I : Submodule B L} {x} :
x ∈ Iᵛ ↔ ∀ a ∈ I, traceForm K L x a ∈ (algebraMap A K).range :=
forall₂_congr fun _ _ ↦ mem_one
lemma le_traceDual_iff_map_le_one {I J : Submodule B L} :
I ≤ Jᵛ ↔ ((I * J : Submodule B L).restrictScalars A).map
((trace K L).restrictScalars A) ≤ 1 := by
rw [Submodule.map_le_iff_le_comap, Submodule.restrictScalars_mul, Submodule.mul_le]
simp [SetLike.le_def, mem_traceDual]
lemma le_traceDual_mul_iff {I J J' : Submodule B L} :
I ≤ (J * J')ᵛ ↔ I * J ≤ J'ᵛ := by
simp_rw [le_traceDual_iff_map_le_one, mul_assoc]
lemma le_traceDual {I J : Submodule B L} :
I ≤ Jᵛ ↔ I * J ≤ 1ᵛ := by
rw [← le_traceDual_mul_iff, mul_one]
lemma le_traceDual_comm {I J : Submodule B L} :
I ≤ Jᵛ ↔ J ≤ Iᵛ := by rw [le_traceDual, mul_comm, ← le_traceDual]
lemma le_traceDual_traceDual {I : Submodule B L} :
I ≤ Iᵛᵛ := le_traceDual_comm.mpr le_rfl
@[simp]
lemma traceDual_bot :
(⊥ : Submodule B L)ᵛ = ⊤ := by ext; simpa [mem_traceDual, -RingHom.mem_range] using zero_mem _
open scoped Classical in
lemma traceDual_top' :
(⊤ : Submodule B L)ᵛ =
if ((LinearMap.range (Algebra.trace K L)).restrictScalars A ≤ 1) then ⊤ else ⊥ := by
classical
split_ifs with h
· rw [_root_.eq_top_iff]
exact fun _ _ _ _ ↦ h ⟨_, rfl⟩
· simp only [SetLike.le_def, restrictScalars_mem, LinearMap.mem_range, mem_one,
forall_exists_index, forall_apply_eq_imp_iff, not_forall, not_exists] at h
obtain ⟨b, hb⟩ := h
simp_rw [eq_bot_iff, SetLike.le_def, mem_bot, mem_traceDual, mem_top, true_implies,
traceForm_apply, RingHom.mem_range]
contrapose! hb with hx'
obtain ⟨c, hc, hc0⟩ := hx'
simpa [hc0] using hc (c⁻¹ * b)
variable [IsDomain A] [IsFractionRing A K] [FiniteDimensional K L] [Algebra.IsSeparable K L]
lemma traceDual_top [Decidable (IsField A)] :
(⊤ : Submodule B L)ᵛ = if IsField A then ⊤ else ⊥ := by
convert traceDual_top'
rw [← IsFractionRing.surjective_iff_isField (R := A) (K := K),
LinearMap.range_eq_top.mpr (Algebra.trace_surjective K L),
← RingHom.range_eq_top, _root_.eq_top_iff]
simp [SetLike.le_def]
end Submodule
open Submodule
variable [IsFractionRing A K]
variable (A K) in
lemma map_equiv_traceDual [IsDomain A] [IsFractionRing B L] [IsDomain B]
[FaithfulSMul A B] (I : Submodule B (FractionRing B)) :
(traceDual A (FractionRing A) I).map (FractionRing.algEquiv B L) =
traceDual A K (I.map (FractionRing.algEquiv B L)) := by
show Submodule.map (FractionRing.algEquiv B L).toLinearEquiv.toLinearMap _ =
traceDual A K (I.map (FractionRing.algEquiv B L).toLinearEquiv.toLinearMap)
rw [Submodule.map_equiv_eq_comap_symm, Submodule.map_equiv_eq_comap_symm]
ext x
simp only [AlgEquiv.toLinearEquiv_symm, AlgEquiv.toLinearEquiv_toLinearMap,
traceDual, traceForm_apply, Submodule.mem_comap, AlgEquiv.toLinearMap_apply,
Submodule.mem_mk, AddSubmonoid.mem_mk, AddSubsemigroup.mem_mk, Set.mem_setOf_eq]
apply (FractionRing.algEquiv B L).forall_congr
simp only [restrictScalars_mem, traceForm_apply, AlgEquiv.toEquiv_eq_coe,
EquivLike.coe_coe, mem_comap, AlgEquiv.toLinearMap_apply, AlgEquiv.symm_apply_apply]
refine fun {y} ↦ (forall_congr' fun hy ↦ ?_)
rw [Algebra.trace_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv
(FractionRing.algEquiv B L).toRingEquiv]
swap
· apply IsLocalization.ringHom_ext (M := A⁰); ext
simp only [AlgEquiv.toRingEquiv_eq_coe, AlgEquiv.toRingEquiv_toRingHom, RingHom.coe_comp,
RingHom.coe_coe, Function.comp_apply, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply]
rw [IsScalarTower.algebraMap_apply A B (FractionRing B), AlgEquiv.commutes,
← IsScalarTower.algebraMap_apply]
simp only [AlgEquiv.toRingEquiv_eq_coe, map_mul, AlgEquiv.coe_ringEquiv,
AlgEquiv.apply_symm_apply, ← AlgEquiv.symm_toRingEquiv, mem_one, AlgEquiv.algebraMap_eq_apply]
variable [IsIntegrallyClosed A]
lemma Submodule.mem_traceDual_iff_isIntegral {I : Submodule B L} {x} :
x ∈ Iᵛ ↔ ∀ a ∈ I, IsIntegral A (traceForm K L x a) :=
forall₂_congr fun _ _ ↦ mem_one.trans IsIntegrallyClosed.isIntegral_iff.symm
variable [FiniteDimensional K L] [IsIntegralClosure B A L]
lemma Submodule.one_le_traceDual_one :
(1 : Submodule B L) ≤ 1ᵛ := by
rw [le_traceDual_iff_map_le_one, mul_one, one_eq_range]
rintro _ ⟨x, ⟨x, rfl⟩, rfl⟩
rw [mem_one]
apply IsIntegrallyClosed.isIntegral_iff.mp
apply isIntegral_trace
rw [IsIntegralClosure.isIntegral_iff (A := B)]
exact ⟨_, rfl⟩
variable [Algebra.IsSeparable K L]
/-- If `b` is an `A`-integral basis of `L` with discriminant `b`, then `d • a * x` is integral over
`A` for all `a ∈ I` and `x ∈ Iᵛ`. -/
lemma isIntegral_discr_mul_of_mem_traceDual
(I : Submodule B L) {ι} [DecidableEq ι] [Fintype ι]
{b : Basis ι K L} (hb : ∀ i, IsIntegral A (b i))
{a x : L} (ha : a ∈ I) (hx : x ∈ Iᵛ) :
IsIntegral A ((discr K b) • a * x) := by
have hinv : IsUnit (traceMatrix K b).det := by
simpa [← discr_def] using discr_isUnit_of_basis _ b
have H := mulVec_cramer (traceMatrix K b) fun i => trace K L (x * a * b i)
have : Function.Injective (traceMatrix K b).mulVec := by
rwa [mulVec_injective_iff_isUnit, isUnit_iff_isUnit_det]
rw [← traceMatrix_of_basis_mulVec, ← mulVec_smul, this.eq_iff,
traceMatrix_of_basis_mulVec] at H
rw [← b.equivFun.symm_apply_apply (_ * _), b.equivFun_symm_apply]
apply IsIntegral.sum
intro i _
rw [smul_mul_assoc, b.equivFun.map_smul, discr_def, mul_comm, ← H, Algebra.smul_def]
refine RingHom.IsIntegralElem.mul _ ?_ (hb _)
apply IsIntegral.algebraMap
rw [cramer_apply]
apply IsIntegral.det
intros j k
rw [updateCol_apply]
split
· rw [mul_assoc]
rw [mem_traceDual_iff_isIntegral] at hx
apply hx
have ⟨y, hy⟩ := (IsIntegralClosure.isIntegral_iff (A := B)).mp (hb j)
rw [mul_comm, ← hy, ← Algebra.smul_def]
exact I.smul_mem _ (ha)
· exact isIntegral_trace (RingHom.IsIntegralElem.mul _ (hb j) (hb k))
variable (A K)
variable [IsDomain A] [IsFractionRing B L] [Nontrivial B] [NoZeroDivisors B]
namespace FractionalIdeal
open scoped Classical in
/-- The dual of a non-zero fractional ideal is the dual of the submodule under the traceform. -/
noncomputable
def dual (I : FractionalIdeal B⁰ L) :
FractionalIdeal B⁰ L :=
if hI : I = 0 then 0 else
⟨Iᵛ, by
classical
have ⟨s, b, hb⟩ := FiniteDimensional.exists_is_basis_integral A K L
obtain ⟨x, hx, hx'⟩ := exists_ne_zero_mem_isInteger hI
have ⟨y, hy⟩ := (IsIntegralClosure.isIntegral_iff (A := B)).mp
(IsIntegral.algebraMap (B := L) (discr_isIntegral K hb))
refine ⟨y * x, mem_nonZeroDivisors_iff_ne_zero.mpr (mul_ne_zero ?_ hx), fun z hz ↦ ?_⟩
· rw [← (IsIntegralClosure.algebraMap_injective B A L).ne_iff, hy, RingHom.map_zero,
← (algebraMap K L).map_zero, (algebraMap K L).injective.ne_iff]
exact discr_not_zero_of_basis K b
· convert isIntegral_discr_mul_of_mem_traceDual I hb hx' hz using 1
· ext w; exact (IsIntegralClosure.isIntegral_iff (A := B)).symm
· rw [Algebra.smul_def, RingHom.map_mul, hy, ← Algebra.smul_def]⟩
end FractionalIdeal
end BIsDomain
variable [IsDomain A] [IsFractionRing A K]
[FiniteDimensional K L] [Algebra.IsSeparable K L] [IsIntegralClosure B A L]
namespace FractionalIdeal
variable [IsFractionRing B L] [IsIntegrallyClosed A]
open Submodule
local notation:max I:max "ᵛ" => Submodule.traceDual A K I
variable [IsDedekindDomain B] {I J : FractionalIdeal B⁰ L}
lemma coe_dual (hI : I ≠ 0) :
(dual A K I : Submodule B L) = Iᵛ := by rw [dual, dif_neg hI, coe_mk]
variable (B L)
@[simp]
lemma coe_dual_one :
(dual A K (1 : FractionalIdeal B⁰ L) : Submodule B L) = 1ᵛ := by
rw [← coe_one, coe_dual]
exact one_ne_zero
@[simp]
lemma dual_zero :
dual A K (0 : FractionalIdeal B⁰ L) = 0 := by rw [dual, dif_pos rfl]
variable {A K L B}
lemma mem_dual (hI : I ≠ 0) {x} :
x ∈ dual A K I ↔ ∀ a ∈ I, traceForm K L x a ∈ (algebraMap A K).range := by
rw [dual, dif_neg hI]; exact forall₂_congr fun _ _ ↦ mem_one
variable (A K)
lemma dual_ne_zero (hI : I ≠ 0) :
dual A K I ≠ 0 := by
obtain ⟨b, hb, hb'⟩ := I.prop
suffices algebraMap B L b ∈ dual A K I by
intro e
rw [e, mem_zero_iff, ← (algebraMap B L).map_zero,
(IsIntegralClosure.algebraMap_injective B A L).eq_iff] at this
exact mem_nonZeroDivisors_iff_ne_zero.mp hb this
rw [mem_dual hI]
intro a ha
apply IsIntegrallyClosed.isIntegral_iff.mp
apply isIntegral_trace
dsimp
convert hb' a ha using 1
· ext w
exact IsIntegralClosure.isIntegral_iff (A := B)
· exact (Algebra.smul_def _ _).symm
variable {A K}
@[simp]
lemma dual_eq_zero_iff :
dual A K I = 0 ↔ I = 0 :=
⟨not_imp_not.mp (dual_ne_zero A K), fun e ↦ e.symm ▸ dual_zero A K L B⟩
lemma dual_ne_zero_iff :
dual A K I ≠ 0 ↔ I ≠ 0 := dual_eq_zero_iff.not
| variable (A K)
lemma le_dual_inv_aux (hI : I ≠ 0) (hIJ : I * J ≤ 1) :
J ≤ dual A K I := by
rw [dual, dif_neg hI]
intro x hx y hy
rw [mem_one]
| Mathlib/RingTheory/DedekindDomain/Different.lean | 295 | 301 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yakov Pechersky
-/
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Infix
import Mathlib.Data.Quot
/-!
# List rotation
This file proves basic results about `List.rotate`, the list rotation.
## Main declarations
* `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`.
* `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`.
## Tags
rotated, rotation, permutation, cycle
-/
universe u
variable {α : Type u}
open Nat Function
namespace List
theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate]
@[simp]
theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate]
@[simp]
theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate]
theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by simp
@[simp]
theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl
theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) :
(a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate']
@[simp]
theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length
| [], _ => by simp
| _ :: _, 0 => rfl
| a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp
| theorem rotate'_eq_drop_append_take :
∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n
| Mathlib/Data/List/Rotate.lean | 56 | 57 |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Yaël Dillies
-/
import Mathlib.Order.Cover
import Mathlib.Order.LatticeIntervals
import Mathlib.Order.GaloisConnection.Defs
/-!
# Modular Lattices
This file defines (semi)modular lattices, a kind of lattice useful in algebra.
For examples, look to the subobject lattices of abelian groups, submodules, and ideals, or consider
any distributive lattice.
## Typeclasses
We define (semi)modularity typeclasses as Prop-valued mixins.
* `IsWeakUpperModularLattice`: Weakly upper modular lattices. Lattice where `a ⊔ b` covers `a`
and `b` if `a` and `b` both cover `a ⊓ b`.
* `IsWeakLowerModularLattice`: Weakly lower modular lattices. Lattice where `a` and `b` cover
`a ⊓ b` if `a ⊔ b` covers both `a` and `b`
* `IsUpperModularLattice`: Upper modular lattices. Lattices where `a ⊔ b` covers `a` if `b`
covers `a ⊓ b`.
* `IsLowerModularLattice`: Lower modular lattices. Lattices where `a` covers `a ⊓ b` if `a ⊔ b`
covers `b`.
- `IsModularLattice`: Modular lattices. Lattices where `a ≤ c → (a ⊔ b) ⊓ c = a ⊔ (b ⊓ c)`. We
only require an inequality because the other direction holds in all lattices.
## Main Definitions
- `infIccOrderIsoIccSup` gives an order isomorphism between the intervals
`[a ⊓ b, a]` and `[b, a ⊔ b]`.
This corresponds to the diamond (or second) isomorphism theorems of algebra.
## Main Results
- `isModularLattice_iff_inf_sup_inf_assoc`:
Modularity is equivalent to the `inf_sup_inf_assoc`: `(x ⊓ z) ⊔ (y ⊓ z) = ((x ⊓ z) ⊔ y) ⊓ z`
- `DistribLattice.isModularLattice`: Distributive lattices are modular.
## References
* [Manfred Stern, *Semimodular lattices. {Theory} and applications*][stern2009]
* [Wikipedia, *Modular Lattice*][https://en.wikipedia.org/wiki/Modular_lattice]
## TODO
- Relate atoms and coatoms in modular lattices
-/
open Set
variable {α : Type*}
/-- A weakly upper modular lattice is a lattice where `a ⊔ b` covers `a` and `b` if `a` and `b` both
cover `a ⊓ b`. -/
class IsWeakUpperModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a ⊔ b` covers `a` and `b` if `a` and `b` both cover `a ⊓ b`. -/
covBy_sup_of_inf_covBy_covBy {a b : α} : a ⊓ b ⋖ a → a ⊓ b ⋖ b → a ⋖ a ⊔ b
/-- A weakly lower modular lattice is a lattice where `a` and `b` cover `a ⊓ b` if `a ⊔ b` covers
both `a` and `b`. -/
class IsWeakLowerModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a` and `b` cover `a ⊓ b` if `a ⊔ b` covers both `a` and `b` -/
inf_covBy_of_covBy_covBy_sup {a b : α} : a ⋖ a ⊔ b → b ⋖ a ⊔ b → a ⊓ b ⋖ a
/-- An upper modular lattice, aka semimodular lattice, is a lattice where `a ⊔ b` covers `a` and `b`
if either `a` or `b` covers `a ⊓ b`. -/
class IsUpperModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a ⊔ b` covers `a` and `b` if either `a` or `b` covers `a ⊓ b` -/
covBy_sup_of_inf_covBy {a b : α} : a ⊓ b ⋖ a → b ⋖ a ⊔ b
/-- A lower modular lattice is a lattice where `a` and `b` both cover `a ⊓ b` if `a ⊔ b` covers
either `a` or `b`. -/
class IsLowerModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a` and `b` both cover `a ⊓ b` if `a ⊔ b` covers either `a` or `b` -/
inf_covBy_of_covBy_sup {a b : α} : a ⋖ a ⊔ b → a ⊓ b ⋖ b
/-- A modular lattice is one with a limited associativity between `⊓` and `⊔`. -/
class IsModularLattice (α : Type*) [Lattice α] : Prop where
/-- Whenever `x ≤ z`, then for any `y`, `(x ⊔ y) ⊓ z ≤ x ⊔ (y ⊓ z)` -/
sup_inf_le_assoc_of_le : ∀ {x : α} (y : α) {z : α}, x ≤ z → (x ⊔ y) ⊓ z ≤ x ⊔ y ⊓ z
section WeakUpperModular
variable [Lattice α] [IsWeakUpperModularLattice α] {a b : α}
theorem covBy_sup_of_inf_covBy_of_inf_covBy_left : a ⊓ b ⋖ a → a ⊓ b ⋖ b → a ⋖ a ⊔ b :=
IsWeakUpperModularLattice.covBy_sup_of_inf_covBy_covBy
theorem covBy_sup_of_inf_covBy_of_inf_covBy_right : a ⊓ b ⋖ a → a ⊓ b ⋖ b → b ⋖ a ⊔ b := by
rw [inf_comm, sup_comm]
exact fun ha hb => covBy_sup_of_inf_covBy_of_inf_covBy_left hb ha
alias CovBy.sup_of_inf_of_inf_left := covBy_sup_of_inf_covBy_of_inf_covBy_left
alias CovBy.sup_of_inf_of_inf_right := covBy_sup_of_inf_covBy_of_inf_covBy_right
instance : IsWeakLowerModularLattice (OrderDual α) :=
⟨fun ha hb => (ha.ofDual.sup_of_inf_of_inf_left hb.ofDual).toDual⟩
end WeakUpperModular
section WeakLowerModular
variable [Lattice α] [IsWeakLowerModularLattice α] {a b : α}
theorem inf_covBy_of_covBy_sup_of_covBy_sup_left : a ⋖ a ⊔ b → b ⋖ a ⊔ b → a ⊓ b ⋖ a :=
IsWeakLowerModularLattice.inf_covBy_of_covBy_covBy_sup
theorem inf_covBy_of_covBy_sup_of_covBy_sup_right : a ⋖ a ⊔ b → b ⋖ a ⊔ b → a ⊓ b ⋖ b := by
rw [sup_comm, inf_comm]
exact fun ha hb => inf_covBy_of_covBy_sup_of_covBy_sup_left hb ha
alias CovBy.inf_of_sup_of_sup_left := inf_covBy_of_covBy_sup_of_covBy_sup_left
alias CovBy.inf_of_sup_of_sup_right := inf_covBy_of_covBy_sup_of_covBy_sup_right
instance : IsWeakUpperModularLattice (OrderDual α) :=
⟨fun ha hb => (ha.ofDual.inf_of_sup_of_sup_left hb.ofDual).toDual⟩
end WeakLowerModular
section UpperModular
variable [Lattice α] [IsUpperModularLattice α] {a b : α}
theorem covBy_sup_of_inf_covBy_left : a ⊓ b ⋖ a → b ⋖ a ⊔ b :=
IsUpperModularLattice.covBy_sup_of_inf_covBy
theorem covBy_sup_of_inf_covBy_right : a ⊓ b ⋖ b → a ⋖ a ⊔ b := by
rw [sup_comm, inf_comm]
exact covBy_sup_of_inf_covBy_left
alias CovBy.sup_of_inf_left := covBy_sup_of_inf_covBy_left
alias CovBy.sup_of_inf_right := covBy_sup_of_inf_covBy_right
-- See note [lower instance priority]
instance (priority := 100) IsUpperModularLattice.to_isWeakUpperModularLattice :
IsWeakUpperModularLattice α :=
⟨fun _ => CovBy.sup_of_inf_right⟩
instance : IsLowerModularLattice (OrderDual α) :=
⟨fun h => h.ofDual.sup_of_inf_left.toDual⟩
end UpperModular
section LowerModular
variable [Lattice α] [IsLowerModularLattice α] {a b : α}
theorem inf_covBy_of_covBy_sup_left : a ⋖ a ⊔ b → a ⊓ b ⋖ b :=
IsLowerModularLattice.inf_covBy_of_covBy_sup
theorem inf_covBy_of_covBy_sup_right : b ⋖ a ⊔ b → a ⊓ b ⋖ a := by
rw [inf_comm, sup_comm]
exact inf_covBy_of_covBy_sup_left
alias CovBy.inf_of_sup_left := inf_covBy_of_covBy_sup_left
alias CovBy.inf_of_sup_right := inf_covBy_of_covBy_sup_right
-- See note [lower instance priority]
instance (priority := 100) IsLowerModularLattice.to_isWeakLowerModularLattice :
IsWeakLowerModularLattice α :=
⟨fun _ => CovBy.inf_of_sup_right⟩
instance : IsUpperModularLattice (OrderDual α) :=
⟨fun h => h.ofDual.inf_of_sup_left.toDual⟩
end LowerModular
section IsModularLattice
variable [Lattice α] [IsModularLattice α]
theorem sup_inf_assoc_of_le {x : α} (y : α) {z : α} (h : x ≤ z) : (x ⊔ y) ⊓ z = x ⊔ y ⊓ z :=
le_antisymm (IsModularLattice.sup_inf_le_assoc_of_le y h)
(le_inf (sup_le_sup_left inf_le_left _) (sup_le h inf_le_right))
theorem IsModularLattice.inf_sup_inf_assoc {x y z : α} : x ⊓ z ⊔ y ⊓ z = (x ⊓ z ⊔ y) ⊓ z :=
(sup_inf_assoc_of_le y inf_le_right).symm
theorem inf_sup_assoc_of_le {x : α} (y : α) {z : α} (h : z ≤ x) : x ⊓ y ⊔ z = x ⊓ (y ⊔ z) := by
rw [inf_comm, sup_comm, ← sup_inf_assoc_of_le y h, inf_comm, sup_comm]
instance : IsModularLattice αᵒᵈ :=
⟨fun y z xz =>
le_of_eq
(by
rw [inf_comm, sup_comm, eq_comm, inf_comm, sup_comm]
exact @sup_inf_assoc_of_le α _ _ _ y _ xz)⟩
variable {x y z : α}
theorem IsModularLattice.sup_inf_sup_assoc : (x ⊔ z) ⊓ (y ⊔ z) = (x ⊔ z) ⊓ y ⊔ z :=
@IsModularLattice.inf_sup_inf_assoc αᵒᵈ _ _ _ _ _
theorem eq_of_le_of_inf_le_of_le_sup (hxy : x ≤ y) (hinf : y ⊓ z ≤ x) (hsup : y ≤ x ⊔ z) :
x = y := by
refine hxy.antisymm ?_
rw [← inf_eq_right, sup_inf_assoc_of_le _ hxy] at hsup
rwa [← hsup, sup_le_iff, and_iff_right rfl.le, inf_comm]
theorem eq_of_le_of_inf_le_of_sup_le (hxy : x ≤ y) (hinf : y ⊓ z ≤ x ⊓ z) (hsup : y ⊔ z ≤ x ⊔ z) :
x = y :=
eq_of_le_of_inf_le_of_le_sup hxy (hinf.trans inf_le_left) (le_sup_left.trans hsup)
theorem sup_lt_sup_of_lt_of_inf_le_inf (hxy : x < y) (hinf : y ⊓ z ≤ x ⊓ z) : x ⊔ z < y ⊔ z :=
lt_of_le_of_ne (sup_le_sup_right (le_of_lt hxy) _) fun hsup =>
| ne_of_lt hxy <| eq_of_le_of_inf_le_of_sup_le (le_of_lt hxy) hinf (le_of_eq hsup.symm)
| Mathlib/Order/ModularLattice.lean | 216 | 217 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yaël Dillies
-/
import Mathlib.Data.List.Iterate
import Mathlib.GroupTheory.Perm.Cycle.Basic
import Mathlib.GroupTheory.NoncommPiCoprod
import Mathlib.Tactic.Group
/-!
# Cycle factors of a permutation
Let `β` be a `Fintype` and `f : Equiv.Perm β`.
* `Equiv.Perm.cycleOf`: `f.cycleOf x` is the cycle of `f` that `x` belongs to.
* `Equiv.Perm.cycleFactors`: `f.cycleFactors` is a list of disjoint cyclic permutations
that multiply to `f`.
-/
open Equiv Function Finset
variable {ι α β : Type*}
namespace Equiv.Perm
/-!
### `cycleOf`
-/
section CycleOf
variable {f g : Perm α} {x y : α}
/-- `f.cycleOf x` is the cycle of the permutation `f` to which `x` belongs. -/
def cycleOf (f : Perm α) [DecidableRel f.SameCycle] (x : α) : Perm α :=
ofSubtype (subtypePerm f fun _ => sameCycle_apply_right.symm : Perm { y // SameCycle f x y })
theorem cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (x y : α) :
cycleOf f x y = if SameCycle f x y then f y else y := by
dsimp only [cycleOf]
split_ifs with h
· apply ofSubtype_apply_of_mem
exact h
· apply ofSubtype_apply_of_not_mem
exact h
theorem cycleOf_inv (f : Perm α) [DecidableRel f.SameCycle] (x : α) :
(cycleOf f x)⁻¹ = cycleOf f⁻¹ x :=
Equiv.ext fun y => by
rw [inv_eq_iff_eq, cycleOf_apply, cycleOf_apply]
split_ifs <;> simp_all [sameCycle_inv, sameCycle_inv_apply_right]
@[simp]
theorem cycleOf_pow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) :
∀ n : ℕ, (cycleOf f x ^ n) x = (f ^ n) x := by
intro n
induction n with
| zero => rfl
| succ n hn =>
rw [pow_succ', mul_apply, cycleOf_apply, hn, if_pos, pow_succ', mul_apply]
exact ⟨n, rfl⟩
@[simp]
theorem cycleOf_zpow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) :
∀ n : ℤ, (cycleOf f x ^ n) x = (f ^ n) x := by
intro z
cases z with
| ofNat z => exact cycleOf_pow_apply_self f x z
| negSucc z =>
rw [zpow_negSucc, ← inv_pow, cycleOf_inv, zpow_negSucc, ← inv_pow, cycleOf_pow_apply_self]
theorem SameCycle.cycleOf_apply [DecidableRel f.SameCycle] :
SameCycle f x y → cycleOf f x y = f y :=
ofSubtype_apply_of_mem _
theorem cycleOf_apply_of_not_sameCycle [DecidableRel f.SameCycle] :
¬SameCycle f x y → cycleOf f x y = y :=
ofSubtype_apply_of_not_mem _
theorem SameCycle.cycleOf_eq [DecidableRel f.SameCycle] (h : SameCycle f x y) :
cycleOf f x = cycleOf f y := by
ext z
rw [Equiv.Perm.cycleOf_apply]
split_ifs with hz
· exact (h.symm.trans hz).cycleOf_apply.symm
· exact (cycleOf_apply_of_not_sameCycle (mt h.trans hz)).symm
@[simp]
theorem cycleOf_apply_apply_zpow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℤ) :
cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by
rw [SameCycle.cycleOf_apply]
· rw [add_comm, zpow_add, zpow_one, mul_apply]
· exact ⟨k, rfl⟩
@[simp]
theorem cycleOf_apply_apply_pow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℕ) :
cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by
convert cycleOf_apply_apply_zpow_self f x k using 1
@[simp]
theorem cycleOf_apply_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) :
cycleOf f x (f x) = f (f x) := by
convert cycleOf_apply_apply_pow_self f x 1 using 1
@[simp]
theorem cycleOf_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f x x = f x :=
SameCycle.rfl.cycleOf_apply
theorem IsCycle.cycleOf_eq [DecidableRel f.SameCycle]
(hf : IsCycle f) (hx : f x ≠ x) : cycleOf f x = f :=
Equiv.ext fun y =>
if h : SameCycle f x y then by rw [h.cycleOf_apply]
else by
rw [cycleOf_apply_of_not_sameCycle h,
Classical.not_not.1 (mt ((isCycle_iff_sameCycle hx).1 hf).2 h)]
@[simp]
theorem cycleOf_eq_one_iff (f : Perm α) [DecidableRel f.SameCycle] : cycleOf f x = 1 ↔ f x = x := by
simp_rw [Perm.ext_iff, cycleOf_apply, one_apply]
refine ⟨fun h => (if_pos (SameCycle.refl f x)).symm.trans (h x), fun h y => ?_⟩
by_cases hy : f y = y
· rw [hy, ite_self]
· exact if_neg (mt SameCycle.apply_eq_self_iff (by tauto))
@[simp]
theorem cycleOf_self_apply (f : Perm α) [DecidableRel f.SameCycle] (x : α) :
cycleOf f (f x) = cycleOf f x :=
(sameCycle_apply_right.2 SameCycle.rfl).symm.cycleOf_eq
@[simp]
theorem cycleOf_self_apply_pow (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) :
cycleOf f ((f ^ n) x) = cycleOf f x :=
SameCycle.rfl.pow_left.cycleOf_eq
@[simp]
theorem cycleOf_self_apply_zpow (f : Perm α) [DecidableRel f.SameCycle] (n : ℤ) (x : α) :
cycleOf f ((f ^ n) x) = cycleOf f x :=
SameCycle.rfl.zpow_left.cycleOf_eq
protected theorem IsCycle.cycleOf [DecidableRel f.SameCycle] [DecidableEq α]
(hf : IsCycle f) : cycleOf f x = if f x = x then 1 else f := by
by_cases hx : f x = x
· rwa [if_pos hx, cycleOf_eq_one_iff]
· rwa [if_neg hx, hf.cycleOf_eq]
theorem cycleOf_one [DecidableRel (1 : Perm α).SameCycle] (x : α) :
cycleOf 1 x = 1 := (cycleOf_eq_one_iff 1).mpr rfl
theorem isCycle_cycleOf (f : Perm α) [DecidableRel f.SameCycle] (hx : f x ≠ x) :
IsCycle (cycleOf f x) :=
have : cycleOf f x x ≠ x := by rwa [SameCycle.rfl.cycleOf_apply]
(isCycle_iff_sameCycle this).2 @fun y =>
⟨fun h => mt h.apply_eq_self_iff.2 this, fun h =>
if hxy : SameCycle f x y then
let ⟨i, hi⟩ := hxy
⟨i, by rw [cycleOf_zpow_apply_self, hi]⟩
else by
rw [cycleOf_apply_of_not_sameCycle hxy] at h
exact (h rfl).elim⟩
theorem pow_mod_orderOf_cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) :
(f ^ (n % orderOf (cycleOf f x))) x = (f ^ n) x := by
rw [← cycleOf_pow_apply_self f, ← cycleOf_pow_apply_self f, pow_mod_orderOf]
theorem cycleOf_mul_of_apply_right_eq_self [DecidableRel f.SameCycle]
[DecidableRel (f * g).SameCycle]
(h : Commute f g) (x : α) (hx : g x = x) : (f * g).cycleOf x = f.cycleOf x := by
ext y
by_cases hxy : (f * g).SameCycle x y
· obtain ⟨z, rfl⟩ := hxy
rw [cycleOf_apply_apply_zpow_self]
simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx]
· rw [cycleOf_apply_of_not_sameCycle hxy, cycleOf_apply_of_not_sameCycle]
contrapose! hxy
obtain ⟨z, rfl⟩ := hxy
refine ⟨z, ?_⟩
simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx]
theorem Disjoint.cycleOf_mul_distrib [DecidableRel f.SameCycle] [DecidableRel g.SameCycle]
[DecidableRel (f * g).SameCycle] [DecidableRel (g * f).SameCycle] (h : f.Disjoint g) (x : α) :
(f * g).cycleOf x = f.cycleOf x * g.cycleOf x := by
rcases (disjoint_iff_eq_or_eq.mp h) x with hfx | hgx
· simp [h.commute.eq, cycleOf_mul_of_apply_right_eq_self h.symm.commute, hfx]
· simp [cycleOf_mul_of_apply_right_eq_self h.commute, hgx]
private theorem mem_support_cycleOf_iff_aux [DecidableRel f.SameCycle] [DecidableEq α] [Fintype α] :
y ∈ support (f.cycleOf x) ↔ SameCycle f x y ∧ x ∈ support f := by
by_cases hx : f x = x
· rw [(cycleOf_eq_one_iff _).mpr hx]
simp [hx]
· rw [mem_support, cycleOf_apply]
split_ifs with hy
· simp only [hx, hy, Ne, not_false_iff, and_self_iff, mem_support]
rcases hy with ⟨k, rfl⟩
rw [← not_mem_support]
simpa using hx
· simpa [hx] using hy
private theorem mem_support_cycleOf_iff'_aux (hx : f x ≠ x)
[DecidableRel f.SameCycle] [DecidableEq α] [Fintype α] :
y ∈ support (f.cycleOf x) ↔ SameCycle f x y := by
rw [mem_support_cycleOf_iff_aux, and_iff_left (mem_support.2 hx)]
/-- `x` is in the support of `f` iff `Equiv.Perm.cycle_of f x` is a cycle. -/
theorem isCycle_cycleOf_iff (f : Perm α) [DecidableRel f.SameCycle] :
IsCycle (cycleOf f x) ↔ f x ≠ x := by
refine ⟨fun hx => ?_, f.isCycle_cycleOf⟩
rw [Ne, ← cycleOf_eq_one_iff f]
exact hx.ne_one
private theorem isCycleOn_support_cycleOf_aux [DecidableEq α] [Fintype α] (f : Perm α)
[DecidableRel f.SameCycle] (x : α) : f.IsCycleOn (f.cycleOf x).support :=
⟨f.bijOn <| by
refine fun _ ↦
⟨fun h ↦ mem_support_cycleOf_iff_aux.2 ?_, fun h ↦ mem_support_cycleOf_iff_aux.2 ?_⟩
· exact ⟨sameCycle_apply_right.1 (mem_support_cycleOf_iff_aux.1 h).1,
(mem_support_cycleOf_iff_aux.1 h).2⟩
· exact ⟨sameCycle_apply_right.2 (mem_support_cycleOf_iff_aux.1 h).1,
(mem_support_cycleOf_iff_aux.1 h).2⟩
, fun a ha b hb =>
by
rw [mem_coe, mem_support_cycleOf_iff_aux] at ha hb
exact ha.1.symm.trans hb.1⟩
private theorem SameCycle.exists_pow_eq_of_mem_support_aux {f} [DecidableEq α] [Fintype α]
[DecidableRel f.SameCycle] (h : SameCycle f x y) (hx : x ∈ f.support) :
∃ i < #(f.cycleOf x).support, (f ^ i) x = y := by
rw [mem_support] at hx
exact Equiv.Perm.IsCycleOn.exists_pow_eq (b := y) (f.isCycleOn_support_cycleOf_aux x)
(by rw [mem_support_cycleOf_iff'_aux hx]) (by rwa [mem_support_cycleOf_iff'_aux hx])
instance instDecidableRelSameCycle [DecidableEq α] [Fintype α] (f : Perm α) :
DecidableRel (SameCycle f) := fun x y =>
decidable_of_iff (y ∈ List.iterate f x (Fintype.card α)) <| by
simp only [List.mem_iterate, iterate_eq_pow, eq_comm (a := y)]
constructor
· rintro ⟨n, _, hn⟩
exact ⟨n, hn⟩
· intro hxy
by_cases hx : x ∈ f.support
case pos =>
-- we can't invoke the aux lemmas above without obtaining the decidable instance we are
-- already building; but now we've left the data, so we can do this non-constructively
-- without sacrificing computability.
let _inst (f : Perm α) : DecidableRel (SameCycle f) := Classical.decRel _
rcases hxy.exists_pow_eq_of_mem_support_aux hx with ⟨i, hixy, hi⟩
refine ⟨i, lt_of_lt_of_le hixy (card_le_univ _), hi⟩
case neg =>
haveI : Nonempty α := ⟨x⟩
rw [not_mem_support] at hx
exact ⟨0, Fintype.card_pos, hxy.eq_of_left hx⟩
@[simp]
theorem two_le_card_support_cycleOf_iff [DecidableEq α] [Fintype α] :
2 ≤ #(cycleOf f x).support ↔ f x ≠ x := by
refine ⟨fun h => ?_, fun h => by simpa using (isCycle_cycleOf _ h).two_le_card_support⟩
contrapose! h
rw [← cycleOf_eq_one_iff] at h
simp [h]
@[simp] lemma support_cycleOf_nonempty [DecidableEq α] [Fintype α] :
(cycleOf f x).support.Nonempty ↔ f x ≠ x := by
rw [← two_le_card_support_cycleOf_iff, ← card_pos, ← Nat.succ_le_iff]
exact ⟨fun h => Or.resolve_left h.eq_or_lt (card_support_ne_one _).symm, zero_lt_two.trans_le⟩
theorem mem_support_cycleOf_iff [DecidableEq α] [Fintype α] :
y ∈ support (f.cycleOf x) ↔ SameCycle f x y ∧ x ∈ support f :=
mem_support_cycleOf_iff_aux
theorem mem_support_cycleOf_iff' (hx : f x ≠ x) [DecidableEq α] [Fintype α] :
y ∈ support (f.cycleOf x) ↔ SameCycle f x y :=
mem_support_cycleOf_iff'_aux hx
theorem sameCycle_iff_cycleOf_eq_of_mem_support [DecidableEq α] [Fintype α]
{g : Perm α} {x y : α} (hx : x ∈ g.support) (hy : y ∈ g.support) :
g.SameCycle x y ↔ g.cycleOf x = g.cycleOf y := by
refine ⟨SameCycle.cycleOf_eq, fun h ↦ ?_⟩
rw [← mem_support_cycleOf_iff' (mem_support.mp hx), h,
mem_support_cycleOf_iff' (mem_support.mp hy)]
theorem support_cycleOf_eq_nil_iff [DecidableEq α] [Fintype α] :
(f.cycleOf x).support = ∅ ↔ x ∉ f.support := by simp
theorem isCycleOn_support_cycleOf [DecidableEq α] [Fintype α] (f : Perm α) (x : α) :
f.IsCycleOn (f.cycleOf x).support :=
isCycleOn_support_cycleOf_aux f x
theorem SameCycle.exists_pow_eq_of_mem_support {f} [DecidableEq α] [Fintype α] (h : SameCycle f x y)
(hx : x ∈ f.support) : ∃ i < #(f.cycleOf x).support, (f ^ i) x = y :=
h.exists_pow_eq_of_mem_support_aux hx
theorem support_cycleOf_le [DecidableEq α] [Fintype α] (f : Perm α) (x : α) :
support (f.cycleOf x) ≤ support f := by
intro y hy
rw [mem_support, cycleOf_apply] at hy
split_ifs at hy
· exact mem_support.mpr hy
· exact absurd rfl hy
theorem SameCycle.mem_support_iff {f} [DecidableEq α] [Fintype α] (h : SameCycle f x y) :
x ∈ support f ↔ y ∈ support f :=
⟨fun hx => support_cycleOf_le f x (mem_support_cycleOf_iff.mpr ⟨h, hx⟩), fun hy =>
support_cycleOf_le f y (mem_support_cycleOf_iff.mpr ⟨h.symm, hy⟩)⟩
theorem pow_mod_card_support_cycleOf_self_apply [DecidableEq α] [Fintype α]
(f : Perm α) (n : ℕ) (x : α) : (f ^ (n % #(f.cycleOf x).support)) x = (f ^ n) x := by
by_cases hx : f x = x
· rw [pow_apply_eq_self_of_apply_eq_self hx, pow_apply_eq_self_of_apply_eq_self hx]
· rw [← cycleOf_pow_apply_self, ← cycleOf_pow_apply_self f, ← (isCycle_cycleOf f hx).orderOf,
pow_mod_orderOf]
theorem SameCycle.exists_pow_eq [DecidableEq α] [Fintype α] (f : Perm α) (h : SameCycle f x y) :
∃ i : ℕ, 0 < i ∧ i ≤ #(f.cycleOf x).support + 1 ∧ (f ^ i) x = y := by
by_cases hx : x ∈ f.support
· obtain ⟨k, hk, hk'⟩ := h.exists_pow_eq_of_mem_support hx
rcases k with - | k
· refine ⟨#(f.cycleOf x).support, ?_, self_le_add_right _ _, ?_⟩
· refine zero_lt_one.trans (one_lt_card_support_of_ne_one ?_)
simpa using hx
· simp only [pow_zero, coe_one, id_eq] at hk'
subst hk'
rw [← (isCycle_cycleOf _ <| mem_support.1 hx).orderOf, ← cycleOf_pow_apply_self,
pow_orderOf_eq_one, one_apply]
· exact ⟨k + 1, by simp, Nat.le_succ_of_le hk.le, hk'⟩
· refine ⟨1, zero_lt_one, by simp, ?_⟩
obtain ⟨k, rfl⟩ := h
rw [not_mem_support] at hx
rw [pow_apply_eq_self_of_apply_eq_self hx, zpow_apply_eq_self_of_apply_eq_self hx]
theorem zpow_eq_zpow_on_iff [DecidableEq α] [Fintype α]
(g : Perm α) {m n : ℤ} {x : α} (hx : g x ≠ x) :
(g ^ m) x = (g ^ n) x ↔ m % #(g.cycleOf x).support = n % #(g.cycleOf x).support := by
rw [Int.emod_eq_emod_iff_emod_sub_eq_zero]
conv_lhs => rw [← Int.sub_add_cancel m n, Int.add_comm, zpow_add]
simp only [coe_mul, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq]
rw [← Int.dvd_iff_emod_eq_zero]
rw [← cycleOf_zpow_apply_self g x, cycle_zpow_mem_support_iff]
· rw [← Int.dvd_iff_emod_eq_zero]
· exact isCycle_cycleOf g hx
· simp only [mem_support, cycleOf_apply_self]; exact hx
end CycleOf
/-!
### `cycleFactors`
-/
section cycleFactors
open scoped List in
/-- Given a list `l : List α` and a permutation `f : Perm α` whose nonfixed points are all in `l`,
recursively factors `f` into cycles. -/
def cycleFactorsAux [DecidableEq α] [Fintype α]
(l : List α) (f : Perm α) (h : ∀ {x}, f x ≠ x → x ∈ l) :
{ pl : List (Perm α) // pl.prod = f ∧ (∀ g ∈ pl, IsCycle g) ∧ pl.Pairwise Disjoint } :=
go l f h (fun _ => rfl)
where
/-- The auxiliary of `cycleFactorsAux`. This functions separates cycles from `f` instead of `g`
to prevent the process of a cycle gets complex. -/
go (l : List α) (g : Perm α) (hg : ∀ {x}, g x ≠ x → x ∈ l)
(hfg : ∀ {x}, g x ≠ x → cycleOf f x = cycleOf g x) :
{ pl : List (Perm α) // pl.prod = g ∧ (∀ g' ∈ pl, IsCycle g') ∧ pl.Pairwise Disjoint } :=
match l with
| [] => ⟨[], by
{ simp only [imp_false, List.Pairwise.nil, List.not_mem_nil, forall_const, and_true,
forall_prop_of_false, Classical.not_not, not_false_iff, List.prod_nil] at *
ext
simp [*]}⟩
| x :: l =>
if hx : g x = x then go l g (by
intro y hy; exact List.mem_of_ne_of_mem (fun h => hy (by rwa [h])) (hg hy)) hfg
else
let ⟨m, hm₁, hm₂, hm₃⟩ :=
go l ((cycleOf f x)⁻¹ * g) (by
rw [hfg hx]
intro y hy
exact List.mem_of_ne_of_mem
(fun h : y = x => by
rw [h, mul_apply, Ne, inv_eq_iff_eq, cycleOf_apply_self] at hy
exact hy rfl)
(hg fun h : g y = y => by
rw [mul_apply, h, Ne, inv_eq_iff_eq, cycleOf_apply] at hy
split_ifs at hy <;> tauto))
(by
rw [hfg hx]
intro y hy
simp [inv_eq_iff_eq, cycleOf_apply, eq_comm (a := g y)] at hy
rw [hfg (Ne.symm hy.right), ← mul_inv_eq_one (a := g.cycleOf y), cycleOf_inv]
simp_rw [mul_inv_rev]
rw [inv_inv, cycleOf_mul_of_apply_right_eq_self, ← cycleOf_inv, mul_inv_eq_one]
· rw [Commute.inv_left_iff, commute_iff_eq]
ext z; by_cases hz : SameCycle g x z
· simp [cycleOf_apply, hz]
· simp [cycleOf_apply_of_not_sameCycle, hz]
· exact cycleOf_apply_of_not_sameCycle hy.left)
⟨cycleOf f x :: m, by
rw [hfg hx] at hm₁ ⊢
constructor
· rw [List.prod_cons, hm₁]
simp
· exact
⟨fun g' hg' =>
((List.mem_cons).1 hg').elim (fun hg' => hg'.symm ▸ isCycle_cycleOf _ hx) (hm₂ g'),
List.pairwise_cons.2
⟨fun g' hg' y =>
or_iff_not_imp_left.2 fun hgy =>
have hxy : SameCycle g x y :=
Classical.not_not.1 (mt cycleOf_apply_of_not_sameCycle hgy)
have hg'm : (g' :: m.erase g') ~ m :=
List.cons_perm_iff_perm_erase.2 ⟨hg', List.Perm.refl _⟩
have : ∀ h ∈ m.erase g', Disjoint g' h :=
| (List.pairwise_cons.1 ((hg'm.pairwise_iff Disjoint.symm).2 hm₃)).1
by_cases id fun hg'y : g' y ≠ y =>
(disjoint_prod_right _ this y).resolve_right <| by
have hsc : SameCycle g⁻¹ x (g y) := by
rwa [sameCycle_inv, sameCycle_apply_right]
rw [disjoint_prod_perm hm₃ hg'm.symm, List.prod_cons,
← eq_inv_mul_iff_mul_eq] at hm₁
rwa [hm₁, mul_apply, mul_apply, cycleOf_inv, hsc.cycleOf_apply,
inv_apply_self, inv_eq_iff_eq, eq_comm],
hm₃⟩⟩⟩
theorem mem_list_cycles_iff {α : Type*} [Finite α] {l : List (Perm α)}
(h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) {σ : Perm α} :
| Mathlib/GroupTheory/Perm/Cycle/Factors.lean | 415 | 427 |
/-
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.Logic.Basic
import Mathlib.Logic.Function.Defs
import Mathlib.Order.Defs.LinearOrder
/-!
# Booleans
This file proves various trivial lemmas about booleans and their
relation to decidable propositions.
## Tags
bool, boolean, Bool, De Morgan
-/
namespace Bool
section
/-!
This section contains lemmas about booleans which were present in core Lean 3.
The remainder of this file contains lemmas about booleans from mathlib 3.
-/
theorem true_eq_false_eq_False : ¬true = false := by decide
theorem false_eq_true_eq_False : ¬false = true := by decide
theorem eq_false_eq_not_eq_true (b : Bool) : (¬b = true) = (b = false) := by simp
theorem eq_true_eq_not_eq_false (b : Bool) : (¬b = false) = (b = true) := by simp
theorem eq_false_of_not_eq_true {b : Bool} : ¬b = true → b = false :=
Eq.mp (eq_false_eq_not_eq_true b)
theorem eq_true_of_not_eq_false {b : Bool} : ¬b = false → b = true :=
Eq.mp (eq_true_eq_not_eq_false b)
theorem and_eq_true_eq_eq_true_and_eq_true (a b : Bool) :
((a && b) = true) = (a = true ∧ b = true) := by simp
theorem or_eq_true_eq_eq_true_or_eq_true (a b : Bool) :
((a || b) = true) = (a = true ∨ b = true) := by simp
theorem not_eq_true_eq_eq_false (a : Bool) : (not a = true) = (a = false) := by cases a <;> simp
#adaptation_note /-- nightly-2024-03-05
this is no longer a simp lemma, as the LHS simplifies. -/
theorem and_eq_false_eq_eq_false_or_eq_false (a b : Bool) :
((a && b) = false) = (a = false ∨ b = false) := by
cases a <;> cases b <;> simp
theorem or_eq_false_eq_eq_false_and_eq_false (a b : Bool) :
((a || b) = false) = (a = false ∧ b = false) := by
cases a <;> cases b <;> simp
theorem not_eq_false_eq_eq_true (a : Bool) : (not a = false) = (a = true) := by cases a <;> simp
theorem coe_false : ↑false = False := by simp
theorem coe_true : ↑true = True := by simp
theorem coe_sort_false : (false : Prop) = False := by simp
theorem coe_sort_true : (true : Prop) = True := by simp
theorem decide_iff (p : Prop) [d : Decidable p] : decide p = true ↔ p := by simp
theorem decide_true {p : Prop} [Decidable p] : p → decide p :=
(decide_iff p).2
theorem of_decide_true {p : Prop} [Decidable p] : decide p → p :=
(decide_iff p).1
theorem bool_iff_false {b : Bool} : ¬b ↔ b = false := by cases b <;> decide
theorem bool_eq_false {b : Bool} : ¬b → b = false :=
bool_iff_false.1
theorem decide_false_iff (p : Prop) {_ : Decidable p} : decide p = false ↔ ¬p :=
bool_iff_false.symm.trans (not_congr (decide_iff _))
theorem decide_false {p : Prop} [Decidable p] : ¬p → decide p = false :=
(decide_false_iff p).2
theorem of_decide_false {p : Prop} [Decidable p] : decide p = false → ¬p :=
(decide_false_iff p).1
theorem decide_congr {p q : Prop} [Decidable p] [Decidable q] (h : p ↔ q) : decide p = decide q :=
decide_eq_decide.mpr h
theorem coe_xor_iff (a b : Bool) : xor a b ↔ Xor' (a = true) (b = true) := by
cases a <;> cases b <;> decide
end
theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp
theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true
theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H]
theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H]
theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide
theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide
theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide
lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide
lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide
theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b :=
not_eq_not
lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide
lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide
lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide
-- TODO naming issue: these two `not` are different.
theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp
theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by
cases a <;> decide
theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by
cases a <;> decide
theorem bne_eq_xor : bne = xor := by funext a b; revert a b; decide
attribute [simp] xor_assoc
theorem xor_iff_ne : ∀ {x y : Bool}, xor x y = true ↔ x ≠ y := by decide
/-! ### De Morgan's laws for booleans -/
instance linearOrder : LinearOrder Bool where
le_refl := by decide
le_trans := by decide
le_antisymm := by decide
le_total := by decide
toDecidableLE := inferInstance
toDecidableEq := inferInstance
toDecidableLT := inferInstance
lt_iff_le_not_le := by decide
max_def := by decide
min_def := by decide
theorem lt_iff : ∀ {x y : Bool}, x < y ↔ x = false ∧ y = true := by decide
@[simp]
theorem false_lt_true : false < true :=
lt_iff.2 ⟨rfl, rfl⟩
theorem le_iff_imp : ∀ {x y : Bool}, x ≤ y ↔ x → y := by decide
theorem and_le_left : ∀ x y : Bool, (x && y) ≤ x := by decide
theorem and_le_right : ∀ x y : Bool, (x && y) ≤ y := by decide
theorem le_and : ∀ {x y z : Bool}, x ≤ y → x ≤ z → x ≤ (y && z) := by decide
theorem left_le_or : ∀ x y : Bool, x ≤ (x || y) := by decide
theorem right_le_or : ∀ x y : Bool, y ≤ (x || y) := by decide
theorem or_le : ∀ {x y z}, x ≤ z → y ≤ z → (x || y) ≤ z := by decide
/-- convert a `ℕ` to a `Bool`, `0 -> false`, everything else -> `true` -/
def ofNat (n : Nat) : Bool :=
decide (n ≠ 0)
@[simp] lemma toNat_beq_zero (b : Bool) : (b.toNat == 0) = !b := by cases b <;> rfl
@[simp] lemma toNat_bne_zero (b : Bool) : (b.toNat != 0) = b := by simp [bne]
@[simp] lemma toNat_beq_one (b : Bool) : (b.toNat == 1) = b := by cases b <;> rfl
@[simp] lemma toNat_bne_one (b : Bool) : (b.toNat != 1) = !b := by simp [bne]
theorem ofNat_le_ofNat {n m : Nat} (h : n ≤ m) : ofNat n ≤ ofNat m := by
simp only [ofNat, ne_eq, _root_.decide_not]
cases Nat.decEq n 0 with
| isTrue hn => rw [_root_.decide_eq_true hn]; exact Bool.false_le _
| isFalse hn =>
cases Nat.decEq m 0 with
| isFalse hm => rw [_root_.decide_eq_false hm]; exact Bool.le_true _
| isTrue hm => subst hm; have h := Nat.le_antisymm h (Nat.zero_le n); contradiction
theorem toNat_le_toNat {b₀ b₁ : Bool} (h : b₀ ≤ b₁) : toNat b₀ ≤ toNat b₁ := by
cases b₀ <;> cases b₁ <;> simp_all +decide
theorem ofNat_toNat (b : Bool) : ofNat (toNat b) = b := by
cases b <;> rfl
@[simp]
theorem injective_iff {α : Sort*} {f : Bool → α} : Function.Injective f ↔ f false ≠ f true :=
⟨fun Hinj Heq ↦ false_ne_true (Hinj Heq), fun H x y hxy ↦ by
cases x <;> cases y
· rfl
· exact (H hxy).elim
· exact (H hxy.symm).elim
· rfl⟩
/-- **Kaminski's Equation** -/
theorem apply_apply_apply (f : Bool → Bool) (x : Bool) : f (f (f x)) = f x := by
cases x <;> cases h₁ : f true <;> cases h₂ : f false <;> simp only [h₁, h₂]
/-- `xor3 x y c` is `((x XOR y) XOR c)`. -/
protected def xor3 (x y c : Bool) :=
xor (xor x y) c
/-- `carry x y c` is `x && y || x && c || y && c`. -/
protected def carry (x y c : Bool) :=
x && y || x && c || y && c
end Bool
| Mathlib/Data/Bool/Basic.lean | 230 | 230 | |
/-
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.Topology.MetricSpace.HausdorffDistance
/-!
# Topological study of spaces `Π (n : ℕ), E n`
When `E n` are topological spaces, the space `Π (n : ℕ), E n` is naturally a topological space
(with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure.
However, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one
can put a noncanonical metric space structure (or rather, several of them). This is done in this
file.
## Main definitions and results
One can define a combinatorial distance on `Π (n : ℕ), E n`, as follows:
* `PiNat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`.
* `PiNat.firstDiff x y` is the first index at which `x i ≠ y i`.
* `PiNat.dist x y` is equal to `(1/2) ^ (firstDiff x y)`. It defines a distance
on `Π (n : ℕ), E n`, compatible with the topology when the `E n` have the discrete topology.
* `PiNat.metricSpace`: the metric space structure, given by this distance. Not registered as an
instance. This space is a complete metric space.
* `PiNat.metricSpaceOfDiscreteUniformity`: the same metric space structure, but adjusting the
uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an
instance
* `PiNat.metricSpaceNatNat`: the particular case of `ℕ → ℕ`, not registered as an instance.
These results are used to construct continuous functions on `Π n, E n`:
* `PiNat.exists_retraction_of_isClosed`: given a nonempty closed subset `s` of `Π (n : ℕ), E n`,
there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s`
restricting to the identity on `s`.
* `exists_nat_nat_continuous_surjective_of_completeSpace`: given any nonempty complete metric
space with second-countable topology, there exists a continuous surjection from `ℕ → ℕ` onto
this space.
One can also put distances on `Π (i : ι), E i` when the spaces `E i` are metric spaces (not discrete
in general), and `ι` is countable.
* `PiCountable.dist` is the distance on `Π i, E i` given by
`dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`.
* `PiCountable.metricSpace` is the corresponding metric space structure, adjusted so that
the uniformity is definitionally the product uniformity. Not registered as an instance.
-/
noncomputable section
open Topology TopologicalSpace Set Metric Filter Function
attribute [local simp] pow_le_pow_iff_right₀ one_lt_two inv_le_inv₀ zero_le_two zero_lt_two
variable {E : ℕ → Type*}
namespace PiNat
/-! ### The firstDiff function -/
open Classical in
/-- In a product space `Π n, E n`, then `firstDiff x y` is the first index at which `x` and `y`
differ. If `x = y`, then by convention we set `firstDiff x x = 0`. -/
irreducible_def firstDiff (x y : ∀ n, E n) : ℕ :=
if h : x ≠ y then Nat.find (ne_iff.1 h) else 0
theorem apply_firstDiff_ne {x y : ∀ n, E n} (h : x ≠ y) :
x (firstDiff x y) ≠ y (firstDiff x y) := by
rw [firstDiff_def, dif_pos h]
classical
exact Nat.find_spec (ne_iff.1 h)
theorem apply_eq_of_lt_firstDiff {x y : ∀ n, E n} {n : ℕ} (hn : n < firstDiff x y) : x n = y n := by
rw [firstDiff_def] at hn
split_ifs at hn with h
· convert Nat.find_min (ne_iff.1 h) hn
simp
· exact (not_lt_zero' hn).elim
theorem firstDiff_comm (x y : ∀ n, E n) : firstDiff x y = firstDiff y x := by
classical
simp only [firstDiff_def, ne_comm]
theorem min_firstDiff_le (x y z : ∀ n, E n) (h : x ≠ z) :
min (firstDiff x y) (firstDiff y z) ≤ firstDiff x z := by
by_contra! H
rw [lt_min_iff] at H
refine apply_firstDiff_ne h ?_
calc
x (firstDiff x z) = y (firstDiff x z) := apply_eq_of_lt_firstDiff H.1
_ = z (firstDiff x z) := apply_eq_of_lt_firstDiff H.2
/-! ### Cylinders -/
/-- In a product space `Π n, E n`, the cylinder set of length `n` around `x`, denoted
`cylinder x n`, is the set of sequences `y` that coincide with `x` on the first `n` symbols, i.e.,
such that `y i = x i` for all `i < n`.
-/
def cylinder (x : ∀ n, E n) (n : ℕ) : Set (∀ n, E n) :=
{ y | ∀ i, i < n → y i = x i }
theorem cylinder_eq_pi (x : ∀ n, E n) (n : ℕ) :
cylinder x n = Set.pi (Finset.range n : Set ℕ) fun i : ℕ => {x i} := by
ext y
simp [cylinder]
@[simp]
theorem cylinder_zero (x : ∀ n, E n) : cylinder x 0 = univ := by simp [cylinder_eq_pi]
theorem cylinder_anti (x : ∀ n, E n) {m n : ℕ} (h : m ≤ n) : cylinder x n ⊆ cylinder x m :=
fun _y hy i hi => hy i (hi.trans_le h)
@[simp]
theorem mem_cylinder_iff {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ ∀ i < n, y i = x i :=
Iff.rfl
theorem self_mem_cylinder (x : ∀ n, E n) (n : ℕ) : x ∈ cylinder x n := by simp
theorem mem_cylinder_iff_eq {x y : ∀ n, E n} {n : ℕ} :
y ∈ cylinder x n ↔ cylinder y n = cylinder x n := by
constructor
· intro hy
apply Subset.antisymm
· intro z hz i hi
rw [← hy i hi]
exact hz i hi
· intro z hz i hi
rw [hy i hi]
exact hz i hi
· intro h
rw [← h]
exact self_mem_cylinder _ _
theorem mem_cylinder_comm (x y : ∀ n, E n) (n : ℕ) : y ∈ cylinder x n ↔ x ∈ cylinder y n := by
simp [mem_cylinder_iff_eq, eq_comm]
theorem mem_cylinder_iff_le_firstDiff {x y : ∀ n, E n} (hne : x ≠ y) (i : ℕ) :
x ∈ cylinder y i ↔ i ≤ firstDiff x y := by
constructor
· intro h
by_contra!
exact apply_firstDiff_ne hne (h _ this)
· intro hi j hj
exact apply_eq_of_lt_firstDiff (hj.trans_le hi)
theorem mem_cylinder_firstDiff (x y : ∀ n, E n) : x ∈ cylinder y (firstDiff x y) := fun _i hi =>
apply_eq_of_lt_firstDiff hi
theorem cylinder_eq_cylinder_of_le_firstDiff (x y : ∀ n, E n) {n : ℕ} (hn : n ≤ firstDiff x y) :
cylinder x n = cylinder y n := by
rw [← mem_cylinder_iff_eq]
intro i hi
exact apply_eq_of_lt_firstDiff (hi.trans_le hn)
theorem iUnion_cylinder_update (x : ∀ n, E n) (n : ℕ) :
⋃ k, cylinder (update x n k) (n + 1) = cylinder x n := by
ext y
simp only [mem_cylinder_iff, mem_iUnion]
constructor
· rintro ⟨k, hk⟩ i hi
simpa [hi.ne] using hk i (Nat.lt_succ_of_lt hi)
· intro H
refine ⟨y n, fun i hi => ?_⟩
rcases Nat.lt_succ_iff_lt_or_eq.1 hi with (h'i | rfl)
· simp [H i h'i, h'i.ne]
· simp
theorem update_mem_cylinder (x : ∀ n, E n) (n : ℕ) (y : E n) : update x n y ∈ cylinder x n :=
mem_cylinder_iff.2 fun i hi => by simp [hi.ne]
section Res
variable {α : Type*}
open List
/-- In the case where `E` has constant value `α`,
the cylinder `cylinder x n` can be identified with the element of `List α`
consisting of the first `n` entries of `x`. See `cylinder_eq_res`.
We call this list `res x n`, the restriction of `x` to `n`. -/
def res (x : ℕ → α) : ℕ → List α
| 0 => nil
| Nat.succ n => x n :: res x n
@[simp]
theorem res_zero (x : ℕ → α) : res x 0 = @nil α :=
rfl
@[simp]
theorem res_succ (x : ℕ → α) (n : ℕ) : res x n.succ = x n :: res x n :=
rfl
@[simp]
theorem res_length (x : ℕ → α) (n : ℕ) : (res x n).length = n := by induction n <;> simp [*]
/-- The restrictions of `x` and `y` to `n` are equal if and only if `x m = y m` for all `m < n`. -/
theorem res_eq_res {x y : ℕ → α} {n : ℕ} :
res x n = res y n ↔ ∀ ⦃m⦄, m < n → x m = y m := by
constructor <;> intro h
· induction n with
| zero => simp
| succ n ih =>
intro m hm
rw [Nat.lt_succ_iff_lt_or_eq] at hm
simp only [res_succ, cons.injEq] at h
rcases hm with hm | hm
· exact ih h.2 hm
rw [hm]
exact h.1
· induction n with
| zero => simp
| succ n ih =>
simp only [res_succ, cons.injEq]
refine ⟨h (Nat.lt_succ_self _), ih fun m hm => ?_⟩
exact h (hm.trans (Nat.lt_succ_self _))
theorem res_injective : Injective (@res α) := by
intro x y h
ext n
apply res_eq_res.mp _ (Nat.lt_succ_self _)
rw [h]
/-- `cylinder x n` is equal to the set of sequences `y` with the same restriction to `n` as `x`. -/
theorem cylinder_eq_res (x : ℕ → α) (n : ℕ) :
cylinder x n = { y | res y n = res x n } := by
ext y
dsimp [cylinder]
rw [res_eq_res]
end Res
/-!
### A distance function on `Π n, E n`
We define a distance function on `Π n, E n`, given by `dist x y = (1/2)^n` where `n` is the first
index at which `x` and `y` differ. When each `E n` has the discrete topology, this distance will
define the right topology on the product space. We do not record a global `Dist` instance nor
a `MetricSpace` instance, as other distances may be used on these spaces, but we register them as
local instances in this section.
-/
open Classical in
/-- The distance function on a product space `Π n, E n`, given by `dist x y = (1/2)^n` where `n` is
the first index at which `x` and `y` differ. -/
protected def dist : Dist (∀ n, E n) :=
⟨fun x y => if x ≠ y then (1 / 2 : ℝ) ^ firstDiff x y else 0⟩
attribute [local instance] PiNat.dist
theorem dist_eq_of_ne {x y : ∀ n, E n} (h : x ≠ y) : dist x y = (1 / 2 : ℝ) ^ firstDiff x y := by
simp [dist, h]
protected theorem dist_self (x : ∀ n, E n) : dist x x = 0 := by simp [dist]
protected theorem dist_comm (x y : ∀ n, E n) : dist x y = dist y x := by
classical
simp [dist, @eq_comm _ x y, firstDiff_comm]
protected theorem dist_nonneg (x y : ∀ n, E n) : 0 ≤ dist x y := by
rcases eq_or_ne x y with (rfl | h)
· simp [dist]
· simp [dist, h, zero_le_two]
theorem dist_triangle_nonarch (x y z : ∀ n, E n) : dist x z ≤ max (dist x y) (dist y z) := by
rcases eq_or_ne x z with (rfl | hxz)
· simp [PiNat.dist_self x, PiNat.dist_nonneg]
rcases eq_or_ne x y with (rfl | hxy)
· simp
rcases eq_or_ne y z with (rfl | hyz)
· simp
simp only [dist_eq_of_ne, hxz, hxy, hyz, inv_le_inv₀, one_div, inv_pow, zero_lt_two, Ne,
not_false_iff, le_max_iff, pow_le_pow_iff_right₀, one_lt_two, pow_pos,
min_le_iff.1 (min_firstDiff_le x y z hxz)]
protected theorem dist_triangle (x y z : ∀ n, E n) : dist x z ≤ dist x y + dist y z :=
calc
dist x z ≤ max (dist x y) (dist y z) := dist_triangle_nonarch x y z
_ ≤ dist x y + dist y z := max_le_add_of_nonneg (PiNat.dist_nonneg _ _) (PiNat.dist_nonneg _ _)
protected theorem eq_of_dist_eq_zero (x y : ∀ n, E n) (hxy : dist x y = 0) : x = y := by
rcases eq_or_ne x y with (rfl | h); · rfl
simp [dist_eq_of_ne h] at hxy
theorem mem_cylinder_iff_dist_le {x y : ∀ n, E n} {n : ℕ} :
y ∈ cylinder x n ↔ dist y x ≤ (1 / 2) ^ n := by
rcases eq_or_ne y x with (rfl | hne)
· simp [PiNat.dist_self]
suffices (∀ i : ℕ, i < n → y i = x i) ↔ n ≤ firstDiff y x by simpa [dist_eq_of_ne hne]
constructor
· intro hy
by_contra! H
exact apply_firstDiff_ne hne (hy _ H)
· intro h i hi
exact apply_eq_of_lt_firstDiff (hi.trans_le h)
theorem apply_eq_of_dist_lt {x y : ∀ n, E n} {n : ℕ} (h : dist x y < (1 / 2) ^ n) {i : ℕ}
(hi : i ≤ n) : x i = y i := by
rcases eq_or_ne x y with (rfl | hne)
· rfl
have : n < firstDiff x y := by
simpa [dist_eq_of_ne hne, inv_lt_inv₀, pow_lt_pow_iff_right₀, one_lt_two] using h
exact apply_eq_of_lt_firstDiff (hi.trans_lt this)
/-- A function to a pseudo-metric-space is `1`-Lipschitz if and only if points in the same cylinder
of length `n` are sent to points within distance `(1/2)^n`.
Not expressed using `LipschitzWith` as we don't have a metric space structure -/
theorem lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder {α : Type*}
[PseudoMetricSpace α] {f : (∀ n, E n) → α} :
(∀ x y : ∀ n, E n, dist (f x) (f y) ≤ dist x y) ↔
∀ x y n, y ∈ cylinder x n → dist (f x) (f y) ≤ (1 / 2) ^ n := by
constructor
· intro H x y n hxy
apply (H x y).trans
rw [PiNat.dist_comm]
exact mem_cylinder_iff_dist_le.1 hxy
· intro H x y
rcases eq_or_ne x y with (rfl | hne)
· simp [PiNat.dist_nonneg]
rw [dist_eq_of_ne hne]
apply H x y (firstDiff x y)
rw [firstDiff_comm]
exact mem_cylinder_firstDiff _ _
variable (E)
variable [∀ n, TopologicalSpace (E n)] [∀ n, DiscreteTopology (E n)]
theorem isOpen_cylinder (x : ∀ n, E n) (n : ℕ) : IsOpen (cylinder x n) := by
rw [PiNat.cylinder_eq_pi]
exact isOpen_set_pi (Finset.range n).finite_toSet fun a _ => isOpen_discrete _
theorem isTopologicalBasis_cylinders :
IsTopologicalBasis { s : Set (∀ n, E n) | ∃ (x : ∀ n, E n) (n : ℕ), s = cylinder x n } := by
apply isTopologicalBasis_of_isOpen_of_nhds
· rintro u ⟨x, n, rfl⟩
apply isOpen_cylinder
· intro x u hx u_open
obtain ⟨v, ⟨U, F, -, rfl⟩, xU, Uu⟩ :
∃ v ∈ { S : Set (∀ i : ℕ, E i) | ∃ (U : ∀ i : ℕ, Set (E i)) (F : Finset ℕ),
(∀ i : ℕ, i ∈ F → U i ∈ { s : Set (E i) | IsOpen s }) ∧ S = (F : Set ℕ).pi U },
x ∈ v ∧ v ⊆ u :=
(isTopologicalBasis_pi fun n : ℕ => isTopologicalBasis_opens).exists_subset_of_mem_open hx
u_open
rcases Finset.bddAbove F with ⟨n, hn⟩
refine ⟨cylinder x (n + 1), ⟨x, n + 1, rfl⟩, self_mem_cylinder _ _, Subset.trans ?_ Uu⟩
intro y hy
suffices ∀ i : ℕ, i ∈ F → y i ∈ U i by simpa
intro i hi
have : y i = x i := mem_cylinder_iff.1 hy i ((hn hi).trans_lt (lt_add_one n))
rw [this]
simp only [Set.mem_pi, Finset.mem_coe] at xU
exact xU i hi
variable {E}
theorem isOpen_iff_dist (s : Set (∀ n, E n)) :
IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s := by
constructor
· intro hs x hx
obtain ⟨v, ⟨y, n, rfl⟩, h'x, h's⟩ :
∃ v ∈ { s | ∃ (x : ∀ n : ℕ, E n) (n : ℕ), s = cylinder x n }, x ∈ v ∧ v ⊆ s :=
(isTopologicalBasis_cylinders E).exists_subset_of_mem_open hx hs
rw [← mem_cylinder_iff_eq.1 h'x] at h's
exact
⟨(1 / 2 : ℝ) ^ n, by simp, fun y hy => h's fun i hi => (apply_eq_of_dist_lt hy hi.le).symm⟩
· intro h
refine (isTopologicalBasis_cylinders E).isOpen_iff.2 fun x hx => ?_
rcases h x hx with ⟨ε, εpos, hε⟩
obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2 : ℝ) ^ n < ε := exists_pow_lt_of_lt_one εpos one_half_lt_one
refine ⟨cylinder x n, ⟨x, n, rfl⟩, self_mem_cylinder x n, fun y hy => hε y ?_⟩
rw [PiNat.dist_comm]
exact (mem_cylinder_iff_dist_le.1 hy).trans_lt hn
/-- Metric space structure on `Π (n : ℕ), E n` when the spaces `E n` have the discrete topology,
where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and
`y` differ. Not registered as a global instance by default.
Warning: this definition makes sure that the topology is defeq to the original product topology,
but it does not take care of a possible uniformity. If the `E n` have a uniform structure, then
there will be two non-defeq uniform structures on `Π n, E n`, the product one and the one coming
from the metric structure. In this case, use `metricSpaceOfDiscreteUniformity` instead. -/
protected def metricSpace : MetricSpace (∀ n, E n) :=
MetricSpace.ofDistTopology dist PiNat.dist_self PiNat.dist_comm PiNat.dist_triangle
isOpen_iff_dist PiNat.eq_of_dist_eq_zero
/-- Metric space structure on `Π (n : ℕ), E n` when the spaces `E n` have the discrete uniformity,
where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and
`y` differ. Not registered as a global instance by default. -/
protected def metricSpaceOfDiscreteUniformity {E : ℕ → Type*} [∀ n, UniformSpace (E n)]
(h : ∀ n, uniformity (E n) = 𝓟 idRel) : MetricSpace (∀ n, E n) :=
haveI : ∀ n, DiscreteTopology (E n) := fun n => discreteTopology_of_discrete_uniformity (h n)
{ dist_triangle := PiNat.dist_triangle
dist_comm := PiNat.dist_comm
dist_self := PiNat.dist_self
eq_of_dist_eq_zero := PiNat.eq_of_dist_eq_zero _ _
toUniformSpace := Pi.uniformSpace _
uniformity_dist := by
simp only [Pi.uniformity, h, idRel, comap_principal, preimage_setOf_eq]
apply le_antisymm
· simp only [le_iInf_iff, le_principal_iff]
intro ε εpos
obtain ⟨n, hn⟩ : ∃ n, (1 / 2 : ℝ) ^ n < ε := exists_pow_lt_of_lt_one εpos (by norm_num)
apply
@mem_iInf_of_iInter _ _ _ _ _ (Finset.range n).finite_toSet fun i =>
{ p : (∀ n : ℕ, E n) × ∀ n : ℕ, E n | p.fst i = p.snd i }
· simp only [mem_principal, setOf_subset_setOf, imp_self, imp_true_iff]
· rintro ⟨x, y⟩ hxy
simp only [Finset.mem_coe, Finset.mem_range, iInter_coe_set, mem_iInter, mem_setOf_eq]
at hxy
apply lt_of_le_of_lt _ hn
rw [← mem_cylinder_iff_dist_le, mem_cylinder_iff]
exact hxy
· simp only [le_iInf_iff, le_principal_iff]
intro n
refine mem_iInf_of_mem ((1 / 2) ^ n : ℝ) ?_
refine mem_iInf_of_mem (by positivity) ?_
simp only [mem_principal, setOf_subset_setOf, Prod.forall]
intro x y hxy
exact apply_eq_of_dist_lt hxy le_rfl }
/-- Metric space structure on `ℕ → ℕ` where the distance is given by `dist x y = (1/2)^n`,
where `n` is the smallest index where `x` and `y` differ.
Not registered as a global instance by default. -/
def metricSpaceNatNat : MetricSpace (ℕ → ℕ) :=
PiNat.metricSpaceOfDiscreteUniformity fun _ => rfl
attribute [local instance] PiNat.metricSpace
protected theorem completeSpace : CompleteSpace (∀ n, E n) := by
refine Metric.complete_of_convergent_controlled_sequences (fun n => (1 / 2) ^ n) (by simp) ?_
intro u hu
refine ⟨fun n => u n n, tendsto_pi_nhds.2 fun i => ?_⟩
refine tendsto_const_nhds.congr' ?_
filter_upwards [Filter.Ici_mem_atTop i] with n hn
exact apply_eq_of_dist_lt (hu i i n le_rfl hn) le_rfl
/-!
### Retractions inside product spaces
We show that, in a space `Π (n : ℕ), E n` where each `E n` is discrete, there is a retraction on
any closed nonempty subset `s`, i.e., a continuous map `f` from the whole space to `s` restricting
to the identity on `s`. The map `f` is defined as follows. For `x ∈ s`, let `f x = x`. Otherwise,
consider the longest prefix `w` that `x` shares with an element of `s`, and let `f x = z_w`
where `z_w` is an element of `s` starting with `w`.
-/
theorem exists_disjoint_cylinder {s : Set (∀ n, E n)} (hs : IsClosed s) {x : ∀ n, E n}
(hx : x ∉ s) : ∃ n, Disjoint s (cylinder x n) := by
rcases eq_empty_or_nonempty s with (rfl | hne)
· exact ⟨0, by simp⟩
have A : 0 < infDist x s := (hs.not_mem_iff_infDist_pos hne).1 hx
obtain ⟨n, hn⟩ : ∃ n, (1 / 2 : ℝ) ^ n < infDist x s := exists_pow_lt_of_lt_one A one_half_lt_one
refine ⟨n, disjoint_left.2 fun y ys hy => ?_⟩
apply lt_irrefl (infDist x s)
calc
infDist x s ≤ dist x y := infDist_le_dist_of_mem ys
_ ≤ (1 / 2) ^ n := by
rw [mem_cylinder_comm] at hy
exact mem_cylinder_iff_dist_le.1 hy
_ < infDist x s := hn
open Classical in
/-- Given a point `x` in a product space `Π (n : ℕ), E n`, and `s` a subset of this space, then
`shortestPrefixDiff x s` if the smallest `n` for which there is no element of `s` having the same
prefix of length `n` as `x`. If there is no such `n`, then use `0` by convention. -/
def shortestPrefixDiff {E : ℕ → Type*} (x : ∀ n, E n) (s : Set (∀ n, E n)) : ℕ :=
if h : ∃ n, Disjoint s (cylinder x n) then Nat.find h else 0
theorem firstDiff_lt_shortestPrefixDiff {s : Set (∀ n, E n)} (hs : IsClosed s) {x y : ∀ n, E n}
(hx : x ∉ s) (hy : y ∈ s) : firstDiff x y < shortestPrefixDiff x s := by
have A := exists_disjoint_cylinder hs hx
rw [shortestPrefixDiff, dif_pos A]
classical
have B := Nat.find_spec A
contrapose! B
rw [not_disjoint_iff_nonempty_inter]
refine ⟨y, hy, ?_⟩
rw [mem_cylinder_comm]
exact cylinder_anti y B (mem_cylinder_firstDiff x y)
theorem shortestPrefixDiff_pos {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty)
{x : ∀ n, E n} (hx : x ∉ s) : 0 < shortestPrefixDiff x s := by
rcases hne with ⟨y, hy⟩
exact (zero_le _).trans_lt (firstDiff_lt_shortestPrefixDiff hs hx hy)
/-- Given a point `x` in a product space `Π (n : ℕ), E n`, and `s` a subset of this space, then
`longestPrefix x s` if the largest `n` for which there is an element of `s` having the same
prefix of length `n` as `x`. If there is no such `n`, use `0` by convention. -/
def longestPrefix {E : ℕ → Type*} (x : ∀ n, E n) (s : Set (∀ n, E n)) : ℕ :=
shortestPrefixDiff x s - 1
theorem firstDiff_le_longestPrefix {s : Set (∀ n, E n)} (hs : IsClosed s) {x y : ∀ n, E n}
(hx : x ∉ s) (hy : y ∈ s) : firstDiff x y ≤ longestPrefix x s := by
rw [longestPrefix, le_tsub_iff_right]
· exact firstDiff_lt_shortestPrefixDiff hs hx hy
· exact shortestPrefixDiff_pos hs ⟨y, hy⟩ hx
theorem inter_cylinder_longestPrefix_nonempty {s : Set (∀ n, E n)} (hs : IsClosed s)
(hne : s.Nonempty) (x : ∀ n, E n) : (s ∩ cylinder x (longestPrefix x s)).Nonempty := by
by_cases hx : x ∈ s
· exact ⟨x, hx, self_mem_cylinder _ _⟩
have A := exists_disjoint_cylinder hs hx
have B : longestPrefix x s < shortestPrefixDiff x s :=
Nat.pred_lt (shortestPrefixDiff_pos hs hne hx).ne'
rw [longestPrefix, shortestPrefixDiff, dif_pos A] at B ⊢
classical
obtain ⟨y, ys, hy⟩ : ∃ y : ∀ n : ℕ, E n, y ∈ s ∧ x ∈ cylinder y (Nat.find A - 1) := by
simpa only [not_disjoint_iff, mem_cylinder_comm] using Nat.find_min A B
refine ⟨y, ys, ?_⟩
rw [mem_cylinder_iff_eq] at hy ⊢
rw [hy]
theorem disjoint_cylinder_of_longestPrefix_lt {s : Set (∀ n, E n)} (hs : IsClosed s) {x : ∀ n, E n}
(hx : x ∉ s) {n : ℕ} (hn : longestPrefix x s < n) : Disjoint s (cylinder x n) := by
contrapose! hn
rcases not_disjoint_iff_nonempty_inter.1 hn with ⟨y, ys, hy⟩
apply le_trans _ (firstDiff_le_longestPrefix hs hx ys)
apply (mem_cylinder_iff_le_firstDiff (ne_of_mem_of_not_mem ys hx).symm _).1
rwa [mem_cylinder_comm]
/-- If two points `x, y` coincide up to length `n`, and the longest common prefix of `x` with `s`
is strictly shorter than `n`, then the longest common prefix of `y` with `s` is the same, and both
cylinders of this length based at `x` and `y` coincide. -/
theorem cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff {x y : ∀ n, E n}
{s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty)
(H : longestPrefix x s < firstDiff x y) (xs : x ∉ s) (ys : y ∉ s) :
cylinder x (longestPrefix x s) = cylinder y (longestPrefix y s) := by
have l_eq : longestPrefix y s = longestPrefix x s := by
rcases lt_trichotomy (longestPrefix y s) (longestPrefix x s) with (L | L | L)
· have Ax : (s ∩ cylinder x (longestPrefix x s)).Nonempty :=
inter_cylinder_longestPrefix_nonempty hs hne x
have Z := disjoint_cylinder_of_longestPrefix_lt hs ys L
rw [firstDiff_comm] at H
rw [cylinder_eq_cylinder_of_le_firstDiff _ _ H.le] at Z
exact (Ax.not_disjoint Z).elim
· exact L
· have Ay : (s ∩ cylinder y (longestPrefix y s)).Nonempty :=
inter_cylinder_longestPrefix_nonempty hs hne y
have A'y : (s ∩ cylinder y (longestPrefix x s).succ).Nonempty :=
Ay.mono (inter_subset_inter_right s (cylinder_anti _ L))
have Z := disjoint_cylinder_of_longestPrefix_lt hs xs (Nat.lt_succ_self _)
rw [cylinder_eq_cylinder_of_le_firstDiff _ _ H] at Z
exact (A'y.not_disjoint Z).elim
rw [l_eq, ← mem_cylinder_iff_eq]
exact cylinder_anti y H.le (mem_cylinder_firstDiff x y)
/-- Given a closed nonempty subset `s` of `Π (n : ℕ), E n`, there exists a Lipschitz retraction
onto this set, i.e., a Lipschitz map with range equal to `s`, equal to the identity on `s`. -/
theorem exists_lipschitz_retraction_of_isClosed {s : Set (∀ n, E n)} (hs : IsClosed s)
(hne : s.Nonempty) :
∃ f : (∀ n, E n) → ∀ n, E n, (∀ x ∈ s, f x = x) ∧ range f = s ∧ LipschitzWith 1 f := by
/- The map `f` is defined as follows. For `x ∈ s`, let `f x = x`. Otherwise, consider the longest
prefix `w` that `x` shares with an element of `s`, and let `f x = z_w` where `z_w` is an element
of `s` starting with `w`. All the desired properties are clear, except the fact that `f` is
`1`-Lipschitz: if two points `x, y` belong to a common cylinder of length `n`, one should show
that their images also belong to a common cylinder of length `n`. This is a case analysis:
* if both `x, y ∈ s`, then this is clear.
* if `x ∈ s` but `y ∉ s`, then the longest prefix `w` of `y` shared by an element of `s` is of
length at least `n` (because of `x`), and then `f y` starts with `w` and therefore stays in the
same length `n` cylinder.
* if `x ∉ s`, `y ∉ s`, let `w` be the longest prefix of `x` shared by an element of `s`. If its
length is `< n`, then it is also the longest prefix of `y`, and we get `f x = f y = z_w`.
Otherwise, `f x` remains in the same `n`-cylinder as `x`. Similarly for `y`. Finally, `f x` and
`f y` are again in the same `n`-cylinder, as desired. -/
classical
set f := fun x => if x ∈ s then x else (inter_cylinder_longestPrefix_nonempty hs hne x).some
have fs : ∀ x ∈ s, f x = x := fun x xs => by simp [f, xs]
refine ⟨f, fs, ?_, ?_⟩
-- check that the range of `f` is `s`.
| · apply Subset.antisymm
· rintro x ⟨y, rfl⟩
by_cases hy : y ∈ s
· rwa [fs y hy]
simpa [f, if_neg hy] using (inter_cylinder_longestPrefix_nonempty hs hne y).choose_spec.1
· intro x hx
rw [← fs x hx]
exact mem_range_self _
-- check that `f` is `1`-Lipschitz, by a case analysis.
· refine LipschitzWith.mk_one fun x y => ?_
-- exclude the trivial cases where `x = y`, or `f x = f y`.
rcases eq_or_ne x y with (rfl | hxy)
· simp
rcases eq_or_ne (f x) (f y) with (h' | hfxfy)
· simp [h', dist_nonneg]
have I2 : cylinder x (firstDiff x y) = cylinder y (firstDiff x y) := by
rw [← mem_cylinder_iff_eq]
apply mem_cylinder_firstDiff
suffices firstDiff x y ≤ firstDiff (f x) (f y) by
simpa [dist_eq_of_ne hxy, dist_eq_of_ne hfxfy]
-- case where `x ∈ s`
by_cases xs : x ∈ s
| Mathlib/Topology/MetricSpace/PiNat.lean | 569 | 590 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finset.Basic
import Mathlib.Data.Finset.Image
import Mathlib.Data.Multiset.Fold
/-!
# The fold operation for a commutative associative operation over a finset.
-/
assert_not_exists Monoid
namespace Finset
open Multiset
variable {α β γ : Type*}
/-! ### fold -/
section Fold
variable (op : β → β → β) [hc : Std.Commutative op] [ha : Std.Associative op]
local notation a " * " b => op a b
/-- `fold op b f s` folds the commutative associative operation `op` over the
`f`-image of `s`, i.e. `fold (+) b f {1,2,3} = f 1 + f 2 + f 3 + b`. -/
def fold (b : β) (f : α → β) (s : Finset α) : β :=
(s.1.map f).fold op b
variable {op} {f : α → β} {b : β} {s : Finset α} {a : α}
@[simp]
theorem fold_empty : (∅ : Finset α).fold op b f = b :=
rfl
@[simp]
theorem fold_cons (h : a ∉ s) : (cons a s h).fold op b f = f a * s.fold op b f := by
dsimp only [fold]
rw [cons_val, Multiset.map_cons, fold_cons_left]
@[simp]
theorem fold_insert [DecidableEq α] (h : a ∉ s) :
(insert a s).fold op b f = f a * s.fold op b f := by
unfold fold
rw [insert_val, ndinsert_of_not_mem h, Multiset.map_cons, fold_cons_left]
@[simp]
theorem fold_singleton : ({a} : Finset α).fold op b f = f a * b :=
rfl
@[simp]
theorem fold_map {g : γ ↪ α} {s : Finset γ} : (s.map g).fold op b f = s.fold op b (f ∘ g) := by
simp only [fold, map, Multiset.map_map]
@[simp]
theorem fold_image [DecidableEq α] {g : γ → α} {s : Finset γ}
(H : ∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) : (s.image g).fold op b f = s.fold op b (f ∘ g) := by
simp only [fold, image_val_of_injOn H, Multiset.map_map]
@[congr]
theorem fold_congr {g : α → β} (H : ∀ x ∈ s, f x = g x) : s.fold op b f = s.fold op b g := by
rw [fold, fold, map_congr rfl H]
theorem fold_op_distrib {f g : α → β} {b₁ b₂ : β} :
(s.fold op (b₁ * b₂) fun x => f x * g x) = s.fold op b₁ f * s.fold op b₂ g := by
simp only [fold, fold_distrib]
theorem fold_const [hd : Decidable (s = ∅)] (c : β) (h : op c (op b c) = op b c) :
Finset.fold op b (fun _ => c) s = if s = ∅ then b else op b c := by
classical
induction' s using Finset.induction_on with x s hx IH generalizing hd
· simp
· simp only [Finset.fold_insert hx, IH, if_false, Finset.insert_ne_empty]
split_ifs
· rw [hc.comm]
· exact h
theorem fold_hom {op' : γ → γ → γ} [Std.Commutative op'] [Std.Associative op'] {m : β → γ}
(hm : ∀ x y, m (op x y) = op' (m x) (m y)) :
(s.fold op' (m b) fun x => m (f x)) = m (s.fold op b f) := by
rw [fold, fold, ← Multiset.fold_hom op hm, Multiset.map_map]
simp only [Function.comp_apply]
theorem fold_disjUnion {s₁ s₂ : Finset α} {b₁ b₂ : β} (h) :
(s₁.disjUnion s₂ h).fold op (b₁ * b₂) f = s₁.fold op b₁ f * s₂.fold op b₂ f :=
(congr_arg _ <| Multiset.map_add _ _ _).trans (Multiset.fold_add _ _ _ _ _)
theorem fold_union_inter [DecidableEq α] {s₁ s₂ : Finset α} {b₁ b₂ : β} :
((s₁ ∪ s₂).fold op b₁ f * (s₁ ∩ s₂).fold op b₂ f) = s₁.fold op b₂ f * s₂.fold op b₁ f := by
unfold fold
rw [← fold_add op, ← Multiset.map_add, union_val, inter_val, union_add_inter, Multiset.map_add,
hc.comm, fold_add]
@[simp]
theorem fold_insert_idem [DecidableEq α] [hi : Std.IdempotentOp op] :
(insert a s).fold op b f = f a * s.fold op b f := by
by_cases h : a ∈ s
· rw [← insert_erase h]
simp [← ha.assoc, hi.idempotent]
· apply fold_insert h
theorem fold_image_idem [DecidableEq α] {g : γ → α} {s : Finset γ} [hi : Std.IdempotentOp op] :
(image g s).fold op b f = s.fold op b (f ∘ g) := by
induction' s using Finset.cons_induction with x xs hx ih
· rw [fold_empty, image_empty, fold_empty]
· haveI := Classical.decEq γ
rw [fold_cons, cons_eq_insert, image_insert, fold_insert_idem, ih]
simp only [Function.comp_apply]
/-- A stronger version of `Finset.fold_ite`, but relies on
an explicit proof of idempotency on the seed element, rather
than relying on typeclass idempotency over the whole type. -/
theorem fold_ite' {g : α → β} (hb : op b b = b) (p : α → Prop) [DecidablePred p] :
Finset.fold op b (fun i => ite (p i) (f i) (g i)) s =
op (Finset.fold op b f (s.filter p)) (Finset.fold op b g (s.filter fun i => ¬p i)) := by
classical
induction' s using Finset.induction_on with x s hx IH
· simp [hb]
· simp only [Finset.fold_insert hx]
split_ifs with h
· have : x ∉ Finset.filter p s := by simp [hx]
simp [Finset.filter_insert, h, Finset.fold_insert this, ha.assoc, IH]
· have : x ∉ Finset.filter (fun i => ¬ p i) s := by simp [hx]
simp [Finset.filter_insert, h, Finset.fold_insert this, IH, ← ha.assoc, hc.comm]
/-- A weaker version of `Finset.fold_ite'`,
relying on typeclass idempotency over the whole type,
instead of solely on the seed element.
However, this is easier to use because it does not generate side goals. -/
theorem fold_ite [Std.IdempotentOp op] {g : α → β} (p : α → Prop) [DecidablePred p] :
Finset.fold op b (fun i => ite (p i) (f i) (g i)) s =
op (Finset.fold op b f (s.filter p)) (Finset.fold op b g (s.filter fun i => ¬p i)) :=
fold_ite' (Std.IdempotentOp.idempotent _) _
theorem fold_op_rel_iff_and {r : β → β → Prop} (hr : ∀ {x y z}, r x (op y z) ↔ r x y ∧ r x z)
{c : β} : r c (s.fold op b f) ↔ r c b ∧ ∀ x ∈ s, r c (f x) := by
classical
induction' s using Finset.induction_on with a s ha IH
· simp
rw [Finset.fold_insert ha, hr, IH, ← and_assoc, @and_comm (r c (f a)), and_assoc]
apply and_congr Iff.rfl
constructor
· rintro ⟨h₁, h₂⟩
intro b hb
rw [Finset.mem_insert] at hb
rcases hb with (rfl | hb) <;> solve_by_elim
· intro h
constructor
· exact h a (Finset.mem_insert_self _ _)
· exact fun b hb => h b <| Finset.mem_insert_of_mem hb
theorem fold_op_rel_iff_or {r : β → β → Prop} (hr : ∀ {x y z}, r x (op y z) ↔ r x y ∨ r x z)
{c : β} : r c (s.fold op b f) ↔ r c b ∨ ∃ x ∈ s, r c (f x) := by
classical
induction' s using Finset.induction_on with a s ha IH
· simp
rw [Finset.fold_insert ha, hr, IH, ← or_assoc, @or_comm (r c (f a)), or_assoc]
apply or_congr Iff.rfl
constructor
· rintro (h₁ | ⟨x, hx, h₂⟩)
· use a
simp [h₁]
· refine ⟨x, by simp [hx], h₂⟩
· rintro ⟨x, hx, h⟩
exact (mem_insert.mp hx).imp (fun hx => by rwa [hx] at h) (fun hx => ⟨x, hx, h⟩)
@[simp]
theorem fold_union_empty_singleton [DecidableEq α] (s : Finset α) :
Finset.fold (· ∪ ·) ∅ singleton s = s := by
induction' s using Finset.induction_on with a s has ih
· simp only [fold_empty]
· rw [fold_insert has, ih, insert_eq]
theorem fold_sup_bot_singleton [DecidableEq α] (s : Finset α) :
Finset.fold (· ⊔ ·) ⊥ singleton s = s :=
fold_union_empty_singleton s
section Order
variable [LinearOrder β] (c : β)
theorem le_fold_min : c ≤ s.fold min b f ↔ c ≤ b ∧ ∀ x ∈ s, c ≤ f x :=
fold_op_rel_iff_and le_min_iff
theorem fold_min_le : s.fold min b f ≤ c ↔ b ≤ c ∨ ∃ x ∈ s, f x ≤ c := by
show _ ≥ _ ↔ _
apply fold_op_rel_iff_or
intro x y z
show _ ≤ _ ↔ _
exact min_le_iff
theorem lt_fold_min : c < s.fold min b f ↔ c < b ∧ ∀ x ∈ s, c < f x :=
fold_op_rel_iff_and lt_min_iff
theorem fold_min_lt : s.fold min b f < c ↔ b < c ∨ ∃ x ∈ s, f x < c := by
show _ > _ ↔ _
apply fold_op_rel_iff_or
intro x y z
show _ < _ ↔ _
exact min_lt_iff
theorem fold_max_le : s.fold max b f ≤ c ↔ b ≤ c ∧ ∀ x ∈ s, f x ≤ c := by
show _ ≥ _ ↔ _
apply fold_op_rel_iff_and
intro x y z
show _ ≤ _ ↔ _
exact max_le_iff
theorem le_fold_max : c ≤ s.fold max b f ↔ c ≤ b ∨ ∃ x ∈ s, c ≤ f x :=
fold_op_rel_iff_or le_max_iff
theorem fold_max_lt : s.fold max b f < c ↔ b < c ∧ ∀ x ∈ s, f x < c := by
show _ > _ ↔ _
apply fold_op_rel_iff_and
intro x y z
show _ < _ ↔ _
exact max_lt_iff
theorem lt_fold_max : c < s.fold max b f ↔ c < b ∨ ∃ x ∈ s, c < f x :=
fold_op_rel_iff_or lt_max_iff
end Order
end Fold
end Finset
| Mathlib/Data/Finset/Fold.lean | 255 | 260 | |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Batteries.Tactic.Init
import Mathlib.Logic.Function.Defs
/-!
# Binary map of options
This file defines the binary map of `Option`. This is mostly useful to define pointwise operations
on intervals.
## Main declarations
* `Option.map₂`: Binary map of options.
## Notes
This file is very similar to the n-ary section of `Mathlib.Data.Set.Basic`, to
`Mathlib.Data.Finset.NAry` and to `Mathlib.Order.Filter.NAry`. Please keep them in sync.
We do not define `Option.map₃` as its only purpose so far would be to prove properties of
`Option.map₂` and casing already fulfills this task.
-/
universe u
open Function
namespace Option
variable {α β γ δ : Type*} {f : α → β → γ} {a : Option α} {b : Option β} {c : Option γ}
/-- The image of a binary function `f : α → β → γ` as a function `Option α → Option β → Option γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def map₂ (f : α → β → γ) (a : Option α) (b : Option β) : Option γ :=
a.bind fun a => b.map <| f a
/-- `Option.map₂` in terms of monadic operations. Note that this can't be taken as the definition
because of the lack of universe polymorphism. -/
theorem map₂_def {α β γ : Type u} (f : α → β → γ) (a : Option α) (b : Option β) :
map₂ f a b = f <$> a <*> b := by
cases a <;> rfl
@[simp]
theorem map₂_some_some (f : α → β → γ) (a : α) (b : β) : map₂ f (some a) (some b) = f a b := rfl
theorem map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl
@[simp]
theorem map₂_none_left (f : α → β → γ) (b : Option β) : map₂ f none b = none := rfl
@[simp]
theorem map₂_none_right (f : α → β → γ) (a : Option α) : map₂ f a none = none := by cases a <;> rfl
@[simp]
theorem map₂_coe_left (f : α → β → γ) (a : α) (b : Option β) : map₂ f a b = b.map fun b => f a b :=
rfl
-- Porting note: This proof was `rfl` in Lean3, but now is not.
@[simp]
theorem map₂_coe_right (f : α → β → γ) (a : Option α) (b : β) :
map₂ f a b = a.map fun a => f a b := by cases a <;> rfl
theorem mem_map₂_iff {c : γ} : c ∈ map₂ f a b ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c := by
simp [map₂, bind_eq_some]
/-- `simp`-normal form of `mem_map₂_iff`. -/
@[simp]
theorem map₂_eq_some_iff {c : γ} :
map₂ f a b = some c ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c := by
simp [map₂, bind_eq_some]
@[simp]
theorem map₂_eq_none_iff : map₂ f a b = none ↔ a = none ∨ b = none := by
cases a <;> cases b <;> simp
theorem map₂_swap (f : α → β → γ) (a : Option α) (b : Option β) :
map₂ f a b = map₂ (fun a b => f b a) b a := by cases a <;> cases b <;> rfl
theorem map_map₂ (f : α → β → γ) (g : γ → δ) :
(map₂ f a b).map g = map₂ (fun a b => g (f a b)) a b := by cases a <;> cases b <;> rfl
theorem map₂_map_left (f : γ → β → δ) (g : α → γ) :
map₂ f (a.map g) b = map₂ (fun a b => f (g a) b) a b := by cases a <;> rfl
theorem map₂_map_right (f : α → γ → δ) (g : β → γ) :
map₂ f a (b.map g) = map₂ (fun a b => f a (g b)) a b := by cases b <;> rfl
@[simp]
theorem map₂_curry (f : α × β → γ) (a : Option α) (b : Option β) :
map₂ (curry f) a b = Option.map f (map₂ Prod.mk a b) := (map_map₂ _ _).symm
@[simp]
theorem map_uncurry (f : α → β → γ) (x : Option (α × β)) :
x.map (uncurry f) = map₂ f (x.map Prod.fst) (x.map Prod.snd) := by cases x <;> rfl
/-!
### Algebraic replacement rules
A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations
to the associativity, commutativity, distributivity, ... of `Option.map₂` of those operations.
The proof pattern is `map₂_lemma operation_lemma`. For example, `map₂_comm mul_comm` proves that
`map₂ (*) a b = map₂ (*) g f` in a `CommSemigroup`.
-/
variable {α' β' δ' ε ε' : Type*}
theorem map₂_assoc {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'}
(h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
map₂ f (map₂ g a b) c = map₂ f' a (map₂ g' b c) := by
cases a <;> cases b <;> cases c <;> simp [h_assoc]
theorem map₂_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : map₂ f a b = map₂ g b a := by
cases a <;> cases b <;> simp [h_comm]
theorem map₂_left_comm {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε}
(h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
map₂ f a (map₂ g b c) = map₂ g' b (map₂ f' a c) := by
cases a <;> cases b <;> cases c <;> simp [h_left_comm]
theorem map₂_right_comm {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε}
(h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
map₂ f (map₂ g a b) c = map₂ g' (map₂ f' a c) b := by
cases a <;> cases b <;> cases c <;> simp [h_right_comm]
theorem map_map₂_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
(map₂ f a b).map g = map₂ f' (a.map g₁) (b.map g₂) := by
cases a <;> cases b <;> simp [h_distrib]
/-!
The following symmetric restatement are needed because unification has a hard time figuring all the
functions if you symmetrize on the spot. This is also how the other n-ary APIs do it.
-/
/-- Symmetric statement to `Option.map₂_map_left_comm`. -/
theorem map_map₂_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
(map₂ f a b).map g = map₂ f' (a.map g') b := by cases a <;> cases b <;> simp [h_distrib]
/-- Symmetric statement to `Option.map_map₂_right_comm`. -/
theorem map_map₂_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
| (h_distrib : ∀ a b, g (f a b) = f' a (g' b)) : (map₂ f a b).map g = map₂ f' a (b.map g') := by
cases a <;> cases b <;> simp [h_distrib]
/-- Symmetric statement to `Option.map_map₂_distrib_left`. -/
| Mathlib/Data/Option/NAry.lean | 146 | 149 |
/-
Copyright (c) 2020 Alexander Bentkamp, Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Sébastien Gouëzel, Eric Wieser
-/
import Mathlib.Algebra.Algebra.RestrictScalars
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Data.Complex.Basic
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.Data.Real.Star
import Mathlib.Data.ZMod.Defs
/-!
# Complex number as a vector space over `ℝ`
This file contains the following instances:
* Any `•`-structure (`SMul`, `MulAction`, `DistribMulAction`, `Module`, `Algebra`) on
`ℝ` imbues a corresponding structure on `ℂ`. This includes the statement that `ℂ` is an `ℝ`
algebra.
* any complex vector space is a real vector space;
* any finite dimensional complex vector space is a finite dimensional real vector space;
* the space of `ℝ`-linear maps from a real vector space to a complex vector space is a complex
vector space.
It also defines bundled versions of four standard maps (respectively, the real part, the imaginary
part, the embedding of `ℝ` in `ℂ`, and the complex conjugate):
* `Complex.reLm` (`ℝ`-linear map);
* `Complex.imLm` (`ℝ`-linear map);
* `Complex.ofRealAm` (`ℝ`-algebra (homo)morphism);
* `Complex.conjAe` (`ℝ`-algebra equivalence).
It also provides a universal property of the complex numbers `Complex.lift`, which constructs a
`ℂ →ₐ[ℝ] A` into any `ℝ`-algebra `A` given a square root of `-1`.
In addition, this file provides a decomposition into `realPart` and `imaginaryPart` for any
element of a `StarModule` over `ℂ`.
## Notation
* `ℜ` and `ℑ` for the `realPart` and `imaginaryPart`, respectively, in the locale
`ComplexStarModule`.
-/
assert_not_exists NNReal
namespace Complex
open ComplexConjugate
open scoped SMul
variable {R : Type*} {S : Type*}
attribute [local ext] Complex.ext
/- The priority of the following instances has been manually lowered, as when they don't apply
they lead Lean to a very costly path, and most often they don't apply (most actions on `ℂ` don't
come from actions on `ℝ`). See https://github.com/leanprover-community/mathlib4/pull/11980 -/
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 90) [SMul R ℝ] [SMul S ℝ] [SMulCommClass R S ℝ] : SMulCommClass R S ℂ where
smul_comm r s x := by ext <;> simp [smul_re, smul_im, smul_comm]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 90) [SMul R S] [SMul R ℝ] [SMul S ℝ] [IsScalarTower R S ℝ] :
IsScalarTower R S ℂ where
smul_assoc r s x := by ext <;> simp [smul_re, smul_im, smul_assoc]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 90) [SMul R ℝ] [SMul Rᵐᵒᵖ ℝ] [IsCentralScalar R ℝ] :
IsCentralScalar R ℂ where
op_smul_eq_smul r x := by ext <;> simp [smul_re, smul_im, op_smul_eq_smul]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 90) mulAction [Monoid R] [MulAction R ℝ] : MulAction R ℂ where
one_smul x := by ext <;> simp [smul_re, smul_im, one_smul]
mul_smul r s x := by ext <;> simp [smul_re, smul_im, mul_smul]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 90) distribSMul [DistribSMul R ℝ] : DistribSMul R ℂ where
smul_add r x y := by ext <;> simp [smul_re, smul_im, smul_add]
smul_zero r := by ext <;> simp [smul_re, smul_im, smul_zero]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 90) [Semiring R] [DistribMulAction R ℝ] : DistribMulAction R ℂ :=
{ Complex.distribSMul, Complex.mulAction with }
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 100) instModule [Semiring R] [Module R ℝ] : Module R ℂ where
add_smul r s x := by ext <;> simp [smul_re, smul_im, add_smul]
zero_smul r := by ext <;> simp [smul_re, smul_im, zero_smul]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980
instance (priority := 95) instAlgebraOfReal [CommSemiring R] [Algebra R ℝ] : Algebra R ℂ where
algebraMap := Complex.ofRealHom.comp (algebraMap R ℝ)
smul := (· • ·)
smul_def' := fun r x => by ext <;> simp [smul_re, smul_im, Algebra.smul_def]
commutes' := fun r ⟨xr, xi⟩ => by ext <;> simp [smul_re, smul_im, Algebra.commutes]
instance : StarModule ℝ ℂ :=
⟨fun r x => by simp only [star_def, star_trivial, real_smul, map_mul, conj_ofReal]⟩
@[simp]
theorem coe_algebraMap : (algebraMap ℝ ℂ : ℝ → ℂ) = ((↑) : ℝ → ℂ) :=
rfl
section
variable {A : Type*} [Semiring A] [Algebra ℝ A]
/-- We need this lemma since `Complex.coe_algebraMap` diverts the simp-normal form away from
`AlgHom.commutes`. -/
@[simp]
theorem _root_.AlgHom.map_coe_real_complex (f : ℂ →ₐ[ℝ] A) (x : ℝ) : f x = algebraMap ℝ A x :=
f.commutes x
/-- Two `ℝ`-algebra homomorphisms from `ℂ` are equal if they agree on `Complex.I`. -/
@[ext]
theorem algHom_ext ⦃f g : ℂ →ₐ[ℝ] A⦄ (h : f I = g I) : f = g := by
ext ⟨x, y⟩
simp only [mk_eq_add_mul_I, map_add, AlgHom.map_coe_real_complex, map_mul, h]
end
open Submodule
/-- `ℂ` has a basis over `ℝ` given by `1` and `I`. -/
noncomputable def basisOneI : Basis (Fin 2) ℝ ℂ :=
Basis.ofEquivFun
{ toFun := fun z => ![z.re, z.im]
invFun := fun c => c 0 + c 1 • I
left_inv := fun z => by simp
right_inv := fun c => by
ext i
fin_cases i <;> simp
map_add' := fun z z' => by simp
map_smul' := fun c z => by simp }
@[simp]
theorem coe_basisOneI_repr (z : ℂ) : ⇑(basisOneI.repr z) = ![z.re, z.im] :=
rfl
@[simp]
theorem coe_basisOneI : ⇑basisOneI = ![1, I] :=
funext fun i =>
Basis.apply_eq_iff.mpr <|
Finsupp.ext fun j => by
fin_cases i <;> fin_cases j <;> simp
end Complex
/- Register as an instance (with low priority) the fact that a complex vector space is also a real
vector space. -/
instance (priority := 900) Module.complexToReal (E : Type*) [AddCommGroup E] [Module ℂ E] :
Module ℝ E :=
RestrictScalars.module ℝ ℂ E
/- Register as an instance (with low priority) the fact that a complex algebra is also a real
algebra. -/
instance (priority := 900) Algebra.complexToReal {A : Type*} [Semiring A] [Algebra ℂ A] :
Algebra ℝ A :=
RestrictScalars.algebra ℝ ℂ A
-- try to make sure we're not introducing diamonds but we will need
-- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906
example : Prod.algebra ℝ ℂ ℂ = (Prod.algebra ℂ ℂ ℂ).complexToReal := rfl
-- try to make sure we're not introducing diamonds but we will need
-- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906
example {ι : Type*} [Fintype ι] :
Pi.algebra (R := ℝ) ι (fun _ ↦ ℂ) = (Pi.algebra (R := ℂ) ι (fun _ ↦ ℂ)).complexToReal :=
rfl
example {A : Type*} [Ring A] [inst : Algebra ℂ A] :
(inst.complexToReal).toModule = (inst.toModule).complexToReal := by
with_reducible_and_instances rfl
@[simp, norm_cast]
theorem Complex.coe_smul {E : Type*} [AddCommGroup E] [Module ℂ E] (x : ℝ) (y : E) :
(x : ℂ) • y = x • y :=
rfl
/-- The scalar action of `ℝ` on a `ℂ`-module `E` induced by `Module.complexToReal` commutes with
another scalar action of `M` on `E` whenever the action of `ℂ` commutes with the action of `M`. -/
instance (priority := 900) SMulCommClass.complexToReal {M E : Type*} [AddCommGroup E] [Module ℂ E]
[SMul M E] [SMulCommClass ℂ M E] : SMulCommClass ℝ M E where
smul_comm r _ _ := smul_comm (r : ℂ) _ _
/-- The scalar action of `ℝ` on a `ℂ`-module `E` induced by `Module.complexToReal` associates with
another scalar action of `M` on `E` whenever the action of `ℂ` associates with the action of `M`. -/
instance IsScalarTower.complexToReal {M E : Type*} [AddCommGroup M] [Module ℂ M] [AddCommGroup E]
[Module ℂ E] [SMul M E] [IsScalarTower ℂ M E] : IsScalarTower ℝ M E where
smul_assoc r _ _ := smul_assoc (r : ℂ) _ _
-- check that the following instance is implied by the one above.
example (E : Type*) [AddCommGroup E] [Module ℂ E] : IsScalarTower ℝ ℂ E := inferInstance
instance (priority := 900) StarModule.complexToReal {E : Type*} [AddCommGroup E] [Star E]
[Module ℂ E] [StarModule ℂ E] : StarModule ℝ E :=
⟨fun r a => by rw [← smul_one_smul ℂ r a, star_smul, star_smul, star_one, smul_one_smul]⟩
namespace Complex
open ComplexConjugate
/-- Linear map version of the real part function, from `ℂ` to `ℝ`. -/
def reLm : ℂ →ₗ[ℝ] ℝ where
toFun x := x.re
map_add' := add_re
map_smul' := by simp
@[simp]
theorem reLm_coe : ⇑reLm = re :=
rfl
/-- Linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/
def imLm : ℂ →ₗ[ℝ] ℝ where
toFun x := x.im
map_add' := add_im
map_smul' := by simp
@[simp]
theorem imLm_coe : ⇑imLm = im :=
rfl
/-- `ℝ`-algebra morphism version of the canonical embedding of `ℝ` in `ℂ`. -/
def ofRealAm : ℝ →ₐ[ℝ] ℂ :=
Algebra.ofId ℝ ℂ
@[simp]
theorem ofRealAm_coe : ⇑ofRealAm = ((↑) : ℝ → ℂ) :=
rfl
/-- `ℝ`-algebra isomorphism version of the complex conjugation function from `ℂ` to `ℂ` -/
def conjAe : ℂ ≃ₐ[ℝ] ℂ :=
{ conj with
invFun := conj
left_inv := star_star
right_inv := star_star
commutes' := conj_ofReal }
@[simp]
theorem conjAe_coe : ⇑conjAe = conj :=
rfl
/-- The matrix representation of `conjAe`. -/
@[simp]
theorem toMatrix_conjAe :
LinearMap.toMatrix basisOneI basisOneI conjAe.toLinearMap = !![1, 0; 0, -1] := by
ext i j
fin_cases i <;> fin_cases j <;> simp [LinearMap.toMatrix_apply]
/-- The identity and the complex conjugation are the only two `ℝ`-algebra homomorphisms of `ℂ`. -/
theorem real_algHom_eq_id_or_conj (f : ℂ →ₐ[ℝ] ℂ) : f = AlgHom.id ℝ ℂ ∨ f = conjAe := by
refine
(eq_or_eq_neg_of_sq_eq_sq (f I) I <| by rw [← map_pow, I_sq, map_neg, map_one]).imp ?_ ?_ <;>
refine fun h => algHom_ext ?_
exacts [h, conj_I.symm ▸ h]
/-- The natural `LinearEquiv` from `ℂ` to `ℝ × ℝ`. -/
@[simps! +simpRhs apply symm_apply_re symm_apply_im]
def equivRealProdLm : ℂ ≃ₗ[ℝ] ℝ × ℝ :=
{ equivRealProdAddHom with
map_smul' := fun r c => by simp }
theorem equivRealProdLm_symm_apply (p : ℝ × ℝ) :
Complex.equivRealProdLm.symm p = p.1 + p.2 * Complex.I := Complex.equivRealProd_symm_apply p
section lift
variable {A : Type*} [Ring A] [Algebra ℝ A]
/-- There is an alg_hom from `ℂ` to any `ℝ`-algebra with an element that squares to `-1`.
See `Complex.lift` for this as an equiv. -/
def liftAux (I' : A) (hf : I' * I' = -1) : ℂ →ₐ[ℝ] A :=
AlgHom.ofLinearMap
((Algebra.linearMap ℝ A).comp reLm + (LinearMap.toSpanSingleton _ _ I').comp imLm)
(show algebraMap ℝ A 1 + (0 : ℝ) • I' = 1 by rw [RingHom.map_one, zero_smul, add_zero])
fun ⟨x₁, y₁⟩ ⟨x₂, y₂⟩ =>
show
algebraMap ℝ A (x₁ * x₂ - y₁ * y₂) + (x₁ * y₂ + y₁ * x₂) • I' =
(algebraMap ℝ A x₁ + y₁ • I') * (algebraMap ℝ A x₂ + y₂ • I') by
rw [add_mul, mul_add, mul_add, add_comm _ (y₁ • I' * y₂ • I'), add_add_add_comm]
congr 1
-- equate "real" and "imaginary" parts
· rw [smul_mul_smul_comm, hf, smul_neg, ← Algebra.algebraMap_eq_smul_one, ← sub_eq_add_neg,
← RingHom.map_mul, ← RingHom.map_sub]
· rw [Algebra.smul_def, Algebra.smul_def, Algebra.smul_def, ← Algebra.right_comm _ x₂,
← mul_assoc, ← add_mul, ← RingHom.map_mul, ← RingHom.map_mul, ← RingHom.map_add]
@[simp]
theorem liftAux_apply (I' : A) (hI') (z : ℂ) : liftAux I' hI' z = algebraMap ℝ A z.re + z.im • I' :=
rfl
theorem liftAux_apply_I (I' : A) (hI') : liftAux I' hI' I = I' := by simp
/-- A universal property of the complex numbers, providing a unique `ℂ →ₐ[ℝ] A` for every element
of `A` which squares to `-1`.
This can be used to embed the complex numbers in the `Quaternion`s.
This isomorphism is named to match the very similar `Zsqrtd.lift`. -/
@[simps +simpRhs]
def lift : { I' : A // I' * I' = -1 } ≃ (ℂ →ₐ[ℝ] A) where
toFun I' := liftAux I' I'.prop
invFun F := ⟨F I, by rw [← map_mul, I_mul_I, map_neg, map_one]⟩
left_inv I' := Subtype.ext <| liftAux_apply_I (I' : A) I'.prop
right_inv _ := algHom_ext <| liftAux_apply_I _ _
-- When applied to `Complex.I` itself, `lift` is the identity.
@[simp]
theorem liftAux_I : liftAux I I_mul_I = AlgHom.id ℝ ℂ :=
algHom_ext <| liftAux_apply_I _ _
-- When applied to `-Complex.I`, `lift` is conjugation, `conj`.
@[simp]
theorem liftAux_neg_I : liftAux (-I) ((neg_mul_neg _ _).trans I_mul_I) = conjAe :=
algHom_ext <| (liftAux_apply_I _ _).trans conj_I.symm
end lift
end Complex
section RealImaginaryPart
open Complex
variable {A : Type*} [AddCommGroup A] [Module ℂ A] [StarAddMonoid A] [StarModule ℂ A]
/-- Create a `selfAdjoint` element from a `skewAdjoint` element by multiplying by the scalar
`-Complex.I`. -/
@[simps]
def skewAdjoint.negISMul : skewAdjoint A →ₗ[ℝ] selfAdjoint A where
toFun a :=
⟨-I • ↑a, by
simp only [neg_smul, neg_mem_iff, selfAdjoint.mem_iff, star_smul, star_def, conj_I,
star_val_eq, smul_neg, neg_neg]⟩
map_add' a b := by
ext
simp only [AddSubgroup.coe_add, smul_add, AddMemClass.mk_add_mk]
map_smul' a b := by
ext
simp only [neg_smul, skewAdjoint.val_smul, AddSubgroup.coe_mk, RingHom.id_apply,
selfAdjoint.val_smul, smul_neg, neg_inj]
rw [smul_comm]
theorem skewAdjoint.I_smul_neg_I (a : skewAdjoint A) : I • (skewAdjoint.negISMul a : A) = a := by
simp only [smul_smul, skewAdjoint.negISMul_apply_coe, neg_smul, smul_neg, I_mul_I, one_smul,
neg_neg]
/-- The real part `ℜ a` of an element `a` of a star module over `ℂ`, as a linear map. This is just
`selfAdjointPart ℝ`, but we provide it as a separate definition in order to link it with lemmas
concerning the `imaginaryPart`, which doesn't exist in star modules over other rings. -/
noncomputable def realPart : A →ₗ[ℝ] selfAdjoint A :=
selfAdjointPart ℝ
/-- The imaginary part `ℑ a` of an element `a` of a star module over `ℂ`, as a linear map into the
self adjoint elements. In a general star module, we have a decomposition into the `selfAdjoint`
and `skewAdjoint` parts, but in a star module over `ℂ` we have
`realPart_add_I_smul_imaginaryPart`, which allows us to decompose into a linear combination of
`selfAdjoint`s. -/
noncomputable def imaginaryPart : A →ₗ[ℝ] selfAdjoint A :=
skewAdjoint.negISMul.comp (skewAdjointPart ℝ)
@[inherit_doc]
scoped[ComplexStarModule] notation "ℜ" => realPart
@[inherit_doc]
scoped[ComplexStarModule] notation "ℑ" => imaginaryPart
open ComplexStarModule
theorem realPart_apply_coe (a : A) : (ℜ a : A) = (2 : ℝ)⁻¹ • (a + star a) := by
unfold realPart
simp only [selfAdjointPart_apply_coe, invOf_eq_inv]
theorem imaginaryPart_apply_coe (a : A) : (ℑ a : A) = -I • (2 : ℝ)⁻¹ • (a - star a) := by
unfold imaginaryPart
simp only [LinearMap.coe_comp, Function.comp_apply, skewAdjoint.negISMul_apply_coe,
skewAdjointPart_apply_coe, invOf_eq_inv, neg_smul]
/-- The standard decomposition of `ℜ a + Complex.I • ℑ a = a` of an element of a star module over
`ℂ` into a linear combination of self adjoint elements. -/
theorem realPart_add_I_smul_imaginaryPart (a : A) : (ℜ a : A) + I • (ℑ a : A) = a := by
simpa only [smul_smul, realPart_apply_coe, imaginaryPart_apply_coe, neg_smul, I_mul_I, one_smul,
neg_sub, add_add_sub_cancel, smul_sub, smul_add, neg_sub_neg, invOf_eq_inv] using
invOf_two_smul_add_invOf_two_smul ℝ a
@[simp]
theorem realPart_I_smul (a : A) : ℜ (I • a) = -ℑ a := by
ext
simp [realPart_apply_coe, imaginaryPart_apply_coe, smul_comm I, sub_eq_add_neg, add_comm]
@[simp]
theorem imaginaryPart_I_smul (a : A) : ℑ (I • a) = ℜ a := by
ext
simp [realPart_apply_coe, imaginaryPart_apply_coe, smul_comm I (2⁻¹ : ℝ), smul_smul I]
theorem realPart_smul (z : ℂ) (a : A) : ℜ (z • a) = z.re • ℜ a - z.im • ℑ a := by
have := by congrm (ℜ ($((re_add_im z).symm) • a))
simpa [-re_add_im, add_smul, ← smul_smul, sub_eq_add_neg]
theorem imaginaryPart_smul (z : ℂ) (a : A) : ℑ (z • a) = z.re • ℑ a + z.im • ℜ a := by
have := by congrm (ℑ ($((re_add_im z).symm) • a))
simpa [-re_add_im, add_smul, ← smul_smul]
lemma skewAdjointPart_eq_I_smul_imaginaryPart (x : A) :
(skewAdjointPart ℝ x : A) = I • (imaginaryPart x : A) := by
simp [imaginaryPart_apply_coe, smul_smul]
lemma imaginaryPart_eq_neg_I_smul_skewAdjointPart (x : A) :
(imaginaryPart x : A) = -I • (skewAdjointPart ℝ x : A) :=
rfl
lemma IsSelfAdjoint.coe_realPart {x : A} (hx : IsSelfAdjoint x) :
(ℜ x : A) = x :=
hx.coe_selfAdjointPart_apply ℝ
nonrec lemma IsSelfAdjoint.imaginaryPart {x : A} (hx : IsSelfAdjoint x) :
ℑ x = 0 := by
rw [imaginaryPart, LinearMap.comp_apply, hx.skewAdjointPart_apply _, map_zero]
lemma realPart_comp_subtype_selfAdjoint :
realPart.comp (selfAdjoint.submodule ℝ A).subtype = LinearMap.id :=
selfAdjointPart_comp_subtype_selfAdjoint ℝ
lemma imaginaryPart_comp_subtype_selfAdjoint :
imaginaryPart.comp (selfAdjoint.submodule ℝ A).subtype = 0 := by
rw [imaginaryPart, LinearMap.comp_assoc, skewAdjointPart_comp_subtype_selfAdjoint,
LinearMap.comp_zero]
@[simp]
lemma imaginaryPart_realPart {x : A} : ℑ (ℜ x : A) = 0 :=
(ℜ x).property.imaginaryPart
@[simp]
lemma imaginaryPart_imaginaryPart {x : A} : ℑ (ℑ x : A) = 0 :=
(ℑ x).property.imaginaryPart
@[simp]
lemma realPart_idem {x : A} : ℜ (ℜ x : A) = ℜ x :=
Subtype.ext <| (ℜ x).property.coe_realPart
@[simp]
lemma realPart_imaginaryPart {x : A} : ℜ (ℑ x : A) = ℑ x :=
Subtype.ext <| (ℑ x).property.coe_realPart
lemma realPart_surjective : Function.Surjective (realPart (A := A)) :=
fun x ↦ ⟨(x : A), Subtype.ext x.property.coe_realPart⟩
lemma imaginaryPart_surjective : Function.Surjective (imaginaryPart (A := A)) :=
fun x ↦
⟨I • (x : A), Subtype.ext <| by simp only [imaginaryPart_I_smul, x.property.coe_realPart]⟩
open Submodule
lemma span_selfAdjoint : span ℂ (selfAdjoint A : Set A) = ⊤ := by
refine eq_top_iff'.mpr fun x ↦ ?_
rw [← realPart_add_I_smul_imaginaryPart x]
exact add_mem (subset_span (ℜ x).property) <|
SMulMemClass.smul_mem _ <| subset_span (ℑ x).property
/-- The natural `ℝ`-linear equivalence between `selfAdjoint ℂ` and `ℝ`. -/
@[simps apply symm_apply]
def Complex.selfAdjointEquiv : selfAdjoint ℂ ≃ₗ[ℝ] ℝ where
toFun := fun z ↦ (z : ℂ).re
invFun := fun x ↦ ⟨x, conj_ofReal x⟩
left_inv := fun z ↦ Subtype.ext <| conj_eq_iff_re.mp z.property.star_eq
right_inv := fun _ ↦ rfl
map_add' := by simp
map_smul' := by simp
lemma Complex.coe_selfAdjointEquiv (z : selfAdjoint ℂ) :
(selfAdjointEquiv z : ℂ) = z := by
simpa [selfAdjointEquiv_symm_apply]
using (congr_arg Subtype.val <| Complex.selfAdjointEquiv.left_inv z)
@[simp]
lemma realPart_ofReal (r : ℝ) : (ℜ (r : ℂ) : ℂ) = r := by
rw [realPart_apply_coe, star_def, conj_ofReal, ← two_smul ℝ (r : ℂ)]
simp
@[simp]
lemma imaginaryPart_ofReal (r : ℝ) : ℑ (r : ℂ) = 0 := by
ext1; simp [imaginaryPart_apply_coe, conj_ofReal]
lemma Complex.coe_realPart (z : ℂ) : (ℜ z : ℂ) = z.re := calc
(ℜ z : ℂ) = (↑(ℜ (↑z.re + ↑z.im * I))) := by congrm (ℜ $((re_add_im z).symm))
_ = z.re := by
rw [map_add, AddSubmonoid.coe_add, mul_comm, ← smul_eq_mul, realPart_I_smul]
simp [conj_ofReal, ← two_mul]
lemma star_mul_self_add_self_mul_star {A : Type*} [NonUnitalNonAssocRing A] [StarRing A]
[Module ℂ A] [IsScalarTower ℂ A A] [SMulCommClass ℂ A A] [StarModule ℂ A] (a : A) :
star a * a + a * star a = 2 • (ℜ a * ℜ a + ℑ a * ℑ a) :=
have a_eq := (realPart_add_I_smul_imaginaryPart a).symm
calc
star a * a + a * star a = _ :=
congr((star $(a_eq)) * $(a_eq) + $(a_eq) * (star $(a_eq)))
_ = 2 • (ℜ a * ℜ a + ℑ a * ℑ a) := by
simp [mul_add, add_mul, smul_smul, two_smul, mul_smul_comm,
smul_mul_assoc]
abel
end RealImaginaryPart
| Mathlib/Data/Complex/Module.lean | 550 | 552 | |
/-
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.Interval
import Mathlib.Order.Interval.Set.Pi
import Mathlib.Tactic.TFAE
import Mathlib.Tactic.NormNum
import Mathlib.Topology.Order.LeftRight
import Mathlib.Topology.Order.OrderClosed
/-!
# Theory of topology on ordered spaces
## Main definitions
The order topology on an ordered space is the topology generated by all open intervals (or
equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `Preorder.topology α`.
However, we do *not* register it as an instance (as many existing ordered types already have
topologies, which would be equal but not definitionally equal to `Preorder.topology α`). Instead,
we introduce a class `OrderTopology α` (which is a `Prop`, also known as a mixin) saying that on
the type `α` having already a topological space structure and a preorder structure, the topological
structure is equal to the order topology.
We prove many basic properties of such topologies.
## Main statements
This file contains the proofs of the following facts. For exact requirements
(`OrderClosedTopology` vs `OrderTopology`, `Preorder` vs `PartialOrder` vs `LinearOrder` etc)
see their statements.
* `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any
neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood
of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`.
* `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem,
sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h`
both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`.
## Implementation notes
We do _not_ register the order topology as an instance on a preorder (or even on a linear order).
Indeed, on many such spaces, a topology has already been constructed in a different way (think
of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`),
and is in general not defeq to the one generated by the intervals. We make it available as a
definition `Preorder.topology α` though, that can be registered as an instance when necessary, or
for specific types.
-/
open Set Filter TopologicalSpace Topology Function
open OrderDual (toDual ofDual)
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
-- TODO: define `Preorder.topology` before `OrderTopology` and reuse the def
/-- The order topology on an ordered type is the topology generated by open intervals. We register
it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed.
We define it as a mixin. If you want to introduce the order topology on a preorder, use
`Preorder.topology`. -/
class OrderTopology (α : Type*) [t : TopologicalSpace α] [Preorder α] : Prop where
/-- The topology is generated by open intervals `Set.Ioi _` and `Set.Iio _`. -/
topology_eq_generate_intervals : t = generateFrom { s | ∃ a, s = Ioi a ∨ s = Iio a }
/-- (Order) topology on a partial order `α` generated by the subbase of open intervals
`(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an
instance as many ordered sets are already endowed with the same topology, most often in a non-defeq
way though. Register as a local instance when necessary. -/
def Preorder.topology (α : Type*) [Preorder α] : TopologicalSpace α :=
generateFrom { s : Set α | ∃ a : α, s = { b : α | a < b } ∨ s = { b : α | b < a } }
section OrderTopology
section Preorder
variable [TopologicalSpace α] [Preorder α]
instance [t : OrderTopology α] : OrderTopology αᵒᵈ :=
⟨by
convert OrderTopology.topology_eq_generate_intervals (α := α) using 6
apply or_comm⟩
theorem isOpen_iff_generate_intervals [t : OrderTopology α] {s : Set α} :
IsOpen s ↔ GenerateOpen { s | ∃ a, s = Ioi a ∨ s = Iio a } s := by
rw [t.topology_eq_generate_intervals]; rfl
theorem isOpen_lt' [OrderTopology α] (a : α) : IsOpen { b : α | a < b } :=
isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inl rfl⟩
theorem isOpen_gt' [OrderTopology α] (a : α) : IsOpen { b : α | b < a } :=
isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inr rfl⟩
theorem lt_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a < x :=
(isOpen_lt' _).mem_nhds h
theorem le_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x :=
(lt_mem_nhds h).mono fun _ => le_of_lt
theorem gt_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b :=
(isOpen_gt' _).mem_nhds h
theorem ge_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b :=
(gt_mem_nhds h).mono fun _ => le_of_lt
theorem nhds_eq_order [OrderTopology α] (a : α) :
𝓝 a = (⨅ b ∈ Iio a, 𝓟 (Ioi b)) ⊓ ⨅ b ∈ Ioi a, 𝓟 (Iio b) := by
rw [OrderTopology.topology_eq_generate_intervals (α := α), nhds_generateFrom]
simp_rw [mem_setOf_eq, @and_comm (a ∈ _), exists_or, or_and_right, iInf_or, iInf_and,
iInf_exists, iInf_inf_eq, iInf_comm (ι := Set α), iInf_iInf_eq_left, mem_Ioi, mem_Iio]
theorem tendsto_order [OrderTopology α] {f : β → α} {a : α} {x : Filter β} :
Tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ ∀ a' > a, ∀ᶠ b in x, f b < a' := by
simp only [nhds_eq_order a, tendsto_inf, tendsto_iInf, tendsto_principal]; rfl
instance tendstoIccClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Icc (𝓝 a) (𝓝 a) := by
simp only [nhds_eq_order, iInf_subtype']
refine
((hasBasis_iInf_principal_finite _).inf (hasBasis_iInf_principal_finite _)).tendstoIxxClass
fun s _ => ?_
refine ((ordConnected_biInter ?_).inter (ordConnected_biInter ?_)).out <;> intro _ _
exacts [ordConnected_Ioi, ordConnected_Iio]
instance tendstoIcoClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ico (𝓝 a) (𝓝 a) :=
tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self
instance tendstoIocClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ioc (𝓝 a) (𝓝 a) :=
tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self
instance tendstoIooClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ioo (𝓝 a) (𝓝 a) :=
tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self
/-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities
hold eventually for the filter. -/
theorem tendsto_of_tendsto_of_tendsto_of_le_of_le' [OrderTopology α] {f g h : β → α} {b : Filter β}
{a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : ∀ᶠ b in b, g b ≤ f b)
(hfh : ∀ᶠ b in b, f b ≤ h b) : Tendsto f b (𝓝 a) :=
(hg.Icc hh).of_smallSets <| hgf.and hfh
alias Filter.Tendsto.squeeze' := tendsto_of_tendsto_of_tendsto_of_le_of_le'
/-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities
hold everywhere. -/
theorem tendsto_of_tendsto_of_tendsto_of_le_of_le [OrderTopology α] {f g h : β → α} {b : Filter β}
{a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) :
Tendsto f b (𝓝 a) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh (Eventually.of_forall hgf)
(Eventually.of_forall hfh)
alias Filter.Tendsto.squeeze := tendsto_of_tendsto_of_tendsto_of_le_of_le
theorem nhds_order_unbounded [OrderTopology α] {a : α} (hu : ∃ u, a < u) (hl : ∃ l, l < a) :
𝓝 a = ⨅ (l) (_ : l < a) (u) (_ : a < u), 𝓟 (Ioo l u) := by
simp only [nhds_eq_order, ← inf_biInf, ← biInf_inf, *, ← inf_principal, ← Ioi_inter_Iio]; rfl
theorem tendsto_order_unbounded [OrderTopology α] {f : β → α} {a : α} {x : Filter β}
(hu : ∃ u, a < u) (hl : ∃ l, l < a) (h : ∀ l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) :
Tendsto f x (𝓝 a) := by
simp only [nhds_order_unbounded hu hl, tendsto_iInf, tendsto_principal]
exact fun l hl u => h l u hl
end Preorder
instance tendstoIxxNhdsWithin {α : Type*} [TopologicalSpace α] (a : α) {s t : Set α}
{Ixx} [TendstoIxxClass Ixx (𝓝 a) (𝓝 a)] [TendstoIxxClass Ixx (𝓟 s) (𝓟 t)] :
TendstoIxxClass Ixx (𝓝[s] a) (𝓝[t] a) :=
Filter.tendstoIxxClass_inf
instance tendstoIccClassNhdsPi {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)]
[∀ i, TopologicalSpace (α i)] [∀ i, OrderTopology (α i)] (f : ∀ i, α i) :
TendstoIxxClass Icc (𝓝 f) (𝓝 f) := by
constructor
conv in (𝓝 f).smallSets => rw [nhds_pi, Filter.pi]
simp only [smallSets_iInf, smallSets_comap_eq_comap_image, tendsto_iInf, tendsto_comap_iff]
intro i
have : Tendsto (fun g : ∀ i, α i => g i) (𝓝 f) (𝓝 (f i)) := (continuous_apply i).tendsto f
refine (this.comp tendsto_fst).Icc (this.comp tendsto_snd) |>.smallSets_mono ?_
filter_upwards [] using fun ⟨f, g⟩ ↦ image_subset_iff.mpr fun p hp ↦ ⟨hp.1 i, hp.2 i⟩
theorem induced_topology_le_preorder [Preorder α] [Preorder β] [TopologicalSpace β]
[OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y) :
induced f ‹TopologicalSpace β› ≤ Preorder.topology α := by
let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩
refine le_of_nhds_le_nhds fun x => ?_
simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal, Ioi, Iio, ← hf]
refine inf_le_inf (le_iInf₂ fun a ha => ?_) (le_iInf₂ fun a ha => ?_)
exacts [iInf₂_le (f a) ha, iInf₂_le (f a) ha]
theorem induced_topology_eq_preorder [Preorder α] [Preorder β] [TopologicalSpace β]
[OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y)
(H₁ : ∀ {a b x}, b < f a → ¬(b < f x) → ∃ y, y < a ∧ b ≤ f y)
(H₂ : ∀ {a b x}, f a < b → ¬(f x < b) → ∃ y, a < y ∧ f y ≤ b) :
induced f ‹TopologicalSpace β› = Preorder.topology α := by
let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩
refine le_antisymm (induced_topology_le_preorder hf) ?_
refine le_of_nhds_le_nhds fun a => ?_
simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal]
refine inf_le_inf (le_iInf₂ fun b hb => ?_) (le_iInf₂ fun b hb => ?_)
· rcases em (∃ x, ¬(b < f x)) with (⟨x, hx⟩ | hb)
· rcases H₁ hb hx with ⟨y, hya, hyb⟩
exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => hyb.trans_lt (hf.2 hz))
· push_neg at hb
exact le_principal_iff.2 (univ_mem' hb)
· rcases em (∃ x, ¬(f x < b)) with (⟨x, hx⟩ | hb)
· rcases H₂ hb hx with ⟨y, hya, hyb⟩
exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => (hf.2 hz).trans_le hyb)
· push_neg at hb
exact le_principal_iff.2 (univ_mem' hb)
theorem induced_orderTopology' {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β]
[Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) :
@OrderTopology _ (induced f ta) _ :=
let _ := induced f ta
⟨induced_topology_eq_preorder hf (fun h _ => H₁ h) (fun h _ => H₂ h)⟩
theorem induced_orderTopology {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β]
[Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @OrderTopology _ (induced f ta) _ :=
induced_orderTopology' f (hf)
(fun xa => let ⟨b, xb, ba⟩ := H xa; ⟨b, hf.1 ba, le_of_lt xb⟩)
fun ax => let ⟨b, ab, bx⟩ := H ax; ⟨b, hf.1 ab, le_of_lt bx⟩
/-- The topology induced by a strictly monotone function with order-connected range is the preorder
topology. -/
nonrec theorem StrictMono.induced_topology_eq_preorder {α β : Type*} [LinearOrder α]
[LinearOrder β] [t : TopologicalSpace β] [OrderTopology β] {f : α → β}
(hf : StrictMono f) (hc : OrdConnected (range f)) : t.induced f = Preorder.topology α := by
refine induced_topology_eq_preorder hf.lt_iff_lt (fun h₁ h₂ => ?_) fun h₁ h₂ => ?_
· rcases hc.out (mem_range_self _) (mem_range_self _) ⟨not_lt.1 h₂, h₁.le⟩ with ⟨y, rfl⟩
exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩
· rcases hc.out (mem_range_self _) (mem_range_self _) ⟨h₁.le, not_lt.1 h₂⟩ with ⟨y, rfl⟩
exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩
/-- A strictly monotone function between linear orders with order topology is a topological
embedding provided that the range of `f` is order-connected. -/
theorem StrictMono.isEmbedding_of_ordConnected {α β : Type*} [LinearOrder α] [LinearOrder β]
[TopologicalSpace α] [h : OrderTopology α] [TopologicalSpace β] [OrderTopology β] {f : α → β}
(hf : StrictMono f) (hc : OrdConnected (range f)) : IsEmbedding f :=
⟨⟨h.1.trans <| Eq.symm <| hf.induced_topology_eq_preorder hc⟩, hf.injective⟩
@[deprecated (since := "2024-10-26")]
alias StrictMono.embedding_of_ordConnected := StrictMono.isEmbedding_of_ordConnected
/-- On a `Set.OrdConnected` subset of a linear order, the order topology for the restriction of the
order is the same as the restriction to the subset of the order topology. -/
instance orderTopology_of_ordConnected {α : Type u} [TopologicalSpace α] [LinearOrder α]
[OrderTopology α] {t : Set α} [ht : OrdConnected t] : OrderTopology t :=
⟨(Subtype.strictMono_coe t).induced_topology_eq_preorder <| by
rwa [← @Subtype.range_val _ t] at ht⟩
theorem nhdsGE_eq_iInf_inf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) :
𝓝[≥] a = (⨅ (u) (_ : a < u), 𝓟 (Iio u)) ⊓ 𝓟 (Ici a) := by
rw [nhdsWithin, nhds_eq_order]
refine le_antisymm (inf_le_inf_right _ inf_le_right) (le_inf (le_inf ?_ inf_le_left) inf_le_right)
exact inf_le_right.trans (le_iInf₂ fun l hl => principal_mono.2 <| Ici_subset_Ioi.2 hl)
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_eq'' := nhdsGE_eq_iInf_inf_principal
theorem nhdsLE_eq_iInf_inf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) :
𝓝[≤] a = (⨅ l < a, 𝓟 (Ioi l)) ⊓ 𝓟 (Iic a) :=
nhdsGE_eq_iInf_inf_principal (toDual a)
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_eq'' := nhdsLE_eq_iInf_inf_principal
theorem nhdsGE_eq_iInf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α}
(ha : ∃ u, a < u) : 𝓝[≥] a = ⨅ (u) (_ : a < u), 𝓟 (Ico a u) := by
simp only [nhdsGE_eq_iInf_inf_principal, biInf_inf ha, inf_principal, Iio_inter_Ici]
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_eq' := nhdsGE_eq_iInf_principal
theorem nhdsLE_eq_iInf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α}
(ha : ∃ l, l < a) : 𝓝[≤] a = ⨅ l < a, 𝓟 (Ioc l a) := by
simp only [nhdsLE_eq_iInf_inf_principal, biInf_inf ha, inf_principal, Ioi_inter_Iic]
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_eq' := nhdsLE_eq_iInf_principal
theorem nhdsGE_basis_of_exists_gt [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α}
(ha : ∃ u, a < u) : (𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u :=
(nhdsGE_eq_iInf_principal ha).symm ▸
hasBasis_biInf_principal
(fun b hb c hc => ⟨min b c, lt_min hb hc, Ico_subset_Ico_right (min_le_left _ _),
Ico_subset_Ico_right (min_le_right _ _)⟩)
ha
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis' := nhdsGE_basis_of_exists_gt
theorem nhdsLE_basis_of_exists_lt [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α}
(ha : ∃ l, l < a) : (𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a := by
convert nhdsGE_basis_of_exists_gt (α := αᵒᵈ) ha using 2
exact Ico_toDual.symm
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_basis' := nhdsLE_basis_of_exists_lt
theorem nhdsGE_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMaxOrder α] (a : α) :
(𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u :=
nhdsGE_basis_of_exists_gt (exists_gt a)
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis := nhdsGE_basis
theorem nhdsLE_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMinOrder α] (a : α) :
(𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a :=
nhdsLE_basis_of_exists_lt (exists_lt a)
@[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_basis := nhdsLE_basis
theorem nhds_top_order [TopologicalSpace α] [Preorder α] [OrderTop α] [OrderTopology α] :
𝓝 (⊤ : α) = ⨅ (l) (_ : l < ⊤), 𝓟 (Ioi l) := by simp [nhds_eq_order (⊤ : α)]
theorem nhds_bot_order [TopologicalSpace α] [Preorder α] [OrderBot α] [OrderTopology α] :
𝓝 (⊥ : α) = ⨅ (l) (_ : ⊥ < l), 𝓟 (Iio l) := by simp [nhds_eq_order (⊥ : α)]
theorem nhds_top_basis [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α]
[Nontrivial α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) fun a : α => Ioi a := by
have : ∃ x : α, x < ⊤ := (exists_ne ⊤).imp fun x hx => hx.lt_top
simpa only [Iic_top, nhdsWithin_univ, Ioc_top] using nhdsLE_basis_of_exists_lt this
theorem nhds_bot_basis [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α]
[Nontrivial α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) fun a : α => Iio a :=
nhds_top_basis (α := αᵒᵈ)
theorem nhds_top_basis_Ici [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α]
[Nontrivial α] [DenselyOrdered α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) Ici :=
nhds_top_basis.to_hasBasis
(fun _a ha => let ⟨b, hab, hb⟩ := exists_between ha; ⟨b, hb, Ici_subset_Ioi.mpr hab⟩)
fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩
theorem nhds_bot_basis_Iic [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α]
[Nontrivial α] [DenselyOrdered α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) Iic :=
nhds_top_basis_Ici (α := αᵒᵈ)
theorem tendsto_nhds_top_mono [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β]
{l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) : Tendsto g l (𝓝 ⊤) := by
simp only [nhds_top_order, tendsto_iInf, tendsto_principal] at hf ⊢
intro x hx
filter_upwards [hf x hx, hg] with _ using lt_of_lt_of_le
theorem tendsto_nhds_bot_mono [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β]
{l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) : Tendsto g l (𝓝 ⊥) :=
tendsto_nhds_top_mono (β := βᵒᵈ) hf hg
theorem tendsto_nhds_top_mono' [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β]
{l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ g) : Tendsto g l (𝓝 ⊤) :=
tendsto_nhds_top_mono hf (Eventually.of_forall hg)
theorem tendsto_nhds_bot_mono' [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β]
{l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ f) : Tendsto g l (𝓝 ⊥) :=
tendsto_nhds_bot_mono hf (Eventually.of_forall hg)
section LinearOrder
variable [TopologicalSpace α] [LinearOrder α]
section OrderTopology
theorem order_separated [OrderTopology α] {a₁ a₂ : α} (h : a₁ < a₂) :
∃ u v : Set α, IsOpen u ∧ IsOpen v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ ∀ b₁ ∈ u, ∀ b₂ ∈ v, b₁ < b₂ :=
let ⟨x, hx, y, hy, h⟩ := h.exists_disjoint_Iio_Ioi
⟨Iio x, Ioi y, isOpen_gt' _, isOpen_lt' _, hx, hy, h⟩
-- see Note [lower instance priority]
instance (priority := 100) OrderTopology.to_orderClosedTopology [OrderTopology α] :
OrderClosedTopology α where
isClosed_le' := isOpen_compl_iff.1 <| isOpen_prod_iff.mpr fun a₁ a₂ (h : ¬a₁ ≤ a₂) =>
have h : a₂ < a₁ := lt_of_not_ge h
let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h
⟨v, u, hv, hu, ha₂, ha₁, fun ⟨b₁, b₂⟩ ⟨h₁, h₂⟩ => not_le_of_gt <| h b₂ h₂ b₁ h₁⟩
theorem exists_Ioc_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a)
(h : ∃ l, l < a) : ∃ l < a, Ioc l a ⊆ s :=
(nhdsLE_basis_of_exists_lt h).mem_iff.mp (nhdsWithin_le_nhds hs)
theorem exists_Ioc_subset_of_mem_nhds' [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {l : α}
(hl : l < a) : ∃ l' ∈ Ico l a, Ioc l' a ⊆ s :=
let ⟨l', hl'a, hl's⟩ := exists_Ioc_subset_of_mem_nhds hs ⟨l, hl⟩
⟨max l l', ⟨le_max_left _ _, max_lt hl hl'a⟩,
(Ioc_subset_Ioc_left <| le_max_right _ _).trans hl's⟩
theorem exists_Ico_subset_of_mem_nhds' [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {u : α}
(hu : a < u) : ∃ u' ∈ Ioc a u, Ico a u' ⊆ s := by
simpa only [OrderDual.exists, exists_prop, Ico_toDual, Ioc_toDual] using
exists_Ioc_subset_of_mem_nhds' (show ofDual ⁻¹' s ∈ 𝓝 (toDual a) from hs) hu.dual
theorem exists_Ico_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a)
(h : ∃ u, a < u) : ∃ u, a < u ∧ Ico a u ⊆ s :=
let ⟨_l', hl'⟩ := h
let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl'
⟨l, hl.1.1, hl.2⟩
theorem exists_Icc_mem_subset_of_mem_nhdsGE [OrderTopology α] {a : α} {s : Set α}
(hs : s ∈ 𝓝[≥] a) : ∃ b, a ≤ b ∧ Icc a b ∈ 𝓝[≥] a ∧ Icc a b ⊆ s := by
rcases (em (IsMax a)).imp_right not_isMax_iff.mp with (ha | ha)
· use a
simpa [ha.Ici_eq] using hs
· rcases(nhdsGE_basis_of_exists_gt ha).mem_iff.mp hs with ⟨b, hab, hbs⟩
rcases eq_empty_or_nonempty (Ioo a b) with (H | ⟨c, hac, hcb⟩)
· have : Ico a b = Icc a a := by rw [← Icc_union_Ioo_eq_Ico le_rfl hab, H, union_empty]
exact ⟨a, le_rfl, this ▸ ⟨Ico_mem_nhdsGE hab, hbs⟩⟩
· refine ⟨c, hac.le, Icc_mem_nhdsGE hac, ?_⟩
exact (Icc_subset_Ico_right hcb).trans hbs
@[deprecated (since := "2024-12-22")]
alias exists_Icc_mem_subset_of_mem_nhdsWithin_Ici := exists_Icc_mem_subset_of_mem_nhdsGE
theorem exists_Icc_mem_subset_of_mem_nhdsLE [OrderTopology α] {a : α} {s : Set α}
(hs : s ∈ 𝓝[≤] a) : ∃ b ≤ a, Icc b a ∈ 𝓝[≤] a ∧ Icc b a ⊆ s := by
simpa only [Icc_toDual, toDual.surjective.exists] using
exists_Icc_mem_subset_of_mem_nhdsGE (α := αᵒᵈ) (a := toDual a) hs
@[deprecated (since := "2024-12-22")]
alias exists_Icc_mem_subset_of_mem_nhdsWithin_Iic := exists_Icc_mem_subset_of_mem_nhdsLE
theorem exists_Icc_mem_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) :
∃ b c, a ∈ Icc b c ∧ Icc b c ∈ 𝓝 a ∧ Icc b c ⊆ s := by
rcases exists_Icc_mem_subset_of_mem_nhdsLE (nhdsWithin_le_nhds hs) with
⟨b, hba, hb_nhds, hbs⟩
rcases exists_Icc_mem_subset_of_mem_nhdsGE (nhdsWithin_le_nhds hs) with
⟨c, hac, hc_nhds, hcs⟩
refine ⟨b, c, ⟨hba, hac⟩, ?_⟩
rw [← Icc_union_Icc_eq_Icc hba hac, ← nhdsLE_sup_nhdsGE]
exact ⟨union_mem_sup hb_nhds hc_nhds, union_subset hbs hcs⟩
theorem IsOpen.exists_Ioo_subset [OrderTopology α] [Nontrivial α] {s : Set α} (hs : IsOpen s)
(h : s.Nonempty) : ∃ a b, a < b ∧ Ioo a b ⊆ s := by
obtain ⟨x, hx⟩ : ∃ x, x ∈ s := h
obtain ⟨y, hy⟩ : ∃ y, y ≠ x := exists_ne x
rcases lt_trichotomy x y with (H | rfl | H)
· obtain ⟨u, xu, hu⟩ : ∃ u, x < u ∧ Ico x u ⊆ s :=
exists_Ico_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩
exact ⟨x, u, xu, Ioo_subset_Ico_self.trans hu⟩
· exact (hy rfl).elim
· obtain ⟨l, lx, hl⟩ : ∃ l, l < x ∧ Ioc l x ⊆ s :=
exists_Ioc_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩
exact ⟨l, x, lx, Ioo_subset_Ioc_self.trans hl⟩
theorem dense_of_exists_between [OrderTopology α] [Nontrivial α] {s : Set α}
(h : ∀ ⦃a b⦄, a < b → ∃ c ∈ s, a < c ∧ c < b) : Dense s := by
refine dense_iff_inter_open.2 fun U U_open U_nonempty => ?_
obtain ⟨a, b, hab, H⟩ : ∃ a b : α, a < b ∧ Ioo a b ⊆ U := U_open.exists_Ioo_subset U_nonempty
obtain ⟨x, xs, hx⟩ : ∃ x ∈ s, a < x ∧ x < b := h hab
exact ⟨x, ⟨H hx, xs⟩⟩
/-- A set in a nontrivial densely linear ordered type is dense in the sense of topology if and only
if for any `a < b` there exists `c ∈ s`, `a < c < b`. Each implication requires less typeclass
assumptions. -/
theorem dense_iff_exists_between [OrderTopology α] [DenselyOrdered α] [Nontrivial α] {s : Set α} :
Dense s ↔ ∀ a b, a < b → ∃ c ∈ s, a < c ∧ c < b :=
⟨fun h _ _ hab => h.exists_between hab, dense_of_exists_between⟩
/-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`,
provided `a` is neither a bottom element nor a top element. -/
theorem mem_nhds_iff_exists_Ioo_subset' [OrderTopology α] {a : α} {s : Set α} (hl : ∃ l, l < a)
(hu : ∃ u, a < u) : s ∈ 𝓝 a ↔ ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := by
constructor
· intro h
rcases exists_Ico_subset_of_mem_nhds h hu with ⟨u, au, hu⟩
rcases exists_Ioc_subset_of_mem_nhds h hl with ⟨l, la, hl⟩
exact ⟨l, u, ⟨la, au⟩, Ioc_union_Ico_eq_Ioo la au ▸ union_subset hl hu⟩
· rintro ⟨l, u, ha, h⟩
apply mem_of_superset (Ioo_mem_nhds ha.1 ha.2) h
/-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`.
-/
theorem mem_nhds_iff_exists_Ioo_subset [OrderTopology α] [NoMaxOrder α] [NoMinOrder α] {a : α}
{s : Set α} : s ∈ 𝓝 a ↔ ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s :=
mem_nhds_iff_exists_Ioo_subset' (exists_lt a) (exists_gt a)
theorem nhds_basis_Ioo' [OrderTopology α] {a : α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) :
(𝓝 a).HasBasis (fun b : α × α => b.1 < a ∧ a < b.2) fun b => Ioo b.1 b.2 :=
⟨fun s => (mem_nhds_iff_exists_Ioo_subset' hl hu).trans <| by simp⟩
theorem nhds_basis_Ioo [OrderTopology α] [NoMaxOrder α] [NoMinOrder α] (a : α) :
(𝓝 a).HasBasis (fun b : α × α => b.1 < a ∧ a < b.2) fun b => Ioo b.1 b.2 :=
nhds_basis_Ioo' (exists_lt a) (exists_gt a)
theorem Filter.Eventually.exists_Ioo_subset [OrderTopology α] [NoMaxOrder α] [NoMinOrder α] {a : α}
{p : α → Prop} (hp : ∀ᶠ x in 𝓝 a, p x) : ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ { x | p x } :=
mem_nhds_iff_exists_Ioo_subset.1 hp
theorem Dense.topology_eq_generateFrom [OrderTopology α] [DenselyOrdered α] {s : Set α}
(hs : Dense s) : ‹TopologicalSpace α› = .generateFrom (Ioi '' s ∪ Iio '' s) := by
refine (OrderTopology.topology_eq_generate_intervals (α := α)).trans ?_
refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_)
· simp only [union_subset_iff, image_subset_iff]
exact ⟨fun a _ ↦ ⟨a, .inl rfl⟩, fun a _ ↦ ⟨a, .inr rfl⟩⟩
· rintro _ ⟨a, rfl | rfl⟩
· rw [hs.Ioi_eq_biUnion]
let _ := generateFrom (Ioi '' s ∪ Iio '' s)
exact isOpen_iUnion fun x ↦ isOpen_iUnion fun h ↦ .basic _ <| .inl <| mem_image_of_mem _ h.1
· rw [hs.Iio_eq_biUnion]
let _ := generateFrom (Ioi '' s ∪ Iio '' s)
exact isOpen_iUnion fun x ↦ isOpen_iUnion fun h ↦ .basic _ <| .inr <| mem_image_of_mem _ h.1
theorem PredOrder.hasBasis_nhds_Ioc_of_exists_gt [OrderTopology α] [PredOrder α] {a : α}
(ha : ∃ u, a < u) : (𝓝 a).HasBasis (a < ·) (Set.Ico a ·) :=
PredOrder.nhdsGE_eq_nhds a ▸ nhdsGE_basis_of_exists_gt ha
theorem PredOrder.hasBasis_nhds_Ioc [OrderTopology α] [PredOrder α] [NoMaxOrder α] {a : α} :
(𝓝 a).HasBasis (a < ·) (Set.Ico a ·) :=
PredOrder.hasBasis_nhds_Ioc_of_exists_gt (exists_gt a)
theorem SuccOrder.hasBasis_nhds_Ioc_of_exists_lt [OrderTopology α] [SuccOrder α] {a : α}
(ha : ∃ l, l < a) : (𝓝 a).HasBasis (· < a) (Set.Ioc · a) :=
SuccOrder.nhdsLE_eq_nhds a ▸ nhdsLE_basis_of_exists_lt ha
theorem SuccOrder.hasBasis_nhds_Ioc [OrderTopology α] [SuccOrder α] {a : α} [NoMinOrder α] :
(𝓝 a).HasBasis (· < a) (Set.Ioc · a) :=
SuccOrder.hasBasis_nhds_Ioc_of_exists_lt (exists_lt a)
variable (α) in
/-- Let `α` be a densely ordered linear order with order topology. If `α` is a separable space, then
it has second countable topology. Note that the "densely ordered" assumption cannot be dropped, see
[double arrow space](https://topology.pi-base.org/spaces/S000093) for a counterexample. -/
theorem SecondCountableTopology.of_separableSpace_orderTopology [OrderTopology α] [DenselyOrdered α]
[SeparableSpace α] : SecondCountableTopology α := by
rcases exists_countable_dense α with ⟨s, hc, hd⟩
refine ⟨⟨_, ?_, hd.topology_eq_generateFrom⟩⟩
exact (hc.image _).union (hc.image _)
/-- The set of points which are isolated on the right is countable when the space is
second-countable. -/
theorem countable_setOf_covBy_right [OrderTopology α] [SecondCountableTopology α] :
Set.Countable { x : α | ∃ y, x ⋖ y } := by
nontriviality α
let s := { x : α | ∃ y, x ⋖ y }
have : ∀ x ∈ s, ∃ y, x ⋖ y := fun x => id
choose! y hy using this
have Hy : ∀ x z, x ∈ s → z < y x → z ≤ x := fun x z hx => (hy x hx).le_of_lt
suffices H : ∀ a : Set α, IsOpen a → Set.Countable { x | x ∈ s ∧ x ∈ a ∧ y x ∉ a } by
have : s ⊆ ⋃ a ∈ countableBasis α, { x | x ∈ s ∧ x ∈ a ∧ y x ∉ a } := fun x hx => by
rcases (isBasis_countableBasis α).exists_mem_of_ne (hy x hx).ne with ⟨a, ab, xa, ya⟩
exact mem_iUnion₂.2 ⟨a, ab, hx, xa, ya⟩
refine Set.Countable.mono this ?_
refine Countable.biUnion (countable_countableBasis α) fun a ha => H _ ?_
exact isOpen_of_mem_countableBasis ha
intro a ha
suffices H : Set.Countable { x | (x ∈ s ∧ x ∈ a ∧ y x ∉ a) ∧ ¬IsBot x } from
H.of_diff (subsingleton_isBot α).countable
simp only [and_assoc]
let t := { x | x ∈ s ∧ x ∈ a ∧ y x ∉ a ∧ ¬IsBot x }
have : ∀ x ∈ t, ∃ z < x, Ioc z x ⊆ a := by
intro x hx
| apply exists_Ioc_subset_of_mem_nhds (ha.mem_nhds hx.2.1)
simpa only [IsBot, not_forall, not_le] using hx.right.right.right
choose! z hz h'z using this
have : PairwiseDisjoint t fun x => Ioc (z x) x := fun x xt x' x't hxx' => by
rcases hxx'.lt_or_lt with (h' | h')
| Mathlib/Topology/Order/Basic.lean | 545 | 549 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Algebra.Rat
import Mathlib.Data.Nat.Cast.Field
import Mathlib.RingTheory.PowerSeries.Basic
/-!
# Definition of well-known power series
In this file we define the following power series:
* `PowerSeries.invUnitsSub`: given `u : Rˣ`, this is the series for `1 / (u - x)`.
It is given by `∑ n, x ^ n /ₚ u ^ (n + 1)`.
* `PowerSeries.invOneSubPow`: given a commutative ring `S` and a number `d : ℕ`,
`PowerSeries.invOneSubPow S d` is the multiplicative inverse of `(1 - X) ^ d` in `S⟦X⟧ˣ`.
When `d` is `0`, `PowerSeries.invOneSubPow S d` will just be `1`. When `d` is positive,
`PowerSeries.invOneSubPow S d` will be `∑ n, Nat.choose (d - 1 + n) (d - 1)`.
* `PowerSeries.sin`, `PowerSeries.cos`, `PowerSeries.exp` : power series for sin, cosine, and
exponential functions.
-/
namespace PowerSeries
section Ring
variable {R S : Type*} [Ring R] [Ring S]
/-- The power series for `1 / (u - x)`. -/
def invUnitsSub (u : Rˣ) : PowerSeries R :=
mk fun n => 1 /ₚ u ^ (n + 1)
@[simp]
theorem coeff_invUnitsSub (u : Rˣ) (n : ℕ) : coeff R n (invUnitsSub u) = 1 /ₚ u ^ (n + 1) :=
coeff_mk _ _
@[simp]
theorem constantCoeff_invUnitsSub (u : Rˣ) : constantCoeff R (invUnitsSub u) = 1 /ₚ u := by
rw [← coeff_zero_eq_constantCoeff_apply, coeff_invUnitsSub, zero_add, pow_one]
@[simp]
| theorem invUnitsSub_mul_X (u : Rˣ) : invUnitsSub u * X = invUnitsSub u * C R u - 1 := by
ext (_ | n)
| Mathlib/RingTheory/PowerSeries/WellKnown.lean | 47 | 48 |
/-
Copyright (c) 2019 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard
-/
import Mathlib.Data.EReal.Basic
deprecated_module (since := "2025-04-13")
| Mathlib/Data/Real/EReal.lean | 869 | 870 | |
/-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.NumberTheory.NumberField.Embeddings
import Mathlib.RingTheory.LocalRing.RingHom.Basic
import Mathlib.GroupTheory.Torsion
/-!
# Units of a number field
We prove some basic results on the group `(𝓞 K)ˣ` of units of the ring of integers `𝓞 K` of a number
field `K` and its torsion subgroup.
## Main definition
* `NumberField.Units.torsion`: the torsion subgroup of a number field.
## Main results
* `NumberField.isUnit_iff_norm`: an algebraic integer `x : 𝓞 K` is a unit if and only if
`|norm ℚ x| = 1`.
* `NumberField.Units.mem_torsion`: a unit `x : (𝓞 K)ˣ` is torsion iff `w x = 1` for all infinite
places `w` of `K`.
## Tags
number field, units
-/
open scoped NumberField
noncomputable section
open NumberField Units
section Rat
theorem Rat.RingOfIntegers.isUnit_iff {x : 𝓞 ℚ} : IsUnit x ↔ (x : ℚ) = 1 ∨ (x : ℚ) = -1 := by
simp_rw [(isUnit_map_iff (Rat.ringOfIntegersEquiv : 𝓞 ℚ →+* ℤ) x).symm, Int.isUnit_iff,
RingEquiv.coe_toRingHom, RingEquiv.map_eq_one_iff, RingEquiv.map_eq_neg_one_iff, ←
Subtype.coe_injective.eq_iff]; rfl
end Rat
variable (K : Type*) [Field K]
section IsUnit
variable {K}
theorem NumberField.isUnit_iff_norm [NumberField K] {x : 𝓞 K} :
IsUnit x ↔ |(RingOfIntegers.norm ℚ x : ℚ)| = 1 := by
convert (RingOfIntegers.isUnit_norm ℚ (F := K)).symm
rw [← abs_one, abs_eq_abs, ← Rat.RingOfIntegers.isUnit_iff]
end IsUnit
namespace NumberField.Units
section coe
instance : CoeHTC (𝓞 K)ˣ K :=
⟨fun x => algebraMap _ K (Units.val x)⟩
theorem coe_injective : Function.Injective ((↑) : (𝓞 K)ˣ → K) :=
RingOfIntegers.coe_injective.comp Units.ext
variable {K}
theorem coe_coe (u : (𝓞 K)ˣ) : ((u : 𝓞 K) : K) = (u : K) := rfl
theorem coe_mul (x y : (𝓞 K)ˣ) : ((x * y : (𝓞 K)ˣ) : K) = (x : K) * (y : K) := rfl
theorem coe_pow (x : (𝓞 K)ˣ) (n : ℕ) : ((x ^ n : (𝓞 K)ˣ) : K) = (x : K) ^ n := by
rw [← map_pow, ← val_pow_eq_pow_val]
theorem coe_zpow (x : (𝓞 K)ˣ) (n : ℤ) : (↑(x ^ n) : K) = (x : K) ^ n := by
change ((Units.coeHom K).comp (map (algebraMap (𝓞 K) K))) (x ^ n) = _
| exact map_zpow _ x n
theorem coe_one : ((1 : (𝓞 K)ˣ) : K) = (1 : K) := rfl
| Mathlib/NumberTheory/NumberField/Units/Basic.lean | 81 | 83 |
/-
Copyright (c) 2020 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Logic.Encodable.Basic
import Mathlib.Order.Atoms
import Mathlib.Order.Cofinal
import Mathlib.Order.UpperLower.Principal
/-!
# Order ideals, cofinal sets, and the Rasiowa–Sikorski lemma
## Main definitions
Throughout this file, `P` is at least a preorder, but some sections require more
structure, such as a bottom element, a top element, or a join-semilattice structure.
- `Order.Ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.
Dual to the notion of a filter on a preorder.
- `Order.IsIdeal I`: a predicate for when a `Set P` is an ideal.
- `Order.Ideal.principal p`: the principal ideal generated by `p : P`.
- `Order.Ideal.IsProper I`: a predicate for proper ideals.
Dual to the notion of a proper filter.
- `Order.Ideal.IsMaximal I`: a predicate for maximal ideals.
Dual to the notion of an ultrafilter.
- `Order.Cofinal P`: the type of subsets of `P` containing arbitrarily large elements.
Dual to the notion of 'dense set' used in forcing.
- `Order.idealOfCofinals p 𝒟`, where `p : P`, and `𝒟` is a countable family of cofinal
subsets of `P`: an ideal in `P` which contains `p` and intersects every set in `𝒟`. (This a form
of the Rasiowa–Sikorski lemma.)
## References
- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>
- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>
- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>
Note that for the Rasiowa–Sikorski lemma, Wikipedia uses the opposite ordering on `P`,
in line with most presentations of forcing.
## Tags
ideal, cofinal, dense, countable, generic
-/
open Function Set
namespace Order
variable {P : Type*}
/-- An ideal on an order `P` is a subset of `P` that is
- nonempty
- upward directed (any pair of elements in the ideal has an upper bound in the ideal)
- downward closed (any element less than an element of the ideal is in the ideal). -/
structure Ideal (P) [LE P] extends LowerSet P where
/-- The ideal is nonempty. -/
nonempty' : carrier.Nonempty
/-- The ideal is upward directed. -/
directed' : DirectedOn (· ≤ ·) carrier
-- TODO: remove this configuration and use the default configuration.
-- We keep this to be consistent with Lean 3.
initialize_simps_projections Ideal (+toLowerSet, -carrier)
/-- A subset of a preorder `P` is an ideal if it is
- nonempty
- upward directed (any pair of elements in the ideal has an upper bound in the ideal)
- downward closed (any element less than an element of the ideal is in the ideal). -/
@[mk_iff]
structure IsIdeal {P} [LE P] (I : Set P) : Prop where
/-- The ideal is downward closed. -/
IsLowerSet : IsLowerSet I
/-- The ideal is nonempty. -/
Nonempty : I.Nonempty
/-- The ideal is upward directed. -/
Directed : DirectedOn (· ≤ ·) I
/-- Create an element of type `Order.Ideal` from a set satisfying the predicate
`Order.IsIdeal`. -/
def IsIdeal.toIdeal [LE P] {I : Set P} (h : IsIdeal I) : Ideal P :=
⟨⟨I, h.IsLowerSet⟩, h.Nonempty, h.Directed⟩
namespace Ideal
section LE
variable [LE P]
section
variable {I s t : Ideal P} {x : P}
theorem toLowerSet_injective : Injective (toLowerSet : Ideal P → LowerSet P) := fun s t _ ↦ by
cases s
cases t
congr
instance : SetLike (Ideal P) P where
coe s := s.carrier
coe_injective' _ _ h := toLowerSet_injective <| SetLike.coe_injective h
@[ext]
theorem ext {s t : Ideal P} : (s : Set P) = t → s = t :=
SetLike.ext'
@[simp]
theorem carrier_eq_coe (s : Ideal P) : s.carrier = s :=
rfl
@[simp]
theorem coe_toLowerSet (s : Ideal P) : (s.toLowerSet : Set P) = s :=
rfl
protected theorem lower (s : Ideal P) : IsLowerSet (s : Set P) :=
s.lower'
protected theorem nonempty (s : Ideal P) : (s : Set P).Nonempty :=
s.nonempty'
protected theorem directed (s : Ideal P) : DirectedOn (· ≤ ·) (s : Set P) :=
s.directed'
protected theorem isIdeal (s : Ideal P) : IsIdeal (s : Set P) :=
⟨s.lower, s.nonempty, s.directed⟩
theorem mem_compl_of_ge {x y : P} : x ≤ y → x ∈ (I : Set P)ᶜ → y ∈ (I : Set P)ᶜ := fun h ↦
mt <| I.lower h
/-- The partial ordering by subset inclusion, inherited from `Set P`. -/
instance instPartialOrderIdeal : PartialOrder (Ideal P) :=
PartialOrder.lift SetLike.coe SetLike.coe_injective
theorem coe_subset_coe : (s : Set P) ⊆ t ↔ s ≤ t :=
Iff.rfl
theorem coe_ssubset_coe : (s : Set P) ⊂ t ↔ s < t :=
Iff.rfl
@[trans]
theorem mem_of_mem_of_le {x : P} {I J : Ideal P} : x ∈ I → I ≤ J → x ∈ J :=
@Set.mem_of_mem_of_subset P x I J
/-- A proper ideal is one that is not the whole set.
Note that the whole set might not be an ideal. -/
@[mk_iff]
class IsProper (I : Ideal P) : Prop where
/-- This ideal is not the whole set. -/
ne_univ : (I : Set P) ≠ univ
theorem isProper_of_not_mem {I : Ideal P} {p : P} (nmem : p ∉ I) : IsProper I :=
⟨fun hp ↦ by
have := mem_univ p
rw [← hp] at this
exact nmem this⟩
/-- An ideal is maximal if it is maximal in the collection of proper ideals.
Note that `IsCoatom` is less general because ideals only have a top element when `P` is directed
and nonempty. -/
@[mk_iff]
class IsMaximal (I : Ideal P) : Prop extends IsProper I where
/-- This ideal is maximal in the collection of proper ideals. -/
maximal_proper : ∀ ⦃J : Ideal P⦄, I < J → (J : Set P) = univ
theorem inter_nonempty [IsDirected P (· ≥ ·)] (I J : Ideal P) : (I ∩ J : Set P).Nonempty := by
obtain ⟨a, ha⟩ := I.nonempty
obtain ⟨b, hb⟩ := J.nonempty
obtain ⟨c, hac, hbc⟩ := exists_le_le a b
exact ⟨c, I.lower hac ha, J.lower hbc hb⟩
end
section Directed
variable [IsDirected P (· ≤ ·)] [Nonempty P] {I : Ideal P}
/-- In a directed and nonempty order, the top ideal of a is `univ`. -/
instance : OrderTop (Ideal P) where
top := ⟨⊤, univ_nonempty, directedOn_univ⟩
le_top _ _ _ := LowerSet.mem_top
@[simp]
theorem top_toLowerSet : (⊤ : Ideal P).toLowerSet = ⊤ :=
rfl
@[simp]
theorem coe_top : ((⊤ : Ideal P) : Set P) = univ :=
rfl
theorem isProper_of_ne_top (ne_top : I ≠ ⊤) : IsProper I :=
⟨fun h ↦ ne_top <| ext h⟩
theorem IsProper.ne_top (_ : IsProper I) : I ≠ ⊤ :=
fun h ↦ IsProper.ne_univ <| congr_arg SetLike.coe h
theorem _root_.IsCoatom.isProper (hI : IsCoatom I) : IsProper I :=
isProper_of_ne_top hI.1
theorem isProper_iff_ne_top : IsProper I ↔ I ≠ ⊤ :=
⟨fun h ↦ h.ne_top, fun h ↦ isProper_of_ne_top h⟩
theorem IsMaximal.isCoatom (_ : IsMaximal I) : IsCoatom I :=
⟨IsMaximal.toIsProper.ne_top, fun _ h ↦ ext <| IsMaximal.maximal_proper h⟩
theorem IsMaximal.isCoatom' [IsMaximal I] : IsCoatom I :=
IsMaximal.isCoatom ‹_›
theorem _root_.IsCoatom.isMaximal (hI : IsCoatom I) : IsMaximal I :=
{ IsCoatom.isProper hI with maximal_proper := fun _ hJ ↦ by simp [hI.2 _ hJ] }
theorem isMaximal_iff_isCoatom : IsMaximal I ↔ IsCoatom I :=
⟨fun h ↦ h.isCoatom, fun h ↦ IsCoatom.isMaximal h⟩
end Directed
section OrderBot
variable [OrderBot P]
@[simp]
theorem bot_mem (s : Ideal P) : ⊥ ∈ s :=
s.lower bot_le s.nonempty'.some_mem
end OrderBot
section OrderTop
variable [OrderTop P] {I : Ideal P}
theorem top_of_top_mem (h : ⊤ ∈ I) : I = ⊤ := by
ext
exact iff_of_true (I.lower le_top h) trivial
theorem IsProper.top_not_mem (hI : IsProper I) : ⊤ ∉ I := fun h ↦ hI.ne_top <| top_of_top_mem h
end OrderTop
end LE
section Preorder
variable [Preorder P]
section
variable {I : Ideal P} {x y : P}
/-- The smallest ideal containing a given element. -/
@[simps]
def principal (p : P) : Ideal P where
toLowerSet := LowerSet.Iic p
nonempty' := nonempty_Iic
directed' _ hx _ hy := ⟨p, le_rfl, hx, hy⟩
instance [Inhabited P] : Inhabited (Ideal P) :=
⟨Ideal.principal default⟩
@[simp]
theorem principal_le_iff : principal x ≤ I ↔ x ∈ I :=
⟨fun h ↦ h le_rfl, fun hx _ hy ↦ I.lower hy hx⟩
@[simp]
theorem mem_principal : x ∈ principal y ↔ x ≤ y :=
Iff.rfl
lemma mem_principal_self : x ∈ principal x :=
mem_principal.2 (le_refl x)
end
section OrderBot
variable [OrderBot P]
/-- There is a bottom ideal when `P` has a bottom element. -/
instance : OrderBot (Ideal P) where
bot := principal ⊥
bot_le := by simp
@[simp]
theorem principal_bot : principal (⊥ : P) = ⊥ :=
rfl
end OrderBot
section OrderTop
variable [OrderTop P]
@[simp]
theorem principal_top : principal (⊤ : P) = ⊤ :=
toLowerSet_injective <| LowerSet.Iic_top
end OrderTop
end Preorder
section SemilatticeSup
variable [SemilatticeSup P] {x y : P} {I s : Ideal P}
/-- A specific witness of `I.directed` when `P` has joins. -/
theorem sup_mem (hx : x ∈ s) (hy : y ∈ s) : x ⊔ y ∈ s :=
let ⟨_, hz, hx, hy⟩ := s.directed x hx y hy
s.lower (sup_le hx hy) hz
@[simp]
theorem sup_mem_iff : x ⊔ y ∈ I ↔ x ∈ I ∧ y ∈ I :=
⟨fun h ↦ ⟨I.lower le_sup_left h, I.lower le_sup_right h⟩, fun h ↦ sup_mem h.1 h.2⟩
@[simp]
lemma finsetSup_mem_iff {P : Type*} [SemilatticeSup P] [OrderBot P]
(t : Ideal P) {ι : Type*}
{f : ι → P} {s : Finset ι} : s.sup f ∈ t ↔ ∀ i ∈ s, f i ∈ t := by
classical
induction s using Finset.induction_on <;> simp [*]
end SemilatticeSup
section SemilatticeSupDirected
variable [SemilatticeSup P] [IsDirected P (· ≥ ·)] {x : P} {I J s t : Ideal P}
/-- The infimum of two ideals of a co-directed order is their intersection. -/
instance : Min (Ideal P) :=
⟨fun I J ↦
{ toLowerSet := I.toLowerSet ⊓ J.toLowerSet
nonempty' := inter_nonempty I J
directed' := fun x hx y hy ↦ ⟨x ⊔ y, ⟨sup_mem hx.1 hy.1, sup_mem hx.2 hy.2⟩, by simp⟩ }⟩
/-- The supremum of two ideals of a co-directed order is the union of the down sets of the pointwise
supremum of `I` and `J`. -/
instance : Max (Ideal P) :=
⟨fun I J ↦
{ carrier := { x | ∃ i ∈ I, ∃ j ∈ J, x ≤ i ⊔ j }
nonempty' := by
obtain ⟨w, h⟩ := inter_nonempty I J
exact ⟨w, w, h.1, w, h.2, le_sup_left⟩
directed' := fun x ⟨xi, _, xj, _, _⟩ y ⟨yi, _, yj, _, _⟩ ↦
⟨x ⊔ y, ⟨xi ⊔ yi, sup_mem ‹_› ‹_›, xj ⊔ yj, sup_mem ‹_› ‹_›,
sup_le
(calc
x ≤ xi ⊔ xj := ‹_›
_ ≤ xi ⊔ yi ⊔ (xj ⊔ yj) := sup_le_sup le_sup_left le_sup_left)
(calc
y ≤ yi ⊔ yj := ‹_›
_ ≤ xi ⊔ yi ⊔ (xj ⊔ yj) := sup_le_sup le_sup_right le_sup_right)⟩,
le_sup_left, le_sup_right⟩
lower' := fun _ _ h ⟨yi, hi, yj, hj, hxy⟩ ↦ ⟨yi, hi, yj, hj, h.trans hxy⟩ }⟩
instance : Lattice (Ideal P) :=
{ Ideal.instPartialOrderIdeal with
sup := (· ⊔ ·)
le_sup_left := fun _ J i hi ↦
let ⟨w, hw⟩ := J.nonempty
⟨i, hi, w, hw, le_sup_left⟩
le_sup_right := fun I _ j hj ↦
let ⟨w, hw⟩ := I.nonempty
⟨w, hw, j, hj, le_sup_right⟩
sup_le := fun _ _ K hIK hJK _ ⟨_, hi, _, hj, ha⟩ ↦
K.lower ha <| sup_mem (mem_of_mem_of_le hi hIK) (mem_of_mem_of_le hj hJK)
inf := (· ⊓ ·)
inf_le_left := fun _ _ ↦ inter_subset_left
inf_le_right := fun _ _ ↦ inter_subset_right
le_inf := fun _ _ _ ↦ subset_inter }
@[simp]
theorem coe_sup : ↑(s ⊔ t) = { x | ∃ a ∈ s, ∃ b ∈ t, x ≤ a ⊔ b } :=
rfl
@[simp]
theorem coe_inf : (↑(s ⊓ t) : Set P) = ↑s ∩ ↑t :=
rfl
@[simp]
theorem mem_inf : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J :=
Iff.rfl
@[simp]
theorem mem_sup : x ∈ I ⊔ J ↔ ∃ i ∈ I, ∃ j ∈ J, x ≤ i ⊔ j :=
Iff.rfl
theorem lt_sup_principal_of_not_mem (hx : x ∉ I) : I < I ⊔ principal x :=
le_sup_left.lt_of_ne fun h ↦ hx <| by simpa only [left_eq_sup, principal_le_iff] using h
end SemilatticeSupDirected
section SemilatticeSupOrderBot
variable [SemilatticeSup P] [OrderBot P] {x : P}
instance : InfSet (Ideal P) :=
⟨fun S ↦
{ toLowerSet := ⨅ s ∈ S, toLowerSet s
nonempty' :=
⟨⊥, by
rw [LowerSet.carrier_eq_coe, LowerSet.coe_iInf₂, Set.mem_iInter₂]
exact fun s _ ↦ s.bot_mem⟩
directed' := fun a ha b hb ↦
⟨a ⊔ b,
⟨by
rw [LowerSet.carrier_eq_coe, LowerSet.coe_iInf₂, Set.mem_iInter₂] at ha hb ⊢
exact fun s hs ↦ sup_mem (ha _ hs) (hb _ hs), le_sup_left, le_sup_right⟩⟩ }⟩
variable {S : Set (Ideal P)}
@[simp]
theorem coe_sInf : (↑(sInf S) : Set P) = ⋂ s ∈ S, ↑s :=
LowerSet.coe_iInf₂ _
@[simp]
theorem mem_sInf : x ∈ sInf S ↔ ∀ s ∈ S, x ∈ s := by
simp_rw [← SetLike.mem_coe, coe_sInf, mem_iInter₂]
instance : CompleteLattice (Ideal P) :=
{ (inferInstance : Lattice (Ideal P)),
completeLatticeOfInf (Ideal P) fun S ↦ by
refine ⟨fun s hs ↦ ?_, fun s hs ↦ by rwa [← coe_subset_coe, coe_sInf, subset_iInter₂_iff]⟩
rw [← coe_subset_coe, coe_sInf]
exact biInter_subset_of_mem hs with }
end SemilatticeSupOrderBot
section DistribLattice
variable [DistribLattice P]
variable {I J : Ideal P}
theorem eq_sup_of_le_sup {x i j : P} (hi : i ∈ I) (hj : j ∈ J) (hx : x ≤ i ⊔ j) :
∃ i' ∈ I, ∃ j' ∈ J, x = i' ⊔ j' := by
refine ⟨x ⊓ i, I.lower inf_le_right hi, x ⊓ j, J.lower inf_le_right hj, ?_⟩
calc
x = x ⊓ (i ⊔ j) := left_eq_inf.mpr hx
_ = x ⊓ i ⊔ x ⊓ j := inf_sup_left _ _ _
theorem coe_sup_eq : ↑(I ⊔ J) = { x | ∃ i ∈ I, ∃ j ∈ J, x = i ⊔ j } :=
Set.ext fun _ ↦
⟨fun ⟨_, _, _, _, _⟩ ↦ eq_sup_of_le_sup ‹_› ‹_› ‹_›, fun ⟨i, _, j, _, _⟩ ↦
⟨i, ‹_›, j, ‹_›, le_of_eq ‹_›⟩⟩
end DistribLattice
section BooleanAlgebra
variable [BooleanAlgebra P] {x : P} {I : Ideal P}
theorem IsProper.not_mem_of_compl_mem (hI : IsProper I) (hxc : xᶜ ∈ I) : x ∉ I := by
intro hx
apply hI.top_not_mem
have ht : x ⊔ xᶜ ∈ I := sup_mem ‹_› ‹_›
rwa [sup_compl_eq_top] at ht
theorem IsProper.not_mem_or_compl_not_mem (hI : IsProper I) : x ∉ I ∨ xᶜ ∉ I := by
have h : xᶜ ∈ I → x ∉ I := hI.not_mem_of_compl_mem
| tauto
| Mathlib/Order/Ideal.lean | 459 | 460 |
/-
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.Algebra.Group.Pointwise.Set.Card
import Mathlib.MeasureTheory.Group.Action
import Mathlib.MeasureTheory.Measure.Prod
import Mathlib.Topology.Algebra.Module.Equiv
import Mathlib.Topology.ContinuousMap.CocompactMap
import Mathlib.Topology.Algebra.ContinuousMonoidHom
/-!
# Measures on Groups
We develop some properties of measures on (topological) groups
* We define properties on measures: measures that are left or right invariant w.r.t. multiplication.
* We define the measure `μ.inv : A ↦ μ(A⁻¹)` and show that it is right invariant iff
`μ` is left invariant.
* We define a class `IsHaarMeasure μ`, requiring that the measure `μ` is left-invariant, finite
on compact sets, and positive on open sets.
We also give analogues of all these notions in the additive world.
-/
noncomputable section
open scoped NNReal ENNReal Pointwise Topology
open Inv Set Function MeasureTheory.Measure Filter
variable {G H : Type*} [MeasurableSpace G] [MeasurableSpace H]
namespace MeasureTheory
section Mul
variable [Mul G] {μ : Measure G}
@[to_additive]
theorem map_mul_left_eq_self (μ : Measure G) [IsMulLeftInvariant μ] (g : G) :
map (g * ·) μ = μ :=
IsMulLeftInvariant.map_mul_left_eq_self g
@[to_additive]
theorem map_mul_right_eq_self (μ : Measure G) [IsMulRightInvariant μ] (g : G) : map (· * g) μ = μ :=
IsMulRightInvariant.map_mul_right_eq_self g
@[to_additive MeasureTheory.isAddLeftInvariant_smul]
instance isMulLeftInvariant_smul [IsMulLeftInvariant μ] (c : ℝ≥0∞) : IsMulLeftInvariant (c • μ) :=
⟨fun g => by rw [Measure.map_smul, map_mul_left_eq_self]⟩
@[to_additive MeasureTheory.isAddRightInvariant_smul]
instance isMulRightInvariant_smul [IsMulRightInvariant μ] (c : ℝ≥0∞) :
IsMulRightInvariant (c • μ) :=
⟨fun g => by rw [Measure.map_smul, map_mul_right_eq_self]⟩
@[to_additive MeasureTheory.isAddLeftInvariant_smul_nnreal]
instance isMulLeftInvariant_smul_nnreal [IsMulLeftInvariant μ] (c : ℝ≥0) :
IsMulLeftInvariant (c • μ) :=
MeasureTheory.isMulLeftInvariant_smul (c : ℝ≥0∞)
@[to_additive MeasureTheory.isAddRightInvariant_smul_nnreal]
instance isMulRightInvariant_smul_nnreal [IsMulRightInvariant μ] (c : ℝ≥0) :
IsMulRightInvariant (c • μ) :=
MeasureTheory.isMulRightInvariant_smul (c : ℝ≥0∞)
section MeasurableMul
variable [MeasurableMul G]
@[to_additive]
theorem measurePreserving_mul_left (μ : Measure G) [IsMulLeftInvariant μ] (g : G) :
MeasurePreserving (g * ·) μ μ :=
⟨measurable_const_mul g, map_mul_left_eq_self μ g⟩
@[to_additive]
theorem MeasurePreserving.mul_left (μ : Measure G) [IsMulLeftInvariant μ] (g : G) {X : Type*}
[MeasurableSpace X] {μ' : Measure X} {f : X → G} (hf : MeasurePreserving f μ' μ) :
MeasurePreserving (fun x => g * f x) μ' μ :=
(measurePreserving_mul_left μ g).comp hf
@[to_additive]
theorem measurePreserving_mul_right (μ : Measure G) [IsMulRightInvariant μ] (g : G) :
MeasurePreserving (· * g) μ μ :=
⟨measurable_mul_const g, map_mul_right_eq_self μ g⟩
@[to_additive]
theorem MeasurePreserving.mul_right (μ : Measure G) [IsMulRightInvariant μ] (g : G) {X : Type*}
[MeasurableSpace X] {μ' : Measure X} {f : X → G} (hf : MeasurePreserving f μ' μ) :
MeasurePreserving (fun x => f x * g) μ' μ :=
(measurePreserving_mul_right μ g).comp hf
@[to_additive]
instance Subgroup.smulInvariantMeasure {G α : Type*} [Group G] [MulAction G α] [MeasurableSpace α]
{μ : Measure α} [SMulInvariantMeasure G α μ] (H : Subgroup G) : SMulInvariantMeasure H α μ :=
⟨fun y s hs => by convert SMulInvariantMeasure.measure_preimage_smul (μ := μ) (y : G) hs⟩
/-- An alternative way to prove that `μ` is left invariant under multiplication. -/
@[to_additive "An alternative way to prove that `μ` is left invariant under addition."]
theorem forall_measure_preimage_mul_iff (μ : Measure G) :
(∀ (g : G) (A : Set G), MeasurableSet A → μ ((fun h => g * h) ⁻¹' A) = μ A) ↔
IsMulLeftInvariant μ := by
trans ∀ g, map (g * ·) μ = μ
· simp_rw [Measure.ext_iff]
refine forall_congr' fun g => forall_congr' fun A => forall_congr' fun hA => ?_
rw [map_apply (measurable_const_mul g) hA]
exact ⟨fun h => ⟨h⟩, fun h => h.1⟩
/-- An alternative way to prove that `μ` is right invariant under multiplication. -/
@[to_additive "An alternative way to prove that `μ` is right invariant under addition."]
theorem forall_measure_preimage_mul_right_iff (μ : Measure G) :
(∀ (g : G) (A : Set G), MeasurableSet A → μ ((fun h => h * g) ⁻¹' A) = μ A) ↔
IsMulRightInvariant μ := by
trans ∀ g, map (· * g) μ = μ
· simp_rw [Measure.ext_iff]
refine forall_congr' fun g => forall_congr' fun A => forall_congr' fun hA => ?_
rw [map_apply (measurable_mul_const g) hA]
exact ⟨fun h => ⟨h⟩, fun h => h.1⟩
@[to_additive]
instance Measure.prod.instIsMulLeftInvariant [IsMulLeftInvariant μ] [SFinite μ] {H : Type*}
[Mul H] {mH : MeasurableSpace H} {ν : Measure H} [MeasurableMul H] [IsMulLeftInvariant ν]
[SFinite ν] : IsMulLeftInvariant (μ.prod ν) := by
constructor
rintro ⟨g, h⟩
change map (Prod.map (g * ·) (h * ·)) (μ.prod ν) = μ.prod ν
rw [← map_prod_map _ _ (measurable_const_mul g) (measurable_const_mul h),
map_mul_left_eq_self μ g, map_mul_left_eq_self ν h]
@[to_additive]
instance Measure.prod.instIsMulRightInvariant [IsMulRightInvariant μ] [SFinite μ] {H : Type*}
[Mul H] {mH : MeasurableSpace H} {ν : Measure H} [MeasurableMul H] [IsMulRightInvariant ν]
[SFinite ν] : IsMulRightInvariant (μ.prod ν) := by
constructor
rintro ⟨g, h⟩
change map (Prod.map (· * g) (· * h)) (μ.prod ν) = μ.prod ν
rw [← map_prod_map _ _ (measurable_mul_const g) (measurable_mul_const h),
map_mul_right_eq_self μ g, map_mul_right_eq_self ν h]
@[to_additive]
theorem isMulLeftInvariant_map {H : Type*} [MeasurableSpace H] [Mul H] [MeasurableMul H]
[IsMulLeftInvariant μ] (f : G →ₙ* H) (hf : Measurable f) (h_surj : Surjective f) :
IsMulLeftInvariant (Measure.map f μ) := by
refine ⟨fun h => ?_⟩
rw [map_map (measurable_const_mul _) hf]
obtain ⟨g, rfl⟩ := h_surj h
conv_rhs => rw [← map_mul_left_eq_self μ g]
rw [map_map hf (measurable_const_mul _)]
congr 2
ext y
simp only [comp_apply, map_mul]
end MeasurableMul
end Mul
section Semigroup
variable [Semigroup G] [MeasurableMul G] {μ : Measure G}
/-- The image of a left invariant measure under a left action is left invariant, assuming that
the action preserves multiplication. -/
@[to_additive "The image of a left invariant measure under a left additive action is left invariant,
assuming that the action preserves addition."]
theorem isMulLeftInvariant_map_smul
{α} [SMul α G] [SMulCommClass α G G] [MeasurableSpace α] [MeasurableSMul α G]
[IsMulLeftInvariant μ] (a : α) :
IsMulLeftInvariant (map (a • · : G → G) μ) :=
(forall_measure_preimage_mul_iff _).1 fun x _ hs =>
(smulInvariantMeasure_map_smul μ a).measure_preimage_smul x hs
/-- The image of a right invariant measure under a left action is right invariant, assuming that
the action preserves multiplication. -/
@[to_additive "The image of a right invariant measure under a left additive action is right
invariant, assuming that the action preserves addition."]
theorem isMulRightInvariant_map_smul
{α} [SMul α G] [SMulCommClass α Gᵐᵒᵖ G] [MeasurableSpace α] [MeasurableSMul α G]
[IsMulRightInvariant μ] (a : α) :
IsMulRightInvariant (map (a • · : G → G) μ) :=
(forall_measure_preimage_mul_right_iff _).1 fun x _ hs =>
(smulInvariantMeasure_map_smul μ a).measure_preimage_smul (MulOpposite.op x) hs
/-- The image of a left invariant measure under right multiplication is left invariant. -/
@[to_additive isMulLeftInvariant_map_add_right
"The image of a left invariant measure under right addition is left invariant."]
instance isMulLeftInvariant_map_mul_right [IsMulLeftInvariant μ] (g : G) :
IsMulLeftInvariant (map (· * g) μ) :=
isMulLeftInvariant_map_smul (MulOpposite.op g)
/-- The image of a right invariant measure under left multiplication is right invariant. -/
@[to_additive isMulRightInvariant_map_add_left
"The image of a right invariant measure under left addition is right invariant."]
instance isMulRightInvariant_map_mul_left [IsMulRightInvariant μ] (g : G) :
IsMulRightInvariant (map (g * ·) μ) :=
isMulRightInvariant_map_smul g
end Semigroup
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem map_div_right_eq_self (μ : Measure G) [IsMulRightInvariant μ] (g : G) :
map (· / g) μ = μ := by simp_rw [div_eq_mul_inv, map_mul_right_eq_self μ g⁻¹]
end DivInvMonoid
section Group
variable [Group G] [MeasurableMul G]
@[to_additive]
theorem measurePreserving_div_right (μ : Measure G) [IsMulRightInvariant μ] (g : G) :
MeasurePreserving (· / g) μ μ := by simp_rw [div_eq_mul_inv, measurePreserving_mul_right μ g⁻¹]
/-- We shorten this from `measure_preimage_mul_left`, since left invariant is the preferred option
for measures in this formalization. -/
@[to_additive (attr := simp)
"We shorten this from `measure_preimage_add_left`, since left invariant is the preferred option for
measures in this formalization."]
theorem measure_preimage_mul (μ : Measure G) [IsMulLeftInvariant μ] (g : G) (A : Set G) :
μ ((fun h => g * h) ⁻¹' A) = μ A :=
calc
μ ((fun h => g * h) ⁻¹' A) = map (fun h => g * h) μ A :=
| ((MeasurableEquiv.mulLeft g).map_apply A).symm
_ = μ A := by rw [map_mul_left_eq_self μ g]
@[to_additive (attr := simp)]
theorem measure_preimage_mul_right (μ : Measure G) [IsMulRightInvariant μ] (g : G) (A : Set G) :
μ ((fun h => h * g) ⁻¹' A) = μ A :=
calc
μ ((fun h => h * g) ⁻¹' A) = map (fun h => h * g) μ A :=
((MeasurableEquiv.mulRight g).map_apply A).symm
_ = μ A := by rw [map_mul_right_eq_self μ g]
| Mathlib/MeasureTheory/Group/Measure.lean | 229 | 239 |
/-
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, Kim Morrison, Jens Wagemaker, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by
by_cases hp0 : p = 0
· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots ≤ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl]))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by
classical
rw [← count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S →+* R}
(hf : Function.Injective f) {x : R} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by
rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.id.map_eq_id, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) :
#Z ≤ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [← sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by
rintro ⟨k, rfl⟩
exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x ∈ (p - C a).roots ↔ p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = ∅ :=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X - C b).roots =
{a⁻¹ * b} := by
rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (a⁻¹ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X + C b).roots =
{-(a⁻¹ * b)} := by
rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ←
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by
rcases m with ⟨L⟩
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) :
s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with ⟨m, hm⟩
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
@[simp]
theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by
induction n with
| zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero]
| succ n ihn =>
rcases eq_or_ne p 0 with (rfl | hp)
· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero]
· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by
rw [roots_pow, roots_X]
theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) :
Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by
rw [roots_C_mul _ ha, roots_X_pow]
@[simp]
theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by
rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
@[simp]
theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by
rw [roots_multiset_prod, Multiset.bind_map]
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· rw [Multiset.mem_map]
rintro ⟨a, -, h⟩
exact X_sub_C_ne_zero a h
theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n :=
WithBot.coe_le_coe.1 <|
calc
(Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) :=
card_roots (X_pow_sub_C_ne_zero hn a)
_ = n := degree_X_pow_sub_C hn a
section NthRoots
/-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/
def nthRoots (n : ℕ) (a : R) : Multiset R :=
roots ((X : R[X]) ^ n - C a)
@[simp]
theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by
rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow,
eval_X, sub_eq_zero]
@[simp]
theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by
simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C]
@[simp]
theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) :
nthRoots n (0 : R) = Multiset.replicate n 0 := by
rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton]
theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by
classical exact
(if hn : n = 0 then
if h : (X : R[X]) ^ n - C a = 0 then by
simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero]
else
WithBot.coe_le_coe.1
(le_trans (card_roots h)
(by
rw [hn, pow_zero, ← C_1, ← RingHom.map_sub]
exact degree_C_le))
else by
rw [← Nat.cast_le (α := WithBot ℕ)]
rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a]
exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a))
@[simp]
theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by
simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2),
← not_exists, eq_comm]
/-- The multiset `nthRoots ↑n a` as a Finset. Previously `nthRootsFinset n` was defined to be
`nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/
def nthRootsFinset (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R :=
haveI := Classical.decEq R
Multiset.toFinset (nthRoots n a)
lemma nthRootsFinset_def (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] :
nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by
unfold nthRootsFinset
convert rfl
@[simp]
theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) (a : R) {x : R} :
x ∈ nthRootsFinset n a ↔ x ^ (n : ℕ) = a := by
classical
rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h]
@[simp]
theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = ∅ := by
classical simp [nthRootsFinset_def]
theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[MonoidHomClass F R S] {a : R} {x : R} (hx : x ∈ nthRootsFinset n a) (f : F) :
f x ∈ nthRootsFinset n (f a) := by
by_cases hn : n = 0
· simp [hn] at hx
· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, ← map_pow, (mem_nthRootsFinset
(Nat.pos_of_ne_zero hn) a).1 hx]
theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[RingHomClass F R S] {x : R} (hx : x ∈ nthRootsFinset n 1) (f : F) :
f x ∈ nthRootsFinset n 1 := by
rw [← (map_one f)]
exact map_mem_nthRootsFinset hx _
theorem mul_mem_nthRootsFinset
{η₁ η₂ : R} {a₁ a₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n a₁) (hη₂ : η₂ ∈ nthRootsFinset n a₂) :
η₁ * η₂ ∈ nthRootsFinset n (a₁ * a₂) := by
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hη₁
| succ n =>
rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢
rw [mul_pow, hη₁, hη₂]
theorem ne_zero_of_mem_nthRootsFinset {η : R} {a : R} (ha : a ≠ 0) (hη : η ∈ nthRootsFinset n a) :
η ≠ 0 := by
nontriviality R
rintro rfl
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hη
| succ n =>
rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη
exact ha hη.symm
theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n (1 : R) := by
rw [mem_nthRootsFinset hn, one_pow]
end NthRoots
theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by
classical
by_contra hp
refine @Fintype.false R _ ?_
exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩
theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by
rw [← sub_eq_zero]
apply zero_of_eval_zero
intro x
rw [eval_sub, sub_eq_zero, ext]
variable [CommRing T]
/-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is
the multiset of roots of `p` regarded as a polynomial over `S`. -/
noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S :=
(p.map (algebraMap T S)).roots
theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
p.aroots S = (p.map (algebraMap T S)).roots :=
rfl
theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} :
a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by
rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def]
theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by
rw [mem_aroots', Polynomial.map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) :
(p * q).aroots S = p.aroots S + q.aroots S := by
suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by
rw [aroots_def, Polynomial.map_mul, roots_mul this]
rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff
(FaithfulSMul.algebraMap_injective T S)]
@[simp]
theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S]
(r : T) : aroots (X - C r) S = {algebraMap T S r} := by
rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C]
@[simp]
theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] :
aroots (X : T[X]) S = {0} := by
rw [aroots_def, map_X, roots_X]
@[simp]
theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by
rw [aroots_def, map_C, roots_C]
@[simp]
theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by
rw [← C_0, aroots_C]
@[simp]
theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] :
(1 : T[X]).aroots S = 0 :=
aroots_C 1
@[simp]
theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) :
(-p).aroots S = p.aroots S := by
rw [aroots, Polynomial.map_neg, roots_neg]
@[simp]
theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(C a * p).aroots S = p.aroots S := by
rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul]
rwa [map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
@[simp]
theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(a • p).aroots S = p.aroots S := by
rw [smul_eq_C_mul, aroots_C_mul _ ha]
@[simp]
theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : ℕ) :
(p ^ n).aroots S = n • p.aroots S := by
rw [aroots_def, Polynomial.map_pow, roots_pow]
theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : ℕ) :
(X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_pow, aroots_X]
theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) :
(C a * X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_C_mul _ ha, aroots_X_pow]
@[simp]
theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) :
(monomial n a).aroots S = n • ({0} : Multiset S) := by
rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha]
variable (R S) in
@[simp]
theorem aroots_map (p : T[X]) [CommRing S] [Algebra T S] [Algebra S R] [Algebra T R]
[IsScalarTower T S R] :
(p.map (algebraMap T S)).aroots R = p.aroots R := by
rw [aroots_def, aroots_def, map_map, IsScalarTower.algebraMap_eq T S R]
/-- The set of distinct roots of `p` in `S`.
If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset
where multiple roots have the appropriate multiplicity. -/
def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S :=
haveI := Classical.decEq S
(p.aroots S).toFinset
theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] :
p.rootSet S = (p.aroots S).toFinset := by
rw [rootSet]
convert rfl
@[simp]
theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = ∅ := by
classical
rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty]
@[simp]
theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = ∅ := by
rw [← C_0, rootSet_C]
@[simp]
theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = ∅ := by
rw [← C_1, rootSet_C]
@[simp]
theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
(-p).rootSet S = p.rootSet S := by
rw [rootSet, aroots_neg, rootSet]
instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
Fintype (p.rootSet S) :=
FinsetCoe.fintype _
theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
(p.rootSet S).Finite :=
Set.toFinite _
/-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set
is finite. -/
theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S]
(m : R →+* S) (d : ℕ) {U : Set R} (h : U.Finite) :
(⋃ (f : R[X]) (_ : f.natDegree ≤ d ∧ ∀ i, f.coeff i ∈ U),
((f.map m).roots.toFinset.toSet : Set S)).Finite :=
Set.Finite.biUnion
(by
-- We prove that the set of polynomials under consideration is finite because its
-- image by the injective map `π` is finite
let π : R[X] → Fin (d + 1) → R := fun f i => f.coeff i
refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn π _)
· exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i
· refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_
exact id congr_fun hxy ⟨i, Nat.lt_succ_of_le hi⟩)
fun _ _ => Finset.finite_toSet _
theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} :
a ∈ p.rootSet S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by
classical
rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots']
theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : S} : a ∈ p.rootSet S ↔ p ≠ 0 ∧ aeval a p = 0 := by
rw [mem_rootSet', Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)]
|
theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] (hp : p ≠ 0) {a : S} : a ∈ p.rootSet S ↔ aeval a p = 0 :=
mem_rootSet.trans <| and_iff_right hp
theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 → p.map (algebraMap T S) = 0)
(f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by
rw [mem_rootSet'] at hx ⊢
rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero]
exact ⟨mt hp hx.1, rfl⟩
theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(h : a ∈ p.rootSet S) : p ≠ 0 := fun hf => by rwa [hf, rootSet_zero] at h
| Mathlib/Algebra/Polynomial/Roots.lean | 546 | 559 |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Covering.Differentiation
/-!
# Besicovitch covering theorems
The topological Besicovitch covering theorem ensures that, in a nice metric space, there exists a
number `N` such that, from any family of balls with bounded radii, one can extract `N` families,
each made of disjoint balls, covering together all the centers of the initial family.
By "nice metric space", we mean a technical property stated as follows: there exists no satellite
configuration of `N + 1` points (with a given parameter `τ > 1`). Such a configuration is a family
of `N + 1` balls, where the first `N` balls all intersect the last one, but none of them contains
the center of another one and their radii are controlled. This property is for instance
satisfied by finite-dimensional real vector spaces.
In this file, we prove the topological Besicovitch covering theorem,
in `Besicovitch.exist_disjoint_covering_families`.
The measurable Besicovitch theorem ensures that, in the same class of metric spaces, if at every
point one considers a class of balls of arbitrarily small radii, called admissible balls, then
one can cover almost all the space by a family of disjoint admissible balls.
It is deduced from the topological Besicovitch theorem, and proved
in `Besicovitch.exists_disjoint_closedBall_covering_ae`.
This implies that balls of small radius form a Vitali family in such spaces. Therefore, theorems
on differentiation of measures hold as a consequence of general results. We restate them in this
context to make them more easily usable.
## Main definitions and results
* `SatelliteConfig α N τ` is the type of all satellite configurations of `N + 1` points
in the metric space `α`, with parameter `τ`.
* `HasBesicovitchCovering` is a class recording that there exist `N` and `τ > 1` such that
there is no satellite configuration of `N + 1` points with parameter `τ`.
* `exist_disjoint_covering_families` is the topological Besicovitch covering theorem: from any
family of balls one can extract finitely many disjoint subfamilies covering the same set.
* `exists_disjoint_closedBall_covering` is the measurable Besicovitch covering theorem: from any
family of balls with arbitrarily small radii at every point, one can extract countably many
disjoint balls covering almost all the space. While the value of `N` is relevant for the precise
statement of the topological Besicovitch theorem, it becomes irrelevant for the measurable one.
Therefore, this statement is expressed using the `Prop`-valued
typeclass `HasBesicovitchCovering`.
We also restate the following specialized versions of general theorems on differentiation of
measures:
* `Besicovitch.ae_tendsto_rnDeriv` ensures that `ρ (closedBall x r) / μ (closedBall x r)` tends
almost surely to the Radon-Nikodym derivative of `ρ` with respect to `μ` at `x`.
* `Besicovitch.ae_tendsto_measure_inter_div` states that almost every point in an arbitrary set `s`
is a Lebesgue density point, i.e., `μ (s ∩ closedBall x r) / μ (closedBall x r)` tends to `1` as
`r` tends to `0`. A stronger version for measurable sets is given in
`Besicovitch.ae_tendsto_measure_inter_div_of_measurableSet`.
## Implementation
#### Sketch of proof of the topological Besicovitch theorem:
We choose balls in a greedy way. First choose a ball with maximal radius (or rather, since there
is no guarantee the maximal radius is realized, a ball with radius within a factor `τ` of the
supremum). Then, remove all balls whose center is covered by the first ball, and choose among the
remaining ones a ball with radius close to maximum. Go on forever until there is no available
center (this is a transfinite induction in general).
Then define inductively a coloring of the balls. A ball will be of color `i` if it intersects
already chosen balls of color `0`, ..., `i - 1`, but none of color `i`. In this way, balls of the
same color form a disjoint family, and the space is covered by the families of the different colors.
The nontrivial part is to show that at most `N` colors are used. If one needs `N + 1` colors,
consider the first time this happens. Then the corresponding ball intersects `N` balls of the
different colors. Moreover, the inductive construction ensures that the radii of all the balls are
controlled: they form a satellite configuration with `N + 1` balls (essentially by definition of
satellite configurations). Since we assume that there are no such configurations, this is a
contradiction.
#### Sketch of proof of the measurable Besicovitch theorem:
From the topological Besicovitch theorem, one can find a disjoint countable family of balls
covering a proportion `> 1 / (N + 1)` of the space. Taking a large enough finite subset of these
balls, one gets the same property for finitely many balls. Their union is closed. Therefore, any
point in the complement has around it an admissible ball not intersecting these finitely many balls.
Applying again the topological Besicovitch theorem, one extracts from these a disjoint countable
subfamily covering a proportion `> 1 / (N + 1)` of the remaining points, and then even a disjoint
finite subfamily. Then one goes on again and again, covering at each step a positive proportion of
the remaining points, while remaining disjoint from the already chosen balls. The union of all these
balls is the desired almost everywhere covering.
-/
noncomputable section
universe u
open Metric Set Filter Fin MeasureTheory TopologicalSpace
open scoped Topology ENNReal MeasureTheory NNReal
/-!
### Satellite configurations
-/
/-- A satellite configuration is a configuration of `N+1` points that shows up in the inductive
construction for the Besicovitch covering theorem. It depends on some parameter `τ ≥ 1`.
This is a family of balls (indexed by `i : Fin N.succ`, with center `c i` and radius `r i`) such
that the last ball intersects all the other balls (condition `inter`),
and given any two balls there is an order between them, ensuring that the first ball does not
contain the center of the other one, and the radius of the second ball can not be larger than
the radius of the first ball (up to a factor `τ`). This order corresponds to the order of choice
in the inductive construction: otherwise, the second ball would have been chosen before.
This is the condition `h`.
Finally, the last ball is chosen after all the other ones, meaning that `h` can be strengthened
by keeping only one side of the alternative in `hlast`.
-/
structure Besicovitch.SatelliteConfig (α : Type*) [MetricSpace α] (N : ℕ) (τ : ℝ) where
/-- Centers of the balls -/
c : Fin N.succ → α
/-- Radii of the balls -/
r : Fin N.succ → ℝ
rpos : ∀ i, 0 < r i
h : Pairwise fun i j =>
r i ≤ dist (c i) (c j) ∧ r j ≤ τ * r i ∨ r j ≤ dist (c j) (c i) ∧ r i ≤ τ * r j
hlast : ∀ i < last N, r i ≤ dist (c i) (c (last N)) ∧ r (last N) ≤ τ * r i
inter : ∀ i < last N, dist (c i) (c (last N)) ≤ r i + r (last N)
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
/-- Extension for the `positivity` tactic: `Besicovitch.SatelliteConfig.r`. -/
@[positivity Besicovitch.SatelliteConfig.r _ _]
def evalBesicovitchSatelliteConfigR : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(@Besicovitch.SatelliteConfig.r $β $inst $N $τ $self $i) =>
assertInstancesCommute
return .positive q(Besicovitch.SatelliteConfig.rpos $self $i)
| _, _, _ => throwError "not Besicovitch.SatelliteConfig.r"
end Mathlib.Meta.Positivity
/-- A metric space has the Besicovitch covering property if there exist `N` and `τ > 1` such that
there are no satellite configuration of parameter `τ` with `N+1` points. This is the condition that
guarantees that the measurable Besicovitch covering theorem holds. It is satisfied by
finite-dimensional real vector spaces. -/
class HasBesicovitchCovering (α : Type*) [MetricSpace α] : Prop where
no_satelliteConfig : ∃ (N : ℕ) (τ : ℝ), 1 < τ ∧ IsEmpty (Besicovitch.SatelliteConfig α N τ)
/-- There is always a satellite configuration with a single point. -/
instance Besicovitch.SatelliteConfig.instInhabited {α : Type*} {τ : ℝ}
[Inhabited α] [MetricSpace α] : Inhabited (Besicovitch.SatelliteConfig α 0 τ) :=
⟨{ c := default
r := fun _ => 1
rpos := fun _ => zero_lt_one
h := fun i j hij => (hij (Subsingleton.elim (α := Fin 1) i j)).elim
hlast := fun i hi => by
rw [Subsingleton.elim (α := Fin 1) i (last 0)] at hi; exact (lt_irrefl _ hi).elim
inter := fun i hi => by
rw [Subsingleton.elim (α := Fin 1) i (last 0)] at hi; exact (lt_irrefl _ hi).elim }⟩
namespace Besicovitch
namespace SatelliteConfig
variable {α : Type*} [MetricSpace α] {N : ℕ} {τ : ℝ} (a : SatelliteConfig α N τ)
theorem inter' (i : Fin N.succ) : dist (a.c i) (a.c (last N)) ≤ a.r i + a.r (last N) := by
rcases lt_or_le i (last N) with (H | H)
· exact a.inter i H
· have I : i = last N := top_le_iff.1 H
have := (a.rpos (last N)).le
simp only [I, add_nonneg this this, dist_self]
theorem hlast' (i : Fin N.succ) (h : 1 ≤ τ) : a.r (last N) ≤ τ * a.r i := by
rcases lt_or_le i (last N) with (H | H)
· exact (a.hlast i H).2
· have : i = last N := top_le_iff.1 H
rw [this]
exact le_mul_of_one_le_left (a.rpos _).le h
end SatelliteConfig
/-! ### Extracting disjoint subfamilies from a ball covering -/
/-- A ball package is a family of balls in a metric space with positive bounded radii. -/
structure BallPackage (β : Type*) (α : Type*) where
/-- Centers of the balls -/
c : β → α
/-- Radii of the balls -/
r : β → ℝ
rpos : ∀ b, 0 < r b
/-- Bound on the radii of the balls -/
r_bound : ℝ
r_le : ∀ b, r b ≤ r_bound
/-- The ball package made of unit balls. -/
def unitBallPackage (α : Type*) : BallPackage α α where
c := id
r _ := 1
rpos _ := zero_lt_one
r_bound := 1
r_le _ := le_rfl
instance BallPackage.instInhabited (α : Type*) : Inhabited (BallPackage α α) :=
⟨unitBallPackage α⟩
/-- A Besicovitch tau-package is a family of balls in a metric space with positive bounded radii,
together with enough data to proceed with the Besicovitch greedy algorithm. We register this in
a single structure to make sure that all our constructions in this algorithm only depend on
one variable. -/
structure TauPackage (β : Type*) (α : Type*) extends BallPackage β α where
/-- Parameter used by the Besicovitch greedy algorithm -/
τ : ℝ
one_lt_tau : 1 < τ
instance TauPackage.instInhabited (α : Type*) : Inhabited (TauPackage α α) :=
⟨{ unitBallPackage α with
τ := 2
one_lt_tau := one_lt_two }⟩
variable {α : Type*} [MetricSpace α] {β : Type u}
namespace TauPackage
variable [Nonempty β] (p : TauPackage β α)
/-- Choose inductively large balls with centers that are not contained in the union of already
chosen balls. This is a transfinite induction. -/
noncomputable def index : Ordinal.{u} → β
| i =>
-- `Z` is the set of points that are covered by already constructed balls
let Z := ⋃ j : { j // j < i }, ball (p.c (index j)) (p.r (index j))
-- `R` is the supremum of the radii of balls with centers not in `Z`
let R := iSup fun b : { b : β // p.c b ∉ Z } => p.r b
-- return an index `b` for which the center `c b` is not in `Z`, and the radius is at
-- least `R / τ`, if such an index exists (and garbage otherwise).
Classical.epsilon fun b : β => p.c b ∉ Z ∧ R ≤ p.τ * p.r b
termination_by i => i
decreasing_by exact j.2
/-- The set of points that are covered by the union of balls selected at steps `< i`. -/
def iUnionUpTo (i : Ordinal.{u}) : Set α :=
⋃ j : { j // j < i }, ball (p.c (p.index j)) (p.r (p.index j))
theorem monotone_iUnionUpTo : Monotone p.iUnionUpTo := by
intro i j hij
simp only [iUnionUpTo]
exact iUnion_mono' fun r => ⟨⟨r, r.2.trans_le hij⟩, Subset.rfl⟩
/-- Supremum of the radii of balls whose centers are not yet covered at step `i`. -/
def R (i : Ordinal.{u}) : ℝ :=
iSup fun b : { b : β // p.c b ∉ p.iUnionUpTo i } => p.r b
/-- Group the balls into disjoint families, by assigning to a ball the smallest color for which
it does not intersect any already chosen ball of this color. -/
noncomputable def color : Ordinal.{u} → ℕ
| i =>
let A : Set ℕ :=
⋃ (j : { j // j < i })
(_ : (closedBall (p.c (p.index j)) (p.r (p.index j)) ∩
closedBall (p.c (p.index i)) (p.r (p.index i))).Nonempty), {color j}
sInf (univ \ A)
termination_by i => i
decreasing_by exact j.2
/-- `p.lastStep` is the first ordinal where the construction stops making sense, i.e., `f` returns
garbage since there is no point left to be chosen. We will only use ordinals before this step. -/
def lastStep : Ordinal.{u} :=
sInf {i | ¬∃ b : β, p.c b ∉ p.iUnionUpTo i ∧ p.R i ≤ p.τ * p.r b}
theorem lastStep_nonempty :
{i | ¬∃ b : β, p.c b ∉ p.iUnionUpTo i ∧ p.R i ≤ p.τ * p.r b}.Nonempty := by
by_contra h
suffices H : Function.Injective p.index from not_injective_of_ordinal p.index H
intro x y hxy
wlog x_le_y : x ≤ y generalizing x y
· exact (this hxy.symm (le_of_not_le x_le_y)).symm
rcases eq_or_lt_of_le x_le_y with (rfl | H); · rfl
simp only [nonempty_def, not_exists, exists_prop, not_and, not_lt, not_le, mem_setOf_eq,
not_forall] at h
specialize h y
have A : p.c (p.index y) ∉ p.iUnionUpTo y := by
have :
p.index y =
Classical.epsilon fun b : β => p.c b ∉ p.iUnionUpTo y ∧ p.R y ≤ p.τ * p.r b := by
rw [TauPackage.index]; rfl
rw [this]
exact (Classical.epsilon_spec h).1
simp only [iUnionUpTo, not_exists, exists_prop, mem_iUnion, mem_closedBall, not_and, not_le,
Subtype.exists, Subtype.coe_mk] at A
specialize A x H
simp? [hxy] at A says simp only [hxy, mem_ball, dist_self, not_lt] at A
exact (lt_irrefl _ ((p.rpos (p.index y)).trans_le A)).elim
/-- Every point is covered by chosen balls, before `p.lastStep`. -/
theorem mem_iUnionUpTo_lastStep (x : β) : p.c x ∈ p.iUnionUpTo p.lastStep := by
have A : ∀ z : β, p.c z ∈ p.iUnionUpTo p.lastStep ∨ p.τ * p.r z < p.R p.lastStep := by
have : p.lastStep ∈ {i | ¬∃ b : β, p.c b ∉ p.iUnionUpTo i ∧ p.R i ≤ p.τ * p.r b} :=
csInf_mem p.lastStep_nonempty
simpa only [not_exists, mem_setOf_eq, not_and_or, not_le, not_not_mem]
by_contra h
rcases A x with (H | H); · exact h H
have Rpos : 0 < p.R p.lastStep := by
apply lt_trans (mul_pos (_root_.zero_lt_one.trans p.one_lt_tau) (p.rpos _)) H
have B : p.τ⁻¹ * p.R p.lastStep < p.R p.lastStep := by
conv_rhs => rw [← one_mul (p.R p.lastStep)]
exact mul_lt_mul (inv_lt_one_of_one_lt₀ p.one_lt_tau) le_rfl Rpos zero_le_one
obtain ⟨y, hy1, hy2⟩ : ∃ y, p.c y ∉ p.iUnionUpTo p.lastStep ∧ p.τ⁻¹ * p.R p.lastStep < p.r y := by
have := exists_lt_of_lt_csSup ?_ B
· simpa only [exists_prop, mem_range, exists_exists_and_eq_and, Subtype.exists,
Subtype.coe_mk]
rw [← image_univ, image_nonempty]
exact ⟨⟨_, h⟩, mem_univ _⟩
rcases A y with (Hy | Hy)
· exact hy1 Hy
· rw [← div_eq_inv_mul] at hy2
have := (div_le_iff₀' (_root_.zero_lt_one.trans p.one_lt_tau)).1 hy2.le
exact lt_irrefl _ (Hy.trans_le this)
/-- If there are no configurations of satellites with `N+1` points, one never uses more than `N`
distinct families in the Besicovitch inductive construction. -/
theorem color_lt {i : Ordinal.{u}} (hi : i < p.lastStep) {N : ℕ}
(hN : IsEmpty (SatelliteConfig α N p.τ)) : p.color i < N := by
/- By contradiction, consider the first ordinal `i` for which one would have `p.color i = N`.
Choose for each `k < N` a ball with color `k` that intersects the ball at color `i`
(there is such a ball, otherwise one would have used the color `k` and not `N`).
Then this family of `N+1` balls forms a satellite configuration, which is forbidden by
the assumption `hN`. -/
induction' i using Ordinal.induction with i IH
let A : Set ℕ :=
⋃ (j : { j // j < i })
(_ : (closedBall (p.c (p.index j)) (p.r (p.index j)) ∩
closedBall (p.c (p.index i)) (p.r (p.index i))).Nonempty),
{p.color j}
have color_i : p.color i = sInf (univ \ A) := by rw [color]
rw [color_i]
have N_mem : N ∈ univ \ A := by
simp only [A, not_exists, true_and, exists_prop, mem_iUnion, mem_singleton_iff,
mem_closedBall, not_and, mem_univ, mem_diff, Subtype.exists, Subtype.coe_mk]
intro j ji _
exact (IH j ji (ji.trans hi)).ne'
suffices sInf (univ \ A) ≠ N by
rcases (csInf_le (OrderBot.bddBelow (univ \ A)) N_mem).lt_or_eq with (H | H)
· exact H
· exact (this H).elim
intro Inf_eq_N
have :
∀ k, k < N → ∃ j, j < i ∧
(closedBall (p.c (p.index j)) (p.r (p.index j)) ∩
closedBall (p.c (p.index i)) (p.r (p.index i))).Nonempty ∧ k = p.color j := by
intro k hk
rw [← Inf_eq_N] at hk
have : k ∈ A := by
simpa only [true_and, mem_univ, Classical.not_not, mem_diff] using
Nat.not_mem_of_lt_sInf hk
simp only [mem_iUnion, mem_singleton_iff, exists_prop, Subtype.exists, exists_and_right,
and_assoc] at this
simpa only [A, exists_prop, mem_iUnion, mem_singleton_iff, mem_closedBall, Subtype.exists,
Subtype.coe_mk]
choose! g hg using this
-- Choose for each `k < N` an ordinal `G k < i` giving a ball of color `k` intersecting
-- the last ball.
let G : ℕ → Ordinal := fun n => if n = N then i else g n
have color_G : ∀ n, n ≤ N → p.color (G n) = n := by
intro n hn
rcases hn.eq_or_lt with (rfl | H)
· simp only [G]; simp only [color_i, Inf_eq_N, if_true, eq_self_iff_true]
· simp only [G]; simp only [H.ne, (hg n H).right.right.symm, if_false]
have G_lt_last : ∀ n, n ≤ N → G n < p.lastStep := by
intro n hn
rcases hn.eq_or_lt with (rfl | H)
· simp only [G]; simp only [hi, if_true, eq_self_iff_true]
· simp only [G]; simp only [H.ne, (hg n H).left.trans hi, if_false]
have fGn :
∀ n, n ≤ N →
p.c (p.index (G n)) ∉ p.iUnionUpTo (G n) ∧ p.R (G n) ≤ p.τ * p.r (p.index (G n)) := by
intro n hn
have :
p.index (G n) =
Classical.epsilon fun t => p.c t ∉ p.iUnionUpTo (G n) ∧ p.R (G n) ≤ p.τ * p.r t := by
rw [index]; rfl
rw [this]
have : ∃ t, p.c t ∉ p.iUnionUpTo (G n) ∧ p.R (G n) ≤ p.τ * p.r t := by
simpa only [not_exists, exists_prop, not_and, not_lt, not_le, mem_setOf_eq, not_forall] using
not_mem_of_lt_csInf (G_lt_last n hn) (OrderBot.bddBelow _)
exact Classical.epsilon_spec this
-- the balls with indices `G k` satisfy the characteristic property of satellite configurations.
have Gab :
∀ a b : Fin (Nat.succ N),
G a < G b →
p.r (p.index (G a)) ≤ dist (p.c (p.index (G a))) (p.c (p.index (G b))) ∧
p.r (p.index (G b)) ≤ p.τ * p.r (p.index (G a)) := by
intro a b G_lt
have ha : (a : ℕ) ≤ N := Nat.lt_succ_iff.1 a.2
have hb : (b : ℕ) ≤ N := Nat.lt_succ_iff.1 b.2
constructor
· have := (fGn b hb).1
simp only [iUnionUpTo, not_exists, exists_prop, mem_iUnion, mem_closedBall, not_and, not_le,
Subtype.exists, Subtype.coe_mk] at this
simpa only [dist_comm, mem_ball, not_lt] using this (G a) G_lt
· apply le_trans _ (fGn a ha).2
have B : p.c (p.index (G b)) ∉ p.iUnionUpTo (G a) := by
intro H; exact (fGn b hb).1 (p.monotone_iUnionUpTo G_lt.le H)
let b' : { t // p.c t ∉ p.iUnionUpTo (G a) } := ⟨p.index (G b), B⟩
apply @le_ciSup _ _ _ (fun t : { t // p.c t ∉ p.iUnionUpTo (G a) } => p.r t) _ b'
refine ⟨p.r_bound, fun t ht => ?_⟩
simp only [exists_prop, mem_range, Subtype.exists, Subtype.coe_mk] at ht
rcases ht with ⟨u, hu⟩
rw [← hu.2]
exact p.r_le _
-- therefore, one may use them to construct a satellite configuration with `N+1` points
let sc : SatelliteConfig α N p.τ :=
{ c := fun k => p.c (p.index (G k))
r := fun k => p.r (p.index (G k))
rpos := fun k => p.rpos (p.index (G k))
h := by
intro a b a_ne_b
wlog G_le : G a ≤ G b generalizing a b
· exact (this a_ne_b.symm (le_of_not_le G_le)).symm
have G_lt : G a < G b := by
rcases G_le.lt_or_eq with (H | H); · exact H
have A : (a : ℕ) ≠ b := Fin.val_injective.ne a_ne_b
rw [← color_G a (Nat.lt_succ_iff.1 a.2), ← color_G b (Nat.lt_succ_iff.1 b.2), H] at A
exact (A rfl).elim
exact Or.inl (Gab a b G_lt)
hlast := by
intro a ha
have I : (a : ℕ) < N := ha
have : G a < G (Fin.last N) := by dsimp; simp [G, I.ne, (hg a I).1]
exact Gab _ _ this
inter := by
intro a ha
have I : (a : ℕ) < N := ha
have J : G (Fin.last N) = i := by dsimp; simp only [G, if_true, eq_self_iff_true]
have K : G a = g a := by dsimp [G]; simp [I.ne, (hg a I).1]
convert dist_le_add_of_nonempty_closedBall_inter_closedBall (hg _ I).2.1 }
-- this is a contradiction
exact hN.false sc
end TauPackage
open TauPackage
/-- The topological Besicovitch covering theorem: there exist finitely many families of disjoint
balls covering all the centers in a package. More specifically, one can use `N` families if there
are no satellite configurations with `N+1` points. -/
theorem exist_disjoint_covering_families {N : ℕ} {τ : ℝ} (hτ : 1 < τ)
(hN : IsEmpty (SatelliteConfig α N τ)) (q : BallPackage β α) :
∃ s : Fin N → Set β,
(∀ i : Fin N, (s i).PairwiseDisjoint fun j => closedBall (q.c j) (q.r j)) ∧
range q.c ⊆ ⋃ i : Fin N, ⋃ j ∈ s i, ball (q.c j) (q.r j) := by
-- first exclude the trivial case where `β` is empty (we need non-emptiness for the transfinite
-- induction, to be able to choose garbage when there is no point left).
cases isEmpty_or_nonempty β
· refine ⟨fun _ => ∅, fun _ => pairwiseDisjoint_empty, ?_⟩
rw [← image_univ, eq_empty_of_isEmpty (univ : Set β)]
simp
-- Now, assume `β` is nonempty.
let p : TauPackage β α :=
{ q with
τ
one_lt_tau := hτ }
-- we use for `s i` the balls of color `i`.
let s := fun i : Fin N =>
⋃ (k : Ordinal.{u}) (_ : k < p.lastStep) (_ : p.color k = i), ({p.index k} : Set β)
refine ⟨s, fun i => ?_, ?_⟩
· -- show that balls of the same color are disjoint
intro x hx y hy x_ne_y
obtain ⟨jx, jx_lt, jxi, rfl⟩ :
∃ jx : Ordinal, jx < p.lastStep ∧ p.color jx = i ∧ x = p.index jx := by
simpa only [s, exists_prop, mem_iUnion, mem_singleton_iff] using hx
obtain ⟨jy, jy_lt, jyi, rfl⟩ :
∃ jy : Ordinal, jy < p.lastStep ∧ p.color jy = i ∧ y = p.index jy := by
simpa only [s, exists_prop, mem_iUnion, mem_singleton_iff] using hy
wlog jxy : jx ≤ jy generalizing jx jy
· exact (this jy jy_lt jyi hy jx jx_lt jxi hx x_ne_y.symm (le_of_not_le jxy)).symm
replace jxy : jx < jy := by
rcases lt_or_eq_of_le jxy with (H | rfl); · { exact H }; · { exact (x_ne_y rfl).elim }
let A : Set ℕ :=
⋃ (j : { j // j < jy })
(_ : (closedBall (p.c (p.index j)) (p.r (p.index j)) ∩
closedBall (p.c (p.index jy)) (p.r (p.index jy))).Nonempty),
{p.color j}
have color_j : p.color jy = sInf (univ \ A) := by rw [TauPackage.color]
have h : p.color jy ∈ univ \ A := by
rw [color_j]
apply csInf_mem
refine ⟨N, ?_⟩
simp only [A, not_exists, true_and, exists_prop, mem_iUnion, mem_singleton_iff, not_and,
mem_univ, mem_diff, Subtype.exists, Subtype.coe_mk]
intro k hk _
exact (p.color_lt (hk.trans jy_lt) hN).ne'
simp only [A, not_exists, true_and, exists_prop, mem_iUnion, mem_singleton_iff, not_and,
mem_univ, mem_diff, Subtype.exists, Subtype.coe_mk] at h
specialize h jx jxy
contrapose! h
simpa only [jxi, jyi, and_true, eq_self_iff_true, ← not_disjoint_iff_nonempty_inter] using h
· -- show that the balls of color at most `N` cover every center.
refine range_subset_iff.2 fun b => ?_
obtain ⟨a, ha⟩ :
∃ a : Ordinal, a < p.lastStep ∧ dist (p.c b) (p.c (p.index a)) < p.r (p.index a) := by
simpa only [iUnionUpTo, exists_prop, mem_iUnion, mem_ball, Subtype.exists,
Subtype.coe_mk] using p.mem_iUnionUpTo_lastStep b
simp only [s, exists_prop, mem_iUnion, mem_ball, mem_singleton_iff, biUnion_and',
exists_eq_left, iUnion_exists, exists_and_left]
exact ⟨⟨p.color a, p.color_lt ha.1 hN⟩, a, rfl, ha⟩
/-!
### The measurable Besicovitch covering theorem
-/
open scoped NNReal
variable [SecondCountableTopology α] [MeasurableSpace α] [OpensMeasurableSpace α]
/-- Consider, for each `x` in a set `s`, a radius `r x ∈ (0, 1]`. Then one can find finitely
many disjoint balls of the form `closedBall x (r x)` covering a proportion `1/(N+1)` of `s`, if
there are no satellite configurations with `N+1` points.
-/
theorem exist_finset_disjoint_balls_large_measure (μ : Measure α) [IsFiniteMeasure μ] {N : ℕ}
{τ : ℝ} (hτ : 1 < τ) (hN : IsEmpty (SatelliteConfig α N τ)) (s : Set α) (r : α → ℝ)
(rpos : ∀ x ∈ s, 0 < r x) (rle : ∀ x ∈ s, r x ≤ 1) :
∃ t : Finset α, ↑t ⊆ s ∧ μ (s \ ⋃ x ∈ t, closedBall x (r x)) ≤ N / (N + 1) * μ s ∧
(t : Set α).PairwiseDisjoint fun x => closedBall x (r x) := by
classical
-- exclude the trivial case where `μ s = 0`.
rcases le_or_lt (μ s) 0 with (hμs | hμs)
· have : μ s = 0 := le_bot_iff.1 hμs
refine ⟨∅, by simp only [Finset.coe_empty, empty_subset], ?_, ?_⟩
· simp only [this, Finset.not_mem_empty, diff_empty, iUnion_false, iUnion_empty,
nonpos_iff_eq_zero, mul_zero]
· simp only [Finset.coe_empty, pairwiseDisjoint_empty]
cases isEmpty_or_nonempty α
· simp only [eq_empty_of_isEmpty s, measure_empty] at hμs
exact (lt_irrefl _ hμs).elim
have Npos : N ≠ 0 := by
rintro rfl
inhabit α
exact not_isEmpty_of_nonempty _ hN
-- introduce a measurable superset `o` with the same measure, for measure computations
obtain ⟨o, so, omeas, μo⟩ : ∃ o : Set α, s ⊆ o ∧ MeasurableSet o ∧ μ o = μ s :=
exists_measurable_superset μ s
/- We will apply the topological Besicovitch theorem, giving `N` disjoint subfamilies of balls
covering `s`. Among these, one of them covers a proportion at least `1/N` of `s`. A large
enough finite subfamily will then cover a proportion at least `1/(N+1)`. -/
let a : BallPackage s α :=
{ c := fun x => x
r := fun x => r x
rpos := fun x => rpos x x.2
r_bound := 1
r_le := fun x => rle x x.2 }
rcases exist_disjoint_covering_families hτ hN a with ⟨u, hu, hu'⟩
have u_count : ∀ i, (u i).Countable := by
intro i
refine (hu i).countable_of_nonempty_interior fun j _ => ?_
have : (ball (j : α) (r j)).Nonempty := nonempty_ball.2 (a.rpos _)
exact this.mono ball_subset_interior_closedBall
let v : Fin N → Set α := fun i => ⋃ (x : s) (_ : x ∈ u i), closedBall x (r x)
have A : s = ⋃ i : Fin N, s ∩ v i := by
refine Subset.antisymm ?_ (iUnion_subset fun i => inter_subset_left)
intro x hx
obtain ⟨i, y, hxy, h'⟩ :
∃ (i : Fin N) (i_1 : ↥s), i_1 ∈ u i ∧ x ∈ ball (↑i_1) (r ↑i_1) := by
have : x ∈ range a.c := by simpa only [a, Subtype.range_coe_subtype, setOf_mem_eq]
simpa only [mem_iUnion, bex_def] using hu' this
refine mem_iUnion.2 ⟨i, ⟨hx, ?_⟩⟩
simp only [v, exists_prop, mem_iUnion, SetCoe.exists, exists_and_right, Subtype.coe_mk]
exact ⟨y, ⟨y.2, by simpa only [Subtype.coe_eta]⟩, ball_subset_closedBall h'⟩
have S : ∑ _i : Fin N, μ s / N ≤ ∑ i, μ (s ∩ v i) :=
calc
∑ _i : Fin N, μ s / N = μ s := by
simp only [Finset.card_fin, Finset.sum_const, nsmul_eq_mul]
rw [ENNReal.mul_div_cancel]
· simp only [Npos, Ne, Nat.cast_eq_zero, not_false_iff]
· exact ENNReal.natCast_ne_top _
_ ≤ ∑ i, μ (s ∩ v i) := by
conv_lhs => rw [A]
apply measure_iUnion_fintype_le
-- choose an index `i` of a subfamily covering at least a proportion `1/N` of `s`.
obtain ⟨i, -, hi⟩ : ∃ (i : Fin N), i ∈ Finset.univ ∧ μ s / N ≤ μ (s ∩ v i) := by
apply ENNReal.exists_le_of_sum_le _ S
exact ⟨⟨0, bot_lt_iff_ne_bot.2 Npos⟩, Finset.mem_univ _⟩
replace hi : μ s / (N + 1) < μ (s ∩ v i) := by
apply lt_of_lt_of_le _ hi
apply (ENNReal.mul_lt_mul_left hμs.ne' (measure_lt_top μ s).ne).2
rw [ENNReal.inv_lt_inv]
conv_lhs => rw [← add_zero (N : ℝ≥0∞)]
exact ENNReal.add_lt_add_left (ENNReal.natCast_ne_top N) zero_lt_one
have B : μ (o ∩ v i) = ∑' x : u i, μ (o ∩ closedBall x (r x)) := by
have : o ∩ v i = ⋃ (x : s) (_ : x ∈ u i), o ∩ closedBall x (r x) := by
simp only [v, inter_iUnion]
rw [this, measure_biUnion (u_count i)]
· exact (hu i).mono fun k => inter_subset_right
· exact fun b _ => omeas.inter measurableSet_closedBall
-- A large enough finite subfamily of `u i` will also cover a proportion `> 1/(N+1)` of `s`.
-- Since `s` might not be measurable, we express this in terms of the measurable superset `o`.
obtain ⟨w, hw⟩ :
∃ w : Finset (u i), μ s / (N + 1) <
∑ x ∈ w, μ (o ∩ closedBall (x : α) (r (x : α))) := by
have C : HasSum (fun x : u i => μ (o ∩ closedBall x (r x))) (μ (o ∩ v i)) := by
rw [B]; exact ENNReal.summable.hasSum
have : μ s / (N + 1) < μ (o ∩ v i) := hi.trans_le (measure_mono (inter_subset_inter_left _ so))
exact ((tendsto_order.1 C).1 _ this).exists
-- Bring back the finset `w i` of `↑(u i)` to a finset of `α`, and check that it works by design.
refine ⟨Finset.image (fun x : u i => x) w, ?_, ?_, ?_⟩
-- show that the finset is included in `s`.
· simp only [image_subset_iff, Finset.coe_image]
intro y _
simp only [Subtype.coe_prop, mem_preimage]
-- show that it covers a large enough proportion of `s`. For measure computations, we do not
-- use `s` (which might not be measurable), but its measurable superset `o`. Since their measures
-- are the same, this does not spoil the estimates
· suffices H : μ (o \ ⋃ x ∈ w, closedBall (↑x) (r ↑x)) ≤ N / (N + 1) * μ s by
rw [Finset.set_biUnion_finset_image]
exact le_trans (measure_mono (diff_subset_diff so (Subset.refl _))) H
rw [← diff_inter_self_eq_diff,
measure_diff_le_iff_le_add _ inter_subset_right (measure_lt_top μ _).ne]
swap
· exact .inter
(w.nullMeasurableSet_biUnion fun _ _ ↦ measurableSet_closedBall.nullMeasurableSet)
omeas.nullMeasurableSet
calc
μ o = 1 / (N + 1) * μ s + N / (N + 1) * μ s := by
rw [μo, ← add_mul, ENNReal.div_add_div_same, add_comm, ENNReal.div_self, one_mul] <;> simp
_ ≤ μ ((⋃ x ∈ w, closedBall (↑x) (r ↑x)) ∩ o) + N / (N + 1) * μ s := by
gcongr
rw [one_div, mul_comm, ← div_eq_mul_inv]
apply hw.le.trans (le_of_eq _)
rw [← Finset.set_biUnion_coe, inter_comm _ o, inter_iUnion₂, Finset.set_biUnion_coe,
measure_biUnion_finset]
· have : (w : Set (u i)).PairwiseDisjoint
fun b : u i => closedBall (b : α) (r (b : α)) := by
intro k _ l _ hkl; exact hu i k.2 l.2 (Subtype.val_injective.ne hkl)
exact this.mono fun k => inter_subset_right
· intro b _
apply omeas.inter measurableSet_closedBall
-- show that the balls are disjoint
· intro k hk l hl hkl
obtain ⟨k', _, rfl⟩ : ∃ k' : u i, k' ∈ w ∧ ↑k' = k := by
simpa only [mem_image, Finset.mem_coe, Finset.coe_image] using hk
obtain ⟨l', _, rfl⟩ : ∃ l' : u i, l' ∈ w ∧ ↑l' = l := by
simpa only [mem_image, Finset.mem_coe, Finset.coe_image] using hl
have k'nel' : (k' : s) ≠ l' := by intro h; rw [h] at hkl; exact hkl rfl
exact hu i k'.2 l'.2 k'nel'
variable [HasBesicovitchCovering α]
/-- The **measurable Besicovitch covering theorem**. Assume that, for any `x` in a set `s`,
one is given a set of admissible closed balls centered at `x`, with arbitrarily small radii.
Then there exists a disjoint covering of almost all `s` by admissible closed balls centered at some
points of `s`.
This version requires that the underlying measure is finite, and that the space has the Besicovitch
covering property (which is satisfied for instance by normed real vector spaces). It expresses the
conclusion in a slightly awkward form (with a subset of `α × ℝ`) coming from the proof technique.
For a version assuming that the measure is sigma-finite,
see `exists_disjoint_closedBall_covering_ae_aux`.
For a version giving the conclusion in a nicer form, see `exists_disjoint_closedBall_covering_ae`.
-/
theorem exists_disjoint_closedBall_covering_ae_of_finiteMeasure_aux (μ : Measure α)
[IsFiniteMeasure μ] (f : α → Set ℝ) (s : Set α)
(hf : ∀ x ∈ s, ∀ δ > 0, (f x ∩ Ioo 0 δ).Nonempty) :
∃ t : Set (α × ℝ), t.Countable ∧ (∀ p ∈ t, p.1 ∈ s) ∧ (∀ p ∈ t, p.2 ∈ f p.1) ∧
μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ t), closedBall p.1 p.2) = 0 ∧
t.PairwiseDisjoint fun p => closedBall p.1 p.2 := by
classical
rcases HasBesicovitchCovering.no_satelliteConfig (α := α) with ⟨N, τ, hτ, hN⟩
/- Introduce a property `P` on finsets saying that we have a nice disjoint covering of a
subset of `s` by admissible balls. -/
let P : Finset (α × ℝ) → Prop := fun t =>
((t : Set (α × ℝ)).PairwiseDisjoint fun p => closedBall p.1 p.2) ∧
(∀ p : α × ℝ, p ∈ t → p.1 ∈ s) ∧ ∀ p : α × ℝ, p ∈ t → p.2 ∈ f p.1
/- Given a finite good covering of a subset `s`, one can find a larger finite good covering,
covering additionally a proportion at least `1/(N+1)` of leftover points. This follows from
`exist_finset_disjoint_balls_large_measure` applied to balls not intersecting the initial
covering. -/
have :
∀ t : Finset (α × ℝ), P t → ∃ u : Finset (α × ℝ), t ⊆ u ∧ P u ∧
μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ u), closedBall p.1 p.2) ≤
N / (N + 1) * μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ t), closedBall p.1 p.2) := by
intro t ht
set B := ⋃ (p : α × ℝ) (_ : p ∈ t), closedBall p.1 p.2 with hB
have B_closed : IsClosed B := isClosed_biUnion_finset fun i _ => isClosed_closedBall
set s' := s \ B
have : ∀ x ∈ s', ∃ r ∈ f x ∩ Ioo 0 1, Disjoint B (closedBall x r) := by
intro x hx
have xs : x ∈ s := ((mem_diff x).1 hx).1
rcases eq_empty_or_nonempty B with (hB | hB)
· rcases hf x xs 1 zero_lt_one with ⟨r, hr, h'r⟩
exact ⟨r, ⟨hr, h'r⟩, by simp only [hB, empty_disjoint]⟩
· let r := infDist x B
have : 0 < min r 1 :=
lt_min ((B_closed.not_mem_iff_infDist_pos hB).1 ((mem_diff x).1 hx).2) zero_lt_one
rcases hf x xs _ this with ⟨r, hr, h'r⟩
refine ⟨r, ⟨hr, ⟨h'r.1, h'r.2.trans_le (min_le_right _ _)⟩⟩, ?_⟩
rw [disjoint_comm]
exact disjoint_closedBall_of_lt_infDist (h'r.2.trans_le (min_le_left _ _))
choose! r hr using this
obtain ⟨v, vs', hμv, hv⟩ :
∃ v : Finset α,
↑v ⊆ s' ∧
μ (s' \ ⋃ x ∈ v, closedBall x (r x)) ≤ N / (N + 1) * μ s' ∧
(v : Set α).PairwiseDisjoint fun x : α => closedBall x (r x) :=
haveI rI : ∀ x ∈ s', r x ∈ Ioo (0 : ℝ) 1 := fun x hx => (hr x hx).1.2
exist_finset_disjoint_balls_large_measure μ hτ hN s' r (fun x hx => (rI x hx).1) fun x hx =>
(rI x hx).2.le
refine ⟨t ∪ Finset.image (fun x => (x, r x)) v, Finset.subset_union_left, ⟨?_, ?_, ?_⟩, ?_⟩
· simp only [Finset.coe_union, pairwiseDisjoint_union, ht.1, true_and, Finset.coe_image]
constructor
· intro p hp q hq hpq
rcases (mem_image _ _ _).1 hp with ⟨p', p'v, rfl⟩
rcases (mem_image _ _ _).1 hq with ⟨q', q'v, rfl⟩
refine hv p'v q'v fun hp'q' => ?_
rw [hp'q'] at hpq
exact hpq rfl
· intro p hp q hq hpq
rcases (mem_image _ _ _).1 hq with ⟨q', q'v, rfl⟩
apply disjoint_of_subset_left _ (hr q' (vs' q'v)).2
rw [hB, ← Finset.set_biUnion_coe]
exact subset_biUnion_of_mem (u := fun x : α × ℝ => closedBall x.1 x.2) hp
· intro p hp
rcases Finset.mem_union.1 hp with (h'p | h'p)
· exact ht.2.1 p h'p
· rcases Finset.mem_image.1 h'p with ⟨p', p'v, rfl⟩
exact ((mem_diff _).1 (vs' (Finset.mem_coe.2 p'v))).1
· intro p hp
rcases Finset.mem_union.1 hp with (h'p | h'p)
· exact ht.2.2 p h'p
· rcases Finset.mem_image.1 h'p with ⟨p', p'v, rfl⟩
exact (hr p' (vs' p'v)).1.1
· convert hμv using 2
rw [Finset.set_biUnion_union, ← diff_diff, Finset.set_biUnion_finset_image]
/- Define `F` associating to a finite good covering the above enlarged good covering, covering
a proportion `1/(N+1)` of leftover points. Iterating `F`, one will get larger and larger good
coverings, missing in the end only a measure-zero set. -/
choose! F hF using this
let u n := F^[n] ∅
have u_succ : ∀ n : ℕ, u n.succ = F (u n) := fun n => by
simp only [u, Function.comp_apply, Function.iterate_succ']
have Pu : ∀ n, P (u n) := by
intro n
induction' n with n IH
· simp only [P, u, Prod.forall, id, Function.iterate_zero]
simp only [Finset.not_mem_empty, IsEmpty.forall_iff, Finset.coe_empty, forall₂_true_iff,
and_self_iff, pairwiseDisjoint_empty]
· rw [u_succ]
exact (hF (u n) IH).2.1
refine ⟨⋃ n, u n, countable_iUnion fun n => (u n).countable_toSet, ?_, ?_, ?_, ?_⟩
· intro p hp
rcases mem_iUnion.1 hp with ⟨n, hn⟩
exact (Pu n).2.1 p (Finset.mem_coe.1 hn)
· intro p hp
rcases mem_iUnion.1 hp with ⟨n, hn⟩
exact (Pu n).2.2 p (Finset.mem_coe.1 hn)
· have A :
∀ n,
μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ ⋃ n : ℕ, (u n : Set (α × ℝ))), closedBall p.fst p.snd) ≤
μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ u n), closedBall p.fst p.snd) := by
intro n
gcongr μ (s \ ?_)
exact biUnion_subset_biUnion_left (subset_iUnion (fun i => (u i : Set (α × ℝ))) n)
have B :
∀ n, μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ u n), closedBall p.fst p.snd) ≤
(N / (N + 1) : ℝ≥0∞) ^ n * μ s := by
intro n
induction' n with n IH
· simp only [u, le_refl, diff_empty, one_mul, iUnion_false, iUnion_empty, pow_zero,
Function.iterate_zero, id, Finset.not_mem_empty]
calc
μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ u n.succ), closedBall p.fst p.snd) ≤
N / (N + 1) * μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ u n), closedBall p.fst p.snd) := by
rw [u_succ]; exact (hF (u n) (Pu n)).2.2
_ ≤ (N / (N + 1) : ℝ≥0∞) ^ n.succ * μ s := by
rw [pow_succ', mul_assoc]; exact mul_le_mul_left' IH _
have C : Tendsto (fun n : ℕ => ((N : ℝ≥0∞) / (N + 1)) ^ n * μ s) atTop (𝓝 (0 * μ s)) := by
apply ENNReal.Tendsto.mul_const _ (Or.inr (measure_lt_top μ s).ne)
apply ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one
rw [ENNReal.div_lt_iff, one_mul]
· conv_lhs => rw [← add_zero (N : ℝ≥0∞)]
exact ENNReal.add_lt_add_left (ENNReal.natCast_ne_top N) zero_lt_one
· simp only [true_or, add_eq_zero, Ne, not_false_iff, one_ne_zero, and_false]
· simp only [ENNReal.natCast_ne_top, Ne, not_false_iff, or_true]
rw [zero_mul] at C
apply le_bot_iff.1
exact le_of_tendsto_of_tendsto' tendsto_const_nhds C fun n => (A n).trans (B n)
· refine (pairwiseDisjoint_iUnion ?_).2 fun n => (Pu n).1
apply (monotone_nat_of_le_succ fun n => ?_).directed_le
rw [← Nat.succ_eq_add_one, u_succ]
exact (hF (u n) (Pu n)).1
/-- The measurable **Besicovitch covering theorem**.
Assume that, for any `x` in a set `s`, one is given a set of admissible closed balls centered at
`x`, with arbitrarily small radii. Then there exists a disjoint covering of almost all `s` by
admissible closed balls centered at some points of `s`.
This version requires the underlying measure to be sigma-finite, and the space to have the
Besicovitch covering property (which is satisfied for instance by normed real vector spaces).
It expresses the conclusion in a slightly awkward form (with a subset of `α × ℝ`) coming from the
proof technique.
For a version giving the conclusion in a nicer form, see `exists_disjoint_closedBall_covering_ae`.
-/
theorem exists_disjoint_closedBall_covering_ae_aux (μ : Measure α) [SFinite μ] (f : α → Set ℝ)
(s : Set α) (hf : ∀ x ∈ s, ∀ δ > 0, (f x ∩ Ioo 0 δ).Nonempty) :
∃ t : Set (α × ℝ), t.Countable ∧ (∀ p ∈ t, p.1 ∈ s) ∧ (∀ p ∈ t, p.2 ∈ f p.1) ∧
μ (s \ ⋃ (p : α × ℝ) (_ : p ∈ t), closedBall p.1 p.2) = 0 ∧
t.PairwiseDisjoint fun p => closedBall p.1 p.2 := by
/- This is deduced from the finite measure case, by using a finite measure with respect to which
the initial sigma-finite measure is absolutely continuous. -/
rcases exists_isFiniteMeasure_absolutelyContinuous μ with ⟨ν, hν, hμν, -⟩
rcases exists_disjoint_closedBall_covering_ae_of_finiteMeasure_aux ν f s hf with
⟨t, t_count, ts, tr, tν, tdisj⟩
exact ⟨t, t_count, ts, tr, hμν tν, tdisj⟩
/-- The measurable **Besicovitch covering theorem**.
Assume that, for any `x` in a set `s`, one is given a set of admissible closed balls centered at
`x`, with arbitrarily small radii. Then there exists a disjoint covering of almost all `s` by
admissible closed balls centered at some points of `s`. We can even require that the radius at `x`
is bounded by a given function `R x`. (Take `R = 1` if you don't need this additional feature).
This version requires the underlying measure to be sigma-finite, and the space to have the
Besicovitch covering property (which is satisfied for instance by normed real vector spaces).
-/
theorem exists_disjoint_closedBall_covering_ae (μ : Measure α) [SFinite μ] (f : α → Set ℝ)
(s : Set α) (hf : ∀ x ∈ s, ∀ δ > 0, (f x ∩ Ioo 0 δ).Nonempty) (R : α → ℝ)
(hR : ∀ x ∈ s, 0 < R x) :
∃ (t : Set α) (r : α → ℝ), t.Countable ∧ t ⊆ s ∧
(∀ x ∈ t, r x ∈ f x ∩ Ioo 0 (R x)) ∧ μ (s \ ⋃ x ∈ t, closedBall x (r x)) = 0 ∧
t.PairwiseDisjoint fun x => closedBall x (r x) := by
let g x := f x ∩ Ioo 0 (R x)
have hg : ∀ x ∈ s, ∀ δ > 0, (g x ∩ Ioo 0 δ).Nonempty := fun x hx δ δpos ↦ by
rcases hf x hx (min δ (R x)) (lt_min δpos (hR x hx)) with ⟨r, hr⟩
exact ⟨r, ⟨⟨hr.1, hr.2.1, hr.2.2.trans_le (min_le_right _ _)⟩,
⟨hr.2.1, hr.2.2.trans_le (min_le_left _ _)⟩⟩⟩
rcases exists_disjoint_closedBall_covering_ae_aux μ g s hg with ⟨v, v_count, vs, vg, μv, v_disj⟩
obtain ⟨r, t, rfl⟩ : ∃ (r : α → ℝ) (t : Set α), v = graphOn r t := by
have I : ∀ p ∈ v, 0 ≤ p.2 := fun p hp => (vg p hp).2.1.le
rw [exists_eq_graphOn]
refine fun x hx y hy heq ↦ v_disj.eq hx hy <| not_disjoint_iff.2 ⟨x.1, ?_⟩
simp [*]
have hinj : InjOn (fun x ↦ (x, r x)) t := LeftInvOn.injOn (f₁' := Prod.fst) fun _ _ ↦ rfl
simp only [graphOn, forall_mem_image, biUnion_image, hinj.pairwiseDisjoint_image] at *
exact ⟨t, r, countable_of_injective_of_countable_image hinj v_count, vs, vg, μv, v_disj⟩
/-- In a space with the Besicovitch property, any set `s` can be covered with balls whose measures
add up to at most `μ s + ε`, for any positive `ε`. This works even if one restricts the set of
allowed radii around a point `x` to a set `f x` which accumulates at `0`. -/
theorem exists_closedBall_covering_tsum_measure_le (μ : Measure α) [SFinite μ]
[Measure.OuterRegular μ] {ε : ℝ≥0∞} (hε : ε ≠ 0) (f : α → Set ℝ) (s : Set α)
(hf : ∀ x ∈ s, ∀ δ > 0, (f x ∩ Ioo 0 δ).Nonempty) :
∃ (t : Set α) (r : α → ℝ), t.Countable ∧ t ⊆ s ∧ (∀ x ∈ t, r x ∈ f x) ∧
(s ⊆ ⋃ x ∈ t, closedBall x (r x)) ∧ (∑' x : t, μ (closedBall x (r x))) ≤ μ s + ε := by
/- For the proof, first cover almost all `s` with disjoint balls thanks to the usual Besicovitch
theorem. Taking the balls included in a well-chosen open neighborhood `u` of `s`, one may
ensure that their measures add at most to `μ s + ε / 2`. Let `s'` be the remaining set, of
measure `0`. Applying the other version of Besicovitch, one may cover it with at most `N`
disjoint subfamilies. Making sure that they are all included in a neighborhood `v` of `s'` of
measure at most `ε / (2 N)`, the sum of their measures is at most `ε / 2`,
completing the proof. -/
classical
obtain ⟨u, su, u_open, μu⟩ : ∃ U, U ⊇ s ∧ IsOpen U ∧ μ U ≤ μ s + ε / 2 :=
Set.exists_isOpen_le_add _ _
(by
simpa only [or_false, Ne, ENNReal.div_eq_zero_iff, ENNReal.ofNat_ne_top] using hε)
have : ∀ x ∈ s, ∃ R > 0, ball x R ⊆ u := fun x hx =>
Metric.mem_nhds_iff.1 (u_open.mem_nhds (su hx))
choose! R hR using this
obtain ⟨t0, r0, t0_count, t0s, hr0, μt0, t0_disj⟩ :
∃ (t0 : Set α) (r0 : α → ℝ), t0.Countable ∧ t0 ⊆ s ∧
(∀ x ∈ t0, r0 x ∈ f x ∩ Ioo 0 (R x)) ∧ μ (s \ ⋃ x ∈ t0, closedBall x (r0 x)) = 0 ∧
t0.PairwiseDisjoint fun x => closedBall x (r0 x) :=
exists_disjoint_closedBall_covering_ae μ f s hf R fun x hx => (hR x hx).1
-- we have constructed an almost everywhere covering of `s` by disjoint balls. Let `s'` be the
-- remaining set.
let s' := s \ ⋃ x ∈ t0, closedBall x (r0 x)
have s's : s' ⊆ s := diff_subset
obtain ⟨N, τ, hτ, H⟩ : ∃ N τ, 1 < τ ∧ IsEmpty (Besicovitch.SatelliteConfig α N τ) :=
HasBesicovitchCovering.no_satelliteConfig
obtain ⟨v, s'v, v_open, μv⟩ : ∃ v, v ⊇ s' ∧ IsOpen v ∧ μ v ≤ μ s' + ε / 2 / N :=
Set.exists_isOpen_le_add _ _
(by simp only [ne_eq, ENNReal.div_eq_zero_iff, hε, ENNReal.ofNat_ne_top, or_self,
ENNReal.natCast_ne_top, not_false_eq_true])
have : ∀ x ∈ s', ∃ r1 ∈ f x ∩ Ioo (0 : ℝ) 1, closedBall x r1 ⊆ v := by
intro x hx
rcases Metric.mem_nhds_iff.1 (v_open.mem_nhds (s'v hx)) with ⟨r, rpos, hr⟩
rcases hf x (s's hx) (min r 1) (lt_min rpos zero_lt_one) with ⟨R', hR'⟩
exact
⟨R', ⟨hR'.1, hR'.2.1, hR'.2.2.trans_le (min_le_right _ _)⟩,
Subset.trans (closedBall_subset_ball (hR'.2.2.trans_le (min_le_left _ _))) hr⟩
choose! r1 hr1 using this
let q : BallPackage s' α :=
{ c := fun x => x
r := fun x => r1 x
rpos := fun x => (hr1 x.1 x.2).1.2.1
r_bound := 1
r_le := fun x => (hr1 x.1 x.2).1.2.2.le }
-- by Besicovitch, we cover `s'` with at most `N` families of disjoint balls, all included in
-- a suitable neighborhood `v` of `s'`.
obtain ⟨S, S_disj, hS⟩ :
∃ S : Fin N → Set s',
(∀ i : Fin N, (S i).PairwiseDisjoint fun j => closedBall (q.c j) (q.r j)) ∧
range q.c ⊆ ⋃ i : Fin N, ⋃ j ∈ S i, ball (q.c j) (q.r j) :=
exist_disjoint_covering_families hτ H q
have S_count : ∀ i, (S i).Countable := by
intro i
apply (S_disj i).countable_of_nonempty_interior fun j _ => ?_
have : (ball (j : α) (r1 j)).Nonempty := nonempty_ball.2 (q.rpos _)
exact this.mono ball_subset_interior_closedBall
let r x := if x ∈ s' then r1 x else r0 x
have r_t0 : ∀ x ∈ t0, r x = r0 x := by
intro x hx
have : ¬x ∈ s' := by
simp only [s', not_exists, exists_prop, mem_iUnion, mem_closedBall, not_and, not_lt, not_le,
mem_diff, not_forall]
intro _
refine ⟨x, hx, ?_⟩
rw [dist_self]
exact (hr0 x hx).2.1.le
simp only [r, if_neg this]
-- the desired covering set is given by the union of the families constructed in the first and
-- second steps.
refine ⟨t0 ∪ ⋃ i : Fin N, ((↑) : s' → α) '' S i, r, ?_, ?_, ?_, ?_, ?_⟩
-- it remains to check that they have the desired properties
· exact t0_count.union (countable_iUnion fun i => (S_count i).image _)
· simp only [t0s, true_and, union_subset_iff, image_subset_iff, iUnion_subset_iff]
intro i x _
exact s's x.2
· intro x hx
cases hx with
| inl hx =>
rw [r_t0 x hx]
exact (hr0 _ hx).1
| inr hx =>
have h'x : x ∈ s' := by
simp only [mem_iUnion, mem_image] at hx
rcases hx with ⟨i, y, _, rfl⟩
exact y.2
simp only [r, if_pos h'x, (hr1 x h'x).1.1]
· intro x hx
by_cases h'x : x ∈ s'
· obtain ⟨i, y, ySi, xy⟩ : ∃ (i : Fin N) (y : ↥s'), y ∈ S i ∧ x ∈ ball (y : α) (r1 y) := by
have A : x ∈ range q.c := by
simpa only [q, not_exists, exists_prop, mem_iUnion, mem_closedBall, not_and,
not_le, mem_setOf_eq, Subtype.range_coe_subtype, mem_diff] using h'x
simpa only [mem_iUnion, mem_image, bex_def] using hS A
refine mem_iUnion₂.2 ⟨y, Or.inr ?_, ?_⟩
· simp only [mem_iUnion, mem_image]
exact ⟨i, y, ySi, rfl⟩
· have : (y : α) ∈ s' := y.2
simp only [r, if_pos this]
exact ball_subset_closedBall xy
· obtain ⟨y, yt0, hxy⟩ : ∃ y : α, y ∈ t0 ∧ x ∈ closedBall y (r0 y) := by
simpa [s', hx, -mem_closedBall] using h'x
refine mem_iUnion₂.2 ⟨y, Or.inl yt0, ?_⟩
rwa [r_t0 _ yt0]
-- the only nontrivial property is the measure control, which we check now
· -- the sets in the first step have measure at most `μ s + ε / 2`
have A : (∑' x : t0, μ (closedBall x (r x))) ≤ μ s + ε / 2 :=
calc
(∑' x : t0, μ (closedBall x (r x))) = ∑' x : t0, μ (closedBall x (r0 x)) := by
congr 1; ext x; rw [r_t0 x x.2]
_ = μ (⋃ x : t0, closedBall x (r0 x)) := by
haveI : Encodable t0 := t0_count.toEncodable
rw [measure_iUnion]
· exact (pairwise_subtype_iff_pairwise_set _ _).2 t0_disj
· exact fun i => measurableSet_closedBall
_ ≤ μ u := by
apply measure_mono
simp only [SetCoe.forall, Subtype.coe_mk, iUnion_subset_iff]
intro x hx
apply Subset.trans (closedBall_subset_ball (hr0 x hx).2.2) (hR x (t0s hx)).2
_ ≤ μ s + ε / 2 := μu
-- each subfamily in the second step has measure at most `ε / (2 N)`.
have B : ∀ i : Fin N, (∑' x : ((↑) : s' → α) '' S i, μ (closedBall x (r x))) ≤ ε / 2 / N :=
fun i =>
calc
(∑' x : ((↑) : s' → α) '' S i, μ (closedBall x (r x))) =
∑' x : S i, μ (closedBall x (r x)) := by
have : InjOn ((↑) : s' → α) (S i) := Subtype.val_injective.injOn
let F : S i ≃ ((↑) : s' → α) '' S i := this.bijOn_image.equiv _
exact (F.tsum_eq fun x => μ (closedBall x (r x))).symm
_ = ∑' x : S i, μ (closedBall x (r1 x)) := by
congr 1; ext x; have : (x : α) ∈ s' := x.1.2; simp only [s', r, if_pos this]
_ = μ (⋃ x : S i, closedBall x (r1 x)) := by
haveI : Encodable (S i) := (S_count i).toEncodable
rw [measure_iUnion]
· exact (pairwise_subtype_iff_pairwise_set _ _).2 (S_disj i)
· exact fun i => measurableSet_closedBall
_ ≤ μ v := by
apply measure_mono
simp only [SetCoe.forall, Subtype.coe_mk, iUnion_subset_iff]
intro x xs' _
exact (hr1 x xs').2
_ ≤ ε / 2 / N := by have : μ s' = 0 := μt0; rwa [this, zero_add] at μv
-- add up all these to prove the desired estimate
calc
(∑' x : ↥(t0 ∪ ⋃ i : Fin N, ((↑) : s' → α) '' S i), μ (closedBall x (r x))) ≤
(∑' x : t0, μ (closedBall x (r x))) +
∑' x : ⋃ i : Fin N, ((↑) : s' → α) '' S i, μ (closedBall x (r x)) :=
ENNReal.tsum_union_le (fun x => μ (closedBall x (r x))) _ _
_ ≤
(∑' x : t0, μ (closedBall x (r x))) +
∑ i : Fin N, ∑' x : ((↑) : s' → α) '' S i, μ (closedBall x (r x)) :=
(add_le_add le_rfl (ENNReal.tsum_iUnion_le (fun x => μ (closedBall x (r x))) _))
_ ≤ μ s + ε / 2 + ∑ i : Fin N, ε / 2 / N := by
gcongr
apply B
_ ≤ μ s + ε / 2 + ε / 2 := by
gcongr
simp only [Finset.card_fin, Finset.sum_const, nsmul_eq_mul, ENNReal.mul_div_le]
_ = μ s + ε := by rw [add_assoc, ENNReal.add_halves]
/-! ### Consequences on differentiation of measures -/
/-- In a space with the Besicovitch covering property, the set of closed balls with positive radius
forms a Vitali family. This is essentially a restatement of the measurable Besicovitch theorem. -/
protected def vitaliFamily (μ : Measure α) [SFinite μ] : VitaliFamily μ where
setsAt x := (fun r : ℝ => closedBall x r) '' Ioi (0 : ℝ)
measurableSet _ := forall_mem_image.2 fun _ _ ↦ isClosed_closedBall.measurableSet
nonempty_interior _ := forall_mem_image.2 fun _ rpos ↦
(nonempty_ball.2 rpos).mono ball_subset_interior_closedBall
nontrivial x ε εpos := ⟨closedBall x ε, mem_image_of_mem _ εpos, Subset.rfl⟩
covering := by
intro s f fsubset ffine
let g : α → Set ℝ := fun x => {r | 0 < r ∧ closedBall x r ∈ f x}
have A : ∀ x ∈ s, ∀ δ > 0, (g x ∩ Ioo 0 δ).Nonempty := by
intro x xs δ δpos
obtain ⟨t, tf, ht⟩ : ∃ (t : Set α), t ∈ f x ∧ t ⊆ closedBall x (δ / 2) :=
ffine x xs (δ / 2) (half_pos δpos)
obtain ⟨r, rpos, rfl⟩ : ∃ r : ℝ, 0 < r ∧ closedBall x r = t := by simpa using fsubset x xs tf
rcases le_total r (δ / 2) with (H | H)
· exact ⟨r, ⟨rpos, tf⟩, ⟨rpos, H.trans_lt (half_lt_self δpos)⟩⟩
· have : closedBall x r = closedBall x (δ / 2) :=
Subset.antisymm ht (closedBall_subset_closedBall H)
rw [this] at tf
exact ⟨δ / 2, ⟨half_pos δpos, tf⟩, ⟨half_pos δpos, half_lt_self δpos⟩⟩
obtain ⟨t, r, _, ts, tg, μt, tdisj⟩ :
∃ (t : Set α) (r : α → ℝ),
t.Countable ∧
t ⊆ s ∧
(∀ x ∈ t, r x ∈ g x ∩ Ioo 0 1) ∧
μ (s \ ⋃ x ∈ t, closedBall x (r x)) = 0 ∧
t.PairwiseDisjoint fun x => closedBall x (r x) :=
exists_disjoint_closedBall_covering_ae μ g s A (fun _ => 1) fun _ _ => zero_lt_one
let F : α → α × Set α := fun x => (x, closedBall x (r x))
refine ⟨F '' t, ?_, ?_, ?_, ?_⟩
· rintro - ⟨x, hx, rfl⟩; exact ts hx
· rintro p ⟨x, hx, rfl⟩ q ⟨y, hy, rfl⟩ hxy
exact tdisj hx hy (ne_of_apply_ne F hxy)
· rintro - ⟨x, hx, rfl⟩; exact (tg x hx).1.2
· rwa [biUnion_image]
/-- The main feature of the Besicovitch Vitali family is that its filter at a point `x` corresponds
to convergence along closed balls. We record one of the two implications here, which will enable us
to deduce specific statements on differentiation of measures in this context from the general
versions. -/
theorem tendsto_filterAt (μ : Measure α) [SFinite μ] (x : α) :
Tendsto (fun r => closedBall x r) (𝓝[>] 0) ((Besicovitch.vitaliFamily μ).filterAt x) := by
intro s hs
simp only [mem_map]
obtain ⟨ε, εpos, hε⟩ :
∃ (ε : ℝ), ε > 0 ∧
∀ a : Set α, a ∈ (Besicovitch.vitaliFamily μ).setsAt x → a ⊆ closedBall x ε → a ∈ s :=
(VitaliFamily.mem_filterAt_iff _).1 hs
filter_upwards [Ioc_mem_nhdsGT εpos] with _r hr
apply hε
· exact mem_image_of_mem _ hr.1
· exact closedBall_subset_closedBall hr.2
variable [MetricSpace β] [MeasurableSpace β] [BorelSpace β] [SecondCountableTopology β]
[HasBesicovitchCovering β]
/-- In a space with the Besicovitch covering property, the ratio of the measure of balls converges
almost surely to the Radon-Nikodym derivative. -/
theorem ae_tendsto_rnDeriv (ρ μ : Measure β) [IsLocallyFiniteMeasure μ] [IsLocallyFiniteMeasure ρ] :
∀ᵐ x ∂μ,
Tendsto (fun r => ρ (closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 (ρ.rnDeriv μ x)) := by
filter_upwards [VitaliFamily.ae_tendsto_rnDeriv (Besicovitch.vitaliFamily μ) ρ] with x hx
exact hx.comp (tendsto_filterAt μ x)
/-- Given a measurable set `s`, then `μ (s ∩ closedBall x r) / μ (closedBall x r)` converges when
`r` tends to `0`, for almost every `x`. The limit is `1` for `x ∈ s` and `0` for `x ∉ s`.
This shows that almost every point of `s` is a Lebesgue density point for `s`.
A version for non-measurable sets holds, but it only gives the first conclusion,
see `ae_tendsto_measure_inter_div`. -/
theorem ae_tendsto_measure_inter_div_of_measurableSet (μ : Measure β) [IsLocallyFiniteMeasure μ]
{s : Set β} (hs : MeasurableSet s) :
∀ᵐ x ∂μ,
Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0)
(𝓝 (s.indicator 1 x)) := by
filter_upwards [VitaliFamily.ae_tendsto_measure_inter_div_of_measurableSet
(Besicovitch.vitaliFamily μ) hs]
intro x hx
exact hx.comp (tendsto_filterAt μ x)
/-- Given an arbitrary set `s`, then `μ (s ∩ closedBall x r) / μ (closedBall x r)` converges
to `1` when `r` tends to `0`, for almost every `x` in `s`.
This shows that almost every point of `s` is a Lebesgue density point for `s`.
A stronger version holds for measurable sets, see `ae_tendsto_measure_inter_div_of_measurableSet`.
See also `IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div`. -/
theorem ae_tendsto_measure_inter_div (μ : Measure β) [IsLocallyFiniteMeasure μ] (s : Set β) :
∀ᵐ x ∂μ.restrict s,
Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1) := by
filter_upwards [VitaliFamily.ae_tendsto_measure_inter_div (Besicovitch.vitaliFamily μ) s] with x
hx using hx.comp (tendsto_filterAt μ x)
end Besicovitch
| Mathlib/MeasureTheory/Covering/Besicovitch.lean | 1,119 | 1,123 | |
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.CategoryTheory.Functor.Flat
import Mathlib.CategoryTheory.Sites.Continuous
import Mathlib.Tactic.ApplyFun
/-!
# Cover-preserving functors between sites.
In order to show that a functor is continuous, we define cover-preserving functors
between sites as functors that push covering sieves to covering sieves.
Then, a cover-preserving and compatible-preserving functor is continuous.
## Main definitions
* `CategoryTheory.CoverPreserving`: a functor between sites is cover-preserving if it
pushes covering sieves to covering sieves
* `CategoryTheory.CompatiblePreserving`: a functor between sites is compatible-preserving
if it pushes compatible families of elements to compatible families.
## Main results
- `CategoryTheory.isContinuous_of_coverPreserving`: If `G : C ⥤ D` is
cover-preserving and compatible-preserving, then `G` is a continuous functor,
i.e. `G.op ⋙ -` as a functor `(Dᵒᵖ ⥤ A) ⥤ (Cᵒᵖ ⥤ A)` of presheaves maps sheaves to sheaves.
## References
* [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.3.
* https://stacks.math.columbia.edu/tag/00WU
-/
universe w v₁ v₂ v₃ u₁ u₂ u₃
noncomputable section
open CategoryTheory Opposite CategoryTheory.Presieve.FamilyOfElements CategoryTheory.Presieve
CategoryTheory.Limits
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D)
variable {A : Type u₃} [Category.{v₃} A]
variable (J : GrothendieckTopology C) (K : GrothendieckTopology D)
variable {L : GrothendieckTopology A}
/-- A functor `G : (C, J) ⥤ (D, K)` between sites is *cover-preserving*
if for all covering sieves `R` in `C`, `R.functorPushforward G` is a covering sieve in `D`.
-/
structure CoverPreserving (G : C ⥤ D) : Prop where
cover_preserve : ∀ {U : C} {S : Sieve U} (_ : S ∈ J U), S.functorPushforward G ∈ K (G.obj U)
/-- The identity functor on a site is cover-preserving. -/
theorem idCoverPreserving : CoverPreserving J J (𝟭 _) :=
⟨fun hS => by simpa using hS⟩
/-- The composition of two cover-preserving functors is cover-preserving. -/
theorem CoverPreserving.comp {F} (hF : CoverPreserving J K F) {G} (hG : CoverPreserving K L G) :
CoverPreserving J L (F ⋙ G) :=
⟨fun hS => by
rw [Sieve.functorPushforward_comp]
exact hG.cover_preserve (hF.cover_preserve hS)⟩
/-- A functor `G : (C, J) ⥤ (D, K)` between sites is called compatible preserving if for each
compatible family of elements at `C` and valued in `G.op ⋙ ℱ`, and each commuting diagram
`f₁ ≫ G.map g₁ = f₂ ≫ G.map g₂`, `x g₁` and `x g₂` coincide when restricted via `fᵢ`.
This is actually stronger than merely preserving compatible families because of the definition of
| `functorPushforward` used.
-/
| Mathlib/CategoryTheory/Sites/CoverPreserving.lean | 72 | 73 |
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Topology.UniformSpace.UniformConvergenceTopology
/-!
# Equicontinuity of a family of functions
Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α`
is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a
neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to
`F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`.
For maps between metric spaces, this corresponds to
`∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`.
`F` is said to be *equicontinuous* if it is equicontinuous at each point.
A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions
`F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an
entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and
`F i y` are `U`-close. In other words, one has
`∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`.
For maps between metric spaces, this corresponds to
`∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`.
## Main definitions
* `EquicontinuousAt`: equicontinuity of a family of functions at a point
* `Equicontinuous`: equicontinuity of a family of functions on the whole domain
* `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain
We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and
`UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn`
respectively.
## Main statements
* `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity
condition between well-chosen function spaces. This is really useful for building up the theory.
* `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure
*for the topology of pointwise convergence* is also equicontinuous.
## Notations
Throughout this file, we use :
- `ι`, `κ` for indexing types
- `X`, `Y`, `Z` for topological spaces
- `α`, `β`, `γ` for uniform spaces
## Implementation details
We choose to express equicontinuity as a properties of indexed families of functions rather
than sets of functions for the following reasons:
- it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just
equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around
would require working with the range of the family, which is always annoying because it
introduces useless existentials.
- in most applications, one doesn't work with bare functions but with a more specific hom type
`hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity
of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families,
because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity
of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials.
To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous`
and `Set.UniformEquicontinuous` asserting the corresponding fact about the family
`(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom
types, and in that case one should go back to the family definition rather than using `Set.image`.
## References
* [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966]
## Tags
equicontinuity, uniform convergence, ascoli
-/
section
open UniformSpace Filter Set Uniformity Topology UniformConvergence Function
variable {ι κ X X' Y α α' β β' γ : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y]
[uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ]
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀`
such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/
def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family
`(↑) : ↥H → (X → α)` is equicontinuous at that point. -/
protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop :=
EquicontinuousAt ((↑) : H → X → α) x₀
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a
neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is
`U`-close to `F i x₀`. -/
def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset
if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/
protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop :=
EquicontinuousWithinAt ((↑) : H → X → α) S x₀
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/
def Equicontinuous (F : ι → X → α) : Prop :=
∀ x₀, EquicontinuousAt F x₀
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family
`(↑) : ↥H → (X → α)` is equicontinuous. -/
protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop :=
Equicontinuous ((↑) : H → X → α)
/-- A family `F : ι → X → α` of functions from a topological space to a uniform space is
*equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/
def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop :=
∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀
/-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family
`(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/
protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop :=
EquicontinuousOn ((↑) : H → X → α) S
/-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if,
for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are
`V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/
def UniformEquicontinuous (F : ι → β → α) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family
`(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/
protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop :=
UniformEquicontinuous ((↑) : H → β → α)
/-- A family `F : ι → β → α` of functions between uniform spaces is
*uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative
entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that,
*for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/
def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop :=
∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U
/-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the
family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/
protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop :=
UniformEquicontinuousOn ((↑) : H → β → α) S
lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀)
(S : Set X) : EquicontinuousWithinAt F S x₀ :=
fun U hU ↦ (H U hU).filter_mono inf_le_left
lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X}
(H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ :=
fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST
@[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) :
EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by
rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ]
lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) :
EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by
simp [EquicontinuousWithinAt, EquicontinuousAt,
← eventually_nhds_subtype_iff]
lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F)
(S : Set X) : EquicontinuousOn F S :=
fun x _ ↦ (H x).equicontinuousWithinAt S
lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X}
(H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S :=
fun x hx ↦ (H x (hST hx)).mono hST
lemma equicontinuousOn_univ (F : ι → X → α) :
EquicontinuousOn F univ ↔ Equicontinuous F := by
simp [EquicontinuousOn, Equicontinuous]
lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} :
Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by
simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff]
lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F)
(S : Set β) : UniformEquicontinuousOn F S :=
fun U hU ↦ (H U hU).filter_mono inf_le_left
lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β}
(H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S :=
fun U hU ↦ (H U hU).filter_mono <| by gcongr
lemma uniformEquicontinuousOn_univ (F : ι → β → α) :
UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by
simp [UniformEquicontinuousOn, UniformEquicontinuous]
lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} :
UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by
rw [UniformEquicontinuous, UniformEquicontinuousOn]
conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prodMap, ← map_comap]
rfl
/-!
### Empty index type
-/
@[simp]
lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) :
EquicontinuousAt F x₀ :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
@[simp]
lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) :
EquicontinuousWithinAt F S x₀ :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
@[simp]
lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) :
Equicontinuous F :=
equicontinuousAt_empty F
@[simp]
lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) :
EquicontinuousOn F S :=
fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀
@[simp]
lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) :
UniformEquicontinuous F :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
@[simp]
lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) :
UniformEquicontinuousOn F S :=
fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim)
/-!
### Finite index type
-/
theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by
simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff,
UniformSpace.ball, @forall_swap _ ι]
theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} :
EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by
simp [EquicontinuousWithinAt, ContinuousWithinAt,
(nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball,
@forall_swap _ ι]
theorem equicontinuous_finite [Finite ι] {F : ι → X → α} :
Equicontinuous F ↔ ∀ i, Continuous (F i) := by
simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι]
theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by
simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι]
theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} :
UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by
simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl
theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by
simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl
/-!
### Index type with a unique element
-/
theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} :
EquicontinuousAt F x ↔ ContinuousAt (F default) x :=
equicontinuousAt_finite.trans Unique.forall_iff
theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} :
EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x :=
equicontinuousWithinAt_finite.trans Unique.forall_iff
theorem equicontinuous_unique [Unique ι] {F : ι → X → α} :
Equicontinuous F ↔ Continuous (F default) :=
equicontinuous_finite.trans Unique.forall_iff
theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ ContinuousOn (F default) S :=
equicontinuousOn_finite.trans Unique.forall_iff
theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} :
UniformEquicontinuous F ↔ UniformContinuous (F default) :=
uniformEquicontinuous_finite.trans Unique.forall_iff
theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S :=
uniformEquicontinuousOn_finite.trans Unique.forall_iff
/-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀`
instead of comparing only one with `x₀`. -/
theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) :
EquicontinuousWithinAt F S x₀ ↔
∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by
constructor <;> intro H U hU
· rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩
refine ⟨_, H V hV, fun x hx y hy i => hVU (prodMk_mem_compRel ?_ (hy i))⟩
exact hVsymm.mk_mem_comm.mp (hx i)
· rcases H U hU with ⟨V, hV, hVU⟩
filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i
/-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing
only one with `x₀`. -/
theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔
∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by
simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀),
nhdsWithin_univ]
/-- Uniform equicontinuity implies equicontinuity. -/
theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) :
Equicontinuous F := fun x₀ U hU ↦
mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i
/-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/
theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β}
(h : UniformEquicontinuousOn F S) :
EquicontinuousOn F S := fun _ hx₀ U hU ↦
mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i
/-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/
theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) :
ContinuousAt (F i) x₀ :=
(UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i
/-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/
theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X}
(h : EquicontinuousWithinAt F S x₀) (i : ι) :
ContinuousWithinAt (F i) S x₀ :=
(UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i
protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X}
(h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ :=
h.continuousAt ⟨f, hf⟩
protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α}
{S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) :
ContinuousWithinAt f S x₀ :=
h.continuousWithinAt ⟨f, hf⟩
/-- Each function of an equicontinuous family is continuous. -/
theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) :
Continuous (F i) :=
continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i
/-- Each function of a family equicontinuous on `S` is continuous on `S`. -/
theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S)
(i : ι) : ContinuousOn (F i) S :=
fun x hx ↦ (h x hx).continuousWithinAt i
protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous)
{f : X → α} (hf : f ∈ H) : Continuous f :=
h.continuous ⟨f, hf⟩
protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X}
(h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S :=
h.continuousOn ⟨f, hf⟩
/-- Each function of a uniformly equicontinuous family is uniformly continuous. -/
theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F)
(i : ι) : UniformContinuous (F i) := fun U hU =>
mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i)
/-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/
theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β}
(h : UniformEquicontinuousOn F S) (i : ι) :
UniformContinuousOn (F i) S := fun U hU =>
mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i)
protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α}
(h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f :=
h.uniformContinuous ⟨f, hf⟩
protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α}
{S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) :
UniformContinuousOn f S :=
h.uniformContinuousOn ⟨f, hf⟩
/-- Taking sub-families preserves equicontinuity at a point. -/
theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) :
EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k)
/-- Taking sub-families preserves equicontinuity at a point within a subset. -/
theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X}
(h : EquicontinuousWithinAt F S x₀) (u : κ → ι) :
EquicontinuousWithinAt (F ∘ u) S x₀ :=
fun U hU ↦ (h U hU).mono fun _ H k => H (u k)
protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X}
(h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ :=
h.comp (inclusion hH)
protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X}
(h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ :=
h.comp (inclusion hH)
/-- Taking sub-families preserves equicontinuity. -/
theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) :
Equicontinuous (F ∘ u) := fun x => (h x).comp u
/-- Taking sub-families preserves equicontinuity on a subset. -/
theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) :
EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u
protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous)
(hH : H' ⊆ H) : H'.Equicontinuous :=
h.comp (inclusion hH)
protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X}
(h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S :=
h.comp (inclusion hH)
/-- Taking sub-families preserves uniform equicontinuity. -/
theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) :
UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k)
/-- Taking sub-families preserves uniform equicontinuity on a subset. -/
theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S)
(u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S :=
fun U hU ↦ (h U hU).mono fun _ H k => H (u k)
protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous)
(hH : H' ⊆ H) : H'.UniformEquicontinuous :=
h.comp (inclusion hH)
protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β}
(h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S :=
h.comp (inclusion hH)
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`,
i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/
theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by
simp only [EquicontinuousAt, forall_subtype_range_iff]
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous
at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/
theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} :
EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by
simp only [EquicontinuousWithinAt, forall_subtype_range_iff]
/-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous,
i.e the family `(↑) : range F → X → α` is equicontinuous. -/
theorem equicontinuous_iff_range {F : ι → X → α} :
Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) :=
forall_congr' fun _ => equicontinuousAt_iff_range
/-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`,
i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/
theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S :=
forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous,
i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/
theorem uniformEquicontinuous_iff_range {F : ι → β → α} :
UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) :=
⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h =>
h.comp (rangeFactorization F)⟩
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly
equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/
theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S :=
⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h =>
h.comp (rangeFactorization F)⟩
section
open UniformFun
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is
continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is
very useful for developing the equicontinuity API, but it should not be used directly for other
purposes. -/
theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} :
EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by
rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff]
rfl
/-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function
`swap 𝓕 : X → ι → α` is continuous at `x₀` within `S`
*when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for
developing the equicontinuity API, but it should not be used directly for other purposes. -/
theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} :
EquicontinuousWithinAt F S x₀ ↔
ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by
rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff]
rfl
/-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is
continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is
very useful for developing the equicontinuity API, but it should not be used directly for other
purposes. -/
theorem equicontinuous_iff_continuous {F : ι → X → α} :
Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by
simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt]
/-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is
continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is
very useful for developing the equicontinuity API, but it should not be used directly for other
purposes. -/
theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} :
EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by
simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt]
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is
uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*.
This is very useful for developing the equicontinuity API, but it should not be used directly
for other purposes. -/
theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} :
UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by
rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff]
rfl
/-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff the function
`swap 𝓕 : β → ι → α` is uniformly continuous on `S`
*when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful
for developing the equicontinuity API, but it should not be used directly for other purposes. -/
theorem uniformEquicontinuousOn_iff_uniformContinuousOn {F : ι → β → α} {S : Set β} :
UniformEquicontinuousOn F S ↔ UniformContinuousOn (ofFun ∘ Function.swap F : β → ι →ᵤ α) S := by
rw [UniformContinuousOn, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff]
rfl
theorem equicontinuousWithinAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'}
{S : Set X} {x₀ : X} : EquicontinuousWithinAt (uα := ⨅ k, u k) F S x₀ ↔
∀ k, EquicontinuousWithinAt (uα := u k) F S x₀ := by
simp only [equicontinuousWithinAt_iff_continuousWithinAt (uα := _), topologicalSpace]
unfold ContinuousWithinAt
rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, nhds_iInf, tendsto_iInf]
theorem equicontinuousAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'}
{x₀ : X} :
EquicontinuousAt (uα := ⨅ k, u k) F x₀ ↔ ∀ k, EquicontinuousAt (uα := u k) F x₀ := by
simp only [← equicontinuousWithinAt_univ (uα := _), equicontinuousWithinAt_iInf_rng]
theorem equicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} :
Equicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, Equicontinuous (uα := u k) F := by
simp_rw [equicontinuous_iff_continuous (uα := _), UniformFun.topologicalSpace]
rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, continuous_iInf_rng]
theorem equicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'}
{S : Set X} :
EquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, EquicontinuousOn (uα := u k) F S := by
simp_rw [EquicontinuousOn, equicontinuousWithinAt_iInf_rng, @forall_swap _ κ]
theorem uniformEquicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} :
UniformEquicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, UniformEquicontinuous (uα := u k) F := by
simp_rw [uniformEquicontinuous_iff_uniformContinuous (uα := _)]
rw [UniformFun.iInf_eq, uniformContinuous_iInf_rng]
theorem uniformEquicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'}
| {S : Set β} : UniformEquicontinuousOn (uα := ⨅ k, u k) F S ↔
∀ k, UniformEquicontinuousOn (uα := u k) F S := by
simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uα := _)]
unfold UniformContinuousOn
rw [UniformFun.iInf_eq, iInf_uniformity, tendsto_iInf]
| Mathlib/Topology/UniformSpace/Equicontinuity.lean | 561 | 566 |
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Dagur Asgeirsson
-/
import Mathlib.Topology.ExtremallyDisconnected
import Mathlib.Topology.Category.CompHaus.Projective
import Mathlib.Topology.Category.Profinite.Basic
/-!
# Extremally disconnected sets
This file develops some of the basic theory of extremally disconnected compact Hausdorff spaces.
## Overview
This file defines the type `Stonean` of all extremally (note: not "extremely"!)
disconnected compact Hausdorff spaces, gives it the structure of a large category,
and proves some basic observations about this category and various functors from it.
The Lean implementation: a term of type `Stonean` is a pair, considering of
a term of type `CompHaus` (i.e. a compact Hausdorff topological space) plus
a proof that the space is extremally disconnected.
This is equivalent to the assertion that the term is projective in `CompHaus`,
in the sense of category theory (i.e., such that morphisms out of the object
can be lifted along epimorphisms).
## Main definitions
* `Stonean` : the category of extremally disconnected compact Hausdorff spaces.
* `Stonean.toCompHaus` : the forgetful functor `Stonean ⥤ CompHaus` from Stonean
spaces to compact Hausdorff spaces
* `Stonean.toProfinite` : the functor from Stonean spaces to profinite spaces.
## Implementation
The category `Stonean` is defined using the structure `CompHausLike`. See the file
`CompHausLike.Basic` for more information.
-/
universe u
open CategoryTheory
open scoped Topology
/-- `Stonean` is the category of extremally disconnected compact Hausdorff spaces. -/
abbrev Stonean := CompHausLike (fun X ↦ ExtremallyDisconnected X)
namespace CompHaus
/-- `Projective` implies `ExtremallyDisconnected`. -/
instance (X : CompHaus.{u}) [Projective X] : ExtremallyDisconnected X := by
apply CompactT2.Projective.extremallyDisconnected
intro A B _ _ _ _ _ _ f g hf hg hsurj
let A' : CompHaus := CompHaus.of A
let B' : CompHaus := CompHaus.of B
let f' : X ⟶ B' := CompHausLike.ofHom _ ⟨f, hf⟩
let g' : A' ⟶ B' := CompHausLike.ofHom _ ⟨g,hg⟩
have : Epi g' := by
rw [CompHaus.epi_iff_surjective]
assumption
obtain ⟨h, hh⟩ := Projective.factors f' g'
refine ⟨h, h.hom.2, ?_⟩
ext t
apply_fun (fun e => e t) at hh
exact hh
/-- `Projective` implies `Stonean`. -/
@[simps!]
def toStonean (X : CompHaus.{u}) [Projective X] :
Stonean where
toTop := X.toTop
prop := inferInstance
end CompHaus
namespace Stonean
/-- The (forgetful) functor from Stonean spaces to compact Hausdorff spaces. -/
abbrev toCompHaus : Stonean.{u} ⥤ CompHaus.{u} :=
compHausLikeToCompHaus _
/-- The forgetful functor `Stonean ⥤ CompHaus` is fully faithful. -/
abbrev fullyFaithfulToCompHaus : toCompHaus.FullyFaithful :=
CompHausLike.fullyFaithfulToCompHausLike _
open CompHausLike
instance (X : Type*) [TopologicalSpace X]
[ExtremallyDisconnected X] : HasProp (fun Y ↦ ExtremallyDisconnected Y) X :=
⟨(inferInstance : ExtremallyDisconnected X)⟩
/-- Construct a term of `Stonean` from a type endowed with the structure of a
compact, Hausdorff and extremally disconnected topological space.
-/
abbrev of (X : Type*) [TopologicalSpace X] [CompactSpace X] [T2Space X]
[ExtremallyDisconnected X] : Stonean := CompHausLike.of _ X
instance (X : Stonean.{u}) : ExtremallyDisconnected X := X.prop
/-- The functor from Stonean spaces to profinite spaces. -/
abbrev toProfinite : Stonean.{u} ⥤ Profinite.{u} :=
CompHausLike.toCompHausLike (fun _ ↦ inferInstance)
/--
A finite discrete space as a Stonean space.
-/
def mkFinite (X : Type*) [Finite X] [TopologicalSpace X] [DiscreteTopology X] : Stonean where
toTop := (CompHaus.of X).toTop
prop := by
dsimp
constructor
intro U _
apply isOpen_discrete (closure U)
/--
A morphism in `Stonean` is an epi iff it is surjective.
-/
lemma epi_iff_surjective {X Y : Stonean} (f : X ⟶ Y) :
Epi f ↔ Function.Surjective f := by
refine ⟨?_, fun h => ConcreteCategory.epi_of_surjective f h⟩
dsimp [Function.Surjective]
intro h y
by_contra! hy
let C := Set.range f
have hC : IsClosed C := (isCompact_range f.hom.continuous).isClosed
let U := Cᶜ
have hUy : U ∈ 𝓝 y := by
simp only [U, C, Set.mem_range, hy, exists_false, not_false_eq_true, hC.compl_mem_nhds]
obtain ⟨V, hV, hyV, hVU⟩ := isTopologicalBasis_isClopen.mem_nhds_iff.mp hUy
classical
let g : Y ⟶ mkFinite (ULift (Fin 2)) := TopCat.ofHom
⟨(LocallyConstant.ofIsClopen hV).map ULift.up, LocallyConstant.continuous _⟩
let h : Y ⟶ mkFinite (ULift (Fin 2)) := TopCat.ofHom ⟨fun _ => ⟨1⟩, continuous_const⟩
have H : h = g := by
rw [← cancel_epi f]
ext x
apply ULift.ext -- why is `ext` not doing this automatically?
change 1 = ite _ _ _ -- why is `dsimp` not getting me here?
rw [if_neg]
refine mt (hVU ·) ?_ -- what would be an idiomatic tactic for this step?
simpa only [U, Set.mem_compl_iff, Set.mem_range, not_exists, not_forall, not_not]
using exists_apply_eq_apply f x
apply_fun fun e => (e y).down at H
change 1 = ite _ _ _ at H -- why is `dsimp at H` not getting me here?
rw [if_pos hyV] at H
exact one_ne_zero H
/-- Every Stonean space is projective in `CompHaus` -/
instance instProjectiveCompHausCompHaus (X : Stonean) : Projective (toCompHaus.obj X) where
factors := by
intro B C φ f _
haveI : ExtremallyDisconnected (toCompHaus.obj X).toTop := X.prop
have hf : Function.Surjective f := by rwa [← CompHaus.epi_iff_surjective]
obtain ⟨f', h⟩ := CompactT2.ExtremallyDisconnected.projective φ.hom.continuous f.hom.continuous
hf
use ofHom _ ⟨f', h.left⟩
ext
exact congr_fun h.right _
/-- Every Stonean space is projective in `Profinite` -/
instance (X : Stonean) : Projective (toProfinite.obj X) where
factors := by
intro B C φ f _
haveI : ExtremallyDisconnected (toProfinite.obj X) := X.prop
have hf : Function.Surjective f := by rwa [← Profinite.epi_iff_surjective]
obtain ⟨f', h⟩ := CompactT2.ExtremallyDisconnected.projective φ.hom.continuous f.hom.continuous
hf
use ofHom _ ⟨f', h.left⟩
ext
exact congr_fun h.right _
/-- Every Stonean space is projective in `Stonean`. -/
instance (X : Stonean) : Projective X where
factors := by
intro B C φ f _
haveI : ExtremallyDisconnected X.toTop := X.prop
have hf : Function.Surjective f := by rwa [← Stonean.epi_iff_surjective]
obtain ⟨f', h⟩ := CompactT2.ExtremallyDisconnected.projective φ.hom.continuous f.hom.continuous
hf
use ofHom _ ⟨f', h.left⟩
ext
exact congr_fun h.right _
end Stonean
namespace CompHaus
/-- If `X` is compact Hausdorff, `presentation X` is a Stonean space equipped with an epimorphism
down to `X` (see `CompHaus.presentation.π` and `CompHaus.presentation.epi_π`). It is a
"constructive" witness to the fact that `CompHaus` has enough projectives. -/
noncomputable
def presentation (X : CompHaus) : Stonean where
toTop := (projectivePresentation X).p.1
prop := by
refine CompactT2.Projective.extremallyDisconnected
(@fun Y Z _ _ _ _ _ _ f g hfcont hgcont hgsurj => ?_)
let g₁ : (CompHaus.of Y) ⟶ (CompHaus.of Z) := CompHausLike.ofHom _ ⟨g, hgcont⟩
let f₁ : (projectivePresentation X).p ⟶ (CompHaus.of Z) := CompHausLike.ofHom _ ⟨f, hfcont⟩
have hg₁ : Epi g₁ := (epi_iff_surjective _).2 hgsurj
refine ⟨Projective.factorThru f₁ g₁, (Projective.factorThru f₁ g₁).hom.2, funext (fun _ => ?_)⟩
change (Projective.factorThru f₁ g₁ ≫ g₁) _ = f _
rw [Projective.factorThru_comp]
rfl
/-- The morphism from `presentation X` to `X`. -/
noncomputable
def presentation.π (X : CompHaus) : Stonean.toCompHaus.obj X.presentation ⟶ X :=
(projectivePresentation X).f
/-- The morphism from `presentation X` to `X` is an epimorphism. -/
noncomputable
instance presentation.epi_π (X : CompHaus) : Epi (π X) :=
(projectivePresentation X).epi
/-- The underlying `CompHaus` of a `Stonean`. -/
abbrev _root_.Stonean.compHaus (X : Stonean) := Stonean.toCompHaus.obj X
/--
```
X
|
(f)
|
\/
Z ---(e)---> Y
```
If `Z` is a Stonean space, `f : X ⟶ Y` an epi in `CompHaus` and `e : Z ⟶ Y` is arbitrary, then
`lift e f` is a fixed (but arbitrary) lift of `e` to a morphism `Z ⟶ X`. It exists because
`Z` is a projective object in `CompHaus`.
-/
noncomputable
def lift {X Y : CompHaus} {Z : Stonean} (e : Z.compHaus ⟶ Y) (f : X ⟶ Y) [Epi f] :
Z.compHaus ⟶ X :=
Projective.factorThru e f
@[simp, reassoc]
lemma lift_lifts {X Y : CompHaus} {Z : Stonean} (e : Z.compHaus ⟶ Y) (f : X ⟶ Y) [Epi f] :
lift e f ≫ f = e := by simp [lift]
lemma Gleason (X : CompHaus.{u}) :
Projective X ↔ ExtremallyDisconnected X := by
constructor
· intro h
show ExtremallyDisconnected X.toStonean
infer_instance
· intro h
let X' : Stonean := ⟨X.toTop, inferInstance⟩
show Projective X'.compHaus
apply Stonean.instProjectiveCompHausCompHaus
end CompHaus
namespace Profinite
/-- If `X` is profinite, `presentation X` is a Stonean space equipped with an epimorphism down to
`X` (see `Profinite.presentation.π` and `Profinite.presentation.epi_π`). -/
noncomputable
def presentation (X : Profinite) : Stonean where
toTop := (profiniteToCompHaus.obj X).projectivePresentation.p.toTop
prop := (profiniteToCompHaus.obj X).presentation.prop
/-- The morphism from `presentation X` to `X`. -/
noncomputable
def presentation.π (X : Profinite) : Stonean.toProfinite.obj X.presentation ⟶ X :=
(profiniteToCompHaus.obj X).projectivePresentation.f
/-- The morphism from `presentation X` to `X` is an epimorphism. -/
noncomputable
instance presentation.epi_π (X : Profinite) : Epi (π X) := by
have := (profiniteToCompHaus.obj X).projectivePresentation.epi
rw [CompHaus.epi_iff_surjective] at this
rw [epi_iff_surjective]
exact this
/--
```
X
|
(f)
|
\/
Z ---(e)---> Y
```
If `Z` is a Stonean space, `f : X ⟶ Y` an epi in `Profinite` and `e : Z ⟶ Y` is arbitrary,
then `lift e f` is a fixed (but arbitrary) lift of `e` to a morphism `Z ⟶ X`. It is
`CompHaus.lift e f` as a morphism in `Profinite`.
-/
noncomputable
def lift {X Y : Profinite} {Z : Stonean} (e : Stonean.toProfinite.obj Z ⟶ Y) (f : X ⟶ Y) [Epi f] :
Stonean.toProfinite.obj Z ⟶ X := Projective.factorThru e f
@[simp, reassoc]
lemma lift_lifts {X Y : Profinite} {Z : Stonean} (e : Stonean.toProfinite.obj Z ⟶ Y) (f : X ⟶ Y)
[Epi f] : lift e f ≫ f = e := by simp [lift]
lemma projective_of_extrDisc {X : Profinite.{u}} (hX : ExtremallyDisconnected X) :
Projective X := by
show Projective (Stonean.toProfinite.obj ⟨X.toTop, inferInstance⟩)
exact inferInstance
end Profinite
| Mathlib/Topology/Category/Stonean/Basic.lean | 306 | 308 | |
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.AlgebraicTopology.SimplicialObject.Split
import Mathlib.AlgebraicTopology.DoldKan.PInfty
/-!
# Construction of the inverse functor of the Dold-Kan equivalence
In this file, we construct the functor `Γ₀ : ChainComplex C ℕ ⥤ SimplicialObject C`
which shall be the inverse functor of the Dold-Kan equivalence in the case of abelian categories,
and more generally pseudoabelian categories.
By definition, when `K` is a chain_complex, `Γ₀.obj K` is a simplicial object which
sends `Δ : SimplexCategoryᵒᵖ` to a certain coproduct indexed by the set
`Splitting.IndexSet Δ` whose elements consists of epimorphisms `e : Δ.unop ⟶ Δ'.unop`
(with `Δ' : SimplexCategoryᵒᵖ`); the summand attached to such an `e` is `K.X Δ'.unop.len`.
By construction, `Γ₀.obj K` is a split simplicial object whose splitting is `Γ₀.splitting K`.
We also construct `Γ₂ : Karoubi (ChainComplex C ℕ) ⥤ Karoubi (SimplicialObject C)`
which shall be an equivalence for any additive category `C`.
(See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.)
-/
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits SimplexCategory
SimplicialObject Opposite CategoryTheory.Idempotents Simplicial DoldKan
namespace AlgebraicTopology
namespace DoldKan
variable {C : Type*} [Category C] [Preadditive C] (K K' : ChainComplex C ℕ) (f : K ⟶ K')
{Δ Δ' Δ'' : SimplexCategory}
/-- `Isδ₀ i` is a simple condition used to check whether a monomorphism `i` in
`SimplexCategory` identifies to the coface map `δ 0`. -/
@[nolint unusedArguments]
def Isδ₀ {Δ Δ' : SimplexCategory} (i : Δ' ⟶ Δ) [Mono i] : Prop :=
Δ.len = Δ'.len + 1 ∧ i.toOrderHom 0 ≠ 0
namespace Isδ₀
theorem iff {j : ℕ} {i : Fin (j + 2)} : Isδ₀ (SimplexCategory.δ i) ↔ i = 0 := by
constructor
· rintro ⟨_, h₂⟩
by_contra h
exact h₂ (Fin.succAbove_ne_zero_zero h)
· rintro rfl
exact ⟨rfl, by dsimp; exact Fin.succ_ne_zero (0 : Fin (j + 1))⟩
theorem eq_δ₀ {n : ℕ} {i : ⦋n⦌ ⟶ ⦋n + 1⦌} [Mono i] (hi : Isδ₀ i) :
i = SimplexCategory.δ 0 := by
obtain ⟨j, rfl⟩ := SimplexCategory.eq_δ_of_mono i
rw [iff] at hi
rw [hi]
end Isδ₀
namespace Γ₀
namespace Obj
/-- In the definition of `(Γ₀.obj K).obj Δ` as a direct sum indexed by `A : Splitting.IndexSet Δ`,
the summand `summand K Δ A` is `K.X A.1.len`. -/
def summand (Δ : SimplexCategoryᵒᵖ) (A : Splitting.IndexSet Δ) : C :=
K.X A.1.unop.len
/-- The functor `Γ₀` sends a chain complex `K` to the simplicial object which
sends `Δ` to the direct sum of the objects `summand K Δ A` for all `A : Splitting.IndexSet Δ` -/
def obj₂ (K : ChainComplex C ℕ) (Δ : SimplexCategoryᵒᵖ) [HasFiniteCoproducts C] : C :=
∐ fun A : Splitting.IndexSet Δ => summand K Δ A
namespace Termwise
/-- A monomorphism `i : Δ' ⟶ Δ` induces a morphism `K.X Δ.len ⟶ K.X Δ'.len` which
is the identity if `Δ = Δ'`, the differential on the complex `K` if `i = δ 0`, and
zero otherwise. -/
def mapMono (K : ChainComplex C ℕ) {Δ' Δ : SimplexCategory} (i : Δ' ⟶ Δ) [Mono i] :
K.X Δ.len ⟶ K.X Δ'.len := by
by_cases Δ = Δ'
· exact eqToHom (by congr)
· by_cases Isδ₀ i
· exact K.d Δ.len Δ'.len
· exact 0
variable (Δ) in
theorem mapMono_id : mapMono K (𝟙 Δ) = 𝟙 _ := by
unfold mapMono
simp only [eq_self_iff_true, eqToHom_refl, dite_eq_ite, if_true]
theorem mapMono_δ₀' (i : Δ' ⟶ Δ) [Mono i] (hi : Isδ₀ i) : mapMono K i = K.d Δ.len Δ'.len := by
unfold mapMono
suffices Δ ≠ Δ' by
simp only [dif_neg this, dif_pos hi]
rintro rfl
simpa only [left_eq_add, Nat.one_ne_zero] using hi.1
@[simp]
theorem mapMono_δ₀ {n : ℕ} : mapMono K (δ (0 : Fin (n + 2))) = K.d (n + 1) n :=
mapMono_δ₀' K _ (by rw [Isδ₀.iff])
theorem mapMono_eq_zero (i : Δ' ⟶ Δ) [Mono i] (h₁ : Δ ≠ Δ') (h₂ : ¬Isδ₀ i) : mapMono K i = 0 := by
unfold mapMono
rw [Ne] at h₁
split_ifs
rfl
variable {K K'}
@[reassoc (attr := simp)]
theorem mapMono_naturality (i : Δ ⟶ Δ') [Mono i] :
mapMono K i ≫ f.f Δ.len = f.f Δ'.len ≫ mapMono K' i := by
unfold mapMono
split_ifs with h
· subst h
simp only [id_comp, eqToHom_refl, comp_id]
· rw [HomologicalComplex.Hom.comm]
· rw [zero_comp, comp_zero]
variable (K)
@[reassoc (attr := simp)]
theorem mapMono_comp (i' : Δ'' ⟶ Δ') (i : Δ' ⟶ Δ) [Mono i'] [Mono i] :
mapMono K i ≫ mapMono K i' = mapMono K (i' ≫ i) := by
-- case where i : Δ' ⟶ Δ is the identity
by_cases h₁ : Δ = Δ'
· subst h₁
simp only [SimplexCategory.eq_id_of_mono i, comp_id, id_comp, mapMono_id K, eqToHom_refl]
-- case where i' : Δ'' ⟶ Δ' is the identity
by_cases h₂ : Δ' = Δ''
· subst h₂
simp only [SimplexCategory.eq_id_of_mono i', comp_id, id_comp, mapMono_id K, eqToHom_refl]
-- then the RHS is always zero
obtain ⟨k, hk⟩ := Nat.exists_eq_add_of_lt (len_lt_of_mono i h₁)
obtain ⟨k', hk'⟩ := Nat.exists_eq_add_of_lt (len_lt_of_mono i' h₂)
have eq : Δ.len = Δ''.len + (k + k' + 2) := by omega
rw [mapMono_eq_zero K (i' ≫ i) _ _]; rotate_left
· by_contra h
simp only [left_eq_add, h, add_eq_zero, and_false, reduceCtorEq] at eq
· by_contra h
simp only [h.1, add_right_inj] at eq
omega
-- in all cases, the LHS is also zero, either by definition, or because d ≫ d = 0
by_cases h₃ : Isδ₀ i
· by_cases h₄ : Isδ₀ i'
· rw [mapMono_δ₀' K i h₃, mapMono_δ₀' K i' h₄, HomologicalComplex.d_comp_d]
· simp only [mapMono_eq_zero K i' h₂ h₄, comp_zero]
· simp only [mapMono_eq_zero K i h₁ h₃, zero_comp]
end Termwise
variable [HasFiniteCoproducts C]
/-- The simplicial morphism on the simplicial object `Γ₀.obj K` induced by
a morphism `Δ' → Δ` in `SimplexCategory` is defined on each summand
associated to an `A : Splitting.IndexSet Δ` in terms of the epi-mono factorisation
of `θ ≫ A.e`. -/
def map (K : ChainComplex C ℕ) {Δ' Δ : SimplexCategoryᵒᵖ} (θ : Δ ⟶ Δ') : obj₂ K Δ ⟶ obj₂ K Δ' :=
Sigma.desc fun A =>
Termwise.mapMono K (image.ι (θ.unop ≫ A.e)) ≫ Sigma.ι (summand K Δ') (A.pull θ)
@[reassoc]
theorem map_on_summand₀ {Δ Δ' : SimplexCategoryᵒᵖ} (A : Splitting.IndexSet Δ) {θ : Δ ⟶ Δ'}
{Δ'' : SimplexCategory} {e : Δ'.unop ⟶ Δ''} {i : Δ'' ⟶ A.1.unop} [Epi e] [Mono i]
(fac : e ≫ i = θ.unop ≫ A.e) :
Sigma.ι (summand K Δ) A ≫ map K θ =
Termwise.mapMono K i ≫ Sigma.ι (summand K Δ') (Splitting.IndexSet.mk e) := by
simp only [map, colimit.ι_desc, Cofan.mk_ι_app]
have h := SimplexCategory.image_eq fac
subst h
congr
· exact SimplexCategory.image_ι_eq fac
· dsimp only [SimplicialObject.Splitting.IndexSet.pull]
congr
exact SimplexCategory.factorThruImage_eq fac
@[reassoc]
theorem map_on_summand₀' {Δ Δ' : SimplexCategoryᵒᵖ} (A : Splitting.IndexSet Δ) (θ : Δ ⟶ Δ') :
Sigma.ι (summand K Δ) A ≫ map K θ =
Termwise.mapMono K (image.ι (θ.unop ≫ A.e)) ≫ Sigma.ι (summand K _) (A.pull θ) :=
| map_on_summand₀ K A (A.fac_pull θ)
end Obj
variable [HasFiniteCoproducts C]
/-- The functor `Γ₀ : ChainComplex C ℕ ⥤ SimplicialObject C`, on objects. -/
@[simps]
def obj (K : ChainComplex C ℕ) : SimplicialObject C where
obj Δ := Obj.obj₂ K Δ
map θ := Obj.map K θ
map_id Δ := colimit.hom_ext (fun ⟨A⟩ => by
dsimp
| Mathlib/AlgebraicTopology/DoldKan/FunctorGamma.lean | 190 | 202 |
/-
Copyright (c) 2018 Rohan Mitta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Order.Interval.Set.ProjIcc
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Topology.Bornology.Hom
import Mathlib.Topology.EMetricSpace.Lipschitz
import Mathlib.Topology.Maps.Proper.Basic
import Mathlib.Topology.MetricSpace.Basic
import Mathlib.Topology.MetricSpace.Bounded
/-!
# Lipschitz continuous functions
A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous*
with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`.
For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`.
There is also a version asserting this inequality only for `x` and `y` in some set `s`.
Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood
on which `f` is Lipschitz continuous (with some constant).
In this file we specialize various facts about Lipschitz continuous maps
to the case of (pseudo) metric spaces.
## Implementation notes
The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have
coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an
argument, and return `LipschitzWith (Real.toNNReal K) f`.
-/
assert_not_exists Basis Ideal
universe u v w x
open Filter Function Set Topology NNReal ENNReal Bornology
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x}
theorem lipschitzWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0}
{f : α → β} : LipschitzWith K f ↔ ∀ x y, dist (f x) (f y) ≤ K * dist x y := by
simp only [LipschitzWith, edist_nndist, dist_nndist]
norm_cast
alias ⟨LipschitzWith.dist_le_mul, LipschitzWith.of_dist_le_mul⟩ := lipschitzWith_iff_dist_le_mul
theorem lipschitzOnWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0}
{s : Set α} {f : α → β} :
LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y := by
simp only [LipschitzOnWith, edist_nndist, dist_nndist]
norm_cast
alias ⟨LipschitzOnWith.dist_le_mul, LipschitzOnWith.of_dist_le_mul⟩ :=
lipschitzOnWith_iff_dist_le_mul
namespace LipschitzWith
section Metric
variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] {K : ℝ≥0} {f : α → β}
{x y : α} {r : ℝ}
protected theorem of_dist_le' {K : ℝ} (h : ∀ x y, dist (f x) (f y) ≤ K * dist x y) :
LipschitzWith (Real.toNNReal K) f :=
of_dist_le_mul fun x y =>
le_trans (h x y) <| by gcongr; apply Real.le_coe_toNNReal
protected theorem mk_one (h : ∀ x y, dist (f x) (f y) ≤ dist x y) : LipschitzWith 1 f :=
of_dist_le_mul <| by simpa only [NNReal.coe_one, one_mul] using h
/-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version
doesn't assume `0≤K`. -/
protected theorem of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀ x y, f x ≤ f y + K * dist x y) :
LipschitzWith (Real.toNNReal K) f :=
have I : ∀ x y, f x - f y ≤ K * dist x y := fun x y => sub_le_iff_le_add'.2 (h x y)
LipschitzWith.of_dist_le' fun x y => abs_sub_le_iff.2 ⟨I x y, dist_comm y x ▸ I y x⟩
/-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version
assumes `0≤K`. -/
protected theorem of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀ x y, f x ≤ f y + K * dist x y) :
LipschitzWith K f := by simpa only [Real.toNNReal_coe] using LipschitzWith.of_le_add_mul' K h
protected theorem of_le_add {f : α → ℝ} (h : ∀ x y, f x ≤ f y + dist x y) : LipschitzWith 1 f :=
LipschitzWith.of_le_add_mul 1 <| by simpa only [NNReal.coe_one, one_mul]
protected theorem le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : LipschitzWith K f) (x y) :
f x ≤ f y + K * dist x y :=
sub_le_iff_le_add'.1 <| le_trans (le_abs_self _) <| h.dist_le_mul x y
protected theorem iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} :
LipschitzWith K f ↔ ∀ x y, f x ≤ f y + K * dist x y :=
⟨LipschitzWith.le_add_mul, LipschitzWith.of_le_add_mul K⟩
theorem nndist_le (hf : LipschitzWith K f) (x y : α) : nndist (f x) (f y) ≤ K * nndist x y :=
hf.dist_le_mul x y
theorem dist_le_mul_of_le (hf : LipschitzWith K f) (hr : dist x y ≤ r) : dist (f x) (f y) ≤ K * r :=
(hf.dist_le_mul x y).trans <| by gcongr
theorem mapsTo_closedBall (hf : LipschitzWith K f) (x : α) (r : ℝ) :
MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) (K * r)) := fun _y hy =>
hf.dist_le_mul_of_le hy
theorem dist_lt_mul_of_lt (hf : LipschitzWith K f) (hK : K ≠ 0) (hr : dist x y < r) :
dist (f x) (f y) < K * r :=
(hf.dist_le_mul x y).trans_lt <| (mul_lt_mul_left <| NNReal.coe_pos.2 hK.bot_lt).2 hr
theorem mapsTo_ball (hf : LipschitzWith K f) (hK : K ≠ 0) (x : α) (r : ℝ) :
MapsTo f (Metric.ball x r) (Metric.ball (f x) (K * r)) := fun _y hy =>
hf.dist_lt_mul_of_lt hK hy
/-- A Lipschitz continuous map is a locally bounded map. -/
def toLocallyBoundedMap (f : α → β) (hf : LipschitzWith K f) : LocallyBoundedMap α β :=
LocallyBoundedMap.ofMapBounded f fun _s hs =>
let ⟨C, hC⟩ := Metric.isBounded_iff.1 hs
Metric.isBounded_iff.2 ⟨K * C, forall_mem_image.2 fun _x hx => forall_mem_image.2 fun _y hy =>
hf.dist_le_mul_of_le (hC hx hy)⟩
@[simp]
theorem coe_toLocallyBoundedMap (hf : LipschitzWith K f) : ⇑(hf.toLocallyBoundedMap f) = f :=
rfl
theorem comap_cobounded_le (hf : LipschitzWith K f) :
comap f (Bornology.cobounded β) ≤ Bornology.cobounded α :=
(hf.toLocallyBoundedMap f).2
/-- The image of a bounded set under a Lipschitz map is bounded. -/
theorem isBounded_image (hf : LipschitzWith K f) {s : Set α} (hs : IsBounded s) :
IsBounded (f '' s) :=
hs.image (toLocallyBoundedMap f hf)
theorem diam_image_le (hf : LipschitzWith K f) (s : Set α) (hs : IsBounded s) :
Metric.diam (f '' s) ≤ K * Metric.diam s :=
Metric.diam_le_of_forall_dist_le (mul_nonneg K.coe_nonneg Metric.diam_nonneg) <|
forall_mem_image.2 fun _x hx =>
forall_mem_image.2 fun _y hy => hf.dist_le_mul_of_le <| Metric.dist_le_diam_of_mem hs hx hy
protected theorem dist_left (y : α) : LipschitzWith 1 (dist · y) :=
LipschitzWith.mk_one fun _ _ => dist_dist_dist_le_left _ _ _
protected theorem dist_right (x : α) : LipschitzWith 1 (dist x) :=
LipschitzWith.of_le_add fun _ _ => dist_triangle_right _ _ _
protected theorem dist : LipschitzWith 2 (Function.uncurry <| @dist α _) := by
rw [← one_add_one_eq_two]
exact LipschitzWith.uncurry LipschitzWith.dist_left LipschitzWith.dist_right
theorem dist_iterate_succ_le_geometric {f : α → α} (hf : LipschitzWith K f) (x n) :
dist (f^[n] x) (f^[n + 1] x) ≤ dist x (f x) * (K : ℝ) ^ n := by
rw [iterate_succ, mul_comm]
simpa only [NNReal.coe_pow] using (hf.iterate n).dist_le_mul x (f x)
theorem _root_.lipschitzWith_max : LipschitzWith 1 fun p : ℝ × ℝ => max p.1 p.2 :=
LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <|
(le_abs_self _).trans (abs_max_sub_max_le_max _ _ _ _)
theorem _root_.lipschitzWith_min : LipschitzWith 1 fun p : ℝ × ℝ => min p.1 p.2 :=
LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <|
(le_abs_self _).trans (abs_min_sub_min_le_max _ _ _ _)
lemma _root_.Real.lipschitzWith_toNNReal : LipschitzWith 1 Real.toNNReal := by
refine lipschitzWith_iff_dist_le_mul.mpr (fun x y ↦ ?_)
simpa only [NNReal.coe_one, dist_prod_same_right, one_mul, Real.dist_eq] using
lipschitzWith_iff_dist_le_mul.mp lipschitzWith_max (x, 0) (y, 0)
lemma cauchySeq_comp (hf : LipschitzWith K f) {u : ℕ → α} (hu : CauchySeq u) :
CauchySeq (f ∘ u) := by
rcases cauchySeq_iff_le_tendsto_0.1 hu with ⟨b, b_nonneg, hb, blim⟩
refine cauchySeq_iff_le_tendsto_0.2 ⟨fun n ↦ K * b n, ?_, ?_, ?_⟩
· exact fun n ↦ mul_nonneg (by positivity) (b_nonneg n)
· exact fun n m N hn hm ↦ hf.dist_le_mul_of_le (hb n m N hn hm)
· rw [← mul_zero (K : ℝ)]
exact blim.const_mul _
end Metric
section EMetric
variable [PseudoEMetricSpace α] {f g : α → ℝ} {Kf Kg : ℝ≥0}
protected theorem max (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (max Kf Kg) fun x => max (f x) (g x) := by
simpa only [(· ∘ ·), one_mul] using lipschitzWith_max.comp (hf.prodMk hg)
protected theorem min (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (max Kf Kg) fun x => min (f x) (g x) := by
simpa only [(· ∘ ·), one_mul] using lipschitzWith_min.comp (hf.prodMk hg)
theorem max_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max (f x) a := by
simpa only [max_eq_left (zero_le Kf)] using hf.max (LipschitzWith.const a)
theorem const_max (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max a (f x) := by
simpa only [max_comm] using hf.max_const a
theorem min_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min (f x) a := by
simpa only [max_eq_left (zero_le Kf)] using hf.min (LipschitzWith.const a)
theorem const_min (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min a (f x) := by
simpa only [min_comm] using hf.min_const a
end EMetric
protected theorem projIcc {a b : ℝ} (h : a ≤ b) : LipschitzWith 1 (projIcc a b h) :=
((LipschitzWith.id.const_min _).const_max _).subtype_mk _
end LipschitzWith
/-- The preimage of a proper space under a Lipschitz proper map is proper. -/
lemma LipschitzWith.properSpace {X Y : Type*} [PseudoMetricSpace X]
[PseudoMetricSpace Y] [ProperSpace Y] {f : X → Y} (hf : IsProperMap f)
{K : ℝ≥0} (hf' : LipschitzWith K f) : ProperSpace X :=
⟨fun x r ↦ (hf.isCompact_preimage (isCompact_closedBall (f x) (K * r))).of_isClosed_subset
Metric.isClosed_closedBall (hf'.mapsTo_closedBall x r).subset_preimage⟩
namespace Metric
variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s : Set α} {t : Set β}
end Metric
namespace LipschitzOnWith
section Metric
variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ]
variable {K : ℝ≥0} {s : Set α} {f : α → β}
protected theorem of_dist_le' {K : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y) :
LipschitzOnWith (Real.toNNReal K) f s :=
of_dist_le_mul fun x hx y hy =>
le_trans (h x hx y hy) <| by gcongr; apply Real.le_coe_toNNReal
protected theorem mk_one (h : ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ dist x y) :
LipschitzOnWith 1 f s :=
of_dist_le_mul <| by simpa only [NNReal.coe_one, one_mul] using h
/-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version
doesn't assume `0≤K`. -/
protected theorem of_le_add_mul' {f : α → ℝ} (K : ℝ)
(h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y) : LipschitzOnWith (Real.toNNReal K) f s :=
have I : ∀ x ∈ s, ∀ y ∈ s, f x - f y ≤ K * dist x y := fun x hx y hy =>
sub_le_iff_le_add'.2 (h x hx y hy)
LipschitzOnWith.of_dist_le' fun x hx y hy =>
abs_sub_le_iff.2 ⟨I x hx y hy, dist_comm y x ▸ I y hy x hx⟩
/-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version
assumes `0≤K`. -/
protected theorem of_le_add_mul {f : α → ℝ} (K : ℝ≥0)
(h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y) : LipschitzOnWith K f s := by
simpa only [Real.toNNReal_coe] using LipschitzOnWith.of_le_add_mul' K h
protected theorem of_le_add {f : α → ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + dist x y) :
LipschitzOnWith 1 f s :=
LipschitzOnWith.of_le_add_mul 1 <| by simpa only [NNReal.coe_one, one_mul]
protected theorem le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : LipschitzOnWith K f s) {x : α} (hx : x ∈ s)
{y : α} (hy : y ∈ s) : f x ≤ f y + K * dist x y :=
sub_le_iff_le_add'.1 <| le_trans (le_abs_self _) <| h.dist_le_mul x hx y hy
protected theorem iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} :
LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y :=
⟨LipschitzOnWith.le_add_mul, LipschitzOnWith.of_le_add_mul K⟩
theorem isBounded_image2 (f : α → β → γ) {K₁ K₂ : ℝ≥0} {s : Set α} {t : Set β}
(hs : Bornology.IsBounded s) (ht : Bornology.IsBounded t)
(hf₁ : ∀ b ∈ t, LipschitzOnWith K₁ (fun a => f a b) s)
(hf₂ : ∀ a ∈ s, LipschitzOnWith K₂ (f a) t) : Bornology.IsBounded (Set.image2 f s t) :=
Metric.isBounded_iff_ediam_ne_top.2 <|
ne_top_of_le_ne_top
(ENNReal.add_ne_top.mpr
⟨ENNReal.mul_ne_top ENNReal.coe_ne_top hs.ediam_ne_top,
ENNReal.mul_ne_top ENNReal.coe_ne_top ht.ediam_ne_top⟩)
(ediam_image2_le _ _ _ hf₁ hf₂)
lemma cauchySeq_comp (hf : LipschitzOnWith K f s)
{u : ℕ → α} (hu : CauchySeq u) (h'u : range u ⊆ s) :
CauchySeq (f ∘ u) := by
rcases cauchySeq_iff_le_tendsto_0.1 hu with ⟨b, b_nonneg, hb, blim⟩
refine cauchySeq_iff_le_tendsto_0.2 ⟨fun n ↦ K * b n, ?_, ?_, ?_⟩
· exact fun n ↦ mul_nonneg (by positivity) (b_nonneg n)
· intro n m N hn hm
have A n : u n ∈ s := h'u (mem_range_self _)
apply (hf.dist_le_mul _ (A n) _ (A m)).trans
exact mul_le_mul_of_nonneg_left (hb n m N hn hm) K.2
· rw [← mul_zero (K : ℝ)]
exact blim.const_mul _
end Metric
end LipschitzOnWith
namespace LocallyLipschitz
section Real
variable [PseudoEMetricSpace α] {f g : α → ℝ}
/-- The minimum of locally Lipschitz functions is locally Lipschitz. -/
protected lemma min (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz (fun x => min (f x) (g x)) :=
lipschitzWith_min.locallyLipschitz.comp (hf.prodMk hg)
/-- The maximum of locally Lipschitz functions is locally Lipschitz. -/
protected lemma max (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz (fun x => max (f x) (g x)) :=
lipschitzWith_max.locallyLipschitz.comp (hf.prodMk hg)
theorem max_const (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => max (f x) a :=
hf.max (LocallyLipschitz.const a)
theorem const_max (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => max a (f x) := by
simpa [max_comm] using (hf.max_const a)
theorem min_const (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => min (f x) a :=
hf.min (LocallyLipschitz.const a)
theorem const_min (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => min a (f x) := by
simpa [min_comm] using (hf.min_const a)
end Real
end LocallyLipschitz
open Metric
variable [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β}
/-- If a function is locally Lipschitz around a point, then it is continuous at this point. -/
theorem continuousAt_of_locally_lipschitz {x : α} {r : ℝ} (hr : 0 < r) (K : ℝ)
(h : ∀ y, dist y x < r → dist (f y) (f x) ≤ K * dist y x) : ContinuousAt f x := by
-- We use `h` to squeeze `dist (f y) (f x)` between `0` and `K * dist y x`
refine tendsto_iff_dist_tendsto_zero.2 (squeeze_zero' (Eventually.of_forall fun _ => dist_nonneg)
(mem_of_superset (ball_mem_nhds _ hr) h) ?_)
-- Then show that `K * dist y x` tends to zero as `y → x`
refine (continuous_const.mul (continuous_id.dist continuous_const)).tendsto' _ _ ?_
simp
/-- A function `f : α → ℝ` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz extension
to the whole space. -/
theorem LipschitzOnWith.extend_real {f : α → ℝ} {s : Set α} {K : ℝ≥0} (hf : LipschitzOnWith K f s) :
∃ g : α → ℝ, LipschitzWith K g ∧ EqOn f g s := by
/- An extension is given by `g y = Inf {f x + K * dist y x | x ∈ s}`. Taking `x = y`, one has
`g y ≤ f y` for `y ∈ s`, and the other inequality holds because `f` is `K`-Lipschitz, so that it
can not counterbalance the growth of `K * dist y x`. One readily checks from the formula that
the extended function is also `K`-Lipschitz. -/
rcases eq_empty_or_nonempty s with (rfl | hs)
· exact ⟨fun _ => 0, (LipschitzWith.const _).weaken (zero_le _), eqOn_empty _ _⟩
have : Nonempty s := by simp only [hs, nonempty_coe_sort]
let g := fun y : α => iInf fun x : s => f x + K * dist y x
have B : ∀ y : α, BddBelow (range fun x : s => f x + K * dist y x) := fun y => by
rcases hs with ⟨z, hz⟩
refine ⟨f z - K * dist y z, ?_⟩
rintro w ⟨t, rfl⟩
dsimp
rw [sub_le_iff_le_add, add_assoc, ← mul_add, add_comm (dist y t)]
calc
f z ≤ f t + K * dist z t := hf.le_add_mul hz t.2
_ ≤ f t + K * (dist y z + dist y t) := by gcongr; apply dist_triangle_left
have E : EqOn f g s := fun x hx => by
refine le_antisymm (le_ciInf fun y => hf.le_add_mul hx y.2) ?_
simpa only [add_zero, Subtype.coe_mk, mul_zero, dist_self] using ciInf_le (B x) ⟨x, hx⟩
refine ⟨g, LipschitzWith.of_le_add_mul K fun x y => ?_, E⟩
rw [← sub_le_iff_le_add]
refine le_ciInf fun z => ?_
rw [sub_le_iff_le_add]
calc
g x ≤ f z + K * dist x z := ciInf_le (B x) _
_ ≤ f z + K * dist y z + K * dist x y := by
rw [add_assoc, ← mul_add, add_comm (dist y z)]
| gcongr
apply dist_triangle
/-- A function `f : α → (ι → ℝ)` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz
extension to the whole space. The same result for the space `ℓ^∞ (ι, ℝ)` over a possibly infinite
type `ι` is implemented in `LipschitzOnWith.extend_lp_infty`. -/
theorem LipschitzOnWith.extend_pi [Fintype ι] {f : α → ι → ℝ} {s : Set α}
{K : ℝ≥0} (hf : LipschitzOnWith K f s) : ∃ g : α → ι → ℝ, LipschitzWith K g ∧ EqOn f g s := by
| Mathlib/Topology/MetricSpace/Lipschitz.lean | 371 | 378 |
/-
Copyright (c) 2024 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.FieldTheory.KummerExtension
/-!
# More results on primitive roots of unity
(We put these in a separate file because of the `KummerExtension` import.)
Assume that `μ` is a primitive `n`th root of unity in an integral domain `R`. Then
$$ \prod_{k=1}^{n-1} (1 - \mu^k) = n \,; $$
see `IsPrimitiveRoot.prod_one_sub_pow_eq_order` and its variant
`IsPrimitiveRoot.prod_pow_sub_one_eq_order` in terms of `∏ (μ^k - 1)`.
We use this to deduce that `n` is divisible by `(μ - 1)^k` in `ℤ[μ] ⊆ R` when `k < n`.
-/
variable {R : Type*} [CommRing R] [IsDomain R]
namespace IsPrimitiveRoot
open Finset Polynomial
/-- If `μ` is a primitive `n`th root of unity in `R`, then `∏(1≤k<n) (1-μ^k) = n`.
(Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/
lemma prod_one_sub_pow_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) :
∏ k ∈ range n, (1 - μ ^ (k + 1)) = n + 1 := by
have := X_pow_sub_C_eq_prod hμ n.zero_lt_succ (one_pow (n + 1))
rw [C_1, ← mul_geom_sum, prod_range_succ', pow_zero, mul_one, mul_comm, eq_comm] at this
replace this := mul_right_cancel₀ (Polynomial.X_sub_C_ne_zero 1) this
apply_fun Polynomial.eval 1 at this
simpa only [mul_one, map_pow, eval_prod, eval_sub, eval_X, eval_pow, eval_C, eval_geom_sum,
one_pow, sum_const, card_range, nsmul_eq_mul, Nat.cast_add, Nat.cast_one] using this
/-- If `μ` is a primitive `n`th root of unity in `R`, then `(-1)^(n-1) * ∏(1≤k<n) (μ^k-1) = n`.
(Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/
lemma prod_pow_sub_one_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) :
(-1) ^ n * ∏ k ∈ range n, (μ ^ (k + 1) - 1) = n + 1 := by
have : (-1 : R) ^ n = ∏ k ∈ range n, -1 := by rw [prod_const, card_range]
simp only [this, ← prod_mul_distrib, neg_one_mul, neg_sub, ← prod_one_sub_pow_eq_order hμ]
open Algebra in
/-- If `μ` is a primitive `n`th root of unity in `R` and `k < n`, then `n` is divisible
| by `(μ-1)^k` in `ℤ[μ] ⊆ R`. -/
lemma self_sub_one_pow_dvd_order {k n : ℕ} (hn : k < n) {μ : R} (hμ : IsPrimitiveRoot μ n) :
∃ z ∈ adjoin ℤ {μ}, n = z * (μ - 1) ^ k := by
let n' + 1 := n
obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le' (Nat.le_of_lt_succ hn)
have hdvd k : ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1) := by
refine ⟨(Finset.range k).sum (μ ^ ·), ?_, (geom_sum_mul μ k).symm⟩
exact Subalgebra.sum_mem _ fun m _ ↦ Subalgebra.pow_mem _ (self_mem_adjoin_singleton _ μ) _
let Z k := Classical.choose <| hdvd k
have Zdef k : Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1) :=
Classical.choose_spec <| hdvd k
refine ⟨(-1) ^ (m + k) * (∏ j ∈ range k, Z (j + 1)) * ∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1),
?_, ?_⟩
· apply Subalgebra.mul_mem
· apply Subalgebra.mul_mem
· exact Subalgebra.pow_mem _ (Subalgebra.neg_mem _ <| Subalgebra.one_mem _) _
· exact Subalgebra.prod_mem _ fun _ _ ↦ (Zdef _).1
· refine Subalgebra.prod_mem _ fun _ _ ↦ ?_
apply Subalgebra.sub_mem
· exact Subalgebra.pow_mem _ (self_mem_adjoin_singleton ℤ μ) _
· exact Subalgebra.one_mem _
· push_cast
have := Nat.cast_add (R := R) m k ▸ hμ.prod_pow_sub_one_eq_order
rw [← this, mul_assoc, mul_assoc]
congr 1
conv => enter [2, 2, 2]; rw [← card_range k]
rw [← prod_range_mul_prod_Ico _ (Nat.le_add_left k m), mul_comm _ (_ ^ #_), ← mul_assoc,
prod_mul_pow_card]
conv => enter [2, 1, 2, j]; rw [← (Zdef _).2]
| Mathlib/RingTheory/RootsOfUnity/Lemmas.lean | 47 | 76 |
/-
Copyright (c) 2021 Gabriel Moise. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Moise, Yaël Dillies, Kyle Miller
-/
import Mathlib.Combinatorics.SimpleGraph.Finite
import Mathlib.Data.Finset.Sym
import Mathlib.Data.Matrix.Mul
/-!
# Incidence matrix of a simple graph
This file defines the unoriented incidence matrix of a simple graph.
## Main definitions
* `SimpleGraph.incMatrix`: `G.incMatrix R` is the incidence matrix of `G` over the ring `R`.
## Main results
* `SimpleGraph.incMatrix_mul_transpose_diag`: The diagonal entries of the product of
`G.incMatrix R` and its transpose are the degrees of the vertices.
* `SimpleGraph.incMatrix_mul_transpose`: Gives a complete description of the product of
`G.incMatrix R` and its transpose; the diagonal is the degrees of each vertex, and the
off-diagonals are 1 or 0 depending on whether or not the vertices are adjacent.
* `SimpleGraph.incMatrix_transpose_mul_diag`: The diagonal entries of the product of the
transpose of `G.incMatrix R` and `G.inc_matrix R` are `2` or `0` depending on whether or
not the unordered pair is an edge of `G`.
## Implementation notes
The usual definition of an incidence matrix has one row per vertex and one column per edge.
However, this definition has columns indexed by all of `Sym2 α`, where `α` is the vertex type.
This appears not to change the theory, and for simple graphs it has the nice effect that every
incidence matrix for each `SimpleGraph α` has the same type.
## TODO
* Define the oriented incidence matrices for oriented graphs.
* Define the graph Laplacian of a simple graph using the oriented incidence matrix from an
arbitrary orientation of a simple graph.
-/
assert_not_exists Field
open Finset Matrix SimpleGraph Sym2
namespace SimpleGraph
variable (R : Type*) {α : Type*} (G : SimpleGraph α)
/-- `G.incMatrix R` is the `α × Sym2 α` matrix whose `(a, e)`-entry is `1` if `e` is incident to
`a` and `0` otherwise. -/
noncomputable def incMatrix [Zero R] [One R] : Matrix α (Sym2 α) R := fun a =>
(G.incidenceSet a).indicator 1
variable {R}
theorem incMatrix_apply [Zero R] [One R] {a : α} {e : Sym2 α} :
G.incMatrix R a e = (G.incidenceSet a).indicator 1 e :=
rfl
/-- Entries of the incidence matrix can be computed given additional decidable instances. -/
theorem incMatrix_apply' [Zero R] [One R] [DecidableEq α] [DecidableRel G.Adj] {a : α}
{e : Sym2 α} : G.incMatrix R a e = if e ∈ G.incidenceSet a then 1 else 0 := by
simp only [incMatrix, Set.indicator, Pi.one_apply]
section MulZeroOneClass
variable [MulZeroOneClass R] {a b : α} {e : Sym2 α}
theorem incMatrix_apply_mul_incMatrix_apply : G.incMatrix R a e * G.incMatrix R b e =
(G.incidenceSet a ∩ G.incidenceSet b).indicator 1 e := by
classical simp only [incMatrix, Set.indicator_apply, ite_zero_mul_ite_zero, Pi.one_apply, mul_one,
Set.mem_inter_iff]
theorem incMatrix_apply_mul_incMatrix_apply_of_not_adj (hab : a ≠ b) (h : ¬G.Adj a b) :
G.incMatrix R a e * G.incMatrix R b e = 0 := by
rw [incMatrix_apply_mul_incMatrix_apply, Set.indicator_of_not_mem]
rw [G.incidenceSet_inter_incidenceSet_of_not_adj h hab]
exact Set.not_mem_empty e
theorem incMatrix_of_not_mem_incidenceSet (h : e ∉ G.incidenceSet a) : G.incMatrix R a e = 0 := by
rw [incMatrix_apply, Set.indicator_of_not_mem h]
theorem incMatrix_of_mem_incidenceSet (h : e ∈ G.incidenceSet a) : G.incMatrix R a e = 1 := by
rw [incMatrix_apply, Set.indicator_of_mem h, Pi.one_apply]
variable [Nontrivial R]
theorem incMatrix_apply_eq_zero_iff : G.incMatrix R a e = 0 ↔ e ∉ G.incidenceSet a := by
simp only [incMatrix_apply, Set.indicator_apply_eq_zero, Pi.one_apply, one_ne_zero]
theorem incMatrix_apply_eq_one_iff : G.incMatrix R a e = 1 ↔ e ∈ G.incidenceSet a := by
convert one_ne_zero.ite_eq_left_iff
infer_instance
end MulZeroOneClass
section NonAssocSemiring
variable [NonAssocSemiring R] {a : α} {e : Sym2 α}
theorem sum_incMatrix_apply [Fintype (Sym2 α)] [Fintype (neighborSet G a)] :
∑ e, G.incMatrix R a e = G.degree a := by
classical simp [incMatrix_apply', sum_boole, Set.filter_mem_univ_eq_toFinset]
theorem incMatrix_mul_transpose_diag [Fintype (Sym2 α)] [Fintype (neighborSet G a)] :
(G.incMatrix R * (G.incMatrix R)ᵀ) a a = G.degree a := by
classical
rw [← sum_incMatrix_apply]
simp only [mul_apply, incMatrix_apply', transpose_apply, mul_ite, mul_one, mul_zero]
simp_all only [ite_true, sum_boole]
theorem sum_incMatrix_apply_of_mem_edgeSet [Fintype α] :
e ∈ G.edgeSet → ∑ a, G.incMatrix R a e = 2 := by
classical
refine e.ind ?_
intro a b h
rw [mem_edgeSet] at h
rw [← Nat.cast_two, ← card_pair h.ne]
simp only [incMatrix_apply', sum_boole, mk'_mem_incidenceSet_iff, h]
congr 2
ext e
simp only [mem_filter, mem_univ, true_and, mem_insert, mem_singleton]
theorem sum_incMatrix_apply_of_not_mem_edgeSet [Fintype α] (h : e ∉ G.edgeSet) :
∑ a, G.incMatrix R a e = 0 :=
sum_eq_zero fun _ _ => G.incMatrix_of_not_mem_incidenceSet fun he => h he.1
theorem incMatrix_transpose_mul_diag [Fintype α] [Decidable (e ∈ G.edgeSet)] :
((G.incMatrix R)ᵀ * G.incMatrix R) e e = if e ∈ G.edgeSet then 2 else 0 := by
classical
| simp only [Matrix.mul_apply, incMatrix_apply', transpose_apply, ite_zero_mul_ite_zero, one_mul,
sum_boole, and_self_iff]
split_ifs with h
· revert h
refine e.ind ?_
intro v w h
rw [← Nat.cast_two, ← card_pair (G.ne_of_adj h)]
simp only [mk'_mem_incidenceSet_iff, G.mem_edgeSet.mp h, true_and, mem_univ, forall_true_left,
forall_eq_or_imp, forall_eq, and_self, mem_singleton, ne_eq]
congr 2
ext u
| Mathlib/Combinatorics/SimpleGraph/IncMatrix.lean | 134 | 144 |
/-
Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov
-/
import Mathlib.Combinatorics.SimpleGraph.Maps
import Mathlib.Data.Finset.Max
import Mathlib.Data.Sym.Card
/-!
# Definitions for finite and locally finite graphs
This file defines finite versions of `edgeSet`, `neighborSet` and `incidenceSet` and proves some
of their basic properties. It also defines the notion of a locally finite graph, which is one
whose vertices have finite degree.
The design for finiteness is that each definition takes the smallest finiteness assumption
necessary. For example, `SimpleGraph.neighborFinset v` only requires that `v` have
finitely many neighbors.
## Main definitions
* `SimpleGraph.edgeFinset` is the `Finset` of edges in a graph, if `edgeSet` is finite
* `SimpleGraph.neighborFinset` is the `Finset` of vertices adjacent to a given vertex,
if `neighborSet` is finite
* `SimpleGraph.incidenceFinset` is the `Finset` of edges containing a given vertex,
if `incidenceSet` is finite
## Naming conventions
If the vertex type of a graph is finite, we refer to its cardinality as `CardVerts`
or `card_verts`.
## Implementation notes
* A locally finite graph is one with instances `Π v, Fintype (G.neighborSet v)`.
* Given instances `DecidableRel G.Adj` and `Fintype V`, then the graph
is locally finite, too.
-/
open Finset Function
namespace SimpleGraph
variable {V : Type*} (G : SimpleGraph V) {e : Sym2 V}
section EdgeFinset
variable {G₁ G₂ : SimpleGraph V} [Fintype G.edgeSet] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet]
/-- The `edgeSet` of the graph as a `Finset`. -/
abbrev edgeFinset : Finset (Sym2 V) :=
Set.toFinset G.edgeSet
@[norm_cast]
theorem coe_edgeFinset : (G.edgeFinset : Set (Sym2 V)) = G.edgeSet :=
Set.coe_toFinset _
variable {G}
theorem mem_edgeFinset : e ∈ G.edgeFinset ↔ e ∈ G.edgeSet :=
Set.mem_toFinset
theorem not_isDiag_of_mem_edgeFinset : e ∈ G.edgeFinset → ¬e.IsDiag :=
not_isDiag_of_mem_edgeSet _ ∘ mem_edgeFinset.1
theorem edgeFinset_inj : G₁.edgeFinset = G₂.edgeFinset ↔ G₁ = G₂ := by simp
theorem edgeFinset_subset_edgeFinset : G₁.edgeFinset ⊆ G₂.edgeFinset ↔ G₁ ≤ G₂ := by simp
theorem edgeFinset_ssubset_edgeFinset : G₁.edgeFinset ⊂ G₂.edgeFinset ↔ G₁ < G₂ := by simp
@[gcongr] alias ⟨_, edgeFinset_mono⟩ := edgeFinset_subset_edgeFinset
alias ⟨_, edgeFinset_strict_mono⟩ := edgeFinset_ssubset_edgeFinset
attribute [mono] edgeFinset_mono edgeFinset_strict_mono
@[simp]
theorem edgeFinset_bot : (⊥ : SimpleGraph V).edgeFinset = ∅ := by simp [edgeFinset]
@[simp]
theorem edgeFinset_sup [Fintype (edgeSet (G₁ ⊔ G₂))] [DecidableEq V] :
(G₁ ⊔ G₂).edgeFinset = G₁.edgeFinset ∪ G₂.edgeFinset := by simp [edgeFinset]
@[simp]
theorem edgeFinset_inf [DecidableEq V] : (G₁ ⊓ G₂).edgeFinset = G₁.edgeFinset ∩ G₂.edgeFinset := by
simp [edgeFinset]
@[simp]
theorem edgeFinset_sdiff [DecidableEq V] :
(G₁ \ G₂).edgeFinset = G₁.edgeFinset \ G₂.edgeFinset := by simp [edgeFinset]
lemma disjoint_edgeFinset : Disjoint G₁.edgeFinset G₂.edgeFinset ↔ Disjoint G₁ G₂ := by
simp_rw [← Finset.disjoint_coe, coe_edgeFinset, disjoint_edgeSet]
lemma edgeFinset_eq_empty : G.edgeFinset = ∅ ↔ G = ⊥ := by
rw [← edgeFinset_bot, edgeFinset_inj]
lemma edgeFinset_nonempty : G.edgeFinset.Nonempty ↔ G ≠ ⊥ := by
rw [Finset.nonempty_iff_ne_empty, edgeFinset_eq_empty.ne]
theorem edgeFinset_card : #G.edgeFinset = Fintype.card G.edgeSet :=
Set.toFinset_card _
@[simp]
theorem edgeSet_univ_card : #(univ : Finset G.edgeSet) = #G.edgeFinset :=
Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset
variable [Fintype V]
@[simp]
theorem edgeFinset_top [DecidableEq V] :
(⊤ : SimpleGraph V).edgeFinset = ({e | ¬e.IsDiag} : Finset _) := by simp [← coe_inj]
/-- The complete graph on `n` vertices has `n.choose 2` edges. -/
theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] :
#(⊤ : SimpleGraph V).edgeFinset = (Fintype.card V).choose 2 := by
simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag]
/-- Any graph on `n` vertices has at most `n.choose 2` edges. -/
theorem card_edgeFinset_le_card_choose_two : #G.edgeFinset ≤ (Fintype.card V).choose 2 := by
classical
rw [← card_edgeFinset_top_eq_card_choose_two]
exact card_le_card (edgeFinset_mono le_top)
end EdgeFinset
section FiniteAt
/-!
## Finiteness at a vertex
This section contains definitions and lemmas concerning vertices that
have finitely many adjacent vertices. We denote this condition by
`Fintype (G.neighborSet v)`.
We define `G.neighborFinset v` to be the `Finset` version of `G.neighborSet v`.
Use `neighborFinset_eq_filter` to rewrite this definition as a `Finset.filter` expression.
-/
variable (v) [Fintype (G.neighborSet v)]
/-- `G.neighbors v` is the `Finset` version of `G.Adj v` in case `G` is
locally finite at `v`. -/
def neighborFinset : Finset V :=
(G.neighborSet v).toFinset
theorem neighborFinset_def : G.neighborFinset v = (G.neighborSet v).toFinset :=
rfl
@[simp]
theorem mem_neighborFinset (w : V) : w ∈ G.neighborFinset v ↔ G.Adj v w :=
Set.mem_toFinset
theorem not_mem_neighborFinset_self : v ∉ G.neighborFinset v := by simp
theorem neighborFinset_disjoint_singleton : Disjoint (G.neighborFinset v) {v} :=
Finset.disjoint_singleton_right.mpr <| not_mem_neighborFinset_self _ _
theorem singleton_disjoint_neighborFinset : Disjoint {v} (G.neighborFinset v) :=
Finset.disjoint_singleton_left.mpr <| not_mem_neighborFinset_self _ _
/-- `G.degree v` is the number of vertices adjacent to `v`. -/
def degree : ℕ := #(G.neighborFinset v)
@[simp]
theorem card_neighborFinset_eq_degree : #(G.neighborFinset v) = G.degree v := rfl
@[simp]
theorem card_neighborSet_eq_degree : Fintype.card (G.neighborSet v) = G.degree v :=
(Set.toFinset_card _).symm
theorem degree_pos_iff_exists_adj : 0 < G.degree v ↔ ∃ w, G.Adj v w := by
simp only [degree, card_pos, Finset.Nonempty, mem_neighborFinset]
theorem degree_pos_iff_mem_support : 0 < G.degree v ↔ v ∈ G.support := by
rw [G.degree_pos_iff_exists_adj v, mem_support]
theorem degree_eq_zero_iff_not_mem_support : G.degree v = 0 ↔ v ∉ G.support := by
rw [← G.degree_pos_iff_mem_support v, Nat.pos_iff_ne_zero, not_ne_iff]
theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] :
Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by
classical
rw [← card_neighborSet_union_compl_neighborSet G v, Set.toFinset_union]
simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v))]
instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) :=
Fintype.ofEquiv (G.neighborSet v) (G.incidenceSetEquivNeighborSet v).symm
/-- This is the `Finset` version of `incidenceSet`. -/
def incidenceFinset [DecidableEq V] : Finset (Sym2 V) :=
(G.incidenceSet v).toFinset
@[simp]
theorem card_incidenceSet_eq_degree [DecidableEq V] :
Fintype.card (G.incidenceSet v) = G.degree v := by
rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v)]
simp
@[simp]
theorem card_incidenceFinset_eq_degree [DecidableEq V] : #(G.incidenceFinset v) = G.degree v := by
rw [← G.card_incidenceSet_eq_degree]
apply Set.toFinset_card
@[simp]
theorem mem_incidenceFinset [DecidableEq V] (e : Sym2 V) :
e ∈ G.incidenceFinset v ↔ e ∈ G.incidenceSet v :=
Set.mem_toFinset
theorem incidenceFinset_eq_filter [DecidableEq V] [Fintype G.edgeSet] :
G.incidenceFinset v = {e ∈ G.edgeFinset | v ∈ e} := by
ext e
induction e
simp [mk'_mem_incidenceSet_iff]
variable {G v}
/-- If `G ≤ H` then `G.degree v ≤ H.degree v` for any vertex `v`. -/
lemma degree_le_of_le {H : SimpleGraph V} [Fintype (H.neighborSet v)] (hle : G ≤ H) :
G.degree v ≤ H.degree v := by
simp_rw [← card_neighborSet_eq_degree]
exact Set.card_le_card fun v hv => hle hv
end FiniteAt
section LocallyFinite
/-- A graph is locally finite if every vertex has a finite neighbor set. -/
abbrev LocallyFinite :=
∀ v : V, Fintype (G.neighborSet v)
variable [LocallyFinite G]
/-- A locally finite simple graph is regular of degree `d` if every vertex has degree `d`. -/
def IsRegularOfDegree (d : ℕ) : Prop :=
∀ v : V, G.degree v = d
variable {G}
theorem IsRegularOfDegree.degree_eq {d : ℕ} (h : G.IsRegularOfDegree d) (v : V) : G.degree v = d :=
h v
theorem IsRegularOfDegree.compl [Fintype V] [DecidableEq V] {G : SimpleGraph V} [DecidableRel G.Adj]
{k : ℕ} (h : G.IsRegularOfDegree k) : Gᶜ.IsRegularOfDegree (Fintype.card V - 1 - k) := by
intro v
rw [degree_compl, h v]
end LocallyFinite
section Finite
variable [Fintype V]
instance neighborSetFintype [DecidableRel G.Adj] (v : V) : Fintype (G.neighborSet v) :=
@Subtype.fintype _ (· ∈ G.neighborSet v)
(by
simp_rw [mem_neighborSet]
infer_instance)
_
theorem neighborFinset_eq_filter {v : V} [DecidableRel G.Adj] :
G.neighborFinset v = ({w | G.Adj v w} : Finset _) := by ext; simp
theorem neighborFinset_compl [DecidableEq V] [DecidableRel G.Adj] (v : V) :
Gᶜ.neighborFinset v = (G.neighborFinset v)ᶜ \ {v} := by
simp only [neighborFinset, neighborSet_compl, Set.toFinset_diff, Set.toFinset_compl,
Set.toFinset_singleton]
@[simp]
theorem complete_graph_degree [DecidableEq V] (v : V) :
(⊤ : SimpleGraph V).degree v = Fintype.card V - 1 := by
simp_rw [degree, neighborFinset_eq_filter, top_adj, filter_ne]
rw [card_erase_of_mem (mem_univ v), card_univ]
theorem bot_degree (v : V) : (⊥ : SimpleGraph V).degree v = 0 := by
simp_rw [degree, neighborFinset_eq_filter, bot_adj, filter_False]
exact Finset.card_empty
theorem IsRegularOfDegree.top [DecidableEq V] :
(⊤ : SimpleGraph V).IsRegularOfDegree (Fintype.card V - 1) := by
intro v
simp
/-- The minimum degree of all vertices (and `0` if there are no vertices).
The key properties of this are given in `exists_minimal_degree_vertex`, `minDegree_le_degree`
and `le_minDegree_of_forall_le_degree`. -/
def minDegree [DecidableRel G.Adj] : ℕ :=
WithTop.untopD 0 (univ.image fun v => G.degree v).min
/-- There exists a vertex of minimal degree. Note the assumption of being nonempty is necessary, as
the lemma implies there exists a vertex. -/
theorem exists_minimal_degree_vertex [DecidableRel G.Adj] [Nonempty V] :
∃ v, G.minDegree = G.degree v := by
obtain ⟨t, ht : _ = _⟩ := min_of_nonempty (univ_nonempty.image fun v => G.degree v)
obtain ⟨v, _, rfl⟩ := mem_image.mp (mem_of_min ht)
exact ⟨v, by simp [minDegree, ht]⟩
/-- The minimum degree in the graph is at most the degree of any particular vertex. -/
theorem minDegree_le_degree [DecidableRel G.Adj] (v : V) : G.minDegree ≤ G.degree v := by
obtain ⟨t, ht⟩ := Finset.min_of_mem (mem_image_of_mem (fun v => G.degree v) (mem_univ v))
have := Finset.min_le_of_eq (mem_image_of_mem _ (mem_univ v)) ht
rwa [minDegree, ht]
/-- In a nonempty graph, if `k` is at most the degree of every vertex, it is at most the minimum
degree. Note the assumption that the graph is nonempty is necessary as long as `G.minDegree` is
defined to be a natural. -/
theorem le_minDegree_of_forall_le_degree [DecidableRel G.Adj] [Nonempty V] (k : ℕ)
(h : ∀ v, k ≤ G.degree v) : k ≤ G.minDegree := by
rcases G.exists_minimal_degree_vertex with ⟨v, hv⟩
rw [hv]
apply h
/-- If there are no vertices then the `minDegree` is zero. -/
@[simp]
lemma minDegree_of_isEmpty [DecidableRel G.Adj] [IsEmpty V] : G.minDegree = 0 := by
rw [minDegree, WithTop.untopD_eq_self_iff]
simp
variable {G} in
/-- If `G` is a subgraph of `H` then `G.minDegree ≤ H.minDegree`. -/
lemma minDegree_le_minDegree {H : SimpleGraph V} [DecidableRel G.Adj] [DecidableRel H.Adj]
(hle : G ≤ H) : G.minDegree ≤ H.minDegree := by
by_cases hne : Nonempty V
· apply le_minDegree_of_forall_le_degree
exact fun v ↦ (G.minDegree_le_degree v).trans (G.degree_le_of_le hle)
· rw [not_nonempty_iff] at hne
simp
/-- The maximum degree of all vertices (and `0` if there are no vertices).
The key properties of this are given in `exists_maximal_degree_vertex`, `degree_le_maxDegree`
and `maxDegree_le_of_forall_degree_le`. -/
def maxDegree [DecidableRel G.Adj] : ℕ :=
Option.getD (univ.image fun v => G.degree v).max 0
/-- There exists a vertex of maximal degree. Note the assumption of being nonempty is necessary, as
the lemma implies there exists a vertex. -/
theorem exists_maximal_degree_vertex [DecidableRel G.Adj] [Nonempty V] :
∃ v, G.maxDegree = G.degree v := by
obtain ⟨t, ht⟩ := max_of_nonempty (univ_nonempty.image fun v => G.degree v)
have ht₂ := mem_of_max ht
simp only [mem_image, mem_univ, exists_prop_of_true] at ht₂
rcases ht₂ with ⟨v, _, rfl⟩
refine ⟨v, ?_⟩
rw [maxDegree, ht]
rfl
/-- The maximum degree in the graph is at least the degree of any particular vertex. -/
theorem degree_le_maxDegree [DecidableRel G.Adj] (v : V) : G.degree v ≤ G.maxDegree := by
obtain ⟨t, ht : _ = _⟩ := Finset.max_of_mem (mem_image_of_mem (fun v => G.degree v) (mem_univ v))
have := Finset.le_max_of_eq (mem_image_of_mem _ (mem_univ v)) ht
rwa [maxDegree, ht]
/-- In a graph, if `k` is at least the degree of every vertex, then it is at least the maximum
degree. -/
theorem maxDegree_le_of_forall_degree_le [DecidableRel G.Adj] (k : ℕ) (h : ∀ v, G.degree v ≤ k) :
G.maxDegree ≤ k := by
by_cases hV : (univ : Finset V).Nonempty
· haveI : Nonempty V := univ_nonempty_iff.mp hV
obtain ⟨v, hv⟩ := G.exists_maximal_degree_vertex
rw [hv]
apply h
· rw [not_nonempty_iff_eq_empty] at hV
rw [maxDegree, hV, image_empty]
exact k.zero_le
theorem degree_lt_card_verts [DecidableRel G.Adj] (v : V) : G.degree v < Fintype.card V := by
classical
apply Finset.card_lt_card
rw [Finset.ssubset_iff]
exact ⟨v, by simp, Finset.subset_univ _⟩
/--
The maximum degree of a nonempty graph is less than the number of vertices. Note that the assumption
that `V` is nonempty is necessary, as otherwise this would assert the existence of a
natural number less than zero. -/
theorem maxDegree_lt_card_verts [DecidableRel G.Adj] [Nonempty V] :
G.maxDegree < Fintype.card V := by
obtain ⟨v, hv⟩ := G.exists_maximal_degree_vertex
rw [hv]
apply G.degree_lt_card_verts v
theorem card_commonNeighbors_le_degree_left [DecidableRel G.Adj] (v w : V) :
Fintype.card (G.commonNeighbors v w) ≤ G.degree v := by
rw [← card_neighborSet_eq_degree]
exact Set.card_le_card Set.inter_subset_left
theorem card_commonNeighbors_le_degree_right [DecidableRel G.Adj] (v w : V) :
Fintype.card (G.commonNeighbors v w) ≤ G.degree w := by
simp_rw [commonNeighbors_symm _ v w, card_commonNeighbors_le_degree_left]
theorem card_commonNeighbors_lt_card_verts [DecidableRel G.Adj] (v w : V) :
Fintype.card (G.commonNeighbors v w) < Fintype.card V :=
Nat.lt_of_le_of_lt (G.card_commonNeighbors_le_degree_left _ _) (G.degree_lt_card_verts v)
/-- If the condition `G.Adj v w` fails, then `card_commonNeighbors_le_degree` is
the best we can do in general. -/
theorem Adj.card_commonNeighbors_lt_degree {G : SimpleGraph V} [DecidableRel G.Adj] {v w : V}
(h : G.Adj v w) : Fintype.card (G.commonNeighbors v w) < G.degree v := by
classical
rw [← Set.toFinset_card]
apply Finset.card_lt_card
rw [Finset.ssubset_iff]
use w
constructor
· rw [Set.mem_toFinset]
apply not_mem_commonNeighbors_right
· rw [Finset.insert_subset_iff]
constructor
· simpa
· rw [neighborFinset, Set.toFinset_subset_toFinset]
exact G.commonNeighbors_subset_neighborSet_left _ _
theorem card_commonNeighbors_top [DecidableEq V] {v w : V} (h : v ≠ w) :
Fintype.card ((⊤ : SimpleGraph V).commonNeighbors v w) = Fintype.card V - 2 := by
simp only [commonNeighbors_top_eq, ← Set.toFinset_card, Set.toFinset_diff]
rw [Finset.card_sdiff]
· simp [Finset.card_univ, h]
· simp only [Set.toFinset_subset_toFinset, Set.subset_univ]
end Finite
section Support
variable {s : Set V} [DecidablePred (· ∈ s)] [Fintype V] {G : SimpleGraph V} [DecidableRel G.Adj]
lemma edgeFinset_subset_sym2_of_support_subset (h : G.support ⊆ s) :
G.edgeFinset ⊆ s.toFinset.sym2 := by
| simp_rw [subset_iff, Sym2.forall,
mem_edgeFinset, mem_edgeSet, mk_mem_sym2_iff, Set.mem_toFinset]
intro _ _ hadj
exact ⟨h ⟨_, hadj⟩, h ⟨_, hadj.symm⟩⟩
| Mathlib/Combinatorics/SimpleGraph/Finite.lean | 431 | 435 |
/-
Copyright (c) 2023 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Algebra.Polynomial.Bivariate
import Mathlib.AlgebraicGeometry.EllipticCurve.Weierstrass
import Mathlib.AlgebraicGeometry.EllipticCurve.VariableChange
/-!
# Affine coordinates for Weierstrass curves
This file defines the type of points on a Weierstrass curve as an inductive, consisting of the point
at infinity and affine points satisfying a Weierstrass equation with a nonsingular condition. This
file also defines the negation and addition operations of the group law for this type, and proves
that they respect the Weierstrass equation and the nonsingular condition. The fact that they form an
abelian group is proven in `Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean`.
## Mathematical background
Let `W` be a Weierstrass curve over a field `F` with coefficients `aᵢ`. An *affine point*
on `W` is a tuple `(x, y)` of elements in `R` satisfying the *Weierstrass equation* `W(X, Y) = 0` in
*affine coordinates*, where `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)`. It is
*nonsingular* if its partial derivatives `W_X(x, y)` and `W_Y(x, y)` do not vanish simultaneously.
The nonsingular affine points on `W` can be given negation and addition operations defined by a
secant-and-tangent process.
* Given a nonsingular affine point `P`, its *negation* `-P` is defined to be the unique third
nonsingular point of intersection between `W` and the vertical line through `P`.
Explicitly, if `P` is `(x, y)`, then `-P` is `(x, -y - a₁x - a₃)`.
* Given two nonsingular affine points `P` and `Q`, their *addition* `P + Q` is defined to be the
negation of the unique third nonsingular point of intersection between `W` and the line `L`
through `P` and `Q`. Explicitly, let `P` be `(x₁, y₁)` and let `Q` be `(x₂, y₂)`.
* If `x₁ = x₂` and `y₁ = -y₂ - a₁x₂ - a₃`, then `L` is vertical.
* If `x₁ = x₂` and `y₁ ≠ -y₂ - a₁x₂ - a₃`, then `L` is the tangent of `W` at `P = Q`, and has
slope `ℓ := (3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`.
* Otherwise `x₁ ≠ x₂`, then `L` is the secant of `W` through `P` and `Q`, and has slope
`ℓ := (y₁ - y₂) / (x₁ - x₂)`.
In the last two cases, the `X`-coordinate of `P + Q` is then the unique third solution of the
equation obtained by substituting the line `Y = ℓ(X - x₁) + y₁` into the Weierstrass equation,
and can be written down explicitly as `x := ℓ² + a₁ℓ - a₂ - x₁ - x₂` by inspecting the
coefficients of `X²`. The `Y`-coordinate of `P + Q`, after applying the final negation that maps
`Y` to `-Y - a₁X - a₃`, is precisely `y := -(ℓ(x - x₁) + y₁) - a₁x - a₃`.
The type of nonsingular points `W⟮F⟯` in affine coordinates is an inductive, consisting of the
unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. Then `W⟮F⟯` can be endowed with
a group law, with `𝓞` as the identity nonsingular point, which is uniquely determined by these
formulae.
## Main definitions
* `WeierstrassCurve.Affine.Equation`: the Weierstrass equation of an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Nonsingular`: the nonsingular condition on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point`: a nonsingular rational point on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point.neg`: the negation operation on an affine Weierstrass curve.
* `WeierstrassCurve.Affine.Point.add`: the addition operation on an affine Weierstrass curve.
## Main statements
* `WeierstrassCurve.Affine.equation_neg`: negation preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.equation_add`: addition preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.nonsingular_neg`: negation preserves the nonsingular condition.
* `WeierstrassCurve.Affine.nonsingular_add`: addition preserves the nonsingular condition.
* `WeierstrassCurve.Affine.nonsingular_of_Δ_ne_zero`: an affine Weierstrass curve is nonsingular at
every point if its discriminant is non-zero.
* `WeierstrassCurve.Affine.nonsingular`: an affine elliptic curve is nonsingular at every point.
## Notations
* `W⟮K⟯`: the group of nonsingular rational points on `W` base changed to `K`.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, rational point, affine coordinates
-/
open Polynomial
open scoped Polynomial.Bivariate
local macro "C_simp" : tactic =>
`(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow])
local macro "derivative_simp" : tactic =>
`(tactic| simp only [derivative_C, derivative_X, derivative_X_pow, derivative_neg, derivative_add,
derivative_sub, derivative_mul, derivative_sq])
local macro "eval_simp" : tactic =>
`(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow, evalEval])
local macro "map_simp" : tactic =>
`(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀,
Polynomial.map_ofNat, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub,
Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom,
WeierstrassCurve.map])
universe r s u v w
/-! ## Weierstrass curves -/
namespace WeierstrassCurve
variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} {L : Type w}
variable (R) in
/-- An abbreviation for a Weierstrass curve in affine coordinates. -/
abbrev Affine : Type r :=
WeierstrassCurve R
/-- The conversion from a Weierstrass curve to affine coordinates. -/
abbrev toAffine (W : WeierstrassCurve R) : Affine R :=
W
namespace Affine
variable [CommRing R] [CommRing S] [CommRing A] [CommRing B] [Field F] [Field K] [Field L]
{W' : Affine R} {W : Affine F}
section Equation
/-! ### Weierstrass equations -/
variable (W') in
/-- The polynomial `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)` associated to a Weierstrass
curve `W` over a ring `R` in affine coordinates.
For ease of polynomial manipulation, this is represented as a term of type `R[X][X]`, where the
inner variable represents `X` and the outer variable represents `Y`. For clarity, the alternative
notations `Y` and `R[X][Y]` are provided in the `Polynomial.Bivariate` scope to represent the outer
variable and the bivariate polynomial ring `R[X][X]` respectively. -/
noncomputable def polynomial : R[X][Y] :=
Y ^ 2 + C (C W'.a₁ * X + C W'.a₃) * Y - C (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆)
lemma polynomial_eq : W'.polynomial = Cubic.toPoly
⟨0, 1, Cubic.toPoly ⟨0, 0, W'.a₁, W'.a₃⟩, Cubic.toPoly ⟨-1, -W'.a₂, -W'.a₄, -W'.a₆⟩⟩ := by
simp only [polynomial, Cubic.toPoly]
C_simp
ring1
lemma polynomial_ne_zero [Nontrivial R] : W'.polynomial ≠ 0 := by
rw [polynomial_eq]
exact Cubic.ne_zero_of_b_ne_zero one_ne_zero
@[simp]
lemma degree_polynomial [Nontrivial R] : W'.polynomial.degree = 2 := by
rw [polynomial_eq]
exact Cubic.degree_of_b_ne_zero' one_ne_zero
@[simp]
lemma natDegree_polynomial [Nontrivial R] : W'.polynomial.natDegree = 2 := by
rw [polynomial_eq]
exact Cubic.natDegree_of_b_ne_zero' one_ne_zero
lemma monic_polynomial : W'.polynomial.Monic := by
nontriviality R
simpa only [polynomial_eq] using Cubic.monic_of_b_eq_one'
lemma irreducible_polynomial [IsDomain R] : Irreducible W'.polynomial := by
by_contra h
rcases (monic_polynomial.not_irreducible_iff_exists_add_mul_eq_coeff natDegree_polynomial).mp h
with ⟨f, g, h0, h1⟩
simp only [polynomial_eq, Cubic.coeff_eq_c, Cubic.coeff_eq_d] at h0 h1
apply_fun degree at h0 h1
rw [Cubic.degree_of_a_ne_zero' <| neg_ne_zero.mpr <| one_ne_zero' R, degree_mul] at h0
apply (h1.symm.le.trans Cubic.degree_of_b_eq_zero').not_lt
rcases Nat.WithBot.add_eq_three_iff.mp h0.symm with h | h | h | h
iterate 2 rw [degree_add_eq_right_of_degree_lt] <;> simp only [h] <;> decide
iterate 2 rw [degree_add_eq_left_of_degree_lt] <;> simp only [h] <;> decide
lemma evalEval_polynomial (x y : R) : W'.polynomial.evalEval x y =
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) := by
simp only [polynomial]
eval_simp
rw [add_mul, ← add_assoc]
@[simp]
lemma evalEval_polynomial_zero : W'.polynomial.evalEval 0 0 = -W'.a₆ := by
simp only [evalEval_polynomial, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _]
variable (W') in
/-- The proposition that an affine point `(x, y)` lies in a Weierstrass curve `W`.
In other words, it satisfies the Weierstrass equation `W(X, Y) = 0`. -/
def Equation (x y : R) : Prop :=
W'.polynomial.evalEval x y = 0
lemma equation_iff' (x y : R) : W'.Equation x y ↔
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) = 0 := by
rw [Equation, evalEval_polynomial]
lemma equation_iff (x y : R) : W'.Equation x y ↔
y ^ 2 + W'.a₁ * x * y + W'.a₃ * y = x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆ := by
rw [equation_iff', sub_eq_zero]
@[simp]
lemma equation_zero : W'.Equation 0 0 ↔ W'.a₆ = 0 := by
rw [Equation, evalEval_polynomial_zero, neg_eq_zero]
lemma equation_iff_variableChange (x y : R) :
W'.Equation x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Equation 0 0 := by
rw [equation_iff', ← neg_eq_zero, equation_zero, variableChange_a₆, inv_one, Units.val_one]
congr! 1
ring1
end Equation
section Nonsingular
/-! ### Nonsingular Weierstrass equations -/
variable (W') in
/-- The partial derivative `W_X(X, Y)` with respect to `X` of the polynomial `W(X, Y)` associated to
a Weierstrass curve `W` in affine coordinates. -/
-- TODO: define this in terms of `Polynomial.derivative`.
noncomputable def polynomialX : R[X][Y] :=
C (C W'.a₁) * Y - C (C 3 * X ^ 2 + C (2 * W'.a₂) * X + C W'.a₄)
lemma evalEval_polynomialX (x y : R) :
W'.polynomialX.evalEval x y = W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) := by
simp only [polynomialX]
eval_simp
@[simp]
lemma evalEval_polynomialX_zero : W'.polynomialX.evalEval 0 0 = -W'.a₄ := by
simp only [evalEval_polynomialX, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _]
variable (W') in
/-- The partial derivative `W_Y(X, Y)` with respect to `Y` of the polynomial `W(X, Y)` associated to
a Weierstrass curve `W` in affine coordinates. -/
-- TODO: define this in terms of `Polynomial.derivative`.
noncomputable def polynomialY : R[X][Y] :=
C (C 2) * Y + C (C W'.a₁ * X + C W'.a₃)
lemma evalEval_polynomialY (x y : R) : W'.polynomialY.evalEval x y = 2 * y + W'.a₁ * x + W'.a₃ := by
simp only [polynomialY]
eval_simp
rw [← add_assoc]
@[simp]
lemma evalEval_polynomialY_zero : W'.polynomialY.evalEval 0 0 = W'.a₃ := by
simp only [evalEval_polynomialY, zero_add, mul_zero]
variable (W') in
/-- The proposition that an affine point `(x, y)` on a Weierstrass curve `W` is nonsingular.
In other words, either `W_X(x, y) ≠ 0` or `W_Y(x, y) ≠ 0`.
Note that this definition is only mathematically accurate for fields. -/
-- TODO: generalise this definition to be mathematically accurate for a larger class of rings.
def Nonsingular (x y : R) : Prop :=
W'.Equation x y ∧ (W'.polynomialX.evalEval x y ≠ 0 ∨ W'.polynomialY.evalEval x y ≠ 0)
lemma nonsingular_iff' (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧
(W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) ≠ 0 ∨ 2 * y + W'.a₁ * x + W'.a₃ ≠ 0) := by
rw [Nonsingular, equation_iff', evalEval_polynomialX, evalEval_polynomialY]
lemma nonsingular_iff (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧
(W'.a₁ * y ≠ 3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄ ∨ y ≠ -y - W'.a₁ * x - W'.a₃) := by
rw [nonsingular_iff', sub_ne_zero, ← sub_ne_zero (a := y)]
congr! 3
ring1
@[simp]
lemma nonsingular_zero : W'.Nonsingular 0 0 ↔ W'.a₆ = 0 ∧ (W'.a₃ ≠ 0 ∨ W'.a₄ ≠ 0) := by
rw [Nonsingular, equation_zero, evalEval_polynomialX_zero, neg_ne_zero, evalEval_polynomialY_zero,
or_comm]
lemma nonsingular_iff_variableChange (x y : R) :
W'.Nonsingular x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Nonsingular 0 0 := by
rw [nonsingular_iff', equation_iff_variableChange, equation_zero, ← neg_ne_zero, or_comm,
nonsingular_zero, variableChange_a₃, variableChange_a₄, inv_one, Units.val_one]
simp only [variableChange_def]
congr! 3 <;> ring1
private lemma equation_zero_iff_nonsingular_zero_of_Δ_ne_zero (hΔ : W'.Δ ≠ 0) :
W'.Equation 0 0 ↔ W'.Nonsingular 0 0 := by
simp only [equation_zero, nonsingular_zero, iff_self_and]
contrapose! hΔ
simp only [b₂, b₄, b₆, b₈, Δ, hΔ]
ring1
/-- A Weierstrass curve is nonsingular at every point if its discriminant is non-zero. -/
lemma equation_iff_nonsingular_of_Δ_ne_zero {x y : R} (hΔ : W'.Δ ≠ 0) :
W'.Equation x y ↔ W'.Nonsingular x y := by
rw [equation_iff_variableChange, nonsingular_iff_variableChange,
equation_zero_iff_nonsingular_zero_of_Δ_ne_zero <| by
rwa [variableChange_Δ, inv_one, Units.val_one, one_pow, one_mul]]
/-- An elliptic curve is nonsingular at every point. -/
lemma equation_iff_nonsingular [Nontrivial R] [W'.IsElliptic] {x y : R} :
W'.toAffine.Equation x y ↔ W'.toAffine.Nonsingular x y :=
W'.toAffine.equation_iff_nonsingular_of_Δ_ne_zero <| W'.coe_Δ' ▸ W'.Δ'.ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular_zero_of_Δ_ne_zero :=
equation_iff_nonsingular_of_Δ_ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular_of_Δ_ne_zero :=
equation_iff_nonsingular_of_Δ_ne_zero
@[deprecated (since := "2025-03-01")] alias nonsingular := equation_iff_nonsingular
end Nonsingular
section Ring
/-! ### Group operation polynomials over a ring -/
variable (W') in
/-- The negation polynomial `-Y - a₁X - a₃` associated to the negation of a nonsingular affine point
on a Weierstrass curve. -/
noncomputable def negPolynomial : R[X][Y] :=
-(Y : R[X][Y]) - C (C W'.a₁ * X + C W'.a₃)
lemma Y_sub_polynomialY : Y - W'.polynomialY = W'.negPolynomial := by
rw [polynomialY, negPolynomial]
C_simp
ring1
lemma Y_sub_negPolynomial : Y - W'.negPolynomial = W'.polynomialY := by
rw [← Y_sub_polynomialY, sub_sub_cancel]
variable (W') in
/-- The `Y`-coordinate of `-(x, y)` for a nonsingular affine point `(x, y)` on a Weierstrass curve
`W`.
This depends on `W`, and has argument order: `x`, `y`. -/
@[simp]
def negY (x y : R) : R :=
-y - W'.a₁ * x - W'.a₃
lemma negY_negY (x y : R) : W'.negY x (W'.negY x y) = y := by
simp only [negY]
ring1
lemma evalEval_negPolynomial (x y : R) : W'.negPolynomial.evalEval x y = W'.negY x y := by
rw [negY, sub_sub, negPolynomial]
eval_simp
@[deprecated (since := "2025-03-05")] alias eval_negPolynomial := evalEval_negPolynomial
/-- The line polynomial `ℓ(X - x) + y` associated to the line `Y = ℓ(X - x) + y` that passes through
a nonsingular affine point `(x, y)` on a Weierstrass curve `W` with a slope of `ℓ`.
This does not depend on `W`, and has argument order: `x`, `y`, `ℓ`. -/
noncomputable def linePolynomial (x y ℓ : R) : R[X] :=
C ℓ * (X - C x) + C y
variable (W') in
/-- The addition polynomial obtained by substituting the line `Y = ℓ(X - x) + y` into the polynomial
`W(X, Y)` associated to a Weierstrass curve `W`. If such a line intersects `W` at another
nonsingular affine point `(x', y')` on `W`, then the roots of this polynomial are precisely `x`,
`x'`, and the `X`-coordinate of the addition of `(x, y)` and `(x', y')`.
This depends on `W`, and has argument order: `x`, `y`, `ℓ`. -/
noncomputable def addPolynomial (x y ℓ : R) : R[X] :=
W'.polynomial.eval <| linePolynomial x y ℓ
lemma C_addPolynomial (x y ℓ : R) : C (W'.addPolynomial x y ℓ) =
(Y - C (linePolynomial x y ℓ)) * (W'.negPolynomial - C (linePolynomial x y ℓ)) +
W'.polynomial := by
rw [addPolynomial, linePolynomial, polynomial, negPolynomial]
eval_simp
C_simp
ring1
lemma addPolynomial_eq (x y ℓ : R) : W'.addPolynomial x y ℓ = -Cubic.toPoly
⟨1, -ℓ ^ 2 - W'.a₁ * ℓ + W'.a₂,
2 * x * ℓ ^ 2 + (W'.a₁ * x - 2 * y - W'.a₃) * ℓ + (-W'.a₁ * y + W'.a₄),
-x ^ 2 * ℓ ^ 2 + (2 * x * y + W'.a₃ * x) * ℓ - (y ^ 2 + W'.a₃ * y - W'.a₆)⟩ := by
rw [addPolynomial, linePolynomial, polynomial, Cubic.toPoly]
eval_simp
C_simp
ring1
variable (W') in
/-- The `X`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `ℓ`. -/
@[simp]
def addX (x₁ x₂ ℓ : R) : R :=
ℓ ^ 2 + W'.a₁ * ℓ - W'.a₂ - x₁ - x₂
variable (W') in
/-- The `Y`-coordinate of `-((x₁, y₁) + (x₂, y₂))` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/
@[simp]
def negAddY (x₁ x₂ y₁ ℓ : R) : R :=
ℓ * (W'.addX x₁ x₂ ℓ - x₁) + y₁
variable (W') in
/-- The `Y`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and
`(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/
@[simp]
def addY (x₁ x₂ y₁ ℓ : R) : R :=
W'.negY (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ)
lemma equation_neg (x y : R) : W'.Equation x (W'.negY x y) ↔ W'.Equation x y := by
rw [equation_iff, equation_iff, negY]
congr! 1
ring1
@[deprecated (since := "2025-02-01")] alias equation_neg_of := equation_neg
@[deprecated (since := "2025-02-01")] alias equation_neg_iff := equation_neg
lemma nonsingular_neg (x y : R) : W'.Nonsingular x (W'.negY x y) ↔ W'.Nonsingular x y := by
rw [nonsingular_iff, equation_neg, ← negY, negY_negY, ← @ne_comm _ y, nonsingular_iff]
exact and_congr_right' <| (iff_congr not_and_or.symm not_and_or.symm).mpr <|
not_congr <| and_congr_left fun h => by rw [← h]
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_of := nonsingular_neg
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_iff := nonsingular_neg
lemma equation_add_iff (x₁ x₂ y₁ ℓ : R) : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) ↔
(W'.addPolynomial x₁ y₁ ℓ).eval (W'.addX x₁ x₂ ℓ) = 0 := by
rw [Equation, negAddY, addPolynomial, linePolynomial, polynomial]
eval_simp
lemma nonsingular_negAdd_of_eval_derivative_ne_zero {x₁ x₂ y₁ ℓ : R}
(hx' : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ))
(hx : (W'.addPolynomial x₁ y₁ ℓ).derivative.eval (W'.addX x₁ x₂ ℓ) ≠ 0) :
W'.Nonsingular (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) := by
rw [Nonsingular, and_iff_right hx', negAddY, polynomialX, polynomialY]
eval_simp
contrapose! hx
rw [addPolynomial, linePolynomial, polynomial]
eval_simp
derivative_simp
simp only [zero_add, add_zero, sub_zero, zero_mul, mul_one]
eval_simp
linear_combination (norm := (norm_num1; ring1)) hx.left + ℓ * hx.right
end Ring
section Field
/-! ### Group operation polynomials over a field -/
open Classical in
variable (W) in
/-- The slope of the line through two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a
Weierstrass curve `W`.
If `x₁ ≠ x₂`, then this line is the secant of `W` through `(x₁, y₁)` and `(x₂, y₂)`, and has slope
`(y₁ - y₂) / (x₁ - x₂)`. Otherwise, if `y₁ ≠ -y₁ - a₁x₁ - a₃`, then this line is the tangent of `W`
at `(x₁, y₁) = (x₂, y₂)`, and has slope `(3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. Otherwise,
this line is vertical, in which case this returns the value `0`.
This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `y₂`. -/
noncomputable def slope (x₁ x₂ y₁ y₂ : F) : F :=
if x₁ = x₂ then if y₁ = W.negY x₂ y₂ then 0
else (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁)
else (y₁ - y₂) / (x₁ - x₂)
@[simp]
lemma slope_of_Y_eq {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ = 0 := by
rw [slope, if_pos hx, if_pos hy]
@[simp]
lemma slope_of_Y_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ =
(3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) := by
rw [slope, if_pos hx, if_neg hy]
@[simp]
lemma slope_of_X_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ ≠ x₂) :
W.slope x₁ x₂ y₁ y₂ = (y₁ - y₂) / (x₁ - x₂) := by
rw [slope, if_neg hx]
lemma slope_of_Y_ne_eq_evalEval {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) :
W.slope x₁ x₂ y₁ y₂ = -W.polynomialX.evalEval x₁ y₁ / W.polynomialY.evalEval x₁ y₁ := by
rw [slope_of_Y_ne hx hy, evalEval_polynomialX, neg_sub]
congr 1
rw [negY, evalEval_polynomialY]
ring1
@[deprecated (since := "2025-03-05")] alias slope_of_Y_ne_eq_eval := slope_of_Y_ne_eq_evalEval
lemma Y_eq_of_X_eq {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hx : x₁ = x₂) : y₁ = y₂ ∨ y₁ = W.negY x₂ y₂ := by
rw [equation_iff] at h₁ h₂
rw [← sub_eq_zero, ← sub_eq_zero (a := y₁), ← mul_eq_zero, negY]
linear_combination (norm := (rw [hx]; ring1)) h₁ - h₂
lemma Y_eq_of_Y_ne {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hx : x₁ = x₂)
(hy : y₁ ≠ W.negY x₂ y₂) : y₁ = y₂ :=
(Y_eq_of_X_eq h₁ h₂ hx).resolve_right hy
lemma addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.addPolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂) =
-((X - C x₁) * (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_eq, neg_inj, Cubic.prod_X_sub_C_eq, Cubic.toPoly_injective]
by_cases hx : x₁ = x₂
· have hy : y₁ ≠ W.negY x₂ y₂ := fun h => hxy ⟨hx, h⟩
rcases hx, Y_eq_of_Y_ne h₁ h₂ hx hy with ⟨rfl, rfl⟩
rw [equation_iff] at h₁ h₂
rw [slope_of_Y_ne rfl hy]
rw [negY, ← sub_ne_zero] at hy
ext
· rfl
· simp only [addX]
ring1
· field_simp [hy]
ring1
· linear_combination (norm := (field_simp [hy]; ring1)) -h₁
· rw [equation_iff] at h₁ h₂
rw [slope_of_X_ne hx]
rw [← sub_eq_zero] at hx
ext
· rfl
· simp only [addX]
ring1
· apply mul_right_injective₀ hx
linear_combination (norm := (field_simp [hx]; ring1)) h₂ - h₁
· apply mul_right_injective₀ hx
linear_combination (norm := (field_simp [hx]; ring1)) x₂ * h₁ - x₁ * h₂
/-- The negated addition of two affine points in `W` on a sloped line lies in `W`. -/
lemma equation_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Equation
(W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
rw [equation_add_iff, addPolynomial_slope h₁ h₂ hxy]
eval_simp
rw [neg_eq_zero, sub_self, mul_zero]
/-- The addition of two affine points in `W` on a sloped line lies in `W`. -/
lemma equation_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) :=
(equation_neg ..).mpr <| equation_negAdd h₁ h₂ hxy
lemma C_addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : C (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) =
-(C (X - C x₁) * C (X - C x₂) * C (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_slope h₁ h₂ hxy]
map_simp
lemma derivative_addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁)
(h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
derivative (W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) =
-((X - C x₁) * (X - C x₂) + (X - C x₁) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)) +
(X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by
rw [addPolynomial_slope h₁ h₂ hxy]
derivative_simp
ring1
/-- The negated addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/
lemma nonsingular_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Nonsingular
(W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
by_cases hx₁ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₁
· rwa [negAddY, hx₁, sub_self, mul_zero, zero_add]
· by_cases hx₂ : W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = x₂
· by_cases hx : x₁ = x₂
· subst hx
contradiction
· rwa [negAddY, ← neg_sub, mul_neg, hx₂, slope_of_X_ne hx,
div_mul_cancel₀ _ <| sub_ne_zero_of_ne hx, neg_sub, sub_add_cancel]
· apply nonsingular_negAdd_of_eval_derivative_ne_zero <| equation_negAdd h₁.left h₂.left hxy
rw [derivative_addPolynomial_slope h₁.left h₂.left hxy]
eval_simp
simp only [neg_ne_zero, sub_self, mul_zero, add_zero]
exact mul_ne_zero (sub_ne_zero_of_ne hx₁) (sub_ne_zero_of_ne hx₂)
/-- The addition of two nonsingular affine points in `W` on a sloped line is nonsingular. -/
lemma nonsingular_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂)
(hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) :
W.Nonsingular (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) :=
(nonsingular_neg ..).mpr <| nonsingular_negAdd h₁ h₂ hxy
/-- The formula `x(P₁ + P₂) = x(P₁ - P₂) - ψ(P₁)ψ(P₂) / (x(P₂) - x(P₁))²`,
where `ψ(x,y) = 2y + a₁x + a₃`. -/
lemma addX_eq_addX_negY_sub {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) = W.addX x₁ x₂ (W.slope x₁ x₂ y₁ <| W.negY x₂ y₂) -
(y₁ - W.negY x₁ y₁) * (y₂ - W.negY x₂ y₂) / (x₂ - x₁) ^ 2 := by
simp_rw [slope_of_X_ne hx, addX, negY, ← neg_sub x₁, neg_sq]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `y(P₁)(x(P₂) - x(P₃)) + y(P₂)(x(P₃) - x(P₁)) + y(P₃)(x(P₁) - x(P₂)) = 0`,
assuming that `P₁ + P₂ + P₃ = O`. -/
lemma cyclic_sum_Y_mul_X_sub_X {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)
y₁ * (x₂ - x₃) + y₂ * (x₃ - x₁) + W.negAddY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂) * (x₁ - x₂) = 0 := by
simp_rw [slope_of_X_ne hx, negAddY, addX]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `ψ(P₁ + P₂) = (ψ(P₂)(x(P₁) - x(P₃)) - ψ(P₁)(x(P₂) - x(P₃))) / (x(P₂) - x(P₁))`,
where `ψ(x,y) = 2y + a₁x + a₃`. -/
lemma addY_sub_negY_addY {x₁ x₂ : F} (y₁ y₂ : F) (hx : x₁ ≠ x₂) :
let x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)
let y₃ := W.addY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂)
y₃ - W.negY x₃ y₃ =
((y₂ - W.negY x₂ y₂) * (x₁ - x₃) - (y₁ - W.negY x₁ y₁) * (x₂ - x₃)) / (x₂ - x₁) := by
simp_rw [addY, negY, eq_div_iff (sub_ne_zero.mpr hx.symm)]
linear_combination (norm := ring1) 2 * cyclic_sum_Y_mul_X_sub_X y₁ y₂ hx
end Field
section Group
/-! ### Nonsingular points -/
variable (W') in
/-- A nonsingular point on a Weierstrass curve `W` in affine coordinates. This is either the unique
point at infinity `WeierstrassCurve.Affine.Point.zero` or a nonsingular affine point
`WeierstrassCurve.Affine.Point.some (x, y)` satisfying the Weierstrass equation of `W`. -/
inductive Point
| zero
| some {x y : R} (h : W'.Nonsingular x y)
/-- For an algebraic extension `S` of a ring `R`, the type of nonsingular `S`-points on a
Weierstrass curve `W` over `R` in affine coordinates. -/
scoped notation3:max W' "⟮" S "⟯" => Affine.Point <| baseChange W' S
namespace Point
/-! ### Group operations -/
instance : Inhabited W'.Point :=
⟨.zero⟩
instance : Zero W'.Point :=
⟨.zero⟩
lemma zero_def : 0 = (.zero : W'.Point) :=
rfl
lemma some_ne_zero {x y : R} (h : W'.Nonsingular x y) : Point.some h ≠ 0 := by
rintro (_ | _)
/-- The negation of a nonsingular point on a Weierstrass curve in affine coordinates.
Given a nonsingular point `P` in affine coordinates, use `-P` instead of `neg P`. -/
def neg : W'.Point → W'.Point
| | 0 => 0
| some h => some <| (nonsingular_neg ..).mpr h
instance : Neg W'.Point :=
⟨neg⟩
lemma neg_def (P : W'.Point) : -P = P.neg :=
rfl
| Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean | 645 | 652 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Algebra.Order.Ring.Abs
/-!
# Lemmas about units in `ℤ`, which interact with the order structure.
-/
namespace Int
theorem isUnit_iff_abs_eq {x : ℤ} : IsUnit x ↔ abs x = 1 := by
rw [isUnit_iff_natAbs_eq, abs_eq_natAbs, ← Int.ofNat_one, natCast_inj]
theorem isUnit_sq {a : ℤ} (ha : IsUnit a) : a ^ 2 = 1 := by rw [sq, isUnit_mul_self ha]
@[simp]
theorem units_sq (u : ℤˣ) : u ^ 2 = 1 := by
rw [Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one, isUnit_sq u.isUnit]
alias units_pow_two := units_sq
@[simp]
theorem units_mul_self (u : ℤˣ) : u * u = 1 := by rw [← sq, units_sq]
@[simp]
theorem units_inv_eq_self (u : ℤˣ) : u⁻¹ = u := by rw [inv_eq_iff_mul_eq_one, units_mul_self]
theorem units_div_eq_mul (u₁ u₂ : ℤˣ) : u₁ / u₂ = u₁ * u₂ := by
| rw [div_eq_mul_inv, units_inv_eq_self]
| Mathlib/Data/Int/Order/Units.lean | 33 | 33 |
/-
Copyright (c) 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Patrick Massot, Floris van Doorn
-/
import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps
import Mathlib.Topology.FiberBundle.Basic
/-!
# Vector bundles
In this file we define (topological) vector bundles.
Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let
`E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a
topological vector space over `R`.
To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the
following properties:
* The bundle trivializations in the trivialization atlas should be continuous linear equivs in the
fibers;
* For any two trivializations `e`, `e'` in the atlas the transition function considered as a map
from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator
norm topology on `F →L[R] F`.
If these conditions are satisfied, we register the typeclass `VectorBundle R F E`.
We define constructions on vector bundles like pullbacks and direct sums in other files.
## Main Definitions
* `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base
set.
* `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the
(continuous) linear fiberwise equivalences a trivialization induces.
* They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt`
and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined
everywhere, since they are extended using the zero function.
* `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only
makes sense on the intersection of their base sets, but is extended outside it using the identity.
* Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over
possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous
(semi)linear map between the chosen fibers of those bundles.
## Implementation notes
The implementation choices in the vector bundle definition are discussed in the "Implementation
notes" section of `Mathlib.Topology.FiberBundle.Basic`.
## Tags
Vector bundle
-/
noncomputable section
open Bundle Set Topology
variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*)
section TopologicalVectorSpace
variable {F E}
variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B]
/-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
namespace Pretrivialization
variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 :=
Pretrivialization.IsLinear.linear b hb
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A fiberwise linear inverse to `e`. -/
@[simps!]
protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by
refine IsLinearMap.mk' (e.symm b) ?_
by_cases hb : b ∈ e.baseSet
· exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦
congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear
· rw [e.coe_symm_of_not_mem hb]
exact (0 : F →ₗ[R] E b).isLinear
/-- A pretrivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
@[simps -fullyApplied]
def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F where
toFun y := (e ⟨b, y⟩).2
invFun := e.symm b
left_inv := e.symm_apply_apply_mk hb
right_inv v := by simp_rw [e.apply_mk_symm hb v]
map_add' v w := (e.linear R hb).map_add v w
map_smul' c v := (e.linear R hb).map_smul c v
open Classical in
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0
variable {R}
open Classical in
theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [Pretrivialization.linearMapAt]
split_ifs <;> rfl
theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
open Classical in
theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
theorem linearMapAt_def_of_not_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).left_inv y
theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).right_inv y
end Pretrivialization
variable [TopologicalSpace (TotalSpace F E)]
/-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
namespace Trivialization
variable (e : Trivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
protected theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun y : E b => (e ⟨b, y⟩).2 :=
Trivialization.IsLinear.linear b hb
instance toPretrivialization.isLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] : e.toPretrivialization.IsLinear R :=
{ (‹_› : e.IsLinear R) with }
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A trivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
def linearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F :=
e.toPretrivialization.linearEquivAt R b hb
variable {R}
@[simp]
theorem linearEquivAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : E b) : e.linearEquivAt R b hb v = (e ⟨b, v⟩).2 :=
rfl
@[simp]
theorem linearEquivAt_symm_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : F) : (e.linearEquivAt R b hb).symm v = e.symm b v :=
rfl
variable (R) in
/-- A fiberwise linear inverse to `e`. -/
protected def symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b :=
e.toPretrivialization.symmₗ R b
theorem coe_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.symmₗ R b) = e.symm b :=
rfl
variable (R) in
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
e.toPretrivialization.linearMapAt R b
open Classical in
theorem coe_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 :=
e.toPretrivialization.coe_linearMapAt b
theorem coe_linearMapAt_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
open Classical in
theorem linearMapAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
theorem linearMapAt_def_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
theorem linearMapAt_def_of_not_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem symmₗ_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y :=
e.toPretrivialization.symmₗ_linearMapAt hb y
theorem linearMapAt_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : F) : e.linearMapAt R b (e.symmₗ R b y) = y :=
e.toPretrivialization.linearMapAt_symmₗ hb y
variable (R) in
open Classical in
/-- A coordinate change function between two trivializations, as a continuous linear equivalence.
Defined to be the identity when `b` does not lie in the base set of both trivializations. -/
def coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] (b : B) :
F ≃L[R] F :=
{ toLinearEquiv := if hb : b ∈ e.baseSet ∩ e'.baseSet
then (e.linearEquivAt R b (hb.1 :)).symm.trans (e'.linearEquivAt R b hb.2)
else LinearEquiv.refl R F
continuous_toFun := by
by_cases hb : b ∈ e.baseSet ∩ e'.baseSet
· rw [dif_pos hb]
refine (e'.continuousOn.comp_continuous ?_ ?_).snd
· exact e.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y =>
mk_mem_prod hb.1 (mem_univ y)
· exact fun y => e'.mem_source.mpr hb.2
· rw [dif_neg hb]
exact continuous_id
continuous_invFun := by
by_cases hb : b ∈ e.baseSet ∩ e'.baseSet
· rw [dif_pos hb]
refine (e.continuousOn.comp_continuous ?_ ?_).snd
· exact e'.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y =>
mk_mem_prod hb.2 (mem_univ y)
exact fun y => e.mem_source.mpr hb.1
· rw [dif_neg hb]
exact continuous_id }
theorem coe_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) :
⇑(coordChangeL R e e' b) = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) :=
congr_arg (fun f : F ≃ₗ[R] F ↦ ⇑f) (dif_pos hb)
theorem coe_coordChangeL' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) :
(coordChangeL R e e' b).toLinearEquiv =
(e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) :=
LinearEquiv.coe_injective (coe_coordChangeL _ _ hb)
theorem symm_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e'.baseSet ∩ e.baseSet) : (e.coordChangeL R e' b).symm = e'.coordChangeL R e b := by
apply ContinuousLinearEquiv.toLinearEquiv_injective
rw [coe_coordChangeL' e' e hb, (coordChangeL R e e' b).symm_toLinearEquiv,
coe_coordChangeL' e e' hb.symm, LinearEquiv.trans_symm, LinearEquiv.symm_symm]
theorem coordChangeL_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
coordChangeL R e e' b y = (e' ⟨b, e.symm b y⟩).2 :=
congr_fun (coe_coordChangeL e e' hb) y
theorem mk_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
(b, coordChangeL R e e' b y) = e' ⟨b, e.symm b y⟩ := by
ext
· rw [e.mk_symm hb.1 y, e'.coe_fst', e.proj_symm_apply' hb.1]
rw [e.proj_symm_apply' hb.1]
exact hb.2
· exact e.coordChangeL_apply e' hb y
theorem apply_symm_apply_eq_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R]
[e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) :
e' (e.toPartialHomeomorph.symm (b, v)) = (b, e.coordChangeL R e' b v) := by
rw [e.mk_coordChangeL e' hb, e.mk_symm hb.1]
/-- A version of `Trivialization.coordChangeL_apply` that fully unfolds `coordChange`. The
right-hand side is ugly, but has good definitional properties for specifically defined
trivializations. -/
theorem coordChangeL_apply' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
coordChangeL R e e' b y = (e' (e.toPartialHomeomorph.symm (b, y))).2 := by
rw [e.coordChangeL_apply e' hb, e.mk_symm hb.1]
theorem coordChangeL_symm_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R]
{b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) :
⇑(coordChangeL R e e' b).symm =
(e'.linearEquivAt R b hb.2).symm.trans (e.linearEquivAt R b hb.1) :=
congr_arg LinearEquiv.invFun (dif_pos hb)
end Trivialization
end TopologicalVectorSpace
section
namespace Bundle
/-- The zero section of a vector bundle -/
def zeroSection [∀ x, Zero (E x)] : B → TotalSpace F E := (⟨·, 0⟩)
@[simp, mfld_simps]
theorem zeroSection_proj [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).proj = x :=
rfl
@[simp, mfld_simps]
theorem zeroSection_snd [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).2 = 0 :=
rfl
end Bundle
open Bundle
variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [TopologicalSpace (TotalSpace F E)]
[∀ x, TopologicalSpace (E x)] [FiberBundle F E]
/-- The space `Bundle.TotalSpace F E` (for `E : B → Type*` such that each `E x` is a topological
vector space) has a topological vector space structure with fiber `F` (denoted with
`VectorBundle R F E`) if around every point there is a fiber bundle trivialization which is linear
in the fibers. -/
class VectorBundle : Prop where
trivialization_linear' : ∀ (e : Trivialization F (π F E)) [MemTrivializationAtlas e], e.IsLinear R
continuousOn_coordChange' :
∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'],
ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F)
(e.baseSet ∩ e'.baseSet)
variable {F E}
instance (priority := 100) trivialization_linear [VectorBundle R F E] (e : Trivialization F (π F E))
[MemTrivializationAtlas e] : e.IsLinear R :=
VectorBundle.trivialization_linear' e
theorem continuousOn_coordChange [VectorBundle R F E] (e e' : Trivialization F (π F E))
[MemTrivializationAtlas e] [MemTrivializationAtlas e'] :
ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F)
(e.baseSet ∩ e'.baseSet) :=
VectorBundle.continuousOn_coordChange' e e'
namespace Trivialization
/-- Forward map of `Trivialization.continuousLinearEquivAt` (only propositionally equal),
defined everywhere (`0` outside domain). -/
@[simps -fullyApplied apply]
def continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →L[R] F :=
{ e.linearMapAt R b with
toFun := e.linearMapAt R b -- given explicitly to help `simps`
cont := by
rw [e.coe_linearMapAt b]
classical
refine continuous_if_const _ (fun hb => ?_) fun _ => continuous_zero
exact (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_isInducing F E b).continuous
fun x => e.mem_source.mpr hb).snd }
/-- Backwards map of `Trivialization.continuousLinearEquivAt`, defined everywhere. -/
@[simps -fullyApplied apply]
def symmL (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →L[R] E b :=
{ e.symmₗ R b with
toFun := e.symm b -- given explicitly to help `simps`
cont := by
by_cases hb : b ∈ e.baseSet
· rw [(FiberBundle.totalSpaceMk_isInducing F E b).continuous_iff]
exact e.continuousOn_symm.comp_continuous (.prodMk_right _) fun x ↦
mk_mem_prod hb (mem_univ x)
· refine continuous_zero.congr fun x => (e.symm_apply_of_not_mem hb x).symm }
variable {R}
theorem symmL_continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : E b) : e.symmL R b (e.continuousLinearMapAt R b y) = y :=
e.symmₗ_linearMapAt hb y
theorem continuousLinearMapAt_symmL (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : F) : e.continuousLinearMapAt R b (e.symmL R b y) = y :=
e.linearMapAt_symmₗ hb y
variable (R) in
/-- In a vector bundle, a trivialization in the fiber (which is a priori only linear)
is in fact a continuous linear equiv between the fibers and the model fiber. -/
@[simps -fullyApplied apply symm_apply]
def continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) : E b ≃L[R] F :=
{ e.toPretrivialization.linearEquivAt R b hb with
toFun := fun y => (e ⟨b, y⟩).2 -- given explicitly to help `simps`
invFun := e.symm b -- given explicitly to help `simps`
continuous_toFun := (e.continuousOn.comp_continuous
(FiberBundle.totalSpaceMk_isInducing F E b).continuous fun _ => e.mem_source.mpr hb).snd
continuous_invFun := (e.symmL R b).continuous }
theorem coe_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) :
(e.continuousLinearEquivAt R b hb : E b → F) = e.continuousLinearMapAt R b :=
(e.coe_linearMapAt_of_mem hb).symm
theorem symm_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ((e.continuousLinearEquivAt R b hb).symm : F → E b) = e.symmL R b :=
rfl
@[simp]
theorem continuousLinearEquivAt_apply' (e : Trivialization F (π F E)) [e.IsLinear R]
(x : TotalSpace F E) (hx : x ∈ e.source) :
e.continuousLinearEquivAt R x.proj (e.mem_source.1 hx) x.2 = (e x).2 := rfl
variable (R)
theorem apply_eq_prod_continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (z : E b) : e ⟨b, z⟩ = (b, e.continuousLinearEquivAt R b hb z) := by
ext
· refine e.coe_fst ?_
rw [e.source_eq]
exact hb
· simp only [coe_coe, continuousLinearEquivAt_apply]
protected theorem zeroSection (e : Trivialization F (π F E)) [e.IsLinear R] {x : B}
(hx : x ∈ e.baseSet) : e (zeroSection F E x) = (x, 0) := by
simp_rw [zeroSection, e.apply_eq_prod_continuousLinearEquivAt R x hx 0, map_zero]
variable {R}
theorem symm_apply_eq_mk_continuousLinearEquivAt_symm (e : Trivialization F (π F E)) [e.IsLinear R]
(b : B) (hb : b ∈ e.baseSet) (z : F) :
e.toPartialHomeomorph.symm ⟨b, z⟩ = ⟨b, (e.continuousLinearEquivAt R b hb).symm z⟩ := by
have h : (b, z) ∈ e.target := by
rw [e.target_eq]
exact ⟨hb, mem_univ _⟩
apply e.injOn (e.map_target h)
· simpa only [e.source_eq, mem_preimage]
· simp_rw [e.right_inv h, coe_coe, e.apply_eq_prod_continuousLinearEquivAt R b hb,
ContinuousLinearEquiv.apply_symm_apply]
theorem comp_continuousLinearEquivAt_eq_coord_change (e e' : Trivialization F (π F E))
[e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) :
(e.continuousLinearEquivAt R b hb.1).symm.trans (e'.continuousLinearEquivAt R b hb.2) =
coordChangeL R e e' b := by
ext v
rw [coordChangeL_apply e e' hb]
rfl
end Trivialization
/-! ### Constructing vector bundles -/
variable (B F)
/-- Analogous construction of `FiberBundleCore` for vector bundles. This
construction gives a way to construct vector bundles from a structure registering how
trivialization changes act on fibers. -/
structure VectorBundleCore (ι : Type*) where
baseSet : ι → Set B
isOpen_baseSet : ∀ i, IsOpen (baseSet i)
indexAt : B → ι
mem_baseSet_at : ∀ x, x ∈ baseSet (indexAt x)
coordChange : ι → ι → B → F →L[R] F
coordChange_self : ∀ i, ∀ x ∈ baseSet i, ∀ v, coordChange i i x v = v
continuousOn_coordChange : ∀ i j, ContinuousOn (coordChange i j) (baseSet i ∩ baseSet j)
coordChange_comp : ∀ i j k, ∀ x ∈ baseSet i ∩ baseSet j ∩ baseSet k, ∀ v,
(coordChange j k x) (coordChange i j x v) = coordChange i k x v
/-- The trivial vector bundle core, in which all the changes of coordinates are the
identity. -/
def trivialVectorBundleCore (ι : Type*) [Inhabited ι] : VectorBundleCore R B F ι where
baseSet _ := univ
isOpen_baseSet _ := isOpen_univ
indexAt := default
mem_baseSet_at x := mem_univ x
coordChange _ _ _ := ContinuousLinearMap.id R F
coordChange_self _ _ _ _ := rfl
coordChange_comp _ _ _ _ _ _ := rfl
continuousOn_coordChange _ _ := continuousOn_const
instance (ι : Type*) [Inhabited ι] : Inhabited (VectorBundleCore R B F ι) :=
⟨trivialVectorBundleCore R B F ι⟩
namespace VectorBundleCore
variable {R B F} {ι : Type*}
variable (Z : VectorBundleCore R B F ι)
/-- Natural identification to a `FiberBundleCore`. -/
@[simps (config := mfld_cfg)]
def toFiberBundleCore : FiberBundleCore ι B F :=
{ Z with
coordChange := fun i j b => Z.coordChange i j b
continuousOn_coordChange := fun i j =>
isBoundedBilinearMap_apply.continuous.comp_continuousOn
((Z.continuousOn_coordChange i j).prodMap continuousOn_id) }
-- TODO: restore coercion?
-- instance toFiberBundleCoreCoe : Coe (VectorBundleCore R B F ι) (FiberBundleCore ι B F) :=
| -- ⟨toFiberBundleCore⟩
theorem coordChange_linear_comp (i j k : ι) :
| Mathlib/Topology/VectorBundle/Basic.lean | 514 | 516 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Data.Countable.Small
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Fintype.Powerset
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Set.Countable
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Logic.Small.Set
import Mathlib.Logic.UnivLE
import Mathlib.SetTheory.Cardinal.Order
/-!
# Basic results on cardinal numbers
We provide a collection of basic results on cardinal numbers, in particular focussing on
finite/countable/small types and sets.
## Main definitions
* `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`.
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, aleph,
Cantor's theorem, König's theorem, Konig's theorem
-/
assert_not_exists Field
open List (Vector)
open Function Order Set
noncomputable section
universe u v w v' w'
variable {α β : Type u}
namespace Cardinal
/-! ### Lifting cardinals to a higher universe -/
@[simp]
lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by
rw [← mk_uLift, Cardinal.eq]
constructor
let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x)
have : Function.Bijective f :=
ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective))
exact Equiv.ofBijective f this
-- `simp` can't figure out universe levels: normal form is `lift_mk_shrink'`.
theorem lift_mk_shrink (α : Type u) [Small.{v} α] :
Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α :=
lift_mk_eq.2 ⟨(equivShrink α).symm⟩
@[simp]
theorem lift_mk_shrink' (α : Type u) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α :=
lift_mk_shrink.{u, v, 0} α
@[simp]
theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = #α := by
rw [← lift_umax, lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id]
theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) :
prod f = Cardinal.lift.{u} (∏ i, f i) := by
revert f
refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h)
· intro α β hβ e h f
letI := Fintype.ofEquiv β e.symm
rw [← e.prod_comp f, ← h]
exact mk_congr (e.piCongrLeft _).symm
· intro f
rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one]
· intro α hα h f
rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax.{v, u}, mk_out, ←
Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)]
simp only [lift_id]
/-! ### Basic cardinals -/
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α :=
⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ =>
⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩
@[simp]
theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton :=
le_one_iff_subsingleton.trans s.subsingleton_coe
alias ⟨_, _root_.Set.Subsingleton.cardinalMk_le_one⟩ := mk_le_one_iff_set_subsingleton
@[deprecated (since := "2024-11-10")]
alias _root_.Set.Subsingleton.cardinal_mk_le_one := Set.Subsingleton.cardinalMk_le_one
private theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by
change #(ULift.{u} _) = #(ULift.{u} _) + 1
rw [← mk_option]
simp
/-! ### Order properties -/
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by
rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not]
lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases s.eq_empty_or_nonempty with rfl | hne
· exact Or.inl rfl
· exact Or.inr ⟨sInf s, csInf_mem hne, h⟩
· rcases h with rfl | ⟨a, ha, rfl⟩
· exact Cardinal.sInf_empty
· exact eq_bot_iff.2 (csInf_le' ha)
lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} :
(⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by
simp [iInf, sInf_eq_zero_iff]
/-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/
protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 :=
ciSup_of_empty f
@[simp]
theorem lift_sInf (s : Set Cardinal) : lift.{u, v} (sInf s) = sInf (lift.{u, v} '' s) := by
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp
· exact lift_monotone.map_csInf hs
@[simp]
theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u, v} (iInf f) = ⨅ i, lift.{u, v} (f i) := by
unfold iInf
convert lift_sInf (range f)
simp_rw [← comp_apply (f := lift), range_comp]
end Cardinal
/-! ### Small sets of cardinals -/
namespace Cardinal
instance small_Iic (a : Cardinal.{u}) : Small.{u} (Iic a) := by
rw [← mk_out a]
apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩
rintro ⟨x, hx⟩
simpa using le_mk_iff_exists_set.1 hx
instance small_Iio (a : Cardinal.{u}) : Small.{u} (Iio a) := small_subset Iio_subset_Iic_self
instance small_Icc (a b : Cardinal.{u}) : Small.{u} (Icc a b) := small_subset Icc_subset_Iic_self
instance small_Ico (a b : Cardinal.{u}) : Small.{u} (Ico a b) := small_subset Ico_subset_Iio_self
instance small_Ioc (a b : Cardinal.{u}) : Small.{u} (Ioc a b) := small_subset Ioc_subset_Iic_self
instance small_Ioo (a b : Cardinal.{u}) : Small.{u} (Ioo a b) := small_subset Ioo_subset_Iio_self
/-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/
theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun _ h => ha h) _, by
rintro ⟨ι, ⟨e⟩⟩
use sum.{u, u} fun x ↦ e.symm x
intro a ha
simpa using le_sum (fun x ↦ e.symm x) (e ⟨a, ha⟩)⟩
theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
theorem bddAbove_range {ι : Type*} [Small.{u} ι] (f : ι → Cardinal.{u}) : BddAbove (Set.range f) :=
bddAbove_of_small _
theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}}
(hs : BddAbove s) : BddAbove (f '' s) := by
rw [bddAbove_iff_small] at hs ⊢
exact small_lift _
theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f))
(g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by
rw [range_comp]
exact bddAbove_image g hf
/-- The type of cardinals in universe `u` is not `Small.{u}`. This is a version of the Burali-Forti
paradox. -/
theorem _root_.not_small_cardinal : ¬ Small.{u} Cardinal.{max u v} := by
intro h
have := small_lift.{_, v} Cardinal.{max u v}
rw [← small_univ_iff, ← bddAbove_iff_small] at this
exact not_bddAbove_univ this
instance uncountable : Uncountable Cardinal.{u} :=
Uncountable.of_not_small not_small_cardinal.{u}
/-! ### Bounds on suprema -/
theorem sum_le_iSup_lift {ι : Type u}
(f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift #ι * iSup f := by
rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const]
exact sum_le_sum _ _ (le_ciSup <| bddAbove_of_small _)
theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by
rw [← lift_id #ι]
exact sum_le_iSup_lift f
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) :
lift.{u} (sSup s) = sSup (lift.{u} '' s) := by
apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _)
· intro c hc
by_contra h
obtain ⟨d, rfl⟩ := Cardinal.mem_range_lift_of_le (not_le.1 h).le
simp_rw [lift_le] at h hc
rw [csSup_le_iff' hs] at h
exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha)
· rintro i ⟨j, hj, rfl⟩
exact lift_le.2 (le_csSup hs hj)
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) :
lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by
rw [iSup, iSup, lift_sSup hf, ← range_comp]
simp [Function.comp_def]
/-- To prove that the lift of a supremum is bounded by some cardinal `t`,
it suffices to show that the lift of each cardinal is bounded by `t`. -/
theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f))
(w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le' w
@[simp]
theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f))
{t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _)
/-- To prove an inequality between the lifts to a common universe of two different supremums,
it suffices to show that the lift of each cardinal from the smaller supremum
if bounded by the lift of some cardinal from the larger supremum.
-/
theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}}
{f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'}
(h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by
rw [lift_iSup hf, lift_iSup hf']
exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩
/-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`.
This is sometimes necessary to avoid universe unification issues. -/
theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}}
{f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι')
(h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') :=
lift_iSup_le_lift_iSup hf hf' h
/-! ### Properties about the cast from `ℕ` -/
theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by
simp [Pow.pow]
@[norm_cast]
theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by
rw [Nat.cast_succ]
refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_)
rw [← Nat.cast_succ]
exact Nat.cast_lt.2 (Nat.lt_succ_self _)
lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by
rw [← Cardinal.nat_succ]
norm_cast
lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by
rw [← Order.succ_le_iff, Cardinal.succ_natCast]
lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by
convert natCast_add_one_le_iff
norm_cast
@[simp]
theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast
-- This works generally to prove inequalities between numeric cardinals.
theorem one_lt_two : (1 : Cardinal) < 2 := by norm_cast
theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) :
∃ s : Finset α, n ≤ s.card := by
obtain hα|hα := finite_or_infinite α
· let hα := Fintype.ofFinite α
use Finset.univ
simpa only [mk_fintype, Nat.cast_le] using h
· obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n
exact ⟨s, hs.ge⟩
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by
contrapose! H
apply exists_finset_le_card α (n+1)
simpa only [nat_succ, succ_le_iff] using H
theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by
rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb
exact (cantor a).trans_le (power_le_power_right hb)
theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by
rw [← succ_zero, succ_le_iff]
theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by
rw [one_le_iff_pos, pos_iff_ne_zero]
@[simp]
theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by
simpa using lt_succ_bot_iff (a := c)
/-! ### Properties about `aleph0` -/
theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ :=
succ_le_iff.1
(by
rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}]
exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩)
@[simp]
theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1
@[simp]
theorem one_le_aleph0 : 1 ≤ ℵ₀ :=
one_lt_aleph0.le
theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n :=
⟨fun h => by
rcases lt_lift_iff.1 h with ⟨c, h', rfl⟩
rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩
suffices S.Finite by
lift S to Finset ℕ using this
simp
contrapose! h'
haveI := Infinite.to_subtype h'
exact ⟨Infinite.natEmbedding S⟩, fun ⟨_, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩
lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by
obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h
rw [hn, succ_natCast]
theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c :=
⟨fun h _ => (nat_lt_aleph0 _).le.trans h, fun h =>
le_of_not_lt fun hn => by
rcases lt_aleph0.1 hn with ⟨n, rfl⟩
exact (Nat.lt_succ_self _).not_le (Nat.cast_le.1 (h (n + 1)))⟩
theorem isSuccPrelimit_aleph0 : IsSuccPrelimit ℵ₀ :=
isSuccPrelimit_of_succ_lt fun a ha => by
rcases lt_aleph0.1 ha with ⟨n, rfl⟩
rw [← nat_succ]
apply nat_lt_aleph0
theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := by
rw [Cardinal.isSuccLimit_iff]
exact ⟨aleph0_ne_zero, isSuccPrelimit_aleph0⟩
lemma not_isSuccLimit_natCast : (n : ℕ) → ¬ IsSuccLimit (n : Cardinal.{u})
| 0, e => e.1 isMin_bot
| Nat.succ n, e => Order.not_isSuccPrelimit_succ _ (nat_succ n ▸ e.2)
theorem not_isSuccLimit_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ¬ IsSuccLimit c := by
obtain ⟨n, rfl⟩ := lt_aleph0.1 h
exact not_isSuccLimit_natCast n
theorem aleph0_le_of_isSuccLimit {c : Cardinal} (h : IsSuccLimit c) : ℵ₀ ≤ c := by
contrapose! h
exact not_isSuccLimit_of_lt_aleph0 h
theorem isStrongLimit_aleph0 : IsStrongLimit ℵ₀ := by
refine ⟨aleph0_ne_zero, fun x hx ↦ ?_⟩
obtain ⟨n, rfl⟩ := lt_aleph0.1 hx
exact_mod_cast nat_lt_aleph0 _
theorem IsStrongLimit.aleph0_le {c} (H : IsStrongLimit c) : ℵ₀ ≤ c :=
aleph0_le_of_isSuccLimit H.isSuccLimit
lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v})
(hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n :=
exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f hf (not_isSuccLimit_natCast n) h
@[simp]
theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ :=
ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0]
theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by
rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq']
theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by
simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin]
theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) :=
lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _)
theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ :=
lt_aleph0_iff_finite.2 ‹_›
theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite :=
lt_aleph0_iff_finite.trans finite_coe_iff
alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite
@[simp]
theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite :=
lt_aleph0_iff_set_finite
theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by
rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le']
@[simp]
theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ :=
mk_le_aleph0_iff.mpr ‹_›
theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff
alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable
@[simp]
theorem le_aleph0_iff_subtype_countable {p : α → Prop} :
#{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable :=
le_aleph0_iff_set_countable
theorem aleph0_lt_mk_iff : ℵ₀ < #α ↔ Uncountable α := by
rw [← not_le, ← not_countable_iff, not_iff_not, mk_le_aleph0_iff]
@[simp]
theorem aleph0_lt_mk [Uncountable α] : ℵ₀ < #α :=
aleph0_lt_mk_iff.mpr ‹_›
instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ :=
⟨fun _ hx =>
let ⟨n, hn⟩ := lt_aleph0.mp hx
⟨n, hn.symm⟩⟩
theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0
theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ :=
⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩,
fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩
theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by
simp only [← not_lt, add_lt_aleph0_iff, not_and_or]
/-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/
theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by
cases n with
| zero => simpa using nat_lt_aleph0 0
| succ n =>
simp only [Nat.succ_ne_zero, false_or]
induction' n with n ih
· simp
rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff]
/-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/
theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ :=
nsmul_lt_aleph0_iff.trans <| or_iff_right h
theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0
theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by
refine ⟨fun h => ?_, ?_⟩
· by_cases ha : a = 0
· exact Or.inl ha
right
by_cases hb : b = 0
· exact Or.inl hb
right
rw [← Ne, ← one_le_iff_ne_zero] at ha hb
constructor
· rw [← mul_one a]
exact (mul_le_mul' le_rfl hb).trans_lt h
· rw [← one_mul b]
exact (mul_le_mul' ha le_rfl).trans_lt h
rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero]
/-- See also `Cardinal.aleph0_le_mul_iff`. -/
theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by
let h := (@mul_lt_aleph0_iff a b).not
rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h
/-- See also `Cardinal.aleph0_le_mul_iff'`. -/
theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by
have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a
simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)]
simp only [and_comm, or_comm]
theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb]
theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [power_natCast, ← Nat.cast_pow]; apply nat_lt_aleph0
theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α :=
calc
#α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff
_ ↔ Subsingleton α ∧ Nonempty α :=
le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff)
theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by
rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite]
lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm
lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff]
@[simp] lemma mk_lt_aleph0 [Finite α] : #α < ℵ₀ := mk_lt_aleph0_iff.2 ‹_›
@[simp]
theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α :=
infinite_iff.1 ‹_›
@[simp]
theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ :=
mk_le_aleph0.antisymm <| aleph0_le_mk _
theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ :=
⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by
obtain ⟨f⟩ := Quotient.exact h
exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩
theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ :=
denumerable_iff.1 ⟨‹_›⟩
theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} :
s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by
rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff]
@[simp]
theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ :=
mk_denumerable _
theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ :=
mk_denumerable _
@[simp]
theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ :=
le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <|
le_mul_of_one_le_left (zero_le _) <| by
rwa [← Nat.cast_one, Nat.cast_le, Nat.one_le_iff_ne_zero]
@[simp]
theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn]
@[simp]
theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) * ℵ₀ = ℵ₀ :=
nat_mul_aleph0 (NeZero.ne n)
@[simp]
theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * ofNat(n) = ℵ₀ :=
aleph0_mul_nat (NeZero.ne n)
@[simp]
theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ :=
⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h =>
aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩
@[simp]
theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ :=
(add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add
@[simp]
theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat]
@[simp]
theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) + ℵ₀ = ℵ₀ :=
nat_add_aleph0 n
@[simp]
theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + ofNat(n) = ℵ₀ :=
aleph0_add_nat n
theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by
lift c to ℕ using h.trans_lt (nat_lt_aleph0 _)
exact ⟨c, mod_cast h, rfl⟩
theorem mk_int : #ℤ = ℵ₀ :=
mk_denumerable ℤ
theorem mk_pnat : #ℕ+ = ℵ₀ :=
mk_denumerable ℕ+
@[deprecated (since := "2025-04-27")]
alias mk_pNat := mk_pnat
/-! ### Cardinalities of basic sets and types -/
@[simp] theorem mk_additive : #(Additive α) = #α := rfl
@[simp] theorem mk_multiplicative : #(Multiplicative α) = #α := rfl
@[to_additive (attr := simp)] theorem mk_mulOpposite : #(MulOpposite α) = #α :=
mk_congr MulOpposite.opEquiv.symm
theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 :=
mk_eq_one _
@[simp]
theorem mk_vector (α : Type u) (n : ℕ) : #(List.Vector α n) = #α ^ n :=
(mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp
theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n :=
calc
#(List α) = #(Σn, List.Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm
_ = sum fun n : ℕ => #α ^ n := by simp
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α :=
mk_le_of_surjective Quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α :=
mk_quot_le
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
#(Subtype p) ≤ #(Subtype q) :=
⟨Embedding.subtypeMap (Embedding.refl α) h⟩
theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 :=
mk_eq_zero _
theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by
constructor
· intro h
rw [mk_eq_zero_iff] at h
exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩
· rintro rfl
exact mk_emptyCollection _
@[simp]
theorem mk_univ {α : Type u} : #(@univ α) = #α :=
mk_congr (Equiv.Set.univ α)
@[simp] lemma mk_setProd {α β : Type u} (s : Set α) (t : Set β) : #(s ×ˢ t) = #s * #t := by
rw [mul_def, mk_congr (Equiv.Set.prod ..)]
theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s :=
mk_le_of_surjective surjective_onto_image
lemma mk_image2_le {α β γ : Type u} {f : α → β → γ} {s : Set α} {t : Set β} :
#(image2 f s t) ≤ #s * #t := by
rw [← image_uncurry_prod, ← mk_setProd]
exact mk_image_le
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} :
lift.{u} #(f '' s) ≤ lift.{v} #s :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α :=
mk_le_of_surjective surjective_onto_range
theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} :
lift.{u} #(range f) ≤ lift.{v} #α :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩
theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α :=
mk_congr (Equiv.ofInjective f h).symm
theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{max u w} #(range f) = lift.{max v w} #α :=
lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩
theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{u} #(range f) = lift.{v} #α :=
lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩
lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by
rw [← Cardinal.mk_range_eq_of_injective hf]
exact Cardinal.lift_le.2 (Cardinal.mk_set_le _)
lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) :
Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) :=
lift_mk_le_lift_mk_of_injective (injective_surjInv hf)
theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) :
#(f '' s) = #s :=
mk_congr (Equiv.Set.imageOfInjOn f s h).symm
theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α)
(h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s :=
lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s :=
mk_image_eq_of_injOn _ _ hf.injOn
theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) :
lift.{u} #(f '' s) = lift.{v} #s :=
mk_image_eq_of_injOn_lift _ _ h.injOn
@[simp]
theorem mk_image_embedding_lift {β : Type v} (f : α ↪ β) (s : Set α) :
lift.{u} #(f '' s) = lift.{v} #s :=
mk_image_eq_lift _ _ f.injective
@[simp]
theorem mk_image_embedding (f : α ↪ β) (s : Set α) : #(f '' s) = #s := by
simpa using mk_image_embedding_lift f s
theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
#(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} :
lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) :=
mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α}
(h : Pairwise (Disjoint on f)) : #(⋃ i, f i) = sum fun i => #(f i) :=
calc
#(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α}
(h : Pairwise (Disjoint on f)) :
lift.{v} #(⋃ i, f i) = sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) = #(Σi, f i) :=
mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) :=
mk_iUnion_le_sum_mk.trans (sum_le_iSup _)
theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) :
lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by
refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _)
rw [← lift_sum, lift_id'.{_,u}]
theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by
rw [sUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) :
#(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) :
lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le_lift
theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ :=
lt_aleph0_of_finite _
theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} :
#s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by
constructor
· intro h
lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n)
simpa using h
· rintro ⟨t, rfl, rfl⟩
exact mk_coe_finset
theorem mk_eq_nat_iff_finset {n : ℕ} :
#α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by
rw [← mk_univ, mk_set_eq_nat_iff_finset]
theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by
rw [mk_eq_nat_iff_finset]
constructor
· rintro ⟨t, ht, hn⟩
exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩
· rintro ⟨⟨t, ht⟩, hn⟩
exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩
theorem mk_union_add_mk_inter {α : Type u} {S T : Set α} :
#(S ∪ T : Set α) + #(S ∩ T : Set α) = #S + #T := by
classical
exact Quot.sound ⟨Equiv.Set.unionSumInter S T⟩
/-- The cardinality of a union is at most the sum of the cardinalities
of the two sets. -/
theorem mk_union_le {α : Type u} (S T : Set α) : #(S ∪ T : Set α) ≤ #S + #T :=
@mk_union_add_mk_inter α S T ▸ self_le_add_right #(S ∪ T : Set α) #(S ∩ T : Set α)
theorem mk_union_of_disjoint {α : Type u} {S T : Set α} (H : Disjoint S T) :
#(S ∪ T : Set α) = #S + #T := by
classical
exact Quot.sound ⟨Equiv.Set.union H⟩
theorem mk_insert {α : Type u} {s : Set α} {a : α} (h : a ∉ s) :
#(insert a s : Set α) = #s + 1 := by
rw [← union_singleton, mk_union_of_disjoint, mk_singleton]
simpa
theorem mk_insert_le {α : Type u} {s : Set α} {a : α} : #(insert a s : Set α) ≤ #s + 1 := by
by_cases h : a ∈ s
· simp only [insert_eq_of_mem h, self_le_add_right]
· rw [mk_insert h]
theorem mk_sum_compl {α} (s : Set α) : #s + #(sᶜ : Set α) = #α := by
classical
exact mk_congr (Equiv.Set.sumCompl s)
theorem mk_le_mk_of_subset {α} {s t : Set α} (h : s ⊆ t) : #s ≤ #t :=
⟨Set.embeddingOfSubset s t h⟩
theorem mk_le_iff_forall_finset_subset_card_le {α : Type u} {n : ℕ} {t : Set α} :
#t ≤ n ↔ ∀ s : Finset α, (s : Set α) ⊆ t → s.card ≤ n := by
refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩
apply card_le_of (fun s ↦ ?_)
classical
let u : Finset α := s.image Subtype.val
have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn
rw [← this]
apply H
simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ]
theorem mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) :
#{ x // p x } ≤ #{ x // q x } :=
⟨embeddingOfSubset _ _ h⟩
theorem le_mk_diff_add_mk (S T : Set α) : #S ≤ #(S \ T : Set α) + #T :=
(mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _
theorem mk_diff_add_mk {S T : Set α} (h : T ⊆ S) : #(S \ T : Set α) + #T = #S := by
refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h]
exact disjoint_sdiff_self_left
theorem mk_union_le_aleph0 {α} {P Q : Set α} :
#(P ∪ Q : Set α) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ := by
simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def,
← countable_union]
theorem mk_sep (s : Set α) (t : α → Prop) : #({ x ∈ s | t x } : Set α) = #{ x : s | t x.1 } :=
mk_congr (Equiv.Set.sep s t)
theorem mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) : lift.{v} #(f ⁻¹' s) ≤ lift.{u} #s := by
rw [lift_mk_le.{0}]
-- Porting note: Needed to insert `mem_preimage.mp` below
use Subtype.coind (fun x => f x.1) fun x => mem_preimage.mp x.2
apply Subtype.coind_injective; exact h.comp Subtype.val_injective
theorem mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : s ⊆ range f) : lift.{u} #s ≤ lift.{v} #(f ⁻¹' s) := by
rw [← image_preimage_eq_iff] at h
nth_rewrite 1 [← h]
apply mk_image_le_lift
theorem mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) (h2 : s ⊆ range f) : lift.{v} #(f ⁻¹' s) = lift.{u} #s :=
le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2)
theorem mk_preimage_of_injective_of_subset_range (f : α → β) (s : Set β) (h : Injective f)
(h2 : s ⊆ range f) : #(f ⁻¹' s) = #s := by
convert mk_preimage_of_injective_of_subset_range_lift.{u, u} f s h h2 using 1 <;> rw [lift_id]
@[simp]
theorem mk_preimage_equiv_lift {β : Type v} (f : α ≃ β) (s : Set β) :
lift.{v} #(f ⁻¹' s) = lift.{u} #s := by
apply mk_preimage_of_injective_of_subset_range_lift _ _ f.injective
rw [f.range_eq_univ]
exact fun _ _ ↦ ⟨⟩
@[simp]
theorem mk_preimage_equiv (f : α ≃ β) (s : Set β) : #(f ⁻¹' s) = #s := by
simpa using mk_preimage_equiv_lift f s
theorem mk_preimage_of_injective (f : α → β) (s : Set β) (h : Injective f) :
#(f ⁻¹' s) ≤ #s := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_injective_lift f s h
theorem mk_preimage_of_subset_range (f : α → β) (s : Set β) (h : s ⊆ range f) :
#s ≤ #(f ⁻¹' s) := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_subset_range_lift f s h
theorem mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : Set α}
{t : Set β} (h : t ⊆ f '' s) : lift.{u} #t ≤ lift.{v} #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range_lift _ _ h using 1
rw [mk_sep]
rfl
theorem mk_subset_ge_of_subset_image (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) :
#t ≤ #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range _ _ h using 1
rw [mk_sep]
rfl
theorem le_mk_iff_exists_subset {c : Cardinal} {α : Type u} {s : Set α} :
c ≤ #s ↔ ∃ p : Set α, p ⊆ s ∧ #p = c := by
rw [le_mk_iff_exists_set, ← Subtype.exists_set_subtype]
apply exists_congr; intro t; rw [mk_image_eq]; apply Subtype.val_injective
@[simp]
theorem mk_range_inl {α : Type u} {β : Type v} : #(range (@Sum.inl α β)) = lift.{v} #α := by
rw [← lift_id'.{u, v} #_, (Equiv.Set.rangeInl α β).lift_cardinal_eq, lift_umax.{u, v}]
@[simp]
theorem mk_range_inr {α : Type u} {β : Type v} : #(range (@Sum.inr α β)) = lift.{u} #β := by
rw [← lift_id'.{v, u} #_, (Equiv.Set.rangeInr α β).lift_cardinal_eq, lift_umax.{v, u}]
theorem two_le_iff : (2 : Cardinal) ≤ #α ↔ ∃ x y : α, x ≠ y := by
rw [← Nat.cast_two, nat_succ, succ_le_iff, Nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff]
theorem two_le_iff' (x : α) : (2 : Cardinal) ≤ #α ↔ ∃ y : α, y ≠ x := by
rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x]
theorem mk_eq_two_iff : #α = 2 ↔ ∃ x y : α, x ≠ y ∧ ({x, y} : Set α) = univ := by
classical
simp only [← @Nat.cast_two Cardinal, mk_eq_nat_iff_finset, Finset.card_eq_two]
constructor
· rintro ⟨t, ht, x, y, hne, rfl⟩
exact ⟨x, y, hne, by simpa using ht⟩
· rintro ⟨x, y, hne, h⟩
exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩
theorem mk_eq_two_iff' (x : α) : #α = 2 ↔ ∃! y, y ≠ x := by
rw [mk_eq_two_iff]; constructor
· rintro ⟨a, b, hne, h⟩
simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h
rcases h x with (rfl | rfl)
exacts [⟨b, hne.symm, fun z => (h z).resolve_left⟩, ⟨a, hne, fun z => (h z).resolve_right⟩]
· rintro ⟨y, hne, hy⟩
exact ⟨x, y, hne.symm, eq_univ_of_forall fun z => or_iff_not_imp_left.2 (hy z)⟩
theorem exists_not_mem_of_length_lt {α : Type*} (l : List α) (h : ↑l.length < #α) :
∃ z : α, z ∉ l := by
classical
contrapose! h
calc
#α = #(Set.univ : Set α) := mk_univ.symm
_ ≤ #l.toFinset := mk_le_mk_of_subset fun x _ => List.mem_toFinset.mpr (h x)
_ = l.toFinset.card := Cardinal.mk_coe_finset
_ ≤ l.length := Nat.cast_le.mpr (List.toFinset_card_le l)
theorem three_le {α : Type*} (h : 3 ≤ #α) (x : α) (y : α) : ∃ z : α, z ≠ x ∧ z ≠ y := by
have : ↑(3 : ℕ) ≤ #α := by simpa using h
have : ↑(2 : ℕ) < #α := by rwa [← succ_le_iff, ← Cardinal.nat_succ]
have := exists_not_mem_of_length_lt [x, y] this
simpa [not_or] using this
/-! ### `powerlt` operation -/
/-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/
def powerlt (a b : Cardinal.{u}) : Cardinal.{u} :=
⨆ c : Iio b, a ^ (c : Cardinal)
@[inherit_doc]
infixl:80 " ^< " => powerlt
theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≤ a ^< b := by
refine le_ciSup (f := fun y : Iio b => a ^ (y : Cardinal)) ?_ ⟨c, h⟩
rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c := by
rw [powerlt, ciSup_le_iff']
· simp
· rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
powerlt_le.2 fun _ hx => le_powerlt a <| hx.trans_le h
theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left
theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = a ^ b :=
(powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <|
le_powerlt a (lt_succ b)
theorem powerlt_min {a b c : Cardinal} : a ^< min b c = min (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_min
theorem powerlt_max {a b c : Cardinal} : a ^< max b c = max (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_max
theorem zero_powerlt {a : Cardinal} (h : a ≠ 0) : 0 ^< a = 1 := by
apply (powerlt_le.2 fun c _ => zero_power_le _).antisymm
rw [← power_zero]
exact le_powerlt 0 (pos_iff_ne_zero.2 h)
@[simp]
theorem powerlt_zero {a : Cardinal} : a ^< 0 = 0 := by
convert Cardinal.iSup_of_empty _
exact Subtype.isEmpty_of_false fun x => mem_Iio.not.mpr (Cardinal.zero_le x).not_lt
end Cardinal
| Mathlib/SetTheory/Cardinal/Basic.lean | 1,597 | 1,598 | |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Fin.VecNotation
import Mathlib.Logic.Small.Basic
import Mathlib.SetTheory.ZFC.PSet
/-!
# A model of ZFC
In this file, we model Zermelo-Fraenkel set theory (+ choice) using Lean's underlying type theory,
building on the pre-sets defined in `Mathlib.SetTheory.ZFC.PSet`.
The theory of classes is developed in `Mathlib.SetTheory.ZFC.Class`.
## Main definitions
* `ZFSet`: ZFC set. Defined as `PSet` quotiented by `PSet.Equiv`, the extensional equivalence.
* `ZFSet.choice`: Axiom of choice. Proved from Lean's axiom of choice.
* `ZFSet.omega`: The von Neumann ordinal `ω` as a `Set`.
* `Classical.allZFSetDefinable`: All functions are classically definable.
* `ZFSet.IsFunc` : Predicate that a ZFC set is a subset of `x × y` that can be considered as a ZFC
function `x → y`. That is, each member of `x` is related by the ZFC set to exactly one member of
`y`.
* `ZFSet.funs`: ZFC set of ZFC functions `x → y`.
* `ZFSet.Hereditarily p x`: Predicate that every set in the transitive closure of `x` has property
`p`.
## Notes
To avoid confusion between the Lean `Set` and the ZFC `Set`, docstrings in this file refer to them
respectively as "`Set`" and "ZFC set".
-/
universe u
/-- The ZFC universe of sets consists of the type of pre-sets,
quotiented by extensional equivalence. -/
@[pp_with_univ]
def ZFSet : Type (u + 1) :=
Quotient PSet.setoid.{u}
namespace ZFSet
/-- Turns a pre-set into a ZFC set. -/
def mk : PSet → ZFSet :=
Quotient.mk''
@[simp]
theorem mk_eq (x : PSet) : @Eq ZFSet ⟦x⟧ (mk x) :=
rfl
@[simp]
theorem mk_out : ∀ x : ZFSet, mk x.out = x :=
Quotient.out_eq
/-- A set function is "definable" if it is the image of some n-ary `PSet`
function. This isn't exactly definability, but is useful as a sufficient
condition for functions that have a computable image. -/
class Definable (n) (f : (Fin n → ZFSet.{u}) → ZFSet.{u}) where
/-- Turns a definable function into an n-ary `PSet` function. -/
out : (Fin n → PSet.{u}) → PSet.{u}
/-- A set function `f` is the image of `Definable.out f`. -/
mk_out xs : mk (out xs) = f (mk <| xs ·) := by simp
attribute [simp] Definable.mk_out
/-- An abbrev of `ZFSet.Definable` for unary functions. -/
abbrev Definable₁ (f : ZFSet.{u} → ZFSet.{u}) := Definable 1 (fun s ↦ f (s 0))
/-- A simpler constructor for `ZFSet.Definable₁`. -/
abbrev Definable₁.mk {f : ZFSet.{u} → ZFSet.{u}}
(out : PSet.{u} → PSet.{u}) (mk_out : ∀ x, ⟦out x⟧ = f ⟦x⟧) :
Definable₁ f where
out xs := out (xs 0)
mk_out xs := mk_out (xs 0)
/-- Turns a unary definable function into a unary `PSet` function. -/
abbrev Definable₁.out (f : ZFSet.{u} → ZFSet.{u}) [Definable₁ f] :
PSet.{u} → PSet.{u} :=
fun x ↦ Definable.out (fun s ↦ f (s 0)) ![x]
lemma Definable₁.mk_out {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f]
{x : PSet} :
.mk (out f x) = f (.mk x) :=
Definable.mk_out ![x]
/-- An abbrev of `ZFSet.Definable` for binary functions. -/
abbrev Definable₂ (f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}) := Definable 2 (fun s ↦ f (s 0) (s 1))
/-- A simpler constructor for `ZFSet.Definable₂`. -/
abbrev Definable₂.mk {f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}}
(out : PSet.{u} → PSet.{u} → PSet.{u}) (mk_out : ∀ x y, ⟦out x y⟧ = f ⟦x⟧ ⟦y⟧) :
Definable₂ f where
out xs := out (xs 0) (xs 1)
mk_out xs := mk_out (xs 0) (xs 1)
/-- Turns a binary definable function into a binary `PSet` function. -/
abbrev Definable₂.out (f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}) [Definable₂ f] :
PSet.{u} → PSet.{u} → PSet.{u} :=
fun x y ↦ Definable.out (fun s ↦ f (s 0) (s 1)) ![x, y]
lemma Definable₂.mk_out {f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}} [Definable₂ f]
{x y : PSet} :
.mk (out f x y) = f (.mk x) (.mk y) :=
Definable.mk_out ![x, y]
instance (f) [Definable₁ f] (n g) [Definable n g] :
Definable n (fun s ↦ f (g s)) where
out xs := Definable₁.out f (Definable.out g xs)
instance (f) [Definable₂ f] (n g₁ g₂) [Definable n g₁] [Definable n g₂] :
Definable n (fun s ↦ f (g₁ s) (g₂ s)) where
out xs := Definable₂.out f (Definable.out g₁ xs) (Definable.out g₂ xs)
instance (n) (i) : Definable n (fun s ↦ s i) where
out s := s i
lemma Definable.out_equiv {n} (f : (Fin n → ZFSet.{u}) → ZFSet.{u}) [Definable n f]
{xs ys : Fin n → PSet} (h : ∀ i, xs i ≈ ys i) :
out f xs ≈ out f ys := by
rw [← Quotient.eq_iff_equiv, mk_eq, mk_eq, mk_out, mk_out]
exact congrArg _ (funext fun i ↦ Quotient.sound (h i))
lemma Definable₁.out_equiv (f : ZFSet.{u} → ZFSet.{u}) [Definable₁ f]
{x y : PSet} (h : x ≈ y) :
out f x ≈ out f y :=
Definable.out_equiv _ (by simp [h])
lemma Definable₂.out_equiv (f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}) [Definable₂ f]
{x₁ y₁ x₂ y₂ : PSet} (h₁ : x₁ ≈ y₁) (h₂ : x₂ ≈ y₂) :
out f x₁ x₂ ≈ out f y₁ y₂ :=
Definable.out_equiv _ (by simp [Fin.forall_fin_succ, h₁, h₂])
end ZFSet
namespace Classical
open PSet ZFSet
/-- All functions are classically definable. -/
noncomputable def allZFSetDefinable {n} (F : (Fin n → ZFSet.{u}) → ZFSet.{u}) : Definable n F where
out xs := (F (mk <| xs ·)).out
end Classical
namespace ZFSet
open PSet
theorem eq {x y : PSet} : mk x = mk y ↔ Equiv x y :=
Quotient.eq
theorem sound {x y : PSet} (h : PSet.Equiv x y) : mk x = mk y :=
Quotient.sound h
theorem exact {x y : PSet} : mk x = mk y → PSet.Equiv x y :=
Quotient.exact
/-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/
protected def Mem : ZFSet → ZFSet → Prop :=
Quotient.lift₂ (· ∈ ·) fun _ _ _ _ hx hy =>
propext ((Mem.congr_left hx).trans (Mem.congr_right hy))
instance : Membership ZFSet ZFSet where
mem t s := ZFSet.Mem s t
@[simp]
theorem mk_mem_iff {x y : PSet} : mk x ∈ mk y ↔ x ∈ y :=
Iff.rfl
/-- Convert a ZFC set into a `Set` of ZFC sets -/
def toSet (u : ZFSet.{u}) : Set ZFSet.{u} :=
{ x | x ∈ u }
@[simp]
theorem mem_toSet (a u : ZFSet.{u}) : a ∈ u.toSet ↔ a ∈ u :=
Iff.rfl
instance small_toSet (x : ZFSet.{u}) : Small.{u} x.toSet :=
Quotient.inductionOn x fun a => by
let f : a.Type → (mk a).toSet := fun i => ⟨mk <| a.Func i, func_mem a i⟩
suffices Function.Surjective f by exact small_of_surjective this
rintro ⟨y, hb⟩
induction y using Quotient.inductionOn
obtain ⟨i, h⟩ := hb
exact ⟨i, Subtype.coe_injective (Quotient.sound h.symm)⟩
/-- A nonempty set is one that contains some element. -/
protected def Nonempty (u : ZFSet) : Prop :=
u.toSet.Nonempty
theorem nonempty_def (u : ZFSet) : u.Nonempty ↔ ∃ x, x ∈ u :=
Iff.rfl
theorem nonempty_of_mem {x u : ZFSet} (h : x ∈ u) : u.Nonempty :=
⟨x, h⟩
@[simp]
theorem nonempty_toSet_iff {u : ZFSet} : u.toSet.Nonempty ↔ u.Nonempty :=
Iff.rfl
/-- `x ⊆ y` as ZFC sets means that all members of `x` are members of `y`. -/
protected def Subset (x y : ZFSet.{u}) :=
∀ ⦃z⦄, z ∈ x → z ∈ y
instance hasSubset : HasSubset ZFSet :=
⟨ZFSet.Subset⟩
theorem subset_def {x y : ZFSet.{u}} : x ⊆ y ↔ ∀ ⦃z⦄, z ∈ x → z ∈ y :=
Iff.rfl
instance : IsRefl ZFSet (· ⊆ ·) :=
⟨fun _ _ => id⟩
instance : IsTrans ZFSet (· ⊆ ·) :=
⟨fun _ _ _ hxy hyz _ ha => hyz (hxy ha)⟩
@[simp]
theorem subset_iff : ∀ {x y : PSet}, mk x ⊆ mk y ↔ x ⊆ y
| ⟨_, A⟩, ⟨_, _⟩ =>
⟨fun h a => @h ⟦A a⟧ (Mem.mk A a), fun h z =>
Quotient.inductionOn z fun _ ⟨a, za⟩ =>
let ⟨b, ab⟩ := h a
⟨b, za.trans ab⟩⟩
@[simp]
theorem toSet_subset_iff {x y : ZFSet} : x.toSet ⊆ y.toSet ↔ x ⊆ y := by
simp [subset_def, Set.subset_def]
@[ext]
theorem ext {x y : ZFSet.{u}} : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y :=
Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧)
theorem toSet_injective : Function.Injective toSet := fun _ _ h => ext <| Set.ext_iff.1 h
@[simp]
theorem toSet_inj {x y : ZFSet} : x.toSet = y.toSet ↔ x = y :=
toSet_injective.eq_iff
instance : IsAntisymm ZFSet (· ⊆ ·) :=
⟨fun _ _ hab hba => ext fun c => ⟨@hab c, @hba c⟩⟩
/-- The empty ZFC set -/
protected def empty : ZFSet :=
mk ∅
instance : EmptyCollection ZFSet :=
⟨ZFSet.empty⟩
instance : Inhabited ZFSet :=
⟨∅⟩
@[simp]
theorem not_mem_empty (x) : x ∉ (∅ : ZFSet.{u}) :=
Quotient.inductionOn x PSet.not_mem_empty
@[simp]
theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet]
@[simp]
theorem empty_subset (x : ZFSet.{u}) : (∅ : ZFSet) ⊆ x :=
Quotient.inductionOn x fun y => subset_iff.2 <| PSet.empty_subset y
@[simp]
theorem not_nonempty_empty : ¬ZFSet.Nonempty ∅ := by simp [ZFSet.Nonempty]
@[simp]
theorem nonempty_mk_iff {x : PSet} : (mk x).Nonempty ↔ x.Nonempty := by
refine ⟨?_, fun ⟨a, h⟩ => ⟨mk a, h⟩⟩
rintro ⟨a, h⟩
induction a using Quotient.inductionOn
exact ⟨_, h⟩
theorem eq_empty (x : ZFSet.{u}) : x = ∅ ↔ ∀ y : ZFSet.{u}, y ∉ x := by
simp [ZFSet.ext_iff]
theorem eq_empty_or_nonempty (u : ZFSet) : u = ∅ ∨ u.Nonempty := by
rw [eq_empty, ← not_exists]
apply em'
/-- `Insert x y` is the set `{x} ∪ y` -/
protected def Insert : ZFSet → ZFSet → ZFSet :=
Quotient.map₂ PSet.insert
fun _ _ uv ⟨_, _⟩ ⟨_, _⟩ ⟨αβ, βα⟩ =>
⟨fun o =>
match o with
| some a =>
let ⟨b, hb⟩ := αβ a
⟨some b, hb⟩
| none => ⟨none, uv⟩,
fun o =>
match o with
| some b =>
let ⟨a, ha⟩ := βα b
⟨some a, ha⟩
| none => ⟨none, uv⟩⟩
instance : Insert ZFSet ZFSet :=
⟨ZFSet.Insert⟩
instance : Singleton ZFSet ZFSet :=
⟨fun x => insert x ∅⟩
instance : LawfulSingleton ZFSet ZFSet :=
⟨fun _ => rfl⟩
@[simp]
theorem mem_insert_iff {x y z : ZFSet.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z :=
Quotient.inductionOn₃ x y z fun _ _ _ => PSet.mem_insert_iff.trans (or_congr_left eq.symm)
theorem mem_insert (x y : ZFSet) : x ∈ insert x y :=
mem_insert_iff.2 <| Or.inl rfl
theorem mem_insert_of_mem {y z : ZFSet} (x) (h : z ∈ y) : z ∈ insert x y :=
mem_insert_iff.2 <| Or.inr h
@[simp]
theorem toSet_insert (x y : ZFSet) : (insert x y).toSet = insert x y.toSet := by
ext
simp
@[simp]
theorem mem_singleton {x y : ZFSet.{u}} : x ∈ @singleton ZFSet.{u} ZFSet.{u} _ y ↔ x = y :=
Quotient.inductionOn₂ x y fun _ _ => PSet.mem_singleton.trans eq.symm
@[simp]
theorem toSet_singleton (x : ZFSet) : ({x} : ZFSet).toSet = {x} := by
ext
simp
theorem insert_nonempty (u v : ZFSet) : (insert u v).Nonempty :=
⟨u, mem_insert u v⟩
theorem singleton_nonempty (u : ZFSet) : ZFSet.Nonempty {u} :=
insert_nonempty u ∅
theorem mem_pair {x y z : ZFSet.{u}} : x ∈ ({y, z} : ZFSet) ↔ x = y ∨ x = z := by
simp
@[simp]
theorem pair_eq_singleton (x : ZFSet) : {x, x} = ({x} : ZFSet) := by
ext
simp
@[simp]
theorem pair_eq_singleton_iff {x y z : ZFSet} : ({x, y} : ZFSet) = {z} ↔ x = z ∧ y = z := by
refine ⟨fun h ↦ ?_, ?_⟩
· rw [← mem_singleton, ← mem_singleton]
simp [← h]
· rintro ⟨rfl, rfl⟩
exact pair_eq_singleton y
@[simp]
theorem singleton_eq_pair_iff {x y z : ZFSet} : ({x} : ZFSet) = {y, z} ↔ x = y ∧ x = z := by
rw [eq_comm, pair_eq_singleton_iff]
simp_rw [eq_comm]
/-- `omega` is the first infinite von Neumann ordinal -/
def omega : ZFSet :=
mk PSet.omega
@[simp]
theorem omega_zero : ∅ ∈ omega :=
⟨⟨0⟩, Equiv.rfl⟩
@[simp]
theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} :=
Quotient.inductionOn n fun x ⟨⟨n⟩, h⟩ =>
⟨⟨n + 1⟩,
ZFSet.exact <|
show insert (mk x) (mk x) = insert (mk <| ofNat n) (mk <| ofNat n) by
rw [ZFSet.sound h]
rfl⟩
/-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/
protected def sep (p : ZFSet → Prop) : ZFSet → ZFSet :=
Quotient.map (PSet.sep fun y => p (mk y))
fun ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ =>
⟨fun ⟨a, pa⟩ =>
let ⟨b, hb⟩ := αβ a
⟨⟨b, by simpa only [mk_func, ← ZFSet.sound hb]⟩, hb⟩,
fun ⟨b, pb⟩ =>
let ⟨a, ha⟩ := βα b
⟨⟨a, by simpa only [mk_func, ZFSet.sound ha]⟩, ha⟩⟩
-- Porting note: the { x | p x } notation appears to be disabled in Lean 4.
instance : Sep ZFSet ZFSet :=
⟨ZFSet.sep⟩
@[simp]
theorem mem_sep {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} :
y ∈ ZFSet.sep p x ↔ y ∈ x ∧ p y :=
Quotient.inductionOn₂ x y fun _ _ =>
PSet.mem_sep (p := p ∘ mk) fun _ _ h => (Quotient.sound h).subst
@[simp]
theorem sep_empty (p : ZFSet → Prop) : (∅ : ZFSet).sep p = ∅ :=
(eq_empty _).mpr fun _ h ↦ not_mem_empty _ (mem_sep.mp h).1
@[simp]
theorem toSet_sep (a : ZFSet) (p : ZFSet → Prop) :
(ZFSet.sep p a).toSet = { x ∈ a.toSet | p x } := by
ext
simp
/-- The powerset operation, the collection of subsets of a ZFC set -/
def powerset : ZFSet → ZFSet :=
Quotient.map PSet.powerset
fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ =>
⟨fun p =>
⟨{ b | ∃ a, p a ∧ Equiv (A a) (B b) }, fun ⟨a, pa⟩ =>
let ⟨b, ab⟩ := αβ a
⟨⟨b, a, pa, ab⟩, ab⟩,
fun ⟨_, a, pa, ab⟩ => ⟨⟨a, pa⟩, ab⟩⟩,
fun q =>
⟨{ a | ∃ b, q b ∧ Equiv (A a) (B b) }, fun ⟨_, b, qb, ab⟩ => ⟨⟨b, qb⟩, ab⟩, fun ⟨b, qb⟩ =>
let ⟨a, ab⟩ := βα b
⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩
@[simp]
theorem mem_powerset {x y : ZFSet.{u}} : y ∈ powerset x ↔ y ⊆ x :=
Quotient.inductionOn₂ x y fun _ _ => PSet.mem_powerset.trans subset_iff.symm
theorem sUnion_lem {α β : Type u} (A : α → PSet) (B : β → PSet) (αβ : ∀ a, ∃ b, Equiv (A a) (B b)) :
∀ a, ∃ b, Equiv ((sUnion ⟨α, A⟩).Func a) ((sUnion ⟨β, B⟩).Func b)
| ⟨a, c⟩ => by
let ⟨b, hb⟩ := αβ a
induction' ea : A a with γ Γ
induction' eb : B b with δ Δ
rw [ea, eb] at hb
obtain ⟨γδ, δγ⟩ := hb
let c : (A a).Type := c
let ⟨d, hd⟩ := γδ (by rwa [ea] at c)
use ⟨b, Eq.ndrec d (Eq.symm eb)⟩
change PSet.Equiv ((A a).Func c) ((B b).Func (Eq.ndrec d eb.symm))
match A a, B b, ea, eb, c, d, hd with
| _, _, rfl, rfl, _, _, hd => exact hd
/-- The union operator, the collection of elements of elements of a ZFC set -/
def sUnion : ZFSet → ZFSet :=
Quotient.map PSet.sUnion
fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ =>
⟨sUnion_lem A B αβ, fun a =>
Exists.elim
(sUnion_lem B A (fun b => Exists.elim (βα b) fun c hc => ⟨c, PSet.Equiv.symm hc⟩) a)
fun b hb => ⟨b, PSet.Equiv.symm hb⟩⟩
@[inherit_doc]
prefix:110 "⋃₀ " => ZFSet.sUnion
/-- The intersection operator, the collection of elements in all of the elements of a ZFC set. We
define `⋂₀ ∅ = ∅`. -/
def sInter (x : ZFSet) : ZFSet := (⋃₀ x).sep (fun y => ∀ z ∈ x, y ∈ z)
@[inherit_doc]
prefix:110 "⋂₀ " => ZFSet.sInter
@[simp]
theorem mem_sUnion {x y : ZFSet.{u}} : y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z :=
Quotient.inductionOn₂ x y fun _ _ => PSet.mem_sUnion.trans
⟨fun ⟨z, h⟩ => ⟨⟦z⟧, h⟩, fun ⟨z, h⟩ => Quotient.inductionOn z (fun z h => ⟨z, h⟩) h⟩
theorem mem_sInter {x y : ZFSet} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z ∈ x, y ∈ z := by
unfold sInter
simp only [and_iff_right_iff_imp, mem_sep]
intro mem
apply mem_sUnion.mpr
replace ⟨s, h⟩ := h
exact ⟨_, h, mem _ h⟩
@[simp]
theorem sUnion_empty : ⋃₀ (∅ : ZFSet.{u}) = ∅ := by
ext
simp
@[simp]
theorem sInter_empty : ⋂₀ (∅ : ZFSet) = ∅ := by simp [sInter]
theorem mem_of_mem_sInter {x y z : ZFSet} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by
rcases eq_empty_or_nonempty x with (rfl | hx)
· exact (not_mem_empty z hz).elim
· exact (mem_sInter hx).1 hy z hz
theorem mem_sUnion_of_mem {x y z : ZFSet} (hy : y ∈ z) (hz : z ∈ x) : y ∈ ⋃₀ x :=
mem_sUnion.2 ⟨z, hz, hy⟩
theorem not_mem_sInter_of_not_mem {x y z : ZFSet} (hy : ¬y ∈ z) (hz : z ∈ x) : ¬y ∈ ⋂₀ x :=
fun hx => hy <| mem_of_mem_sInter hx hz
@[simp]
theorem sUnion_singleton {x : ZFSet.{u}} : ⋃₀ ({x} : ZFSet) = x :=
ext fun y => by simp_rw [mem_sUnion, mem_singleton, exists_eq_left]
@[simp]
theorem sInter_singleton {x : ZFSet.{u}} : ⋂₀ ({x} : ZFSet) = x :=
ext fun y => by simp_rw [mem_sInter (singleton_nonempty x), mem_singleton, forall_eq]
@[simp]
theorem toSet_sUnion (x : ZFSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by
ext
simp
theorem toSet_sInter {x : ZFSet.{u}} (h : x.Nonempty) : (⋂₀ x).toSet = ⋂₀ (toSet '' x.toSet) := by
ext
simp [mem_sInter h]
theorem singleton_injective : Function.Injective (@singleton ZFSet ZFSet _) := fun x y H => by
let this := congr_arg sUnion H
rwa [sUnion_singleton, sUnion_singleton] at this
@[simp]
theorem singleton_inj {x y : ZFSet} : ({x} : ZFSet) = {y} ↔ x = y :=
singleton_injective.eq_iff
/-- The binary union operation -/
protected def union (x y : ZFSet.{u}) : ZFSet.{u} :=
⋃₀ {x, y}
/-- The binary intersection operation -/
protected def inter (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => z ∈ y) x -- { z ∈ x | z ∈ y }
/-- The set difference operation -/
protected def diff (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => z ∉ y) x -- { z ∈ x | z ∉ y }
instance : Union ZFSet :=
⟨ZFSet.union⟩
instance : Inter ZFSet :=
⟨ZFSet.inter⟩
instance : SDiff ZFSet :=
⟨ZFSet.diff⟩
@[simp]
theorem toSet_union (x y : ZFSet.{u}) : (x ∪ y).toSet = x.toSet ∪ y.toSet := by
change (⋃₀ {x, y}).toSet = _
simp
@[simp]
theorem toSet_inter (x y : ZFSet.{u}) : (x ∩ y).toSet = x.toSet ∩ y.toSet := by
change (ZFSet.sep (fun z => z ∈ y) x).toSet = _
ext
simp
@[simp]
theorem toSet_sdiff (x y : ZFSet.{u}) : (x \ y).toSet = x.toSet \ y.toSet := by
change (ZFSet.sep (fun z => z ∉ y) x).toSet = _
ext
simp
@[simp]
theorem mem_union {x y z : ZFSet.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y := by
rw [← mem_toSet]
simp
@[simp]
theorem mem_inter {x y z : ZFSet.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y :=
@mem_sep (fun z : ZFSet.{u} => z ∈ y) x z
@[simp]
theorem mem_diff {x y z : ZFSet.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y :=
@mem_sep (fun z : ZFSet.{u} => z ∉ y) x z
@[simp]
theorem sUnion_pair {x y : ZFSet.{u}} : ⋃₀ ({x, y} : ZFSet.{u}) = x ∪ y :=
rfl
theorem mem_wf : @WellFounded ZFSet (· ∈ ·) :=
(wellFounded_lift₂_iff (H := fun a b c d hx hy =>
propext ((@Mem.congr_left a c hx).trans (@Mem.congr_right b d hy _)))).mpr PSet.mem_wf
/-- Induction on the `∈` relation. -/
@[elab_as_elim]
theorem inductionOn {p : ZFSet → Prop} (x) (h : ∀ x, (∀ y ∈ x, p y) → p x) : p x :=
mem_wf.induction x h
instance : IsWellFounded ZFSet (· ∈ ·) :=
⟨mem_wf⟩
instance : WellFoundedRelation ZFSet :=
⟨_, mem_wf⟩
theorem mem_asymm {x y : ZFSet} : x ∈ y → y ∉ x :=
asymm_of (· ∈ ·)
theorem mem_irrefl (x : ZFSet) : x ∉ x :=
irrefl_of (· ∈ ·) x
theorem not_subset_of_mem {x y : ZFSet} (h : x ∈ y) : ¬ y ⊆ x :=
fun h' ↦ mem_irrefl _ (h' h)
theorem not_mem_of_subset {x y : ZFSet} (h : x ⊆ y) : y ∉ x :=
imp_not_comm.2 not_subset_of_mem h
theorem regularity (x : ZFSet.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ :=
by_contradiction fun ne =>
h <| (eq_empty x).2 fun y =>
@inductionOn (fun z => z ∉ x) y fun z IH zx =>
ne ⟨z, zx, (eq_empty _).2 fun w wxz =>
let ⟨wx, wz⟩ := mem_inter.1 wxz
IH w wz wx⟩
/-- The image of a (definable) ZFC set function -/
def image (f : ZFSet → ZFSet) [Definable₁ f] : ZFSet → ZFSet :=
let r := Definable₁.out f
Quotient.map (PSet.image r)
fun _ _ e =>
Mem.ext fun _ =>
(mem_image (fun _ _ ↦ Definable₁.out_equiv _)).trans <|
Iff.trans
⟨fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).1 h1, h2⟩, fun ⟨w, h1, h2⟩ =>
⟨w, (Mem.congr_right e).2 h1, h2⟩⟩ <|
(mem_image (fun _ _ ↦ Definable₁.out_equiv _)).symm
theorem image.mk (f : ZFSet.{u} → ZFSet.{u}) [Definable₁ f] (x) {y} : y ∈ x → f y ∈ image f x :=
Quotient.inductionOn₂ x y fun ⟨_, _⟩ _ ⟨a, ya⟩ => by
simp only [mk_eq, ← Definable₁.mk_out (f := f)]
exact ⟨a, Definable₁.out_equiv f ya⟩
@[simp]
theorem mem_image {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f] {x y : ZFSet.{u}} :
y ∈ image f x ↔ ∃ z ∈ x, f z = y :=
Quotient.inductionOn₂ x y fun ⟨_, A⟩ _ =>
⟨fun ⟨a, ya⟩ => ⟨⟦A a⟧, Mem.mk A a, ((Quotient.sound ya).trans Definable₁.mk_out).symm⟩,
fun ⟨_, hz, e⟩ => e ▸ image.mk _ _ hz⟩
@[simp]
theorem toSet_image (f : ZFSet → ZFSet) [Definable₁ f] (x : ZFSet) :
(image f x).toSet = f '' x.toSet := by
ext
simp
/-- The range of a type-indexed family of sets. -/
noncomputable def range {α} [Small.{u} α] (f : α → ZFSet.{u}) : ZFSet.{u} :=
⟦⟨_, Quotient.out ∘ f ∘ (equivShrink α).symm⟩⟧
@[simp]
theorem mem_range {α} [Small.{u} α] {f : α → ZFSet.{u}} {x : ZFSet.{u}} :
x ∈ range f ↔ x ∈ Set.range f :=
Quotient.inductionOn x fun y => by
constructor
· rintro ⟨z, hz⟩
exact ⟨(equivShrink α).symm z, Quotient.eq_mk_iff_out.2 hz.symm⟩
· rintro ⟨z, hz⟩
use equivShrink α z
simpa [hz] using PSet.Equiv.symm (Quotient.mk_out y)
@[simp]
theorem toSet_range {α} [Small.{u} α] (f : α → ZFSet.{u}) :
(range f).toSet = Set.range f := by
ext
simp
/-- Kuratowski ordered pair -/
def pair (x y : ZFSet.{u}) : ZFSet.{u} :=
{{x}, {x, y}}
@[simp]
theorem toSet_pair (x y : ZFSet.{u}) : (pair x y).toSet = {{x}, {x, y}} := by simp [pair]
/-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/
def pairSep (p : ZFSet.{u} → ZFSet.{u} → Prop) (x y : ZFSet.{u}) : ZFSet.{u} :=
(powerset (powerset (x ∪ y))).sep fun z => ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b
@[simp]
theorem mem_pairSep {p} {x y z : ZFSet.{u}} :
z ∈ pairSep p x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b := by
refine mem_sep.trans ⟨And.right, fun e => ⟨?_, e⟩⟩
rcases e with ⟨a, ax, b, bY, rfl, pab⟩
simp only [mem_powerset, subset_def, mem_union, pair, mem_pair]
rintro u (rfl | rfl) v <;> simp only [mem_singleton, mem_pair]
· rintro rfl
exact Or.inl ax
· rintro (rfl | rfl) <;> [left; right] <;> assumption
theorem pair_injective : Function.Injective2 pair := by
intro x x' y y' H
simp_rw [ZFSet.ext_iff, pair, mem_pair] at H
obtain rfl : x = x' := And.left <| by simpa [or_and_left] using (H {x}).1 (Or.inl rfl)
have he : y = x → y = y' := by
rintro rfl
simpa [eq_comm] using H {y, y'}
have hx := H {x, y}
simp_rw [pair_eq_singleton_iff, true_and, or_true, true_iff] at hx
refine ⟨rfl, hx.elim he fun hy ↦ Or.elim ?_ he id⟩
simpa using ZFSet.ext_iff.1 hy y
@[simp]
theorem pair_inj {x y x' y' : ZFSet} : pair x y = pair x' y' ↔ x = x' ∧ y = y' :=
pair_injective.eq_iff
/-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/
def prod : ZFSet.{u} → ZFSet.{u} → ZFSet.{u} :=
pairSep fun _ _ => True
@[simp]
theorem mem_prod {x y z : ZFSet.{u}} : z ∈ prod x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b := by
simp [prod]
theorem pair_mem_prod {x y a b : ZFSet.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y := by
simp
/-- `isFunc x y f` is the assertion that `f` is a subset of `x × y` which relates to each element
of `x` a unique element of `y`, so that we can consider `f` as a ZFC function `x → y`. -/
def IsFunc (x y f : ZFSet.{u}) : Prop :=
f ⊆ prod x y ∧ ∀ z : ZFSet.{u}, z ∈ x → ∃! w, pair z w ∈ f
/-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/
def funs (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (IsFunc x y) (powerset (prod x y))
@[simp]
theorem mem_funs {x y f : ZFSet.{u}} : f ∈ funs x y ↔ IsFunc x y f := by simp [funs, IsFunc]
instance : Definable₁ ({·}) := .mk ({·}) (fun _ ↦ rfl)
instance : Definable₂ insert := .mk insert (fun _ _ ↦ rfl)
instance : Definable₂ pair := by unfold pair; infer_instance
/-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/
def map (f : ZFSet → ZFSet) [Definable₁ f] : ZFSet → ZFSet :=
image fun y => pair y (f y)
@[simp]
theorem mem_map {f : ZFSet → ZFSet} [Definable₁ f] {x y : ZFSet} :
y ∈ map f x ↔ ∃ z ∈ x, pair z (f z) = y :=
mem_image
theorem map_unique {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f] {x z : ZFSet.{u}}
(zx : z ∈ x) : ∃! w, pair z w ∈ map f x :=
⟨f z, image.mk _ _ zx, fun y yx => by
let ⟨w, _, we⟩ := mem_image.1 yx
let ⟨wz, fy⟩ := pair_injective we
rw [← fy, wz]⟩
@[simp]
theorem map_isFunc {f : ZFSet → ZFSet} [Definable₁ f] {x y : ZFSet} :
IsFunc x y (map f x) ↔ ∀ z ∈ x, f z ∈ y :=
⟨fun ⟨ss, h⟩ z zx =>
let ⟨_, t1, t2⟩ := h z zx
(t2 (f z) (image.mk _ _ zx)).symm ▸ (pair_mem_prod.1 (ss t1)).right,
fun h =>
⟨fun _ yx =>
let ⟨z, zx, ze⟩ := mem_image.1 yx
ze ▸ pair_mem_prod.2 ⟨zx, h z zx⟩,
fun _ => map_unique⟩⟩
/-- Given a predicate `p` on ZFC sets. `Hereditarily p x` means that `x` has property `p` and the
members of `x` are all `Hereditarily p`. -/
def Hereditarily (p : ZFSet → Prop) (x : ZFSet) : Prop :=
p x ∧ ∀ y ∈ x, Hereditarily p y
termination_by x
section Hereditarily
variable {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}}
theorem hereditarily_iff : Hereditarily p x ↔ p x ∧ ∀ y ∈ x, Hereditarily p y := by
rw [← Hereditarily]
alias ⟨Hereditarily.def, _⟩ := hereditarily_iff
theorem Hereditarily.self (h : x.Hereditarily p) : p x :=
h.def.1
theorem Hereditarily.mem (h : x.Hereditarily p) (hy : y ∈ x) : y.Hereditarily p :=
h.def.2 _ hy
theorem Hereditarily.empty : Hereditarily p x → p ∅ := by
apply @ZFSet.inductionOn _ x
intro y IH h
rcases ZFSet.eq_empty_or_nonempty y with (rfl | ⟨a, ha⟩)
· exact h.self
· exact IH a ha (h.mem ha)
end Hereditarily
end ZFSet
| Mathlib/SetTheory/ZFC/Basic.lean | 1,308 | 1,309 | |
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.Calculus.BumpFunction.FiniteDimension
import Mathlib.Analysis.Calculus.BumpFunction.Normed
import Mathlib.MeasureTheory.Integral.Average
import Mathlib.MeasureTheory.Covering.Differentiation
import Mathlib.MeasureTheory.Covering.BesicovitchVectorSpace
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Convolution with a bump function
In this file we prove lemmas about convolutions `(φ.normed μ ⋆[lsmul ℝ ℝ, μ] g) x₀`,
where `φ : ContDiffBump 0` is a smooth bump function.
We prove that this convolution is equal to `g x₀`
if `g` is a constant on `Metric.ball x₀ φ.rOut`.
We also provide estimates in the case if `g x` is close to `g x₀` on this ball.
## Main results
- `ContDiffBump.convolution_tendsto_right_of_continuous`:
Let `g` be a continuous function; let `φ i` be a family of `ContDiffBump 0` functions with.
If `(φ i).rOut` tends to zero along a filter `l`,
then `((φ i).normed μ ⋆[lsmul ℝ ℝ, μ] g) x₀` tends to `g x₀` along the same filter.
- `ContDiffBump.convolution_tendsto_right`: generalization of the above lemma.
- `ContDiffBump.ae_convolution_tendsto_right_of_locallyIntegrable`: let `g` be a locally
integrable function. Then the convolution of `g` with a family of bump functions with
support tending to `0` converges almost everywhere to `g`.
## Keywords
convolution, smooth function, bump function
-/
universe uG uE'
open ContinuousLinearMap Metric MeasureTheory Filter Function Measure Set
open scoped Convolution Topology
namespace ContDiffBump
variable {G : Type uG} {E' : Type uE'} [NormedAddCommGroup E'] {g : G → E'} [MeasurableSpace G]
{μ : MeasureTheory.Measure G} [NormedSpace ℝ E'] [NormedAddCommGroup G] [NormedSpace ℝ G]
[CompleteSpace E'] {φ : ContDiffBump (0 : G)} {x₀ : G}
/-- If `φ` is a bump function, compute `(φ ⋆ g) x₀`
if `g` is constant on `Metric.ball x₀ φ.rOut`. -/
theorem convolution_eq_right [HasContDiffBump G] {x₀ : G} (hg : ∀ x ∈ ball x₀ φ.rOut, g x = g x₀) :
(φ ⋆[lsmul ℝ ℝ, μ] g : G → E') x₀ = integral μ φ • g x₀ := by
simp_rw [convolution_eq_right' _ φ.support_eq.subset hg, lsmul_apply, integral_smul_const]
variable [BorelSpace G] [FiniteDimensional ℝ G]
/-- If `φ` is a normed bump function, compute `φ ⋆ g`
if `g` is constant on `Metric.ball x₀ φ.rOut`. -/
theorem normed_convolution_eq_right [IsLocallyFiniteMeasure μ] [μ.IsOpenPosMeasure] {x₀ : G}
(hg : ∀ x ∈ ball x₀ φ.rOut, g x = g x₀) :
(φ.normed μ ⋆[lsmul ℝ ℝ, μ] g : G → E') x₀ = g x₀ := by
rw [convolution_eq_right' _ φ.support_normed_eq.subset hg]
| exact integral_normed_smul φ μ (g x₀)
variable [μ.IsAddHaarMeasure]
| Mathlib/Analysis/Calculus/BumpFunction/Convolution.lean | 65 | 68 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Data.Subtype
import Mathlib.Order.Defs.LinearOrder
import Mathlib.Order.Notation
import Mathlib.Tactic.GCongr.Core
import Mathlib.Tactic.Spread
import Mathlib.Tactic.Convert
import Mathlib.Tactic.Inhabit
import Mathlib.Tactic.SimpRw
/-!
# Basic definitions about `≤` and `<`
This file proves basic results about orders, provides extensive dot notation, defines useful order
classes and allows to transfer order instances.
## Type synonyms
* `OrderDual α` : A type synonym reversing the meaning of all inequalities, with notation `αᵒᵈ`.
* `AsLinearOrder α`: A type synonym to promote `PartialOrder α` to `LinearOrder α` using
`IsTotal α (≤)`.
### Transferring orders
- `Order.Preimage`, `Preorder.lift`: Transfers a (pre)order on `β` to an order on `α`
using a function `f : α → β`.
- `PartialOrder.lift`, `LinearOrder.lift`: Transfers a partial (resp., linear) order on `β` to a
partial (resp., linear) order on `α` using an injective function `f`.
### Extra class
* `DenselyOrdered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such
that `a < c < b`.
## Notes
`≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all
lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares
us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.
Dot notation is particularly useful on `≤` (`LE.le`) and `<` (`LT.lt`). To that end, we
provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with
`LE.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`,
`hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `LE.le.trans_lt` and can be used to construct
`hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`.
## TODO
- expand module docs
- automatic construction of dual definitions / theorems
## Tags
preorder, order, partial order, poset, linear order, chain
-/
open Function
variable {ι α β : Type*} {π : ι → Type*}
/-! ### Bare relations -/
attribute [ext] LE
protected lemma LE.le.ge [LE α] {x y : α} (h : x ≤ y) : y ≥ x := h
protected lemma GE.ge.le [LE α] {x y : α} (h : x ≥ y) : y ≤ x := h
protected lemma LT.lt.gt [LT α] {x y : α} (h : x < y) : y > x := h
protected lemma GT.gt.lt [LT α] {x y : α} (h : x > y) : y < x := h
/-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined
by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `RelEmbedding` (assuming `f`
is injective). -/
@[simp]
def Order.Preimage (f : α → β) (s : β → β → Prop) (x y : α) : Prop := s (f x) (f y)
@[inherit_doc] infixl:80 " ⁻¹'o " => Order.Preimage
/-- The preimage of a decidable order is decidable. -/
instance Order.Preimage.decidable (f : α → β) (s : β → β → Prop) [H : DecidableRel s] :
DecidableRel (f ⁻¹'o s) := fun _ _ ↦ H _ _
/-! ### Preorders -/
section Preorder
variable [Preorder α] {a b c d : α}
theorem le_trans' : b ≤ c → a ≤ b → a ≤ c :=
flip le_trans
theorem lt_trans' : b < c → a < b → a < c :=
flip lt_trans
theorem lt_of_le_of_lt' : b ≤ c → a < b → a < c :=
flip lt_of_lt_of_le
theorem lt_of_lt_of_le' : b < c → a ≤ b → a < c :=
flip lt_of_le_of_lt
theorem le_of_le_of_eq' : b ≤ c → a = b → a ≤ c :=
flip le_of_eq_of_le
theorem le_of_eq_of_le' : b = c → a ≤ b → a ≤ c :=
flip le_of_le_of_eq
theorem lt_of_lt_of_eq' : b < c → a = b → a < c :=
flip lt_of_eq_of_lt
theorem lt_of_eq_of_lt' : b = c → a < b → a < c :=
flip lt_of_lt_of_eq
theorem not_lt_iff_not_le_or_ge : ¬a < b ↔ ¬a ≤ b ∨ b ≤ a := by
rw [lt_iff_le_not_le, Classical.not_and_iff_not_or_not, Classical.not_not]
-- Unnecessary brackets are here for readability
lemma not_lt_iff_le_imp_le : ¬ a < b ↔ (a ≤ b → b ≤ a) := by
simp [not_lt_iff_not_le_or_ge, or_iff_not_imp_left]
/-- If `x = y` then `y ≤ x`. Note: this lemma uses `y ≤ x` instead of `x ≥ y`, because `le` is used
almost exclusively in mathlib. -/
lemma ge_of_eq (h : a = b) : b ≤ a := le_of_eq h.symm
@[simp] lemma lt_self_iff_false (x : α) : x < x ↔ False := ⟨lt_irrefl x, False.elim⟩
alias LE.le.trans := le_trans
alias LE.le.trans' := le_trans'
alias LT.lt.trans := lt_trans
alias LT.lt.trans' := lt_trans'
alias LE.le.trans_lt := lt_of_le_of_lt
alias LE.le.trans_lt' := lt_of_le_of_lt'
alias LT.lt.trans_le := lt_of_lt_of_le
alias LT.lt.trans_le' := lt_of_lt_of_le'
alias LE.le.trans_eq := le_of_le_of_eq
alias LE.le.trans_eq' := le_of_le_of_eq'
alias LT.lt.trans_eq := lt_of_lt_of_eq
alias LT.lt.trans_eq' := lt_of_lt_of_eq'
alias Eq.trans_le := le_of_eq_of_le
alias Eq.trans_ge := le_of_eq_of_le'
alias Eq.trans_lt := lt_of_eq_of_lt
alias Eq.trans_gt := lt_of_eq_of_lt'
alias LE.le.lt_of_not_le := lt_of_le_not_le
alias LE.le.lt_or_eq_dec := Decidable.lt_or_eq_of_le
alias LT.lt.le := le_of_lt
alias LT.lt.ne := ne_of_lt
alias Eq.le := le_of_eq
@[inherit_doc ge_of_eq] alias Eq.ge := ge_of_eq
alias LT.lt.asymm := lt_asymm
alias LT.lt.not_lt := lt_asymm
theorem ne_of_not_le (h : ¬a ≤ b) : a ≠ b := fun hab ↦ h (le_of_eq hab)
protected lemma Eq.not_lt (hab : a = b) : ¬a < b := fun h' ↦ h'.ne hab
protected lemma Eq.not_gt (hab : a = b) : ¬b < a := hab.symm.not_lt
@[simp] lemma le_of_subsingleton [Subsingleton α] : a ≤ b := (Subsingleton.elim a b).le
-- Making this a @[simp] lemma causes confluence problems downstream.
lemma not_lt_of_subsingleton [Subsingleton α] : ¬a < b := (Subsingleton.elim a b).not_lt
namespace LT.lt
protected theorem false : a < a → False := lt_irrefl a
theorem ne' (h : a < b) : b ≠ a := h.ne.symm
end LT.lt
theorem le_of_forall_le (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b := H _ le_rfl
theorem le_of_forall_ge (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a := H _ le_rfl
@[deprecated (since := "2025-01-30")] alias le_of_forall_le' := le_of_forall_ge
theorem forall_le_iff_le : (∀ ⦃c⦄, c ≤ a → c ≤ b) ↔ a ≤ b :=
⟨le_of_forall_le, fun h _ hca ↦ le_trans hca h⟩
theorem forall_le_iff_ge : (∀ ⦃c⦄, a ≤ c → b ≤ c) ↔ b ≤ a :=
⟨le_of_forall_ge, fun h _ hca ↦ le_trans h hca⟩
/-- monotonicity of `≤` with respect to `→` -/
theorem le_implies_le_of_le_of_le (hca : c ≤ a) (hbd : b ≤ d) : a ≤ b → c ≤ d :=
fun hab ↦ (hca.trans hab).trans hbd
end Preorder
/-! ### Partial order -/
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem ge_antisymm : a ≤ b → b ≤ a → b = a :=
flip le_antisymm
theorem lt_of_le_of_ne' : a ≤ b → b ≠ a → a < b := fun h₁ h₂ ↦ lt_of_le_of_ne h₁ h₂.symm
theorem Ne.lt_of_le : a ≠ b → a ≤ b → a < b :=
flip lt_of_le_of_ne
theorem Ne.lt_of_le' : b ≠ a → a ≤ b → a < b :=
flip lt_of_le_of_ne'
alias LE.le.antisymm := le_antisymm
alias LE.le.antisymm' := ge_antisymm
alias LE.le.lt_of_ne := lt_of_le_of_ne
alias LE.le.lt_of_ne' := lt_of_le_of_ne'
alias LE.le.lt_or_eq := lt_or_eq_of_le
-- Unnecessary brackets are here for readability
lemma le_imp_eq_iff_le_imp_le : (a ≤ b → b = a) ↔ (a ≤ b → b ≤ a) where
mp h hab := (h hab).le
mpr h hab := (h hab).antisymm hab
-- Unnecessary brackets are here for readability
lemma ge_imp_eq_iff_le_imp_le : (a ≤ b → a = b) ↔ (a ≤ b → b ≤ a) where
mp h hab := (h hab).ge
mpr h hab := hab.antisymm (h hab)
namespace LE.le
theorem lt_iff_ne (h : a ≤ b) : a < b ↔ a ≠ b :=
⟨fun h ↦ h.ne, h.lt_of_ne⟩
theorem gt_iff_ne (h : a ≤ b) : a < b ↔ b ≠ a :=
⟨fun h ↦ h.ne.symm, h.lt_of_ne'⟩
theorem not_lt_iff_eq (h : a ≤ b) : ¬a < b ↔ a = b :=
h.lt_iff_ne.not_left
theorem not_gt_iff_eq (h : a ≤ b) : ¬a < b ↔ b = a :=
h.gt_iff_ne.not_left
theorem le_iff_eq (h : a ≤ b) : b ≤ a ↔ b = a :=
⟨fun h' ↦ h'.antisymm h, Eq.le⟩
theorem ge_iff_eq (h : a ≤ b) : b ≤ a ↔ a = b :=
⟨h.antisymm, Eq.ge⟩
end LE.le
-- See Note [decidable namespace]
protected theorem Decidable.le_iff_eq_or_lt [DecidableLE α] : a ≤ b ↔ a = b ∨ a < b :=
Decidable.le_iff_lt_or_eq.trans or_comm
theorem le_iff_eq_or_lt : a ≤ b ↔ a = b ∨ a < b := le_iff_lt_or_eq.trans or_comm
theorem lt_iff_le_and_ne : a < b ↔ a ≤ b ∧ a ≠ b :=
⟨fun h ↦ ⟨le_of_lt h, ne_of_lt h⟩, fun ⟨h1, h2⟩ ↦ h1.lt_of_ne h2⟩
lemma eq_iff_not_lt_of_le (hab : a ≤ b) : a = b ↔ ¬ a < b := by simp [hab, lt_iff_le_and_ne]
alias LE.le.eq_iff_not_lt := eq_iff_not_lt_of_le
-- See Note [decidable namespace]
protected theorem Decidable.eq_iff_le_not_lt [DecidableLE α] : a = b ↔ a ≤ b ∧ ¬a < b :=
⟨fun h ↦ ⟨h.le, h ▸ lt_irrefl _⟩, fun ⟨h₁, h₂⟩ ↦
h₁.antisymm <| Decidable.byContradiction fun h₃ ↦ h₂ (h₁.lt_of_not_le h₃)⟩
theorem eq_iff_le_not_lt : a = b ↔ a ≤ b ∧ ¬a < b :=
haveI := Classical.dec
Decidable.eq_iff_le_not_lt
theorem eq_or_lt_of_le (h : a ≤ b) : a = b ∨ a < b := h.lt_or_eq.symm
theorem eq_or_gt_of_le (h : a ≤ b) : b = a ∨ a < b := h.lt_or_eq.symm.imp Eq.symm id
theorem gt_or_eq_of_le (h : a ≤ b) : a < b ∨ b = a := (eq_or_gt_of_le h).symm
alias LE.le.eq_or_lt_dec := Decidable.eq_or_lt_of_le
alias LE.le.eq_or_lt := eq_or_lt_of_le
alias LE.le.eq_or_gt := eq_or_gt_of_le
alias LE.le.gt_or_eq := gt_or_eq_of_le
theorem eq_of_le_of_not_lt (hab : a ≤ b) (hba : ¬a < b) : a = b := hab.eq_or_lt.resolve_right hba
theorem eq_of_ge_of_not_gt (hab : a ≤ b) (hba : ¬a < b) : b = a := (eq_of_le_of_not_lt hab hba).symm
alias LE.le.eq_of_not_lt := eq_of_le_of_not_lt
alias LE.le.eq_of_not_gt := eq_of_ge_of_not_gt
theorem Ne.le_iff_lt (h : a ≠ b) : a ≤ b ↔ a < b := ⟨fun h' ↦ lt_of_le_of_ne h' h, fun h ↦ h.le⟩
theorem Ne.not_le_or_not_le (h : a ≠ b) : ¬a ≤ b ∨ ¬b ≤ a := not_and_or.1 <| le_antisymm_iff.not.1 h
-- See Note [decidable namespace]
protected theorem Decidable.ne_iff_lt_iff_le [DecidableEq α] : (a ≠ b ↔ a < b) ↔ a ≤ b :=
⟨fun h ↦ Decidable.byCases le_of_eq (le_of_lt ∘ h.mp), fun h ↦ ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩
@[simp]
theorem ne_iff_lt_iff_le : (a ≠ b ↔ a < b) ↔ a ≤ b :=
haveI := Classical.dec
Decidable.ne_iff_lt_iff_le
lemma eq_of_forall_le_iff (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b :=
((H _).1 le_rfl).antisymm ((H _).2 le_rfl)
lemma eq_of_forall_ge_iff (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b :=
((H _).2 le_rfl).antisymm ((H _).1 le_rfl)
/-- To prove commutativity of a binary operation `○`, we only to check `a ○ b ≤ b ○ a` for all `a`,
`b`. -/
lemma commutative_of_le {f : β → β → α} (comm : ∀ a b, f a b ≤ f b a) : ∀ a b, f a b = f b a :=
fun _ _ ↦ (comm _ _).antisymm <| comm _ _
/-- To prove associativity of a commutative binary operation `○`, we only to check
`(a ○ b) ○ c ≤ a ○ (b ○ c)` for all `a`, `b`, `c`. -/
lemma associative_of_commutative_of_le {f : α → α → α} (comm : Std.Commutative f)
(assoc : ∀ a b c, f (f a b) c ≤ f a (f b c)) : Std.Associative f where
assoc a b c :=
le_antisymm (assoc _ _ _) <| by
rw [comm.comm, comm.comm b, comm.comm _ c, comm.comm a]
exact assoc ..
end PartialOrder
section LinearOrder
variable [LinearOrder α] {a b : α}
namespace LE.le
lemma lt_or_le (h : a ≤ b) (c : α) : a < c ∨ c ≤ b := (lt_or_ge a c).imp id h.trans'
lemma le_or_lt (h : a ≤ b) (c : α) : a ≤ c ∨ c < b := (le_or_gt a c).imp id h.trans_lt'
lemma le_or_le (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b := (h.lt_or_le c).imp le_of_lt id
end LE.le
namespace LT.lt
lemma lt_or_lt (h : a < b) (c : α) : a < c ∨ c < b := (le_or_gt b c).imp h.trans_le id
end LT.lt
-- Variant of `min_def` with the branches reversed.
theorem min_def' (a b : α) : min a b = if b ≤ a then b else a := by
rw [min_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
-- Variant of `min_def` with the branches reversed.
-- This is sometimes useful as it used to be the default.
theorem max_def' (a b : α) : max a b = if b ≤ a then a else b := by
rw [max_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
theorem lt_of_not_le (h : ¬b ≤ a) : a < b :=
((le_total _ _).resolve_right h).lt_of_not_le h
theorem lt_iff_not_le : a < b ↔ ¬b ≤ a :=
⟨not_le_of_lt, lt_of_not_le⟩
theorem Ne.lt_or_lt (h : a ≠ b) : a < b ∨ b < a :=
lt_or_gt_of_ne h
/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/
@[simp]
theorem lt_or_lt_iff_ne : a < b ∨ b < a ↔ a ≠ b :=
ne_iff_lt_or_gt.symm
theorem not_lt_iff_eq_or_lt : ¬a < b ↔ a = b ∨ b < a :=
not_lt.trans <| Decidable.le_iff_eq_or_lt.trans <| or_congr eq_comm Iff.rfl
theorem exists_ge_of_linear (a b : α) : ∃ c, a ≤ c ∧ b ≤ c :=
match le_total a b with
| Or.inl h => ⟨_, h, le_rfl⟩
| Or.inr h => ⟨_, le_rfl, h⟩
lemma exists_forall_ge_and {p q : α → Prop} :
(∃ i, ∀ j ≥ i, p j) → (∃ i, ∀ j ≥ i, q j) → ∃ i, ∀ j ≥ i, p j ∧ q j
| ⟨a, ha⟩, ⟨b, hb⟩ =>
let ⟨c, hac, hbc⟩ := exists_ge_of_linear a b
⟨c, fun _d hcd ↦ ⟨ha _ <| hac.trans hcd, hb _ <| hbc.trans hcd⟩⟩
theorem le_of_forall_lt (H : ∀ c, c < a → c < b) : a ≤ b :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
theorem forall_lt_iff_le : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b :=
⟨le_of_forall_lt, fun h _ hca ↦ lt_of_lt_of_le hca h⟩
theorem le_of_forall_lt' (H : ∀ c, a < c → b < c) : b ≤ a :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
theorem forall_lt_iff_le' : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a :=
⟨le_of_forall_lt', fun h _ hac ↦ lt_of_le_of_lt h hac⟩
theorem eq_of_forall_lt_iff (h : ∀ c, c < a ↔ c < b) : a = b :=
(le_of_forall_lt fun _ ↦ (h _).1).antisymm <| le_of_forall_lt fun _ ↦ (h _).2
theorem eq_of_forall_gt_iff (h : ∀ c, a < c ↔ b < c) : a = b :=
(le_of_forall_lt' fun _ ↦ (h _).2).antisymm <| le_of_forall_lt' fun _ ↦ (h _).1
section ltByCases
variable {P : Sort*} {x y : α}
@[simp]
lemma ltByCases_lt (h : x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₁ h := dif_pos h
@[simp]
lemma ltByCases_gt (h : y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₃ h := (dif_neg h.not_lt).trans (dif_pos h)
@[simp]
lemma ltByCases_eq (h : x = y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₂ h := (dif_neg h.not_lt).trans (dif_neg h.not_gt)
lemma ltByCases_not_lt (h : ¬ x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ y < x → x = y := fun h' => (le_antisymm (le_of_not_gt h') (le_of_not_gt h))) :
ltByCases x y h₁ h₂ h₃ = if h' : y < x then h₃ h' else h₂ (p h') := dif_neg h
lemma ltByCases_not_gt (h : ¬ y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → x = y := fun h' => (le_antisymm (le_of_not_gt h) (le_of_not_gt h'))) :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₂ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_neg h)
lemma ltByCases_ne (h : x ≠ y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → y < x := fun h' => h.lt_or_lt.resolve_left h') :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₃ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_pos _)
lemma ltByCases_comm {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : y = x → x = y := fun h' => h'.symm) :
ltByCases x y h₁ h₂ h₃ = ltByCases y x h₃ (h₂ ∘ p) h₁ := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt h, ltByCases_gt h]
· rw [ltByCases_eq h, ltByCases_eq h.symm, comp_apply]
· rw [ltByCases_lt h, ltByCases_gt h]
lemma eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt {x' y' : α}
(ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) :
x = y ↔ x' = y' := by simp_rw [eq_iff_le_not_lt, ← not_lt, ltc, gtc]
lemma ltByCases_rec {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : P)
(hlt : (h : x < y) → h₁ h = p) (heq : (h : x = y) → h₂ h = p)
(hgt : (h : y < x) → h₃ h = p) :
ltByCases x y h₁ h₂ h₃ = p :=
ltByCases x y
(fun h => ltByCases_lt h ▸ hlt h)
(fun h => ltByCases_eq h ▸ heq h)
(fun h => ltByCases_gt h ▸ hgt h)
lemma ltByCases_eq_iff {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {p : P} :
ltByCases x y h₁ h₂ h₃ = p ↔ (∃ h, h₁ h = p) ∨ (∃ h, h₂ h = p) ∨ (∃ h, h₃ h = p) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltByCases_lt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, or_false, h.ne]
· simp only [h, lt_self_iff_false, ltByCases_eq, not_false_eq_true,
exists_prop_of_false, exists_prop_of_true, or_false, false_or]
· simp only [ltByCases_gt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, false_or, h.ne']
lemma ltByCases_congr {x' y' : α} {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
{h₁' : x' < y' → P} {h₂' : x' = y' → P} {h₃' : y' < x' → P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : ∀ (h : x' < y'), h₁ (ltc.mpr h) = h₁' h)
(hh'₂ : ∀ (h : x' = y'), h₂ ((eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc).mpr h) = h₂' h)
(hh'₃ : ∀ (h : y' < x'), h₃ (gtc.mpr h) = h₃' h) :
ltByCases x y h₁ h₂ h₃ = ltByCases x' y' h₁' h₂' h₃' := by
refine ltByCases_rec _ (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt (ltc.mp h), hh'₁]
· rw [eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc] at h
rw [ltByCases_eq h, hh'₂]
· rw [ltByCases_gt (gtc.mp h), hh'₃]
/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order,
non-dependently. -/
abbrev ltTrichotomy (x y : α) (p q r : P) := ltByCases x y (fun _ => p) (fun _ => q) (fun _ => r)
variable {p q r s : P}
@[simp]
lemma ltTrichotomy_lt (h : x < y) : ltTrichotomy x y p q r = p := ltByCases_lt h
@[simp]
lemma ltTrichotomy_gt (h : y < x) : ltTrichotomy x y p q r = r := ltByCases_gt h
@[simp]
lemma ltTrichotomy_eq (h : x = y) : ltTrichotomy x y p q r = q := ltByCases_eq h
lemma ltTrichotomy_not_lt (h : ¬ x < y) :
ltTrichotomy x y p q r = if y < x then r else q := ltByCases_not_lt h
lemma ltTrichotomy_not_gt (h : ¬ y < x) :
ltTrichotomy x y p q r = if x < y then p else q := ltByCases_not_gt h
lemma ltTrichotomy_ne (h : x ≠ y) :
ltTrichotomy x y p q r = if x < y then p else r := ltByCases_ne h
lemma ltTrichotomy_comm : ltTrichotomy x y p q r = ltTrichotomy y x r q p := ltByCases_comm
lemma ltTrichotomy_self {p : P} : ltTrichotomy x y p p p = p :=
ltByCases_rec p (fun _ => rfl) (fun _ => rfl) (fun _ => rfl)
lemma ltTrichotomy_eq_iff : ltTrichotomy x y p q r = s ↔
(x < y ∧ p = s) ∨ (x = y ∧ q = s) ∨ (y < x ∧ r = s) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltTrichotomy_lt, false_and, true_and, or_false, h, h.not_lt, h.ne]
· simp only [ltTrichotomy_eq, false_and, true_and, or_false, false_or, h, lt_irrefl]
· simp only [ltTrichotomy_gt, false_and, true_and, false_or, h, h.not_lt, h.ne']
lemma ltTrichotomy_congr {x' y' : α} {p' q' r' : P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : x' < y' → p = p')
(hh'₂ : x' = y' → q = q') (hh'₃ : y' < x' → r = r') :
ltTrichotomy x y p q r = ltTrichotomy x' y' p' q' r' :=
ltByCases_congr ltc gtc hh'₁ hh'₂ hh'₃
end ltByCases
/-! #### `min`/`max` recursors -/
section MinMaxRec
variable {p : α → Prop}
lemma min_rec (ha : a ≤ b → p a) (hb : b ≤ a → p b) : p (min a b) := by
obtain hab | hba := le_total a b <;> simp [min_eq_left, min_eq_right, *]
lemma max_rec (ha : b ≤ a → p a) (hb : a ≤ b → p b) : p (max a b) := by
obtain hab | hba := le_total a b <;> simp [max_eq_left, max_eq_right, *]
lemma min_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (min a b) :=
min_rec (fun _ ↦ ha) fun _ ↦ hb
lemma max_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (max a b) :=
max_rec (fun _ ↦ ha) fun _ ↦ hb
lemma min_def_lt (a b : α) : min a b = if a < b then a else b := by
rw [min_comm, min_def, ← ite_not]; simp only [not_le]
lemma max_def_lt (a b : α) : max a b = if a < b then b else a := by
rw [max_comm, max_def, ← ite_not]; simp only [not_le]
end MinMaxRec
end LinearOrder
/-! ### Implications -/
lemma lt_imp_lt_of_le_imp_le {β} [LinearOrder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b → c ≤ d) (h : d < c) : b < a :=
lt_of_not_le fun h' ↦ (H h').not_lt h
lemma le_imp_le_iff_lt_imp_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
a ≤ b → c ≤ d ↔ d < c → b < a :=
⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩
lemma lt_iff_lt_of_le_iff_le' {β} [Preorder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c :=
lt_iff_le_not_le.trans <| (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm
lemma lt_iff_lt_of_le_iff_le {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c := not_le.symm.trans <| (not_congr H).trans <| not_le
lemma le_iff_le_iff_lt_iff_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
(a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) :=
⟨lt_iff_lt_of_le_iff_le, fun H ↦ not_lt.symm.trans <| (not_congr H).trans <| not_lt⟩
/-- A symmetric relation implies two values are equal, when it implies they're less-equal. -/
lemma rel_imp_eq_of_rel_imp_le [PartialOrder β] (r : α → α → Prop) [IsSymm α r] {f : α → β}
(h : ∀ a b, r a b → f a ≤ f b) {a b : α} : r a b → f a = f b := fun hab ↦
le_antisymm (h a b hab) (h b a <| symm hab)
/-! ### Extensionality lemmas -/
@[ext]
lemma Preorder.toLE_injective : Function.Injective (@Preorder.toLE α) :=
fun
| { lt := A_lt, lt_iff_le_not_le := A_iff, .. },
{ lt := B_lt, lt_iff_le_not_le := B_iff, .. } => by
rintro ⟨⟩
have : A_lt = B_lt := by
funext a b
rw [A_iff, B_iff]
cases this
congr
@[ext]
lemma PartialOrder.toPreorder_injective : Function.Injective (@PartialOrder.toPreorder α) := by
rintro ⟨⟩ ⟨⟩ ⟨⟩; congr
@[ext]
lemma LinearOrder.toPartialOrder_injective : Function.Injective (@LinearOrder.toPartialOrder α) :=
fun
| { le := A_le, lt := A_lt,
toDecidableLE := A_decidableLE, toDecidableEq := A_decidableEq, toDecidableLT := A_decidableLT
min := A_min, max := A_max, min_def := A_min_def, max_def := A_max_def,
compare := A_compare, compare_eq_compareOfLessAndEq := A_compare_canonical, .. },
{ le := B_le, lt := B_lt,
toDecidableLE := B_decidableLE, toDecidableEq := B_decidableEq, toDecidableLT := B_decidableLT
min := B_min, max := B_max, min_def := B_min_def, max_def := B_max_def,
compare := B_compare, compare_eq_compareOfLessAndEq := B_compare_canonical, .. } => by
rintro ⟨⟩
obtain rfl : A_decidableLE = B_decidableLE := Subsingleton.elim _ _
obtain rfl : A_decidableEq = B_decidableEq := Subsingleton.elim _ _
obtain rfl : A_decidableLT = B_decidableLT := Subsingleton.elim _ _
have : A_min = B_min := by
funext a b
exact (A_min_def _ _).trans (B_min_def _ _).symm
cases this
have : A_max = B_max := by
funext a b
exact (A_max_def _ _).trans (B_max_def _ _).symm
cases this
have : A_compare = B_compare := by
funext a b
exact (A_compare_canonical _ _).trans (B_compare_canonical _ _).symm
congr
lemma Preorder.ext {A B : Preorder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y; exact H x y
lemma PartialOrder.ext {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by ext x y; exact H x y
lemma PartialOrder.ext_lt {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) :
A = B := by ext x y; rw [le_iff_lt_or_eq, @le_iff_lt_or_eq _ A, H]
lemma LinearOrder.ext {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by ext x y; exact H x y
lemma LinearOrder.ext_lt {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) :
A = B := LinearOrder.toPartialOrder_injective (PartialOrder.ext_lt H)
/-! ### Order dual -/
/-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. `αᵒᵈ` is
notation for `OrderDual α`. -/
def OrderDual (α : Type*) : Type _ :=
α
@[inherit_doc]
notation:max α "ᵒᵈ" => OrderDual α
namespace OrderDual
instance (α : Type*) [h : Nonempty α] : Nonempty αᵒᵈ :=
h
instance (α : Type*) [h : Subsingleton α] : Subsingleton αᵒᵈ :=
h
instance (α : Type*) [LE α] : LE αᵒᵈ :=
⟨fun x y : α ↦ y ≤ x⟩
instance (α : Type*) [LT α] : LT αᵒᵈ :=
⟨fun x y : α ↦ y < x⟩
instance instOrd (α : Type*) [Ord α] : Ord αᵒᵈ where
compare := fun (a b : α) ↦ compare b a
instance instSup (α : Type*) [Min α] : Max αᵒᵈ :=
⟨((· ⊓ ·) : α → α → α)⟩
instance instInf (α : Type*) [Max α] : Min αᵒᵈ :=
⟨((· ⊔ ·) : α → α → α)⟩
instance instPreorder (α : Type*) [Preorder α] : Preorder αᵒᵈ where
le_refl := fun _ ↦ le_refl _
le_trans := fun _ _ _ hab hbc ↦ hbc.trans hab
lt_iff_le_not_le := fun _ _ ↦ lt_iff_le_not_le
instance instPartialOrder (α : Type*) [PartialOrder α] : PartialOrder αᵒᵈ where
__ := inferInstanceAs (Preorder αᵒᵈ)
le_antisymm := fun a b hab hba ↦ @le_antisymm α _ a b hba hab
instance instLinearOrder (α : Type*) [LinearOrder α] : LinearOrder αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
__ := inferInstanceAs (Ord αᵒᵈ)
le_total := fun a b : α ↦ le_total b a
max := fun a b ↦ (min a b : α)
min := fun a b ↦ (max a b : α)
min_def := fun a b ↦ show (max .. : α) = _ by rw [max_comm, max_def]; rfl
max_def := fun a b ↦ show (min .. : α) = _ by rw [min_comm, min_def]; rfl
toDecidableLE := (inferInstance : DecidableRel (fun a b : α ↦ b ≤ a))
toDecidableLT := (inferInstance : DecidableRel (fun a b : α ↦ b < a))
toDecidableEq := (inferInstance : DecidableEq α)
compare_eq_compareOfLessAndEq a b := by
simp only [compare, LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq, eq_comm]
rfl
/-- The opposite linear order to a given linear order -/
def _root_.LinearOrder.swap (α : Type*) (_ : LinearOrder α) : LinearOrder α :=
inferInstanceAs <| LinearOrder (OrderDual α)
instance : ∀ [Inhabited α], Inhabited αᵒᵈ := fun [x : Inhabited α] => x
theorem Ord.dual_dual (α : Type*) [H : Ord α] : OrderDual.instOrd αᵒᵈ = H :=
rfl
theorem Preorder.dual_dual (α : Type*) [H : Preorder α] : OrderDual.instPreorder αᵒᵈ = H :=
rfl
theorem instPartialOrder.dual_dual (α : Type*) [H : PartialOrder α] :
OrderDual.instPartialOrder αᵒᵈ = H :=
rfl
theorem instLinearOrder.dual_dual (α : Type*) [H : LinearOrder α] :
OrderDual.instLinearOrder αᵒᵈ = H :=
rfl
end OrderDual
/-! ### `HasCompl` -/
instance Prop.hasCompl : HasCompl Prop :=
⟨Not⟩
instance Pi.hasCompl [∀ i, HasCompl (π i)] : HasCompl (∀ i, π i) :=
⟨fun x i ↦ (x i)ᶜ⟩
theorem Pi.compl_def [∀ i, HasCompl (π i)] (x : ∀ i, π i) :
xᶜ = fun i ↦ (x i)ᶜ :=
rfl
@[simp]
theorem Pi.compl_apply [∀ i, HasCompl (π i)] (x : ∀ i, π i) (i : ι) :
xᶜ i = (x i)ᶜ :=
rfl
instance IsIrrefl.compl (r) [IsIrrefl α r] : IsRefl α rᶜ :=
⟨@irrefl α r _⟩
instance IsRefl.compl (r) [IsRefl α r] : IsIrrefl α rᶜ :=
⟨fun a ↦ not_not_intro (refl a)⟩
theorem compl_lt [LinearOrder α] : (· < · : α → α → _)ᶜ = (· ≥ ·) := by ext; simp [compl]
theorem compl_le [LinearOrder α] : (· ≤ · : α → α → _)ᶜ = (· > ·) := by ext; simp [compl]
theorem compl_gt [LinearOrder α] : (· > · : α → α → _)ᶜ = (· ≤ ·) := by ext; simp [compl]
theorem compl_ge [LinearOrder α] : (· ≥ · : α → α → _)ᶜ = (· < ·) := by ext; simp [compl]
instance Ne.instIsEquiv_compl : IsEquiv α (· ≠ ·)ᶜ := by
convert eq_isEquiv α
simp [compl]
/-! ### Order instances on the function space -/
instance Pi.hasLe [∀ i, LE (π i)] :
LE (∀ i, π i) where le x y := ∀ i, x i ≤ y i
theorem Pi.le_def [∀ i, LE (π i)] {x y : ∀ i, π i} :
x ≤ y ↔ ∀ i, x i ≤ y i :=
Iff.rfl
instance Pi.preorder [∀ i, Preorder (π i)] : Preorder (∀ i, π i) where
__ := inferInstanceAs (LE (∀ i, π i))
le_refl := fun a i ↦ le_refl (a i)
le_trans := fun _ _ _ h₁ h₂ i ↦ le_trans (h₁ i) (h₂ i)
theorem Pi.lt_def [∀ i, Preorder (π i)] {x y : ∀ i, π i} :
x < y ↔ x ≤ y ∧ ∃ i, x i < y i := by
simp +contextual [lt_iff_le_not_le, Pi.le_def]
instance Pi.partialOrder [∀ i, PartialOrder (π i)] : PartialOrder (∀ i, π i) where
__ := Pi.preorder
le_antisymm := fun _ _ h1 h2 ↦ funext fun b ↦ (h1 b).antisymm (h2 b)
namespace Sum
variable {α₁ α₂ : Type*} [LE β]
@[simp]
lemma elim_le_elim_iff {u₁ v₁ : α₁ → β} {u₂ v₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Sum.elim v₁ v₂ ↔ u₁ ≤ v₁ ∧ u₂ ≤ v₂ :=
Sum.forall
lemma const_le_elim_iff {b : β} {v₁ : α₁ → β} {v₂ : α₂ → β} :
Function.const _ b ≤ Sum.elim v₁ v₂ ↔ Function.const _ b ≤ v₁ ∧ Function.const _ b ≤ v₂ :=
elim_const_const b ▸ elim_le_elim_iff ..
lemma elim_le_const_iff {b : β} {u₁ : α₁ → β} {u₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Function.const _ b ↔ u₁ ≤ Function.const _ b ∧ u₂ ≤ Function.const _ b :=
elim_const_const b ▸ elim_le_elim_iff ..
end Sum
section Pi
/-- A function `a` is strongly less than a function `b` if `a i < b i` for all `i`. -/
def StrongLT [∀ i, LT (π i)] (a b : ∀ i, π i) : Prop :=
∀ i, a i < b i
@[inherit_doc]
local infixl:50 " ≺ " => StrongLT
variable [∀ i, Preorder (π i)] {a b c : ∀ i, π i}
theorem le_of_strongLT (h : a ≺ b) : a ≤ b := fun _ ↦ (h _).le
theorem lt_of_strongLT [Nonempty ι] (h : a ≺ b) : a < b := by
inhabit ι
exact Pi.lt_def.2 ⟨le_of_strongLT h, default, h _⟩
theorem strongLT_of_strongLT_of_le (hab : a ≺ b) (hbc : b ≤ c) : a ≺ c := fun _ ↦
(hab _).trans_le <| hbc _
theorem strongLT_of_le_of_strongLT (hab : a ≤ b) (hbc : b ≺ c) : a ≺ c := fun _ ↦
(hab _).trans_lt <| hbc _
alias StrongLT.le := le_of_strongLT
alias StrongLT.lt := lt_of_strongLT
alias StrongLT.trans_le := strongLT_of_strongLT_of_le
alias LE.le.trans_strongLT := strongLT_of_le_of_strongLT
end Pi
section Function
variable [DecidableEq ι] [∀ i, Preorder (π i)] {x y : ∀ i, π i} {i : ι} {a b : π i}
theorem le_update_iff : x ≤ Function.update y i a ↔ x i ≤ a ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ x j ≤ z
theorem update_le_iff : Function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ z ≤ y j
theorem update_le_update_iff :
Function.update x i a ≤ Function.update y i b ↔ a ≤ b ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := by
simp +contextual [update_le_iff]
@[simp]
theorem update_le_update_iff' : update x i a ≤ update x i b ↔ a ≤ b := by
simp [update_le_update_iff]
@[simp]
theorem update_lt_update_iff : update x i a < update x i b ↔ a < b :=
lt_iff_lt_of_le_iff_le' update_le_update_iff' update_le_update_iff'
@[simp]
theorem le_update_self_iff : x ≤ update x i a ↔ x i ≤ a := by simp [le_update_iff]
@[simp]
theorem update_le_self_iff : update x i a ≤ x ↔ a ≤ x i := by simp [update_le_iff]
@[simp]
theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_not_le]
@[simp]
theorem update_lt_self_iff : update x i a < x ↔ a < x i := by simp [lt_iff_le_not_le]
end Function
instance Pi.sdiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) :=
⟨fun x y i ↦ x i \ y i⟩
theorem Pi.sdiff_def [∀ i, SDiff (π i)] (x y : ∀ i, π i) :
x \ y = fun i ↦ x i \ y i :=
rfl
@[simp]
theorem Pi.sdiff_apply [∀ i, SDiff (π i)] (x y : ∀ i, π i) (i : ι) :
(x \ y) i = x i \ y i :=
rfl
namespace Function
variable [Preorder α] [Nonempty β] {a b : α}
@[simp]
theorem const_le_const : const β a ≤ const β b ↔ a ≤ b := by simp [Pi.le_def]
@[simp]
theorem const_lt_const : const β a < const β b ↔ a < b := by simpa [Pi.lt_def] using le_of_lt
end Function
/-! ### Lifts of order instances -/
/-- Transfer a `Preorder` on `β` to a `Preorder` on `α` using a function `f : α → β`.
See note [reducible non-instances]. -/
abbrev Preorder.lift [Preorder β] (f : α → β) : Preorder α where
le x y := f x ≤ f y
le_refl _ := le_rfl
le_trans _ _ _ := _root_.le_trans
lt x y := f x < f y
lt_iff_le_not_le _ _ := _root_.lt_iff_le_not_le
/-- Transfer a `PartialOrder` on `β` to a `PartialOrder` on `α` using an injective
function `f : α → β`. See note [reducible non-instances]. -/
abbrev PartialOrder.lift [PartialOrder β] (f : α → β) (inj : Injective f) : PartialOrder α :=
{ Preorder.lift f with le_antisymm := fun _ _ h₁ h₂ ↦ inj (h₁.antisymm h₂) }
theorem compare_of_injective_eq_compareOfLessAndEq (a b : α) [LinearOrder β]
[DecidableEq α] (f : α → β) (inj : Injective f)
[Decidable (LT.lt (self := PartialOrder.lift f inj |>.toLT) a b)] :
compare (f a) (f b) =
@compareOfLessAndEq _ a b (PartialOrder.lift f inj |>.toLT) _ _ := by
have h := LinearOrder.compare_eq_compareOfLessAndEq (f a) (f b)
simp only [h, compareOfLessAndEq]
split_ifs <;> try (first | rfl | contradiction)
· have : ¬ f a = f b := by rename_i h; exact inj.ne h
contradiction
· have : f a = f b := by rename_i h; exact congrArg f h
contradiction
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses
them for `max` and `min` fields. See `LinearOrder.lift'` for a version that autogenerates `min` and
`max` fields, and `LinearOrder.liftWithOrd` for one that does not auto-generate `compare`
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.lift [LinearOrder β] [Max α] [Min α] (f : α → β) (inj : Injective f)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrder α :=
letI instOrdα : Ord α := ⟨fun a b ↦ compare (f a) (f b)⟩
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj, instOrdα with
le_total := fun x y ↦ le_total (f x) (f y)
toDecidableLE := decidableLE
toDecidableLT := decidableLT
toDecidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version autogenerates `min` and `max` fields. See `LinearOrder.lift`
for a version that takes `[Max α]` and `[Min α]`, then uses them as `max` and `min`. See
`LinearOrder.liftWithOrd'` for a version which does not auto-generate `compare` fields.
See note [reducible non-instances]. -/
abbrev LinearOrder.lift' [LinearOrder β] (f : α → β) (inj : Injective f) : LinearOrder α :=
@LinearOrder.lift α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm) fun _ _ ↦
(apply_ite f _ _ _).trans (min_def _ _).symm
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses
them for `max` and `min` fields. It also takes `[Ord α]` as an argument and uses them for `compare`
fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and
`LinearOrder.liftWithOrd'` for one that auto-generates `min` and `max` fields.
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd [LinearOrder β] [Max α] [Min α] [Ord α] (f : α → β)
(inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y))
(hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y))
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj with
le_total := fun x y ↦ le_total (f x) (f y)
toDecidableLE := decidableLE
toDecidableLT := decidableLT
toDecidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
(compare_f a b).trans <| compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version auto-generates `min` and `max` fields. It also takes `[Ord α]`
as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that
autogenerates `compare` fields, and `LinearOrder.liftWithOrd` for one that doesn't auto-generate
`min` and `max` fields. fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd' [LinearOrder β] [Ord α] (f : α → β)
(inj : Injective f)
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
@LinearOrder.liftWithOrd α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ _ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm)
(fun _ _ ↦ (apply_ite f _ _ _).trans (min_def _ _).symm)
compare_f
/-! ### Subtype of an order -/
namespace Subtype
instance le [LE α] {p : α → Prop} : LE (Subtype p) :=
⟨fun x y ↦ (x : α) ≤ y⟩
instance lt [LT α] {p : α → Prop} : LT (Subtype p) :=
⟨fun x y ↦ (x : α) < y⟩
@[simp]
theorem mk_le_mk [LE α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : Subtype p) ≤ ⟨y, hy⟩ ↔ x ≤ y :=
Iff.rfl
@[simp]
theorem mk_lt_mk [LT α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : Subtype p) < ⟨y, hy⟩ ↔ x < y :=
Iff.rfl
@[simp, norm_cast]
theorem coe_le_coe [LE α] {p : α → Prop} {x y : Subtype p} : (x : α) ≤ y ↔ x ≤ y :=
Iff.rfl
@[gcongr] alias ⟨_, GCongr.coe_le_coe⟩ := coe_le_coe
@[simp, norm_cast]
theorem coe_lt_coe [LT α] {p : α → Prop} {x y : Subtype p} : (x : α) < y ↔ x < y :=
Iff.rfl
@[gcongr] alias ⟨_, GCongr.coe_lt_coe⟩ := coe_lt_coe
instance preorder [Preorder α] (p : α → Prop) : Preorder (Subtype p) :=
Preorder.lift (fun (a : Subtype p) ↦ (a : α))
instance partialOrder [PartialOrder α] (p : α → Prop) : PartialOrder (Subtype p) :=
PartialOrder.lift (fun (a : Subtype p) ↦ (a : α)) Subtype.coe_injective
instance decidableLE [Preorder α] [h : DecidableLE α] {p : α → Prop} :
DecidableLE (Subtype p) := fun a b ↦ h a b
instance decidableLT [Preorder α] [h : DecidableLT α] {p : α → Prop} :
DecidableLT (Subtype p) := fun a b ↦ h a b
/-- A subtype of a linear order is a linear order. We explicitly give the proofs of decidable
equality and decidable order in order to ensure the decidability instances are all definitionally
equal. -/
instance instLinearOrder [LinearOrder α] (p : α → Prop) : LinearOrder (Subtype p) :=
@LinearOrder.lift (Subtype p) _ _ ⟨fun x y ↦ ⟨max x y, max_rec' _ x.2 y.2⟩⟩
⟨fun x y ↦ ⟨min x y, min_rec' _ x.2 y.2⟩⟩ (fun (a : Subtype p) ↦ (a : α))
Subtype.coe_injective (fun _ _ ↦ rfl) fun _ _ ↦
rfl
end Subtype
/-!
### Pointwise order on `α × β`
The lexicographic order is defined in `Data.Prod.Lex`, and the instances are available via the
type synonym `α ×ₗ β = α × β`.
-/
namespace Prod
section LE
variable [LE α] [LE β] {x y : α × β} {a a₁ a₂ : α} {b b₁ b₂ : β}
instance : LE (α × β) where le p q := p.1 ≤ q.1 ∧ p.2 ≤ q.2
instance instDecidableLE [Decidable (x.1 ≤ y.1)] [Decidable (x.2 ≤ y.2)] : Decidable (x ≤ y) :=
inferInstanceAs (Decidable (x.1 ≤ y.1 ∧ x.2 ≤ y.2))
lemma le_def : x ≤ y ↔ x.1 ≤ y.1 ∧ x.2 ≤ y.2 := .rfl
@[simp] lemma mk_le_mk : (a₁, b₁) ≤ (a₂, b₂) ↔ a₁ ≤ a₂ ∧ b₁ ≤ b₂ := .rfl
@[simp] lemma swap_le_swap : x.swap ≤ y.swap ↔ x ≤ y := and_comm
@[simp] lemma swap_le_mk : x.swap ≤ (b, a) ↔ x ≤ (a, b) := and_comm
@[simp] lemma mk_le_swap : (b, a) ≤ x.swap ↔ (a, b) ≤ x := and_comm
end LE
section Preorder
variable [Preorder α] [Preorder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β}
instance : Preorder (α × β) where
__ := inferInstanceAs (LE (α × β))
le_refl := fun ⟨a, b⟩ ↦ ⟨le_refl a, le_refl b⟩
le_trans := fun ⟨_, _⟩ ⟨_, _⟩ ⟨_, _⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩ ↦ ⟨le_trans hac hce, le_trans hbd hdf⟩
@[simp]
theorem swap_lt_swap : x.swap < y.swap ↔ x < y :=
and_congr swap_le_swap (not_congr swap_le_swap)
@[simp] lemma swap_lt_mk : x.swap < (b, a) ↔ x < (a, b) := by rw [← swap_lt_swap]; simp
@[simp] lemma mk_lt_swap : (b, a) < x.swap ↔ (a, b) < x := by rw [← swap_lt_swap]; simp
theorem mk_le_mk_iff_left : (a₁, b) ≤ (a₂, b) ↔ a₁ ≤ a₂ :=
and_iff_left le_rfl
theorem mk_le_mk_iff_right : (a, b₁) ≤ (a, b₂) ↔ b₁ ≤ b₂ :=
and_iff_right le_rfl
theorem mk_lt_mk_iff_left : (a₁, b) < (a₂, b) ↔ a₁ < a₂ :=
lt_iff_lt_of_le_iff_le' mk_le_mk_iff_left mk_le_mk_iff_left
theorem mk_lt_mk_iff_right : (a, b₁) < (a, b₂) ↔ b₁ < b₂ :=
lt_iff_lt_of_le_iff_le' mk_le_mk_iff_right mk_le_mk_iff_right
theorem lt_iff : x < y ↔ x.1 < y.1 ∧ x.2 ≤ y.2 ∨ x.1 ≤ y.1 ∧ x.2 < y.2 := by
refine ⟨fun h ↦ ?_, ?_⟩
· by_cases h₁ : y.1 ≤ x.1
· exact Or.inr ⟨h.1.1, LE.le.lt_of_not_le h.1.2 fun h₂ ↦ h.2 ⟨h₁, h₂⟩⟩
· exact Or.inl ⟨LE.le.lt_of_not_le h.1.1 h₁, h.1.2⟩
· rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩)
· exact ⟨⟨h₁.le, h₂⟩, fun h ↦ h₁.not_le h.1⟩
· exact ⟨⟨h₁, h₂.le⟩, fun h ↦ h₂.not_le h.2⟩
@[simp]
theorem mk_lt_mk : (a₁, b₁) < (a₂, b₂) ↔ a₁ < a₂ ∧ b₁ ≤ b₂ ∨ a₁ ≤ a₂ ∧ b₁ < b₂ :=
lt_iff
protected lemma lt_of_lt_of_le (h₁ : x.1 < y.1) (h₂ : x.2 ≤ y.2) : x < y := by simp [lt_iff, *]
protected lemma lt_of_le_of_lt (h₁ : x.1 ≤ y.1) (h₂ : x.2 < y.2) : x < y := by simp [lt_iff, *]
lemma mk_lt_mk_of_lt_of_le (h₁ : a₁ < a₂) (h₂ : b₁ ≤ b₂) : (a₁, b₁) < (a₂, b₂) := by
simp [lt_iff, *]
lemma mk_lt_mk_of_le_of_lt (h₁ : a₁ ≤ a₂) (h₂ : b₁ < b₂) : (a₁, b₁) < (a₂, b₂) := by
simp [lt_iff, *]
end Preorder
/-- The pointwise partial order on a product.
(The lexicographic ordering is defined in `Order.Lexicographic`, and the instances are
available via the type synonym `α ×ₗ β = α × β`.) -/
instance instPartialOrder (α β : Type*) [PartialOrder α] [PartialOrder β] :
PartialOrder (α × β) where
__ := inferInstanceAs (Preorder (α × β))
le_antisymm := fun _ _ ⟨hac, hbd⟩ ⟨hca, hdb⟩ ↦ Prod.ext (hac.antisymm hca) (hbd.antisymm hdb)
end Prod
/-! ### Additional order classes -/
/-- An order is dense if there is an element between any pair of distinct comparable elements. -/
class DenselyOrdered (α : Type*) [LT α] : Prop where
/-- An order is dense if there is an element between any pair of distinct elements. -/
dense : ∀ a₁ a₂ : α, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂
theorem exists_between [LT α] [DenselyOrdered α] : ∀ {a₁ a₂ : α}, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ :=
DenselyOrdered.dense _ _
instance OrderDual.denselyOrdered (α : Type*) [LT α] [h : DenselyOrdered α] :
DenselyOrdered αᵒᵈ :=
⟨fun _ _ ha ↦ (@exists_between α _ h _ _ ha).imp fun _ ↦ And.symm⟩
@[simp]
theorem denselyOrdered_orderDual [LT α] : DenselyOrdered αᵒᵈ ↔ DenselyOrdered α :=
⟨by convert @OrderDual.denselyOrdered αᵒᵈ _, @OrderDual.denselyOrdered α _⟩
/-- Any ordered subsingleton is densely ordered. Not an instance to avoid a heavy subsingleton
typeclass search. -/
lemma Subsingleton.instDenselyOrdered {X : Type*} [Subsingleton X] [Preorder X] :
DenselyOrdered X :=
⟨fun _ _ h ↦ (not_lt_of_subsingleton h).elim⟩
instance [Preorder α] [Preorder β] [DenselyOrdered α] [DenselyOrdered β] : DenselyOrdered (α × β) :=
⟨fun a b ↦ by
simp_rw [Prod.lt_iff]
rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩)
· obtain ⟨c, ha, hb⟩ := exists_between h₁
exact ⟨(c, _), Or.inl ⟨ha, h₂⟩, Or.inl ⟨hb, le_rfl⟩⟩
· obtain ⟨c, ha, hb⟩ := exists_between h₂
exact ⟨(_, c), Or.inr ⟨h₁, ha⟩, Or.inr ⟨le_rfl, hb⟩⟩⟩
instance [∀ i, Preorder (π i)] [∀ i, DenselyOrdered (π i)] :
DenselyOrdered (∀ i, π i) :=
⟨fun a b ↦ by
classical
simp_rw [Pi.lt_def]
rintro ⟨hab, i, hi⟩
obtain ⟨c, ha, hb⟩ := exists_between hi
exact
⟨Function.update a i c,
⟨le_update_iff.2 ⟨ha.le, fun _ _ ↦ le_rfl⟩, i, by rwa [update_self]⟩,
update_le_iff.2 ⟨hb.le, fun _ _ ↦ hab _⟩, i, by rwa [update_self]⟩⟩
section LinearOrder
variable [LinearOrder α] [DenselyOrdered α] {a₁ a₂ : α}
theorem le_of_forall_gt_imp_ge_of_dense (h : ∀ a, a₂ < a → a₁ ≤ a) : a₁ ≤ a₂ :=
le_of_not_gt fun ha ↦
let ⟨a, ha₁, ha₂⟩ := exists_between ha
lt_irrefl a <| lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›)
lemma forall_gt_imp_ge_iff_le_of_dense : (∀ a, a₂ < a → a₁ ≤ a) ↔ a₁ ≤ a₂ :=
⟨le_of_forall_gt_imp_ge_of_dense, fun ha _a ha₂ ↦ ha.trans ha₂.le⟩
lemma eq_of_le_of_forall_lt_imp_le_of_dense (h₁ : a₂ ≤ a₁) (h₂ : ∀ a, a₂ < a → a₁ ≤ a) : a₁ = a₂ :=
le_antisymm (le_of_forall_gt_imp_ge_of_dense h₂) h₁
theorem le_of_forall_lt_imp_le_of_dense (h : ∀ a < a₁, a ≤ a₂) : a₁ ≤ a₂ :=
le_of_not_gt fun ha ↦
let ⟨a, ha₁, ha₂⟩ := exists_between ha
lt_irrefl a <| lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a›
lemma forall_lt_imp_le_iff_le_of_dense : (∀ a < a₁, a ≤ a₂) ↔ a₁ ≤ a₂ :=
⟨le_of_forall_lt_imp_le_of_dense, fun ha _a ha₁ ↦ ha₁.le.trans ha⟩
theorem eq_of_le_of_forall_gt_imp_ge_of_dense (h₁ : a₂ ≤ a₁) (h₂ : ∀ a < a₁, a ≤ a₂) : a₁ = a₂ :=
(le_of_forall_lt_imp_le_of_dense h₂).antisymm h₁
@[deprecated (since := "2025-01-21")]
alias le_of_forall_le_of_dense := le_of_forall_gt_imp_ge_of_dense
@[deprecated (since := "2025-01-21")]
alias le_of_forall_ge_of_dense := le_of_forall_lt_imp_le_of_dense
@[deprecated (since := "2025-01-21")] alias forall_lt_le_iff := forall_lt_imp_le_iff_le_of_dense
@[deprecated (since := "2025-01-21")] alias forall_gt_ge_iff := forall_gt_imp_ge_iff_le_of_dense
@[deprecated (since := "2025-01-21")]
alias eq_of_le_of_forall_le_of_dense := eq_of_le_of_forall_lt_imp_le_of_dense
@[deprecated (since := "2025-01-21")]
alias eq_of_le_of_forall_ge_of_dense := eq_of_le_of_forall_gt_imp_ge_of_dense
end LinearOrder
theorem dense_or_discrete [LinearOrder α] (a₁ a₂ : α) :
(∃ a, a₁ < a ∧ a < a₂) ∨ (∀ a, a₁ < a → a₂ ≤ a) ∧ ∀ a < a₂, a ≤ a₁ :=
or_iff_not_imp_left.2 fun h ↦
⟨fun a ha₁ ↦ le_of_not_gt fun ha₂ ↦ h ⟨a, ha₁, ha₂⟩,
fun a ha₂ ↦ le_of_not_gt fun ha₁ ↦ h ⟨a, ha₁, ha₂⟩⟩
/-- If a linear order has no elements `x < y < z`, then it has at most two elements. -/
lemma eq_or_eq_or_eq_of_forall_not_lt_lt [LinearOrder α]
(h : ∀ ⦃x y z : α⦄, x < y → y < z → False) (x y z : α) : x = y ∨ y = z ∨ x = z := by
by_contra hne
simp only [not_or, ← Ne.eq_def] at hne
rcases hne.1.lt_or_lt with h₁ | h₁ <;>
rcases hne.2.1.lt_or_lt with h₂ | h₂ <;>
rcases hne.2.2.lt_or_lt with h₃ | h₃
exacts [h h₁ h₂, h h₂ h₃, h h₃ h₂, h h₃ h₁, h h₁ h₃, h h₂ h₃, h h₁ h₃, h h₂ h₁]
namespace PUnit
variable (a b : PUnit)
instance instLinearOrder : LinearOrder PUnit where
le := fun _ _ ↦ True
lt := fun _ _ ↦ False
max := fun _ _ ↦ unit
min := fun _ _ ↦ unit
toDecidableEq := inferInstance
toDecidableLE := fun _ _ ↦ Decidable.isTrue trivial
toDecidableLT := fun _ _ ↦ Decidable.isFalse id
le_refl := by intros; trivial
le_trans := by intros; trivial
le_total := by intros; exact Or.inl trivial
le_antisymm := by intros; rfl
lt_iff_le_not_le := by simp only [not_true, and_false, forall_const]
theorem max_eq : max a b = unit :=
rfl
theorem min_eq : min a b = unit :=
rfl
protected theorem le : a ≤ b :=
trivial
theorem not_lt : ¬a < b :=
not_false
instance : DenselyOrdered PUnit :=
⟨fun _ _ ↦ False.elim⟩
end PUnit
section «Prop»
/-- Propositions form a complete boolean algebra, where the `≤` relation is given by implication. -/
instance Prop.le : LE Prop :=
⟨(· → ·)⟩
@[simp]
theorem le_Prop_eq : ((· ≤ ·) : Prop → Prop → Prop) = (· → ·) :=
rfl
theorem subrelation_iff_le {r s : α → α → Prop} : Subrelation r s ↔ r ≤ s :=
Iff.rfl
instance Prop.partialOrder : PartialOrder Prop where
__ := Prop.le
le_refl _ := id
le_trans _ _ _ f g := g ∘ f
le_antisymm _ _ Hab Hba := propext ⟨Hab, Hba⟩
end «Prop»
/-! ### Linear order from a total partial order -/
/-- Type synonym to create an instance of `LinearOrder` from a `PartialOrder` and `IsTotal α (≤)` -/
def AsLinearOrder (α : Type*) :=
α
instance [Inhabited α] : Inhabited (AsLinearOrder α) :=
⟨(default : α)⟩
noncomputable instance AsLinearOrder.linearOrder [PartialOrder α] [IsTotal α (· ≤ ·)] :
LinearOrder (AsLinearOrder α) where
__ := inferInstanceAs (PartialOrder α)
le_total := @total_of α (· ≤ ·) _
toDecidableLE := Classical.decRel _
| Mathlib/Order/Basic.lean | 1,343 | 1,344 | |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Mario Carneiro
-/
import Mathlib.Algebra.Field.IsField
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.LinearAlgebra.Finsupp.LinearCombination
import Mathlib.RingTheory.Ideal.Maximal
import Mathlib.Tactic.FinCases
/-!
# Ideals over a ring
This file contains an assortment of definitions and results for `Ideal R`,
the type of (left) ideals over a ring `R`.
Note that over commutative rings, left ideals and two-sided ideals are equivalent.
## Implementation notes
`Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
variable {ι α β F : Type*}
open Set Function
open Pointwise
section Semiring
namespace Ideal
variable {α : ι → Type*} [Π i, Semiring (α i)] (I : Π i, Ideal (α i))
section Pi
/-- `Πᵢ Iᵢ` as an ideal of `Πᵢ Rᵢ`. -/
def pi : Ideal (Π i, α i) where
carrier := { x | ∀ i, x i ∈ I i }
zero_mem' i := (I i).zero_mem
add_mem' ha hb i := (I i).add_mem (ha i) (hb i)
smul_mem' a _b hb i := (I i).mul_mem_left (a i) (hb i)
theorem mem_pi (x : Π i, α i) : x ∈ pi I ↔ ∀ i, x i ∈ I i :=
Iff.rfl
instance (priority := low) [∀ i, (I i).IsTwoSided] : (pi I).IsTwoSided :=
⟨fun _b hb i ↦ mul_mem_right _ _ (hb i)⟩
end Pi
section Commute
variable {α : Type*} [Semiring α] (I : Ideal α) {a b : α}
theorem add_pow_mem_of_pow_mem_of_le_of_commute {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1)
(hab : Commute a b) :
(a + b) ^ k ∈ I := by
simp_rw [hab.add_pow, ← Nat.cast_comm]
apply I.sum_mem
intro c _
apply mul_mem_left
by_cases h : m ≤ c
· rw [hab.pow_pow]
exact I.mul_mem_left _ (I.pow_mem_of_pow_mem ha h)
· refine I.mul_mem_left _ (I.pow_mem_of_pow_mem hb ?_)
omega
theorem add_pow_add_pred_mem_of_pow_mem_of_commute {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hab : Commute a b) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb (by rw [← Nat.sub_le_iff_le_add]) hab
end Commute
end Ideal
end Semiring
section CommSemiring
variable {a b : α}
-- A separate namespace definition is needed because the variables were historically in a different
-- order.
namespace Ideal
variable [CommSemiring α] (I : Ideal α)
theorem add_pow_mem_of_pow_mem_of_le {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1) :
(a + b) ^ k ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb hk (Commute.all ..)
theorem add_pow_add_pred_mem_of_pow_mem {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_add_pred_mem_of_pow_mem_of_commute ha hb (Commute.all ..)
theorem pow_multiset_sum_mem_span_pow [DecidableEq α] (s : Multiset α) (n : ℕ) :
s.sum ^ (Multiset.card s * n + 1) ∈
span ((s.map fun (x : α) ↦ x ^ (n + 1)).toFinset : Set α) := by
induction' s using Multiset.induction_on with a s hs
· simp
simp only [Finset.coe_insert, Multiset.map_cons, Multiset.toFinset_cons, Multiset.sum_cons,
Multiset.card_cons, add_pow]
refine Submodule.sum_mem _ ?_
intro c _hc
rw [mem_span_insert]
by_cases h : n + 1 ≤ c
· refine ⟨a ^ (c - (n + 1)) * s.sum ^ ((Multiset.card s + 1) * n + 1 - c) *
((Multiset.card s + 1) * n + 1).choose c, 0, Submodule.zero_mem _, ?_⟩
rw [mul_comm _ (a ^ (n + 1))]
simp_rw [← mul_assoc]
rw [← pow_add, add_zero, add_tsub_cancel_of_le h]
· use 0
simp_rw [zero_mul, zero_add]
refine ⟨_, ?_, rfl⟩
replace h : c ≤ n := Nat.lt_succ_iff.mp (not_le.mp h)
have : (Multiset.card s + 1) * n + 1 - c = Multiset.card s * n + 1 + (n - c) := by
rw [add_mul, one_mul, add_assoc, add_comm n 1, ← add_assoc, add_tsub_assoc_of_le h]
rw [this, pow_add]
simp_rw [mul_assoc, mul_comm (s.sum ^ (Multiset.card s * n + 1)), ← mul_assoc]
exact mul_mem_left _ _ hs
theorem sum_pow_mem_span_pow {ι} (s : Finset ι) (f : ι → α) (n : ℕ) :
(∑ i ∈ s, f i) ^ (s.card * n + 1) ∈ span ((fun i => f i ^ (n + 1)) '' s) := by
classical
simpa only [Multiset.card_map, Multiset.map_map, comp_apply, Multiset.toFinset_map,
Finset.coe_image, Finset.val_toFinset] using pow_multiset_sum_mem_span_pow (s.1.map f) n
theorem span_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : ℕ) :
span ((fun (x : α) => x ^ n) '' s) = ⊤ := by
rw [eq_top_iff_one]
rcases n with - | n
· obtain rfl | ⟨x, hx⟩ := eq_empty_or_nonempty s
· rw [Set.image_empty, hs]
trivial
· exact subset_span ⟨_, hx, pow_zero _⟩
rw [eq_top_iff_one, span, Finsupp.mem_span_iff_linearCombination] at hs
rcases hs with ⟨f, hf⟩
have hf : (f.support.sum fun a => f a * a) = 1 := hf -- Porting note: was `change ... at hf`
have := sum_pow_mem_span_pow f.support (fun a => f a * a) n
rw [hf, one_pow] at this
refine span_le.mpr ?_ this
rintro _ hx
simp_rw [Set.mem_image] at hx
rcases hx with ⟨x, _, rfl⟩
have : span ({(x : α) ^ (n + 1)} : Set α) ≤ span ((fun x : α => x ^ (n + 1)) '' s) := by
rw [span_le, Set.singleton_subset_iff]
exact subset_span ⟨x, x.prop, rfl⟩
refine this ?_
rw [mul_pow, mem_span_singleton]
exact ⟨f x ^ (n + 1), mul_comm _ _⟩
theorem span_range_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : s → ℕ) :
span (Set.range fun x ↦ x.1 ^ n x) = ⊤ := by
have ⟨t, hts, mem⟩ := Submodule.mem_span_finite_of_mem_span ((eq_top_iff_one _).mp hs)
refine top_unique ((span_pow_eq_top _ ((eq_top_iff_one _).mpr mem) <|
t.attach.sup fun x ↦ n ⟨x, hts x.2⟩).ge.trans <| span_le.mpr ?_)
rintro _ ⟨x, hxt, rfl⟩
rw [← Nat.sub_add_cancel (Finset.le_sup <| t.mem_attach ⟨x, hxt⟩)]
simp_rw [pow_add]
exact mul_mem_left _ _ (subset_span ⟨_, rfl⟩)
theorem prod_mem {ι : Type*} {f : ι → α} {s : Finset ι}
(I : Ideal α) {i : ι} (hi : i ∈ s) (hfi : f i ∈ I) :
∏ i ∈ s, f i ∈ I := by
classical
rw [Finset.prod_eq_prod_diff_singleton_mul hi]
exact Ideal.mul_mem_left _ _ hfi
end Ideal
end CommSemiring
section DivisionSemiring
variable {K : Type*} [DivisionSemiring K] (I : Ideal K)
namespace Ideal
variable (K) in
/-- A bijection between (left) ideals of a division ring and `{0, 1}`, sending `⊥` to `0`
and `⊤` to `1`. -/
def equivFinTwo [DecidableEq (Ideal K)] : Ideal K ≃ Fin 2 where
toFun := fun I ↦ if I = ⊥ then 0 else 1
invFun := ![⊥, ⊤]
left_inv := fun I ↦ by rcases eq_bot_or_top I with rfl | rfl <;> simp
right_inv := fun i ↦ by fin_cases i <;> simp
instance : Finite (Ideal K) := let _i := Classical.decEq (Ideal K); ⟨equivFinTwo K⟩
/-- Ideals of a `DivisionSemiring` are a simple order. Thanks to the way abbreviations work,
this automatically gives an `IsSimpleModule K` instance. -/
instance isSimpleOrder : IsSimpleOrder (Ideal K) :=
⟨eq_bot_or_top⟩
end Ideal
end DivisionSemiring
-- TODO: consider moving the lemmas below out of the `Ring` namespace since they are
-- about `CommSemiring`s.
namespace Ring
variable {R : Type*} [CommSemiring R]
theorem exists_not_isUnit_of_not_isField [Nontrivial R] (hf : ¬IsField R) :
∃ (x : R) (_hx : x ≠ (0 : R)), ¬IsUnit x := by
have : ¬_ := fun h => hf ⟨exists_pair_ne R, mul_comm, h⟩
simp_rw [isUnit_iff_exists_inv]
push_neg at this ⊢
obtain ⟨x, hx, not_unit⟩ := this
exact ⟨x, hx, not_unit⟩
theorem not_isField_iff_exists_ideal_bot_lt_and_lt_top [Nontrivial R] :
¬IsField R ↔ ∃ I : Ideal R, ⊥ < I ∧ I < ⊤ := by
constructor
· intro h
obtain ⟨x, nz, nu⟩ := exists_not_isUnit_of_not_isField h
use Ideal.span {x}
rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top]
exact ⟨mt Ideal.span_singleton_eq_bot.mp nz, mt Ideal.span_singleton_eq_top.mp nu⟩
· rintro ⟨I, bot_lt, lt_top⟩ hf
obtain ⟨x, mem, ne_zero⟩ := SetLike.exists_of_lt bot_lt
rw [Submodule.mem_bot] at ne_zero
obtain ⟨y, hy⟩ := hf.mul_inv_cancel ne_zero
rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, ← hy] at lt_top
exact lt_top (I.mul_mem_right _ mem)
theorem not_isField_iff_exists_prime [Nontrivial R] :
¬IsField R ↔ ∃ p : Ideal R, p ≠ ⊥ ∧ p.IsPrime :=
not_isField_iff_exists_ideal_bot_lt_and_lt_top.trans
⟨fun ⟨I, bot_lt, lt_top⟩ =>
let ⟨p, hp, le_p⟩ := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top)
⟨p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.isPrime⟩,
fun ⟨p, ne_bot, Prime⟩ => ⟨p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr Prime.1⟩⟩
/-- Also see `Ideal.isSimpleOrder` for the forward direction as an instance when `R` is a
division (semi)ring.
This result actually holds for all division semirings, but we lack the predicate to state it. -/
theorem isField_iff_isSimpleOrder_ideal : IsField R ↔ IsSimpleOrder (Ideal R) := by
cases subsingleton_or_nontrivial R
· exact
⟨fun h => (not_isField_of_subsingleton _ h).elim, fun h =>
(false_of_nontrivial_of_subsingleton <| Ideal R).elim⟩
rw [← not_iff_not, Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top, ← not_iff_not]
push_neg
simp_rw [lt_top_iff_ne_top, bot_lt_iff_ne_bot, ← or_iff_not_imp_left, not_ne_iff]
exact ⟨fun h => ⟨h⟩, fun h => h.2⟩
/-- When a ring is not a field, the maximal ideals are nontrivial. -/
theorem ne_bot_of_isMaximal_of_not_isField [Nontrivial R] {M : Ideal R} (max : M.IsMaximal)
(not_field : ¬IsField R) : M ≠ ⊥ := by
rintro h
rw [h] at max
rcases max with ⟨⟨_h1, h2⟩⟩
obtain ⟨I, hIbot, hItop⟩ := not_isField_iff_exists_ideal_bot_lt_and_lt_top.mp not_field
exact ne_of_lt hItop (h2 I hIbot)
end Ring
namespace Ideal
variable {R : Type*} [CommSemiring R] [Nontrivial R]
theorem bot_lt_of_maximal (M : Ideal R) [hm : M.IsMaximal] (non_field : ¬IsField R) : ⊥ < M := by
rcases Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top.1 non_field with ⟨I, Ibot, Itop⟩
constructor; · simp
intro mle
apply lt_irrefl (⊤ : Ideal R)
have : M = ⊥ := eq_bot_iff.mpr mle
rw [← this] at Ibot
rwa [hm.1.2 I Ibot] at Itop
end Ideal
| Mathlib/RingTheory/Ideal/Basic.lean | 751 | 759 | |
/-
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.Data.Set.Operations
import Mathlib.Order.Basic
import Mathlib.Order.BooleanAlgebra
import Mathlib.Tactic.Tauto
import Mathlib.Tactic.ByContra
import Mathlib.Util.Delaborators
import Mathlib.Tactic.Lift
/-!
# 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 module `Mathlib.Data.Set.Defs`.
This file provides some basic definitions related to sets and functions not present in the
definitions file, as well as extra lemmas for functions defined in the definitions file and
`Mathlib.Data.Set.Operations` (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
-/
assert_not_exists RelIso
/-! ### Set coercion to a type -/
open Function
universe u v
namespace Set
variable {α : Type u} {s t : Set α}
instance instBooleanAlgebra : 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
@[simp]
theorem bot_eq_empty : (⊥ : Set α) = ∅ :=
rfl
@[simp]
theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) :=
rfl
@[simp]
theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) :=
rfl
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) :=
rfl
@[simp]
theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) :=
rfl
theorem le_iff_subset : s ≤ t ↔ s ⊆ t :=
Iff.rfl
theorem lt_iff_ssubset : s < t ↔ s ⊂ t :=
Iff.rfl
alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset
alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset
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
instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiSetCoe.canLift ι (fun _ => α) s
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
@[simp]
theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } :=
rfl
theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
theorem SetCoe.exists {s : Set α} {p : s → Prop} :
(∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.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
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
@[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
theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b :=
Subtype.eq
theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
Iff.intro SetCoe.ext fun h => h ▸ rfl
end SetCoe
/-- See also `Subtype.prop` -/
theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s :=
p.prop
/-- 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₂
namespace Set
variable {α : Type u} {β : Type v} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α}
instance : Inhabited (Set α) :=
⟨∅⟩
@[trans]
theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t :=
h hx
theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by
tauto
theorem setOf_injective : Function.Injective (@setOf α) := injective_id
theorem setOf_inj {p q : α → Prop} : { x | p x } = { x | q x } ↔ p = q := Iff.rfl
/-! ### Lemmas about `mem` and `setOf` -/
theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a :=
Iff.rfl
/-- This lemma is intended for use with `rw` where a membership predicate is needed,
hence the explicit argument and the equality in the reverse direction from normal.
See also `Set.mem_setOf_eq` for the reverse direction applied to an argument. -/
theorem eq_mem_setOf (p : α → Prop) : p = (· ∈ {a | p a}) := rfl
/-- 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
| Mathlib/Data/Set/Basic.lean | 215 | 216 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov, Eric Wieser
-/
import Mathlib.Analysis.Calculus.FDeriv.Linear
import Mathlib.Analysis.Calculus.FDeriv.Comp
/-!
# Derivative of the cartesian product of functions
For detailed documentation of the Fréchet derivative,
see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`.
This file contains the usual formulas (and existence assertions) for the derivative of
cartesian products of functions, and functions into Pi-types.
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G']
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable (e : E →L[𝕜] F)
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
section CartesianProduct
/-! ### Derivative of the cartesian product of two functions -/
section Prod
variable {f₂ : E → G} {f₂' : E →L[𝕜] G}
protected theorem HasStrictFDerivAt.prodMk (hf₁ : HasStrictFDerivAt f₁ f₁' x)
(hf₂ : HasStrictFDerivAt f₂ f₂' x) :
HasStrictFDerivAt (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') x :=
.of_isLittleO <| hf₁.isLittleO.prod_left hf₂.isLittleO
@[deprecated (since := "2025-03-09")]
alias HasStrictFDerivAt.prod := HasStrictFDerivAt.prodMk
theorem HasFDerivAtFilter.prodMk (hf₁ : HasFDerivAtFilter f₁ f₁' x L)
(hf₂ : HasFDerivAtFilter f₂ f₂' x L) :
HasFDerivAtFilter (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') x L :=
.of_isLittleO <| hf₁.isLittleO.prod_left hf₂.isLittleO
@[deprecated (since := "2025-03-09")]
alias HasFDerivAtFilter.prod := HasFDerivAtFilter.prodMk
@[fun_prop]
nonrec theorem HasFDerivWithinAt.prodMk (hf₁ : HasFDerivWithinAt f₁ f₁' s x)
(hf₂ : HasFDerivWithinAt f₂ f₂' s x) :
HasFDerivWithinAt (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') s x :=
hf₁.prodMk hf₂
@[deprecated (since := "2025-03-09")]
alias HasFDerivWithinAt.prod := HasFDerivWithinAt.prodMk
@[fun_prop]
nonrec theorem HasFDerivAt.prodMk (hf₁ : HasFDerivAt f₁ f₁' x) (hf₂ : HasFDerivAt f₂ f₂' x) :
HasFDerivAt (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') x :=
hf₁.prodMk hf₂
@[deprecated (since := "2025-03-09")]
alias HasFDerivAt.prod := HasFDerivAt.prodMk
@[fun_prop]
theorem hasFDerivAt_prodMk_left (e₀ : E) (f₀ : F) :
HasFDerivAt (fun e : E => (e, f₀)) (inl 𝕜 E F) e₀ :=
(hasFDerivAt_id e₀).prodMk (hasFDerivAt_const f₀ e₀)
@[deprecated (since := "2025-03-09")]
alias hasFDerivAt_prod_mk_left := hasFDerivAt_prodMk_left
@[fun_prop]
theorem hasFDerivAt_prodMk_right (e₀ : E) (f₀ : F) :
HasFDerivAt (fun f : F => (e₀, f)) (inr 𝕜 E F) f₀ :=
(hasFDerivAt_const e₀ f₀).prodMk (hasFDerivAt_id f₀)
@[deprecated (since := "2025-03-09")]
alias hasFDerivAt_prod_mk_right := hasFDerivAt_prodMk_right
@[fun_prop]
theorem DifferentiableWithinAt.prodMk (hf₁ : DifferentiableWithinAt 𝕜 f₁ s x)
(hf₂ : DifferentiableWithinAt 𝕜 f₂ s x) :
DifferentiableWithinAt 𝕜 (fun x : E => (f₁ x, f₂ x)) s x :=
(hf₁.hasFDerivWithinAt.prodMk hf₂.hasFDerivWithinAt).differentiableWithinAt
@[deprecated (since := "2025-03-09")]
alias DifferentiableWithinAt.prod := DifferentiableWithinAt.prodMk
@[simp, fun_prop]
theorem DifferentiableAt.prodMk (hf₁ : DifferentiableAt 𝕜 f₁ x) (hf₂ : DifferentiableAt 𝕜 f₂ x) :
DifferentiableAt 𝕜 (fun x : E => (f₁ x, f₂ x)) x :=
(hf₁.hasFDerivAt.prodMk hf₂.hasFDerivAt).differentiableAt
@[deprecated (since := "2025-03-09")]
alias DifferentiableAt.prod := DifferentiableAt.prodMk
@[fun_prop]
theorem DifferentiableOn.prodMk (hf₁ : DifferentiableOn 𝕜 f₁ s) (hf₂ : DifferentiableOn 𝕜 f₂ s) :
DifferentiableOn 𝕜 (fun x : E => (f₁ x, f₂ x)) s := fun x hx => (hf₁ x hx).prodMk (hf₂ x hx)
@[deprecated (since := "2025-03-09")]
alias DifferentiableOn.prod := DifferentiableOn.prodMk
@[simp, fun_prop]
theorem Differentiable.prodMk (hf₁ : Differentiable 𝕜 f₁) (hf₂ : Differentiable 𝕜 f₂) :
Differentiable 𝕜 fun x : E => (f₁ x, f₂ x) := fun x ↦
(hf₁ x).prodMk (hf₂ x)
@[deprecated (since := "2025-03-09")]
alias Differentiable.prod := Differentiable.prodMk
theorem DifferentiableAt.fderiv_prodMk (hf₁ : DifferentiableAt 𝕜 f₁ x)
(hf₂ : DifferentiableAt 𝕜 f₂ x) :
fderiv 𝕜 (fun x : E => (f₁ x, f₂ x)) x = (fderiv 𝕜 f₁ x).prod (fderiv 𝕜 f₂ x) :=
(hf₁.hasFDerivAt.prodMk hf₂.hasFDerivAt).fderiv
@[deprecated (since := "2025-03-09")]
alias DifferentiableAt.fderiv_prod := DifferentiableAt.fderiv_prodMk
theorem DifferentiableWithinAt.fderivWithin_prodMk (hf₁ : DifferentiableWithinAt 𝕜 f₁ s x)
(hf₂ : DifferentiableWithinAt 𝕜 f₂ s x) (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (fun x : E => (f₁ x, f₂ x)) s x =
(fderivWithin 𝕜 f₁ s x).prod (fderivWithin 𝕜 f₂ s x) :=
(hf₁.hasFDerivWithinAt.prodMk hf₂.hasFDerivWithinAt).fderivWithin hxs
@[deprecated (since := "2025-03-09")]
alias DifferentiableWithinAt.fderivWithin_prod := DifferentiableWithinAt.fderivWithin_prodMk
end Prod
section Fst
variable {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}
@[fun_prop]
theorem hasStrictFDerivAt_fst : HasStrictFDerivAt (@Prod.fst E F) (fst 𝕜 E F) p :=
(fst 𝕜 E F).hasStrictFDerivAt
@[fun_prop]
protected theorem HasStrictFDerivAt.fst (h : HasStrictFDerivAt f₂ f₂' x) :
HasStrictFDerivAt (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=
hasStrictFDerivAt_fst.comp x h
theorem hasFDerivAtFilter_fst {L : Filter (E × F)} :
HasFDerivAtFilter (@Prod.fst E F) (fst 𝕜 E F) p L :=
(fst 𝕜 E F).hasFDerivAtFilter
protected theorem HasFDerivAtFilter.fst (h : HasFDerivAtFilter f₂ f₂' x L) :
HasFDerivAtFilter (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') x L :=
hasFDerivAtFilter_fst.comp x h tendsto_map
@[fun_prop]
theorem hasFDerivAt_fst : HasFDerivAt (@Prod.fst E F) (fst 𝕜 E F) p :=
hasFDerivAtFilter_fst
@[fun_prop]
protected nonrec theorem HasFDerivAt.fst (h : HasFDerivAt f₂ f₂' x) :
HasFDerivAt (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=
h.fst
@[fun_prop]
theorem hasFDerivWithinAt_fst {s : Set (E × F)} :
HasFDerivWithinAt (@Prod.fst E F) (fst 𝕜 E F) s p :=
hasFDerivAtFilter_fst
@[fun_prop]
protected nonrec theorem HasFDerivWithinAt.fst (h : HasFDerivWithinAt f₂ f₂' s x) :
HasFDerivWithinAt (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') s x :=
h.fst
@[fun_prop]
theorem differentiableAt_fst : DifferentiableAt 𝕜 Prod.fst p :=
hasFDerivAt_fst.differentiableAt
@[simp, fun_prop]
protected theorem DifferentiableAt.fst (h : DifferentiableAt 𝕜 f₂ x) :
DifferentiableAt 𝕜 (fun x => (f₂ x).1) x :=
differentiableAt_fst.comp x h
@[fun_prop]
theorem differentiable_fst : Differentiable 𝕜 (Prod.fst : E × F → E) := fun _ =>
differentiableAt_fst
@[simp, fun_prop]
protected theorem Differentiable.fst (h : Differentiable 𝕜 f₂) :
Differentiable 𝕜 fun x => (f₂ x).1 :=
differentiable_fst.comp h
@[fun_prop]
theorem differentiableWithinAt_fst {s : Set (E × F)} : DifferentiableWithinAt 𝕜 Prod.fst s p :=
differentiableAt_fst.differentiableWithinAt
@[fun_prop]
protected theorem DifferentiableWithinAt.fst (h : DifferentiableWithinAt 𝕜 f₂ s x) :
DifferentiableWithinAt 𝕜 (fun x => (f₂ x).1) s x :=
differentiableAt_fst.comp_differentiableWithinAt x h
@[fun_prop]
theorem differentiableOn_fst {s : Set (E × F)} : DifferentiableOn 𝕜 Prod.fst s :=
differentiable_fst.differentiableOn
@[fun_prop]
protected theorem DifferentiableOn.fst (h : DifferentiableOn 𝕜 f₂ s) :
DifferentiableOn 𝕜 (fun x => (f₂ x).1) s :=
differentiable_fst.comp_differentiableOn h
theorem fderiv_fst : fderiv 𝕜 Prod.fst p = fst 𝕜 E F :=
hasFDerivAt_fst.fderiv
theorem fderiv.fst (h : DifferentiableAt 𝕜 f₂ x) :
fderiv 𝕜 (fun x => (f₂ x).1) x = (fst 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=
h.hasFDerivAt.fst.fderiv
theorem fderivWithin_fst {s : Set (E × F)} (hs : UniqueDiffWithinAt 𝕜 s p) :
fderivWithin 𝕜 Prod.fst s p = fst 𝕜 E F :=
hasFDerivWithinAt_fst.fderivWithin hs
theorem fderivWithin.fst (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f₂ s x) :
fderivWithin 𝕜 (fun x => (f₂ x).1) s x = (fst 𝕜 F G).comp (fderivWithin 𝕜 f₂ s x) :=
h.hasFDerivWithinAt.fst.fderivWithin hs
end Fst
section Snd
variable {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}
@[fun_prop]
theorem hasStrictFDerivAt_snd : HasStrictFDerivAt (@Prod.snd E F) (snd 𝕜 E F) p :=
(snd 𝕜 E F).hasStrictFDerivAt
@[fun_prop]
protected theorem HasStrictFDerivAt.snd (h : HasStrictFDerivAt f₂ f₂' x) :
HasStrictFDerivAt (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=
hasStrictFDerivAt_snd.comp x h
theorem hasFDerivAtFilter_snd {L : Filter (E × F)} :
HasFDerivAtFilter (@Prod.snd E F) (snd 𝕜 E F) p L :=
(snd 𝕜 E F).hasFDerivAtFilter
protected theorem HasFDerivAtFilter.snd (h : HasFDerivAtFilter f₂ f₂' x L) :
HasFDerivAtFilter (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') x L :=
hasFDerivAtFilter_snd.comp x h tendsto_map
@[fun_prop]
theorem hasFDerivAt_snd : HasFDerivAt (@Prod.snd E F) (snd 𝕜 E F) p :=
hasFDerivAtFilter_snd
@[fun_prop]
protected nonrec theorem HasFDerivAt.snd (h : HasFDerivAt f₂ f₂' x) :
HasFDerivAt (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=
h.snd
@[fun_prop]
theorem hasFDerivWithinAt_snd {s : Set (E × F)} :
HasFDerivWithinAt (@Prod.snd E F) (snd 𝕜 E F) s p :=
hasFDerivAtFilter_snd
@[fun_prop]
protected nonrec theorem HasFDerivWithinAt.snd (h : HasFDerivWithinAt f₂ f₂' s x) :
HasFDerivWithinAt (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') s x :=
h.snd
@[fun_prop]
theorem differentiableAt_snd : DifferentiableAt 𝕜 Prod.snd p :=
hasFDerivAt_snd.differentiableAt
@[simp, fun_prop]
protected theorem DifferentiableAt.snd (h : DifferentiableAt 𝕜 f₂ x) :
DifferentiableAt 𝕜 (fun x => (f₂ x).2) x :=
differentiableAt_snd.comp x h
@[fun_prop]
theorem differentiable_snd : Differentiable 𝕜 (Prod.snd : E × F → F) := fun _ =>
differentiableAt_snd
@[simp, fun_prop]
protected theorem Differentiable.snd (h : Differentiable 𝕜 f₂) :
Differentiable 𝕜 fun x => (f₂ x).2 :=
differentiable_snd.comp h
@[fun_prop]
theorem differentiableWithinAt_snd {s : Set (E × F)} : DifferentiableWithinAt 𝕜 Prod.snd s p :=
differentiableAt_snd.differentiableWithinAt
@[fun_prop]
protected theorem DifferentiableWithinAt.snd (h : DifferentiableWithinAt 𝕜 f₂ s x) :
DifferentiableWithinAt 𝕜 (fun x => (f₂ x).2) s x :=
differentiableAt_snd.comp_differentiableWithinAt x h
@[fun_prop]
theorem differentiableOn_snd {s : Set (E × F)} : DifferentiableOn 𝕜 Prod.snd s :=
differentiable_snd.differentiableOn
@[fun_prop]
protected theorem DifferentiableOn.snd (h : DifferentiableOn 𝕜 f₂ s) :
DifferentiableOn 𝕜 (fun x => (f₂ x).2) s :=
differentiable_snd.comp_differentiableOn h
theorem fderiv_snd : fderiv 𝕜 Prod.snd p = snd 𝕜 E F :=
hasFDerivAt_snd.fderiv
theorem fderiv.snd (h : DifferentiableAt 𝕜 f₂ x) :
fderiv 𝕜 (fun x => (f₂ x).2) x = (snd 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=
h.hasFDerivAt.snd.fderiv
theorem fderivWithin_snd {s : Set (E × F)} (hs : UniqueDiffWithinAt 𝕜 s p) :
fderivWithin 𝕜 Prod.snd s p = snd 𝕜 E F :=
hasFDerivWithinAt_snd.fderivWithin hs
theorem fderivWithin.snd (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f₂ s x) :
fderivWithin 𝕜 (fun x => (f₂ x).2) s x = (snd 𝕜 F G).comp (fderivWithin 𝕜 f₂ s x) :=
h.hasFDerivWithinAt.snd.fderivWithin hs
end Snd
section prodMap
variable {f₂ : G → G'} {f₂' : G →L[𝕜] G'} {y : G} (p : E × G)
@[fun_prop]
protected theorem HasStrictFDerivAt.prodMap (hf : HasStrictFDerivAt f f' p.1)
(hf₂ : HasStrictFDerivAt f₂ f₂' p.2) : HasStrictFDerivAt (Prod.map f f₂) (f'.prodMap f₂') p :=
(hf.comp p hasStrictFDerivAt_fst).prodMk (hf₂.comp p hasStrictFDerivAt_snd)
@[fun_prop]
protected theorem HasFDerivAt.prodMap (hf : HasFDerivAt f f' p.1) (hf₂ : HasFDerivAt f₂ f₂' p.2) :
HasFDerivAt (Prod.map f f₂) (f'.prodMap f₂') p :=
(hf.comp p hasFDerivAt_fst).prodMk (hf₂.comp p hasFDerivAt_snd)
@[simp, fun_prop]
protected theorem DifferentiableAt.prodMap (hf : DifferentiableAt 𝕜 f p.1)
(hf₂ : DifferentiableAt 𝕜 f₂ p.2) : DifferentiableAt 𝕜 (fun p : E × G => (f p.1, f₂ p.2)) p :=
(hf.comp p differentiableAt_fst).prodMk (hf₂.comp p differentiableAt_snd)
@[deprecated (since := "2025-03-09")]
alias DifferentiableAt.prod_map := DifferentiableAt.prodMap
end prodMap
section Pi
/-!
### Derivatives of functions `f : E → Π i, F' i`
In this section we formulate `has*FDeriv*_pi` theorems as `iff`s, and provide two versions of each
theorem:
* the version without `'` deals with `φ : Π i, E → F' i` and `φ' : Π i, E →L[𝕜] F' i`
and is designed to deduce differentiability of `fun x i ↦ φ i x` from differentiability
of each `φ i`;
* the version with `'` deals with `Φ : E → Π i, F' i` and `Φ' : E →L[𝕜] Π i, F' i`
and is designed to deduce differentiability of the components `fun x ↦ Φ x i` from
differentiability of `Φ`.
-/
variable {ι : Type*} [Fintype ι] {F' : ι → Type*} [∀ i, NormedAddCommGroup (F' i)]
[∀ i, NormedSpace 𝕜 (F' i)] {φ : ∀ i, E → F' i} {φ' : ∀ i, E →L[𝕜] F' i} {Φ : E → ∀ i, F' i}
{Φ' : E →L[𝕜] ∀ i, F' i}
@[simp]
theorem hasStrictFDerivAt_pi' :
HasStrictFDerivAt Φ Φ' x ↔ ∀ i, HasStrictFDerivAt (fun x => Φ x i) ((proj i).comp Φ') x := by
simp only [hasStrictFDerivAt_iff_isLittleO, ContinuousLinearMap.coe_pi]
exact isLittleO_pi
@[fun_prop]
theorem hasStrictFDerivAt_pi'' (hφ : ∀ i, HasStrictFDerivAt (fun x => Φ x i) ((proj i).comp Φ') x) :
HasStrictFDerivAt Φ Φ' x := hasStrictFDerivAt_pi'.2 hφ
@[fun_prop]
theorem hasStrictFDerivAt_apply (i : ι) (f : ∀ i, F' i) :
HasStrictFDerivAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) (proj i) f := by
let id' := ContinuousLinearMap.id 𝕜 (∀ i, F' i)
have h := ((hasStrictFDerivAt_pi'
(Φ := fun (f : ∀ i, F' i) (i' : ι) => f i') (Φ' := id') (x := f))).1
have h' : comp (proj i) id' = proj i := by ext; simp [id']
rw [← h']; apply h; apply hasStrictFDerivAt_id
@[simp 1100] -- Porting note: increased priority to make lint happy
theorem hasStrictFDerivAt_pi :
HasStrictFDerivAt (fun x i => φ i x) (ContinuousLinearMap.pi φ') x ↔
∀ i, HasStrictFDerivAt (φ i) (φ' i) x :=
hasStrictFDerivAt_pi'
@[simp]
theorem hasFDerivAtFilter_pi' :
HasFDerivAtFilter Φ Φ' x L ↔
∀ i, HasFDerivAtFilter (fun x => Φ x i) ((proj i).comp Φ') x L := by
simp only [hasFDerivAtFilter_iff_isLittleO, ContinuousLinearMap.coe_pi]
exact isLittleO_pi
theorem hasFDerivAtFilter_pi :
HasFDerivAtFilter (fun x i => φ i x) (ContinuousLinearMap.pi φ') x L ↔
∀ i, HasFDerivAtFilter (φ i) (φ' i) x L :=
hasFDerivAtFilter_pi'
@[simp]
theorem hasFDerivAt_pi' :
HasFDerivAt Φ Φ' x ↔ ∀ i, HasFDerivAt (fun x => Φ x i) ((proj i).comp Φ') x :=
hasFDerivAtFilter_pi'
@[fun_prop]
theorem hasFDerivAt_pi'' (hφ : ∀ i, HasFDerivAt (fun x => Φ x i) ((proj i).comp Φ') x) :
HasFDerivAt Φ Φ' x := hasFDerivAt_pi'.2 hφ
@[fun_prop]
theorem hasFDerivAt_apply (i : ι) (f : ∀ i, F' i) :
HasFDerivAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) (proj i) f := by
apply HasStrictFDerivAt.hasFDerivAt
apply hasStrictFDerivAt_apply
theorem hasFDerivAt_pi :
HasFDerivAt (fun x i => φ i x) (ContinuousLinearMap.pi φ') x ↔
∀ i, HasFDerivAt (φ i) (φ' i) x :=
hasFDerivAtFilter_pi
@[simp]
theorem hasFDerivWithinAt_pi' :
HasFDerivWithinAt Φ Φ' s x ↔ ∀ i, HasFDerivWithinAt (fun x => Φ x i) ((proj i).comp Φ') s x :=
hasFDerivAtFilter_pi'
@[fun_prop]
theorem hasFDerivWithinAt_pi''
(hφ : ∀ i, HasFDerivWithinAt (fun x => Φ x i) ((proj i).comp Φ') s x) :
HasFDerivWithinAt Φ Φ' s x := hasFDerivWithinAt_pi'.2 hφ
@[fun_prop]
theorem hasFDerivWithinAt_apply (i : ι) (f : ∀ i, F' i) (s' : Set (∀ i, F' i)) :
HasFDerivWithinAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) (proj i) s' f := by
let id' := ContinuousLinearMap.id 𝕜 (∀ i, F' i)
have h := ((hasFDerivWithinAt_pi'
(Φ := fun (f : ∀ i, F' i) (i' : ι) => f i') (Φ' := id') (x := f) (s := s'))).1
have h' : comp (proj i) id' = proj i := by rfl
rw [← h']; apply h; apply hasFDerivWithinAt_id
theorem hasFDerivWithinAt_pi :
HasFDerivWithinAt (fun x i => φ i x) (ContinuousLinearMap.pi φ') s x ↔
∀ i, HasFDerivWithinAt (φ i) (φ' i) s x :=
hasFDerivAtFilter_pi
@[simp]
theorem differentiableWithinAt_pi :
DifferentiableWithinAt 𝕜 Φ s x ↔ ∀ i, DifferentiableWithinAt 𝕜 (fun x => Φ x i) s x :=
⟨fun h i => (hasFDerivWithinAt_pi'.1 h.hasFDerivWithinAt i).differentiableWithinAt, fun h =>
(hasFDerivWithinAt_pi.2 fun i => (h i).hasFDerivWithinAt).differentiableWithinAt⟩
@[fun_prop]
theorem differentiableWithinAt_pi'' (hφ : ∀ i, DifferentiableWithinAt 𝕜 (fun x => Φ x i) s x) :
DifferentiableWithinAt 𝕜 Φ s x := differentiableWithinAt_pi.2 hφ
@[fun_prop]
theorem differentiableWithinAt_apply (i : ι) (f : ∀ i, F' i) (s' : Set (∀ i, F' i)) :
DifferentiableWithinAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) s' f := by
apply HasFDerivWithinAt.differentiableWithinAt
fun_prop
|
@[simp]
theorem differentiableAt_pi : DifferentiableAt 𝕜 Φ x ↔ ∀ i, DifferentiableAt 𝕜 (fun x => Φ x i) x :=
⟨fun h i => (hasFDerivAt_pi'.1 h.hasFDerivAt i).differentiableAt, fun h =>
(hasFDerivAt_pi.2 fun i => (h i).hasFDerivAt).differentiableAt⟩
@[fun_prop]
| Mathlib/Analysis/Calculus/FDeriv/Prod.lean | 474 | 480 |
/-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Thickenings in pseudo-metric spaces
## Main definitions
* `Metric.thickening δ s`, the open thickening by radius `δ` of a set `s` in a pseudo emetric space.
* `Metric.cthickening δ s`, the closed thickening by radius `δ` of a set `s` in a pseudo emetric
space.
## Main results
* `Disjoint.exists_thickenings`: two disjoint sets admit disjoint thickenings
* `Disjoint.exists_cthickenings`: two disjoint sets admit disjoint closed thickenings
* `IsCompact.exists_cthickening_subset_open`: if `s` is compact, `t` is open and `s ⊆ t`,
some `cthickening` of `s` is contained in `t`.
* `Metric.hasBasis_nhdsSet_cthickening`: the `cthickening`s of a compact set `K` form a basis
of the neighbourhoods of `K`
* `Metric.closure_eq_iInter_cthickening'`: the closure of a set equals the intersection
of its closed thickenings of positive radii accumulating at zero.
The same holds for open thickenings.
* `IsCompact.cthickening_eq_biUnion_closedBall`: if `s` is compact, `cthickening δ s` is the union
of `closedBall`s of radius `δ` around `x : E`.
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Bornology
universe u v w
variable {ι : Sort*} {α : Type u}
namespace Metric
section Thickening
variable [PseudoEMetricSpace α] {δ : ℝ} {s : Set α} {x : α}
open EMetric
/-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a pseudo emetric space
consists of those points that are at distance less than `δ` from some point of `E`. -/
def thickening (δ : ℝ) (E : Set α) : Set α :=
{ x : α | infEdist x E < ENNReal.ofReal δ }
theorem mem_thickening_iff_infEdist_lt : x ∈ thickening δ s ↔ infEdist x s < ENNReal.ofReal δ :=
Iff.rfl
/-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the
(open) `δ`-thickening of `E` for small enough positive `δ`. -/
lemma eventually_not_mem_thickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) :
∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.thickening δ E := by
obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h
filter_upwards [eventually_lt_nhds ε_pos] with δ hδ
simp only [thickening, mem_setOf_eq, not_lt]
exact (ENNReal.ofReal_le_ofReal hδ.le).trans ε_lt.le
/-- The (open) thickening equals the preimage of an open interval under `EMetric.infEdist`. -/
theorem thickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) :
thickening δ E = (infEdist · E) ⁻¹' Iio (ENNReal.ofReal δ) :=
rfl
/-- The (open) thickening is an open set. -/
theorem isOpen_thickening {δ : ℝ} {E : Set α} : IsOpen (thickening δ E) :=
Continuous.isOpen_preimage continuous_infEdist _ isOpen_Iio
/-- The (open) thickening of the empty set is empty. -/
@[simp]
theorem thickening_empty (δ : ℝ) : thickening δ (∅ : Set α) = ∅ := by
simp only [thickening, setOf_false, infEdist_empty, not_top_lt]
theorem thickening_of_nonpos (hδ : δ ≤ 0) (s : Set α) : thickening δ s = ∅ :=
eq_empty_of_forall_not_mem fun _ => ((ENNReal.ofReal_of_nonpos hδ).trans_le bot_le).not_lt
/-- The (open) thickening `Metric.thickening δ E` of a fixed subset `E` is an increasing function of
the thickening radius `δ`. -/
@[gcongr]
theorem thickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
thickening δ₁ E ⊆ thickening δ₂ E :=
preimage_mono (Iio_subset_Iio (ENNReal.ofReal_le_ofReal hle))
/-- The (open) thickening `Metric.thickening δ E` with a fixed thickening radius `δ` is
an increasing function of the subset `E`. -/
theorem thickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) :
thickening δ E₁ ⊆ thickening δ E₂ := fun _ hx => lt_of_le_of_lt (infEdist_anti h) hx
theorem mem_thickening_iff_exists_edist_lt {δ : ℝ} (E : Set α) (x : α) :
x ∈ thickening δ E ↔ ∃ z ∈ E, edist x z < ENNReal.ofReal δ :=
infEdist_lt_iff
/-- The frontier of the (open) thickening of a set is contained in an `EMetric.infEdist` level
set. -/
theorem frontier_thickening_subset (E : Set α) {δ : ℝ} :
frontier (thickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } :=
frontier_lt_subset_eq continuous_infEdist continuous_const
open scoped Function in -- required for scoped `on` notation
theorem frontier_thickening_disjoint (A : Set α) :
Pairwise (Disjoint on fun r : ℝ => frontier (thickening r A)) := by
refine (pairwise_disjoint_on _).2 fun r₁ r₂ hr => ?_
rcases le_total r₁ 0 with h₁ | h₁
· simp [thickening_of_nonpos h₁]
refine ((disjoint_singleton.2 fun h => hr.ne ?_).preimage _).mono (frontier_thickening_subset _)
(frontier_thickening_subset _)
apply_fun ENNReal.toReal at h
rwa [ENNReal.toReal_ofReal h₁, ENNReal.toReal_ofReal (h₁.trans hr.le)] at h
/-- Any set is contained in the complement of the δ-thickening of the complement of its
δ-thickening. -/
lemma subset_compl_thickening_compl_thickening_self (δ : ℝ) (E : Set α) :
E ⊆ (thickening δ (thickening δ E)ᶜ)ᶜ := by
intro x x_in_E
simp only [thickening, mem_compl_iff, mem_setOf_eq, not_lt]
apply EMetric.le_infEdist.mpr fun y hy ↦ ?_
simp only [mem_compl_iff, mem_setOf_eq, not_lt] at hy
simpa only [edist_comm] using le_trans hy <| EMetric.infEdist_le_edist_of_mem x_in_E
/-- The δ-thickening of the complement of the δ-thickening of a set is contained in the complement
of the set. -/
lemma thickening_compl_thickening_self_subset_compl (δ : ℝ) (E : Set α) :
thickening δ (thickening δ E)ᶜ ⊆ Eᶜ := by
apply compl_subset_compl.mp
simpa only [compl_compl] using subset_compl_thickening_compl_thickening_self δ E
variable {X : Type u} [PseudoMetricSpace X]
theorem mem_thickening_iff_infDist_lt {E : Set X} {x : X} (h : E.Nonempty) :
x ∈ thickening δ E ↔ infDist x E < δ :=
lt_ofReal_iff_toReal_lt (infEdist_ne_top h)
/-- A point in a metric space belongs to the (open) `δ`-thickening of a subset `E` if and only if
it is at distance less than `δ` from some point of `E`. -/
theorem mem_thickening_iff {E : Set X} {x : X} : x ∈ thickening δ E ↔ ∃ z ∈ E, dist x z < δ := by
have key_iff : ∀ z : X, edist x z < ENNReal.ofReal δ ↔ dist x z < δ := fun z ↦ by
rw [dist_edist, lt_ofReal_iff_toReal_lt (edist_ne_top _ _)]
simp_rw [mem_thickening_iff_exists_edist_lt, key_iff]
@[simp]
theorem thickening_singleton (δ : ℝ) (x : X) : thickening δ ({x} : Set X) = ball x δ := by
ext
simp [mem_thickening_iff]
theorem ball_subset_thickening {x : X} {E : Set X} (hx : x ∈ E) (δ : ℝ) :
ball x δ ⊆ thickening δ E :=
Subset.trans (by simp [Subset.rfl]) (thickening_subset_of_subset δ <| singleton_subset_iff.mpr hx)
/-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a metric space equals the
union of balls of radius `δ` centered at points of `E`. -/
theorem thickening_eq_biUnion_ball {δ : ℝ} {E : Set X} : thickening δ E = ⋃ x ∈ E, ball x δ := by
ext x
simp only [mem_iUnion₂, exists_prop]
exact mem_thickening_iff
protected theorem _root_.Bornology.IsBounded.thickening {δ : ℝ} {E : Set X} (h : IsBounded E) :
IsBounded (thickening δ E) := by
rcases E.eq_empty_or_nonempty with rfl | ⟨x, hx⟩
· simp
· refine (isBounded_iff_subset_closedBall x).2 ⟨δ + diam E, fun y hy ↦ ?_⟩
calc
dist y x ≤ infDist y E + diam E := dist_le_infDist_add_diam (x := y) h hx
_ ≤ δ + diam E := add_le_add_right ((mem_thickening_iff_infDist_lt ⟨x, hx⟩).1 hy).le _
end Thickening
section Cthickening
variable [PseudoEMetricSpace α] {δ ε : ℝ} {s t : Set α} {x : α}
open EMetric
/-- The closed `δ`-thickening `Metric.cthickening δ E` of a subset `E` in a pseudo emetric space
consists of those points that are at infimum distance at most `δ` from `E`. -/
def cthickening (δ : ℝ) (E : Set α) : Set α :=
{ x : α | infEdist x E ≤ ENNReal.ofReal δ }
@[simp]
theorem mem_cthickening_iff : x ∈ cthickening δ s ↔ infEdist x s ≤ ENNReal.ofReal δ :=
Iff.rfl
/-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the
closed `δ`-thickening of `E` for small enough positive `δ`. -/
lemma eventually_not_mem_cthickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) :
∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.cthickening δ E := by
obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h
filter_upwards [eventually_lt_nhds ε_pos] with δ hδ
simp only [cthickening, mem_setOf_eq, not_le]
exact ((ofReal_lt_ofReal_iff ε_pos).mpr hδ).trans ε_lt
theorem mem_cthickening_of_edist_le (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E)
(h' : edist x y ≤ ENNReal.ofReal δ) : x ∈ cthickening δ E :=
(infEdist_le_edist_of_mem h).trans h'
theorem mem_cthickening_of_dist_le {α : Type*} [PseudoMetricSpace α] (x y : α) (δ : ℝ) (E : Set α)
(h : y ∈ E) (h' : dist x y ≤ δ) : x ∈ cthickening δ E := by
apply mem_cthickening_of_edist_le x y δ E h
rw [edist_dist]
exact ENNReal.ofReal_le_ofReal h'
theorem cthickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) :
cthickening δ E = (fun x => infEdist x E) ⁻¹' Iic (ENNReal.ofReal δ) :=
rfl
/-- The closed thickening is a closed set. -/
theorem isClosed_cthickening {δ : ℝ} {E : Set α} : IsClosed (cthickening δ E) :=
IsClosed.preimage continuous_infEdist isClosed_Iic
/-- The closed thickening of the empty set is empty. -/
@[simp]
theorem cthickening_empty (δ : ℝ) : cthickening δ (∅ : Set α) = ∅ := by
simp only [cthickening, ENNReal.ofReal_ne_top, setOf_false, infEdist_empty, top_le_iff]
theorem cthickening_of_nonpos {δ : ℝ} (hδ : δ ≤ 0) (E : Set α) : cthickening δ E = closure E := by
ext x
simp [mem_closure_iff_infEdist_zero, cthickening, ENNReal.ofReal_eq_zero.2 hδ]
/-- The closed thickening with radius zero is the closure of the set. -/
@[simp]
theorem cthickening_zero (E : Set α) : cthickening 0 E = closure E :=
cthickening_of_nonpos le_rfl E
theorem cthickening_max_zero (δ : ℝ) (E : Set α) : cthickening (max 0 δ) E = cthickening δ E := by
cases le_total δ 0 <;> simp [cthickening_of_nonpos, *]
/-- The closed thickening `Metric.cthickening δ E` of a fixed subset `E` is an increasing function
of the thickening radius `δ`. -/
theorem cthickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
cthickening δ₁ E ⊆ cthickening δ₂ E :=
preimage_mono (Iic_subset_Iic.mpr (ENNReal.ofReal_le_ofReal hle))
@[simp]
theorem cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) {δ : ℝ} (hδ : 0 ≤ δ) :
cthickening δ ({x} : Set α) = closedBall x δ := by
ext y
simp [cthickening, edist_dist, ENNReal.ofReal_le_ofReal_iff hδ]
theorem closedBall_subset_cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) (δ : ℝ) :
closedBall x δ ⊆ cthickening δ ({x} : Set α) := by
rcases lt_or_le δ 0 with (hδ | hδ)
· simp only [closedBall_eq_empty.mpr hδ, empty_subset]
· simp only [cthickening_singleton x hδ, Subset.rfl]
/-- The closed thickening `Metric.cthickening δ E` with a fixed thickening radius `δ` is
an increasing function of the subset `E`. -/
theorem cthickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) :
cthickening δ E₁ ⊆ cthickening δ E₂ := fun _ hx => le_trans (infEdist_anti h) hx
theorem cthickening_subset_thickening {δ₁ : ℝ≥0} {δ₂ : ℝ} (hlt : (δ₁ : ℝ) < δ₂) (E : Set α) :
cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx =>
hx.out.trans_lt ((ENNReal.ofReal_lt_ofReal_iff (lt_of_le_of_lt δ₁.prop hlt)).mpr hlt)
/-- The closed thickening `Metric.cthickening δ₁ E` is contained in the open thickening
`Metric.thickening δ₂ E` if the radius of the latter is positive and larger. -/
theorem cthickening_subset_thickening' {δ₁ δ₂ : ℝ} (δ₂_pos : 0 < δ₂) (hlt : δ₁ < δ₂) (E : Set α) :
cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx =>
lt_of_le_of_lt hx.out ((ENNReal.ofReal_lt_ofReal_iff δ₂_pos).mpr hlt)
/-- The open thickening `Metric.thickening δ E` is contained in the closed thickening
`Metric.cthickening δ E` with the same radius. -/
theorem thickening_subset_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ cthickening δ E := by
intro x hx
rw [thickening, mem_setOf_eq] at hx
exact hx.le
theorem thickening_subset_cthickening_of_le {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
thickening δ₁ E ⊆ cthickening δ₂ E :=
(thickening_subset_cthickening δ₁ E).trans (cthickening_mono hle E)
theorem _root_.Bornology.IsBounded.cthickening {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α}
(h : IsBounded E) : IsBounded (cthickening δ E) := by
have : IsBounded (thickening (max (δ + 1) 1) E) := h.thickening
apply this.subset
exact cthickening_subset_thickening' (zero_lt_one.trans_le (le_max_right _ _))
((lt_add_one _).trans_le (le_max_left _ _)) _
protected theorem _root_.IsCompact.cthickening
{α : Type*} [PseudoMetricSpace α] [ProperSpace α] {s : Set α}
(hs : IsCompact s) {r : ℝ} : IsCompact (cthickening r s) :=
isCompact_of_isClosed_isBounded isClosed_cthickening hs.isBounded.cthickening
theorem thickening_subset_interior_cthickening (δ : ℝ) (E : Set α) :
thickening δ E ⊆ interior (cthickening δ E) :=
(subset_interior_iff_isOpen.mpr isOpen_thickening).trans
(interior_mono (thickening_subset_cthickening δ E))
theorem closure_thickening_subset_cthickening (δ : ℝ) (E : Set α) :
closure (thickening δ E) ⊆ cthickening δ E :=
(closure_mono (thickening_subset_cthickening δ E)).trans isClosed_cthickening.closure_subset
/-- The closed thickening of a set contains the closure of the set. -/
theorem closure_subset_cthickening (δ : ℝ) (E : Set α) : closure E ⊆ cthickening δ E := by
rw [← cthickening_of_nonpos (min_le_right δ 0)]
exact cthickening_mono (min_le_left δ 0) E
/-- The (open) thickening of a set contains the closure of the set. -/
theorem closure_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) :
closure E ⊆ thickening δ E := by
rw [← cthickening_zero]
exact cthickening_subset_thickening' δ_pos δ_pos E
/-- A set is contained in its own (open) thickening. -/
theorem self_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : E ⊆ thickening δ E :=
(@subset_closure _ _ E).trans (closure_subset_thickening δ_pos E)
/-- A set is contained in its own closed thickening. -/
theorem self_subset_cthickening {δ : ℝ} (E : Set α) : E ⊆ cthickening δ E :=
subset_closure.trans (closure_subset_cthickening δ E)
theorem thickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : thickening δ E ∈ 𝓝ˢ E :=
isOpen_thickening.mem_nhdsSet.2 <| self_subset_thickening hδ E
theorem cthickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : cthickening δ E ∈ 𝓝ˢ E :=
mem_of_superset (thickening_mem_nhdsSet E hδ) (thickening_subset_cthickening _ _)
@[simp]
theorem thickening_union (δ : ℝ) (s t : Set α) :
thickening δ (s ∪ t) = thickening δ s ∪ thickening δ t := by
simp_rw [thickening, infEdist_union, min_lt_iff, setOf_or]
@[simp]
theorem cthickening_union (δ : ℝ) (s t : Set α) :
cthickening δ (s ∪ t) = cthickening δ s ∪ cthickening δ t := by
simp_rw [cthickening, infEdist_union, min_le_iff, setOf_or]
@[simp]
theorem thickening_iUnion (δ : ℝ) (f : ι → Set α) :
thickening δ (⋃ i, f i) = ⋃ i, thickening δ (f i) := by
simp_rw [thickening, infEdist_iUnion, iInf_lt_iff, setOf_exists]
lemma thickening_biUnion {ι : Type*} (δ : ℝ) (f : ι → Set α) (I : Set ι) :
thickening δ (⋃ i ∈ I, f i) = ⋃ i ∈ I, thickening δ (f i) := by simp only [thickening_iUnion]
theorem ediam_cthickening_le (ε : ℝ≥0) :
EMetric.diam (cthickening ε s) ≤ EMetric.diam s + 2 * ε := by
refine diam_le fun x hx y hy => ENNReal.le_of_forall_pos_le_add fun δ hδ _ => ?_
rw [mem_cthickening_iff, ENNReal.ofReal_coe_nnreal] at hx hy
have hε : (ε : ℝ≥0∞) < ε + δ := ENNReal.coe_lt_coe.2 (lt_add_of_pos_right _ hδ)
replace hx := hx.trans_lt hε
obtain ⟨x', hx', hxx'⟩ := infEdist_lt_iff.mp hx
calc
edist x y ≤ edist x x' + edist y x' := edist_triangle_right _ _ _
_ ≤ ε + δ + (infEdist y s + EMetric.diam s) :=
add_le_add hxx'.le (edist_le_infEdist_add_ediam hx')
_ ≤ ε + δ + (ε + EMetric.diam s) := add_le_add_left (add_le_add_right hy _) _
_ = _ := by rw [two_mul]; ac_rfl
theorem ediam_thickening_le (ε : ℝ≥0) : EMetric.diam (thickening ε s) ≤ EMetric.diam s + 2 * ε :=
(EMetric.diam_mono <| thickening_subset_cthickening _ _).trans <| ediam_cthickening_le _
theorem diam_cthickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) :
diam (cthickening ε s) ≤ diam s + 2 * ε := by
lift ε to ℝ≥0 using hε
refine (toReal_le_add' (ediam_cthickening_le _) ?_ ?_).trans_eq ?_
· exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono (self_subset_cthickening _)
· simp [mul_eq_top]
· simp [diam]
theorem diam_thickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) :
diam (thickening ε s) ≤ diam s + 2 * ε := by
by_cases hs : IsBounded s
· exact (diam_mono (thickening_subset_cthickening _ _) hs.cthickening).trans
(diam_cthickening_le _ hε)
obtain rfl | hε := hε.eq_or_lt
· simp [thickening_of_nonpos, diam_nonneg]
· rw [diam_eq_zero_of_unbounded (mt (IsBounded.subset · <| self_subset_thickening hε _) hs)]
positivity
@[simp]
theorem thickening_closure : thickening δ (closure s) = thickening δ s := by
simp_rw [thickening, infEdist_closure]
@[simp]
theorem cthickening_closure : cthickening δ (closure s) = cthickening δ s := by
simp_rw [cthickening, infEdist_closure]
open ENNReal
theorem _root_.Disjoint.exists_thickenings (hst : Disjoint s t) (hs : IsCompact s)
(ht : IsClosed t) :
∃ δ, 0 < δ ∧ Disjoint (thickening δ s) (thickening δ t) := by
obtain ⟨r, hr, h⟩ := exists_pos_forall_lt_edist hs ht hst
refine ⟨r / 2, half_pos (NNReal.coe_pos.2 hr), ?_⟩
rw [disjoint_iff_inf_le]
rintro z ⟨hzs, hzt⟩
rw [mem_thickening_iff_exists_edist_lt] at hzs hzt
rw [← NNReal.coe_two, ← NNReal.coe_div, ENNReal.ofReal_coe_nnreal] at hzs hzt
obtain ⟨x, hx, hzx⟩ := hzs
obtain ⟨y, hy, hzy⟩ := hzt
refine (h x hx y hy).not_le ?_
calc
edist x y ≤ edist z x + edist z y := edist_triangle_left _ _ _
_ ≤ ↑(r / 2) + ↑(r / 2) := add_le_add hzx.le hzy.le
_ = r := by rw [← ENNReal.coe_add, add_halves]
theorem _root_.Disjoint.exists_cthickenings (hst : Disjoint s t) (hs : IsCompact s)
(ht : IsClosed t) :
∃ δ, 0 < δ ∧ Disjoint (cthickening δ s) (cthickening δ t) := by
obtain ⟨δ, hδ, h⟩ := hst.exists_thickenings hs ht
refine ⟨δ / 2, half_pos hδ, h.mono ?_ ?_⟩ <;>
exact cthickening_subset_thickening' hδ (half_lt_self hδ) _
/-- If `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. -/
theorem _root_.IsCompact.exists_cthickening_subset_open (hs : IsCompact s) (ht : IsOpen t)
(hst : s ⊆ t) :
∃ δ, 0 < δ ∧ cthickening δ s ⊆ t :=
(hst.disjoint_compl_right.exists_cthickenings hs ht.isClosed_compl).imp fun _ h =>
⟨h.1, disjoint_compl_right_iff_subset.1 <| h.2.mono_right <| self_subset_cthickening _⟩
theorem _root_.IsCompact.exists_isCompact_cthickening [LocallyCompactSpace α] (hs : IsCompact s) :
∃ δ, 0 < δ ∧ IsCompact (cthickening δ s) := by
rcases exists_compact_superset hs with ⟨K, K_compact, hK⟩
rcases hs.exists_cthickening_subset_open isOpen_interior hK with ⟨δ, δpos, hδ⟩
refine ⟨δ, δpos, ?_⟩
exact K_compact.of_isClosed_subset isClosed_cthickening (hδ.trans interior_subset)
theorem _root_.IsCompact.exists_thickening_subset_open (hs : IsCompact s) (ht : IsOpen t)
(hst : s ⊆ t) : ∃ δ, 0 < δ ∧ thickening δ s ⊆ t :=
let ⟨δ, h₀, hδ⟩ := hs.exists_cthickening_subset_open ht hst
⟨δ, h₀, (thickening_subset_cthickening _ _).trans hδ⟩
theorem hasBasis_nhdsSet_thickening {K : Set α} (hK : IsCompact K) :
(𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => thickening δ K :=
(hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_thickening_subset_open hU.1 hU.2)
| fun _ => thickening_mem_nhdsSet K
| Mathlib/Topology/MetricSpace/Thickening.lean | 429 | 430 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.PropInstances
import Mathlib.Order.GaloisConnection.Defs
/-!
# Heyting algebras
This file defines Heyting, co-Heyting and bi-Heyting algebras.
A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that
`a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`.
Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬`
such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`.
Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras.
From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean
algebras model classical logic.
Heyting algebras are the order theoretic equivalent of cartesian-closed categories.
## Main declarations
* `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation).
* `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement).
* `HeytingAlgebra`: Heyting algebra.
* `CoheytingAlgebra`: Co-Heyting algebra.
* `BiheytingAlgebra`: bi-Heyting algebra.
## References
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
## Tags
Heyting, Brouwer, algebra, implication, negation, intuitionistic
-/
assert_not_exists RelIso
open Function OrderDual
universe u
variable {ι α β : Type*}
/-! ### Notation -/
section
variable (α β)
instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) :=
⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩
instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) :=
⟨fun a => (¬a.1, ¬a.2)⟩
instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) :=
⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩
instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) :=
⟨fun a => (a.1ᶜ, a.2ᶜ)⟩
end
@[simp]
theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 :=
rfl
@[simp]
theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 :=
rfl
@[simp]
theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 :=
rfl
@[simp]
theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 :=
rfl
@[simp]
theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 :=
rfl
@[simp]
theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 :=
rfl
@[simp]
theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ :=
rfl
@[simp]
theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ :=
rfl
namespace Pi
variable {π : ι → Type*}
instance [∀ i, HImp (π i)] : HImp (∀ i, π i) :=
⟨fun a b i => a i ⇨ b i⟩
instance [∀ i, HNot (π i)] : HNot (∀ i, π i) :=
⟨fun a i => ¬a i⟩
theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i :=
rfl
theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i :=
rfl
@[simp]
theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i :=
rfl
@[simp]
theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i :=
rfl
end Pi
/-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called
Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`.
This generalizes `HeytingAlgebra` by not requiring a bottom element. -/
class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where
/-- `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)` -/
le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c
/-- A generalized co-Heyting algebra is a lattice with an additional binary
difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`.
This generalizes `CoheytingAlgebra` by not requiring a top element. -/
class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where
/-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting
implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. -/
class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where
/-- `aᶜ` is defined as `a ⇨ ⊥` -/
himp_bot (a : α) : a ⇨ ⊥ = aᶜ
/-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\`
such that `(· \ a)` is left adjoint to `(· ⊔ a)`. -/
class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
/-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/
class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where
/-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
-- See note [lower instance priority]
attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop
attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot
-- See note [lower instance priority]
instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α :=
{ bot_le := ‹HeytingAlgebra α›.bot_le }
-- See note [lower instance priority]
instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α :=
{ ‹CoheytingAlgebra α› with }
-- See note [lower instance priority]
instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] :
CoheytingAlgebra α :=
{ ‹BiheytingAlgebra α› with }
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/
abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α)
(le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
himp,
compl := fun a => himp a ⊥,
le_himp_iff,
himp_bot := fun _ => rfl }
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/
abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α)
(le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where
himp := (compl · ⊔ ·)
compl := compl
le_himp_iff := le_himp_iff
himp_bot _ := sup_bot_eq _
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/
abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α)
(sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
sdiff,
hnot := fun a => sdiff ⊤ a,
sdiff_le_iff,
top_sdiff := fun _ => rfl }
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/
abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α)
(sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where
sdiff a b := a ⊓ hnot b
hnot := hnot
sdiff_le_iff := sdiff_le_iff
top_sdiff _ := top_inf_eq _
/-! In this section, we'll give interpretations of these results in the Heyting algebra model of
intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and",
`⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are
the same in this logic.
See also `Prop.heytingAlgebra`. -/
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] {a b c d : α}
/-- `p → q → r ↔ p ∧ q → r` -/
@[simp]
theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c :=
GeneralizedHeytingAlgebra.le_himp_iff _ _ _
/-- `p → q → r ↔ q ∧ p → r` -/
theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm]
/-- `p → q → r ↔ q → p → r` -/
theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff']
/-- `p → q → p` -/
theorem le_himp : a ≤ b ⇨ a :=
le_himp_iff.2 inf_le_left
/-- `p → p → q ↔ p → q` -/
theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem]
/-- `p → p` -/
@[simp]
theorem himp_self : a ⇨ a = ⊤ :=
top_le_iff.1 <| le_himp_iff.2 inf_le_right
/-- `(p → q) ∧ p → q` -/
theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b :=
le_himp_iff.1 le_rfl
/-- `p ∧ (p → q) → q` -/
theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff]
/-- `p ∧ (p → q) ↔ p ∧ q` -/
@[simp]
theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b :=
le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp
/-- `(p → q) ∧ p ↔ q ∧ p` -/
@[simp]
theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm]
/-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic:
an implication holds iff the conclusion follows from the hypothesis. -/
@[simp]
theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq]
/-- `p → true`, `true → p ↔ p` -/
@[simp]
theorem himp_top : a ⇨ ⊤ = ⊤ :=
himp_eq_top_iff.2 le_top
@[simp]
theorem top_himp : ⊤ ⇨ a = a :=
eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq]
/-- `p → q → r ↔ p ∧ q → r` -/
theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c :=
eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc]
/-- `(q → r) → (p → q) → q → r` -/
theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by
rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc]
exact inf_le_left
@[simp]
theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by
simpa using @himp_le_himp_himp_himp
/-- `p → q → r ↔ q → p → r` -/
theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm]
@[simp]
theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem]
theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) :=
eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff]
theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) :=
eq_of_forall_le_iff fun d => by
rw [le_inf_iff, le_himp_comm, sup_le_iff]
simp_rw [le_himp_comm]
theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b :=
le_himp_iff.2 <| himp_inf_le.trans h
theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c :=
le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le
theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d :=
(himp_le_himp_right hab).trans <| himp_le_himp_left hcd
@[simp]
theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by
rw [sup_himp_distrib, himp_self, top_inf_eq]
@[simp]
theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by
rw [sup_himp_distrib, himp_self, inf_top_eq]
theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by
conv_rhs => rw [← @top_himp _ _ a]
rw [← h.eq_top, sup_himp_self_left]
theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b :=
h.symm.himp_eq_right
theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by
rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left]
theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by
rw [himp_inf_distrib, himp_self, inf_top_eq, h.himp_eq_right]
/-- See `himp_le` for a stronger version in Boolean algebras. -/
theorem Codisjoint.himp_le_of_right_le (hac : Codisjoint a c) (hba : b ≤ a) : c ⇨ b ≤ a :=
(himp_le_himp_left hba).trans_eq hac.himp_eq_right
theorem le_himp_himp : a ≤ (a ⇨ b) ⇨ b :=
le_himp_iff.2 inf_himp_le
@[simp] lemma himp_eq_himp_iff : b ⇨ a = a ⇨ b ↔ a = b := by simp [le_antisymm_iff]
lemma himp_ne_himp_iff : b ⇨ a ≠ a ⇨ b ↔ a ≠ b := himp_eq_himp_iff.not
theorem himp_triangle (a b c : α) : (a ⇨ b) ⊓ (b ⇨ c) ≤ a ⇨ c := by
rw [le_himp_iff, inf_right_comm, ← le_himp_iff]
exact himp_inf_le.trans le_himp_himp
theorem himp_inf_himp_cancel (hba : b ≤ a) (hcb : c ≤ b) : (a ⇨ b) ⊓ (b ⇨ c) = a ⇨ c :=
(himp_triangle _ _ _).antisymm <| le_inf (himp_le_himp_left hcb) (himp_le_himp_right hba)
theorem gc_inf_himp : GaloisConnection (a ⊓ ·) (a ⇨ ·) :=
fun _ _ ↦ Iff.symm le_himp_iff'
-- See note [lower instance priority]
instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribLattice α :=
DistribLattice.ofInfSupLe fun a b c => by
simp_rw [inf_comm a, ← le_himp_iff, sup_le_iff, le_himp_iff, ← sup_le_iff]; rfl
instance OrderDual.instGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra αᵒᵈ where
sdiff a b := toDual (ofDual b ⇨ ofDual a)
sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff
instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] :
GeneralizedHeytingAlgebra (α × β) where
le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff
instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] :
GeneralizedHeytingAlgebra (∀ i, α i) where
le_himp_iff i := by simp [le_def]
end GeneralizedHeytingAlgebra
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra α] {a b c d : α}
@[simp]
theorem sdiff_le_iff : a \ b ≤ c ↔ a ≤ b ⊔ c :=
GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _
theorem sdiff_le_iff' : a \ b ≤ c ↔ a ≤ c ⊔ b := by rw [sdiff_le_iff, sup_comm]
theorem sdiff_le_comm : a \ b ≤ c ↔ a \ c ≤ b := by rw [sdiff_le_iff, sdiff_le_iff']
theorem sdiff_le : a \ b ≤ a :=
sdiff_le_iff.2 le_sup_right
theorem Disjoint.disjoint_sdiff_left (h : Disjoint a b) : Disjoint (a \ c) b :=
h.mono_left sdiff_le
theorem Disjoint.disjoint_sdiff_right (h : Disjoint a b) : Disjoint a (b \ c) :=
h.mono_right sdiff_le
theorem sdiff_le_iff_left : a \ b ≤ b ↔ a ≤ b := by rw [sdiff_le_iff, sup_idem]
@[simp]
theorem sdiff_self : a \ a = ⊥ :=
le_bot_iff.1 <| sdiff_le_iff.2 le_sup_left
theorem le_sup_sdiff : a ≤ b ⊔ a \ b :=
sdiff_le_iff.1 le_rfl
theorem le_sdiff_sup : a ≤ a \ b ⊔ b := by rw [sup_comm, ← sdiff_le_iff]
theorem sup_sdiff_left : a ⊔ a \ b = a :=
sup_of_le_left sdiff_le
theorem sup_sdiff_right : a \ b ⊔ a = a :=
sup_of_le_right sdiff_le
theorem inf_sdiff_left : a \ b ⊓ a = a \ b :=
inf_of_le_left sdiff_le
theorem inf_sdiff_right : a ⊓ a \ b = a \ b :=
inf_of_le_right sdiff_le
@[simp]
theorem sup_sdiff_self (a b : α) : a ⊔ b \ a = a ⊔ b :=
le_antisymm (sup_le_sup_left sdiff_le _) (sup_le le_sup_left le_sup_sdiff)
@[simp]
theorem sdiff_sup_self (a b : α) : b \ a ⊔ a = b ⊔ a := by rw [sup_comm, sup_sdiff_self, sup_comm]
alias sup_sdiff_self_left := sdiff_sup_self
alias sup_sdiff_self_right := sup_sdiff_self
theorem sup_sdiff_eq_sup (h : c ≤ a) : a ⊔ b \ c = a ⊔ b :=
sup_congr_left (sdiff_le.trans le_sup_right) <| le_sup_sdiff.trans <| sup_le_sup_right h _
-- cf. `Set.union_diff_cancel'`
theorem sup_sdiff_cancel' (hab : a ≤ b) (hbc : b ≤ c) : b ⊔ c \ a = c := by
rw [sup_sdiff_eq_sup hab, sup_of_le_right hbc]
theorem sup_sdiff_cancel_right (h : a ≤ b) : a ⊔ b \ a = b :=
sup_sdiff_cancel' le_rfl h
theorem sdiff_sup_cancel (h : b ≤ a) : a \ b ⊔ b = a := by rw [sup_comm, sup_sdiff_cancel_right h]
theorem sup_le_of_le_sdiff_left (h : b ≤ c \ a) (hac : a ≤ c) : a ⊔ b ≤ c :=
sup_le hac <| h.trans sdiff_le
theorem sup_le_of_le_sdiff_right (h : a ≤ c \ b) (hbc : b ≤ c) : a ⊔ b ≤ c :=
sup_le (h.trans sdiff_le) hbc
@[simp]
theorem sdiff_eq_bot_iff : a \ b = ⊥ ↔ a ≤ b := by rw [← le_bot_iff, sdiff_le_iff, sup_bot_eq]
@[simp]
theorem sdiff_bot : a \ ⊥ = a :=
eq_of_forall_ge_iff fun b => by rw [sdiff_le_iff, bot_sup_eq]
@[simp]
theorem bot_sdiff : ⊥ \ a = ⊥ :=
sdiff_eq_bot_iff.2 bot_le
theorem sdiff_sdiff_sdiff_le_sdiff : (a \ b) \ (a \ c) ≤ c \ b := by
rw [sdiff_le_iff, sdiff_le_iff, sup_left_comm, sup_sdiff_self, sup_left_comm, sdiff_sup_self,
sup_left_comm]
exact le_sup_left
@[simp]
theorem le_sup_sdiff_sup_sdiff : a ≤ b ⊔ (a \ c ⊔ c \ b) := by
simpa using @sdiff_sdiff_sdiff_le_sdiff
theorem sdiff_sdiff (a b c : α) : (a \ b) \ c = a \ (b ⊔ c) :=
eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_assoc]
theorem sdiff_sdiff_left : (a \ b) \ c = a \ (b ⊔ c) :=
sdiff_sdiff _ _ _
theorem sdiff_right_comm (a b c : α) : (a \ b) \ c = (a \ c) \ b := by
simp_rw [sdiff_sdiff, sup_comm]
theorem sdiff_sdiff_comm : (a \ b) \ c = (a \ c) \ b :=
sdiff_right_comm _ _ _
@[simp]
theorem sdiff_idem : (a \ b) \ b = a \ b := by rw [sdiff_sdiff_left, sup_idem]
@[simp]
theorem sdiff_sdiff_self : (a \ b) \ a = ⊥ := by rw [sdiff_sdiff_comm, sdiff_self, bot_sdiff]
theorem sup_sdiff_distrib (a b c : α) : (a ⊔ b) \ c = a \ c ⊔ b \ c :=
eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_le_iff, sdiff_le_iff]
theorem sdiff_inf_distrib (a b c : α) : a \ (b ⊓ c) = a \ b ⊔ a \ c :=
eq_of_forall_ge_iff fun d => by
rw [sup_le_iff, sdiff_le_comm, le_inf_iff]
simp_rw [sdiff_le_comm]
theorem sup_sdiff : (a ⊔ b) \ c = a \ c ⊔ b \ c :=
sup_sdiff_distrib _ _ _
@[simp]
theorem sup_sdiff_right_self : (a ⊔ b) \ b = a \ b := by rw [sup_sdiff, sdiff_self, sup_bot_eq]
@[simp]
theorem sup_sdiff_left_self : (a ⊔ b) \ a = b \ a := by rw [sup_comm, sup_sdiff_right_self]
@[gcongr]
theorem sdiff_le_sdiff_right (h : a ≤ b) : a \ c ≤ b \ c :=
sdiff_le_iff.2 <| h.trans <| le_sup_sdiff
@[gcongr]
theorem sdiff_le_sdiff_left (h : a ≤ b) : c \ b ≤ c \ a :=
sdiff_le_iff.2 <| le_sup_sdiff.trans <| sup_le_sup_right h _
@[gcongr]
theorem sdiff_le_sdiff (hab : a ≤ b) (hcd : c ≤ d) : a \ d ≤ b \ c :=
(sdiff_le_sdiff_right hab).trans <| sdiff_le_sdiff_left hcd
-- cf. `IsCompl.inf_sup`
theorem sdiff_inf : a \ (b ⊓ c) = a \ b ⊔ a \ c :=
sdiff_inf_distrib _ _ _
@[simp]
theorem sdiff_inf_self_left (a b : α) : a \ (a ⊓ b) = a \ b := by
rw [sdiff_inf, sdiff_self, bot_sup_eq]
@[simp]
theorem sdiff_inf_self_right (a b : α) : b \ (a ⊓ b) = b \ a := by
rw [sdiff_inf, sdiff_self, sup_bot_eq]
theorem Disjoint.sdiff_eq_left (h : Disjoint a b) : a \ b = a := by
conv_rhs => rw [← @sdiff_bot _ _ a]
rw [← h.eq_bot, sdiff_inf_self_left]
theorem Disjoint.sdiff_eq_right (h : Disjoint a b) : b \ a = b :=
h.symm.sdiff_eq_left
theorem Disjoint.sup_sdiff_cancel_left (h : Disjoint a b) : (a ⊔ b) \ a = b := by
rw [sup_sdiff, sdiff_self, bot_sup_eq, h.sdiff_eq_right]
theorem Disjoint.sup_sdiff_cancel_right (h : Disjoint a b) : (a ⊔ b) \ b = a := by
rw [sup_sdiff, sdiff_self, sup_bot_eq, h.sdiff_eq_left]
/-- See `le_sdiff` for a stronger version in generalised Boolean algebras. -/
theorem Disjoint.le_sdiff_of_le_left (hac : Disjoint a c) (hab : a ≤ b) : a ≤ b \ c :=
hac.sdiff_eq_left.ge.trans <| sdiff_le_sdiff_right hab
theorem sdiff_sdiff_le : a \ (a \ b) ≤ b :=
sdiff_le_iff.2 le_sdiff_sup
@[simp] lemma sdiff_eq_sdiff_iff : a \ b = b \ a ↔ a = b := by simp [le_antisymm_iff]
lemma sdiff_ne_sdiff_iff : a \ b ≠ b \ a ↔ a ≠ b := sdiff_eq_sdiff_iff.not
theorem sdiff_triangle (a b c : α) : a \ c ≤ a \ b ⊔ b \ c := by
rw [sdiff_le_iff, sup_left_comm, ← sdiff_le_iff]
exact sdiff_sdiff_le.trans le_sup_sdiff
theorem sdiff_sup_sdiff_cancel (hba : b ≤ a) (hcb : c ≤ b) : a \ b ⊔ b \ c = a \ c :=
(sdiff_triangle _ _ _).antisymm' <| sup_le (sdiff_le_sdiff_left hcb) (sdiff_le_sdiff_right hba)
/-- a version of `sdiff_sup_sdiff_cancel` with more general hypotheses. -/
theorem sdiff_sup_sdiff_cancel' (hinf : a ⊓ c ≤ b) (hsup : b ≤ a ⊔ c) :
a \ b ⊔ b \ c = a \ c := by
refine (sdiff_triangle ..).antisymm' <| sup_le ?_ <| by simpa [sup_comm]
rw [← sdiff_inf_self_left (b := c)]
exact sdiff_le_sdiff_left hinf
theorem sdiff_le_sdiff_of_sup_le_sup_left (h : c ⊔ a ≤ c ⊔ b) : a \ c ≤ b \ c := by
rw [← sup_sdiff_left_self, ← @sup_sdiff_left_self _ _ _ b]
exact sdiff_le_sdiff_right h
theorem sdiff_le_sdiff_of_sup_le_sup_right (h : a ⊔ c ≤ b ⊔ c) : a \ c ≤ b \ c := by
rw [← sup_sdiff_right_self, ← @sup_sdiff_right_self _ _ b]
exact sdiff_le_sdiff_right h
@[simp]
theorem inf_sdiff_sup_left : a \ c ⊓ (a ⊔ b) = a \ c :=
inf_of_le_left <| sdiff_le.trans le_sup_left
@[simp]
theorem inf_sdiff_sup_right : a \ c ⊓ (b ⊔ a) = a \ c :=
inf_of_le_left <| sdiff_le.trans le_sup_right
theorem gc_sdiff_sup : GaloisConnection (· \ a) (a ⊔ ·) :=
fun _ _ ↦ sdiff_le_iff
-- See note [lower instance priority]
instance (priority := 100) GeneralizedCoheytingAlgebra.toDistribLattice : DistribLattice α :=
{ ‹GeneralizedCoheytingAlgebra α› with
le_sup_inf :=
fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl }
instance OrderDual.instGeneralizedHeytingAlgebra : GeneralizedHeytingAlgebra αᵒᵈ where
himp := fun a b => toDual (ofDual b \ ofDual a)
le_himp_iff := fun a b c => by rw [inf_comm]; exact sdiff_le_iff
| Mathlib/Order/Heyting/Basic.lean | 595 | 595 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.CharP.Reduced
import Mathlib.RingTheory.IntegralDomain
-- TODO: remove Mathlib.Algebra.CharP.Reduced and move the last two lemmas to Lemmas
/-!
# Roots of unity
We define roots of unity in the context of an arbitrary commutative monoid,
as a subgroup of the group of units.
## Main definitions
* `rootsOfUnity n M`, for `n : ℕ` is the subgroup of the units of a commutative monoid `M`
consisting of elements `x` that satisfy `x ^ n = 1`.
## Main results
* `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group.
## Implementation details
It is desirable that `rootsOfUnity` is a subgroup,
and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields.
We therefore implement it as a subgroup of the units of a commutative monoid.
We have chosen to define `rootsOfUnity n` for `n : ℕ` and add a `[NeZero n]` typeclass
assumption when we need `n` to be non-zero (which is the case for most interesting statements).
Note that `rootsOfUnity 0 M` is the top subgroup of `Mˣ` (as the condition `ζ^0 = 1` is
satisfied for all units).
-/
noncomputable section
open Polynomial
open Finset
variable {M N G R S F : Type*}
variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G]
section rootsOfUnity
variable {k l : ℕ}
/-- `rootsOfUnity k M` is the subgroup of elements `m : Mˣ` that satisfy `m ^ k = 1`. -/
def rootsOfUnity (k : ℕ) (M : Type*) [CommMonoid M] : Subgroup Mˣ where
carrier := {ζ | ζ ^ k = 1}
one_mem' := one_pow _
mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul]
inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one]
@[simp]
theorem mem_rootsOfUnity (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ ζ ^ k = 1 :=
Iff.rfl
/-- A variant of `mem_rootsOfUnity` using `ζ : Mˣ`. -/
theorem mem_rootsOfUnity' (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ (ζ : M) ^ k = 1 := by
rw [mem_rootsOfUnity]; norm_cast
@[simp]
theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = ⊥ := by
ext1
simp only [mem_rootsOfUnity, pow_one, Subgroup.mem_bot]
@[simp]
lemma rootsOfUnity_zero (M : Type*) [CommMonoid M] : rootsOfUnity 0 M = ⊤ := by
ext1
simp only [mem_rootsOfUnity, pow_zero, Subgroup.mem_top]
theorem rootsOfUnity.coe_injective {n : ℕ} :
Function.Injective (fun x : rootsOfUnity n M ↦ x.val.val) :=
Units.ext.comp fun _ _ ↦ Subtype.eq
/-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has
a positive power equal to one. -/
@[simps! coe_val]
def rootsOfUnity.mkOfPowEq (ζ : M) {n : ℕ} [NeZero n] (h : ζ ^ n = 1) : rootsOfUnity n M :=
⟨Units.ofPowEqOne ζ n h <| NeZero.ne n, Units.pow_ofPowEqOne _ _⟩
@[simp]
theorem rootsOfUnity.coe_mkOfPowEq {ζ : M} {n : ℕ} [NeZero n] (h : ζ ^ n = 1) :
((rootsOfUnity.mkOfPowEq _ h : Mˣ) : M) = ζ :=
rfl
theorem rootsOfUnity_le_of_dvd (h : k ∣ l) : rootsOfUnity k M ≤ rootsOfUnity l M := by
obtain ⟨d, rfl⟩ := h
intro ζ h
simp_all only [mem_rootsOfUnity, pow_mul, one_pow]
theorem map_rootsOfUnity (f : Mˣ →* Nˣ) (k : ℕ) : (rootsOfUnity k M).map f ≤ rootsOfUnity k N := by
rintro _ ⟨ζ, h, rfl⟩
simp_all only [← map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one]
@[norm_cast]
theorem rootsOfUnity.coe_pow [CommMonoid R] (ζ : rootsOfUnity k R) (m : ℕ) :
(((ζ ^ m :) : Rˣ) : R) = ((ζ : Rˣ) : R) ^ m := by
rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val]
/-- The canonical isomorphism from the `n`th roots of unity in `Mˣ`
to the `n`th roots of unity in `M`. -/
def rootsOfUnityUnitsMulEquiv (M : Type*) [CommMonoid M] (n : ℕ) :
rootsOfUnity n Mˣ ≃* rootsOfUnity n M where
toFun ζ := ⟨ζ.val, (mem_rootsOfUnity ..).mpr <| (mem_rootsOfUnity' ..).mp ζ.prop⟩
invFun ζ := ⟨toUnits ζ.val, by
simp only [mem_rootsOfUnity, ← map_pow, EmbeddingLike.map_eq_one_iff]
exact (mem_rootsOfUnity ..).mp ζ.prop⟩
left_inv ζ := by simp only [toUnits_val_apply, Subtype.coe_eta]
right_inv ζ := by simp only [val_toUnits_apply, Subtype.coe_eta]
map_mul' ζ ζ' := by simp only [Subgroup.coe_mul, Units.val_mul, MulMemClass.mk_mul_mk]
section CommMonoid
variable [CommMonoid R] [CommMonoid S] [FunLike F R S]
/-- Restrict a ring homomorphism to the nth roots of unity. -/
def restrictRootsOfUnity [MonoidHomClass F R S] (σ : F) (n : ℕ) :
rootsOfUnity n R →* rootsOfUnity n S :=
{ toFun := fun ξ ↦ ⟨Units.map σ (ξ : Rˣ), by
rw [mem_rootsOfUnity, ← map_pow, Units.ext_iff, Units.coe_map, ξ.prop]
exact map_one σ⟩
map_one' := by ext1; simp only [OneMemClass.coe_one, map_one]
map_mul' := fun ξ₁ ξ₂ ↦ by
ext1; simp only [Subgroup.coe_mul, map_mul, MulMemClass.mk_mul_mk] }
@[simp]
theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (σ : F) (ζ : rootsOfUnity k R) :
(restrictRootsOfUnity σ k ζ : Sˣ) = σ (ζ : Rˣ) :=
rfl
/-- Restrict a monoid isomorphism to the nth roots of unity. -/
nonrec def MulEquiv.restrictRootsOfUnity (σ : R ≃* S) (n : ℕ) :
rootsOfUnity n R ≃* rootsOfUnity n S where
toFun := restrictRootsOfUnity σ n
invFun := restrictRootsOfUnity σ.symm n
left_inv ξ := by ext; exact σ.symm_apply_apply _
right_inv ξ := by ext; exact σ.apply_symm_apply _
map_mul' := (restrictRootsOfUnity _ n).map_mul
@[simp]
theorem MulEquiv.restrictRootsOfUnity_coe_apply (σ : R ≃* S) (ζ : rootsOfUnity k R) :
(σ.restrictRootsOfUnity k ζ : Sˣ) = σ (ζ : Rˣ) :=
rfl
@[simp]
theorem MulEquiv.restrictRootsOfUnity_symm (σ : R ≃* S) :
(σ.restrictRootsOfUnity k).symm = σ.symm.restrictRootsOfUnity k :=
rfl
end CommMonoid
section IsDomain
-- The following results need `k` to be nonzero.
variable [NeZero k] [CommRing R] [IsDomain R]
theorem mem_rootsOfUnity_iff_mem_nthRoots {ζ : Rˣ} :
ζ ∈ rootsOfUnity k R ↔ (ζ : R) ∈ nthRoots k (1 : R) := by
simp only [mem_rootsOfUnity, mem_nthRoots (NeZero.pos k), Units.ext_iff, Units.val_one,
Units.val_pow_eq_pow_val]
variable (k R)
/-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`.
This is implemented as equivalence of subtypes,
because `rootsOfUnity` is a subgroup of the group of units,
whereas `nthRoots` is a multiset. -/
def rootsOfUnityEquivNthRoots : rootsOfUnity k R ≃ { x // x ∈ nthRoots k (1 : R) } where
toFun x := ⟨(x : Rˣ), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2⟩
invFun x := by
refine ⟨⟨x, ↑x ^ (k - 1 : ℕ), ?_, ?_⟩, ?_⟩
all_goals
rcases x with ⟨x, hx⟩; rw [mem_nthRoots <| NeZero.pos k] at hx
simp only [← pow_succ, ← pow_succ', hx, tsub_add_cancel_of_le NeZero.one_le]
simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, hx, Units.val_one]
left_inv := by rintro ⟨x, hx⟩; ext; rfl
right_inv := by rintro ⟨x, hx⟩; ext; rfl
variable {k R}
@[simp]
theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) :
(rootsOfUnityEquivNthRoots R k x : R) = ((x : Rˣ) : R) :=
rfl
@[simp]
theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x ∈ nthRoots k (1 : R) }) :
(((rootsOfUnityEquivNthRoots R k).symm x : Rˣ) : R) = (x : R) :=
rfl
variable (k R)
instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) := by
classical
exact Fintype.ofEquiv { x // x ∈ nthRoots k (1 : R) } (rootsOfUnityEquivNthRoots R k).symm
instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) :=
isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype) coe_injective
theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) ≤ k := by
classical
calc
Fintype.card (rootsOfUnity k R) = Fintype.card { x // x ∈ nthRoots k (1 : R) } :=
Fintype.card_congr (rootsOfUnityEquivNthRoots R k)
_ ≤ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _)
_ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach
_ ≤ k := card_nthRoots k 1
variable {k R}
theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [MonoidHomClass F R R] (σ : F)
(ζ : rootsOfUnity k R) :
∃ m : ℕ, σ (ζ : Rˣ) = ((ζ : Rˣ) : R) ^ m := by
obtain ⟨m, hm⟩ := MonoidHom.map_cyclic (restrictRootsOfUnity σ k)
rw [← restrictRootsOfUnity_coe_apply, hm, ← zpow_mod_orderOf, ← Int.toNat_of_nonneg
(m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ζ)))),
zpow_natCast, rootsOfUnity.coe_pow]
exact ⟨(m % orderOf ζ).toNat, rfl⟩
end IsDomain
section Reduced
variable (R) [CommRing R] [IsReduced R]
-- @[simp] -- Porting note: simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'`
theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} :
ζ ∈ rootsOfUnity (p ^ k * m) R ↔ ζ ∈ rootsOfUnity m R := by
simp only [mem_rootsOfUnity', ExpChar.pow_prime_pow_mul_eq_one_iff]
/-- A variant of `mem_rootsOfUnity_prime_pow_mul_iff` in terms of `ζ ^ _` -/
@[simp]
theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} :
ζ ^ (p ^ k * m) = 1 ↔ ζ ∈ rootsOfUnity m R := by
rw [← mem_rootsOfUnity, mem_rootsOfUnity_prime_pow_mul_iff]
end Reduced
end rootsOfUnity
section cyclic
namespace IsCyclic
/-- The isomorphism from the group of group homomorphisms from a finite cyclic group `G` of order
`n` into another group `G'` to the group of `n`th roots of unity in `G'` determined by a generator
`g` of `G`. It sends `φ : G →* G'` to `φ g`. -/
noncomputable
def monoidHomMulEquivRootsOfUnityOfGenerator {G : Type*} [CommGroup G] {g : G}
(hg : ∀ (x : G), x ∈ Subgroup.zpowers g) (G' : Type*) [CommGroup G'] :
(G →* G') ≃* rootsOfUnity (Nat.card G) G' where
toFun φ := ⟨(IsUnit.map φ <| Group.isUnit g).unit, by
simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, IsUnit.unit_spec,
← map_pow, pow_card_eq_one', map_one, Units.val_one]⟩
invFun ζ := monoidHomOfForallMemZpowers hg (g' := (ζ.val : G')) <| by
simpa only [orderOf_eq_card_of_forall_mem_zpowers hg, orderOf_dvd_iff_pow_eq_one,
← Units.val_pow_eq_pow_val, Units.val_eq_one] using ζ.prop
left_inv φ := (MonoidHom.eq_iff_eq_on_generator hg _ φ).mpr <| by
simp only [IsUnit.unit_spec, monoidHomOfForallMemZpowers_apply_gen]
right_inv φ := Subtype.ext <| by
simp only [monoidHomOfForallMemZpowers_apply_gen, IsUnit.unit_of_val_units]
map_mul' x y := by
simp only [MonoidHom.mul_apply, MulMemClass.mk_mul_mk, Subtype.mk.injEq, Units.ext_iff,
IsUnit.unit_spec, Units.val_mul]
/-- The group of group homomorphisms from a finite cyclic group `G` of order `n` into another
group `G'` is (noncanonically) isomorphic to the group of `n`th roots of unity in `G'`. -/
lemma monoidHom_mulEquiv_rootsOfUnity (G : Type*) [CommGroup G] [IsCyclic G]
(G' : Type*) [CommGroup G'] :
Nonempty <| (G →* G') ≃* rootsOfUnity (Nat.card G) G' := by
obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := G)
exact ⟨monoidHomMulEquivRootsOfUnityOfGenerator hg G'⟩
end IsCyclic
end cyclic
| Mathlib/RingTheory/RootsOfUnity/Basic.lean | 501 | 509 | |
/-
Copyright (c) 2020 Thomas Browning and Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.GroupTheory.Solvable
import Mathlib.FieldTheory.PolynomialGaloisGroup
import Mathlib.RingTheory.RootsOfUnity.Basic
/-!
# The Abel-Ruffini Theorem
This file proves one direction of the Abel-Ruffini theorem, namely that if an element is solvable
by radicals, then its minimal polynomial has solvable Galois group.
## Main definitions
* `solvableByRad F E` : the intermediate field of solvable-by-radicals elements
## Main results
* the Abel-Ruffini Theorem `solvableByRad.isSolvable'` : An irreducible polynomial with a root
that is solvable by radicals has a solvable Galois group.
-/
noncomputable section
open Polynomial IntermediateField
section AbelRuffini
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
theorem gal_zero_isSolvable : IsSolvable (0 : F[X]).Gal := by infer_instance
theorem gal_one_isSolvable : IsSolvable (1 : F[X]).Gal := by infer_instance
theorem gal_C_isSolvable (x : F) : IsSolvable (C x).Gal := by infer_instance
theorem gal_X_isSolvable : IsSolvable (X : F[X]).Gal := by infer_instance
theorem gal_X_sub_C_isSolvable (x : F) : IsSolvable (X - C x).Gal := by infer_instance
theorem gal_X_pow_isSolvable (n : ℕ) : IsSolvable (X ^ n : F[X]).Gal := by infer_instance
theorem gal_mul_isSolvable {p q : F[X]} (_ : IsSolvable p.Gal) (_ : IsSolvable q.Gal) :
IsSolvable (p * q).Gal :=
solvable_of_solvable_injective (Gal.restrictProd_injective p q)
theorem gal_prod_isSolvable {s : Multiset F[X]} (hs : ∀ p ∈ s, IsSolvable (Gal p)) :
IsSolvable s.prod.Gal := by
apply Multiset.induction_on' s
· exact gal_one_isSolvable
· intro p t hps _ ht
rw [Multiset.insert_eq_cons, Multiset.prod_cons]
exact gal_mul_isSolvable (hs p hps) ht
theorem gal_isSolvable_of_splits {p q : F[X]}
(_ : Fact (p.Splits (algebraMap F q.SplittingField))) (hq : IsSolvable q.Gal) :
IsSolvable p.Gal :=
haveI : IsSolvable (q.SplittingField ≃ₐ[F] q.SplittingField) := hq
solvable_of_surjective (AlgEquiv.restrictNormalHom_surjective q.SplittingField)
theorem gal_isSolvable_tower (p q : F[X]) (hpq : p.Splits (algebraMap F q.SplittingField))
(hp : IsSolvable p.Gal) (hq : IsSolvable (q.map (algebraMap F p.SplittingField)).Gal) :
IsSolvable q.Gal := by
let K := p.SplittingField
let L := q.SplittingField
haveI : Fact (p.Splits (algebraMap F L)) := ⟨hpq⟩
let ϕ : (L ≃ₐ[K] L) ≃* (q.map (algebraMap F K)).Gal :=
(IsSplittingField.algEquiv L (q.map (algebraMap F K))).autCongr
have ϕ_inj : Function.Injective ϕ.toMonoidHom := ϕ.injective
haveI : IsSolvable (K ≃ₐ[F] K) := hp
haveI : IsSolvable (L ≃ₐ[K] L) := solvable_of_solvable_injective ϕ_inj
exact isSolvable_of_isScalarTower F p.SplittingField q.SplittingField
section GalXPowSubC
theorem gal_X_pow_sub_one_isSolvable (n : ℕ) : IsSolvable (X ^ n - 1 : F[X]).Gal := by
by_cases hn : n = 0
· rw [hn, pow_zero, sub_self]
exact gal_zero_isSolvable
have hn' : 0 < n := pos_iff_ne_zero.mpr hn
have hn'' : (X ^ n - 1 : F[X]) ≠ 0 := X_pow_sub_C_ne_zero hn' 1
apply isSolvable_of_comm
intro σ τ
ext a ha
simp only [mem_rootSet_of_ne hn'', map_sub, aeval_X_pow, aeval_one, sub_eq_zero] at ha
have key : ∀ σ : (X ^ n - 1 : F[X]).Gal, ∃ m : ℕ, σ a = a ^ m := by
intro σ
lift n to ℕ+ using hn'
exact map_rootsOfUnity_eq_pow_self σ.toAlgHom (rootsOfUnity.mkOfPowEq a ha)
obtain ⟨c, hc⟩ := key σ
obtain ⟨d, hd⟩ := key τ
rw [σ.mul_apply, τ.mul_apply, hc, map_pow, hd, map_pow, hc, ← pow_mul, pow_mul']
theorem gal_X_pow_sub_C_isSolvable_aux (n : ℕ) (a : F)
(h : (X ^ n - 1 : F[X]).Splits (RingHom.id F)) : IsSolvable (X ^ n - C a).Gal := by
by_cases ha : a = 0
· rw [ha, C_0, sub_zero]
exact gal_X_pow_isSolvable n
have ha' : algebraMap F (X ^ n - C a).SplittingField a ≠ 0 :=
mt ((injective_iff_map_eq_zero _).mp (RingHom.injective _) a) ha
by_cases hn : n = 0
· rw [hn, pow_zero, ← C_1, ← C_sub]
exact gal_C_isSolvable (1 - a)
have hn' : 0 < n := pos_iff_ne_zero.mpr hn
have hn'' : X ^ n - C a ≠ 0 := X_pow_sub_C_ne_zero hn' a
have hn''' : (X ^ n - 1 : F[X]) ≠ 0 := X_pow_sub_C_ne_zero hn' 1
have mem_range : ∀ {c : (X ^ n - C a).SplittingField},
(c ^ n = 1 → (∃ d, algebraMap F (X ^ n - C a).SplittingField d = c)) := fun {c} hc =>
RingHom.mem_range.mp (minpoly.mem_range_of_degree_eq_one F c (h.def.resolve_left hn'''
(minpoly.irreducible ((SplittingField.instNormal (X ^ n - C a)).isIntegral c))
(minpoly.dvd F c (by rwa [map_id, map_sub, sub_eq_zero, aeval_X_pow, aeval_one]))))
apply isSolvable_of_comm
intro σ τ
ext b hb
rw [mem_rootSet_of_ne hn'', map_sub, aeval_X_pow, aeval_C, sub_eq_zero] at hb
have hb' : b ≠ 0 := by
intro hb'
rw [hb', zero_pow hn] at hb
exact ha' hb.symm
have key : ∀ σ : (X ^ n - C a).Gal, ∃ c, σ b = b * algebraMap F _ c := by
intro σ
have key : (σ b / b) ^ n = 1 := by rw [div_pow, ← map_pow, hb, σ.commutes, div_self ha']
obtain ⟨c, hc⟩ := mem_range key
use c
rw [hc, mul_div_cancel₀ (σ b) hb']
obtain ⟨c, hc⟩ := key σ
obtain ⟨d, hd⟩ := key τ
rw [σ.mul_apply, τ.mul_apply, hc, map_mul, τ.commutes, hd, map_mul, σ.commutes, hc,
mul_assoc, mul_assoc, mul_right_inj' hb', mul_comm]
theorem splits_X_pow_sub_one_of_X_pow_sub_C {F : Type*} [Field F] {E : Type*} [Field E]
(i : F →+* E) (n : ℕ) {a : F} (ha : a ≠ 0) (h : (X ^ n - C a).Splits i) :
(X ^ n - 1 : F[X]).Splits i := by
have ha' : i a ≠ 0 := mt ((injective_iff_map_eq_zero i).mp i.injective a) ha
by_cases hn : n = 0
· rw [hn, pow_zero, sub_self]
exact splits_zero i
have hn' : 0 < n := pos_iff_ne_zero.mpr hn
have hn'' : (X ^ n - C a).degree ≠ 0 :=
ne_of_eq_of_ne (degree_X_pow_sub_C hn' a) (mt WithBot.coe_eq_coe.mp hn)
obtain ⟨b, hb⟩ := exists_root_of_splits i h hn''
rw [eval₂_sub, eval₂_X_pow, eval₂_C, sub_eq_zero] at hb
have hb' : b ≠ 0 := by
intro hb'
rw [hb', zero_pow hn] at hb
exact ha' hb.symm
let s := ((X ^ n - C a).map i).roots
have hs : _ = _ * (s.map _).prod := eq_prod_roots_of_splits h
rw [leadingCoeff_X_pow_sub_C hn', RingHom.map_one, C_1, one_mul] at hs
have hs' : Multiset.card s = n := (natDegree_eq_card_roots h).symm.trans natDegree_X_pow_sub_C
apply @splits_of_exists_multiset F E _ _ i (X ^ n - 1) (s.map fun c : E => c / b)
rw [leadingCoeff_X_pow_sub_one hn', RingHom.map_one, C_1, one_mul, Multiset.map_map]
have C_mul_C : C (i a⁻¹) * C (i a) = 1 := by
rw [← C_mul, ← i.map_mul, inv_mul_cancel₀ ha, i.map_one, C_1]
have key1 : (X ^ n - 1 : F[X]).map i = C (i a⁻¹) * ((X ^ n - C a).map i).comp (C b * X) := by
rw [Polynomial.map_sub, Polynomial.map_sub, Polynomial.map_pow, map_X, map_C,
Polynomial.map_one, sub_comp, pow_comp, X_comp, C_comp, mul_pow, ← C_pow, hb, mul_sub, ←
mul_assoc, C_mul_C, one_mul]
have key2 : ((fun q : E[X] => q.comp (C b * X)) ∘ fun c : E => X - C c) = fun c : E =>
C b * (X - C (c / b)) := by
ext1 c
dsimp only [Function.comp_apply]
rw [sub_comp, X_comp, C_comp, mul_sub, ← C_mul, mul_div_cancel₀ c hb']
rw [key1, hs, multiset_prod_comp, Multiset.map_map, key2, Multiset.prod_map_mul,
Function.const_def (α := E) (y := C b), Multiset.map_const, Multiset.prod_replicate,
hs', ← C_pow, hb, ← mul_assoc, C_mul_C, one_mul]
rfl
theorem gal_X_pow_sub_C_isSolvable (n : ℕ) (x : F) : IsSolvable (X ^ n - C x).Gal := by
by_cases hx : x = 0
· rw [hx, C_0, sub_zero]
exact gal_X_pow_isSolvable n
apply gal_isSolvable_tower (X ^ n - 1) (X ^ n - C x)
· exact splits_X_pow_sub_one_of_X_pow_sub_C _ n hx (SplittingField.splits _)
· exact gal_X_pow_sub_one_isSolvable n
· rw [Polynomial.map_sub, Polynomial.map_pow, map_X, map_C]
apply gal_X_pow_sub_C_isSolvable_aux
have key := SplittingField.splits (X ^ n - 1 : F[X])
rwa [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_pow, map_X,
Polynomial.map_one] at key
end GalXPowSubC
variable (F)
/-- Inductive definition of solvable by radicals -/
inductive IsSolvableByRad : E → Prop
| base (α : F) : IsSolvableByRad (algebraMap F E α)
| add (α β : E) : IsSolvableByRad α → IsSolvableByRad β → IsSolvableByRad (α + β)
| neg (α : E) : IsSolvableByRad α → IsSolvableByRad (-α)
| mul (α β : E) : IsSolvableByRad α → IsSolvableByRad β → IsSolvableByRad (α * β)
| inv (α : E) : IsSolvableByRad α → IsSolvableByRad α⁻¹
| rad (α : E) (n : ℕ) (hn : n ≠ 0) : IsSolvableByRad (α ^ n) → IsSolvableByRad α
variable (E)
/-- The intermediate field of solvable-by-radicals elements -/
def solvableByRad : IntermediateField F E where
carrier := IsSolvableByRad F
zero_mem' := by
change IsSolvableByRad F 0
convert IsSolvableByRad.base (E := E) (0 : F); rw [RingHom.map_zero]
add_mem' := by apply IsSolvableByRad.add
one_mem' := by
change IsSolvableByRad F 1
convert IsSolvableByRad.base (E := E) (1 : F); rw [RingHom.map_one]
mul_mem' := by apply IsSolvableByRad.mul
inv_mem' := IsSolvableByRad.inv
algebraMap_mem' := IsSolvableByRad.base
namespace solvableByRad
variable {F} {E} {α : E}
theorem induction (P : solvableByRad F E → Prop)
(base : ∀ α : F, P (algebraMap F (solvableByRad F E) α))
(add : ∀ α β : solvableByRad F E, P α → P β → P (α + β))
(neg : ∀ α : solvableByRad F E, P α → P (-α))
(mul : ∀ α β : solvableByRad F E, P α → P β → P (α * β))
(inv : ∀ α : solvableByRad F E, P α → P α⁻¹)
(rad : ∀ α : solvableByRad F E, ∀ n : ℕ, n ≠ 0 → P (α ^ n) → P α) (α : solvableByRad F E) :
P α := by
revert α
suffices ∀ α : E, IsSolvableByRad F α → ∃ β : solvableByRad F E, ↑β = α ∧ P β by
intro α
obtain ⟨α₀, hα₀, Pα⟩ := this α (Subtype.mem α)
convert Pα
exact Subtype.ext hα₀.symm
apply IsSolvableByRad.rec
· exact fun α => ⟨algebraMap F (solvableByRad F E) α, rfl, base α⟩
· intro α β _ _ Pα Pβ
obtain ⟨⟨α₀, hα₀, Pα⟩, β₀, hβ₀, Pβ⟩ := Pα, Pβ
exact ⟨α₀ + β₀, by rw [← hα₀, ← hβ₀]; rfl, add α₀ β₀ Pα Pβ⟩
· intro α _ Pα
obtain ⟨α₀, hα₀, Pα⟩ := Pα
exact ⟨-α₀, by rw [← hα₀]; rfl, neg α₀ Pα⟩
· intro α β _ _ Pα Pβ
obtain ⟨⟨α₀, hα₀, Pα⟩, β₀, hβ₀, Pβ⟩ := Pα, Pβ
exact ⟨α₀ * β₀, by rw [← hα₀, ← hβ₀]; rfl, mul α₀ β₀ Pα Pβ⟩
· intro α _ Pα
obtain ⟨α₀, hα₀, Pα⟩ := Pα
exact ⟨α₀⁻¹, by rw [← hα₀]; rfl, inv α₀ Pα⟩
· intro α n hn hα Pα
obtain ⟨α₀, hα₀, Pα⟩ := Pα
refine ⟨⟨α, IsSolvableByRad.rad α n hn hα⟩, rfl, rad _ n hn ?_⟩
convert Pα
exact Subtype.ext (Eq.trans ((solvableByRad F E).coe_pow _ n) hα₀.symm)
theorem isIntegral (α : solvableByRad F E) : IsIntegral F α := by
revert α
apply solvableByRad.induction
· exact fun _ => isIntegral_algebraMap
· exact fun _ _ => IsIntegral.add
· exact fun _ => IsIntegral.neg
· exact fun _ _ => IsIntegral.mul
· intro α hα
exact IsIntegral.inv hα
· intro α n hn hα
obtain ⟨p, h1, h2⟩ := hα.isAlgebraic
refine IsAlgebraic.isIntegral ⟨p.comp (X ^ n),
⟨fun h => h1 (leadingCoeff_eq_zero.mp ?_), by rw [aeval_comp, aeval_X_pow, h2]⟩⟩
rwa [← leadingCoeff_eq_zero, leadingCoeff_comp, leadingCoeff_X_pow, one_pow, mul_one] at h
rwa [natDegree_X_pow]
/-- The statement to be proved inductively -/
def P (α : solvableByRad F E) : Prop :=
IsSolvable (minpoly F α).Gal
/-- An auxiliary induction lemma, which is generalized by `solvableByRad.isSolvable`. -/
theorem induction3 {α : solvableByRad F E} {n : ℕ} (hn : n ≠ 0) (hα : P (α ^ n)) : P α := by
let p := minpoly F (α ^ n)
have hp : p.comp (X ^ n) ≠ 0 := by
intro h
rcases comp_eq_zero_iff.mp h with h' | h'
· exact minpoly.ne_zero (isIntegral (α ^ n)) h'
· exact hn (by rw [← @natDegree_C F, ← h'.2, natDegree_X_pow])
apply gal_isSolvable_of_splits
· exact ⟨splits_of_splits_of_dvd _ hp (SplittingField.splits (p.comp (X ^ n)))
(minpoly.dvd F α (by rw [aeval_comp, aeval_X_pow, minpoly.aeval]))⟩
· refine gal_isSolvable_tower p (p.comp (X ^ n)) ?_ hα ?_
· exact Gal.splits_in_splittingField_of_comp _ _ (by rwa [natDegree_X_pow])
· obtain ⟨s, hs⟩ := (splits_iff_exists_multiset _).1 (SplittingField.splits p)
rw [map_comp, Polynomial.map_pow, map_X, hs, mul_comp, C_comp]
apply gal_mul_isSolvable (gal_C_isSolvable _)
rw [multiset_prod_comp]
apply gal_prod_isSolvable
intro q hq
rw [Multiset.mem_map] at hq
obtain ⟨q, hq, rfl⟩ := hq
rw [Multiset.mem_map] at hq
obtain ⟨q, _, rfl⟩ := hq
rw [sub_comp, X_comp, C_comp]
exact gal_X_pow_sub_C_isSolvable n q
/-- An auxiliary induction lemma, which is generalized by `solvableByRad.isSolvable`. -/
theorem induction2 {α β γ : solvableByRad F E} (hγ : γ ∈ F⟮α, β⟯) (hα : P α) (hβ : P β) : P γ := by
let p := minpoly F α
let q := minpoly F β
have hpq := Polynomial.splits_of_splits_mul _
(mul_ne_zero (minpoly.ne_zero (isIntegral α)) (minpoly.ne_zero (isIntegral β)))
(SplittingField.splits (p * q))
let f : ↥F⟮α, β⟯ →ₐ[F] (p * q).SplittingField :=
Classical.choice <| nonempty_algHom_adjoin_of_splits <| by
intro x hx
simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hx
cases hx with rw [hx]
| inl hx => exact ⟨isIntegral α, hpq.1⟩
| inr hx => exact ⟨isIntegral β, hpq.2⟩
have key : minpoly F γ = minpoly F (f ⟨γ, hγ⟩) := by
refine minpoly.eq_of_irreducible_of_monic
(minpoly.irreducible (isIntegral γ)) ?_ (minpoly.monic (isIntegral γ))
suffices aeval (⟨γ, hγ⟩ : F⟮α, β⟯) (minpoly F γ) = 0 by
rw [aeval_algHom_apply, this, map_zero]
apply (algebraMap (↥F⟮α, β⟯) (solvableByRad F E)).injective
simp only [map_zero, _root_.map_eq_zero]
-- Porting note: end of the proof was `exact minpoly.aeval F γ`.
apply Subtype.val_injective
dsimp only [← coe_type_toSubalgebra]
rw [Polynomial.aeval_subalgebra_coe (minpoly F γ)]
simp
rw [P, key]
refine gal_isSolvable_of_splits ⟨Normal.splits ?_ (f ⟨γ, hγ⟩)⟩ (gal_mul_isSolvable hα hβ)
apply SplittingField.instNormal
/-- An auxiliary induction lemma, which is generalized by `solvableByRad.isSolvable`. -/
theorem induction1 {α β : solvableByRad F E} (hβ : β ∈ F⟮α⟯) (hα : P α) : P β :=
induction2 (adjoin.mono F _ _ (ge_of_eq (Set.pair_eq_singleton α)) hβ) hα hα
theorem isSolvable (α : solvableByRad F E) : IsSolvable (minpoly F α).Gal := by
revert α
apply solvableByRad.induction
· exact fun α => by rw [minpoly.eq_X_sub_C (solvableByRad F E)]; exact gal_X_sub_C_isSolvable α
· exact fun α β => induction2 (add_mem (subset_adjoin F _ (Set.mem_insert α _))
(subset_adjoin F _ (Set.mem_insert_of_mem α (Set.mem_singleton β))))
· exact fun α => induction1 (neg_mem (mem_adjoin_simple_self F α))
· exact fun α β => induction2 (mul_mem (subset_adjoin F _ (Set.mem_insert α _))
(subset_adjoin F _ (Set.mem_insert_of_mem α (Set.mem_singleton β))))
· exact fun α => induction1 (inv_mem (mem_adjoin_simple_self F α))
· exact fun α n => induction3
/-- **Abel-Ruffini Theorem** (one direction): An irreducible polynomial with an
`IsSolvableByRad` root has solvable Galois group -/
theorem isSolvable' {α : E} {q : F[X]} (q_irred : Irreducible q) (q_aeval : aeval α q = 0)
(hα : IsSolvableByRad F α) : IsSolvable q.Gal := by
have : _root_.IsSolvable (q * C q.leadingCoeff⁻¹).Gal := by
rw [minpoly.eq_of_irreducible q_irred q_aeval, ←
show minpoly F (⟨α, hα⟩ : solvableByRad F E) = minpoly F α from
(minpoly.algebraMap_eq (RingHom.injective _) _).symm]
exact isSolvable ⟨α, hα⟩
refine solvable_of_surjective (Gal.restrictDvd_surjective ⟨C q.leadingCoeff⁻¹, rfl⟩ ?_)
rw [mul_ne_zero_iff, Ne, Ne, C_eq_zero, inv_eq_zero]
exact ⟨q_irred.ne_zero, leadingCoeff_ne_zero.mpr q_irred.ne_zero⟩
end solvableByRad
end AbelRuffini
| Mathlib/FieldTheory/AbelRuffini.lean | 385 | 394 | |
/-
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, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.MonoidAlgebra.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Ring.Action.Rat
import Mathlib.Data.Finset.Sort
import Mathlib.Tactic.FastInstance
/-!
# Theory of univariate polynomials
This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds
a semiring structure on it, and gives basic definitions that are expanded in other files in this
directory.
## Main definitions
* `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map.
* `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism.
* `X` is the polynomial `X`, i.e., `monomial 1 1`.
* `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied
to coefficients of the polynomial `p`.
* `p.erase n` is the polynomial `p` in which one removes the `c X^n` term.
There are often two natural variants of lemmas involving sums, depending on whether one acts on the
polynomials, or on the function. The naming convention is that one adds `index` when acting on
the polynomials. For instance,
* `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`;
* `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`.
* Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`.
## Implementation
Polynomials are defined using `R[ℕ]`, where `R` is a semiring.
The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity
`X * p = p * X`. The relationship to `R[ℕ]` is through a structure
to make polynomials irreducible from the point of view of the kernel. Most operations
are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two
exceptions that we make semireducible:
* The zero polynomial, so that its coefficients are definitionally equal to `0`.
* The scalar action, to permit typeclass search to unfold it to resolve potential instance
diamonds.
The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is
done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial
gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The
equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should
in general not be used once the basic API for polynomials is constructed.
-/
noncomputable section
/-- `Polynomial R` is the type of univariate polynomials over `R`,
denoted as `R[X]` within the `Polynomial` namespace.
Polynomials should be seen as (semi-)rings with the additional constructor `X`.
The embedding from `R` is called `C`. -/
structure Polynomial (R : Type*) [Semiring R] where ofFinsupp ::
toFinsupp : AddMonoidAlgebra R ℕ
@[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R
open AddMonoidAlgebra Finset
open Finsupp hiding single
open Function hiding Commute
namespace Polynomial
universe u
variable {R : Type u} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
theorem forall_iff_forall_finsupp (P : R[X] → Prop) :
(∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ :=
⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩
theorem exists_iff_exists_finsupp (P : R[X] → Prop) :
(∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ :=
⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩
@[simp]
theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl
/-! ### Conversions to and from `AddMonoidAlgebra`
Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping
it, we have to copy across all the arithmetic operators manually, along with the lemmas about how
they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`.
-/
section AddMonoidAlgebra
private irreducible_def add : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a + b⟩
private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X]
| ⟨a⟩ => ⟨-a⟩
private irreducible_def mul : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a * b⟩
instance zero : Zero R[X] :=
⟨⟨0⟩⟩
instance one : One R[X] :=
⟨⟨1⟩⟩
instance add' : Add R[X] :=
⟨add⟩
instance neg' {R : Type u} [Ring R] : Neg R[X] :=
⟨neg⟩
instance sub {R : Type u} [Ring R] : Sub R[X] :=
⟨fun a b => a + -b⟩
instance mul' : Mul R[X] :=
⟨mul⟩
-- If the private definitions are accidentally exposed, simplify them away.
@[simp] theorem add_eq_add : add p q = p + q := rfl
@[simp] theorem mul_eq_mul : mul p q = p * q := rfl
instance instNSMul : SMul ℕ R[X] where
smul r p := ⟨r • p.toFinsupp⟩
instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where
smul r p := ⟨r • p.toFinsupp⟩
smul_zero a := congr_arg ofFinsupp (smul_zero a)
instance {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] :
NoZeroSMulDivisors S R[X] where
eq_zero_or_eq_zero_of_smul_eq_zero eq :=
(eq_zero_or_eq_zero_of_smul_eq_zero <| congr_arg toFinsupp eq).imp id (congr_arg ofFinsupp)
-- to avoid a bug in the `ring` tactic
instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p
@[simp]
theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 :=
rfl
@[simp]
theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 :=
rfl
@[simp]
theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ :=
show _ = add _ _ by rw [add_def]
@[simp]
theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ :=
show _ = neg _ by rw [neg_def]
@[simp]
theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by
rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg]
rfl
|
@[simp]
| Mathlib/Algebra/Polynomial/Basic.lean | 168 | 169 |
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Cover.Open
import Mathlib.AlgebraicGeometry.Over
/-!
# Restriction of Schemes and Morphisms
## Main definition
- `AlgebraicGeometry.Scheme.restrict`: The restriction of a scheme along an open embedding.
The map `X.restrict f ⟶ X` is `AlgebraicGeometry.Scheme.ofRestrict`.
`U : X.Opens` has a coercion to `Scheme` and `U.ι` is a shorthand
for `X.restrict U.open_embedding : U ⟶ X`.
- `AlgebraicGeometry.morphism_restrict`: The restriction of `X ⟶ Y` to `X ∣_ᵤ f ⁻¹ᵁ U ⟶ Y ∣_ᵤ U`.
-/
-- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737
noncomputable section
open TopologicalSpace CategoryTheory Opposite
open CategoryTheory.Limits
namespace AlgebraicGeometry
universe v v₁ v₂ u u₁
variable {C : Type u₁} [Category.{v} C]
section
variable {X : Scheme.{u}} (U : X.Opens)
namespace Scheme.Opens
/-- Open subset of a scheme as a scheme. -/
@[coe]
def toScheme {X : Scheme.{u}} (U : X.Opens) : Scheme.{u} :=
X.restrict U.isOpenEmbedding
instance : CoeOut X.Opens Scheme := ⟨toScheme⟩
/-- The restriction of a scheme to an open subset. -/
def ι : ↑U ⟶ X := X.ofRestrict _
@[simp]
lemma ι_base_apply (x : U) : U.ι.base x = x.val := rfl
instance : IsOpenImmersion U.ι := inferInstanceAs (IsOpenImmersion (X.ofRestrict _))
@[simps! over] instance : U.toScheme.CanonicallyOver X where
hom := U.ι
instance (U : X.Opens) : U.ι.IsOver X where
lemma toScheme_carrier : (U : Type u) = (U : Set X) := rfl
lemma toScheme_presheaf_obj (V) : Γ(U, V) = Γ(X, U.ι ''ᵁ V) := rfl
@[simp]
lemma toScheme_presheaf_map {V W} (i : V ⟶ W) :
U.toScheme.presheaf.map i = X.presheaf.map (U.ι.opensFunctor.map i.unop).op := rfl
@[simp]
lemma ι_app (V) : U.ι.app V = X.presheaf.map
(homOfLE (x := U.ι ''ᵁ U.ι ⁻¹ᵁ V) (Set.image_preimage_subset _ _)).op :=
rfl
@[simp]
lemma ι_appTop :
U.ι.appTop = X.presheaf.map (homOfLE (x := U.ι ''ᵁ ⊤) le_top).op :=
rfl
@[simp]
lemma ι_appLE (V W e) :
U.ι.appLE V W e =
X.presheaf.map (homOfLE (x := U.ι ''ᵁ W) (Set.image_subset_iff.mpr ‹_›)).op := by
| simp only [Hom.appLE, ι_app, Functor.op_obj, Opens.carrier_eq_coe, toScheme_presheaf_map,
Quiver.Hom.unop_op, Hom.opensFunctor_map_homOfLE, Opens.coe_inclusion', ← Functor.map_comp]
rfl
| Mathlib/AlgebraicGeometry/Restrict.lean | 84 | 87 |
/-
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.Data.Set.Prod
/-!
# N-ary images of sets
This file defines `Set.image2`, the binary image of sets.
This is mostly useful to define pointwise operations and `Set.seq`.
## Notes
This file is very similar to `Data.Finset.NAry`, to `Order.Filter.NAry`, and to
`Data.Option.NAry`. Please keep them in sync.
-/
open Function
namespace Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} {f f' : α → β → γ}
variable {s s' : Set α} {t t' : Set β} {u : Set γ} {v : Set δ} {a : α} {b : β}
theorem mem_image2_iff (hf : Injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t :=
⟨by
rintro ⟨a', ha', b', hb', h⟩
| rcases hf h with ⟨rfl, rfl⟩
exact ⟨ha', hb'⟩, fun ⟨ha, hb⟩ => mem_image2_of_mem ha hb⟩
/-- image2 is monotone with respect to `⊆`. -/
@[gcongr]
| Mathlib/Data/Set/NAry.lean | 29 | 33 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.LeftHomology
import Mathlib.CategoryTheory.Limits.Opposites
/-!
# Right Homology of short complexes
In this file, we define the dual notions to those defined in
`Algebra.Homology.ShortComplex.LeftHomology`. In particular, if `S : ShortComplex C` is
a short complex consisting of two composable maps `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such
that `f ≫ g = 0`, we define `h : S.RightHomologyData` to be the datum of morphisms
`p : X₂ ⟶ Q` and `ι : H ⟶ Q` such that `Q` identifies to the cokernel of `f` and `H`
to the kernel of the induced map `g' : Q ⟶ X₃`.
When such a `S.RightHomologyData` exists, we shall say that `[S.HasRightHomology]`
and we define `S.rightHomology` to be the `H` field of a chosen right homology data.
Similarly, we define `S.opcycles` to be the `Q` field.
In `Homology.lean`, when `S` has two compatible left and right homology data
(i.e. they give the same `H` up to a canonical isomorphism), we shall define
`[S.HasHomology]` and `S.homology`.
-/
namespace CategoryTheory
open Category Limits
namespace ShortComplex
variable {C : Type*} [Category C] [HasZeroMorphisms C]
(S : ShortComplex C) {S₁ S₂ S₃ : ShortComplex C}
/-- A right homology data for a short complex `S` consists of morphisms `p : S.X₂ ⟶ Q` and
`ι : H ⟶ Q` such that `p` identifies `Q` to the kernel of `f : S.X₁ ⟶ S.X₂`,
and that `ι` identifies `H` to the kernel of the induced map `g' : Q ⟶ S.X₃` -/
structure RightHomologyData where
/-- a choice of cokernel of `S.f : S.X₁ ⟶ S.X₂` -/
Q : C
/-- a choice of kernel of the induced morphism `S.g' : S.Q ⟶ X₃` -/
H : C
/-- the projection from `S.X₂` -/
p : S.X₂ ⟶ Q
/-- the inclusion of the (right) homology in the chosen cokernel of `S.f` -/
ι : H ⟶ Q
/-- the cokernel condition for `p` -/
wp : S.f ≫ p = 0
/-- `p : S.X₂ ⟶ Q` is a cokernel of `S.f : S.X₁ ⟶ S.X₂` -/
hp : IsColimit (CokernelCofork.ofπ p wp)
/-- the kernel condition for `ι` -/
wι : ι ≫ hp.desc (CokernelCofork.ofπ _ S.zero) = 0
/-- `ι : H ⟶ Q` is a kernel of `S.g' : Q ⟶ S.X₃` -/
hι : IsLimit (KernelFork.ofι ι wι)
initialize_simps_projections RightHomologyData (-hp, -hι)
namespace RightHomologyData
/-- The chosen cokernels and kernels of the limits API give a `RightHomologyData` -/
@[simps]
noncomputable def ofHasCokernelOfHasKernel
[HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] :
S.RightHomologyData :=
{ Q := cokernel S.f,
H := kernel (cokernel.desc S.f S.g S.zero),
p := cokernel.π _,
ι := kernel.ι _,
wp := cokernel.condition _,
hp := cokernelIsCokernel _,
wι := kernel.condition _,
hι := kernelIsKernel _, }
attribute [reassoc (attr := simp)] wp wι
variable {S}
variable (h : S.RightHomologyData) {A : C}
instance : Epi h.p := ⟨fun _ _ => Cofork.IsColimit.hom_ext h.hp⟩
instance : Mono h.ι := ⟨fun _ _ => Fork.IsLimit.hom_ext h.hι⟩
/-- Any morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0` descends
to a morphism `Q ⟶ A` -/
def descQ (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.Q ⟶ A :=
h.hp.desc (CokernelCofork.ofπ k hk)
@[reassoc (attr := simp)]
lemma p_descQ (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.p ≫ h.descQ k hk = k :=
h.hp.fac _ WalkingParallelPair.one
/-- The morphism from the (right) homology attached to a morphism
`k : S.X₂ ⟶ A` such that `S.f ≫ k = 0`. -/
@[simp]
def descH (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.H ⟶ A :=
h.ι ≫ h.descQ k hk
/-- The morphism `h.Q ⟶ S.X₃` induced by `S.g : S.X₂ ⟶ S.X₃` and the fact that
`h.Q` is a cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/
def g' : h.Q ⟶ S.X₃ := h.descQ S.g S.zero
@[reassoc (attr := simp)] lemma p_g' : h.p ≫ h.g' = S.g := p_descQ _ _ _
@[reassoc (attr := simp)] lemma ι_g' : h.ι ≫ h.g' = 0 := h.wι
@[reassoc]
lemma ι_descQ_eq_zero_of_boundary (k : S.X₂ ⟶ A) (x : S.X₃ ⟶ A) (hx : k = S.g ≫ x) :
h.ι ≫ h.descQ k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := by
rw [show 0 = h.ι ≫ h.g' ≫ x by simp]
congr 1
simp only [← cancel_epi h.p, hx, p_descQ, p_g'_assoc]
/-- For `h : S.RightHomologyData`, this is a restatement of `h.hι`, saying that
`ι : h.H ⟶ h.Q` is a kernel of `h.g' : h.Q ⟶ S.X₃`. -/
def hι' : IsLimit (KernelFork.ofι h.ι h.ι_g') := h.hι
/-- The morphism `A ⟶ H` induced by a morphism `k : A ⟶ Q` such that `k ≫ g' = 0` -/
def liftH (k : A ⟶ h.Q) (hk : k ≫ h.g' = 0) : A ⟶ h.H :=
h.hι.lift (KernelFork.ofι k hk)
@[reassoc (attr := simp)]
lemma liftH_ι (k : A ⟶ h.Q) (hk : k ≫ h.g' = 0) : h.liftH k hk ≫ h.ι = k :=
h.hι.fac (KernelFork.ofι k hk) WalkingParallelPair.zero
| lemma isIso_p (hf : S.f = 0) : IsIso h.p :=
⟨h.descQ (𝟙 S.X₂) (by rw [hf, comp_id]), p_descQ _ _ _, by
simp only [← cancel_epi h.p, p_descQ_assoc, id_comp, comp_id]⟩
| Mathlib/Algebra/Homology/ShortComplex/RightHomology.lean | 129 | 131 |
/-
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.Control.Basic
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.List.Monad
import Mathlib.Logic.OpClass
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
/-!
# Basic properties of lists
-/
assert_not_exists GroupWithZero
assert_not_exists Lattice
assert_not_exists Prod.swap_eq_iff_eq_swap
assert_not_exists Ring
assert_not_exists Set.range
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
/-- 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 }
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
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
/-! ### 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⟩))
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
-- The simpNF linter says that the LHS can be simplified via `List.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- 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⟩
@[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 _⟩⟩
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]
/-! ### length -/
alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
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⟩
@[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
· subsingleton
· apply ih; simpa using hl
@[simp default+1] -- Raise priority above `length_injective_iff`.
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
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⟩
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⟩
/-! ### set-theoretic notation of lists -/
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_empty_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil }
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
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]
/-! ### bounded quantifiers over lists -/
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
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self, h⟩
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⟩
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⟩
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
/-! ### list 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⟩
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 _)
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 hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
/-! ### 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, replicate_succ]
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
rw [replicate_append_replicate]
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left']
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
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]
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate (n := ·))
theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
@[simp]
theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.head? = l.head? := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
induction l <;> simp [replicate]
@[simp]
theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.getLast? = l.getLast? := by
rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate,
List.reverse_replicate, head?_flatten_replicate h]
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
/-! ### bind -/
@[simp]
theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f :=
rfl
/-! ### concat -/
/-! ### reverse -/
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
@[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
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]
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]
-- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self`
@[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where
mp := l₁.reverse_perm.symm.trans
mpr := l₁.reverse_perm.trans
@[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where
mp hl := hl.trans l₂.reverse_perm
mpr hl := hl.trans l₂.reverse_perm.symm
/-! ### getLast -/
attribute [simp] getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by
simp [getLast_append]
theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by
induction l₁ with
| nil => simp
| cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih
@[deprecated (since := "2025-02-06")]
alias getLast_append' := getLast_append_of_right_ne_nil
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by
simp
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
@[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
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl 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)
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
@[deprecated (since := "2025-02-07")]
alias getLast_filter' := getLast_filter_of_pos
/-! ### getLast? -/
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
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 _ _)
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
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]
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [_] => rfl
| [_, _] => rfl
| [_, _, _] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], _, _ => rfl
| [_], _, _ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
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₂
theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
/-! ### 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_getElem_zero {l : List α} (hl : l ≠ []) :
l.head hl = l[0]'(length_pos_iff.2 hl) :=
(getElem_zero _).symm
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
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
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) :
x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
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]
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]
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| _ :: _, _ => rfl
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self
rwa [cons_head!_tail h] at h'
theorem get_eq_getElem? (l : List α) (i : Fin l.length) :
l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by
simp
@[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem?
theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} :
(∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by
simp only [mem_iff_getElem]
exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩
theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} :
(∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by
simp [mem_iff_getElem, @forall_swap α]
theorem get_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by
cases l <;> [cases h; rfl]
/-! ### sublists -/
attribute [refl] List.Sublist.refl
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by
constructor
· rintro (_ | _)
· exact Or.inl ‹_›
· exact Or.inr ⟨rfl, ‹_›⟩
· rintro (h | ⟨rfl, h⟩)
· exact h.cons _
· rwa [cons_sublist_cons]
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
@[deprecated (since := "2025-02-07")]
alias sublist_nil_iff_eq_nil := sublist_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
/-- If the first element of two lists are different, then a sublist relation can be reduced. -/
theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ :=
match h₁, h₂ with
| _, .cons _ h => h
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0
| e => by rw [← e]; exact idxOf_cons_self
@[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq
@[simp]
theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l)
| h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h]
@[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne
theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by
induction l with
| nil => exact iff_of_true rfl not_mem_nil
| cons b l ih =>
simp only [length, mem_cons, idxOf_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]
rw [← ih]
exact succ_inj
@[simp]
theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l :=
idxOf_eq_length_iff.2
@[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem
theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by
induction l with | nil => rfl | cons b l ih => ?_
simp only [length, idxOf_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
@[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length
theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al,
fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩
@[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff
theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by
induction l₁ with
| nil =>
exfalso
exact not_mem_nil h
| cons d₁ t₁ ih =>
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [idxOf_cons_eq _ hh]
rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem
theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by
induction l₁ with
| nil => rw [List.nil_append, List.length, Nat.zero_add]
| cons d₁ t₁ ih =>
rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
@[simp]
theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl
/-- A version of `getElem_map` that can be used for rewriting. -/
theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} :
f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _)
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_getElem _).symm
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_getElem_cons h, take, take]
simp
theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) :
l₁ = l₂ := by
apply ext_getElem?
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, getElem?_eq_none]
@[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?'
@[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff
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_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? :=
⟨by rintro rfl _ _; rfl, ext_getElem?'⟩
@[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff'
/-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`,
then the lists are equal. -/
theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) :
l₁ = l₂ :=
ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n
@[simp]
theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length),
l[idxOf a l] = a
| b :: l, h => by
by_cases h' : b = a <;>
simp [h', if_pos, if_false, getElem_idxOf]
@[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf
-- This is incorrectly named and should be `get_idxOf`;
-- this already exists, so will require a deprecation dance.
theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by
simp
@[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get
@[simp]
theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
l[idxOf a l]? = some a := by
rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)]
@[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf
@[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf
@[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf
theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
idxOf x l = idxOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ =
get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by
simp only [h]
simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
@[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by
simp
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp
congr
omega
end deprecated
@[simp]
theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a)[j] = l[j]'(by simpa using hj) := by
rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h,
List.getElem?_eq_getElem]
/-! ### map -/
-- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged
-- `simp` in Core
-- TODO: Upstream the tagging to Core?
attribute [simp] map_const'
theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l :=
.symm <| map_eq_flatMap ..
theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
l.flatMap f = l.flatMap g :=
(congr_arg List.flatten <| map_congr_left h :)
theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.flatMap f :=
infix_of_mem_flatten (mem_map_of_mem h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
/-- 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
/-- 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]
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]
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 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
/-- `eq_nil_or_concat` in simp normal form -/
lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by
simpa using l.eq_nil_or_concat
/-! ### 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]
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 | nil => rfl | cons hd tl ih => ?_
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
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]
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]
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
@[deprecated foldr_cons_nil (since := "2025-02-10")]
theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
simp
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]]
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]]
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 generalizing f with
| nil => exact hf
| cons lh lt l_ih =>
apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ mem_cons_self
/-- 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_iff, 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 FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α}
theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] :
∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| _, _, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]
rw [hassoc.assoc]
theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] :
∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm.comm a b
| a, b, c :: l => by
simp only [foldl_cons]
have : RightCommutative f := inferInstance
rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons]
theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] :
∀ a l, foldl f a l = foldr f a l
| _, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc]
rw [foldl_eq_foldr a l]
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
include hf
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| _, _, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| _, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) :
∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| _, _, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op]
/-- Notation for `op a b`. -/
local notation a " ⋆ " b => op a b
/-- Notation for `foldl op a l`. -/
local notation l " <*> " a => foldl op a l
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], _, _ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
variable [hc : Std.Commutative op]
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
variable [LawfulMonad m]
theorem foldrM_eq_foldr (f : α → β → m β) (b l) :
foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*]
theorem foldlM_eq_foldl (f : β → α → m β) (b l) :
List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by
suffices h :
∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
by simp [← h (pure b)]
induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
end FoldlMFoldrM
/-! ### intersperse -/
@[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single
@[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂
/-! ### map for partial functions -/
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
/-! ### filter -/
theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) :
l.length = (l.filter f).length + (l.filter (! f ·)).length := by
simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true,
Bool.decide_eq_false]
/-! ### filterMap -/
theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.flatMap fun a ↦ (f a).toList := by
induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons]
rcases f a <;> simp [ih]
theorem filterMap_congr {f g : α → Option β} {l : List α}
(h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by
induction l <;> simp_all [filterMap_cons]
theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} :
l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where
mp := by
induction l with | nil => simp | cons a l ih => ?_
rcases ha : f a with - | b <;> simp [ha, filterMap_cons]
· intro h
simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff]
using List.length_filterMap_le f l
· rintro rfl h
exact ⟨rfl, ih h⟩
mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _)
/-! ### filter -/
section Filter
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
theorem filter_eq_foldr (p : α → Bool) (l : List α) :
filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by
induction l <;> simp [*, filter]; rfl
#adaptation_note /-- nightly-2024-07-27
This has to be temporarily renamed to avoid an unintentional collision.
The prime should be removed at nightly-2024-07-27. -/
@[simp]
theorem filter_subset' (l : List α) : filter p l ⊆ l :=
filter_sublist.subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset' l h
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
@[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset
variable (p)
theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄
(h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by
induction l with
| nil => rfl
| cons hd tl IH =>
by_cases hp : p hd
· rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)]
exact IH.cons_cons hd
· rw [filter_cons_of_neg hp]
by_cases hq : q hd
· rw [filter_cons_of_pos hq]
exact sublist_cons_of_sublist hd IH
· rw [filter_cons_of_neg hq]
exact IH
lemma map_filter {f : α → β} (hf : Injective f) (l : List α)
[DecidablePred fun b => ∃ a, p a ∧ f a = b] :
(l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [comp_def, filter_map, hf.eq_iff]
@[deprecated (since := "2025-02-07")] alias map_filter' := map_filter
lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] :
l.attach.filter p =
(l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [comp_def, map_filter _ Subtype.coe_injective]
lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) =
(l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← filter_map, attach_map_subtype_val]
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [Bool.and_comm]
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
end Filter
/-! ### eraseP -/
section eraseP
variable {p : α → Bool}
@[simp]
theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) :
(l.eraseP p).length + 1 = l.length := by
let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa
rw [h₂, h₁, length_append, length_append]
rfl
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
@[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) :
(l.erase a).length + 1 = l.length := by
rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)]
theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) :
map f (l.erase a) = (map f l).erase (f a) := by
have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff]
rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl
theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by
induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]]
theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) :
Perm (l.erase l[i]) (l.eraseIdx i) := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
have hi' : i < l.length := by simpa using hi
if ha : a = l[i] then
simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi'))
else
simpa [ha] using IH hi'
theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) :
(l.eraseIdx i).length + 1 = l.length := by
rw [length_eraseIdx]
split <;> omega
end Erase
/-! ### diff -/
section Diff
variable [DecidableEq α]
@[simp]
theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by
simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj]
@[deprecated (since := "2025-04-10")]
alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist
end Diff
section Choose
variable (p : α → Prop) [DecidablePred p] (l : List α)
theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
/-! ### Forall -/
section Forall
variable {p q : α → Prop} {l : List α}
@[simp]
theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l
| [] => (and_iff_left_of_imp fun _ ↦ trivial).symm
| _ :: _ => Iff.rfl
@[simp]
theorem forall_append {p : α → Prop} : ∀ {xs ys : List α},
Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys
| [] => by simp
| _ :: _ => by simp [forall_append, and_assoc]
theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x
| [] => (iff_true_intro <| forall_mem_nil _).symm
| x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem]
theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l
| [] => id
| x :: l => by
simp only [forall_cons, and_imp]
rw [← and_imp]
exact And.imp (h x) (Forall.imp h)
@[simp]
theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by
induction l <;> simp [*]
instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ =>
decidable_of_iff' _ forall_iff_forall_mem
end Forall
/-! ### Miscellaneous lemmas -/
theorem get_attach (l : List α) (i) :
(l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp
section Disjoint
/-- The images of disjoint lists under a partially defined map are disjoint -/
theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α}
(hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a)
(hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a')
(h : Disjoint s t) :
Disjoint (s.pmap f hs) (t.pmap f ht) := by
simp only [Disjoint, mem_pmap]
rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩
apply h ha
rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm]
/-- The images of disjoint lists under an injective map are disjoint -/
theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f)
(h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by
rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)]
exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h
alias Disjoint.map := disjoint_map
theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) :
Disjoint s t := fun _a has hat ↦
h (mem_map_of_mem has) (mem_map_of_mem hat)
theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩
theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l₁ l ↔ Disjoint l₂ l := by
simp_rw [List.disjoint_left, p.mem_iff]
theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l l₁ ↔ Disjoint l l₂ := by
simp_rw [List.disjoint_right, p.mem_iff]
@[simp]
theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_left
@[simp]
theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_right
end Disjoint
section lookup
variable [BEq α] [LawfulBEq α]
lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) :
lookup a (as.map fun x => (x, f x)) = some (f a) := by
induction as with
| nil => exact (not_mem_nil h).elim
| cons a' as ih =>
by_cases ha : a = a'
· simp [ha, lookup_cons]
· simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h)
end lookup
section range'
@[simp]
lemma range'_0 (a b : ℕ) :
range' a b 0 = replicate b a := by
induction b with
| zero => simp
| succ b ih => simp [range'_succ, ih, replicate_succ]
lemma left_le_of_mem_range' {a b s x : ℕ}
(hx : x ∈ List.range' a b s) : a ≤ x := by
obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx
exact le_add_right a (s * i)
end range'
end List
| Mathlib/Data/List/Basic.lean | 2,894 | 2,898 | |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Const
import Mathlib.Order.Fin.Basic
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.SuppressCompilation
/-!
# Composable arrows
If `C` is a category, the type of `n`-simplices in the nerve of `C` identifies
to the type of functors `Fin (n + 1) ⥤ C`, which can be thought as families of `n` composable
arrows in `C`. In this file, we introduce and study this category `ComposableArrows C n`
of `n` composable arrows in `C`.
If `F : ComposableArrows C n`, we define `F.left` as the leftmost object, `F.right` as the
rightmost object, and `F.hom : F.left ⟶ F.right` is the canonical map.
The most significant definition in this file is the constructor
`F.precomp f : ComposableArrows C (n + 1)` for `F : ComposableArrows C n` and `f : X ⟶ F.left`:
"it shifts `F` towards the right and inserts `f` on the left". This `precomp` has
good definitional properties.
In the namespace `CategoryTheory.ComposableArrows`, we provide constructors
like `mk₁ f`, `mk₂ f g`, `mk₃ f g h` for `ComposableArrows C n` for small `n`.
TODO (@joelriou):
* redefine `Arrow C` as `ComposableArrow C 1`?
* construct some elements in `ComposableArrows m (Fin (n + 1))` for small `n`
the precomposition with which shall induce functors
`ComposableArrows C n ⥤ ComposableArrows C m` which correspond to simplicial operations
(specifically faces) with good definitional properties (this might be necessary for
up to `n = 7` in order to formalize spectral sequences following Verdier)
-/
/-!
New `simprocs` that run even in `dsimp` have caused breakages in this file.
(e.g. `dsimp` can now simplify `2 + 3` to `5`)
For now, we just turn off simprocs in this file.
We'll soon provide finer grained options here, e.g. to turn off simprocs only in `dsimp`, etc.
*However*, hopefully it is possible to refactor the material here so that no backwards compatibility
`set_option`s are required at all
-/
set_option simprocs false
namespace CategoryTheory
open Category
variable (C : Type*) [Category C]
/-- `ComposableArrows C n` is the type of functors `Fin (n + 1) ⥤ C`. -/
abbrev ComposableArrows (n : ℕ) := Fin (n + 1) ⥤ C
namespace ComposableArrows
variable {C} {n m : ℕ}
variable (F G : ComposableArrows C n)
/-- A wrapper for `omega` which prefaces it with some quick and useful attempts -/
macro "valid" : tactic =>
`(tactic| first | assumption | apply zero_le | apply le_rfl | transitivity <;> assumption | omega)
/-- The `i`th object (with `i : ℕ` such that `i ≤ n`) of `F : ComposableArrows C n`. -/
@[simp]
abbrev obj' (i : ℕ) (hi : i ≤ n := by valid) : C := F.obj ⟨i, by omega⟩
/-- The map `F.obj' i ⟶ F.obj' j` when `F : ComposableArrows C n`, and `i` and `j`
are natural numbers such that `i ≤ j ≤ n`. -/
@[simp]
abbrev map' (i j : ℕ) (hij : i ≤ j := by valid) (hjn : j ≤ n := by valid) :
F.obj ⟨i, by omega⟩ ⟶ F.obj ⟨j, by omega⟩ := F.map (homOfLE (by
simp only [Fin.mk_le_mk]
valid))
lemma map'_self (i : ℕ) (hi : i ≤ n := by valid) :
F.map' i i = 𝟙 _ := F.map_id _
lemma map'_comp (i j k : ℕ) (hij : i ≤ j := by valid)
(hjk : j ≤ k := by valid) (hk : k ≤ n := by valid) :
F.map' i k = F.map' i j ≫ F.map' j k :=
F.map_comp _ _
/-- The leftmost object of `F : ComposableArrows C n`. -/
abbrev left := obj' F 0
/-- The rightmost object of `F : ComposableArrows C n`. -/
abbrev right := obj' F n
/-- The canonical map `F.left ⟶ F.right` for `F : ComposableArrows C n`. -/
abbrev hom : F.left ⟶ F.right := map' F 0 n
variable {F G}
/-- The map `F.obj' i ⟶ G.obj' i` induced on `i`th objects by a morphism `F ⟶ G`
in `ComposableArrows C n` when `i` is a natural number such that `i ≤ n`. -/
@[simp]
abbrev app' (φ : F ⟶ G) (i : ℕ) (hi : i ≤ n := by valid) :
F.obj' i ⟶ G.obj' i := φ.app _
@[reassoc]
lemma naturality' (φ : F ⟶ G) (i j : ℕ) (hij : i ≤ j := by valid)
(hj : j ≤ n := by valid) :
F.map' i j ≫ app' φ j = app' φ i ≫ G.map' i j :=
φ.naturality _
/-- Constructor for `ComposableArrows C 0`. -/
@[simps!]
def mk₀ (X : C) : ComposableArrows C 0 := (Functor.const (Fin 1)).obj X
namespace Mk₁
variable (X₀ X₁ : C)
/-- The map which sends `0 : Fin 2` to `X₀` and `1` to `X₁`. -/
@[simp]
def obj : Fin 2 → C
| ⟨0, _⟩ => X₀
| ⟨1, _⟩ => X₁
variable {X₀ X₁}
variable (f : X₀ ⟶ X₁)
/-- The obvious map `obj X₀ X₁ i ⟶ obj X₀ X₁ j` whenever `i j : Fin 2` satisfy `i ≤ j`. -/
@[simp]
def map : ∀ (i j : Fin 2) (_ : i ≤ j), obj X₀ X₁ i ⟶ obj X₀ X₁ j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 _
| | ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨1, _⟩, ⟨1, _⟩, _ => 𝟙 _
lemma map_id (i : Fin 2) : map f i i (by simp) = 𝟙 _ :=
| Mathlib/CategoryTheory/ComposableArrows.lean | 138 | 141 |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Algebra.Group.Pointwise.Set.Lattice
import Mathlib.Algebra.Group.Subgroup.MulOppositeLemmas
import Mathlib.Algebra.Group.Submonoid.Pointwise
import Mathlib.GroupTheory.GroupAction.ConjAct
/-! # Pointwise instances on `Subgroup` and `AddSubgroup`s
This file provides the actions
* `Subgroup.pointwiseMulAction`
* `AddSubgroup.pointwiseMulAction`
which matches the action of `Set.mulActionSet`.
These actions are available in the `Pointwise` locale.
## Implementation notes
The pointwise section of this file is almost identical to
the file `Mathlib.Algebra.Group.Submonoid.Pointwise`.
Where possible, try to keep them in sync.
-/
assert_not_exists GroupWithZero
open Set
open Pointwise
variable {α G A S : Type*}
@[to_additive (attr := simp, norm_cast)]
theorem inv_coe_set [InvolutiveInv G] [SetLike S G] [InvMemClass S G] {H : S} : (H : Set G)⁻¹ = H :=
Set.ext fun _ => inv_mem_iff
@[to_additive (attr := simp)]
lemma smul_coe_set [Group G] [SetLike S G] [SubgroupClass S G] {s : S} {a : G} (ha : a ∈ s) :
a • (s : Set G) = s := by
ext; simp [Set.mem_smul_set_iff_inv_smul_mem, mul_mem_cancel_left, ha]
@[norm_cast, to_additive]
lemma coe_set_eq_one [Group G] {s : Subgroup G} : (s : Set G) = 1 ↔ s = ⊥ :=
(SetLike.ext'_iff.trans (by rfl)).symm
@[to_additive (attr := simp)]
lemma op_smul_coe_set [Group G] [SetLike S G] [SubgroupClass S G] {s : S} {a : G} (ha : a ∈ s) :
MulOpposite.op a • (s : Set G) = s := by
ext; simp [Set.mem_smul_set_iff_inv_smul_mem, mul_mem_cancel_right, ha]
@[to_additive (attr := simp, norm_cast)]
lemma coe_div_coe [SetLike S G] [DivisionMonoid G] [SubgroupClass S G] (H : S) :
H / H = (H : Set G) := by simp [div_eq_mul_inv]
variable [Group G] [AddGroup A] {s : Set G}
namespace Set
open Subgroup
@[to_additive (attr := simp)]
lemma mul_subgroupClosure (hs : s.Nonempty) : s * closure s = closure s := by
rw [← smul_eq_mul, ← Set.iUnion_smul_set]
have h a (ha : a ∈ s) : a • (closure s : Set G) = closure s :=
smul_coe_set <| subset_closure ha
simp +contextual [h, hs]
open scoped RightActions in
@[to_additive (attr := simp)]
lemma subgroupClosure_mul (hs : s.Nonempty) : closure s * s = closure s := by
rw [← Set.iUnion_op_smul_set]
have h a (ha : a ∈ s) : (closure s : Set G) <• a = closure s :=
op_smul_coe_set <| subset_closure ha
simp +contextual [h, hs]
@[to_additive (attr := simp)]
lemma pow_mul_subgroupClosure (hs : s.Nonempty) : ∀ n, s ^ n * closure s = closure s
| 0 => by simp
| n + 1 => by rw [pow_succ, mul_assoc, mul_subgroupClosure hs, pow_mul_subgroupClosure hs]
@[to_additive (attr := simp)]
lemma subgroupClosure_mul_pow (hs : s.Nonempty) : ∀ n, closure s * s ^ n = closure s
| 0 => by simp
| n + 1 => by rw [pow_succ', ← mul_assoc, subgroupClosure_mul hs, subgroupClosure_mul_pow hs]
end Set
namespace Subgroup
@[to_additive (attr := simp)]
theorem inv_subset_closure (S : Set G) : S⁻¹ ⊆ closure S := fun s hs => by
rw [SetLike.mem_coe, ← Subgroup.inv_mem_iff]
exact subset_closure (mem_inv.mp hs)
@[to_additive]
theorem closure_toSubmonoid (S : Set G) :
(closure S).toSubmonoid = Submonoid.closure (S ∪ S⁻¹) := by
refine le_antisymm (fun x hx => ?_) (Submonoid.closure_le.2 ?_)
· refine
closure_induction
(fun x hx => Submonoid.closure_mono subset_union_left (Submonoid.subset_closure hx))
(Submonoid.one_mem _) (fun x y _ _ hx hy => Submonoid.mul_mem _ hx hy) (fun x _ hx => ?_) hx
rwa [← Submonoid.mem_closure_inv, Set.union_inv, inv_inv, Set.union_comm]
· simp only [true_and, coe_toSubmonoid, union_subset_iff, subset_closure, inv_subset_closure]
/-- For subgroups generated by a single element, see the simpler `zpow_induction_left`. -/
@[to_additive (attr := elab_as_elim)
"For additive subgroups generated by a single element, see the simpler
`zsmul_induction_left`."]
theorem closure_induction_left {p : (x : G) → x ∈ closure s → Prop} (one : p 1 (one_mem _))
(mul_left : ∀ x (hx : x ∈ s), ∀ (y) hy, p y hy → p (x * y) (mul_mem (subset_closure hx) hy))
(inv_mul_cancel : ∀ x (hx : x ∈ s), ∀ (y) hy, p y hy →
p (x⁻¹ * y) (mul_mem (inv_mem (subset_closure hx)) hy))
{x : G} (h : x ∈ closure s) : p x h := by
revert h
simp_rw [← mem_toSubmonoid, closure_toSubmonoid] at *
intro h
induction h using Submonoid.closure_induction_left with
| one => exact one
| mul_left x hx y hy ih =>
cases hx with
| inl hx => exact mul_left _ hx _ hy ih
| inr hx => simpa only [inv_inv] using inv_mul_cancel _ hx _ hy ih
/-- For subgroups generated by a single element, see the simpler `zpow_induction_right`. -/
@[to_additive (attr := elab_as_elim)
"For additive subgroups generated by a single element, see the simpler
`zsmul_induction_right`."]
theorem closure_induction_right {p : (x : G) → x ∈ closure s → Prop} (one : p 1 (one_mem _))
(mul_right : ∀ (x) hx, ∀ y (hy : y ∈ s), p x hx → p (x * y) (mul_mem hx (subset_closure hy)))
(mul_inv_cancel : ∀ (x) hx, ∀ y (hy : y ∈ s), p x hx →
p (x * y⁻¹) (mul_mem hx (inv_mem (subset_closure hy))))
{x : G} (h : x ∈ closure s) : p x h :=
closure_induction_left (s := MulOpposite.unop ⁻¹' s)
(p := fun m hm => p m.unop <| by rwa [← op_closure] at hm)
one
(fun _x hx _y _ => mul_right _ _ _ hx)
(fun _x hx _y _ => mul_inv_cancel _ _ _ hx)
(by rwa [← op_closure])
@[to_additive (attr := simp)]
theorem closure_inv (s : Set G) : closure s⁻¹ = closure s := by
simp only [← toSubmonoid_inj, closure_toSubmonoid, inv_inv, union_comm]
@[to_additive (attr := simp)]
lemma closure_singleton_inv (x : G) : closure {x⁻¹} = closure {x} := by
rw [← Set.inv_singleton, closure_inv]
/-- An induction principle for closure membership. If `p` holds for `1` and all elements of
`k` and their inverse, and is preserved under multiplication, then `p` holds for all elements of
the closure of `k`. -/
@[to_additive (attr := elab_as_elim)
"An induction principle for additive closure membership. If `p` holds for `0` and all
elements of `k` and their negation, and is preserved under addition, then `p` holds for all
elements of the additive closure of `k`."]
theorem closure_induction'' {p : (g : G) → g ∈ closure s → Prop}
(mem : ∀ x (hx : x ∈ s), p x (subset_closure hx))
(inv_mem : ∀ x (hx : x ∈ s), p x⁻¹ (inv_mem (subset_closure hx)))
(one : p 1 (one_mem _))
(mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
{x} (h : x ∈ closure s) : p x h :=
closure_induction_left one (fun x hx y _ hy => mul x y _ _ (mem x hx) hy)
(fun x hx y _ => mul x⁻¹ y _ _ <| inv_mem x hx) h
/-- An induction principle for elements of `⨆ i, S i`.
If `C` holds for `1` and all elements of `S i` for all `i`, and is preserved under multiplication,
then it holds for all elements of the supremum of `S`. -/
@[to_additive (attr := elab_as_elim) " An induction principle for elements of `⨆ i, S i`.
If `C` holds for `0` and all elements of `S i` for all `i`, and is preserved under addition,
then it holds for all elements of the supremum of `S`. "]
theorem iSup_induction {ι : Sort*} (S : ι → Subgroup G) {C : G → Prop} {x : G} (hx : x ∈ ⨆ i, S i)
(mem : ∀ (i), ∀ x ∈ S i, C x) (one : C 1) (mul : ∀ x y, C x → C y → C (x * y)) : C x := by
rw [iSup_eq_closure] at hx
induction hx using closure_induction'' with
| one => exact one
| mem x hx =>
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx
exact mem _ _ hi
| inv_mem x hx =>
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx
exact mem _ _ (inv_mem hi)
| mul x y _ _ ihx ihy => exact mul x y ihx ihy
/-- A dependent version of `Subgroup.iSup_induction`. -/
@[to_additive (attr := elab_as_elim) "A dependent version of `AddSubgroup.iSup_induction`. "]
theorem iSup_induction' {ι : Sort*} (S : ι → Subgroup G) {C : ∀ x, (x ∈ ⨆ i, S i) → Prop}
(hp : ∀ (i), ∀ x (hx : x ∈ S i), C x (mem_iSup_of_mem i hx)) (h1 : C 1 (one_mem _))
(hmul : ∀ x y hx hy, C x hx → C y hy → C (x * y) (mul_mem ‹_› ‹_›)) {x : G}
(hx : x ∈ ⨆ i, S i) : C x hx := by
suffices ∃ h, C x h from this.snd
refine iSup_induction S (C := fun x => ∃ h, C x h) hx (fun i x hx => ?_) ?_ fun x y => ?_
· exact ⟨_, hp i _ hx⟩
· exact ⟨_, h1⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, hmul _ _ _ _ Cx Cy⟩
| @[to_additive]
theorem closure_mul_le (S T : Set G) : closure (S * T) ≤ closure S ⊔ closure T :=
sInf_le fun _x ⟨_s, hs, _t, ht, hx⟩ => hx ▸
(closure S ⊔ closure T).mul_mem (SetLike.le_def.mp le_sup_left <| subset_closure hs)
| Mathlib/Algebra/Group/Subgroup/Pointwise.lean | 202 | 205 |
/-
Copyright (c) 2018 Guy Leroy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Semiconj
import Mathlib.Algebra.Group.Commute.Units
import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Data.Set.Operations
import Mathlib.Order.Basic
import Mathlib.Order.Bounds.Defs
import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Data.Int.Basic
/-!
# Extended GCD and divisibility over ℤ
## Main definitions
* Given `x y : ℕ`, `xgcd x y` computes the pair of integers `(a, b)` such that
`gcd x y = x * a + y * b`. `gcdA x y` and `gcdB x y` are defined to be `a` and `b`,
respectively.
## Main statements
* `gcd_eq_gcd_ab`: Bézout's lemma, given `x y : ℕ`, `gcd x y = x * gcdA x y + y * gcdB x y`.
## Tags
Bézout's lemma, Bezout's lemma
-/
/-! ### Extended Euclidean algorithm -/
namespace Nat
/-- Helper function for the extended GCD algorithm (`Nat.xgcd`). -/
def xgcdAux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ
| 0, _, _, r', s', t' => (r', s', t')
| succ k, s, t, r', s', t' =>
let q := r' / succ k
xgcdAux (r' % succ k) (s' - q * s) (t' - q * t) (succ k) s t
termination_by k => k
decreasing_by exact mod_lt _ <| (succ_pos _).gt
@[simp]
theorem xgcd_zero_left {s t r' s' t'} : xgcdAux 0 s t r' s' t' = (r', s', t') := by simp [xgcdAux]
theorem xgcdAux_rec {r s t r' s' t'} (h : 0 < r) :
xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - r' / r * s) (t' - r' / r * t) r s t := by
obtain ⟨r, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h.ne'
simp [xgcdAux]
/-- Use the extended GCD algorithm to generate the `a` and `b` values
satisfying `gcd x y = x * a + y * b`. -/
def xgcd (x y : ℕ) : ℤ × ℤ :=
(xgcdAux x 1 0 y 0 1).2
/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/
def gcdA (x y : ℕ) : ℤ :=
(xgcd x y).1
/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/
def gcdB (x y : ℕ) : ℤ :=
(xgcd x y).2
@[simp]
theorem gcdA_zero_left {s : ℕ} : gcdA 0 s = 0 := by
unfold gcdA
rw [xgcd, xgcd_zero_left]
@[simp]
theorem gcdB_zero_left {s : ℕ} : gcdB 0 s = 1 := by
unfold gcdB
rw [xgcd, xgcd_zero_left]
@[simp]
theorem gcdA_zero_right {s : ℕ} (h : s ≠ 0) : gcdA s 0 = 1 := by
unfold gcdA xgcd
obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
rw [xgcdAux]
simp
@[simp]
| theorem gcdB_zero_right {s : ℕ} (h : s ≠ 0) : gcdB s 0 = 0 := by
unfold gcdB xgcd
obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
rw [xgcdAux]
simp
| Mathlib/Data/Int/GCD.lean | 86 | 90 |
/-
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, Devon Tuma
-/
import Mathlib.Probability.ProbabilityMassFunction.Monad
import Mathlib.Control.ULiftable
/-!
# Specific Constructions of Probability Mass Functions
This file gives a number of different `PMF` constructions for common probability distributions.
`map` and `seq` allow pushing a `PMF α` along a function `f : α → β` (or distribution of
functions `f : PMF (α → β)`) to get a `PMF β`.
`ofFinset` and `ofFintype` simplify the construction of a `PMF α` from a function `f : α → ℝ≥0∞`,
by allowing the "sum equals 1" constraint to be in terms of `Finset.sum` instead of `tsum`.
`normalize` constructs a `PMF α` by normalizing a function `f : α → ℝ≥0∞` by its sum,
and `filter` uses this to filter the support of a `PMF` and re-normalize the new distribution.
`bernoulli` represents the bernoulli distribution on `Bool`.
-/
universe u v
namespace PMF
noncomputable section
variable {α β γ : Type*}
open NNReal ENNReal Finset MeasureTheory
section Map
/-- The functorial action of a function on a `PMF`. -/
def map (f : α → β) (p : PMF α) : PMF β :=
bind p (pure ∘ f)
variable (f : α → β) (p : PMF α) (b : β)
theorem monad_map_eq_map {α β : Type u} (f : α → β) (p : PMF α) : f <$> p = p.map f := rfl
open scoped Classical in
@[simp]
theorem map_apply : (map f p) b = ∑' a, if b = f a then p a else 0 := by simp [map]
@[simp]
theorem support_map : (map f p).support = f '' p.support :=
Set.ext fun b => by simp [map, @eq_comm β b]
theorem mem_support_map_iff : b ∈ (map f p).support ↔ ∃ a ∈ p.support, f a = b := by simp
|
theorem bind_pure_comp : bind p (pure ∘ f) = map f p := rfl
| Mathlib/Probability/ProbabilityMassFunction/Constructions.lean | 56 | 57 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finset.Fold
import Mathlib.Data.Multiset.Bind
import Mathlib.Order.SetNotation
/-!
# Unions of finite sets
This file defines the union of a family `t : α → Finset β` of finsets bounded by a finset
`s : Finset α`.
## Main declarations
* `Finset.disjUnion`: Given a hypothesis `h` which states that finsets `s` and `t` are disjoint,
`s.disjUnion t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`; this does
not require decidable equality on the type `α`.
* `Finset.biUnion`: Finite unions of finsets; given an indexing function `f : α → Finset β` and an
`s : Finset α`, `s.biUnion f` is the union of all finsets of the form `f a` for `a ∈ s`.
## TODO
Remove `Finset.biUnion` in favour of `Finset.sup`.
-/
assert_not_exists MonoidWithZero MulAction
variable {α β γ : Type*} {s s₁ s₂ : Finset α} {t t₁ t₂ : α → Finset β}
namespace Finset
section DisjiUnion
/-- `disjiUnion s f h` is the set such that `a ∈ disjiUnion s f` iff `a ∈ f i` for some `i ∈ s`.
It is the same as `s.biUnion f`, but it does not require decidable equality on the type. The
hypothesis ensures that the sets are disjoint. -/
def disjiUnion (s : Finset α) (t : α → Finset β) (hf : (s : Set α).PairwiseDisjoint t) : Finset β :=
⟨s.val.bind (Finset.val ∘ t), Multiset.nodup_bind.2
⟨fun a _ ↦ (t a).nodup, s.nodup.pairwise fun _ ha _ hb hab ↦ disjoint_val.2 <| hf ha hb hab⟩⟩
@[simp]
lemma disjiUnion_val (s : Finset α) (t : α → Finset β) (h) :
(s.disjiUnion t h).1 = s.1.bind fun a ↦ (t a).1 := rfl
@[simp] lemma disjiUnion_empty (t : α → Finset β) : disjiUnion ∅ t (by simp) = ∅ := rfl
@[simp] lemma mem_disjiUnion {b : β} {h} : b ∈ s.disjiUnion t h ↔ ∃ a ∈ s, b ∈ t a := by
simp only [mem_def, disjiUnion_val, Multiset.mem_bind, exists_prop]
@[simp, norm_cast]
lemma coe_disjiUnion {h} : (s.disjiUnion t h : Set β) = ⋃ x ∈ (s : Set α), t x := by
simp [Set.ext_iff, mem_disjiUnion, Set.mem_iUnion, mem_coe, imp_true_iff]
@[simp] lemma disjiUnion_cons (a : α) (s : Finset α) (ha : a ∉ s) (f : α → Finset β) (H) :
disjiUnion (cons a s ha) f H =
(f a).disjUnion ((s.disjiUnion f) fun _ hb _ hc ↦ H (mem_cons_of_mem hb) (mem_cons_of_mem hc))
(disjoint_left.2 fun _ hb h ↦
let ⟨_, hc, h⟩ := mem_disjiUnion.mp h
disjoint_left.mp
(H (mem_cons_self a s) (mem_cons_of_mem hc) (ne_of_mem_of_not_mem hc ha).symm) hb h) :=
eq_of_veq <| Multiset.cons_bind _ _ _
@[simp] lemma singleton_disjiUnion (a : α) {h} : Finset.disjiUnion {a} t h = t a :=
eq_of_veq <| Multiset.singleton_bind _ _
lemma disjiUnion_disjiUnion (s : Finset α) (f : α → Finset β) (g : β → Finset γ) (h1 h2) :
(s.disjiUnion f h1).disjiUnion g h2 =
s.attach.disjiUnion
(fun a ↦ ((f a).disjiUnion g) fun _ hb _ hc ↦
h2 (mem_disjiUnion.mpr ⟨_, a.prop, hb⟩) (mem_disjiUnion.mpr ⟨_, a.prop, hc⟩))
fun a _ b _ hab ↦
disjoint_left.mpr fun x hxa hxb ↦ by
obtain ⟨xa, hfa, hga⟩ := mem_disjiUnion.mp hxa
obtain ⟨xb, hfb, hgb⟩ := mem_disjiUnion.mp hxb
refine disjoint_left.mp
(h2 (mem_disjiUnion.mpr ⟨_, a.prop, hfa⟩) (mem_disjiUnion.mpr ⟨_, b.prop, hfb⟩) ?_) hga
hgb
rintro rfl
exact disjoint_left.mp (h1 a.prop b.prop <| Subtype.coe_injective.ne hab) hfa hfb :=
eq_of_veq <| Multiset.bind_assoc.trans (Multiset.attach_bind_coe _ _).symm
lemma sUnion_disjiUnion {f : α → Finset (Set β)} (I : Finset α)
(hf : (I : Set α).PairwiseDisjoint f) :
⋃₀ (I.disjiUnion f hf : Set (Set β)) = ⋃ a ∈ I, ⋃₀ ↑(f a) := by
ext
simp only [coe_disjiUnion, Set.mem_sUnion, Set.mem_iUnion, mem_coe, exists_prop]
tauto
section DecidableEq
variable [DecidableEq β] {s : Finset α} {t : Finset β} {f : α → β}
private lemma pairwiseDisjoint_fibers : Set.PairwiseDisjoint ↑t fun a ↦ s.filter (f · = a) :=
fun x' hx y' hy hne ↦ by
simp_rw [disjoint_left, mem_filter]; rintro i ⟨_, rfl⟩ ⟨_, rfl⟩; exact hne rfl
@[simp] lemma disjiUnion_filter_eq (s : Finset α) (t : Finset β) (f : α → β) :
t.disjiUnion (fun a ↦ s.filter (f · = a)) pairwiseDisjoint_fibers =
s.filter fun c ↦ f c ∈ t :=
ext fun b => by simpa using and_comm
lemma disjiUnion_filter_eq_of_maps_to (h : ∀ x ∈ s, f x ∈ t) :
t.disjiUnion (fun a ↦ s.filter (f · = a)) pairwiseDisjoint_fibers = s := by
simpa [filter_eq_self]
end DecidableEq
theorem map_disjiUnion {f : α ↪ β} {s : Finset α} {t : β → Finset γ} {h} :
(s.map f).disjiUnion t h =
s.disjiUnion (fun a => t (f a)) fun _ ha _ hb hab =>
h (mem_map_of_mem _ ha) (mem_map_of_mem _ hb) (f.injective.ne hab) :=
eq_of_veq <| Multiset.bind_map _ _ _
theorem disjiUnion_map {s : Finset α} {t : α → Finset β} {f : β ↪ γ} {h} :
(s.disjiUnion t h).map f =
s.disjiUnion (fun a => (t a).map f) (h.mono' fun _ _ ↦ (disjoint_map _).2) :=
eq_of_veq <| Multiset.map_bind _ _ _
variable {f : α → β} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op]
theorem fold_disjiUnion {ι : Type*} {s : Finset ι} {t : ι → Finset α} {b : ι → β} {b₀ : β} (h) :
(s.disjiUnion t h).fold op (s.fold op b₀ b) f = s.fold op b₀ fun i => (t i).fold op (b i) f :=
(congr_arg _ <| Multiset.map_bind _ _ _).trans (Multiset.fold_bind _ _ _ _ _)
end DisjiUnion
section BUnion
variable [DecidableEq β]
/-- `Finset.biUnion s t` is the union of `t a` over `a ∈ s`.
(This was formerly `bind` due to the monad structure on types with `DecidableEq`.) -/
protected def biUnion (s : Finset α) (t : α → Finset β) : Finset β :=
(s.1.bind fun a ↦ (t a).1).toFinset
@[simp] lemma biUnion_val (s : Finset α) (t : α → Finset β) :
(s.biUnion t).1 = (s.1.bind fun a ↦ (t a).1).dedup := rfl
@[simp] lemma biUnion_empty : Finset.biUnion ∅ t = ∅ := rfl
@[simp] lemma mem_biUnion {b : β} : b ∈ s.biUnion t ↔ ∃ a ∈ s, b ∈ t a := by
simp only [mem_def, biUnion_val, Multiset.mem_dedup, Multiset.mem_bind, exists_prop]
@[simp, norm_cast]
lemma coe_biUnion : (s.biUnion t : Set β) = ⋃ x ∈ (s : Set α), t x := by
simp [Set.ext_iff, mem_biUnion, Set.mem_iUnion, mem_coe, imp_true_iff]
@[simp]
lemma biUnion_insert [DecidableEq α] {a : α} : (insert a s).biUnion t = t a ∪ s.biUnion t := by
aesop
lemma biUnion_congr (hs : s₁ = s₂) (ht : ∀ a ∈ s₁, t₁ a = t₂ a) :
s₁.biUnion t₁ = s₂.biUnion t₂ := by
aesop
@[simp]
lemma disjiUnion_eq_biUnion (s : Finset α) (f : α → Finset β) (hf) :
s.disjiUnion f hf = s.biUnion f := eq_of_veq (s.disjiUnion f hf).nodup.dedup.symm
lemma biUnion_subset {s' : Finset β} : s.biUnion t ⊆ s' ↔ ∀ x ∈ s, t x ⊆ s' := by
simp only [subset_iff, mem_biUnion]
exact ⟨fun H a ha b hb ↦ H ⟨a, ha, hb⟩, fun H b ⟨a, ha, hb⟩ ↦ H a ha hb⟩
@[simp]
lemma singleton_biUnion {a : α} : Finset.biUnion {a} t = t a := by
classical rw [← insert_empty_eq, biUnion_insert, biUnion_empty, union_empty]
lemma biUnion_inter (s : Finset α) (f : α → Finset β) (t : Finset β) :
s.biUnion f ∩ t = s.biUnion fun x ↦ f x ∩ t := by
ext x
simp only [mem_biUnion, mem_inter]
tauto
lemma inter_biUnion (t : Finset β) (s : Finset α) (f : α → Finset β) :
t ∩ s.biUnion f = s.biUnion fun x ↦ t ∩ f x := by
rw [inter_comm, biUnion_inter]
simp [inter_comm]
lemma biUnion_biUnion [DecidableEq γ] (s : Finset α) (f : α → Finset β) (g : β → Finset γ) :
(s.biUnion f).biUnion g = s.biUnion fun a ↦ (f a).biUnion g := by
ext
simp only [Finset.mem_biUnion, exists_prop]
simp_rw [← exists_and_right, ← exists_and_left, and_assoc]
rw [exists_comm]
lemma bind_toFinset [DecidableEq α] (s : Multiset α) (t : α → Multiset β) :
| (s.bind t).toFinset = s.toFinset.biUnion fun a ↦ (t a).toFinset :=
ext fun x ↦ by simp only [Multiset.mem_toFinset, mem_biUnion, Multiset.mem_bind, exists_prop]
| Mathlib/Data/Finset/Union.lean | 189 | 191 |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Geometry.Euclidean.Altitude
import Mathlib.Geometry.Euclidean.Circumcenter
/-!
# Monge point and orthocenter
This file defines the orthocenter of a triangle, via its n-dimensional
generalization, the Monge point of a simplex.
## Main definitions
* `mongePoint` is the Monge point of a simplex, defined in terms of
its position on the Euler line and then shown to be the point of
concurrence of the Monge planes.
* `mongePlane` is a Monge plane of an (n+2)-simplex, which is the
(n+1)-dimensional affine subspace of the subspace spanned by the
simplex that passes through the centroid of an n-dimensional face
and is orthogonal to the opposite edge (in 2 dimensions, this is the
same as an altitude).
* `orthocenter` is defined, for the case of a triangle, to be the same
as its Monge point, then shown to be the point of concurrence of the
altitudes.
* `OrthocentricSystem` is a predicate on sets of points that says
whether they are four points, one of which is the orthocenter of the
other three (in which case various other properties hold, including
that each is the orthocenter of the other three).
## References
* <https://en.wikipedia.org/wiki/Monge_point>
* <https://en.wikipedia.org/wiki/Orthocentric_system>
* Małgorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point
Sphere of an
n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf)
-/
noncomputable section
open scoped RealInnerProductSpace
namespace Affine
namespace Simplex
open Finset AffineSubspace EuclideanGeometry PointsWithCircumcenterIndex
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P]
/-- The Monge point of a simplex (in 2 or more dimensions) is a
generalization of the orthocenter of a triangle. It is defined to be
the intersection of the Monge planes, where a Monge plane is the
(n-1)-dimensional affine subspace of the subspace spanned by the
simplex that passes through the centroid of an (n-2)-dimensional face
and is orthogonal to the opposite edge (in 2 dimensions, this is the
same as an altitude). The circumcenter O, centroid G and Monge point
M are collinear in that order on the Euler line, with OG : GM = (n-1): 2.
Here, we use that ratio to define the Monge point (so resulting
in a point that equals the centroid in 0 or 1 dimensions), and then
show in subsequent lemmas that the point so defined lies in the Monge
planes and is their unique point of intersection. -/
def mongePoint {n : ℕ} (s : Simplex ℝ P n) : P :=
(((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) •
((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ
s.circumcenter
/-- The position of the Monge point in relation to the circumcenter
and centroid. -/
theorem mongePoint_eq_smul_vsub_vadd_circumcenter {n : ℕ} (s : Simplex ℝ P n) :
s.mongePoint =
(((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) •
((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ
s.circumcenter :=
rfl
/-- The Monge point lies in the affine span. -/
theorem mongePoint_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) :
s.mongePoint ∈ affineSpan ℝ (Set.range s.points) :=
smul_vsub_vadd_mem _ _ (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (card_fin (n + 1)))
s.circumcenter_mem_affineSpan s.circumcenter_mem_affineSpan
/-- Two simplices with the same points have the same Monge point. -/
theorem mongePoint_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n}
(h : Set.range s₁.points = Set.range s₂.points) : s₁.mongePoint = s₂.mongePoint := by
simp_rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h,
circumcenter_eq_of_range_eq h]
/-- The weights for the Monge point of an (n+2)-simplex, in terms of
`pointsWithCircumcenter`. -/
def mongePointWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex (n + 2) → ℝ
| pointIndex _ => ((n + 1 : ℕ) : ℝ)⁻¹
| circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ)
/-- `mongePointWeightsWithCircumcenter` sums to 1. -/
@[simp]
theorem sum_mongePointWeightsWithCircumcenter (n : ℕ) :
∑ i, mongePointWeightsWithCircumcenter n i = 1 := by
simp_rw [sum_pointsWithCircumcenter, mongePointWeightsWithCircumcenter, sum_const, card_fin,
nsmul_eq_mul]
field_simp
ring
/-- The Monge point of an (n+2)-simplex, in terms of
`pointsWithCircumcenter`. -/
theorem mongePoint_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ}
(s : Simplex ℝ P (n + 2)) :
s.mongePoint =
(univ : Finset (PointsWithCircumcenterIndex (n + 2))).affineCombination ℝ
s.pointsWithCircumcenter (mongePointWeightsWithCircumcenter n) := by
rw [mongePoint_eq_smul_vsub_vadd_circumcenter,
centroid_eq_affineCombination_of_pointsWithCircumcenter,
circumcenter_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub,
← LinearMap.map_smul, weightedVSub_vadd_affineCombination]
congr with i
rw [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Pi.sub_apply]
-- Porting note: replaced
-- have hn1 : (n + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _
have hn1 : (n + 1 : ℝ) ≠ 0 := n.cast_add_one_ne_zero
cases i <;>
simp_rw [centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter,
mongePointWeightsWithCircumcenter] <;>
rw [add_tsub_assoc_of_le (by decide : 1 ≤ 2), (by decide : 2 - 1 = 1)]
· rw [if_pos (mem_univ _), sub_zero, add_zero, card_fin]
-- Porting note: replaced
-- have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _
have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := by norm_cast
field_simp [hn1, hn3, mul_comm]
· field_simp [hn1]
ring
/-- The weights for the Monge point of an (n+2)-simplex, minus the
centroid of an n-dimensional face, in terms of
`pointsWithCircumcenter`. This definition is only valid when `i₁ ≠ i₂`. -/
def mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 3)) :
PointsWithCircumcenterIndex (n + 2) → ℝ
| pointIndex i => if i = i₁ ∨ i = i₂ then ((n + 1 : ℕ) : ℝ)⁻¹ else 0
| circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ)
/-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` is the
result of subtracting `centroidWeightsWithCircumcenter` from
`mongePointWeightsWithCircumcenter`. -/
theorem mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub {n : ℕ} {i₁ i₂ : Fin (n + 3)}
(h : i₁ ≠ i₂) :
mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ =
mongePointWeightsWithCircumcenter n - centroidWeightsWithCircumcenter {i₁, i₂}ᶜ := by
ext i
obtain i | i := i
· rw [Pi.sub_apply, mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter,
mongePointVSubFaceCentroidWeightsWithCircumcenter]
have hu : #{i₁, i₂}ᶜ = n + 1 := by
simp [card_compl, Fintype.card_fin, h]
rw [hu]
by_cases hi : i = i₁ ∨ i = i₂ <;> simp [compl_eq_univ_sdiff, hi]
· simp [mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter,
mongePointVSubFaceCentroidWeightsWithCircumcenter]
/-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` sums to 0. -/
@[simp]
theorem sum_mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 3)}
(h : i₁ ≠ i₂) : ∑ i, mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ i = 0 := by
rw [mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h]
simp_rw [Pi.sub_apply, sum_sub_distrib, sum_mongePointWeightsWithCircumcenter]
rw [sum_centroidWeightsWithCircumcenter, sub_self]
simp [← card_pos, card_compl, h]
/-- The Monge point of an (n+2)-simplex, minus the centroid of an
n-dimensional face, in terms of `pointsWithCircumcenter`. -/
theorem mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter {n : ℕ}
(s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) :
s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points =
(univ : Finset (PointsWithCircumcenterIndex (n + 2))).weightedVSub s.pointsWithCircumcenter
(mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂) := by
simp_rw [mongePoint_eq_affineCombination_of_pointsWithCircumcenter,
centroid_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub,
mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h]
/-- The Monge point of an (n+2)-simplex, minus the centroid of an
n-dimensional face, is orthogonal to the difference of the two
vertices not in that face. -/
theorem inner_mongePoint_vsub_face_centroid_vsub {n : ℕ} (s : Simplex ℝ P (n + 2))
{i₁ i₂ : Fin (n + 3)} :
⟪s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points,
s.points i₁ -ᵥ s.points i₂⟫ =
0 := by
by_cases h : i₁ = i₂
· simp [h]
simp_rw [mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter s h,
point_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub]
have hs : ∑ i, (pointWeightsWithCircumcenter i₁ - pointWeightsWithCircumcenter i₂) i = 0 := by
simp
rw [inner_weightedVSub _ (sum_mongePointVSubFaceCentroidWeightsWithCircumcenter h) _ hs,
sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter]
simp only [mongePointVSubFaceCentroidWeightsWithCircumcenter, pointsWithCircumcenter_point]
let fs : Finset (Fin (n + 3)) := {i₁, i₂}
have hfs : ∀ i : Fin (n + 3), i ∉ fs → i ≠ i₁ ∧ i ≠ i₂ := by
intro i hi
constructor <;> · intro hj; simp [fs, ← hj] at hi
rw [← sum_subset fs.subset_univ _]
· simp_rw [sum_pointsWithCircumcenter, pointsWithCircumcenter_eq_circumcenter,
pointsWithCircumcenter_point, Pi.sub_apply, pointWeightsWithCircumcenter]
rw [← sum_subset fs.subset_univ _]
· simp_rw [fs, sum_insert (not_mem_singleton.2 h), sum_singleton]
repeat rw [← sum_subset fs.subset_univ _]
· simp_rw [fs, sum_insert (not_mem_singleton.2 h), sum_singleton]
simp [h, Ne.symm h, dist_comm (s.points i₁)]
all_goals intro i _ hi; simp [hfs i hi]
· intro i _ hi
simp [hfs i hi, pointsWithCircumcenter]
· intro i _ hi
simp [hfs i hi]
/-- A Monge plane of an (n+2)-simplex is the (n+1)-dimensional affine
subspace of the subspace spanned by the simplex that passes through
the centroid of an n-dimensional face and is orthogonal to the
opposite edge (in 2 dimensions, this is the same as an altitude).
This definition is only intended to be used when `i₁ ≠ i₂`. -/
def mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) : AffineSubspace ℝ P :=
mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points) (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓
affineSpan ℝ (Set.range s.points)
/-- The definition of a Monge plane. -/
theorem mongePlane_def {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) :
s.mongePlane i₁ i₂ =
mk' (({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points)
(ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓
affineSpan ℝ (Set.range s.points) :=
rfl
/-- The Monge plane associated with vertices `i₁` and `i₂` equals that
associated with `i₂` and `i₁`. -/
theorem mongePlane_comm {n : ℕ} (s : Simplex ℝ P (n + 2)) (i₁ i₂ : Fin (n + 3)) :
s.mongePlane i₁ i₂ = s.mongePlane i₂ i₁ := by
simp_rw [mongePlane_def]
congr 3
· congr 1
exact pair_comm _ _
· ext
simp_rw [Submodule.mem_span_singleton]
constructor
all_goals rintro ⟨r, rfl⟩; use -r; rw [neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev]
/-- The Monge point lies in the Monge planes. -/
theorem mongePoint_mem_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} :
s.mongePoint ∈ s.mongePlane i₁ i₂ := by
rw [mongePlane_def, mem_inf_iff, ← vsub_right_mem_direction_iff_mem (self_mem_mk' _ _),
direction_mk', Submodule.mem_orthogonal']
refine ⟨?_, s.mongePoint_mem_affineSpan⟩
intro v hv
rcases Submodule.mem_span_singleton.mp hv with ⟨r, rfl⟩
rw [inner_smul_right, s.inner_mongePoint_vsub_face_centroid_vsub, mul_zero]
/-- The direction of a Monge plane. -/
theorem direction_mongePlane {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} :
(s.mongePlane i₁ i₂).direction =
(ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by
rw [mongePlane_def, direction_inf_of_mem_inf s.mongePoint_mem_mongePlane, direction_mk',
direction_affineSpan]
/-- The Monge point is the only point in all the Monge planes from any
one vertex. -/
theorem eq_mongePoint_of_forall_mem_mongePlane {n : ℕ} {s : Simplex ℝ P (n + 2)} {i₁ : Fin (n + 3)}
{p : P} (h : ∀ i₂, i₁ ≠ i₂ → p ∈ s.mongePlane i₁ i₂) : p = s.mongePoint := by
rw [← @vsub_eq_zero_iff_eq V]
have h' : ∀ i₂, i₁ ≠ i₂ → p -ᵥ s.mongePoint ∈
(ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ ⊓ vectorSpan ℝ (Set.range s.points) := by
intro i₂ hne
rw [← s.direction_mongePlane, vsub_right_mem_direction_iff_mem s.mongePoint_mem_mongePlane]
exact h i₂ hne
have hi : p -ᵥ s.mongePoint ∈ ⨅ i₂ : { i // i₁ ≠ i }, (ℝ ∙ s.points i₁ -ᵥ s.points i₂)ᗮ := by
rw [Submodule.mem_iInf]
exact fun i => (Submodule.mem_inf.1 (h' i i.property)).1
rw [Submodule.iInf_orthogonal, ← Submodule.span_iUnion] at hi
have hu :
⋃ i : { i // i₁ ≠ i }, ({s.points i₁ -ᵥ s.points i} : Set V) =
(s.points i₁ -ᵥ ·) '' (s.points '' (Set.univ \ {i₁})) := by
rw [Set.image_image]
ext x
simp_rw [Set.mem_iUnion, Set.mem_image, Set.mem_singleton_iff, Set.mem_diff_singleton]
constructor
· rintro ⟨i, rfl⟩
use i, ⟨Set.mem_univ _, i.property.symm⟩
· rintro ⟨i, ⟨-, hi⟩, rfl⟩
use ⟨i, hi.symm⟩
rw [hu, ← vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_univ _), Set.image_univ] at hi
have hv : p -ᵥ s.mongePoint ∈ vectorSpan ℝ (Set.range s.points) := by
let s₁ : Finset (Fin (n + 3)) := univ.erase i₁
obtain ⟨i₂, h₂⟩ := card_pos.1 (show 0 < #s₁ by simp [s₁, card_erase_of_mem])
have h₁₂ : i₁ ≠ i₂ := (ne_of_mem_erase h₂).symm
exact (Submodule.mem_inf.1 (h' i₂ h₁₂)).2
exact Submodule.disjoint_def.1 (vectorSpan ℝ (Set.range s.points)).orthogonal_disjoint _ hv hi
end Simplex
namespace Triangle
open EuclideanGeometry Finset Simplex AffineSubspace Module
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P]
/-- The orthocenter of a triangle is the intersection of its
altitudes. It is defined here as the 2-dimensional case of the
Monge point. -/
def orthocenter (t : Triangle ℝ P) : P :=
t.mongePoint
/-- The orthocenter equals the Monge point. -/
theorem orthocenter_eq_mongePoint (t : Triangle ℝ P) : t.orthocenter = t.mongePoint :=
rfl
/-- The position of the orthocenter in relation to the circumcenter
and centroid. -/
theorem orthocenter_eq_smul_vsub_vadd_circumcenter (t : Triangle ℝ P) :
t.orthocenter =
(3 : ℝ) • ((univ : Finset (Fin 3)).centroid ℝ t.points -ᵥ t.circumcenter : V) +ᵥ
t.circumcenter := by
rw [orthocenter_eq_mongePoint, mongePoint_eq_smul_vsub_vadd_circumcenter]
norm_num
/-- The orthocenter lies in the affine span. -/
theorem orthocenter_mem_affineSpan (t : Triangle ℝ P) :
t.orthocenter ∈ affineSpan ℝ (Set.range t.points) :=
t.mongePoint_mem_affineSpan
/-- Two triangles with the same points have the same orthocenter. -/
theorem orthocenter_eq_of_range_eq {t₁ t₂ : Triangle ℝ P}
(h : Set.range t₁.points = Set.range t₂.points) : t₁.orthocenter = t₂.orthocenter :=
mongePoint_eq_of_range_eq h
/-- In the case of a triangle, altitudes are the same thing as Monge
planes. -/
theorem altitude_eq_mongePlane (t : Triangle ℝ P) {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃)
(h₂₃ : i₂ ≠ i₃) : t.altitude i₁ = t.mongePlane i₂ i₃ := by
have hs : ({i₂, i₃}ᶜ : Finset (Fin 3)) = {i₁} := by decide +revert
have he : univ.erase i₁ = {i₂, i₃} := by decide +revert
rw [mongePlane_def, altitude_def, direction_affineSpan, hs, he, centroid_singleton, coe_insert,
coe_singleton, vectorSpan_image_eq_span_vsub_set_left_ne ℝ _ (Set.mem_insert i₂ _)]
simp [h₂₃, Submodule.span_insert_eq_span]
/-- The orthocenter lies in the altitudes. -/
theorem orthocenter_mem_altitude (t : Triangle ℝ P) {i₁ : Fin 3} :
t.orthocenter ∈ t.altitude i₁ := by
obtain ⟨i₂, i₃, h₁₂, h₂₃, h₁₃⟩ : ∃ i₂ i₃, i₁ ≠ i₂ ∧ i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by
decide +revert
rw [orthocenter_eq_mongePoint, t.altitude_eq_mongePlane h₁₂ h₁₃ h₂₃]
exact t.mongePoint_mem_mongePlane
/-- The orthocenter is the only point lying in any two of the
altitudes. -/
theorem eq_orthocenter_of_forall_mem_altitude {t : Triangle ℝ P} {i₁ i₂ : Fin 3} {p : P}
(h₁₂ : i₁ ≠ i₂) (h₁ : p ∈ t.altitude i₁) (h₂ : p ∈ t.altitude i₂) : p = t.orthocenter := by
obtain ⟨i₃, h₂₃, h₁₃⟩ : ∃ i₃, i₂ ≠ i₃ ∧ i₁ ≠ i₃ := by
clear h₁ h₂
decide +revert
rw [t.altitude_eq_mongePlane h₁₃ h₁₂ h₂₃.symm] at h₁
rw [t.altitude_eq_mongePlane h₂₃ h₁₂.symm h₁₃.symm] at h₂
rw [orthocenter_eq_mongePoint]
have ha : ∀ i, i₃ ≠ i → p ∈ t.mongePlane i₃ i := by
intro i hi
obtain rfl | rfl : i₁ = i ∨ i₂ = i := by omega
all_goals assumption
exact eq_mongePoint_of_forall_mem_mongePlane ha
/-- The distance from the orthocenter to the reflection of the
circumcenter in a side equals the circumradius. -/
theorem dist_orthocenter_reflection_circumcenter (t : Triangle ℝ P) {i₁ i₂ : Fin 3} (h : i₁ ≠ i₂) :
dist t.orthocenter (reflection (affineSpan ℝ (t.points '' {i₁, i₂})) t.circumcenter) =
t.circumradius := by
rw [← mul_self_inj_of_nonneg dist_nonneg t.circumradius_nonneg,
t.reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter h,
t.orthocenter_eq_mongePoint, mongePoint_eq_affineCombination_of_pointsWithCircumcenter,
dist_affineCombination t.pointsWithCircumcenter (sum_mongePointWeightsWithCircumcenter _)
(sum_reflectionCircumcenterWeightsWithCircumcenter h)]
simp_rw [sum_pointsWithCircumcenter, Pi.sub_apply, mongePointWeightsWithCircumcenter,
reflectionCircumcenterWeightsWithCircumcenter]
have hu : ({i₁, i₂} : Finset (Fin 3)) ⊆ univ := subset_univ _
obtain ⟨i₃, hi₃, hi₃₁, hi₃₂⟩ :
∃ i₃, univ \ ({i₁, i₂} : Finset (Fin 3)) = {i₃} ∧ i₃ ≠ i₁ ∧ i₃ ≠ i₂ := by
decide +revert
simp_rw [← sum_sdiff hu, hi₃]
norm_num [hi₃₁, hi₃₂]
/-- The distance from the orthocenter to the reflection of the
circumcenter in a side equals the circumradius, variant using a
`Finset`. -/
theorem dist_orthocenter_reflection_circumcenter_finset (t : Triangle ℝ P) {i₁ i₂ : Fin 3}
(h : i₁ ≠ i₂) :
dist t.orthocenter
(reflection (affineSpan ℝ (t.points '' ↑({i₁, i₂} : Finset (Fin 3)))) t.circumcenter) =
t.circumradius := by
simp only [mem_singleton, coe_insert, coe_singleton, Set.mem_singleton_iff]
exact dist_orthocenter_reflection_circumcenter _ h
/-- The affine span of the orthocenter and a vertex is contained in
the altitude. -/
theorem affineSpan_orthocenter_point_le_altitude (t : Triangle ℝ P) (i : Fin 3) :
line[ℝ, t.orthocenter, t.points i] ≤ t.altitude i := by
refine affineSpan_le_of_subset_coe ?_
rw [Set.insert_subset_iff, Set.singleton_subset_iff]
exact ⟨t.orthocenter_mem_altitude, t.mem_altitude i⟩
/-- Suppose we are given a triangle `t₁`, and replace one of its
vertices by its orthocenter, yielding triangle `t₂` (with vertices not
necessarily listed in the same order). Then an altitude of `t₂` from
a vertex that was not replaced is the corresponding side of `t₁`. -/
theorem altitude_replace_orthocenter_eq_affineSpan {t₁ t₂ : Triangle ℝ P}
{i₁ i₂ i₃ j₁ j₂ j₃ : Fin 3} (hi₁₂ : i₁ ≠ i₂) (hi₁₃ : i₁ ≠ i₃) (hi₂₃ : i₂ ≠ i₃) (hj₁₂ : j₁ ≠ j₂)
(hj₁₃ : j₁ ≠ j₃) (hj₂₃ : j₂ ≠ j₃) (h₁ : t₂.points j₁ = t₁.orthocenter)
(h₂ : t₂.points j₂ = t₁.points i₂) (h₃ : t₂.points j₃ = t₁.points i₃) :
t₂.altitude j₂ = line[ℝ, t₁.points i₁, t₁.points i₂] := by
symm
rw [← h₂, t₂.affineSpan_pair_eq_altitude_iff]
rw [h₂]
use t₁.independent.injective.ne hi₁₂
have he : affineSpan ℝ (Set.range t₂.points) = affineSpan ℝ (Set.range t₁.points) := by
refine ext_of_direction_eq ?_
⟨t₁.points i₃, mem_affineSpan ℝ ⟨j₃, h₃⟩, mem_affineSpan ℝ (Set.mem_range_self _)⟩
refine Submodule.eq_of_le_of_finrank_eq (direction_le (affineSpan_le_of_subset_coe ?_))
?_
· have hu : (Finset.univ : Finset (Fin 3)) = {j₁, j₂, j₃} := by
clear h₁ h₂ h₃
decide +revert
rw [← Set.image_univ, ← Finset.coe_univ, hu, Finset.coe_insert, Finset.coe_insert,
Finset.coe_singleton, Set.image_insert_eq, Set.image_insert_eq, Set.image_singleton, h₁, h₂,
h₃, Set.insert_subset_iff, Set.insert_subset_iff, Set.singleton_subset_iff]
exact
⟨t₁.orthocenter_mem_affineSpan, mem_affineSpan ℝ (Set.mem_range_self _),
mem_affineSpan ℝ (Set.mem_range_self _)⟩
· rw [direction_affineSpan, direction_affineSpan,
t₁.independent.finrank_vectorSpan (Fintype.card_fin _),
t₂.independent.finrank_vectorSpan (Fintype.card_fin _)]
rw [he]
use mem_affineSpan ℝ (Set.mem_range_self _)
have hu : Finset.univ.erase j₂ = {j₁, j₃} := by
clear h₁ h₂ h₃
decide +revert
rw [hu, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_singleton, h₁, h₃]
have hle : (t₁.altitude i₃).directionᗮ ≤ line[ℝ, t₁.orthocenter, t₁.points i₃].directionᗮ :=
Submodule.orthogonal_le (direction_le (affineSpan_orthocenter_point_le_altitude _ _))
refine hle ((t₁.vectorSpan_isOrtho_altitude_direction i₃) ?_)
have hui : Finset.univ.erase i₃ = {i₁, i₂} := by
clear hle h₂ h₃
decide +revert
rw [hui, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_singleton]
exact vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_singleton _))
/-- Suppose we are given a triangle `t₁`, and replace one of its
vertices by its orthocenter, yielding triangle `t₂` (with vertices not
necessarily listed in the same order). Then the orthocenter of `t₂`
is the vertex of `t₁` that was replaced. -/
theorem orthocenter_replace_orthocenter_eq_point {t₁ t₂ : Triangle ℝ P} {i₁ i₂ i₃ j₁ j₂ j₃ : Fin 3}
(hi₁₂ : i₁ ≠ i₂) (hi₁₃ : i₁ ≠ i₃) (hi₂₃ : i₂ ≠ i₃) (hj₁₂ : j₁ ≠ j₂) (hj₁₃ : j₁ ≠ j₃)
(hj₂₃ : j₂ ≠ j₃) (h₁ : t₂.points j₁ = t₁.orthocenter) (h₂ : t₂.points j₂ = t₁.points i₂)
(h₃ : t₂.points j₃ = t₁.points i₃) : t₂.orthocenter = t₁.points i₁ := by
refine (Triangle.eq_orthocenter_of_forall_mem_altitude hj₂₃ ?_ ?_).symm
· rw [altitude_replace_orthocenter_eq_affineSpan hi₁₂ hi₁₃ hi₂₃ hj₁₂ hj₁₃ hj₂₃ h₁ h₂ h₃]
exact mem_affineSpan ℝ (Set.mem_insert _ _)
· rw [altitude_replace_orthocenter_eq_affineSpan hi₁₃ hi₁₂ hi₂₃.symm hj₁₃ hj₁₂ hj₂₃.symm h₁ h₃ h₂]
exact mem_affineSpan ℝ (Set.mem_insert _ _)
end Triangle
end Affine
namespace EuclideanGeometry
open Affine AffineSubspace Module
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P]
/-- Four points form an orthocentric system if they consist of the
vertices of a triangle and its orthocenter. -/
def OrthocentricSystem (s : Set P) : Prop :=
∃ t : Triangle ℝ P,
t.orthocenter ∉ Set.range t.points ∧ s = insert t.orthocenter (Set.range t.points)
| /-- This is an auxiliary lemma giving information about the relation
of two triangles in an orthocentric system; it abstracts some
reasoning, with no geometric content, that is common to some other
lemmas. Suppose the orthocentric system is generated by triangle `t`,
and we are given three points `p` in the orthocentric system. Then
either we can find indices `i₁`, `i₂` and `i₃` for `p` such that `p
i₁` is the orthocenter of `t` and `p i₂` and `p i₃` are points `j₂`
| Mathlib/Geometry/Euclidean/MongePoint.lean | 487 | 493 |
/-
Copyright (c) 2020 Jean Lo, Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Yury Kudryashov
-/
import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set
import Mathlib.Algebra.Ring.Action.Pointwise.Set
import Mathlib.Topology.Bornology.Basic
/-!
# Absorption of sets
Let `M` act on `α`, let `A` and `B` be sets in `α`.
We say that `A` *absorbs* `B` if for sufficiently large `a : M`, we have `B ⊆ a • A`.
Formally, "for sufficiently large `a : M`" means "for all but a bounded set of `a`".
Traditionally, this definition is formulated
for the action of a (semi)normed ring on a module over that ring.
We formulate it in a more general settings for two reasons:
- this way we don't have to depend on metric spaces, normed rings etc;
- some proofs look nicer with this definition than with something like
`∃ r : ℝ, ∀ a : R, r ≤ ‖a‖ → B ⊆ a • A`.
If `M` is a `GroupWithZero` (e.g., a division ring),
the sets absorbing a given set form a filter, see `Filter.absorbing`.
## Implementation notes
For now, all theorems assume that we deal with (a generalization of) a module over a division ring.
Some lemmas have multiplicative versions for `MulDistribMulAction`s.
They can be added later when someone needs them.
## Keywords
absorbs, absorbent
-/
assert_not_exists Real
open Set Bornology Filter
open scoped Pointwise
section Defs
variable (M : Type*) {α : Type*} [Bornology M] [SMul M α]
/-- A set `s` absorbs another set `t` if `t` is contained in all scalings of `s`
by all but a bounded set of elements. -/
def Absorbs (s t : Set α) : Prop :=
∀ᶠ a in cobounded M, t ⊆ a • s
/-- A set is *absorbent* if it absorbs every singleton. -/
def Absorbent (s : Set α) : Prop :=
∀ x, Absorbs M s {x}
end Defs
namespace Absorbs
section SMul
variable {M α : Type*} [Bornology M] [SMul M α] {s s₁ s₂ t t₁ t₂ : Set α} {S T : Set (Set α)}
protected lemma empty : Absorbs M s ∅ := by simp [Absorbs]
protected lemma eventually (h : Absorbs M s t) : ∀ᶠ a in cobounded M, t ⊆ a • s := h
@[simp] lemma of_boundedSpace [BoundedSpace M] : Absorbs M s t := by simp [Absorbs]
lemma mono_left (h : Absorbs M s₁ t) (hs : s₁ ⊆ s₂) : Absorbs M s₂ t :=
h.mono fun _a ha ↦ ha.trans <| smul_set_mono hs
lemma mono_right (h : Absorbs M s t₁) (ht : t₂ ⊆ t₁) : Absorbs M s t₂ :=
h.mono fun _ ↦ ht.trans
lemma mono (h : Absorbs M s₁ t₁) (hs : s₁ ⊆ s₂) (ht : t₂ ⊆ t₁) : Absorbs M s₂ t₂ :=
(h.mono_left hs).mono_right ht
@[simp]
lemma _root_.absorbs_union : Absorbs M s (t₁ ∪ t₂) ↔ Absorbs M s t₁ ∧ Absorbs M s t₂ := by
simp [Absorbs]
protected lemma union (h₁ : Absorbs M s t₁) (h₂ : Absorbs M s t₂) : Absorbs M s (t₁ ∪ t₂) :=
absorbs_union.2 ⟨h₁, h₂⟩
lemma _root_.Set.Finite.absorbs_sUnion {T : Set (Set α)} (hT : T.Finite) :
Absorbs M s (⋃₀ T) ↔ ∀ t ∈ T, Absorbs M s t := by
simp [Absorbs, hT]
protected lemma sUnion (hT : T.Finite) (hs : ∀ t ∈ T, Absorbs M s t) :
Absorbs M s (⋃₀ T) :=
hT.absorbs_sUnion.2 hs
@[simp]
lemma _root_.absorbs_iUnion {ι : Sort*} [Finite ι] {t : ι → Set α} :
Absorbs M s (⋃ i, t i) ↔ ∀ i, Absorbs M s (t i) :=
(finite_range t).absorbs_sUnion.trans forall_mem_range
protected alias ⟨_, iUnion⟩ := absorbs_iUnion
lemma _root_.Set.Finite.absorbs_biUnion {ι : Type*} {t : ι → Set α} {I : Set ι} (hI : I.Finite) :
Absorbs M s (⋃ i ∈ I, t i) ↔ ∀ i ∈ I, Absorbs M s (t i) := by
simp [Absorbs, hI]
protected alias ⟨_, biUnion⟩ := Set.Finite.absorbs_biUnion
@[simp]
lemma _root_.absorbs_biUnion_finset {ι : Type*} {t : ι → Set α} {I : Finset ι} :
Absorbs M s (⋃ i ∈ I, t i) ↔ ∀ i ∈ I, Absorbs M s (t i) :=
I.finite_toSet.absorbs_biUnion
protected alias ⟨_, biUnion_finset⟩ := absorbs_biUnion_finset
end SMul
section AddZero
variable {M E : Type*} [Bornology M] {s₁ s₂ t₁ t₂ : Set E}
protected lemma add [AddZeroClass E] [DistribSMul M E]
(h₁ : Absorbs M s₁ t₁) (h₂ : Absorbs M s₂ t₂) : Absorbs M (s₁ + s₂) (t₁ + t₂) :=
h₂.mp <| h₁.eventually.mono fun x hx₁ hx₂ ↦ by rw [smul_add]; exact add_subset_add hx₁ hx₂
protected lemma zero [Zero E] [SMulZeroClass M E] {s : Set E} (hs : 0 ∈ s) : Absorbs M s 0 :=
Eventually.of_forall fun _ ↦ zero_subset.2 <| zero_mem_smul_set hs
end AddZero
end Absorbs
section GroupWithZero
variable {G₀ α : Type*} [GroupWithZero G₀] [Bornology G₀] [MulAction G₀ α]
{s t u : Set α} {S : Set (Set α)}
@[simp]
protected lemma Absorbs.univ : Absorbs G₀ univ s :=
(eventually_ne_cobounded 0).mono fun a ha ↦ by rw [smul_set_univ₀ ha]; apply subset_univ
lemma absorbs_iff_eventually_cobounded_mapsTo :
Absorbs G₀ s t ↔ ∀ᶠ c in cobounded G₀, MapsTo (c⁻¹ • ·) t s :=
eventually_congr <| (eventually_ne_cobounded 0).mono fun c hc ↦ by
rw [← preimage_smul_inv₀ hc]; rfl
alias ⟨eventually_cobounded_mapsTo, _⟩ := absorbs_iff_eventually_cobounded_mapsTo
@[simp]
lemma absorbs_inter : Absorbs G₀ (s ∩ t) u ↔ Absorbs G₀ s u ∧ Absorbs G₀ t u := by
simp only [absorbs_iff_eventually_cobounded_mapsTo, mapsTo_inter, eventually_and]
protected lemma Absorbs.inter (hs : Absorbs G₀ s u) (ht : Absorbs G₀ t u) : Absorbs G₀ (s ∩ t) u :=
absorbs_inter.2 ⟨hs, ht⟩
variable (G₀ u) in
/-- The filter of sets that absorb `u`. -/
def Filter.absorbing : Filter α where
sets := {s | Absorbs G₀ s u}
univ_sets := .univ
sets_of_superset h := h.mono_left
inter_sets := .inter
@[simp]
lemma Filter.mem_absorbing : s ∈ absorbing G₀ u ↔ Absorbs G₀ s u := .rfl
lemma Set.Finite.absorbs_sInter (hS : S.Finite) :
Absorbs G₀ (⋂₀ S) t ↔ ∀ s ∈ S, Absorbs G₀ s t :=
sInter_mem (f := absorbing G₀ t) hS
| protected alias ⟨_, Absorbs.sInter⟩ := Set.Finite.absorbs_sInter
@[simp]
| Mathlib/Topology/Bornology/Absorbs.lean | 171 | 173 |
/-
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.Algebra.Group.Indicator
import Mathlib.Data.Int.Cast.Pi
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.MeasureTheory.MeasurableSpace.Defs
/-!
# Measurable spaces and measurable functions
This file provides properties of measurable spaces and the functions and isomorphisms between them.
The definition of a measurable space is in `Mathlib/MeasureTheory/MeasurableSpace/Defs.lean`.
A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under
complementation and countable union. A function between measurable spaces is measurable if
the preimage of each measurable subset is measurable.
σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂`
if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`).
In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains
all of them. A function `f : α → β` induces a Galois connection between the lattices of σ-algebras
on `α` and `β`.
## Implementation notes
Measurability of a function `f : α → β` between measurable spaces is defined in terms of the
Galois connection induced by `f`.
## References
* <https://en.wikipedia.org/wiki/Measurable_space>
* <https://en.wikipedia.org/wiki/Sigma-algebra>
* <https://en.wikipedia.org/wiki/Dynkin_system>
## Tags
measurable space, σ-algebra, measurable function, dynkin system, π-λ theorem, π-system
-/
open Set MeasureTheory
universe uι
variable {α β γ : Type*} {ι : Sort uι} {s : Set α}
namespace MeasurableSpace
section Functors
variable {m m₁ m₂ : MeasurableSpace α} {m' : MeasurableSpace β} {f : α → β} {g : β → α}
/-- The forward image of a measurable space under a function. `map f m` contains the sets
`s : Set β` whose preimage under `f` is measurable. -/
protected def map (f : α → β) (m : MeasurableSpace α) : MeasurableSpace β where
MeasurableSet' s := MeasurableSet[m] <| f ⁻¹' s
measurableSet_empty := m.measurableSet_empty
measurableSet_compl _ hs := m.measurableSet_compl _ hs
measurableSet_iUnion f hf := by simpa only [preimage_iUnion] using m.measurableSet_iUnion _ hf
lemma map_def {s : Set β} : MeasurableSet[m.map f] s ↔ MeasurableSet[m] (f ⁻¹' s) := Iff.rfl
@[simp]
theorem map_id : m.map id = m :=
MeasurableSpace.ext fun _ => Iff.rfl
@[simp]
theorem map_comp {f : α → β} {g : β → γ} : (m.map f).map g = m.map (g ∘ f) :=
MeasurableSpace.ext fun _ => Iff.rfl
/-- The reverse image of a measurable space under a function. `comap f m` contains the sets
`s : Set α` such that `s` is the `f`-preimage of a measurable set in `β`. -/
protected def comap (f : α → β) (m : MeasurableSpace β) : MeasurableSpace α where
MeasurableSet' s := ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s
measurableSet_empty := ⟨∅, m.measurableSet_empty, rfl⟩
measurableSet_compl := fun _ ⟨s', h₁, h₂⟩ => ⟨s'ᶜ, m.measurableSet_compl _ h₁, h₂ ▸ rfl⟩
measurableSet_iUnion s hs :=
let ⟨s', hs'⟩ := Classical.axiom_of_choice hs
⟨⋃ i, s' i, m.measurableSet_iUnion _ fun i => (hs' i).left, by simp [hs']⟩
lemma measurableSet_comap {m : MeasurableSpace β} :
MeasurableSet[m.comap f] s ↔ ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s := .rfl
theorem comap_eq_generateFrom (m : MeasurableSpace β) (f : α → β) :
m.comap f = generateFrom { t | ∃ s, MeasurableSet s ∧ f ⁻¹' s = t } :=
(@generateFrom_measurableSet _ (.comap f m)).symm
@[simp]
theorem comap_id : m.comap id = m :=
MeasurableSpace.ext fun s => ⟨fun ⟨_, hs', h⟩ => h ▸ hs', fun h => ⟨s, h, rfl⟩⟩
@[simp]
theorem comap_comp {f : β → α} {g : γ → β} : (m.comap f).comap g = m.comap (f ∘ g) :=
MeasurableSpace.ext fun _ =>
⟨fun ⟨_, ⟨u, h, hu⟩, ht⟩ => ⟨u, h, ht ▸ hu ▸ rfl⟩, fun ⟨t, h, ht⟩ => ⟨f ⁻¹' t, ⟨_, h, rfl⟩, ht⟩⟩
theorem comap_le_iff_le_map {f : α → β} : m'.comap f ≤ m ↔ m' ≤ m.map f :=
⟨fun h _s hs => h _ ⟨_, hs, rfl⟩, fun h _s ⟨_t, ht, heq⟩ => heq ▸ h _ ht⟩
theorem gc_comap_map (f : α → β) :
GaloisConnection (MeasurableSpace.comap f) (MeasurableSpace.map f) := fun _ _ =>
comap_le_iff_le_map
theorem map_mono (h : m₁ ≤ m₂) : m₁.map f ≤ m₂.map f :=
(gc_comap_map f).monotone_u h
theorem monotone_map : Monotone (MeasurableSpace.map f) := fun _ _ => map_mono
theorem comap_mono (h : m₁ ≤ m₂) : m₁.comap g ≤ m₂.comap g :=
(gc_comap_map g).monotone_l h
theorem monotone_comap : Monotone (MeasurableSpace.comap g) := fun _ _ h => comap_mono h
@[simp]
theorem comap_bot : (⊥ : MeasurableSpace α).comap g = ⊥ :=
(gc_comap_map g).l_bot
@[simp]
theorem comap_sup : (m₁ ⊔ m₂).comap g = m₁.comap g ⊔ m₂.comap g :=
(gc_comap_map g).l_sup
@[simp]
theorem comap_iSup {m : ι → MeasurableSpace α} : (⨆ i, m i).comap g = ⨆ i, (m i).comap g :=
(gc_comap_map g).l_iSup
@[simp]
theorem map_top : (⊤ : MeasurableSpace α).map f = ⊤ :=
(gc_comap_map f).u_top
@[simp]
theorem map_inf : (m₁ ⊓ m₂).map f = m₁.map f ⊓ m₂.map f :=
(gc_comap_map f).u_inf
@[simp]
theorem map_iInf {m : ι → MeasurableSpace α} : (⨅ i, m i).map f = ⨅ i, (m i).map f :=
(gc_comap_map f).u_iInf
theorem comap_map_le : (m.map f).comap f ≤ m :=
(gc_comap_map f).l_u_le _
theorem le_map_comap : m ≤ (m.comap g).map g :=
(gc_comap_map g).le_u_l _
end Functors
@[simp] theorem map_const {m} (b : β) : MeasurableSpace.map (fun _a : α ↦ b) m = ⊤ :=
eq_top_iff.2 <| fun s _ ↦ by rw [map_def]; by_cases h : b ∈ s <;> simp [h]
@[simp] theorem comap_const {m} (b : β) : MeasurableSpace.comap (fun _a : α => b) m = ⊥ :=
eq_bot_iff.2 <| by rintro _ ⟨s, -, rfl⟩; by_cases b ∈ s <;> simp [*]
theorem comap_generateFrom {f : α → β} {s : Set (Set β)} :
(generateFrom s).comap f = generateFrom (preimage f '' s) :=
le_antisymm
(comap_le_iff_le_map.2 <|
generateFrom_le fun _t hts => GenerateMeasurable.basic _ <| mem_image_of_mem _ <| hts)
(generateFrom_le fun _t ⟨u, hu, Eq⟩ => Eq ▸ ⟨u, GenerateMeasurable.basic _ hu, rfl⟩)
end MeasurableSpace
section MeasurableFunctions
open MeasurableSpace
theorem measurable_iff_le_map {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} :
Measurable f ↔ m₂ ≤ m₁.map f :=
Iff.rfl
alias ⟨Measurable.le_map, Measurable.of_le_map⟩ := measurable_iff_le_map
theorem measurable_iff_comap_le {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} :
Measurable f ↔ m₂.comap f ≤ m₁ :=
comap_le_iff_le_map.symm
alias ⟨Measurable.comap_le, Measurable.of_comap_le⟩ := measurable_iff_comap_le
theorem comap_measurable {m : MeasurableSpace β} (f : α → β) : Measurable[m.comap f] f :=
fun s hs => ⟨s, hs, rfl⟩
theorem Measurable.mono {ma ma' : MeasurableSpace α} {mb mb' : MeasurableSpace β} {f : α → β}
(hf : @Measurable α β ma mb f) (ha : ma ≤ ma') (hb : mb' ≤ mb) : @Measurable α β ma' mb' f :=
fun _t ht => ha _ <| hf <| hb _ ht
lemma Measurable.iSup' {mα : ι → MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β} (i₀ : ι)
(h : Measurable[mα i₀] f) :
Measurable[⨆ i, mα i] f :=
h.mono (le_iSup mα i₀) le_rfl
lemma Measurable.sup_of_left {mα mα' : MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β}
(h : Measurable[mα] f) :
Measurable[mα ⊔ mα'] f :=
h.mono le_sup_left le_rfl
lemma Measurable.sup_of_right {mα mα' : MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β}
(h : Measurable[mα'] f) :
Measurable[mα ⊔ mα'] f :=
h.mono le_sup_right le_rfl
theorem measurable_id'' {m mα : MeasurableSpace α} (hm : m ≤ mα) : @Measurable α α mα m id :=
measurable_id.mono le_rfl hm
@[measurability]
theorem measurable_from_top [MeasurableSpace β] {f : α → β} : Measurable[⊤] f := fun _ _ => trivial
theorem measurable_generateFrom [MeasurableSpace α] {s : Set (Set β)} {f : α → β}
(h : ∀ t ∈ s, MeasurableSet (f ⁻¹' t)) : @Measurable _ _ _ (generateFrom s) f :=
Measurable.of_le_map <| generateFrom_le h
variable {f g : α → β}
section TypeclassMeasurableSpace
variable [MeasurableSpace α] [MeasurableSpace β]
@[nontriviality, measurability]
theorem Subsingleton.measurable [Subsingleton α] : Measurable f := fun _ _ =>
@Subsingleton.measurableSet α _ _ _
@[nontriviality, measurability]
theorem measurable_of_subsingleton_codomain [Subsingleton β] (f : α → β) : Measurable f :=
fun s _ => Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s
@[to_additive (attr := measurability, fun_prop)]
theorem measurable_one [One α] : Measurable (1 : β → α) :=
@measurable_const _ _ _ _ 1
theorem measurable_of_empty [IsEmpty α] (f : α → β) : Measurable f :=
Subsingleton.measurable
theorem measurable_of_empty_codomain [IsEmpty β] (f : α → β) : Measurable f :=
measurable_of_subsingleton_codomain f
/-- A version of `measurable_const` that assumes `f x = f y` for all `x, y`. This version works
for functions between empty types. -/
theorem measurable_const' {f : β → α} (hf : ∀ x y, f x = f y) : Measurable f := by
nontriviality β
inhabit β
convert @measurable_const α β _ _ (f default) using 2
apply hf
@[measurability]
theorem measurable_natCast [NatCast α] (n : ℕ) : Measurable (n : β → α) :=
@measurable_const α _ _ _ n
@[measurability]
theorem measurable_intCast [IntCast α] (n : ℤ) : Measurable (n : β → α) :=
@measurable_const α _ _ _ n
theorem measurable_of_countable [Countable α] [MeasurableSingletonClass α] (f : α → β) :
Measurable f := fun s _ =>
(f ⁻¹' s).to_countable.measurableSet
theorem measurable_of_finite [Finite α] [MeasurableSingletonClass α] (f : α → β) : Measurable f :=
measurable_of_countable f
end TypeclassMeasurableSpace
variable {m : MeasurableSpace α}
@[measurability]
theorem Measurable.iterate {f : α → α} (hf : Measurable f) : ∀ n, Measurable f^[n]
| 0 => measurable_id
| n + 1 => (Measurable.iterate hf n).comp hf
variable {mβ : MeasurableSpace β}
@[measurability]
theorem measurableSet_preimage {t : Set β} (hf : Measurable f) (ht : MeasurableSet t) :
MeasurableSet (f ⁻¹' t) :=
hf ht
protected theorem MeasurableSet.preimage {t : Set β} (ht : MeasurableSet t) (hf : Measurable f) :
MeasurableSet (f ⁻¹' t) :=
hf ht
@[measurability, fun_prop]
protected theorem Measurable.piecewise {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s)
(hf : Measurable f) (hg : Measurable g) : Measurable (piecewise s f g) := by
intro t ht
rw [piecewise_preimage]
exact hs.ite (hf ht) (hg ht)
/-- This is slightly different from `Measurable.piecewise`. It can be used to show
`Measurable (ite (x=0) 0 1)` by
`exact Measurable.ite (measurableSet_singleton 0) measurable_const measurable_const`,
but replacing `Measurable.ite` by `Measurable.piecewise` in that example proof does not work. -/
theorem Measurable.ite {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a })
(hf : Measurable f) (hg : Measurable g) : Measurable fun x => ite (p x) (f x) (g x) :=
Measurable.piecewise hp hf hg
@[measurability, fun_prop]
theorem Measurable.indicator [Zero β] (hf : Measurable f) (hs : MeasurableSet s) :
Measurable (s.indicator f) :=
hf.piecewise hs measurable_const
/-- The measurability of a set `A` is equivalent to the measurability of the indicator function
which takes a constant value `b ≠ 0` on a set `A` and `0` elsewhere. -/
lemma measurable_indicator_const_iff [Zero β] [MeasurableSingletonClass β] (b : β) [NeZero b] :
Measurable (s.indicator (fun (_ : α) ↦ b)) ↔ MeasurableSet s := by
constructor <;> intro h
· convert h (MeasurableSet.singleton (0 : β)).compl
ext a
simp [NeZero.ne b]
· exact measurable_const.indicator h
@[to_additive (attr := measurability)]
theorem measurableSet_mulSupport [One β] [MeasurableSingletonClass β] (hf : Measurable f) :
MeasurableSet (Function.mulSupport f) :=
hf (measurableSet_singleton 1).compl
/-- If a function coincides with a measurable function outside of a countable set, it is
measurable. -/
theorem Measurable.measurable_of_countable_ne [MeasurableSingletonClass α] (hf : Measurable f)
(h : Set.Countable { x | f x ≠ g x }) : Measurable g := by
intro t ht
have : g ⁻¹' t = g ⁻¹' t ∩ { x | f x = g x }ᶜ ∪ g ⁻¹' t ∩ { x | f x = g x } := by
simp [← inter_union_distrib_left]
rw [this]
refine (h.mono inter_subset_right).measurableSet.union ?_
have : g ⁻¹' t ∩ { x : α | f x = g x } = f ⁻¹' t ∩ { x : α | f x = g x } := by
ext x
simp +contextual
rw [this]
exact (hf ht).inter h.measurableSet.of_compl
end MeasurableFunctions
/-- We say that a collection of sets is countably spanning if a countable subset spans the
whole type. This is a useful condition in various parts of measure theory. For example, it is
a needed condition to show that the product of two collections generate the product sigma algebra,
see `generateFrom_prod_eq`. -/
def IsCountablySpanning (C : Set (Set α)) : Prop :=
∃ s : ℕ → Set α, (∀ n, s n ∈ C) ∧ ⋃ n, s n = univ
theorem isCountablySpanning_measurableSet [MeasurableSpace α] :
IsCountablySpanning { s : Set α | MeasurableSet s } :=
⟨fun _ => univ, fun _ => MeasurableSet.univ, iUnion_const _⟩
/-- Rectangles of countably spanning sets are countably spanning. -/
lemma 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]
| Mathlib/MeasureTheory/MeasurableSpace/Basic.lean | 791 | 797 | |
/-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.Data.Fintype.Pigeonhole
import Mathlib.FieldTheory.IsAlgClosed.Basic
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.RingTheory.IntegralDomain
import Mathlib.RingTheory.Polynomial.UniqueFactorization
/-!
# Primitive Element Theorem
In this file we prove the primitive element theorem.
## Main results
- `Field.exists_primitive_element`: a finite separable extension `E / F` has a primitive element,
i.e. there is an `α : E` such that `F⟮α⟯ = (⊤ : Subalgebra F E)`.
- `Field.exists_primitive_element_iff_finite_intermediateField`: a finite extension `E / F` has a
primitive element if and only if there exist only finitely many intermediate fields between `E`
and `F`.
## Implementation notes
In declaration names, `primitive_element` abbreviates `adjoin_simple_eq_top`:
it stands for the statement `F⟮α⟯ = (⊤ : Subalgebra F E)`. We did not add an extra
declaration `IsPrimitiveElement F α := F⟮α⟯ = (⊤ : Subalgebra F E)` because this
requires more unfolding without much obvious benefit.
## Tags
primitive element, separable field extension, separable extension, intermediate field, adjoin,
exists_adjoin_simple_eq_top
-/
noncomputable section
open Module Polynomial IntermediateField
namespace Field
section PrimitiveElementFinite
variable (F : Type*) [Field F] (E : Type*) [Field E] [Algebra F E]
/-! ### Primitive element theorem for finite fields -/
/-- **Primitive element theorem** assuming E is finite. -/
@[stacks 09HY "second part"]
theorem exists_primitive_element_of_finite_top [Finite E] : ∃ α : E, F⟮α⟯ = ⊤ := by
obtain ⟨α, hα⟩ := @IsCyclic.exists_generator Eˣ _ _
use α
rw [eq_top_iff]
rintro x -
by_cases hx : x = 0
· rw [hx]
exact F⟮α.val⟯.zero_mem
· obtain ⟨n, hn⟩ := Set.mem_range.mp (hα (Units.mk0 x hx))
rw [show x = α ^ n by norm_cast; rw [hn, Units.val_mk0]]
exact zpow_mem (mem_adjoin_simple_self F (E := E) ↑α) n
/-- Primitive element theorem for finite dimensional extension of a finite field. -/
theorem exists_primitive_element_of_finite_bot [Finite F] [FiniteDimensional F E] :
∃ α : E, F⟮α⟯ = ⊤ :=
haveI : Finite E := Module.finite_of_finite F
exists_primitive_element_of_finite_top F E
end PrimitiveElementFinite
/-! ### Primitive element theorem for infinite fields -/
section PrimitiveElementInf
variable {F : Type*} [Field F] [Infinite F] {E : Type*} [Field E] (ϕ : F →+* E) (α β : E)
theorem primitive_element_inf_aux_exists_c (f g : F[X]) :
∃ c : F, ∀ α' ∈ (f.map ϕ).roots, ∀ β' ∈ (g.map ϕ).roots, -(α' - α) / (β' - β) ≠ ϕ c := by
classical
let sf := (f.map ϕ).roots
let sg := (g.map ϕ).roots
classical
let s := (sf.bind fun α' => sg.map fun β' => -(α' - α) / (β' - β)).toFinset
let s' := s.preimage ϕ fun x _ y _ h => ϕ.injective h
obtain ⟨c, hc⟩ := Infinite.exists_not_mem_finset s'
simp_rw [s', s, Finset.mem_preimage, Multiset.mem_toFinset, Multiset.mem_bind, Multiset.mem_map]
at hc
push_neg at hc
exact ⟨c, hc⟩
variable (F)
variable [Algebra F E]
/-- This is the heart of the proof of the primitive element theorem. It shows that if `F` is
infinite and `α` and `β` are separable over `F` then `F⟮α, β⟯` is generated by a single element. -/
theorem primitive_element_inf_aux [Algebra.IsSeparable F E] : ∃ γ : E, F⟮α, β⟯ = F⟮γ⟯ := by
classical
have hα := Algebra.IsSeparable.isIntegral F α
have hβ := Algebra.IsSeparable.isIntegral F β
let f := minpoly F α
let g := minpoly F β
let ιFE := algebraMap F E
let ιEE' := algebraMap E (SplittingField (g.map ιFE))
obtain ⟨c, hc⟩ := primitive_element_inf_aux_exists_c (ιEE'.comp ιFE) (ιEE' α) (ιEE' β) f g
let γ := α + c • β
suffices β_in_Fγ : β ∈ F⟮γ⟯ by
use γ
apply le_antisymm
· rw [adjoin_le_iff]
have α_in_Fγ : α ∈ F⟮γ⟯ := by
rw [← add_sub_cancel_right α (c • β)]
exact F⟮γ⟯.sub_mem (mem_adjoin_simple_self F γ) (F⟮γ⟯.toSubalgebra.smul_mem β_in_Fγ c)
rintro x (rfl | rfl) <;> assumption
· rw [adjoin_simple_le_iff]
have α_in_Fαβ : α ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert α {β})
have β_in_Fαβ : β ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert_of_mem α rfl)
exact F⟮α, β⟯.add_mem α_in_Fαβ (F⟮α, β⟯.smul_mem β_in_Fαβ)
classical
let p := EuclideanDomain.gcd ((f.map (algebraMap F F⟮γ⟯)).comp
(C (AdjoinSimple.gen F γ) - (C ↑c : F⟮γ⟯[X]) * X)) (g.map (algebraMap F F⟮γ⟯))
let h := EuclideanDomain.gcd ((f.map ιFE).comp (C γ - C (ιFE c) * X)) (g.map ιFE)
have map_g_ne_zero : g.map ιFE ≠ 0 := map_ne_zero (minpoly.ne_zero hβ)
have h_ne_zero : h ≠ 0 :=
mt EuclideanDomain.gcd_eq_zero_iff.mp (not_and.mpr fun _ => map_g_ne_zero)
suffices p_linear : p.map (algebraMap F⟮γ⟯ E) = C h.leadingCoeff * (X - C β) by
have finale : β = algebraMap F⟮γ⟯ E (-p.coeff 0 / p.coeff 1) := by
simp [map_div₀, RingHom.map_neg, ← coeff_map, ← coeff_map, p_linear,
mul_sub, coeff_C, mul_div_cancel_left₀ β (mt leadingCoeff_eq_zero.mp h_ne_zero)]
rw [finale]
exact Subtype.mem (-p.coeff 0 / p.coeff 1)
have h_sep : h.Separable := separable_gcd_right _ (Algebra.IsSeparable.isSeparable F β).map
have h_root : h.eval β = 0 := by
apply eval_gcd_eq_zero
· rw [eval_comp, eval_sub, eval_mul, eval_C, eval_C, eval_X, eval_map, ← aeval_def, ←
Algebra.smul_def, add_sub_cancel_right, minpoly.aeval]
· rw [eval_map, ← aeval_def, minpoly.aeval]
have h_splits : Splits ιEE' h :=
splits_of_splits_gcd_right ιEE' map_g_ne_zero (SplittingField.splits _)
have h_roots : ∀ x ∈ (h.map ιEE').roots, x = ιEE' β := by
intro x hx
rw [mem_roots_map h_ne_zero] at hx
specialize hc (ιEE' γ - ιEE' (ιFE c) * x) (by
have f_root := root_left_of_root_gcd hx
rw [eval₂_comp, eval₂_sub, eval₂_mul, eval₂_C, eval₂_C, eval₂_X, eval₂_map] at f_root
exact (mem_roots_map (minpoly.ne_zero hα)).mpr f_root)
specialize hc x (by
rw [mem_roots_map (minpoly.ne_zero hβ), ← eval₂_map]
exact root_right_of_root_gcd hx)
by_contra a
apply hc
apply (div_eq_iff (sub_ne_zero.mpr a)).mpr
simp only [γ, Algebra.smul_def, RingHom.map_add, RingHom.map_mul, RingHom.comp_apply]
ring
rw [← eq_X_sub_C_of_separable_of_root_eq h_sep h_root h_splits h_roots]
trans EuclideanDomain.gcd (?_ : E[X]) (?_ : E[X])
· dsimp only [γ]
convert (gcd_map (algebraMap F⟮γ⟯ E)).symm
· simp only [map_comp, Polynomial.map_map, ← IsScalarTower.algebraMap_eq, Polynomial.map_sub,
map_C, AdjoinSimple.algebraMap_gen, map_add, Polynomial.map_mul, map_X]
congr
-- If `F` is infinite and `E/F` has only finitely many intermediate fields, then for any
-- `α` and `β` in `E`, `F⟮α, β⟯` is generated by a single element.
-- Marked as private since it's a special case of
-- `exists_primitive_element_of_finite_intermediateField`.
private theorem primitive_element_inf_aux_of_finite_intermediateField
[Finite (IntermediateField F E)] : ∃ γ : E, F⟮α, β⟯ = F⟮γ⟯ := by
let f : F → IntermediateField F E := fun x ↦ F⟮α + x • β⟯
obtain ⟨x, y, hneq, heq⟩ := Finite.exists_ne_map_eq_of_infinite f
use α + x • β
apply le_antisymm
· rw [adjoin_le_iff]
have αxβ_in_K : α + x • β ∈ F⟮α + x • β⟯ := mem_adjoin_simple_self F _
have αyβ_in_K : α + y • β ∈ F⟮α + y • β⟯ := mem_adjoin_simple_self F _
dsimp [f] at *
simp only [← heq] at αyβ_in_K
have β_in_K := sub_mem αxβ_in_K αyβ_in_K
rw [show (α + x • β) - (α + y • β) = (x - y) • β by rw [sub_smul]; abel1] at β_in_K
replace β_in_K := smul_mem _ β_in_K (x := (x - y)⁻¹)
rw [smul_smul, inv_mul_eq_div, div_self (sub_ne_zero.2 hneq), one_smul] at β_in_K
have α_in_K : α ∈ F⟮α + x • β⟯ := by
convert ← sub_mem αxβ_in_K (smul_mem _ β_in_K)
apply add_sub_cancel_right
rintro x (rfl | rfl) <;> assumption
· rw [adjoin_simple_le_iff]
have α_in_Fαβ : α ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert α {β})
have β_in_Fαβ : β ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert_of_mem α rfl)
exact F⟮α, β⟯.add_mem α_in_Fαβ (F⟮α, β⟯.smul_mem β_in_Fαβ)
end PrimitiveElementInf
variable (F E : Type*) [Field F] [Field E]
variable [Algebra F E]
section SeparableAssumption
variable [FiniteDimensional F E] [Algebra.IsSeparable F E]
/-- **Primitive element theorem**: a finite separable field extension `E` of `F` has a
primitive element, i.e. there is an `α ∈ E` such that `F⟮α⟯ = (⊤ : Subalgebra F E)`. -/
@[stacks 030N "The moreover part"]
theorem exists_primitive_element : ∃ α : E, F⟮α⟯ = ⊤ := by
rcases isEmpty_or_nonempty (Fintype F) with (F_inf | ⟨⟨F_finite⟩⟩)
· let P : IntermediateField F E → Prop := fun K => ∃ α : E, F⟮α⟯ = K
have base : P ⊥ := ⟨0, adjoin_zero⟩
have ih : ∀ (K : IntermediateField F E) (x : E), P K → P (K⟮x⟯.restrictScalars F) := by
intro K β hK
obtain ⟨α, hK⟩ := hK
rw [← hK, adjoin_simple_adjoin_simple]
haveI : Infinite F := isEmpty_fintype.mp F_inf
obtain ⟨γ, hγ⟩ := primitive_element_inf_aux F α β
exact ⟨γ, hγ.symm⟩
exact induction_on_adjoin P base ih ⊤
· exact exists_primitive_element_of_finite_bot F E
/-- Alternative phrasing of primitive element theorem:
a finite separable field extension has a basis `1, α, α^2, ..., α^n`.
See also `exists_primitive_element`. -/
noncomputable def powerBasisOfFiniteOfSeparable : PowerBasis F E :=
let α := (exists_primitive_element F E).choose
let pb := adjoin.powerBasis (Algebra.IsSeparable.isIntegral F α)
have e : F⟮α⟯ = ⊤ := (exists_primitive_element F E).choose_spec
pb.map ((IntermediateField.equivOfEq e).trans IntermediateField.topEquiv)
end SeparableAssumption
section FiniteIntermediateField
-- TODO: show a more generalized result: [F⟮α⟯ : F⟮α ^ m⟯] = m if m > 0 and α transcendental.
theorem isAlgebraic_of_adjoin_eq_adjoin {α : E} {m n : ℕ} (hneq : m ≠ n)
(heq : F⟮α ^ m⟯ = F⟮α ^ n⟯) : IsAlgebraic F α := by
wlog hmn : m < n
· exact this F E hneq.symm heq.symm (hneq.lt_or_lt.resolve_left hmn)
by_cases hm : m = 0
· rw [hm] at heq hmn
simp only [pow_zero, adjoin_one] at heq
obtain ⟨y, h⟩ := mem_bot.1 (heq.symm ▸ mem_adjoin_simple_self F (α ^ n))
refine ⟨X ^ n - C y, X_pow_sub_C_ne_zero hmn y, ?_⟩
| simp only [map_sub, map_pow, aeval_X, aeval_C, h, sub_self]
obtain ⟨r, s, h⟩ := (mem_adjoin_simple_iff F _).1 (heq ▸ mem_adjoin_simple_self F (α ^ m))
by_cases hzero : aeval (α ^ n) s = 0
· simp only [hzero, div_zero, pow_eq_zero_iff hm] at h
exact h.symm ▸ isAlgebraic_zero
replace hm : 0 < m := Nat.pos_of_ne_zero hm
rw [eq_div_iff hzero, ← sub_eq_zero] at h
replace hzero : s ≠ 0 := by rintro rfl; simp only [map_zero, not_true_eq_false] at hzero
let f : F[X] := X ^ m * expand F n s - expand F n r
refine ⟨f, ?_, ?_⟩
· have : f.coeff (n * s.natDegree + m) ≠ 0 := by
have hn : 0 < n := by linarith only [hm, hmn]
have hndvd : ¬ n ∣ n * s.natDegree + m := by
rw [← Nat.dvd_add_iff_right (n.dvd_mul_right s.natDegree)]
exact Nat.not_dvd_of_pos_of_lt hm hmn
simp only [f, coeff_sub, coeff_X_pow_mul, s.coeff_expand_mul' hn, coeff_natDegree,
coeff_expand hn r, hndvd, ite_false, sub_zero]
exact leadingCoeff_ne_zero.2 hzero
intro h
simp only [h, coeff_zero, ne_eq, not_true_eq_false] at this
· simp only [f, map_sub, map_mul, map_pow, aeval_X, expand_aeval, h]
theorem isAlgebraic_of_finite_intermediateField
[Finite (IntermediateField F E)] : Algebra.IsAlgebraic F E := ⟨fun α ↦
have ⟨_m, _n, hneq, heq⟩ := Finite.exists_ne_map_eq_of_infinite fun n ↦ F⟮α ^ n⟯
isAlgebraic_of_adjoin_eq_adjoin F E hneq heq⟩
theorem FiniteDimensional.of_finite_intermediateField
[Finite (IntermediateField F E)] : FiniteDimensional F E := by
let IF := { K : IntermediateField F E // ∃ x, K = F⟮x⟯ }
| Mathlib/FieldTheory/PrimitiveElement.lean | 245 | 274 |
/-
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.Algebra.BigOperators.Field
import Mathlib.Analysis.Complex.Basic
import Mathlib.Analysis.InnerProductSpace.Defs
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Properties of inner product spaces
This file proves many basic properties of inner product spaces (real or complex).
## Main results
- `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants).
- `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many
variants).
- `inner_eq_sum_norm_sq_div_four`: the polarization identity.
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap (BilinForm)
variable {𝕜 E F : Type*} [RCLike 𝕜]
section BasicProperties_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local postfix:90 "†" => starRingEnd _
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ :=
InnerProductSpace.conj_inner_symm _ _
theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ :=
@inner_conj_symm ℝ _ _ _ _ x y
theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by
rw [← inner_conj_symm]
exact star_eq_zero
@[simp]
theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp
theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=
InnerProductSpace.add_left _ _ _
theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by
rw [← inner_conj_symm, inner_add_left, RingHom.map_add]
simp only [inner_conj_symm]
theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re]
theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im]
section Algebra
variable {𝕝 : Type*} [CommSemiring 𝕝] [StarRing 𝕝] [Algebra 𝕝 𝕜] [Module 𝕝 E]
[IsScalarTower 𝕝 𝕜 E] [StarModule 𝕝 𝕜]
/-- See `inner_smul_left` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_left_eq_star_smul (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r† • ⟪x, y⟫ := by
rw [← algebraMap_smul 𝕜 r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply,
← algebraMap_star_comm, ← smul_eq_mul, algebraMap_smul]
/-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star
(eg `ℕ`, `ℤ`, `ℚ≥0`, `ℚ`, `ℝ`). -/
lemma inner_smul_left_eq_smul [TrivialStar 𝕝] (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial]
/-- See `inner_smul_right` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_right_eq_smul (x y : E) (r : 𝕝) : ⟪x, r • y⟫ = r • ⟪x, y⟫ := by
rw [← inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply,
star_smul, star_star, ← starRingEnd_apply, inner_conj_symm]
end Algebra
/-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/
theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=
inner_smul_left_eq_star_smul ..
theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_left _ _ _
theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left, conj_ofReal, Algebra.smul_def]
/-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/
theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=
inner_smul_right_eq_smul ..
theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_right _ _ _
theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_right, Algebra.smul_def]
/-- The inner product as a sesquilinear form.
Note that in the case `𝕜 = ℝ` this is a bilinear form. -/
@[simps!]
def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=
LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫)
(fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _)
(fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _
/-- The real inner product as a bilinear form.
Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/
@[simps!]
def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip
/-- An inner product with a sum on the left. -/
theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ :=
map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _
/-- An inner product with a sum on the right. -/
theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ :=
map_sum (LinearMap.flip sesqFormOfInner x) _ _
/-- An inner product with a sum on the left, `Finsupp` version. -/
protected theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by
convert sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_left, Finsupp.sum, smul_eq_mul]
/-- An inner product with a sum on the right, `Finsupp` version. -/
protected theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by
convert inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_right, Finsupp.sum, smul_eq_mul]
protected theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by
simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul]
protected theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by
simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul]
@[simp]
theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by
rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul]
theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by
simp only [inner_zero_left, AddMonoidHom.map_zero]
@[simp]
theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by
rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero]
theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by
simp only [inner_zero_right, AddMonoidHom.map_zero]
theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ :=
PreInnerProductSpace.toCore.re_inner_nonneg x
theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ :=
@inner_self_nonneg ℝ F _ _ _ x
@[simp]
theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=
((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im (𝕜 := 𝕜) x)
theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by
rw [← inner_self_ofReal_re, ← norm_sq_eq_re_inner, ofReal_pow]
theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by
conv_rhs => rw [← inner_self_ofReal_re]
symm
exact norm_of_nonneg inner_self_nonneg
theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by
rw [← inner_self_re_eq_norm]
exact inner_self_ofReal_re _
theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ :=
@inner_self_ofReal_norm ℝ F _ _ _ x
theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj]
@[simp]
theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by
rw [← neg_one_smul 𝕜 x, inner_smul_left]
simp
@[simp]
theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by
rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm]
theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp
theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _
theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by
simp [sub_eq_add_neg, inner_add_left]
theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by
simp [sub_eq_add_neg, inner_add_right]
theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by
rw [← inner_conj_symm, mul_comm]
exact re_eq_norm_of_mul_conj (inner y x)
/-- Expand `⟪x + y, x + y⟫` -/
theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_add_left, inner_add_right]; ring
/-- Expand `⟪x + y, x + y⟫_ℝ` -/
theorem real_inner_add_add_self (x y : F) :
⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_add_add_self, this, add_left_inj]
ring
-- Expand `⟪x - y, x - y⟫`
theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_sub_left, inner_sub_right]; ring
/-- Expand `⟪x - y, x - y⟫_ℝ` -/
theorem real_inner_sub_sub_self (x y : F) :
⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_sub_sub_self, this, add_left_inj]
ring
/-- Parallelogram law -/
theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by
simp only [inner_add_add_self, inner_sub_sub_self]
ring
/-- **Cauchy–Schwarz inequality**. -/
theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=
letI cd : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
InnerProductSpace.Core.inner_mul_inner_self_le x y
/-- Cauchy–Schwarz inequality for real inner products. -/
theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=
calc
⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by
rw [real_inner_comm y, ← norm_mul]
exact le_abs_self _
_ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y
end BasicProperties_Seminormed
section BasicProperties
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by
rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero]
theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=
inner_self_eq_zero.not
variable (𝕜)
theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)]
theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)]
variable {𝕜}
@[simp]
theorem re_inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by
rw [← norm_sq_eq_re_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero]
@[simp]
lemma re_inner_self_pos {x : E} : 0 < re ⟪x, x⟫ ↔ x ≠ 0 := by
simpa [-re_inner_self_nonpos] using re_inner_self_nonpos (𝕜 := 𝕜) (x := x).not
@[deprecated (since := "2025-04-22")] alias inner_self_nonpos := re_inner_self_nonpos
@[deprecated (since := "2025-04-22")] alias inner_self_pos := re_inner_self_pos
open scoped InnerProductSpace in
theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := re_inner_self_nonpos (𝕜 := ℝ)
open scoped InnerProductSpace in
theorem real_inner_self_pos {x : F} : 0 < ⟪x, x⟫_ℝ ↔ x ≠ 0 := re_inner_self_pos (𝕜 := ℝ)
/-- A family of vectors is linearly independent if they are nonzero
and orthogonal. -/
theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0)
(ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by
rw [linearIndependent_iff']
intro s g hg i hi
have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by
rw [inner_sum]
symm
convert Finset.sum_eq_single (M := 𝕜) i ?_ ?_
· rw [inner_smul_right]
· intro j _hj hji
rw [inner_smul_right, ho hji.symm, mul_zero]
· exact fun h => False.elim (h hi)
simpa [hg, hz] using h'
end BasicProperties
section Norm_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "IK" => @RCLike.I 𝕜 _
theorem norm_eq_sqrt_re_inner (x : E) : ‖x‖ = √(re ⟪x, x⟫) :=
calc
‖x‖ = √(‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm
_ = √(re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_re_inner _)
@[deprecated (since := "2025-04-22")] alias norm_eq_sqrt_inner := norm_eq_sqrt_re_inner
theorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = √⟪x, x⟫_ℝ :=
@norm_eq_sqrt_re_inner ℝ _ _ _ _ x
theorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by
rw [@norm_eq_sqrt_re_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫),
sqrt_mul_self inner_self_nonneg]
theorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by
rw [pow_two, inner_self_eq_norm_mul_norm]
theorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ := by
have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x
simpa using h
theorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by
rw [pow_two, real_inner_self_eq_norm_mul_norm]
/-- Expand the square -/
theorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜]
rw [inner_add_add_self, two_mul]
simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add]
rw [← inner_conj_symm, conj_re]
alias norm_add_pow_two := norm_add_sq
/-- Expand the square -/
theorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := by
have h := @norm_add_sq ℝ _ _ _ _ x y
simpa using h
alias norm_add_pow_two_real := norm_add_sq_real
/-- Expand the square -/
theorem norm_add_mul_self (x y : E) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_add_sq _ _
/-- Expand the square -/
theorem norm_add_mul_self_real (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_add_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Expand the square -/
theorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg,
sub_eq_add_neg]
alias norm_sub_pow_two := norm_sub_sq
/-- Expand the square -/
theorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 :=
@norm_sub_sq ℝ _ _ _ _ _ _
alias norm_sub_pow_two_real := norm_sub_sq_real
/-- Expand the square -/
theorem norm_sub_mul_self (x y : E) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_sub_sq _ _
/-- Expand the square -/
theorem norm_sub_mul_self_real (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_sub_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Cauchy–Schwarz inequality with norm -/
theorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by
rw [norm_eq_sqrt_re_inner (𝕜 := 𝕜) x, norm_eq_sqrt_re_inner (𝕜 := 𝕜) y]
letI : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
exact InnerProductSpace.Core.norm_inner_le_norm x y
theorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ :=
norm_inner_le_norm x y
theorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=
le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ :=
(Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ :=
le_trans (le_abs_self _) (abs_real_inner_le_norm _ _)
lemma inner_eq_zero_of_left {x : E} (y : E) (h : ‖x‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [← norm_eq_zero]
refine le_antisymm ?_ (by positivity)
exact norm_inner_le_norm _ _ |>.trans <| by simp [h]
lemma inner_eq_zero_of_right (x : E) {y : E} (h : ‖y‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [inner_eq_zero_symm, inner_eq_zero_of_left _ h]
variable (𝕜)
include 𝕜 in
theorem parallelogram_law_with_norm (x y : E) :
‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) := by
simp only [← @inner_self_eq_norm_mul_norm 𝕜]
| rw [← re.map_add, parallelogram_law, two_mul, two_mul]
simp only [re.map_add]
| Mathlib/Analysis/InnerProductSpace/Basic.lean | 453 | 455 |
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.CartanSubalgebra
import Mathlib.Algebra.Lie.Weights.Basic
/-!
# Weights and roots of Lie modules and Lie algebras with respect to Cartan subalgebras
Given a Lie algebra `L` which is not necessarily nilpotent, it may be useful to study its
representations by restricting them to a nilpotent subalgebra (e.g., a Cartan subalgebra). In the
particular case when we view `L` as a module over itself via the adjoint action, the weight spaces
of `L` restricted to a nilpotent subalgebra are known as root spaces.
Basic definitions and properties of the above ideas are provided in this file.
## Main definitions
* `LieAlgebra.rootSpace`
* `LieAlgebra.corootSpace`
* `LieAlgebra.rootSpaceWeightSpaceProduct`
* `LieAlgebra.rootSpaceProduct`
* `LieAlgebra.zeroRootSubalgebra_eq_iff_is_cartan`
-/
suppress_compilation
open Set
variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L]
(H : LieSubalgebra R L) [LieRing.IsNilpotent H]
{M : Type*} [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
namespace LieAlgebra
open scoped TensorProduct
open TensorProduct.LieModule LieModule
/-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of a map `χ : H → R` is the weight
space of `L` regarded as a module of `H` via the adjoint action. -/
abbrev rootSpace (χ : H → R) : LieSubmodule R H L :=
genWeightSpace L χ
theorem zero_rootSpace_eq_top_of_nilpotent [LieRing.IsNilpotent L] :
rootSpace (⊤ : LieSubalgebra R L) 0 = ⊤ :=
zero_genWeightSpace_eq_top_of_nilpotent L
@[simp]
theorem rootSpace_comap_eq_genWeightSpace (χ : H → R) :
(rootSpace H χ).comap H.incl' = genWeightSpace H χ :=
comap_genWeightSpace_eq_of_injective Subtype.coe_injective
variable {H}
theorem lie_mem_genWeightSpace_of_mem_genWeightSpace {χ₁ χ₂ : H → R} {x : L} {m : M}
(hx : x ∈ rootSpace H χ₁) (hm : m ∈ genWeightSpace M χ₂) :
⁅x, m⁆ ∈ genWeightSpace M (χ₁ + χ₂) := by
rw [genWeightSpace, LieSubmodule.mem_iInf]
intro y
replace hx : x ∈ genWeightSpaceOf L (χ₁ y) y := by
rw [rootSpace, genWeightSpace, LieSubmodule.mem_iInf] at hx; exact hx y
replace hm : m ∈ genWeightSpaceOf M (χ₂ y) y := by
rw [genWeightSpace, LieSubmodule.mem_iInf] at hm; exact hm y
exact lie_mem_maxGenEigenspace_toEnd hx hm
lemma toEnd_pow_apply_mem {χ₁ χ₂ : H → R} {x : L} {m : M}
(hx : x ∈ rootSpace H χ₁) (hm : m ∈ genWeightSpace M χ₂) (n) :
(toEnd R L M x ^ n : Module.End R M) m ∈ genWeightSpace M (n • χ₁ + χ₂) := by
induction n with
| zero => simpa using hm
| succ n IH =>
simp only [pow_succ', Module.End.mul_apply, toEnd_apply_apply,
Nat.cast_add, Nat.cast_one, rootSpace]
convert lie_mem_genWeightSpace_of_mem_genWeightSpace hx IH using 2
rw [succ_nsmul, ← add_assoc, add_comm (n • _)]
variable (R L H M)
/-- Auxiliary definition for `rootSpaceWeightSpaceProduct`,
which is close to the deterministic timeout limit.
-/
def rootSpaceWeightSpaceProductAux {χ₁ χ₂ χ₃ : H → R} (hχ : χ₁ + χ₂ = χ₃) :
rootSpace H χ₁ →ₗ[R] genWeightSpace M χ₂ →ₗ[R] genWeightSpace M χ₃ where
toFun x :=
{ toFun := fun m =>
⟨⁅(x : L), (m : M)⁆,
hχ ▸ lie_mem_genWeightSpace_of_mem_genWeightSpace x.property m.property⟩
map_add' := fun m n => by simp only [LieSubmodule.coe_add, lie_add, AddMemClass.mk_add_mk]
map_smul' := fun t m => by
conv_lhs =>
congr
rw [LieSubmodule.coe_smul, lie_smul]
rfl }
map_add' x y := by
ext m
simp only [LieSubmodule.coe_add, add_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.add_apply,
AddMemClass.mk_add_mk]
map_smul' t x := by
simp only [RingHom.id_apply]
ext m
simp only [SetLike.val_smul, smul_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.smul_apply,
SetLike.mk_smul_mk]
/-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural
`R`-bilinear product of root vectors and weight vectors, compatible with the actions of `H`. -/
def rootSpaceWeightSpaceProduct (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) :
rootSpace H χ₁ ⊗[R] genWeightSpace M χ₂ →ₗ⁅R,H⁆ genWeightSpace M χ₃ :=
liftLie R H (rootSpace H χ₁) (genWeightSpace M χ₂) (genWeightSpace M χ₃)
{ toLinearMap := rootSpaceWeightSpaceProductAux R L H M hχ
map_lie' := fun {x y} => by
ext m
simp only [rootSpaceWeightSpaceProductAux]
dsimp
simp only [LieSubalgebra.coe_bracket_of_module, lie_lie] }
@[simp]
theorem coe_rootSpaceWeightSpaceProduct_tmul (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃)
(x : rootSpace H χ₁) (m : genWeightSpace M χ₂) :
(rootSpaceWeightSpaceProduct R L H M χ₁ χ₂ χ₃ hχ (x ⊗ₜ m) : M) = ⁅(x : L), (m : M)⁆ := by
simp only [rootSpaceWeightSpaceProduct, rootSpaceWeightSpaceProductAux, coe_liftLie_eq_lift_coe,
AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, lift_apply, LinearMap.coe_mk, AddHom.coe_mk,
Submodule.coe_mk]
theorem mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace (α χ : H → R)
{x : L} (hx : x ∈ rootSpace H α) :
MapsTo (toEnd R L M x) (genWeightSpace M χ) (genWeightSpace M (α + χ)) := by
intro m hm
let x' : rootSpace H α := ⟨x, hx⟩
let m' : genWeightSpace M χ := ⟨m, hm⟩
exact (rootSpaceWeightSpaceProduct R L H M α χ (α + χ) rfl (x' ⊗ₜ m')).property
| /-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural
`R`-bilinear product of root vectors, compatible with the actions of `H`. -/
def rootSpaceProduct (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) :
rootSpace H χ₁ ⊗[R] rootSpace H χ₂ →ₗ⁅R,H⁆ rootSpace H χ₃ :=
rootSpaceWeightSpaceProduct R L H L χ₁ χ₂ χ₃ hχ
@[simp]
| Mathlib/Algebra/Lie/Weights/Cartan.lean | 135 | 141 |
/-
Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.AlgebraicGeometry.EllipticCurve.DivisionPolynomial.Basic
import Mathlib.Tactic.ComputeDegree
/-!
# Division polynomials of Weierstrass curves
This file computes the leading terms of certain polynomials associated to division polynomials of
Weierstrass curves defined in `Mathlib.AlgebraicGeometry.EllipticCurve.DivisionPolynomial.Basic`.
## Mathematical background
Let `W` be a Weierstrass curve over a commutative ring `R`. By strong induction,
* `preΨₙ` has leading coefficient `n / 2` and degree `(n² - 4) / 2` if `n` is even,
* `preΨₙ` has leading coefficient `n` and degree `(n² - 1) / 2` if `n` is odd,
* `ΨSqₙ` has leading coefficient `n²` and degree `n² - 1`, and
* `Φₙ` has leading coefficient `1` and degree `n²`.
In particular, when `R` is an integral domain of characteristic different from `n`, the univariate
polynomials `preΨₙ`, `ΨSqₙ`, and `Φₙ` all have their expected leading terms.
## Main statements
* `WeierstrassCurve.natDegree_preΨ_le`: the degree bound `d` of `preΨₙ`.
* `WeierstrassCurve.coeff_preΨ`: the `d`-th coefficient of `preΨₙ`.
* `WeierstrassCurve.natDegree_preΨ`: the degree of `preΨₙ` when `n ≠ 0`.
* `WeierstrassCurve.leadingCoeff_preΨ`: the leading coefficient of `preΨₙ` when `n ≠ 0`.
* `WeierstrassCurve.natDegree_ΨSq_le`: the degree bound `d` of `ΨSqₙ`.
* `WeierstrassCurve.coeff_ΨSq`: the `d`-th coefficient of `ΨSqₙ`.
* `WeierstrassCurve.natDegree_ΨSq`: the degree of `ΨSqₙ` when `n ≠ 0`.
* `WeierstrassCurve.leadingCoeff_ΨSq`: the leading coefficient of `ΨSqₙ` when `n ≠ 0`.
* `WeierstrassCurve.natDegree_Φ_le`: the degree bound `d` of `Φₙ`.
* `WeierstrassCurve.coeff_Φ`: the `d`-th coefficient of `Φₙ`.
* `WeierstrassCurve.natDegree_Φ`: the degree of `Φₙ` when `n ≠ 0`.
* `WeierstrassCurve.leadingCoeff_Φ`: the leading coefficient of `Φₙ` when `n ≠ 0`.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, division polynomial, torsion point
-/
open Polynomial
universe u
namespace WeierstrassCurve
variable {R : Type u} [CommRing R] (W : WeierstrassCurve R)
section Ψ₂Sq
lemma natDegree_Ψ₂Sq_le : W.Ψ₂Sq.natDegree ≤ 3 := by
rw [Ψ₂Sq]
compute_degree
@[simp]
lemma coeff_Ψ₂Sq : W.Ψ₂Sq.coeff 3 = 4 := by
rw [Ψ₂Sq]
compute_degree!
lemma coeff_Ψ₂Sq_ne_zero (h : (4 : R) ≠ 0) : W.Ψ₂Sq.coeff 3 ≠ 0 := by
rwa [coeff_Ψ₂Sq]
@[simp]
lemma natDegree_Ψ₂Sq (h : (4 : R) ≠ 0) : W.Ψ₂Sq.natDegree = 3 :=
natDegree_eq_of_le_of_coeff_ne_zero W.natDegree_Ψ₂Sq_le <| W.coeff_Ψ₂Sq_ne_zero h
lemma natDegree_Ψ₂Sq_pos (h : (4 : R) ≠ 0) : 0 < W.Ψ₂Sq.natDegree :=
W.natDegree_Ψ₂Sq h ▸ three_pos
@[simp]
lemma leadingCoeff_Ψ₂Sq (h : (4 : R) ≠ 0) : W.Ψ₂Sq.leadingCoeff = 4 := by
rw [leadingCoeff, W.natDegree_Ψ₂Sq h, coeff_Ψ₂Sq]
lemma Ψ₂Sq_ne_zero (h : (4 : R) ≠ 0) : W.Ψ₂Sq ≠ 0 :=
ne_zero_of_natDegree_gt <| W.natDegree_Ψ₂Sq_pos h
end Ψ₂Sq
section Ψ₃
lemma natDegree_Ψ₃_le : W.Ψ₃.natDegree ≤ 4 := by
rw [Ψ₃]
compute_degree
@[simp]
lemma coeff_Ψ₃ : W.Ψ₃.coeff 4 = 3 := by
rw [Ψ₃]
compute_degree!
lemma coeff_Ψ₃_ne_zero (h : (3 : R) ≠ 0) : W.Ψ₃.coeff 4 ≠ 0 := by
rwa [coeff_Ψ₃]
@[simp]
lemma natDegree_Ψ₃ (h : (3 : R) ≠ 0) : W.Ψ₃.natDegree = 4 :=
natDegree_eq_of_le_of_coeff_ne_zero W.natDegree_Ψ₃_le <| W.coeff_Ψ₃_ne_zero h
lemma natDegree_Ψ₃_pos (h : (3 : R) ≠ 0) : 0 < W.Ψ₃.natDegree :=
W.natDegree_Ψ₃ h ▸ four_pos
@[simp]
lemma leadingCoeff_Ψ₃ (h : (3 : R) ≠ 0) : W.Ψ₃.leadingCoeff = 3 := by
rw [leadingCoeff, W.natDegree_Ψ₃ h, coeff_Ψ₃]
lemma Ψ₃_ne_zero (h : (3 : R) ≠ 0) : W.Ψ₃ ≠ 0 :=
ne_zero_of_natDegree_gt <| W.natDegree_Ψ₃_pos h
end Ψ₃
section preΨ₄
lemma natDegree_preΨ₄_le : W.preΨ₄.natDegree ≤ 6 := by
rw [preΨ₄]
compute_degree
@[simp]
lemma coeff_preΨ₄ : W.preΨ₄.coeff 6 = 2 := by
rw [preΨ₄]
compute_degree!
lemma coeff_preΨ₄_ne_zero (h : (2 : R) ≠ 0) : W.preΨ₄.coeff 6 ≠ 0 := by
rwa [coeff_preΨ₄]
@[simp]
lemma natDegree_preΨ₄ (h : (2 : R) ≠ 0) : W.preΨ₄.natDegree = 6 :=
natDegree_eq_of_le_of_coeff_ne_zero W.natDegree_preΨ₄_le <| W.coeff_preΨ₄_ne_zero h
lemma natDegree_preΨ₄_pos (h : (2 : R) ≠ 0) : 0 < W.preΨ₄.natDegree := by
linarith only [W.natDegree_preΨ₄ h]
@[simp]
lemma leadingCoeff_preΨ₄ (h : (2 : R) ≠ 0) : W.preΨ₄.leadingCoeff = 2 := by
rw [leadingCoeff, W.natDegree_preΨ₄ h, coeff_preΨ₄]
lemma preΨ₄_ne_zero (h : (2 : R) ≠ 0) : W.preΨ₄ ≠ 0 :=
ne_zero_of_natDegree_gt <| W.natDegree_preΨ₄_pos h
end preΨ₄
section preΨ'
private def expDegree (n : ℕ) : ℕ :=
(n ^ 2 - if Even n then 4 else 1) / 2
private lemma expDegree_cast {n : ℕ} (hn : n ≠ 0) :
2 * (expDegree n : ℤ) = n ^ 2 - if Even n then 4 else 1 := by
rcases n.even_or_odd' with ⟨n, rfl | rfl⟩
· rcases n with _ | n
· contradiction
push_cast [expDegree, show (2 * (n + 1)) ^ 2 = 2 * (2 * n * (n + 2)) + 4 by ring1, even_two_mul,
Nat.add_sub_cancel, Nat.mul_div_cancel_left _ two_pos]
ring1
· push_cast [expDegree, show (2 * n + 1) ^ 2 = 2 * (2 * n * (n + 1)) + 1 by ring1,
n.not_even_two_mul_add_one, Nat.add_sub_cancel, Nat.mul_div_cancel_left _ two_pos]
ring1
private lemma expDegree_rec (m : ℕ) :
(expDegree (2 * (m + 3)) = 2 * expDegree (m + 2) + expDegree (m + 3) + expDegree (m + 5) ∧
expDegree (2 * (m + 3)) = expDegree (m + 1) + expDegree (m + 3) + 2 * expDegree (m + 4)) ∧
(expDegree (2 * (m + 2) + 1) =
expDegree (m + 4) + 3 * expDegree (m + 2) + (if Even m then 2 * 3 else 0) ∧
expDegree (2 * (m + 2) + 1) =
expDegree (m + 1) + 3 * expDegree (m + 3) + (if Even m then 0 else 2 * 3)) := by
push_cast [← @Nat.cast_inj ℤ, ← mul_left_cancel_iff_of_pos (b := (expDegree _ : ℤ)) two_pos,
mul_add, mul_left_comm (2 : ℤ)]
repeat rw [expDegree_cast <| by omega]
push_cast [Nat.even_add_one, ite_not, even_two_mul]
constructor <;> constructor <;> split_ifs <;> ring1
private def expCoeff (n : ℕ) : ℤ :=
if Even n then n / 2 else n
private lemma expCoeff_cast (n : ℕ) : (expCoeff n : ℚ) = if Even n then (n / 2 : ℚ) else n := by
rcases n.even_or_odd' with ⟨n, rfl | rfl⟩ <;> simp [expCoeff, n.not_even_two_mul_add_one]
private lemma expCoeff_rec (m : ℕ) :
(expCoeff (2 * (m + 3)) =
expCoeff (m + 2) ^ 2 * expCoeff (m + 3) * expCoeff (m + 5) -
expCoeff (m + 1) * expCoeff (m + 3) * expCoeff (m + 4) ^ 2) ∧
(expCoeff (2 * (m + 2) + 1) =
expCoeff (m + 4) * expCoeff (m + 2) ^ 3 * (if Even m then 4 ^ 2 else 1) -
expCoeff (m + 1) * expCoeff (m + 3) ^ 3 * (if Even m then 1 else 4 ^ 2)) := by
push_cast [← @Int.cast_inj ℚ, expCoeff_cast, even_two_mul, m.not_even_two_mul_add_one,
Nat.even_add_one, ite_not]
constructor <;> split_ifs <;> ring1
private lemma natDegree_coeff_preΨ' (n : ℕ) :
(W.preΨ' n).natDegree ≤ expDegree n ∧ (W.preΨ' n).coeff (expDegree n) = expCoeff n := by
let dm {m n p q} : _ → _ → (p * q : R[X]).natDegree ≤ m + n := natDegree_mul_le_of_le
let dp {m n p} : _ → (p ^ n : R[X]).natDegree ≤ n * m := natDegree_pow_le_of_le n
let cm {m n p q} : _ → _ → (p * q : R[X]).coeff (m + n) = _ := coeff_mul_of_natDegree_le
let cp {m n p} : _ → (p ^ m : R[X]).coeff (m * n) = _ := coeff_pow_of_natDegree_le
induction n using normEDSRec with
| zero => simpa only [preΨ'_zero] using ⟨natDegree_zero.le, Int.cast_zero.symm⟩
| one => simpa only [preΨ'_one] using ⟨natDegree_one.le, coeff_one_zero.trans Int.cast_one.symm⟩
| two => simpa only [preΨ'_two] using ⟨natDegree_one.le, coeff_one_zero.trans Int.cast_one.symm⟩
| three => simpa only [preΨ'_three] using ⟨W.natDegree_Ψ₃_le, W.coeff_Ψ₃ ▸ Int.cast_three.symm⟩
| four => simpa only [preΨ'_four] using ⟨W.natDegree_preΨ₄_le, W.coeff_preΨ₄ ▸ Int.cast_two.symm⟩
| even m h₁ h₂ h₃ h₄ h₅ =>
constructor
· nth_rw 1 [preΨ'_even, ← max_self <| expDegree _, (expDegree_rec m).1.1, (expDegree_rec m).1.2]
exact natDegree_sub_le_of_le (dm (dm (dp h₂.1) h₃.1) h₅.1) (dm (dm h₁.1 h₃.1) (dp h₄.1))
· nth_rw 1 [preΨ'_even, coeff_sub, (expDegree_rec m).1.1, cm (dm (dp h₂.1) h₃.1) h₅.1,
cm (dp h₂.1) h₃.1, cp h₂.1, h₂.2, h₃.2, h₅.2, (expDegree_rec m).1.2,
cm (dm h₁.1 h₃.1) (dp h₄.1), cm h₁.1 h₃.1, h₁.2, cp h₄.1, h₃.2, h₄.2, (expCoeff_rec m).1]
norm_cast
| odd m h₁ h₂ h₃ h₄ =>
rw [preΨ'_odd]
constructor
· nth_rw 1 [← max_self <| expDegree _, (expDegree_rec m).2.1, (expDegree_rec m).2.2]
refine natDegree_sub_le_of_le (dm (dm h₄.1 (dp h₂.1)) ?_) (dm (dm h₁.1 (dp h₃.1)) ?_)
all_goals split_ifs <;>
simp only [apply_ite natDegree, natDegree_one.le, dp W.natDegree_Ψ₂Sq_le]
· nth_rw 1 [coeff_sub, (expDegree_rec m).2.1, cm (dm h₄.1 (dp h₂.1)), cm h₄.1 (dp h₂.1),
h₄.2, cp h₂.1, h₂.2, apply_ite₂ coeff, cp W.natDegree_Ψ₂Sq_le, coeff_Ψ₂Sq, coeff_one_zero,
(expDegree_rec m).2.2, cm (dm h₁.1 (dp h₃.1)), cm h₁.1 (dp h₃.1), h₁.2, cp h₃.1, h₃.2,
apply_ite₂ coeff, cp W.natDegree_Ψ₂Sq_le, coeff_one_zero, coeff_Ψ₂Sq, (expCoeff_rec m).2]
· norm_cast
all_goals split_ifs <;>
simp only [apply_ite natDegree, natDegree_one.le, dp W.natDegree_Ψ₂Sq_le]
lemma natDegree_preΨ'_le (n : ℕ) : (W.preΨ' n).natDegree ≤ (n ^ 2 - if Even n then 4 else 1) / 2 :=
(W.natDegree_coeff_preΨ' n).left
@[simp]
lemma coeff_preΨ' (n : ℕ) : (W.preΨ' n).coeff ((n ^ 2 - if Even n then 4 else 1) / 2) =
if Even n then n / 2 else n := by
convert (W.natDegree_coeff_preΨ' n).right using 1
rcases n.even_or_odd' with ⟨n, rfl | rfl⟩ <;> simp [expCoeff, n.not_even_two_mul_add_one]
lemma coeff_preΨ'_ne_zero {n : ℕ} (h : (n : R) ≠ 0) :
(W.preΨ' n).coeff ((n ^ 2 - if Even n then 4 else 1) / 2) ≠ 0 := by
rcases n.even_or_odd' with ⟨n, rfl | rfl⟩
· rw [coeff_preΨ', if_pos <| even_two_mul n, n.mul_div_cancel_left two_pos]
exact right_ne_zero_of_mul <| by rwa [← Nat.cast_mul]
· rwa [coeff_preΨ', if_neg n.not_even_two_mul_add_one]
@[simp]
lemma natDegree_preΨ' {n : ℕ} (h : (n : R) ≠ 0) :
(W.preΨ' n).natDegree = (n ^ 2 - if Even n then 4 else 1) / 2 :=
natDegree_eq_of_le_of_coeff_ne_zero (W.natDegree_preΨ'_le n) <| W.coeff_preΨ'_ne_zero h
lemma natDegree_preΨ'_pos {n : ℕ} (hn : 2 < n) (h : (n : R) ≠ 0) : 0 < (W.preΨ' n).natDegree := by
simp only [W.natDegree_preΨ' h, Nat.div_pos_iff, zero_lt_two, true_and]
split_ifs <;>
exact Nat.AtLeastTwo.prop.trans <| Nat.sub_le_sub_right (Nat.pow_le_pow_left hn 2) _
@[simp]
lemma leadingCoeff_preΨ' {n : ℕ} (h : (n : R) ≠ 0) :
(W.preΨ' n).leadingCoeff = if Even n then n / 2 else n := by
rw [leadingCoeff, W.natDegree_preΨ' h, coeff_preΨ']
lemma preΨ'_ne_zero [Nontrivial R] {n : ℕ} (h : (n : R) ≠ 0) : W.preΨ' n ≠ 0 := by
by_cases hn : 2 < n
· exact ne_zero_of_natDegree_gt <| W.natDegree_preΨ'_pos hn h
· rcases n with _ | _ | _ <;> aesop
end preΨ'
section preΨ
lemma natDegree_preΨ_le (n : ℤ) : (W.preΨ n).natDegree ≤
(n.natAbs ^ 2 - if Even n then 4 else 1) / 2 := by
induction n using Int.negInduction with
| nat n => exact_mod_cast W.preΨ_ofNat n ▸ W.natDegree_preΨ'_le n
| neg ih => simp only [preΨ_neg, natDegree_neg, Int.natAbs_neg, even_neg, ih]
@[simp]
lemma coeff_preΨ (n : ℤ) : (W.preΨ n).coeff ((n.natAbs ^ 2 - if Even n then 4 else 1) / 2) =
if Even n then n / 2 else n := by
induction n using Int.negInduction with
| nat n => exact_mod_cast W.preΨ_ofNat n ▸ W.coeff_preΨ' n
| neg ih n =>
simp only [preΨ_neg, coeff_neg, Int.natAbs_neg, even_neg]
rcases ih n, n.even_or_odd' with ⟨ih, ⟨n, rfl | rfl⟩⟩ <;>
push_cast [even_two_mul, Int.not_even_two_mul_add_one, Int.neg_ediv_of_dvd ⟨n, rfl⟩] at * <;>
rw [ih]
lemma coeff_preΨ_ne_zero {n : ℤ} (h : (n : R) ≠ 0) :
(W.preΨ n).coeff ((n.natAbs ^ 2 - if Even n then 4 else 1) / 2) ≠ 0 := by
induction n using Int.negInduction with
| nat n => simpa only [preΨ_ofNat, Int.even_coe_nat]
using W.coeff_preΨ'_ne_zero <| by exact_mod_cast h
| neg ih n => simpa only [preΨ_neg, coeff_neg, neg_ne_zero, Int.natAbs_neg, even_neg]
using ih n <| neg_ne_zero.mp <| by exact_mod_cast h
@[simp]
lemma natDegree_preΨ {n : ℤ} (h : (n : R) ≠ 0) :
(W.preΨ n).natDegree = (n.natAbs ^ 2 - if Even n then 4 else 1) / 2 :=
natDegree_eq_of_le_of_coeff_ne_zero (W.natDegree_preΨ_le n) <| W.coeff_preΨ_ne_zero h
lemma natDegree_preΨ_pos {n : ℤ} (hn : 2 < n.natAbs) (h : (n : R) ≠ 0) :
0 < (W.preΨ n).natDegree := by
induction n using Int.negInduction with
| nat n => simpa only [preΨ_ofNat] using W.natDegree_preΨ'_pos hn <| by exact_mod_cast h
| neg ih n => simpa only [preΨ_neg, natDegree_neg]
using ih n (by rwa [← Int.natAbs_neg]) <| neg_ne_zero.mp <| by exact_mod_cast h
@[simp]
lemma leadingCoeff_preΨ {n : ℤ} (h : (n : R) ≠ 0) :
(W.preΨ n).leadingCoeff = if Even n then n / 2 else n := by
rw [leadingCoeff, W.natDegree_preΨ h, coeff_preΨ]
lemma preΨ_ne_zero [Nontrivial R] {n : ℤ} (h : (n : R) ≠ 0) : W.preΨ n ≠ 0 := by
induction n using Int.negInduction with
| nat n => simpa only [preΨ_ofNat] using W.preΨ'_ne_zero <| by exact_mod_cast h
| neg ih n => simpa only [preΨ_neg, neg_ne_zero]
using ih n <| neg_ne_zero.mp <| by exact_mod_cast h
end preΨ
section ΨSq
private lemma natDegree_coeff_ΨSq_ofNat (n : ℕ) :
(W.ΨSq n).natDegree ≤ n ^ 2 - 1 ∧ (W.ΨSq n).coeff (n ^ 2 - 1) = (n ^ 2 : ℤ) := by
let dp {m n p} : _ → (p ^ n : R[X]).natDegree ≤ n * m := natDegree_pow_le_of_le n
let h {n} := W.natDegree_coeff_preΨ' n
rcases n with _ | n
· simp
have hd : (n + 1) ^ 2 - 1 = 2 * expDegree (n + 1) + if Even (n + 1) then 3 else 0 := by
push_cast [← @Nat.cast_inj ℤ, add_sq, expDegree_cast (by omega : n + 1 ≠ 0)]
split_ifs <;> ring1
have hc : (n + 1 : ℕ) ^ 2 = expCoeff (n + 1) ^ 2 * if Even (n + 1) then 4 else 1 := by
push_cast [← @Int.cast_inj ℚ, expCoeff_cast]
split_ifs <;> ring1
rw [ΨSq_ofNat, hd]
constructor
· refine natDegree_mul_le_of_le (dp h.1) ?_
split_ifs <;> simp only [apply_ite natDegree, natDegree_one.le, W.natDegree_Ψ₂Sq_le]
· rw [coeff_mul_of_natDegree_le (dp h.1), coeff_pow_of_natDegree_le h.1, h.2, apply_ite₂ coeff,
coeff_Ψ₂Sq, coeff_one_zero, hc]
· norm_cast
split_ifs <;> simp only [apply_ite natDegree, natDegree_one.le, W.natDegree_Ψ₂Sq_le]
lemma natDegree_ΨSq_le (n : ℤ) : (W.ΨSq n).natDegree ≤ n.natAbs ^ 2 - 1 := by
induction n using Int.negInduction with
| nat n => exact (W.natDegree_coeff_ΨSq_ofNat n).left
| neg ih => simp only [ΨSq_neg, Int.natAbs_neg, ih]
@[simp]
lemma coeff_ΨSq (n : ℤ) : (W.ΨSq n).coeff (n.natAbs ^ 2 - 1) = n ^ 2 := by
induction n using Int.negInduction with
| nat n => exact_mod_cast (W.natDegree_coeff_ΨSq_ofNat n).right
| neg ih => simp_rw [ΨSq_neg, Int.natAbs_neg, ← Int.cast_pow, neg_sq, Int.cast_pow, ih]
lemma coeff_ΨSq_ne_zero [NoZeroDivisors R] {n : ℤ} (h : (n : R) ≠ 0) :
(W.ΨSq n).coeff (n.natAbs ^ 2 - 1) ≠ 0 := by
rwa [coeff_ΨSq, pow_ne_zero_iff two_ne_zero]
@[simp]
lemma natDegree_ΨSq [NoZeroDivisors R] {n : ℤ} (h : (n : R) ≠ 0) :
(W.ΨSq n).natDegree = n.natAbs ^ 2 - 1 :=
natDegree_eq_of_le_of_coeff_ne_zero (W.natDegree_ΨSq_le n) <| W.coeff_ΨSq_ne_zero h
lemma natDegree_ΨSq_pos [NoZeroDivisors R] {n : ℤ} (hn : 1 < n.natAbs) (h : (n : R) ≠ 0) :
| 0 < (W.ΨSq n).natDegree := by
rwa [W.natDegree_ΨSq h, Nat.sub_pos_iff_lt, Nat.one_lt_pow_iff two_ne_zero]
@[simp]
| Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Degree.lean | 364 | 367 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Aurélien Saue, Anne Baanen
-/
import Mathlib.Tactic.NormNum.Inv
import Mathlib.Tactic.NormNum.Pow
import Mathlib.Util.AtomM
/-!
# `ring` tactic
A tactic for solving equations in commutative (semi)rings,
where the exponents can also contain variables.
Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> .
More precisely, expressions of the following form are supported:
- constants (non-negative integers)
- variables
- coefficients (any rational number, embedded into the (semi)ring)
- addition of expressions
- multiplication of expressions (`a * b`)
- scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`)
- exponentiation of expressions (the exponent must have type `ℕ`)
- subtraction and negation of expressions (if the base is a full ring)
The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved,
even though it is not strictly speaking an equation in the language of commutative rings.
## Implementation notes
The basic approach to prove equalities is to normalise both sides and check for equality.
The normalisation is guided by building a value in the type `ExSum` at the meta level,
together with a proof (at the base level) that the original value is equal to
the normalised version.
The outline of the file:
- Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`,
which can represent expressions with `+`, `*`, `^` and rational numerals.
The mutual induction ensures that associativity and distributivity are applied,
by restricting which kinds of subexpressions appear as arguments to the various operators.
- Represent addition, multiplication and exponentiation in the `ExSum` type,
thus allowing us to map expressions to `ExSum` (the `eval` function drives this).
We apply associativity and distributivity of the operators here (helped by `Ex*` types)
and commutativity as well (by sorting the subterms; unfortunately not helped by anything).
Any expression not of the above formats is treated as an atom (the same as a variable).
There are some details we glossed over which make the plan more complicated:
- The order on atoms is not initially obvious.
We construct a list containing them in order of initial appearance in the expression,
then use the index into the list as a key to order on.
- For `pow`, the exponent must be a natural number, while the base can be any semiring `α`.
We swap out operations for the base ring `α` with those for the exponent ring `ℕ`
as soon as we deal with exponents.
## Caveats and future work
The normalized form of an expression is the one that is useful for the tactic,
but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`.
Subtraction cancels out identical terms, but division does not.
That is: `a - a = 0 := by ring` solves the goal,
but `a / a := 1 by ring` doesn't.
Note that `0 / 0` is generally defined to be `0`,
so division cancelling out is not true in general.
Multiplication of powers can be simplified a little bit further:
`2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented
in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works.
This feature wasn't needed yet, so it's not implemented yet.
## Tags
ring, semiring, exponent, power
-/
assert_not_exists OrderedAddCommMonoid
namespace Mathlib.Tactic
namespace Ring
open Mathlib.Meta Qq NormNum Lean.Meta AtomM
attribute [local instance] monadLiftOptionMetaM
open Lean (MetaM Expr mkRawNatLit)
/-- A shortcut instance for `CommSemiring ℕ` used by ring. -/
def instCommSemiringNat : CommSemiring ℕ := inferInstance
/--
A typed expression of type `CommSemiring ℕ` used when we are working on
ring subexpressions of type `ℕ`.
-/
def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat)
mutual
/-- The base `e` of a normalized exponent expression. -/
inductive ExBase : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type
/--
An atomic expression `e` with id `id`.
Atomic expressions are those which `ring` cannot parse any further.
For instance, `a + (a % b)` has `a` and `(a % b)` as atoms.
The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does.
Atoms in fact represent equivalence classes of expressions, modulo definitional equality.
The field `index : ℕ` should be a unique number for each class,
while `value : expr` contains a representative of this class.
The function `resolve_atom` determines the appropriate atom for a given expression.
-/
| atom {sα} {e} (id : ℕ) : ExBase sα e
/-- A sum of monomials. -/
| sum {sα} {e} (_ : ExSum sα e) : ExBase sα e
/--
A monomial, which is a product of powers of `ExBase` expressions,
terminated by a (nonzero) constant coefficient.
-/
inductive ExProd : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type
/-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast.
If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/
| const {sα} {e} (value : ℚ) (hyp : Option Expr := none) : ExProd sα e
/-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase`
and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of
a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/
| mul {u : Lean.Level} {α : Q(Type u)} {sα} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} :
ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b)
/-- A polynomial expression, which is a sum of monomials. -/
inductive ExSum : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type
/-- Zero is a polynomial. `e` is the expression `0`. -/
| zero {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α)
/-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/
| add {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExProd sα a → ExSum sα b → ExSum sα q($a + $b)
end
mutual -- partial only to speed up compilation
/-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/
partial def ExBase.eq
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExBase sα a → ExBase sα b → Bool
| .atom i, .atom j => i == j
| .sum a, .sum b => a.eq b
| _, _ => false
@[inherit_doc ExBase.eq]
partial def ExProd.eq
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExProd sα a → ExProd sα b → Bool
| .const i _, .const j _ => i == j
| .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃
| _, _ => false
@[inherit_doc ExBase.eq]
partial def ExSum.eq
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExSum sα a → ExSum sα b → Bool
| .zero, .zero => true
| .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂
| _, _ => false
end
mutual -- partial only to speed up compilation
/--
A total order on normalized expressions.
This is not an `Ord` instance because it is heterogeneous.
-/
partial def ExBase.cmp
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExBase sα a → ExBase sα b → Ordering
| .atom i, .atom j => compare i j
| .sum a, .sum b => a.cmp b
| .atom .., .sum .. => .lt
| .sum .., .atom .. => .gt
@[inherit_doc ExBase.cmp]
partial def ExProd.cmp
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExProd sα a → ExProd sα b → Ordering
| .const i _, .const j _ => compare i j
| .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃)
| .const _ _, .mul .. => .lt
| .mul .., .const _ _ => .gt
@[inherit_doc ExBase.cmp]
partial def ExSum.cmp
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExSum sα a → ExSum sα b → Ordering
| .zero, .zero => .eq
| .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂)
| .zero, .add .. => .lt
| .add .., .zero => .gt
end
variable {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)}
instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩
instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩
instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩
mutual
/-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/
partial def ExBase.cast
{v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} :
ExBase sα a → Σ a, ExBase sβ a
| .atom i => ⟨a, .atom i⟩
| .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩
/-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/
partial def ExProd.cast
{v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} :
ExProd sα a → Σ a, ExProd sβ a
| .const i h => ⟨a, .const i h⟩
| .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩
/-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/
partial def ExSum.cast
{v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} :
ExSum sα a → Σ a, ExSum sβ a
| .zero => ⟨_, .zero⟩
| .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩
end
variable {u : Lean.Level}
/--
The result of evaluating an (unnormalized) expression `e` into the type family `E`
(one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'`
and a representation `E e'` for it, and a proof of `e = e'`.
-/
structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where
/-- The normalized result. -/
expr : Q($α)
/-- The data associated to the normalization. -/
val : E expr
/-- A proof that the original expression is equal to the normalized result. -/
proof : Q($e = $expr)
instance {α : Q(Type u)} {E : Q($α) → Type} {e : Q($α)} [Inhabited (Σ e, E e)] :
Inhabited (Result E e) :=
let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩
variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) {R : Type*} [CommSemiring R]
/--
Constructs the expression corresponding to `.const n`.
(The `.const` constructor does not check that the expression is correct.)
-/
def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e :=
let lit : Q(ℕ) := mkRawNatLit n
⟨q(($lit).rawCast : $α), .const n none⟩
/--
Constructs the expression corresponding to `.const (-n)`.
(The `.const` constructor does not check that the expression is correct.)
-/
def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e :=
let lit : Q(ℕ) := mkRawNatLit n
⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩
/--
Constructs the expression corresponding to `.const q h` for `q = n / d`
and `h` a proof that `(d : α) ≠ 0`.
(The `.const` constructor does not check that the expression is correct.)
-/
def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) :
(e : Q($α)) × ExProd sα e :=
⟨q(Rat.rawCast $n $d : $α), .const q h⟩
section
/-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/
def ExBase.toProd {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a : Q($α)} {b : Q(ℕ)}
(va : ExBase sα a) (vb : ExProd sℕ b) :
ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none)
/-- Embed `ExProd` in `ExSum` by adding 0. -/
def ExProd.toSum {sα : Q(CommSemiring $α)} {e : Q($α)} (v : ExProd sα e) : ExSum sα q($e + 0) :=
.add v .zero
/-- Get the leading coefficient of an `ExProd`. -/
def ExProd.coeff {sα : Q(CommSemiring $α)} {e : Q($α)} : ExProd sα e → ℚ
| .const q _ => q
| .mul _ _ v => v.coeff
end
/--
Two monomials are said to "overlap" if they differ by a constant factor, in which case the
constants just add. When this happens, the constant may be either zero (if the monomials cancel)
or nonzero (if they add up); the zero case is handled specially.
-/
inductive Overlap (e : Q($α)) where
/-- The expression `e` (the sum of monomials) is equal to `0`. -/
| zero (_ : Q(IsNat $e (nat_lit 0)))
/-- The expression `e` (the sum of monomials) is equal to another monomial
(with nonzero leading coefficient). -/
| nonzero (_ : Result (ExProd sα) e)
variable {a a' a₁ a₂ a₃ b b' b₁ b₂ b₃ c c₁ c₂ : R}
theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) :
x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add]
theorem add_overlap_pf_zero (x : R) (e) :
IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0)
| ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩
-- TODO: decide if this is a good idea globally in
-- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.60MonadLift.20Option.20.28OptionT.20m.29.60/near/469097834
private local instance {m} [Pure m] : MonadLift Option (OptionT m) where
monadLift f := .mk <| pure f
/--
Given monomials `va, vb`, attempts to add them together to get another monomial.
If the monomials are not compatible, returns `none`.
For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none`
and `xy + -xy = 0` is a `.zero` overlap.
-/
def evalAddOverlap {a b : Q($α)} (va : ExProd sα a) (vb : ExProd sα b) :
OptionT Lean.Core.CoreM (Overlap sα q($a + $b)) := do
Lean.Core.checkSystem decl_name%.toString
match va, vb with
| .const za ha, .const zb hb => do
let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb
let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb
match res with
| .isNat _ (.lit (.natVal 0)) p => pure <| .zero p
| rc =>
let ⟨zc, hc⟩ ← rc.toRatNZ
let ⟨c, pc⟩ := rc.toRawEq
pure <| .nonzero ⟨c, .const zc hc, pc⟩
| .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do
guard (va₁.eq vb₁ && va₂.eq vb₂)
match ← evalAddOverlap va₃ vb₃ with
| .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr)
| .nonzero ⟨_, vc, p⟩ =>
pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩
| _, _ => OptionT.fail
theorem add_pf_zero_add (b : R) : 0 + b = b := by simp
theorem add_pf_add_zero (a : R) : a + 0 = a := by simp
theorem add_pf_add_overlap
(_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by
subst_vars; simp [add_assoc, add_left_comm]
theorem add_pf_add_overlap_zero
(h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by
subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add]
theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc]
theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by
subst_vars; simp [add_left_comm]
/-- Adds two polynomials `va, vb` together to get a normalized result polynomial.
* `0 + b = b`
* `a + 0 = a`
* `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`)
* `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`)
* `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`)
-/
partial def evalAdd {a b : Q($α)} (va : ExSum sα a) (vb : ExSum sα b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a + $b) := do
Lean.Core.checkSystem decl_name%.toString
match va, vb with
| .zero, vb => return ⟨b, vb, q(add_pf_zero_add $b)⟩
| va, .zero => return ⟨a, va, q(add_pf_add_zero $a)⟩
| .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ =>
match ← (evalAddOverlap sα va₁ vb₁).run with
| some (.nonzero ⟨_, vc₁, pc₁⟩) =>
let ⟨_, vc₂, pc₂⟩ ← evalAdd va₂ vb₂
return ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩
| some (.zero pc₁) =>
let ⟨c₂, vc₂, pc₂⟩ ← evalAdd va₂ vb₂
return ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩
| none =>
if let .lt := va₁.cmp vb₁ then
let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ ← evalAdd va₂ vb
return ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩
else
let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ ← evalAdd va vb₂
return ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩
theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast]
theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast]
theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) :
(a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by
subst_vars; rw [mul_assoc]
theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) :
a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by
subst_vars; rw [mul_left_comm]
theorem mul_pp_pf_overlap {ea eb e : ℕ} (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) :
(x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by
subst_vars; simp [pow_add, mul_mul_mul_comm]
/-- Multiplies two monomials `va, vb` together to get a normalized result monomial.
* `x * y = (x * y)` (for `x`, `y` coefficients)
* `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient)
* `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient)
* `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)`
(if `ea` and `eb` are identical except coefficient)
* `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`)
* `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`)
-/
partial def evalMulProd {a b : Q($α)} (va : ExProd sα a) (vb : ExProd sα b) :
Lean.Core.CoreM <| Result (ExProd sα) q($a * $b) := do
Lean.Core.checkSystem decl_name%.toString
match va, vb with
| .const za ha, .const zb hb =>
if za = 1 then
return ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩
else if zb = 1 then
return ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩
else
let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb
let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _
q(CommSemiring.toSemiring) ra rb).get!
let ⟨zc, hc⟩ := rc.toRatNZ.get!
let ⟨c, pc⟩ := rc.toRawEq
return ⟨c, .const zc hc, pc⟩
| .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ =>
let ⟨_, vc, pc⟩ ← evalMulProd va₃ vb
return ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩
| .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ =>
let ⟨_, vc, pc⟩ ← evalMulProd va vb₃
return ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩
| .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => do
if vxa.eq vxb then
if let some (.nonzero ⟨_, ve, pe⟩) ← (evalAddOverlap sℕ vea veb).run then
let ⟨_, vc, pc⟩ ← evalMulProd va₂ vb₂
return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩
if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then
let ⟨_, vc, pc⟩ ← evalMulProd va₂ vb
return ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩
else
let ⟨_, vc, pc⟩ ← evalMulProd va vb₂
return ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩
theorem mul_zero (a : R) : a * 0 = 0 := by simp
theorem mul_add {d : R} (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) :
a * (b₁ + b₂) = d := by
subst_vars; simp [_root_.mul_add]
/-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial.
* `a * 0 = 0`
* `a * (b₁ + b₂) = (a * b₁) + (a * b₂)`
-/
def evalMul₁ {a b : Q($α)} (va : ExProd sα a) (vb : ExSum sα b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a * $b) := do
match vb with
| .zero => return ⟨_, .zero, q(mul_zero $a)⟩
| .add vb₁ vb₂ =>
let ⟨_, vc₁, pc₁⟩ ← evalMulProd sα va vb₁
let ⟨_, vc₂, pc₂⟩ ← evalMul₁ va vb₂
let ⟨_, vd, pd⟩ ← evalAdd sα vc₁.toSum vc₂
return ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩
theorem zero_mul (b : R) : 0 * b = 0 := by simp
theorem add_mul {d : R} (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) :
(a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul]
/-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial.
* `0 * b = 0`
* `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)`
-/
def evalMul {a b : Q($α)} (va : ExSum sα a) (vb : ExSum sα b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a * $b) := do
match va with
| .zero => return ⟨_, .zero, q(zero_mul $b)⟩
| .add va₁ va₂ =>
let ⟨_, vc₁, pc₁⟩ ← evalMul₁ sα va₁ vb
let ⟨_, vc₂, pc₂⟩ ← evalMul va₂ vb
let ⟨_, vd, pd⟩ ← evalAdd sα vc₁ vc₂
return ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩
theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp
theorem natCast_mul {a₁ a₃ : ℕ} (a₂) (_ : ((a₁ : ℕ) : R) = b₁)
(_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by
subst_vars; simp
theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero
theorem natCast_add {a₁ a₂ : ℕ}
(_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by
subst_vars; simp
mutual
/-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`.
* An atom `e` causes `↑e` to be allocated as a new atom.
* A sum delegates to `ExSum.evalNatCast`.
-/
partial def ExBase.evalNatCast {a : Q(ℕ)} (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) :=
match va with
| .atom _ => do
let (i, ⟨b', _⟩) ← addAtomQ q($a)
pure ⟨b', ExBase.atom i, q(Eq.refl $b')⟩
| .sum va => do
let ⟨_, vc, p⟩ ← va.evalNatCast
pure ⟨_, .sum vc, p⟩
/-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`.
* `↑c = c` if `c` is a numeric literal
* `↑(a ^ n * b) = ↑a ^ n * ↑b`
-/
partial def ExProd.evalNatCast {a : Q(ℕ)} (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) :=
match va with
| .const c hc =>
have n : Q(ℕ) := a.appArg!
pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩
| .mul (e := a₂) va₁ va₂ va₃ => do
let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast
let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast
pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩
/-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`.
* `↑0 = 0`
* `↑(a + b) = ↑a + ↑b`
-/
partial def ExSum.evalNatCast {a : Q(ℕ)} (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) :=
match va with
| .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩
| .add va₁ va₂ => do
let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast
let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast
pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩
end
theorem smul_nat {a b c : ℕ} (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp
theorem smul_eq_cast {a : ℕ} (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by
subst_vars; simp
/-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized
polynomial expressions.
* `a • b = a * b` if `α = ℕ`
* `a • b = ↑a * b` otherwise
-/
def evalNSMul {a : Q(ℕ)} {b : Q($α)} (va : ExSum sℕ a) (vb : ExSum sα b) :
AtomM (Result (ExSum sα) q($a • $b)) := do
if ← isDefEq sα sℕ then
let ⟨_, va'⟩ := va.cast
have _b : Q(ℕ) := b
let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ ← evalMul sα va' vb
pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩
else
let ⟨_, va', pa'⟩ ← va.evalNatCast sα
let ⟨_, vc, pc⟩ ← evalMul sα va' vb
pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩
theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) :
-a = b := by subst_vars; simp [Int.negOfNat]
theorem neg_mul {R} [Ring R] (a₁ : R) (a₂) {a₃ b : R}
(_ : -a₃ = b) : -(a₁ ^ a₂ * a₃) = a₁ ^ a₂ * b := by subst_vars; simp
/-- Negates a monomial `va` to get another monomial.
* `-c = (-c)` (for `c` coefficient)
* `-(a₁ * a₂) = a₁ * -a₂`
-/
def evalNegProd {a : Q($α)} (rα : Q(Ring $α)) (va : ExProd sα a) :
Lean.Core.CoreM <| Result (ExProd sα) q(-$a) := do
Lean.Core.checkSystem decl_name%.toString
match va with
| .const za ha =>
let lit : Q(ℕ) := mkRawNatLit 1
let ⟨m1, _⟩ := ExProd.mkNegNat sα rα 1
let rm := Result.isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr)
let ra := Result.ofRawRat za a ha
let rb := (NormNum.evalMul.core q($m1 * $a) q(HMul.hMul) _ _
q(CommSemiring.toSemiring) rm ra).get!
let ⟨zb, hb⟩ := rb.toRatNZ.get!
let ⟨b, (pb : Q((Int.negOfNat (nat_lit 1)).rawCast * $a = $b))⟩ := rb.toRawEq
return ⟨b, .const zb hb, (q(neg_one_mul (R := $α) $pb) : Expr)⟩
| .mul (x := a₁) (e := a₂) va₁ va₂ va₃ =>
let ⟨_, vb, pb⟩ ← evalNegProd rα va₃
return ⟨_, .mul va₁ va₂ vb, (q(neg_mul $a₁ $a₂ $pb) : Expr)⟩
theorem neg_zero {R} [Ring R] : -(0 : R) = 0 := by simp
theorem neg_add {R} [Ring R] {a₁ a₂ b₁ b₂ : R}
(_ : -a₁ = b₁) (_ : -a₂ = b₂) : -(a₁ + a₂) = b₁ + b₂ := by
subst_vars; simp [add_comm]
/-- Negates a polynomial `va` to get another polynomial.
* `-0 = 0` (for `c` coefficient)
* `-(a₁ + a₂) = -a₁ + -a₂`
-/
def evalNeg {a : Q($α)} (rα : Q(Ring $α)) (va : ExSum sα a) :
Lean.Core.CoreM <| Result (ExSum sα) q(-$a) := do
match va with
| .zero => return ⟨_, .zero, (q(neg_zero (R := $α)) : Expr)⟩
| .add va₁ va₂ =>
let ⟨_, vb₁, pb₁⟩ ← evalNegProd sα rα va₁
let ⟨_, vb₂, pb₂⟩ ← evalNeg rα va₂
return ⟨_, .add vb₁ vb₂, (q(neg_add $pb₁ $pb₂) : Expr)⟩
theorem sub_pf {R} [Ring R] {a b c d : R}
(_ : -b = c) (_ : a + c = d) : a - b = d := by subst_vars; simp [sub_eq_add_neg]
/-- Subtracts two polynomials `va, vb` to get a normalized result polynomial.
* `a - b = a + -b`
-/
def evalSub {α : Q(Type u)} (sα : Q(CommSemiring $α)) {a b : Q($α)}
(rα : Q(Ring $α)) (va : ExSum sα a) (vb : ExSum sα b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a - $b) := do
let ⟨_c, vc, pc⟩ ← evalNeg sα rα vb
let ⟨d, vd, (pd : Q($a + $_c = $d))⟩ ← evalAdd sα va vc
return ⟨d, vd, (q(sub_pf $pc $pd) : Expr)⟩
theorem pow_prod_atom (a : R) (b) : a ^ b = (a + 0) ^ b * (nat_lit 1).rawCast := by simp
/--
The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an
exponent expression. (This has a slightly different normalization than `evalPowAtom` because
the input types are different.)
* `x ^ e = (x + 0) ^ e * 1`
-/
def evalPowProdAtom {a : Q($α)} {b : Q(ℕ)} (va : ExProd sα a) (vb : ExProd sℕ b) :
Result (ExProd sα) q($a ^ $b) :=
⟨_, (ExBase.sum va.toSum).toProd vb, q(pow_prod_atom $a $b)⟩
theorem pow_atom (a : R) (b) : a ^ b = a ^ b * (nat_lit 1).rawCast + 0 := by simp
/--
The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an
exponent expression.
* `x ^ e = x ^ e * 1 + 0`
-/
def evalPowAtom {a : Q($α)} {b : Q(ℕ)} (va : ExBase sα a) (vb : ExProd sℕ b) :
Result (ExSum sα) q($a ^ $b) :=
⟨_, (va.toProd vb).toSum, q(pow_atom $a $b)⟩
theorem const_pos (n : ℕ) (h : Nat.ble 1 n = true) : 0 < (n.rawCast : ℕ) := Nat.le_of_ble_eq_true h
theorem mul_exp_pos {a₁ a₂ : ℕ} (n) (h₁ : 0 < a₁) (h₂ : 0 < a₂) : 0 < a₁ ^ n * a₂ :=
Nat.mul_pos (Nat.pow_pos h₁) h₂
theorem add_pos_left {a₁ : ℕ} (a₂) (h : 0 < a₁) : 0 < a₁ + a₂ :=
Nat.lt_of_lt_of_le h (Nat.le_add_right ..)
theorem add_pos_right {a₂ : ℕ} (a₁) (h : 0 < a₂) : 0 < a₁ + a₂ :=
Nat.lt_of_lt_of_le h (Nat.le_add_left ..)
mutual
/-- Attempts to prove that a polynomial expression in `ℕ` is positive.
* Atoms are not (necessarily) positive
* Sums defer to `ExSum.evalPos`
-/
partial def ExBase.evalPos {a : Q(ℕ)} (va : ExBase sℕ a) : Option Q(0 < $a) :=
match va with
| .atom _ => none
| .sum va => va.evalPos
/-- Attempts to prove that a monomial expression in `ℕ` is positive.
* `0 < c` (where `c` is a numeral) is true by the normalization invariant (`c` is not zero)
* `0 < x ^ e * b` if `0 < x` and `0 < b`
-/
partial def ExProd.evalPos {a : Q(ℕ)} (va : ExProd sℕ a) : Option Q(0 < $a) :=
match va with
| .const _ _ =>
-- it must be positive because it is a nonzero nat literal
have lit : Q(ℕ) := a.appArg!
haveI : $a =Q Nat.rawCast $lit := ⟨⟩
haveI p : Nat.ble 1 $lit =Q true := ⟨⟩
some q(const_pos $lit $p)
| .mul (e := ea₁) vxa₁ _ va₂ => do
let pa₁ ← vxa₁.evalPos
let pa₂ ← va₂.evalPos
some q(mul_exp_pos $ea₁ $pa₁ $pa₂)
/-- Attempts to prove that a polynomial expression in `ℕ` is positive.
* `0 < 0` fails
* `0 < a + b` if `0 < a` or `0 < b`
-/
partial def ExSum.evalPos {a : Q(ℕ)} (va : ExSum sℕ a) : Option Q(0 < $a) :=
match va with
| .zero => none
| .add (a := a₁) (b := a₂) va₁ va₂ => do
match va₁.evalPos with
| some p => some q(add_pos_left $a₂ $p)
| none => let p ← va₂.evalPos; some q(add_pos_right $a₁ $p)
end
theorem pow_one (a : R) : a ^ nat_lit 1 = a := by simp
theorem pow_bit0 {k : ℕ} (_ : (a : R) ^ k = b) (_ : b * b = c) :
a ^ (Nat.mul (nat_lit 2) k) = c := by
subst_vars; simp [Nat.succ_mul, pow_add]
theorem pow_bit1 {k : ℕ} {d : R} (_ : (a : R) ^ k = b) (_ : b * b = c) (_ : c * a = d) :
a ^ (Nat.add (Nat.mul (nat_lit 2) k) (nat_lit 1)) = d := by
subst_vars; simp [Nat.succ_mul, pow_add]
/--
The main case of exponentiation of ring expressions is when `va` is a polynomial and `n` is a
nonzero literal expression, like `(x + y)^5`. In this case we work out the polynomial completely
into a sum of monomials.
* `x ^ 1 = x`
* `x ^ (2*n) = x ^ n * x ^ n`
* `x ^ (2*n+1) = x ^ n * x ^ n * x`
-/
partial def evalPowNat {a : Q($α)} (va : ExSum sα a) (n : Q(ℕ)) :
Lean.Core.CoreM <| Result (ExSum sα) q($a ^ $n) := do
let nn := n.natLit!
if nn = 1 then
return ⟨_, va, (q(pow_one $a) : Expr)⟩
else
let nm := nn >>> 1
have m : Q(ℕ) := mkRawNatLit nm
if nn &&& 1 = 0 then
let ⟨_, vb, pb⟩ ← evalPowNat va m
let ⟨_, vc, pc⟩ ← evalMul sα vb vb
return ⟨_, vc, (q(pow_bit0 $pb $pc) : Expr)⟩
else
let ⟨_, vb, pb⟩ ← evalPowNat va m
let ⟨_, vc, pc⟩ ← evalMul sα vb vb
let ⟨_, vd, pd⟩ ← evalMul sα vc va
return ⟨_, vd, (q(pow_bit1 $pb $pc $pd) : Expr)⟩
theorem one_pow (b : ℕ) : ((nat_lit 1).rawCast : R) ^ b = (nat_lit 1).rawCast := by simp
theorem mul_pow {ea₁ b c₁ : ℕ} {xa₁ : R}
(_ : ea₁ * b = c₁) (_ : a₂ ^ b = c₂) : (xa₁ ^ ea₁ * a₂ : R) ^ b = xa₁ ^ c₁ * c₂ := by
subst_vars; simp [_root_.mul_pow, pow_mul]
/-- There are several special cases when exponentiating monomials:
* `1 ^ n = 1`
* `x ^ y = (x ^ y)` when `x` and `y` are constants
* `(a * b) ^ e = a ^ e * b ^ e`
In all other cases we use `evalPowProdAtom`.
-/
def evalPowProd {a : Q($α)} {b : Q(ℕ)} (va : ExProd sα a) (vb : ExProd sℕ b) :
Lean.Core.CoreM <| Result (ExProd sα) q($a ^ $b) := do
Lean.Core.checkSystem decl_name%.toString
let res : OptionT Lean.Core.CoreM (Result (ExProd sα) q($a ^ $b)) := do
match va, vb with
| .const 1, _ => return ⟨_, va, (q(one_pow (R := $α) $b) : Expr)⟩
| .const za ha, .const zb hb =>
assert! 0 ≤ zb
let ra := Result.ofRawRat za a ha
have lit : Q(ℕ) := b.appArg!
let rb := (q(IsNat.of_raw ℕ $lit) : Expr)
let rc ← NormNum.evalPow.core q($a ^ $b) q(HPow.hPow) q($a) q($b) lit rb
q(CommSemiring.toSemiring) ra
let ⟨zc, hc⟩ ← rc.toRatNZ
let ⟨c, pc⟩ := rc.toRawEq
return ⟨c, .const zc hc, pc⟩
| .mul vxa₁ vea₁ va₂, vb =>
let ⟨_, vc₁, pc₁⟩ ← evalMulProd sℕ vea₁ vb
let ⟨_, vc₂, pc₂⟩ ← evalPowProd va₂ vb
return ⟨_, .mul vxa₁ vc₁ vc₂, q(mul_pow $pc₁ $pc₂)⟩
| _, _ => OptionT.fail
return (← res.run).getD (evalPowProdAtom sα va vb)
/--
The result of `extractCoeff` is a numeral and a proof that the original expression
factors by this numeral.
-/
structure ExtractCoeff (e : Q(ℕ)) where
/-- A raw natural number literal. -/
k : Q(ℕ)
/-- The result of extracting the coefficient is a monic monomial. -/
e' : Q(ℕ)
/-- `e'` is a monomial. -/
ve' : ExProd sℕ e'
/-- The proof that `e` splits into the coefficient `k` and the monic monomial `e'`. -/
p : Q($e = $e' * $k)
theorem coeff_one (k : ℕ) : k.rawCast = (nat_lit 1).rawCast * k := by simp
theorem coeff_mul {a₃ c₂ k : ℕ}
(a₁ a₂ : ℕ) (_ : a₃ = c₂ * k) : a₁ ^ a₂ * a₃ = (a₁ ^ a₂ * c₂) * k := by
subst_vars; rw [mul_assoc]
/-- Given a monomial expression `va`, splits off the leading coefficient `k` and the remainder
`e'`, stored in the `ExtractCoeff` structure.
* `c = 1 * c` (if `c` is a constant)
* `a * b = (a * b') * k` if `b = b' * k`
-/
def extractCoeff {a : Q(ℕ)} (va : ExProd sℕ a) : ExtractCoeff a :=
match va with
| .const _ _ =>
have k : Q(ℕ) := a.appArg!
⟨k, q((nat_lit 1).rawCast), .const 1, (q(coeff_one $k) : Expr)⟩
| .mul (x := a₁) (e := a₂) va₁ va₂ va₃ =>
let ⟨k, _, vc, pc⟩ := extractCoeff va₃
⟨k, _, .mul va₁ va₂ vc, q(coeff_mul $a₁ $a₂ $pc)⟩
theorem pow_one_cast (a : R) : a ^ (nat_lit 1).rawCast = a := by simp
theorem zero_pow {b : ℕ} (_ : 0 < b) : (0 : R) ^ b = 0 := match b with | b+1 => by simp [pow_succ]
theorem single_pow {b : ℕ} (_ : (a : R) ^ b = c) : (a + 0) ^ b = c + 0 := by
simp [*]
theorem pow_nat {b c k : ℕ} {d e : R} (_ : b = c * k) (_ : a ^ c = d) (_ : d ^ k = e) :
(a : R) ^ b = e := by
subst_vars; simp [pow_mul]
/-- Exponentiates a polynomial `va` by a monomial `vb`, including several special cases.
* `a ^ 1 = a`
* `0 ^ e = 0` if `0 < e`
* `(a + 0) ^ b = a ^ b` computed using `evalPowProd`
* `a ^ b = (a ^ b') ^ k` if `b = b' * k` and `k > 1`
Otherwise `a ^ b` is just encoded as `a ^ b * 1 + 0` using `evalPowAtom`.
-/
partial def evalPow₁ {a : Q($α)} {b : Q(ℕ)} (va : ExSum sα a) (vb : ExProd sℕ b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a ^ $b) := do
match va, vb with
| va, .const 1 =>
haveI : $b =Q Nat.rawCast (nat_lit 1) := ⟨⟩
return ⟨_, va, q(pow_one_cast $a)⟩
| .zero, vb => match vb.evalPos with
| some p => return ⟨_, .zero, q(zero_pow (R := $α) $p)⟩
| none => return evalPowAtom sα (.sum .zero) vb
| ExSum.add va .zero, vb => -- TODO: using `.add` here takes a while to compile?
let ⟨_, vc, pc⟩ ← evalPowProd sα va vb
return ⟨_, vc.toSum, q(single_pow $pc)⟩
| va, vb =>
if vb.coeff > 1 then
let ⟨k, _, vc, pc⟩ := extractCoeff vb
let ⟨_, vd, pd⟩ ← evalPow₁ va vc
let ⟨_, ve, pe⟩ ← evalPowNat sα vd k
return ⟨_, ve, q(pow_nat $pc $pd $pe)⟩
else
return evalPowAtom sα (.sum va) vb
theorem pow_zero (a : R) : a ^ 0 = (nat_lit 1).rawCast + 0 := by simp
theorem pow_add {b₁ b₂ : ℕ} {d : R}
(_ : a ^ b₁ = c₁) (_ : a ^ b₂ = c₂) (_ : c₁ * c₂ = d) : (a : R) ^ (b₁ + b₂) = d := by
subst_vars; simp [_root_.pow_add]
/-- Exponentiates two polynomials `va, vb`.
* `a ^ 0 = 1`
* `a ^ (b₁ + b₂) = a ^ b₁ * a ^ b₂`
-/
def evalPow {a : Q($α)} {b : Q(ℕ)} (va : ExSum sα a) (vb : ExSum sℕ b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a ^ $b) := do
match vb with
| .zero => return ⟨_, (ExProd.mkNat sα 1).2.toSum, q(pow_zero $a)⟩
| .add vb₁ vb₂ =>
let ⟨_, vc₁, pc₁⟩ ← evalPow₁ sα va vb₁
let ⟨_, vc₂, pc₂⟩ ← evalPow va vb₂
let ⟨_, vd, pd⟩ ← evalMul sα vc₁ vc₂
return ⟨_, vd, q(pow_add $pc₁ $pc₂ $pd)⟩
/-- This cache contains data required by the `ring` tactic during execution. -/
structure Cache {α : Q(Type u)} (sα : Q(CommSemiring $α)) where
/-- A ring instance on `α`, if available. -/
rα : Option Q(Ring $α)
/-- A division ring instance on `α`, if available. -/
dα : Option Q(DivisionRing $α)
/-- A characteristic zero ring instance on `α`, if available. -/
czα : Option Q(CharZero $α)
/-- Create a new cache for `α` by doing the necessary instance searches. -/
def mkCache {α : Q(Type u)} (sα : Q(CommSemiring $α)) : MetaM (Cache sα) :=
return {
rα := (← trySynthInstanceQ q(Ring $α)).toOption
dα := (← trySynthInstanceQ q(DivisionRing $α)).toOption
czα := (← trySynthInstanceQ q(CharZero $α)).toOption }
theorem cast_pos {n : ℕ} : IsNat (a : R) n → a = n.rawCast + 0
| ⟨e⟩ => by simp [e]
theorem cast_zero : IsNat (a : R) (nat_lit 0) → a = 0
| ⟨e⟩ => by simp [e]
theorem cast_neg {n : ℕ} {R} [Ring R] {a : R} :
IsInt a (.negOfNat n) → a = (Int.negOfNat n).rawCast + 0
| ⟨e⟩ => by simp [e]
theorem cast_rat {n : ℤ} {d : ℕ} {R} [DivisionRing R] {a : R} :
IsRat a n d → a = Rat.rawCast n d + 0
| ⟨_, e⟩ => by simp [e, div_eq_mul_inv]
/-- Converts a proof by `norm_num` that `e` is a numeral, into a normalization as a monomial:
* `e = 0` if `norm_num` returns `IsNat e 0`
* `e = Nat.rawCast n + 0` if `norm_num` returns `IsNat e n`
* `e = Int.rawCast n + 0` if `norm_num` returns `IsInt e n`
* `e = Rat.rawCast n d + 0` if `norm_num` returns `IsRat e n d`
-/
def evalCast {α : Q(Type u)} (sα : Q(CommSemiring $α)) {e : Q($α)} :
NormNum.Result e → Option (Result (ExSum sα) e)
| .isNat _ (.lit (.natVal 0)) p => do
assumeInstancesCommute
pure ⟨_, .zero, q(cast_zero $p)⟩
| .isNat _ lit p => do
assumeInstancesCommute
pure ⟨_, (ExProd.mkNat sα lit.natLit!).2.toSum, (q(cast_pos $p) :)⟩
| .isNegNat rα lit p =>
pure ⟨_, (ExProd.mkNegNat _ rα lit.natLit!).2.toSum, (q(cast_neg $p) : Expr)⟩
| .isRat dα q n d p =>
pure ⟨_, (ExProd.mkRat sα dα q n d q(IsRat.den_nz $p)).2.toSum, (q(cast_rat $p) : Expr)⟩
| _ => none
theorem toProd_pf (p : (a : R) = a') :
a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast := by simp [*]
theorem atom_pf (a : R) : a = a ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp
theorem atom_pf' (p : (a : R) = a') :
a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp [*]
/--
Evaluates an atom, an expression where `ring` can find no additional structure.
* `a = a ^ 1 * 1 + 0`
-/
def evalAtom (e : Q($α)) : AtomM (Result (ExSum sα) e) := do
let r ← (← read).evalAtom e
have e' : Q($α) := r.expr
let (i, ⟨a', _⟩) ← addAtomQ e'
let ve' := (ExBase.atom i (e := a')).toProd (ExProd.mkNat sℕ 1).2 |>.toSum
pure ⟨_, ve', match r.proof? with
| none => (q(atom_pf $e) : Expr)
| some (p : Q($e = $a')) => (q(atom_pf' $p) : Expr)⟩
theorem inv_mul {R} [DivisionRing R] {a₁ a₂ a₃ b₁ b₃ c}
(_ : (a₁⁻¹ : R) = b₁) (_ : (a₃⁻¹ : R) = b₃)
(_ : b₃ * (b₁ ^ a₂ * (nat_lit 1).rawCast) = c) :
(a₁ ^ a₂ * a₃ : R)⁻¹ = c := by subst_vars; simp
nonrec theorem inv_zero {R} [DivisionRing R] : (0 : R)⁻¹ = 0 := inv_zero
theorem inv_single {R} [DivisionRing R] {a b : R}
(_ : (a : R)⁻¹ = b) : (a + 0)⁻¹ = b + 0 := by simp [*]
theorem inv_add {a₁ a₂ : ℕ} (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) :
((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by
subst_vars; simp
section
variable (dα : Q(DivisionRing $α))
/-- Applies `⁻¹` to a polynomial to get an atom. -/
def evalInvAtom (a : Q($α)) : AtomM (Result (ExBase sα) q($a⁻¹)) := do
let (i, ⟨b', _⟩) ← addAtomQ q($a⁻¹)
pure ⟨b', ExBase.atom i, q(Eq.refl $b')⟩
/-- Inverts a polynomial `va` to get a normalized result polynomial.
* `c⁻¹ = (c⁻¹)` if `c` is a constant
* `(a ^ b * c)⁻¹ = a⁻¹ ^ b * c⁻¹`
-/
def ExProd.evalInv {a : Q($α)} (czα : Option Q(CharZero $α)) (va : ExProd sα a) :
| AtomM (Result (ExProd sα) q($a⁻¹)) := do
Lean.Core.checkSystem decl_name%.toString
| Mathlib/Tactic/Ring/Basic.lean | 989 | 990 |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
/-!
# Integral average of a function
In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average
value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it
is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability
measure, then the average of any function is equal to its integral.
For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For
average w.r.t. the volume, one can omit `∂volume`.
Both have a version for the Lebesgue integral rather than Bochner.
We prove several version of the first moment method: An integrable function is below/above its
average on a set of positive measure:
* `measure_le_setLAverage_pos` for the Lebesgue integral
* `measure_le_setAverage_pos` for the Bochner integral
## Implementation notes
The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner
integrals work for the average without modifications. For theorems that require integrability of a
function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`.
## Tags
integral, center mass, average value
-/
open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function
open scoped Topology ENNReal Convex
variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α}
{s t : Set α}
/-!
### Average value of a function w.r.t. a measure
The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation:
`⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total
measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if
`f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to
its integral.
-/
namespace MeasureTheory
section ENNReal
variable (μ) {f g : α → ℝ≥0∞}
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure.
It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite
measure. In a probability space, the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`.
It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s`
has measure `1`, then the average of any function is equal to its integral.
For the average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`.
It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If
`s` has measure `1`, then the average of any function is equal to its integral. -/
notation3 (prettyPrint := false)
"⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r
@[simp]
theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero]
@[simp]
theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage]
theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl
theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by
rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul]
theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) :
⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul]
@[simp]
theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by
rcases eq_or_ne μ 0 with hμ | hμ
· rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero]
· rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)]
theorem setLAverage_eq (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq := setLAverage_eq
theorem setLAverage_eq' (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by
simp only [laverage_eq', restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq' := setLAverage_eq'
variable {μ}
theorem laverage_congr {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ⨍⁻ x, f x ∂μ = ⨍⁻ x, g x ∂μ := by
simp only [laverage_eq, lintegral_congr_ae h]
theorem setLAverage_congr (h : s =ᵐ[μ] t) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in t, f x ∂μ := by
simp only [setLAverage_eq, setLIntegral_congr h, measure_congr h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr := setLAverage_congr
theorem setLAverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) :
⨍⁻ x in s, f x ∂μ = ⨍⁻ x in s, g x ∂μ := by
simp only [laverage_eq, setLIntegral_congr_fun hs h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr_fun := setLAverage_congr_fun
theorem laverage_lt_top (hf : ∫⁻ x, f x ∂μ ≠ ∞) : ⨍⁻ x, f x ∂μ < ∞ := by
obtain rfl | hμ := eq_or_ne μ 0
· simp
· rw [laverage_eq]
exact div_lt_top hf (measure_univ_ne_zero.2 hμ)
theorem setLAverage_lt_top : ∫⁻ x in s, f x ∂μ ≠ ∞ → ⨍⁻ x in s, f x ∂μ < ∞ :=
laverage_lt_top
@[deprecated (since := "2025-04-22")] alias setLaverage_lt_top := setLAverage_lt_top
theorem laverage_add_measure :
⨍⁻ x, f x ∂(μ + ν) =
μ univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂μ + ν univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂ν := by
by_cases hμ : IsFiniteMeasure μ; swap
· rw [not_isFiniteMeasure_iff] at hμ
simp [laverage_eq, hμ]
by_cases hν : IsFiniteMeasure ν; swap
· rw [not_isFiniteMeasure_iff] at hν
simp [laverage_eq, hν]
haveI := hμ; haveI := hν
simp only [← ENNReal.mul_div_right_comm, measure_mul_laverage, ← ENNReal.add_div,
← lintegral_add_measure, ← Measure.add_apply, ← laverage_eq]
theorem measure_mul_setLAverage (f : α → ℝ≥0∞) (h : μ s ≠ ∞) :
μ s * ⨍⁻ x in s, f x ∂μ = ∫⁻ x in s, f x ∂μ := by
have := Fact.mk h.lt_top
rw [← measure_mul_laverage, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias measure_mul_setLaverage := measure_mul_setLAverage
theorem laverage_union (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
⨍⁻ x in s ∪ t, f x ∂μ =
μ s / (μ s + μ t) * ⨍⁻ x in s, f x ∂μ + μ t / (μ s + μ t) * ⨍⁻ x in t, f x ∂μ := by
rw [restrict_union₀ hd ht, laverage_add_measure, restrict_apply_univ, restrict_apply_univ]
theorem laverage_union_mem_openSegment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hs₀ : μ s ≠ 0) (ht₀ : μ t ≠ 0) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in t, f x ∂μ) := by
refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), ENNReal.div_pos hs₀ <| add_ne_top.2 ⟨hsμ, htμ⟩,
ENNReal.div_pos ht₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ?_, (laverage_union hd ht).symm⟩
rw [← ENNReal.add_div,
ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
theorem laverage_union_mem_segment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
| (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ [⨍⁻ x in s, f x ∂μ -[ℝ≥0∞] ⨍⁻ x in t, f x ∂μ] := by
by_cases hs₀ : μ s = 0
· rw [← ae_eq_empty] at hs₀
rw [restrict_congr_set (hs₀.union EventuallyEq.rfl), empty_union]
exact right_mem_segment _ _ _
· refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), zero_le _, zero_le _, ?_, (laverage_union hd ht).symm⟩
| Mathlib/MeasureTheory/Integral/Average.lean | 195 | 202 |
/-
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.GroupWithZero.Action.Pointwise.Set
import Mathlib.Algebra.Module.LinearMap.Prod
import Mathlib.Algebra.Order.Module.Synonym
import Mathlib.Analysis.Convex.Segment
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.Module
/-!
# Star-convex sets
This files defines star-convex sets (aka star domains, star-shaped set, radially convex set).
A set is star-convex at `x` if every segment from `x` to a point in the set is contained in the set.
This is the prototypical example of a contractible set in homotopy theory (by scaling every point
towards `x`), but has wider uses.
Note that this has nothing to do with star rings, `Star` and co.
## Main declarations
* `StarConvex 𝕜 x s`: `s` is star-convex at `x` with scalars `𝕜`.
## Implementation notes
Instead of saying that a set is star-convex, we say a set is star-convex *at a point*. This has the
advantage of allowing us to talk about convexity as being "everywhere star-convexity" and of making
the union of star-convex sets be star-convex.
Incidentally, this choice means we don't need to assume a set is nonempty for it to be star-convex.
Concretely, the empty set is star-convex at every point.
## TODO
Balanced sets are star-convex.
The closure of a star-convex set is star-convex.
Star-convex sets are contractible.
A nonempty open star-convex set in `ℝ^n` is diffeomorphic to the entire space.
-/
open Set
open Convex Pointwise
variable {𝕜 E F : Type*}
section OrderedSemiring
variable [Semiring 𝕜] [PartialOrder 𝕜]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F]
section SMul
variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (x : E) (s : Set E)
/-- Star-convexity of sets. `s` is star-convex at `x` if every segment from `x` to a point in `s` is
contained in `s`. -/
def StarConvex (𝕜 : Type*) {E : Type*} [Semiring 𝕜] [PartialOrder 𝕜]
[AddCommMonoid E] [SMul 𝕜 E] (x : E) (s : Set E) : Prop :=
∀ ⦃y : E⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s
variable {𝕜 x s} {t : Set E}
theorem starConvex_iff_segment_subset : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s := by
constructor
· rintro h y hy z ⟨a, b, ha, hb, hab, rfl⟩
exact h hy ha hb hab
· rintro h y hy a b ha hb hab
exact h hy ⟨a, b, ha, hb, hab, rfl⟩
theorem StarConvex.segment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) : [x -[𝕜] y] ⊆ s :=
starConvex_iff_segment_subset.1 h hy
theorem StarConvex.openSegment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) :
openSegment 𝕜 x y ⊆ s :=
(openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hy)
/-- Alternative definition of star-convexity, in terms of pointwise set operations. -/
theorem starConvex_iff_pointwise_add_subset :
StarConvex 𝕜 x s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • {x} + b • s ⊆ s := by
refine
⟨?_, fun h y hy a b ha hb hab =>
h ha hb hab (add_mem_add (smul_mem_smul_set <| mem_singleton _) ⟨_, hy, rfl⟩)⟩
rintro hA a b ha hb hab w ⟨au, ⟨u, rfl : u = x, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩
exact hA hv ha hb hab
theorem starConvex_empty (x : E) : StarConvex 𝕜 x ∅ := fun _ hy => hy.elim
theorem starConvex_univ (x : E) : StarConvex 𝕜 x univ := fun _ _ _ _ _ _ _ => trivial
theorem StarConvex.inter (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) : StarConvex 𝕜 x (s ∩ t) :=
fun _ hy _ _ ha hb hab => ⟨hs hy.left ha hb hab, ht hy.right ha hb hab⟩
theorem starConvex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, StarConvex 𝕜 x s) :
StarConvex 𝕜 x (⋂₀ S) := fun _ hy _ _ ha hb hab s hs => h s hs (hy s hs) ha hb hab
theorem starConvex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, StarConvex 𝕜 x (s i)) :
StarConvex 𝕜 x (⋂ i, s i) :=
sInter_range s ▸ starConvex_sInter <| forall_mem_range.2 h
theorem starConvex_iInter₂ {ι : Sort*} {κ : ι → Sort*} {s : (i : ι) → κ i → Set E}
(h : ∀ i j, StarConvex 𝕜 x (s i j)) : StarConvex 𝕜 x (⋂ (i) (j), s i j) :=
starConvex_iInter fun i => starConvex_iInter (h i)
theorem StarConvex.union (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) :
StarConvex 𝕜 x (s ∪ t) := by
rintro y (hy | hy) a b ha hb hab
· exact Or.inl (hs hy ha hb hab)
· exact Or.inr (ht hy ha hb hab)
theorem starConvex_iUnion {ι : Sort*} {s : ι → Set E} (hs : ∀ i, StarConvex 𝕜 x (s i)) :
StarConvex 𝕜 x (⋃ i, s i) := by
rintro y hy a b ha hb hab
rw [mem_iUnion] at hy ⊢
obtain ⟨i, hy⟩ := hy
exact ⟨i, hs i hy ha hb hab⟩
theorem starConvex_iUnion₂ {ι : Sort*} {κ : ι → Sort*} {s : (i : ι) → κ i → Set E}
(h : ∀ i j, StarConvex 𝕜 x (s i j)) : StarConvex 𝕜 x (⋃ (i) (j), s i j) :=
starConvex_iUnion fun i => starConvex_iUnion (h i)
theorem starConvex_sUnion {S : Set (Set E)} (hS : ∀ s ∈ S, StarConvex 𝕜 x s) :
StarConvex 𝕜 x (⋃₀ S) := by
rw [sUnion_eq_iUnion]
exact starConvex_iUnion fun s => hS _ s.2
theorem StarConvex.prod {y : F} {s : Set E} {t : Set F} (hs : StarConvex 𝕜 x s)
(ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x, y) (s ×ˢ t) := fun _ hy _ _ ha hb hab =>
⟨hs hy.1 ha hb hab, ht hy.2 ha hb hab⟩
theorem starConvex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)]
{x : ∀ i, E i} {s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → StarConvex 𝕜 (x i) (t i)) :
StarConvex 𝕜 x (s.pi t) := fun _ hy _ _ ha hb hab i hi => ht hi (hy i hi) ha hb hab
end SMul
section Module
variable [Module 𝕜 E] [Module 𝕜 F] {x y z : E} {s : Set E}
theorem StarConvex.mem [ZeroLEOneClass 𝕜] (hs : StarConvex 𝕜 x s) (h : s.Nonempty) : x ∈ s := by
obtain ⟨y, hy⟩ := h
convert hs hy zero_le_one le_rfl (add_zero 1)
rw [one_smul, zero_smul, add_zero]
theorem starConvex_iff_forall_pos (hx : x ∈ s) : StarConvex 𝕜 x s ↔
∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by
refine ⟨fun h y hy a b ha hb hab => h hy ha.le hb.le hab, ?_⟩
intro h y hy a b ha hb hab
obtain rfl | ha := ha.eq_or_lt
· rw [zero_add] at hab
rwa [hab, one_smul, zero_smul, zero_add]
obtain rfl | hb := hb.eq_or_lt
· rw [add_zero] at hab
rwa [hab, one_smul, zero_smul, add_zero]
exact h hy ha hb hab
theorem starConvex_iff_forall_ne_pos (hx : x ∈ s) :
StarConvex 𝕜 x s ↔
∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by
refine ⟨fun h y hy _ a b ha hb hab => h hy ha.le hb.le hab, ?_⟩
intro h y hy a b ha hb hab
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_add] at hab
rwa [hab, zero_smul, one_smul, zero_add]
obtain rfl | hb' := hb.eq_or_lt
· rw [add_zero] at hab
rwa [hab, zero_smul, one_smul, add_zero]
obtain rfl | hxy := eq_or_ne x y
· rwa [Convex.combo_self hab]
exact h hy hxy ha' hb' hab
theorem starConvex_iff_openSegment_subset [ZeroLEOneClass 𝕜] (hx : x ∈ s) :
StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s :=
starConvex_iff_segment_subset.trans <|
forall₂_congr fun _ hy => (openSegment_subset_iff_segment_subset hx hy).symm
theorem starConvex_singleton (x : E) : StarConvex 𝕜 x {x} := by
rintro y (rfl : y = x) a b _ _ hab
exact Convex.combo_self hab _
theorem StarConvex.linear_image (hs : StarConvex 𝕜 x s) (f : E →ₗ[𝕜] F) :
StarConvex 𝕜 (f x) (f '' s) := by
rintro _ ⟨y, hy, rfl⟩ a b ha hb hab
exact ⟨a • x + b • y, hs hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩
theorem StarConvex.is_linear_image (hs : StarConvex 𝕜 x s) {f : E → F} (hf : IsLinearMap 𝕜 f) :
| StarConvex 𝕜 (f x) (f '' s) :=
hs.linear_image <| hf.mk' f
| Mathlib/Analysis/Convex/Star.lean | 200 | 202 |
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.NatIso
import Mathlib.Logic.Equiv.Defs
/-!
# Full and faithful functors
We define typeclasses `Full` and `Faithful`, decorating functors. These typeclasses
carry no data. However, we also introduce a structure `Functor.FullyFaithful` which
contains the data of the inverse map `(F.obj X ⟶ F.obj Y) ⟶ (X ⟶ Y)` of the
map induced on morphisms by a functor `F`.
## Main definitions and results
* Use `F.map_injective` to retrieve the fact that `F.map` is injective when `[Faithful F]`.
* Similarly, `F.map_surjective` states that `F.map` is surjective when `[Full F]`.
* Use `F.preimage` to obtain preimages of morphisms when `[Full F]`.
* We prove some basic "cancellation" lemmas for full and/or faithful functors, as well as a
construction for "dividing" a functor by a faithful functor, see `Faithful.div`.
See `CategoryTheory.Equivalence.of_fullyFaithful_ess_surj` for the fact that a functor is an
equivalence if and only if it is fully faithful and essentially surjective.
-/
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {E : Type*} [Category E]
namespace Functor
/-- A functor `F : C ⥤ D` is full if for each `X Y : C`, `F.map` is surjective. -/
@[stacks 001C]
class Full (F : C ⥤ D) : Prop where
map_surjective {X Y : C} : Function.Surjective (F.map (X := X) (Y := Y))
/-- A functor `F : C ⥤ D` is faithful if for each `X Y : C`, `F.map` is injective. -/
@[stacks 001C]
class Faithful (F : C ⥤ D) : Prop where
/-- `F.map` is injective for each `X Y : C`. -/
map_injective : ∀ {X Y : C}, Function.Injective (F.map : (X ⟶ Y) → (F.obj X ⟶ F.obj Y)) := by
aesop_cat
variable {X Y : C}
theorem map_injective (F : C ⥤ D) [Faithful F] :
Function.Injective <| (F.map : (X ⟶ Y) → (F.obj X ⟶ F.obj Y)) :=
Faithful.map_injective
lemma map_injective_iff (F : C ⥤ D) [Faithful F] {X Y : C} (f g : X ⟶ Y) :
F.map f = F.map g ↔ f = g :=
⟨fun h => F.map_injective h, fun h => by rw [h]⟩
theorem mapIso_injective (F : C ⥤ D) [Faithful F] :
Function.Injective <| (F.mapIso : (X ≅ Y) → (F.obj X ≅ F.obj Y)) := fun _ _ h =>
Iso.ext (map_injective F (congr_arg Iso.hom h :))
theorem map_surjective (F : C ⥤ D) [Full F] :
Function.Surjective (F.map : (X ⟶ Y) → (F.obj X ⟶ F.obj Y)) :=
Full.map_surjective
/-- The choice of a preimage of a morphism under a full functor. -/
noncomputable def preimage (F : C ⥤ D) [Full F] (f : F.obj X ⟶ F.obj Y) : X ⟶ Y :=
(F.map_surjective f).choose
@[simp]
theorem map_preimage (F : C ⥤ D) [Full F] {X Y : C} (f : F.obj X ⟶ F.obj Y) :
F.map (preimage F f) = f :=
(F.map_surjective f).choose_spec
variable {F : C ⥤ D} {X Y Z : C}
section
variable [Full F] [F.Faithful]
@[simp]
theorem preimage_id : F.preimage (𝟙 (F.obj X)) = 𝟙 X :=
F.map_injective (by simp)
@[simp]
theorem preimage_comp (f : F.obj X ⟶ F.obj Y) (g : F.obj Y ⟶ F.obj Z) :
F.preimage (f ≫ g) = F.preimage f ≫ F.preimage g :=
F.map_injective (by simp)
@[simp]
theorem preimage_map (f : X ⟶ Y) : F.preimage (F.map f) = f :=
F.map_injective (by simp)
variable (F)
/-- If `F : C ⥤ D` is fully faithful, every isomorphism `F.obj X ≅ F.obj Y` has a preimage. -/
@[simps]
noncomputable def preimageIso (f : F.obj X ≅ F.obj Y) :
X ≅ Y where
hom := F.preimage f.hom
inv := F.preimage f.inv
hom_inv_id := F.map_injective (by simp)
inv_hom_id := F.map_injective (by simp)
@[simp]
theorem preimageIso_mapIso (f : X ≅ Y) : F.preimageIso (F.mapIso f) = f := by
ext
simp
end
variable (F) in
/-- Structure containing the data of inverse map `(F.obj X ⟶ F.obj Y) ⟶ (X ⟶ Y)` of `F.map`
in order to express that `F` is a fully faithful functor. -/
structure FullyFaithful where
/-- The inverse map `(F.obj X ⟶ F.obj Y) ⟶ (X ⟶ Y)` of `F.map`. -/
preimage {X Y : C} (f : F.obj X ⟶ F.obj Y) : X ⟶ Y
map_preimage {X Y : C} (f : F.obj X ⟶ F.obj Y) : F.map (preimage f) = f := by aesop_cat
preimage_map {X Y : C} (f : X ⟶ Y) : preimage (F.map f) = f := by aesop_cat
namespace FullyFaithful
attribute [simp] map_preimage preimage_map
variable (F) in
/-- A `FullyFaithful` structure can be obtained from the assumption the `F` is both
full and faithful. -/
noncomputable def ofFullyFaithful [F.Full] [F.Faithful] :
F.FullyFaithful where
preimage := F.preimage
variable (C) in
/-- The identity functor is fully faithful. -/
@[simps]
def id : (𝟭 C).FullyFaithful where
preimage f := f
section
variable (hF : F.FullyFaithful)
include hF
/-- The equivalence `(X ⟶ Y) ≃ (F.obj X ⟶ F.obj Y)` given by `h : F.FullyFaithful`. -/
@[simps]
def homEquiv {X Y : C} : (X ⟶ Y) ≃ (F.obj X ⟶ F.obj Y) where
toFun := F.map
invFun := hF.preimage
left_inv _ := by simp
right_inv _ := by simp
lemma map_injective {X Y : C} {f g : X ⟶ Y} (h : F.map f = F.map g) : f = g :=
hF.homEquiv.injective h
lemma map_surjective {X Y : C} :
Function.Surjective (F.map : (X ⟶ Y) → (F.obj X ⟶ F.obj Y)) :=
hF.homEquiv.surjective
lemma map_bijective (X Y : C) :
Function.Bijective (F.map : (X ⟶ Y) → (F.obj X ⟶ F.obj Y)) :=
hF.homEquiv.bijective
@[simp]
lemma preimage_id {X : C} :
hF.preimage (𝟙 (F.obj X)) = 𝟙 X :=
hF.map_injective (by simp)
@[simp, reassoc]
lemma preimage_comp {X Y Z : C} (f : F.obj X ⟶ F.obj Y) (g : F.obj Y ⟶ F.obj Z) :
hF.preimage (f ≫ g) = hF.preimage f ≫ hF.preimage g :=
hF.map_injective (by simp)
lemma full : F.Full where
map_surjective := hF.map_surjective
lemma faithful : F.Faithful where
map_injective := hF.map_injective
instance : Subsingleton F.FullyFaithful where
allEq h₁ h₂ := by
have := h₁.faithful
cases h₁ with | mk f₁ hf₁ _ => cases h₂ with | mk f₂ hf₂ _ =>
simp only [Functor.FullyFaithful.mk.injEq]
| ext
apply F.map_injective
| Mathlib/CategoryTheory/Functor/FullyFaithful.lean | 185 | 186 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.